Toolbar button order #102
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Thank you for posting this great question. As of today, there is no elegant way to change the order of buttons added through the import * as React from "react";
import { Lightbox, Plugin } from "yet-another-react-lightbox";
import { useLightboxState } from "yet-another-react-lightbox/core";
import Captions from "yet-another-react-lightbox/plugins/captions";
import Fullscreen from "yet-another-react-lightbox/plugins/fullscreen";
import { BiShareAlt } from "react-icons/bi";
function ShareButton({ onClick }: { onClick: (currentIndex: number) => void }) {
const { slides, currentIndex } = useLightboxState().state;
return (
<button
type="button"
className="yarl__button"
disabled={slides.length === 0}
onClick={() => onClick(currentIndex)}
>
<BiShareAlt className="p-1 yarl__icon" />
</button>
);
}
export default function Page() {
const [open, setOpen] = React.useState(false);
const onClick = (currentIndex: number) => {
// handle Share button click
};
const Share: Plugin = ({ augment }) => {
augment(({ toolbar: { buttons, ...restToolbar }, ...rest }) => ({
toolbar: { buttons: [<ShareButton key="share" onClick={onClick} />, ...buttons], ...restToolbar },
...rest,
}));
};
return (
<>
<Lightbox
open={open}
close={() => setOpen(false)}
slides={slides}
plugins={[Fullscreen, Captions, Share]}
/>
// ...
</>
);
} p.s. I've added a note to simplify this process in one of the future releases. |
Beta Was this translation helpful? Give feedback.
Thank you for posting this great question. As of today, there is no elegant way to change the order of buttons added through the
toolbar.buttons
prop and the ones added by plugins. Each plugin prepends its button to the beginning of thetoolbar.buttons
array, so you can easily re-arrange plugin buttons by changing the order of the plugins. However, plugin buttons would always appear to the left of the buttons you add through thetoolbar.buttons
prop, and the only way to change this is to add your own buttons via a custom plugin as well. Here is how you'd do it.