Create a customized plugin with the caption plugin didn't appear #227
-
|
I am trying to create a customized plugin that displays poll info and I want it to appear below the image and caption. import {
ComponentProps,
createModule,
PLUGIN_THUMBNAILS,
PLUGIN_CAPTIONS,
PluginProps,
useLightboxState,
} from "yet-another-react-lightbox";
function PollComponent({ children }: ComponentProps) {
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)",
}}
>
<div className="m-auto flex h-80 w-full max-w-[95%] flex-col gap-3 overflow-y-scroll md:h-56">
<p className="text-2xl font-bold">{t("poll")}</p>
{/* rest of logic*/}
</div>
</div>
</div>
);
}
// export default function PollCaptionPlugin({ addParent }: PluginProps) {
// addParent(PLUGIN_CAPTIONS, createModule("pollCaption", PollComponent));
// }
export default function PollCaptionPlugin() {
createModule("pollCaption", PollComponent);
}I tried this 2 ways to createModule but nothing changes export default function PollCaptionPlugin({ addParent }: PluginProps) {
addParent(PLUGIN_CAPTIONS, createModule("pollCaption", PollComponent));
}or export default function PollCaptionPlugin() {
createModule("pollCaption", PollComponent);
}And here's my lightbox component import React from "react";
import "yet-another-react-lightbox/plugins/captions.css";
import Captions from "yet-another-react-lightbox/plugins/captions";
import Lightbox from "yet-another-react-lightbox";
import PollCaptionPlugin from "./PollCaptionPlugin";
declare module "yet-another-react-lightbox" {
interface GenericSlide {
src: string;
pollName: string;
}
interface SlideImage {
pollName: string;
}
}
const PhotoModal = ({
photoItem,
open,
setOpen,
}: {
photoItem: PhotoDetail | undefined;
open: boolean;
setOpen: (value: React.SetStateAction<boolean>) => void;
}) => {
const slides: any = [
{
src: photoItem?.websiteUrl,
description: photoItem?.description,
pollName: photoItem?.poll?.name,
},
];
return (
<>
{photoItem && (
<Lightbox
open={open}
close={() => setOpen(false)}
slides={slides}
plugins={[Captions, PollCaptionPlugin]}
captions={{ descriptionMaxLines: 1, descriptionTextAlign: "center" }}
styles={{
container: {
backgroundColor: "rgba(0, 0, 0, .95)",
},
captionsDescriptionContainer: {
paddingBottom: "3%",
},
}}
render={{
buttonPrev: () => null,
buttonNext: () => null,
}}
/>
)}
</>
);
};
export default PhotoModal;The lightbox opens and the photo with the caption appears but the poll plugin doesn't, Can you help spot the problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hi there! Here are 2 modifications that you need to make:
addParent(MODULE_CONTROLLER, createModule("poll", PollComponent));
<div style={{ flex: 1, position: "relative" }}>{children}</div>And to make this solution compatible with #225, you can use the following conditional logic: export default function Poll({ contains, addParent }: PluginProps) {
addParent(
contains(PLUGIN_THUMBNAILS) ? PLUGIN_THUMBNAILS : MODULE_CONTROLLER,
createModule("poll", PollComponent),
);
}Live demo - https://codesandbox.io/p/devbox/yet-another-react-lightbox-227-2q6qmp?file=%2Fsrc%2FPoll.tsx |
Beta Was this translation helpful? Give feedback.


Hi there!
Here are 2 modifications that you need to make:
childrenwith an extra<div>wrapper sinceyarl_containeruses absolute positioningAnd to make this solution compatible with #225, you can use the following conditional logic:
Live d…