Skip to content

Commit ff5b5ac

Browse files
authored
docs(useLightbox): add hook docs and a gallery grid example block (#9752)
* docs(useLightbox): add hook docs and a gallery grid example block * fix(docs): remove template-blank from route lock and add LightboxHookUsage to sandbox routes * fix(docs): key LightboxHookUsage thumbnails by photo.alt
1 parent b5ce149 commit ff5b5ac

6 files changed

Lines changed: 263 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astryxdesign/core': patch
3+
'@astryxdesign/cli': patch
4+
---
5+
6+
[docs] Hook docs for `useLightbox`, so `astryx hook useLightbox` and `astryx search` return it, and a `useLightbox — Gallery Grid` example block: a grid of photo thumbnails that opens a fullscreen gallery at the clicked item.
7+
8+
@Geervan

‎apps/sandbox/scripts/next-export-routes.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
"/templates/LayoutShowcase/",
392392
"/templates/LayoutSidebarLayout/",
393393
"/templates/LightboxGallery/",
394+
"/templates/LightboxHookUsage/",
394395
"/templates/LightboxShowcase/",
395396
"/templates/LightboxVideo/",
396397
"/templates/LightboxZoom/",

‎internal/shadcn-registry/routes.lock.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,11 @@
36963696
"path": "examples/use-layer/anchored-layer",
36973697
"aliases": []
36983698
},
3699+
{
3700+
"name": "example-use-lightbox-gallery-grid",
3701+
"path": "examples/use-lightbox/gallery-grid",
3702+
"aliases": []
3703+
},
36993704
{
37003705
"name": "example-use-list-focus-recent-files",
37013706
"path": "examples/use-list-focus/recent-files",
@@ -3951,6 +3956,11 @@
39513956
"path": "hooks/use-layer",
39523957
"aliases": []
39533958
},
3959+
{
3960+
"name": "hook-use-lightbox",
3961+
"path": "hooks/use-lightbox",
3962+
"aliases": []
3963+
},
39543964
{
39553965
"name": "hook-use-list-focus",
39563966
"path": "hooks/use-list-focus",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4+
export const doc = {
5+
type: 'block',
6+
exampleFor: 'useLightbox',
7+
name: 'useLightbox — Gallery Grid',
8+
displayName: 'useLightbox — Gallery Grid',
9+
description:
10+
'Photo gallery thumbnail grid using useLightbox for trigger props, keyboard navigation, and open state.',
11+
isReady: true,
12+
aspectRatio: 4 / 3,
13+
componentsUsed: ['Lightbox', 'Grid'],
14+
};
15+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
'use client';
4+
5+
import {useLightbox} from '@astryxdesign/core/Lightbox';
6+
import {Grid} from '@astryxdesign/core/Grid';
7+
8+
const PHOTOS = [
9+
{
10+
src: '/template-assets/Neutral-Backpack.png',
11+
alt: 'Backpack',
12+
caption: 'Backpack on a neutral background',
13+
},
14+
{
15+
src: '/template-assets/Neutral-Blanket.png',
16+
alt: 'Blanket',
17+
caption: 'Cozy blanket on a neutral background',
18+
},
19+
{
20+
src: '/template-assets/Neutral-Headphones.png',
21+
alt: 'Headphones',
22+
caption: 'Wireless headphones on a neutral background',
23+
},
24+
{
25+
src: '/template-assets/Neutral-Tumbler.png',
26+
alt: 'Tumbler',
27+
caption: 'Stainless tumbler on a neutral background',
28+
},
29+
{
30+
src: '/template-assets/Neutral-Wallet.png',
31+
alt: 'Wallet',
32+
caption: 'Leather wallet on a neutral background',
33+
},
34+
{
35+
src: '/template-assets/Neutral-Watch.png',
36+
alt: 'Watch',
37+
caption: 'Wristwatch on a neutral background',
38+
},
39+
];
40+
41+
export default function LightboxHookUsage() {
42+
const lightbox = useLightbox({media: PHOTOS});
43+
44+
return (
45+
<>
46+
<Grid columns={3} gap={2} width={304}>
47+
{PHOTOS.map((photo, i) => (
48+
<img
49+
key={photo.alt}
50+
src={photo.src}
51+
alt={photo.alt}
52+
width={96}
53+
height={96}
54+
style={{objectFit: 'cover'}}
55+
{...lightbox.getTriggerProps(i)}
56+
/>
57+
))}
58+
</Grid>
59+
{lightbox.element}
60+
</>
61+
);
62+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/** @type {import('@astryxdesign/cli/authoring').HookDoc} */
4+
export const docs = {
5+
name: 'useLightbox',
6+
displayName: 'useLightbox',
7+
group: 'Lightbox',
8+
keywords: [
9+
'lightbox',
10+
'gallery',
11+
'viewer',
12+
'image',
13+
'video',
14+
'media',
15+
'modal',
16+
'overlay',
17+
'trigger',
18+
],
19+
params: [
20+
{
21+
name: 'options',
22+
type: 'UseLightboxOptions',
23+
description: 'Configuration options for the lightbox.',
24+
required: true,
25+
},
26+
{
27+
name: 'options.media',
28+
type: 'LightboxMedia | LightboxMedia[]',
29+
description:
30+
'Media to display in the lightbox. Pass a single object for one item, or an array for gallery mode.',
31+
required: true,
32+
},
33+
{
34+
name: 'options.hasZoom',
35+
type: 'boolean',
36+
description:
37+
'Enable zoom on double-click, or Enter/Space/+/- via keyboard (images only). When zoomed, drag or use arrow keys to pan.',
38+
default: 'false',
39+
required: false,
40+
},
41+
{
42+
name: 'options.hasAutoPlay',
43+
type: 'boolean',
44+
description: 'Whether video should autoplay when the lightbox opens.',
45+
default: 'false',
46+
required: false,
47+
},
48+
],
49+
returns: [
50+
{
51+
name: 'open',
52+
type: '(index?: number) => void',
53+
description:
54+
'Open the lightbox, optionally at a specific gallery index (defaults to 0).',
55+
},
56+
{
57+
name: 'close',
58+
type: '() => void',
59+
description: 'Close the lightbox.',
60+
},
61+
{
62+
name: 'isOpen',
63+
type: 'boolean',
64+
description: 'Whether the lightbox is currently open.',
65+
},
66+
{
67+
name: 'index',
68+
type: 'number',
69+
description: 'Current gallery index.',
70+
},
71+
{
72+
name: 'element',
73+
type: 'ReactNode',
74+
description:
75+
'Pre-wired Lightbox component element to render in your JSX tree.',
76+
},
77+
{
78+
name: 'triggerProps',
79+
type: "{role: 'button', tabIndex: 0, 'aria-haspopup': 'dialog', onClick: () => void, onKeyDown: (e: React.KeyboardEvent) => void}",
80+
description:
81+
'Props to spread onto a single trigger element to open the lightbox at index 0 on click, Enter, or Space.',
82+
},
83+
{
84+
name: 'getTriggerProps',
85+
type: "(index: number) => {role: 'button', tabIndex: 0, 'aria-haspopup': 'dialog', onClick: () => void, onKeyDown: (e: React.KeyboardEvent) => void}",
86+
description:
87+
'Returns trigger props to spread onto an element to open the lightbox at a specific gallery index on click, Enter, or Space.',
88+
},
89+
],
90+
usage: {
91+
description:
92+
'State management and accessible trigger wiring for Lightbox. Eliminates boilerplate for managing open state and current index. Returns trigger props with button role, tabIndex={0}, aria-haspopup="dialog", and keyboard activation handlers, along with a pre-wired Lightbox element that handles dismissal, next/previous navigation, and focus restoration.',
93+
bestPractices: [
94+
{
95+
guidance: true,
96+
description:
97+
'Spread getTriggerProps(index) onto image or thumbnail elements to give them accessible button semantics and keyboard activation.',
98+
},
99+
{
100+
guidance: true,
101+
description:
102+
'Render lightbox.element once in your component JSX tree alongside the triggers.',
103+
},
104+
{
105+
guidance: false,
106+
description:
107+
'Manage separate isOpen or index state alongside useLightbox; the hook already tracks both.',
108+
},
109+
{
110+
guidance: false,
111+
description:
112+
'Add custom click or keydown handlers to open the lightbox when using triggerProps or getTriggerProps.',
113+
},
114+
],
115+
},
116+
relatedComponents: ['Lightbox', 'Grid', 'Thumbnail'],
117+
relatedHooks: [],
118+
importPath: '@astryxdesign/core/Lightbox',
119+
category: 'interaction',
120+
};
121+
122+
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
123+
export const docsDense = {
124+
description:
125+
'State management and accessible trigger wiring for Lightbox. Eliminates boilerplate for open state and index. Returns trigger props and pre-wired Lightbox element.',
126+
paramDescriptions: {
127+
options: 'configuration options for the lightbox.',
128+
'options.media':
129+
'media to display (single item or array for gallery mode).',
130+
'options.hasZoom':
131+
'enable zoom on double-click or Enter/Space/+/- (images only).',
132+
'options.hasAutoPlay': 'whether video should autoplay when opened.',
133+
},
134+
returnDescriptions: {
135+
open: 'open the lightbox, optionally at a specific gallery index.',
136+
close: 'close the lightbox.',
137+
isOpen: 'whether the lightbox is currently open.',
138+
index: 'current gallery index.',
139+
element: 'pre-wired Lightbox element to render in JSX tree.',
140+
triggerProps:
141+
'trigger attributes to spread onto a single trigger element.',
142+
getTriggerProps:
143+
'(index) => props: returns trigger attributes for opening at index on click, Enter, or Space.',
144+
},
145+
usage: {
146+
description:
147+
'State management and trigger wiring for Lightbox. Returns trigger props and pre-wired element.',
148+
bestPractices: [
149+
{
150+
guidance: true,
151+
description:
152+
'Spread getTriggerProps(index) onto image elements for accessible button semantics.',
153+
},
154+
{
155+
guidance: true,
156+
description:
157+
'Render lightbox.element once in JSX alongside the triggers.',
158+
},
159+
{
160+
guidance: false,
161+
description:
162+
'Manage separate isOpen or index state alongside useLightbox.',
163+
},
164+
],
165+
},
166+
};
167+

0 commit comments

Comments
 (0)