|
| 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