Skip to content

Commit 54a7431

Browse files
committed
docs: add custom label example
1 parent 8ce1c9a commit 54a7431

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

docs/advanced.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,14 @@ augmentations are applied before the lightbox starts rendering.
140140

141141
For example, you can add a toolbar button using the following augmentation:
142142

143-
```tsx
144-
import { addToolbarButton, IconButton } from "yet-another-react-lightbox";
145-
146-
declare module "yet-another-react-lightbox" {
147-
interface Labels {
148-
"My button"?: string;
149-
}
150-
}
143+
```jsx
144+
import { addToolbarButton } from "yet-another-react-lightbox";
151145

152146
// ...
153147

154148
function MyPlugin({ augment }) {
155149
augment(({ toolbar, ...restProps }) => ({
156-
toolbar: addToolbarButton(
157-
toolbar,
158-
"my-button",
159-
<IconButton
160-
icon={MyIcon}
161-
label="My button"
162-
onClick={() => {
163-
// ...
164-
}}
165-
/>,
166-
),
150+
toolbar: addToolbarButton(toolbar, "my-button", <MyButton />),
167151
...restProps,
168152
}));
169153
}
@@ -317,21 +301,34 @@ const { containerRect, setContainerRef } = useContainerRect();
317301
You can create custom toolbar buttons by using the `IconButton` component and
318302
the `createIcon` helper function.
319303

320-
```jsx
304+
```tsx
321305
import {
322306
Lightbox,
323307
IconButton,
324308
createIcon,
325309
useLightboxState,
326310
} from "yet-another-react-lightbox";
327311

312+
declare module "yet-another-react-lightbox" {
313+
interface Labels {
314+
"My button"?: string;
315+
}
316+
}
317+
328318
const MyIcon = createIcon("MyIcon", <path d="..." />);
329319

330320
function MyButton() {
331321
const { currentSlide } = useLightboxState();
332322

333323
return (
334-
<IconButton label="My button" icon={MyIcon} disabled={!currentSlide} />
324+
<IconButton
325+
label="My button"
326+
icon={MyIcon}
327+
disabled={!currentSlide}
328+
onClic={() => {
329+
// ...
330+
}}
331+
/>
335332
);
336333
}
337334

0 commit comments

Comments
 (0)