How to add a poll below the thumbnails? #225
-
I am using the caption and thumbnail plugin, I want to show a poll question with answers where the user can vote (API request), the problem I am facing is I want to show it below the thumbnail and I want it to be fixed through all the slides or at least shown in each slide. From the previous answers, I figured out I need to create a custom plugin and a custom slide, correct me if I am wrong. Is it doable with these specific requirements? and if yes can you help me with how to do it? import Thumbnails from "yet-another-react-lightbox/plugins/thumbnails";
import "yet-another-react-lightbox/plugins/thumbnails.css";
import "yet-another-react-lightbox/plugins/captions.css";
import Captions from "yet-another-react-lightbox/plugins/captions";
import Lightbox from "yet-another-react-lightbox";
// ...
<Lightbox
open={open}
close={() => setOpen(false)}
slides={slides}
carousel={{
finite: true,
imageFit: "contain",
}}
plugins={[Thumbnails, Captions,]}
captions={{ descriptionMaxLines: 1, descriptionTextAlign: "center" }}
styles = {{
container: {
backgroundColor: "rgba(0, 0, 0, .95)",
},
captionsDescriptionContainer: {
paddingBottom: "5%",
},
}}
/> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi there! You are absolutely correct; you need a custom plugin in this case. To add your poll component below the thumbnails, you need to wrap the topmost Thumbnails element with an extra Here is how you can implement this. // Poll.tsx
import {
ComponentProps,
createModule,
PLUGIN_THUMBNAILS,
PluginProps,
useLightboxState,
} from "yet-another-react-lightbox";
function PollComponent({ children }: ComponentProps) {
// access current slide if needed
const { currentSlide } = useLightboxState();
return (
<div
style={{
height: "100%",
display: "flex",
flexDirection: "column",
}}
>
{children}
<div
style={{
padding: 16,
textAlign: "center",
color: "#fff",
backgroundColor: "var(--yarl__color_backdrop, #000)",
}}
>
Poll
</div>
</div>
);
}
export default function Poll({ addParent }: PluginProps) {
addParent(PLUGIN_THUMBNAILS, createModule("poll", PollComponent));
} <Lightbox
slides={slides}
open={open}
close={() => setOpen(false)}
// Poll plugin must be declared after Thumbnails
plugins={[Captions, Thumbnails, Poll]}
carousel={{ finite: true }}
captions={{ descriptionMaxLines: 1, descriptionTextAlign: "center" }}
styles={{
root: { "--yarl__color_backdrop": "rgba(0, 0, 0, .95)" },
captionsDescriptionContainer: { paddingBottom: "5%" },
}}
/> Live demo - https://codesandbox.io/p/devbox/yet-another-react-lightbox-225-6gfyg2?file=%2Fsrc%2FApp.tsx Please let me know if this addresses your use case. |
Beta Was this translation helpful? Give feedback.
Hi there!
You are absolutely correct; you need a custom plugin in this case. To add your poll component below the thumbnails, you need to wrap the topmost Thumbnails element with an extra
<div>
and render your poll below.Here is how you can implement this.