You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to provide props to customUI, but not sure how to access them.
const imageList = (imageCollection) => imageCollection.map((img) => {
return {
...img, // this includes a data object with a property/value for 'likes'
original: img.url,
thumbnail: img.thumb,
height: img.height,
width: img.width,
alt: img.title,
id: img.id
}
})
const likeButton = {
name: `like-button`,
ariaLabel: 'Like',
order: 11,
isButton: true,
tagName: 'div',
appendTo: 'bar',
html: `
<span class="relative">
<svg ...>
<path d="..."></path>
</svg>
<span>
// I WANT TO ADD DATA VALUE HERE, this obviously is not working
${item.data.likes}
</span>
</span>
`,
onClick: async (e, item, pswp) => {
// userid is provided by context
// this feature is working correctly
if (await like({userId: user.id, imageId: pswp.currSlide.data.id})) {
notify('You liked this image.', 'success')
}
},
onInit: (btn, pswp) => {
// pswp.currSlide.data.likes is the number property I want to add
console.log('onInit', btn, pswp)
}
}
// NOTE shareButton excluded for brevity, but is nearly identical to likeButton
My tsx component:
<PhotoGallery uiElements={[likeButton, shareButton]}>
<div ...>
{imageList.map(item => (
// item extends ItemProps, see imageList above
<Item {...item} key={guid()}>
{({ ref, open }) => (
<div ... ref={ref}>
<div ...>
{/* placing open() method here, since ImageFooter captures clicks to do stuff */}
<img ... src={item.url} onClick={(e) => open(e)} />
{/* custom component to display likes and shares */}
<ImageFooter image={item} />
</div>
</div>
)}
</Item>
))}
</div>
</PhotoGallery>
How can I add a uiElement to the bar which includes an SVG icon, and a dynamic value provided by ItemProps? So the output should be something like:
<span>
<svg ...>
<path d="..."></path>
</svg>
<span>312</span> <!-- this is dynamic value 'likes' -->
</span>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to provide props to customUI, but not sure how to access them.
My tsx component:
How can I add a uiElement to the bar which includes an SVG icon, and a dynamic value provided by ItemProps? So the output should be something like:
Beta Was this translation helpful? Give feedback.
All reactions