@arshad-shah/cynosure 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/README.md +9 -8
  2. package/dist/components/Accordion/Accordion.d.ts +14 -0
  3. package/dist/components/Accordion/Accordion.js.map +1 -1
  4. package/dist/components/Announcer/Announcer.d.ts +1 -0
  5. package/dist/components/Announcer/Announcer.js.map +1 -1
  6. package/dist/components/AppShell/AppShell.d.ts +22 -1
  7. package/dist/components/AppShell/AppShell.js +95 -83
  8. package/dist/components/AppShell/AppShell.js.map +1 -1
  9. package/dist/components/AppShell/index.d.ts +1 -1
  10. package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
  11. package/dist/components/AspectRatio/AspectRatio.js +21 -0
  12. package/dist/components/AspectRatio/AspectRatio.js.map +1 -0
  13. package/dist/components/AspectRatio/index.d.ts +1 -0
  14. package/dist/components/Avatar/Avatar.d.ts +96 -0
  15. package/dist/components/Avatar/Avatar.js +90 -0
  16. package/dist/components/Avatar/Avatar.js.map +1 -0
  17. package/dist/components/Avatar/index.d.ts +1 -0
  18. package/dist/components/Badge/Badge.d.ts +6 -0
  19. package/dist/components/Badge/Badge.js.map +1 -1
  20. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +55 -0
  21. package/dist/components/Breadcrumbs/Breadcrumbs.js +85 -0
  22. package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -0
  23. package/dist/components/Breadcrumbs/index.d.ts +1 -0
  24. package/dist/components/Button/Button.d.ts +13 -2
  25. package/dist/components/Button/Button.js +28 -26
  26. package/dist/components/Button/Button.js.map +1 -1
  27. package/dist/components/Calendar/Calendar.d.ts +65 -7
  28. package/dist/components/Calendar/Calendar.js +207 -95
  29. package/dist/components/Calendar/Calendar.js.map +1 -1
  30. package/dist/components/Calendar/dates.d.ts +4 -0
  31. package/dist/components/Calendar/dates.js +41 -27
  32. package/dist/components/Calendar/dates.js.map +1 -1
  33. package/dist/components/Calendar/index.d.ts +1 -1
  34. package/dist/components/Card/Card.d.ts +27 -0
  35. package/dist/components/Card/Card.js +48 -36
  36. package/dist/components/Card/Card.js.map +1 -1
  37. package/dist/components/Card/index.d.ts +1 -1
  38. package/dist/components/Checkbox/Checkbox.d.ts +8 -1
  39. package/dist/components/Checkbox/Checkbox.js +7 -6
  40. package/dist/components/Checkbox/Checkbox.js.map +1 -1
  41. package/dist/components/Checkbox/ChoiceRow.d.ts +17 -1
  42. package/dist/components/Checkbox/ChoiceRow.js +19 -18
  43. package/dist/components/Checkbox/ChoiceRow.js.map +1 -1
  44. package/dist/components/Checklist/Checklist.d.ts +65 -0
  45. package/dist/components/Checklist/Checklist.js +163 -0
  46. package/dist/components/Checklist/Checklist.js.map +1 -0
  47. package/dist/components/Checklist/index.d.ts +1 -0
  48. package/dist/components/CodeBlock/CodeBlock.d.ts +5 -0
  49. package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
  50. package/dist/components/ColorField/ColorField.d.ts +12 -0
  51. package/dist/components/ColorField/ColorField.js +19 -19
  52. package/dist/components/ColorField/ColorField.js.map +1 -1
  53. package/dist/components/ColorSwatches/ColorSwatches.d.ts +5 -0
  54. package/dist/components/ColorSwatches/ColorSwatches.js +6 -6
  55. package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
  56. package/dist/components/Combobox/Combobox.d.ts +20 -1
  57. package/dist/components/Combobox/Combobox.js +38 -34
  58. package/dist/components/Combobox/Combobox.js.map +1 -1
  59. package/dist/components/CommandPalette/CommandPalette.d.ts +9 -0
  60. package/dist/components/CommandPalette/CommandPalette.js +10 -10
  61. package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
  62. package/dist/components/CompareSlider/CompareSlider.d.ts +4 -0
  63. package/dist/components/CompareSlider/CompareSlider.js +4 -4
  64. package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
  65. package/dist/components/Container/Container.d.ts +44 -0
  66. package/dist/components/Container/Container.js +24 -0
  67. package/dist/components/Container/Container.js.map +1 -0
  68. package/dist/components/Container/index.d.ts +1 -0
  69. package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
  70. package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
  71. package/dist/components/CopyButton/CopyButton.d.ts +8 -0
  72. package/dist/components/CopyButton/CopyButton.js.map +1 -1
  73. package/dist/components/DateField/DateField.d.ts +17 -0
  74. package/dist/components/DateField/DateField.js +6 -6
  75. package/dist/components/DateField/DateField.js.map +1 -1
  76. package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
  77. package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
  78. package/dist/components/Dialog/Dialog.d.ts +16 -2
  79. package/dist/components/Dialog/Dialog.js +82 -70
  80. package/dist/components/Dialog/Dialog.js.map +1 -1
  81. package/dist/components/Disclosure/Disclosure.d.ts +7 -0
  82. package/dist/components/Disclosure/Disclosure.js.map +1 -1
  83. package/dist/components/Divider/Divider.d.ts +59 -0
  84. package/dist/components/Divider/Divider.js +32 -0
  85. package/dist/components/Divider/Divider.js.map +1 -0
  86. package/dist/components/Divider/index.d.ts +1 -0
  87. package/dist/components/DocumentViewport/DocumentViewport.d.ts +8 -0
  88. package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
  89. package/dist/components/EmptyState/EmptyState.d.ts +3 -0
  90. package/dist/components/EmptyState/EmptyState.js.map +1 -1
  91. package/dist/components/Field/Field.d.ts +6 -0
  92. package/dist/components/Field/Field.js.map +1 -1
  93. package/dist/components/FileDrop/FileDrop.d.ts +8 -0
  94. package/dist/components/FileDrop/FileDrop.js.map +1 -1
  95. package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +4 -0
  96. package/dist/components/FloatingToolbar/FloatingToolbar.js +4 -4
  97. package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
  98. package/dist/components/Grid/Grid.d.ts +33 -7
  99. package/dist/components/Grid/Grid.js +46 -25
  100. package/dist/components/Grid/Grid.js.map +1 -1
  101. package/dist/components/Grid/index.d.ts +1 -1
  102. package/dist/components/Heading/Heading.d.ts +57 -0
  103. package/dist/components/Heading/Heading.js +33 -0
  104. package/dist/components/Heading/Heading.js.map +1 -0
  105. package/dist/components/Heading/index.d.ts +1 -0
  106. package/dist/components/HoverCard/HoverCard.d.ts +1 -0
  107. package/dist/components/HoverCard/HoverCard.js.map +1 -1
  108. package/dist/components/IconButton/IconButton.d.ts +1 -0
  109. package/dist/components/IconButton/IconButton.js.map +1 -1
  110. package/dist/components/Image/Image.d.ts +62 -0
  111. package/dist/components/Image/Image.js +75 -0
  112. package/dist/components/Image/Image.js.map +1 -0
  113. package/dist/components/Image/index.d.ts +1 -0
  114. package/dist/components/Inline/Inline.d.ts +7 -3
  115. package/dist/components/Inline/Inline.js +19 -13
  116. package/dist/components/Inline/Inline.js.map +1 -1
  117. package/dist/components/Kbd/Kbd.d.ts +2 -0
  118. package/dist/components/Kbd/Kbd.js.map +1 -1
  119. package/dist/components/KeyValueEditor/KeyValueEditor.d.ts +7 -0
  120. package/dist/components/KeyValueEditor/KeyValueEditor.js +8 -8
  121. package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
  122. package/dist/components/Link/Link.d.ts +7 -0
  123. package/dist/components/Link/Link.js.map +1 -1
  124. package/dist/components/LoadingDots/LoadingDots.d.ts +2 -0
  125. package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
  126. package/dist/components/Menu/Menu.d.ts +13 -1
  127. package/dist/components/Menu/Menu.js +37 -35
  128. package/dist/components/Menu/Menu.js.map +1 -1
  129. package/dist/components/Notice/Notice.d.ts +5 -0
  130. package/dist/components/Notice/Notice.js.map +1 -1
  131. package/dist/components/NumberField/NumberField.d.ts +17 -0
  132. package/dist/components/NumberField/NumberField.js +8 -8
  133. package/dist/components/NumberField/NumberField.js.map +1 -1
  134. package/dist/components/PageHeader/PageHeader.d.ts +61 -0
  135. package/dist/components/PageHeader/PageHeader.js +63 -0
  136. package/dist/components/PageHeader/PageHeader.js.map +1 -0
  137. package/dist/components/PageHeader/index.d.ts +1 -0
  138. package/dist/components/Pagination/Pagination.d.ts +77 -0
  139. package/dist/components/Pagination/Pagination.js +120 -0
  140. package/dist/components/Pagination/Pagination.js.map +1 -0
  141. package/dist/components/Pagination/index.d.ts +1 -0
  142. package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +4 -0
  143. package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
  144. package/dist/components/Popover/Popover.d.ts +10 -0
  145. package/dist/components/Popover/Popover.js.map +1 -1
  146. package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
  147. package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
  148. package/dist/components/ProgressOverlay/ProgressOverlay.d.ts +3 -0
  149. package/dist/components/ProgressOverlay/ProgressOverlay.js.map +1 -1
  150. package/dist/components/Prose/Prose.d.ts +1 -0
  151. package/dist/components/Prose/Prose.js.map +1 -1
  152. package/dist/components/RadioGroup/RadioGroup.d.ts +13 -0
  153. package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
  154. package/dist/components/SegmentedControl/SegmentedControl.d.ts +9 -0
  155. package/dist/components/SegmentedControl/SegmentedControl.js +35 -27
  156. package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
  157. package/dist/components/Select/Select.d.ts +18 -1
  158. package/dist/components/Select/Select.js +97 -88
  159. package/dist/components/Select/Select.js.map +1 -1
  160. package/dist/components/Select/index.d.ts +1 -0
  161. package/dist/components/SelectionFrame/SelectionFrame.d.ts +6 -0
  162. package/dist/components/SelectionFrame/SelectionFrame.js.map +1 -1
  163. package/dist/components/SideNav/SideNav.d.ts +37 -1
  164. package/dist/components/SideNav/SideNav.js +100 -73
  165. package/dist/components/SideNav/SideNav.js.map +1 -1
  166. package/dist/components/SideNav/index.d.ts +1 -1
  167. package/dist/components/SignaturePad/SignaturePad.d.ts +3 -0
  168. package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
  169. package/dist/components/Skeleton/Skeleton.d.ts +1 -0
  170. package/dist/components/Skeleton/Skeleton.js.map +1 -1
  171. package/dist/components/Slider/Slider.d.ts +11 -0
  172. package/dist/components/Slider/Slider.js +6 -6
  173. package/dist/components/Slider/Slider.js.map +1 -1
  174. package/dist/components/SortableList/SortableList.d.ts +6 -0
  175. package/dist/components/SortableList/SortableList.js.map +1 -1
  176. package/dist/components/SplitPane/SplitPane.d.ts +5 -0
  177. package/dist/components/SplitPane/SplitPane.js +4 -4
  178. package/dist/components/SplitPane/SplitPane.js.map +1 -1
  179. package/dist/components/Stack/Stack.d.ts +7 -3
  180. package/dist/components/Stack/Stack.js +18 -12
  181. package/dist/components/Stack/Stack.js.map +1 -1
  182. package/dist/components/Stack/index.d.ts +1 -0
  183. package/dist/components/Stack/space.d.ts +18 -0
  184. package/dist/components/Stack/space.js +12 -0
  185. package/dist/components/Stack/space.js.map +1 -0
  186. package/dist/components/Steps/Steps.d.ts +4 -0
  187. package/dist/components/Steps/Steps.js.map +1 -1
  188. package/dist/components/Table/Table.d.ts +12 -0
  189. package/dist/components/Table/Table.js.map +1 -1
  190. package/dist/components/Tabs/Tabs.d.ts +14 -0
  191. package/dist/components/Tabs/Tabs.js +4 -4
  192. package/dist/components/Tabs/Tabs.js.map +1 -1
  193. package/dist/components/TagInput/TagInput.d.ts +18 -0
  194. package/dist/components/TagInput/TagInput.js +5 -5
  195. package/dist/components/TagInput/TagInput.js.map +1 -1
  196. package/dist/components/Text/Text.d.ts +72 -0
  197. package/dist/components/Text/Text.js +30 -0
  198. package/dist/components/Text/Text.js.map +1 -0
  199. package/dist/components/Text/index.d.ts +1 -0
  200. package/dist/components/TextArea/TextArea.d.ts +10 -0
  201. package/dist/components/TextArea/TextArea.js +4 -4
  202. package/dist/components/TextArea/TextArea.js.map +1 -1
  203. package/dist/components/TextField/TextField.d.ts +13 -0
  204. package/dist/components/TextField/TextField.js +4 -4
  205. package/dist/components/TextField/TextField.js.map +1 -1
  206. package/dist/components/ThemeToggle/ThemeToggle.d.ts +4 -0
  207. package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
  208. package/dist/components/TimeField/TimeField.d.ts +62 -8
  209. package/dist/components/TimeField/TimeField.js +308 -72
  210. package/dist/components/TimeField/TimeField.js.map +1 -1
  211. package/dist/components/Toast/Toast.d.ts +25 -1
  212. package/dist/components/Toast/Toast.js +134 -125
  213. package/dist/components/Toast/Toast.js.map +1 -1
  214. package/dist/components/Toast/index.d.ts +1 -1
  215. package/dist/components/Toolbar/Toolbar.d.ts +3 -0
  216. package/dist/components/Toolbar/Toolbar.js.map +1 -1
  217. package/dist/components/Tooltip/Tooltip.d.ts +1 -0
  218. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  219. package/dist/components/Tree/Tree.d.ts +8 -0
  220. package/dist/components/Tree/Tree.js.map +1 -1
  221. package/dist/components/VirtualList/VirtualList.d.ts +8 -0
  222. package/dist/components/VirtualList/VirtualList.js +4 -4
  223. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  224. package/dist/components/ZoomControls/ZoomControls.d.ts +4 -0
  225. package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
  226. package/dist/foundations/ChoiceBase/ChoiceBase.d.ts +1 -0
  227. package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
  228. package/dist/foundations/HiddenValue/HiddenValue.d.ts +3 -0
  229. package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
  230. package/dist/foundations/Icon/Icon.d.ts +3 -0
  231. package/dist/foundations/Icon/Icon.js.map +1 -1
  232. package/dist/foundations/image-outcome.d.ts +15 -0
  233. package/dist/foundations/image-outcome.js +39 -0
  234. package/dist/foundations/image-outcome.js.map +1 -0
  235. package/dist/foundations/option-icon.d.ts +26 -0
  236. package/dist/foundations/option-icon.js +16 -0
  237. package/dist/foundations/option-icon.js.map +1 -0
  238. package/dist/icons/index.d.ts +1 -0
  239. package/dist/icons/index.js +476 -474
  240. package/dist/icons/keywords.d.ts +249 -0
  241. package/dist/icons/keywords.js +1728 -0
  242. package/dist/icons/keywords.js.map +1 -0
  243. package/dist/index.d.ts +20 -9
  244. package/dist/index.js +240 -213
  245. package/dist/styles/app-shell.css +1 -1
  246. package/dist/styles/aspect-ratio.css +1 -0
  247. package/dist/styles/avatar.css +1 -0
  248. package/dist/styles/breadcrumbs.css +1 -0
  249. package/dist/styles/calendar.css +1 -1
  250. package/dist/styles/card.css +1 -1
  251. package/dist/styles/checkbox.css +1 -1
  252. package/dist/styles/checklist.css +1 -0
  253. package/dist/styles/container.css +1 -0
  254. package/dist/styles/divider.css +1 -0
  255. package/dist/styles/generated-css.d.ts +1 -1
  256. package/dist/styles/generated-css.js +1 -1
  257. package/dist/styles/generated-css.js.map +1 -1
  258. package/dist/styles/grid.css +1 -1
  259. package/dist/styles/heading.css +1 -0
  260. package/dist/styles/image.css +1 -0
  261. package/dist/styles/menu.css +1 -1
  262. package/dist/styles/page-header.css +1 -0
  263. package/dist/styles/pagination.css +1 -0
  264. package/dist/styles/segmented-control.css +1 -1
  265. package/dist/styles/side-nav.css +1 -1
  266. package/dist/styles/stack.css +1 -1
  267. package/dist/styles/text.css +1 -0
  268. package/dist/styles/time-field.css +1 -1
  269. package/dist/styles/toast.css +1 -1
  270. package/dist/styles.css +1 -1
  271. package/dist/theme/CynosureTheme.d.ts +4 -0
  272. package/dist/theme/CynosureTheme.js.map +1 -1
  273. package/dist/tokens/to-css.js +12 -12
  274. package/dist/tokens/to-css.js.map +1 -1
  275. package/package.json +4 -3
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Cynosure
4
4
 
5
- One small, themeable, accessible UI system for every Arshad Shah product: browser extensions, web apps and sites. Same feel and layout everywhere; each product sets its accent, its scale and any token it needs.
5
+ One small, themeable, accessible UI system, used by all my projects: browser extensions, web apps and sites. Same feel and layout everywhere; each project sets its accent, its scale and any token it needs.
6
6
 
7
7
  - **Tiny and tree-shaken**: one module per component and icon, and one small runtime dependency ([Detent](https://github.com/arshad-shah/detent), for dragging).
8
8
  - **Looks identical anywhere**: pages, iframes, extension popups and shadow roots; host CSS can't break it.
@@ -31,7 +31,7 @@ export const App = () => (
31
31
  );
32
32
  ```
33
33
 
34
- **Storybook:** https://cynosure.arshadshah.com/storybook/ (every component with live examples, its props and its keyboard behaviour).
34
+ **Documentation:** https://cynosure.arshadshah.com (every component with live examples, its props and its keyboard behaviour).
35
35
 
36
36
  ## Docs
37
37
 
@@ -39,6 +39,7 @@ export const App = () => (
39
39
  | -------------------------------------------------------------- | ------------------------------------------------------------------ |
40
40
  | [Theming](docs/theming.md) | Accent, scale, radius, fonts, light and dark, per-component tokens |
41
41
  | [Icons](docs/icons.md) | Facet icons, brand marks and how brands allow them to be used |
42
+ | [Accessibility](docs/accessibility.md) | What every component guarantees, and how it is tested |
42
43
  | [Without React](docs/without-react.md) | Tokens and icons in Astro pages, static sites and plain TypeScript |
43
44
  | [Code editors](docs/code-editors.md) | Code colours for CodeMirror, Monaco, Shiki, Prism and highlight.js |
44
45
  | [Build adapters](docs/adapters.md) | The Vite adapter and shadow roots (`styles.inline`) |
@@ -50,11 +51,11 @@ export const App = () => (
50
51
 
51
52
  ## Components
52
53
 
53
- **Foundations:** ButtonBase, LinkBase, InputBase, FileInputBase, TextAreaBase, ChoiceBase, HiddenValue, DialogBase, Icon (240 Facet icons and 97 brand marks); hooks `useRovingFocus`, `useDismiss`, `useDrag` (pointer dragging through Detent), `useControllableState`.
54
- **Controls:** Button, IconButton, CopyButton, Link, TextField, NumberField, SearchField, TextArea, Select, Combobox, TagInput, Checkbox, Switch, RadioGroup, SegmentedControl, Slider, DateField, TimeField, ColorField, ColorSwatches, KeyValueEditor, FileDrop, SignaturePad, SelectionFrame, CompareSlider, ThemeToggle.
55
- **Structure:** AppShell, Stack, Inline, Grid, SideNav, SplitPane, Card, Toolbar, Tabs, Disclosure, Accordion, Tree, SortableList, VirtualList, Calendar, DocumentViewport, PanZoomCanvas, ZoomControls.
56
- **Overlays:** Tooltip, HoverCard, Popover, FloatingToolbar (`DockedToolbar`), Menu, ContextMenu, Dialog, ProgressOverlay, Sheet, CommandPalette (`useHotkey`), Toast (`Toaster`, `useToast`).
57
- **Feedback and display:** Notice, EmptyState, ProgressBar, Steps, LoadingDots, Skeleton, DescriptionList, Table, Prose, CodeBlock, Announcer (`useAnnounce`), Badge, Kbd, Field. **Theme:** CynosureTheme, useColorMode, themeInitScript, createTheme.
58
- **Build:** optional Vite adapter (`@arshad-shah/cynosure/vite`), React-free tokens (`@arshad-shah/cynosure/tokens`) and self-hosted Hanken Grotesk (`fonts/hanken.css`).
54
+ - **Foundations:** ButtonBase, LinkBase, InputBase, FileInputBase, TextAreaBase, ChoiceBase, HiddenValue, DialogBase, Icon (240 Facet icons and 97 brand marks); hooks `useRovingFocus`, `useDismiss`, `useDrag` (pointer dragging through Detent), `useControllableState`.
55
+ - **Controls:** Button, IconButton, CopyButton, Link, TextField, NumberField, SearchField, TextArea, Select, Combobox, TagInput, Checkbox, Switch, RadioGroup, SegmentedControl, Slider, DateField, TimeField, Checklist, Pagination, ColorField, ColorSwatches, KeyValueEditor, FileDrop, SignaturePad, SelectionFrame, CompareSlider, ThemeToggle.
56
+ - **Structure:** AppShell (`useAppShell`), Container, PageHeader, Stack, Inline, Grid, Divider, AspectRatio, Breadcrumbs, SideNav, SplitPane, Card, Toolbar, Tabs, Disclosure, Accordion, Tree, SortableList, VirtualList, Calendar, DocumentViewport, PanZoomCanvas, ZoomControls.
57
+ - **Overlays:** Tooltip, HoverCard, Popover, FloatingToolbar (`DockedToolbar`), Menu, ContextMenu, Dialog, ProgressOverlay, Sheet, CommandPalette (`useHotkey`), Toast (`Toaster`, `useToast`).
58
+ - **Feedback and display:** Notice, EmptyState, ProgressBar, Steps, LoadingDots, Skeleton, DescriptionList, Table, Text, Heading, Prose, Avatar (`AvatarGroup`), Image, CodeBlock, Announcer (`useAnnounce`), Badge, Kbd, Field. **Theme:** CynosureTheme, useColorMode, themeInitScript, createTheme.
59
+ - **Build:** optional Vite adapter (`@arshad-shah/cynosure/vite`), React-free tokens (`@arshad-shah/cynosure/tokens`) and self-hosted Hanken Grotesk (`fonts/hanken.css`).
59
60
 
60
61
  > Status: pre-release (`0.x`), developed on `next`. Releases publish to npm from `main` through GitHub Actions (see [Release](docs/release.md)).
@@ -1,22 +1,29 @@
1
1
  import { type CSSProperties, type ReactNode } from "react";
2
2
  import type { Size } from "../../tokens/schema.js";
3
3
  interface Shared {
4
+ /** `plain` no chrome, `line` a divider under each section, `card` bordered surfaces. Default "line". */
4
5
  variant?: "plain" | "line" | "card";
6
+ /** Size of every section's header and content. Default "md". */
5
7
  size?: Size;
6
8
  /** Heading level wrapping each header (default 3). */
7
9
  headingLevel?: 2 | 3 | 4 | 5 | 6;
8
10
  /** Expose each open section as a labelled region. Turn off for long lists (more than about six sections). */
9
11
  regions?: boolean;
12
+ /** Added to the root element, for layout. */
10
13
  className?: string;
11
14
  /** Layout only. */
12
15
  style?: CSSProperties;
16
+ /** The sections: one `AccordionItem` each. */
13
17
  children?: ReactNode;
14
18
  }
15
19
  export interface AccordionSingleProps extends Shared {
16
20
  /** One section open at a time. */
17
21
  type?: "single";
22
+ /** Controlled: the `value` of the open section, or undefined for none. */
18
23
  value?: string | undefined;
24
+ /** The section open at first, when uncontrolled. */
19
25
  defaultValue?: string;
26
+ /** Called when a section opens or closes, with the open section's `value` (undefined when none is open). */
20
27
  onValueChange?: (value: string | undefined) => void;
21
28
  /** The open section can be closed, leaving none open. */
22
29
  collapsible?: boolean;
@@ -24,17 +31,24 @@ export interface AccordionSingleProps extends Shared {
24
31
  export interface AccordionMultipleProps extends Shared {
25
32
  /** Any number of sections open. */
26
33
  type: "multiple";
34
+ /** Controlled: the `value` of every open section. */
27
35
  value?: string[];
36
+ /** The sections open at first, when uncontrolled. */
28
37
  defaultValue?: string[];
38
+ /** Called when a section opens or closes, with the `value` of every open section. */
29
39
  onValueChange?: (value: string[]) => void;
40
+ /** Not used here: with `type="multiple"` every section can always be closed. */
30
41
  collapsible?: never;
31
42
  }
32
43
  export type AccordionProps = AccordionSingleProps | AccordionMultipleProps;
33
44
  /** Stacked Disclosures with shared state: single or multiple open, collapsible, arrow keys between headers. */
34
45
  export declare function Accordion(props: AccordionProps): import("react").JSX.Element;
35
46
  export interface AccordionItemProps {
47
+ /** Identifies the section in the Accordion's `value`. Unique among its items. */
36
48
  value: string;
49
+ /** The header: what people press to open or close the section. */
37
50
  summary: ReactNode;
51
+ /** The section's content, shown while it is open. */
38
52
  children?: ReactNode;
39
53
  }
40
54
  export declare function AccordionItem({ value, summary, children }: AccordionItemProps): import("react").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"Accordion.js","names":["useControllableState","Disclosure","createContext","useContext","jsx","Context","Accordion","props","variant","size","headingLevel","regions","className","style","children","multiple","asList","v","open","commit","next","collapsible","ctx","x","moveFocus","event","root","triggers","t","at","last","AccordionItem","value","summary"],"sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["import { type CSSProperties, createContext, type KeyboardEvent, type ReactNode, useContext } from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Disclosure } from \"../Disclosure/Disclosure.js\";\n\ninterface Shared {\n variant?: \"plain\" | \"line\" | \"card\";\n size?: Size;\n /** Heading level wrapping each header (default 3). */\n headingLevel?: 2 | 3 | 4 | 5 | 6;\n /** Expose each open section as a labelled region. Turn off for long lists (more than about six sections). */\n regions?: boolean;\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n children?: ReactNode;\n}\n\nexport interface AccordionSingleProps extends Shared {\n /** One section open at a time. */\n type?: \"single\";\n value?: string | undefined;\n defaultValue?: string;\n onValueChange?: (value: string | undefined) => void;\n /** The open section can be closed, leaving none open. */\n collapsible?: boolean;\n}\n\nexport interface AccordionMultipleProps extends Shared {\n /** Any number of sections open. */\n type: \"multiple\";\n value?: string[];\n defaultValue?: string[];\n onValueChange?: (value: string[]) => void;\n collapsible?: never;\n}\n\nexport type AccordionProps = AccordionSingleProps | AccordionMultipleProps;\n\ninterface Ctx {\n isOpen: (value: string) => boolean;\n toggle: (value: string) => void;\n locked: (value: string) => boolean;\n variant: \"plain\" | \"line\" | \"card\";\n size: Size;\n headingLevel: 2 | 3 | 4 | 5 | 6;\n regions: boolean;\n}\n\nconst Context = createContext<Ctx | null>(null);\n\n/** Stacked Disclosures with shared state: single or multiple open, collapsible, arrow keys between headers. */\nexport function Accordion(props: AccordionProps) {\n const {\n variant = \"line\",\n size = \"md\",\n headingLevel = 3,\n regions = true,\n className,\n style,\n children,\n } = props;\n const multiple = props.type === \"multiple\";\n // Single mode holds one value (or none); both modes are kept as a list here.\n const asList = (v: string | string[] | undefined) =>\n v === undefined ? undefined : Array.isArray(v) ? v : [v];\n const [open, commit] = useControllableState<string[]>(\n asList(props.value),\n () => asList(props.defaultValue) ?? [],\n (next) =>\n multiple\n ? (props as AccordionMultipleProps).onValueChange?.(next)\n : (props as AccordionSingleProps).onValueChange?.(next[0]),\n );\n const collapsible = !multiple && (props as AccordionSingleProps).collapsible === true;\n\n const ctx: Ctx = {\n isOpen: (v) => open.includes(v),\n locked: (v) => !multiple && !collapsible && open.includes(v),\n toggle: (v) => {\n if (multiple) commit(open.includes(v) ? open.filter((x) => x !== v) : [...open, v]);\n else if (open.includes(v)) {\n if (collapsible) commit([]);\n } else commit([v]);\n },\n variant,\n size,\n headingLevel,\n regions,\n };\n return (\n <Context.Provider value={ctx}>\n <div\n className={className ? `cy-accordion ${className}` : \"cy-accordion\"}\n data-variant={variant}\n style={style}\n >\n {children}\n </div>\n </Context.Provider>\n );\n}\n\n/** APG: Up and Down move between headers (wrapping), Home and End jump. Headers stay ordinary Tab stops. */\nfunction moveFocus(event: KeyboardEvent<HTMLButtonElement>) {\n const keys = [\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n if (!keys.includes(event.key)) return;\n const root = event.currentTarget.closest(\".cy-accordion\");\n if (!root) return;\n const triggers = [...root.querySelectorAll<HTMLButtonElement>(\".cy-disclosure-trigger\")].filter(\n (t) => t.closest(\".cy-accordion\") === root && !t.disabled,\n );\n const at = triggers.indexOf(event.currentTarget);\n const last = triggers.length - 1;\n const next =\n event.key === \"Home\"\n ? 0\n : event.key === \"End\"\n ? last\n : event.key === \"ArrowDown\"\n ? (at + 1) % triggers.length\n : (at - 1 + triggers.length) % triggers.length;\n event.preventDefault();\n triggers[next]?.focus();\n}\n\nexport interface AccordionItemProps {\n value: string;\n summary: ReactNode;\n children?: ReactNode;\n}\n\nexport function AccordionItem({ value, summary, children }: AccordionItemProps) {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"<AccordionItem> must be inside <Accordion>\");\n return (\n <Disclosure\n summary={summary}\n open={ctx.isOpen(value)}\n onOpenChange={() => ctx.toggle(value)}\n locked={ctx.locked(value)}\n variant={ctx.variant}\n size={ctx.size}\n headingLevel={ctx.headingLevel}\n region={ctx.regions}\n onTriggerKeyDown={moveFocus}\n >\n {children}\n </Disclosure>\n );\n}\n"],"mappings":";;;;;AAiDA,IAAMK,IAAUH,EAA0B,IAAI;AAG9C,SAAgBI,EAAUC,GAAuB;AAC/C,QAAM,EACJ,SAAAC,IAAU,QACV,MAAAC,IAAO,MACP,cAAAC,IAAe,GACf,SAAAC,IAAU,IACV,WAAAC,GACA,OAAAC,GACA,UAAAC,EAAA,IACEP,GACEQ,IAAWR,EAAM,SAAS,YAE1BS,IAAA,CAAUC,MACdA,MAAM,SAAY,SAAY,MAAM,QAAQA,CAAC,IAAIA,IAAI,CAACA,CAAC,GACnD,CAACC,GAAMC,CAAA,IAAUnB,EACrBgB,EAAOT,EAAM,KAAK,GAAA,MACZS,EAAOT,EAAM,YAAY,KAAK,CAAC,GAAA,CACpCa,MACCL,IACKR,EAAiC,gBAAgBa,CAAI,IACrDb,EAA+B,gBAAgBa,EAAK,CAAA,CAAE,CAC/D,GACMC,IAAc,CAACN,KAAaR,EAA+B,gBAAgB,IAE3Ee,IAAW;AAAA,IACf,QAAA,CAASL,MAAMC,EAAK,SAASD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AAF,EAAM,eAAe,GACrBE,EAASP,CAAA,GAAO,MAAM;AACxB;AAQA,SAAgBW,EAAc,EAAE,OAAAC,GAAO,SAAAC,GAAS,UAAAnB,EAAA,GAAgC;AAC9E,QAAMQ,IAAMnB,EAAWE,CAAO;AAC9B,MAAI,CAACiB,EAAK,OAAM,IAAI,MAAM,4CAA4C;AACtE,SACE,gBAAAlB,EAACH,GAAD;AAAA,IACW,SAAAgC;AAAA,IACT,MAAMX,EAAI,OAAOU,CAAK;AAAA,IACtB,cAAA,MAAoBV,EAAI,OAAOU,CAAK;AAAA,IACpC,QAAQV,EAAI,OAAOU,CAAK;AAAA,IACxB,SAASV,EAAI;AAAA,IACb,MAAMA,EAAI;AAAA,IACV,cAAcA,EAAI;AAAA,IAClB,QAAQA,EAAI;AAAA,IACZ,kBAAkBE;AAAA,IAEjB,UAAAV;AAAA,EACS,CAAA;AAEhB"}
1
+ {"version":3,"file":"Accordion.js","names":["useControllableState","Disclosure","createContext","useContext","jsx","Context","Accordion","props","variant","size","headingLevel","regions","className","style","children","multiple","asList","v","open","commit","next","collapsible","ctx","x","moveFocus","event","root","triggers","t","at","last","AccordionItem","value","summary"],"sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["import { type CSSProperties, createContext, type KeyboardEvent, type ReactNode, useContext } from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Disclosure } from \"../Disclosure/Disclosure.js\";\n\ninterface Shared {\n /** `plain` no chrome, `line` a divider under each section, `card` bordered surfaces. Default \"line\". */\n variant?: \"plain\" | \"line\" | \"card\";\n /** Size of every section's header and content. Default \"md\". */\n size?: Size;\n /** Heading level wrapping each header (default 3). */\n headingLevel?: 2 | 3 | 4 | 5 | 6;\n /** Expose each open section as a labelled region. Turn off for long lists (more than about six sections). */\n regions?: boolean;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The sections: one `AccordionItem` each. */\n children?: ReactNode;\n}\n\nexport interface AccordionSingleProps extends Shared {\n /** One section open at a time. */\n type?: \"single\";\n /** Controlled: the `value` of the open section, or undefined for none. */\n value?: string | undefined;\n /** The section open at first, when uncontrolled. */\n defaultValue?: string;\n /** Called when a section opens or closes, with the open section's `value` (undefined when none is open). */\n onValueChange?: (value: string | undefined) => void;\n /** The open section can be closed, leaving none open. */\n collapsible?: boolean;\n}\n\nexport interface AccordionMultipleProps extends Shared {\n /** Any number of sections open. */\n type: \"multiple\";\n /** Controlled: the `value` of every open section. */\n value?: string[];\n /** The sections open at first, when uncontrolled. */\n defaultValue?: string[];\n /** Called when a section opens or closes, with the `value` of every open section. */\n onValueChange?: (value: string[]) => void;\n /** Not used here: with `type=\"multiple\"` every section can always be closed. */\n collapsible?: never;\n}\n\nexport type AccordionProps = AccordionSingleProps | AccordionMultipleProps;\n\ninterface Ctx {\n isOpen: (value: string) => boolean;\n toggle: (value: string) => void;\n locked: (value: string) => boolean;\n variant: \"plain\" | \"line\" | \"card\";\n size: Size;\n headingLevel: 2 | 3 | 4 | 5 | 6;\n regions: boolean;\n}\n\nconst Context = createContext<Ctx | null>(null);\n\n/** Stacked Disclosures with shared state: single or multiple open, collapsible, arrow keys between headers. */\nexport function Accordion(props: AccordionProps) {\n const {\n variant = \"line\",\n size = \"md\",\n headingLevel = 3,\n regions = true,\n className,\n style,\n children,\n } = props;\n const multiple = props.type === \"multiple\";\n // Single mode holds one value (or none); both modes are kept as a list here.\n const asList = (v: string | string[] | undefined) =>\n v === undefined ? undefined : Array.isArray(v) ? v : [v];\n const [open, commit] = useControllableState<string[]>(\n asList(props.value),\n () => asList(props.defaultValue) ?? [],\n (next) =>\n multiple\n ? (props as AccordionMultipleProps).onValueChange?.(next)\n : (props as AccordionSingleProps).onValueChange?.(next[0]),\n );\n const collapsible = !multiple && (props as AccordionSingleProps).collapsible === true;\n\n const ctx: Ctx = {\n isOpen: (v) => open.includes(v),\n locked: (v) => !multiple && !collapsible && open.includes(v),\n toggle: (v) => {\n if (multiple) commit(open.includes(v) ? open.filter((x) => x !== v) : [...open, v]);\n else if (open.includes(v)) {\n if (collapsible) commit([]);\n } else commit([v]);\n },\n variant,\n size,\n headingLevel,\n regions,\n };\n return (\n <Context.Provider value={ctx}>\n <div\n className={className ? `cy-accordion ${className}` : \"cy-accordion\"}\n data-variant={variant}\n style={style}\n >\n {children}\n </div>\n </Context.Provider>\n );\n}\n\n/** APG: Up and Down move between headers (wrapping), Home and End jump. Headers stay ordinary Tab stops. */\nfunction moveFocus(event: KeyboardEvent<HTMLButtonElement>) {\n const keys = [\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n if (!keys.includes(event.key)) return;\n const root = event.currentTarget.closest(\".cy-accordion\");\n if (!root) return;\n const triggers = [...root.querySelectorAll<HTMLButtonElement>(\".cy-disclosure-trigger\")].filter(\n (t) => t.closest(\".cy-accordion\") === root && !t.disabled,\n );\n const at = triggers.indexOf(event.currentTarget);\n const last = triggers.length - 1;\n const next =\n event.key === \"Home\"\n ? 0\n : event.key === \"End\"\n ? last\n : event.key === \"ArrowDown\"\n ? (at + 1) % triggers.length\n : (at - 1 + triggers.length) % triggers.length;\n event.preventDefault();\n triggers[next]?.focus();\n}\n\nexport interface AccordionItemProps {\n /** Identifies the section in the Accordion's `value`. Unique among its items. */\n value: string;\n /** The header: what people press to open or close the section. */\n summary: ReactNode;\n /** The section's content, shown while it is open. */\n children?: ReactNode;\n}\n\nexport function AccordionItem({ value, summary, children }: AccordionItemProps) {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"<AccordionItem> must be inside <Accordion>\");\n return (\n <Disclosure\n summary={summary}\n open={ctx.isOpen(value)}\n onOpenChange={() => ctx.toggle(value)}\n locked={ctx.locked(value)}\n variant={ctx.variant}\n size={ctx.size}\n headingLevel={ctx.headingLevel}\n region={ctx.regions}\n onTriggerKeyDown={moveFocus}\n >\n {children}\n </Disclosure>\n );\n}\n"],"mappings":";;;;;AA4DA,IAAMK,IAAU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A,IACE,CAAA;AAAA,EACW,CAAA;AAEtB;AAGA,SAASU,EAAUC,GAAyC;AAE1D,MAAI,CAAC;AAAA,IADS;AAAA,IAAa;AAAA,IAAW;AAAA,IAAQ;AAAA,EACzC,EAAK,SAASA,EAAM,GAAG,EAAG;AAC/B,QAAMC,IAAOD,EAAM,cAAc,QAAQ,eAAe;AACxD,MAAI,CAACC,EAAM;AACX,QAAMC,IAAW,CAAC,GAAGD,EAAK,iBAAoC,wBAAwB,CAAC,EAAE,OAAA,CACtFE,MAAMA,EAAE,QAAQ,eAAe,MAAMF,KAAQ,CAACE,EAAE,QACnD,GACMC,IAAKF,EAAS,QAAQF,EAAM,aAAa,GACzCK,IAAOH,EAAS,SAAS,GACzBP,IACJK,EAAM,QAAQ,SACV,IACAA,EAAM,QAAQ,QACZK,IACAL,EAAM,QAAQ,eACXI,IAAK,KAAKF,EAAS,UACnBE,IAAK,IAAIF,EAAS,UAAUA,EAAS;AAChD,EAAAF,EAAM,eAAe,GACrBE,EAASP,CAAA,GAAO,MAAM;AACxB;AAWA,SAAgBW,EAAc,EAAE,OAAAC,GAAO,SAAAC,GAAS,UAAAnB,EAAA,GAAgC;AAC9E,QAAMQ,IAAMnB,EAAWE,CAAO;AAC9B,MAAI,CAACiB,EAAK,OAAM,IAAI,MAAM,4CAA4C;AACtE,SACE,gBAAAlB,EAACH,GAAD;AAAA,IACW,SAAAgC;AAAA,IACT,MAAMX,EAAI,OAAOU,CAAK;AAAA,IACtB,cAAA,MAAoBV,EAAI,OAAOU,CAAK;AAAA,IACpC,QAAQV,EAAI,OAAOU,CAAK;AAAA,IACxB,SAASV,EAAI;AAAA,IACb,MAAMA,EAAI;AAAA,IACV,cAAcA,EAAI;AAAA,IAClB,QAAQA,EAAI;AAAA,IACZ,kBAAkBE;AAAA,IAEjB,UAAAV;AAAA,EACS,CAAA;AAEhB"}
@@ -8,6 +8,7 @@ export type Announce = (message: string, options?: AnnounceOptions) => void;
8
8
  export interface AnnouncerProps {
9
9
  /** Milliseconds before an announcement is cleared from the hidden region. Default: 5000. */
10
10
  clearAfter?: number;
11
+ /** Your app. Anything inside can announce through `useAnnounce()`. */
11
12
  children?: ReactNode;
12
13
  }
13
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Announcer.js","names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","jsx","jsxs","AnnounceContext","warned","Announcer","clearAfter","children","polite","setPolite","assertive","setAssertive","timers","announce","message","options","politeness","set","said","pending","useAnnounce"],"sources":["../../../src/components/Announcer/Announcer.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nexport type Politeness = \"polite\" | \"assertive\";\n\nexport interface AnnounceOptions {\n /** `polite` (default) waits for the screen reader to finish; `assertive` interrupts. Keep assertive for errors. */\n politeness?: Politeness;\n}\n\nexport type Announce = (message: string, options?: AnnounceOptions) => void;\n\nexport interface AnnouncerProps {\n /** Milliseconds before an announcement is cleared from the hidden region. Default: 5000. */\n clearAfter?: number;\n children?: ReactNode;\n}\n\ninterface Said {\n text: string;\n /** Changes on every announcement, so the same text twice is a new node and is read again. */\n n: number;\n}\n\nconst AnnounceContext = createContext<Announce | null>(null);\nlet warned = false;\n\n/**\n * Hidden live regions for screen reader announcements, rendered where you put it (inside your app, never in `<body>`).\n * Render one near the root; `useAnnounce()` below it speaks through it.\n */\nexport function Announcer({ clearAfter = 5000, children }: AnnouncerProps) {\n const [polite, setPolite] = useState<Said>({ text: \"\", n: 0 });\n const [assertive, setAssertive] = useState<Said>({ text: \"\", n: 0 });\n const timers = useRef<Partial<Record<Politeness, ReturnType<typeof setTimeout>>>>({});\n\n const announce = useCallback<Announce>(\n (message, options) => {\n const politeness = options?.politeness ?? \"polite\";\n const set = politeness === \"assertive\" ? setAssertive : setPolite;\n set((said) => ({ text: message, n: said.n + 1 }));\n clearTimeout(timers.current[politeness]);\n timers.current[politeness] = setTimeout(() => set((said) => ({ ...said, text: \"\" })), clearAfter);\n },\n [clearAfter],\n );\n\n useEffect(() => {\n const pending = timers.current;\n return () => {\n clearTimeout(pending.polite);\n clearTimeout(pending.assertive);\n };\n }, []);\n\n return (\n <AnnounceContext.Provider value={announce}>\n {children}\n <div className=\"cy-announcer\">\n <div className=\"cy-announcer-region cy-reset\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n {polite.text && <span key={polite.n}>{polite.text}</span>}\n </div>\n <div className=\"cy-announcer-region cy-reset\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n {assertive.text && <span key={assertive.n}>{assertive.text}</span>}\n </div>\n </div>\n </AnnounceContext.Provider>\n );\n}\n\n/** Returns `announce(message, { politeness })`, spoken through the nearest `<Announcer>`. */\nexport function useAnnounce(): Announce {\n const announce = useContext(AnnounceContext);\n return useMemo(\n () =>\n announce ??\n (() => {\n if (warned) return;\n warned = true;\n console.warn(\"Cynosure: useAnnounce() needs an <Announcer> above it; nothing was announced.\");\n }),\n [announce],\n );\n}\n"],"mappings":";;;AAgCA,IAAMS,IAAkBT,EAA+B,IAAI,GACvDU,IAAS;AAMb,SAAgBC,EAAU,EAAE,YAAAC,IAAa,KAAM,UAAAC,EAAA,GAA4B;AACzE,QAAM,CAACC,GAAQC,CAAA,IAAaT,EAAe;AAAA,IAAE,MAAM;AAAA,IAAI,GAAG;AAAA,EAAE,CAAC,GACvD,CAACU,GAAWC,CAAA,IAAgBX,EAAe;AAAA,IAAE,MAAM;AAAA,IAAI,GAAG;AAAA,EAAE,CAAC,GAC7DY,IAASb,EAAmE,CAAC,CAAC,GAE9Ec,IAAWlB,EAAA,CACdmB,GAASC,MAAY;AACpB,UAAMC,IAAaD,GAAS,cAAc,UACpCE,IAAMD,MAAe,cAAcL,IAAeF;AACxD,IAAAQ,EAAA,CAAKC,OAAU;AAAA,MAAE,MAAMJ;AAAA,MAAS,GAAGI,EAAK,IAAI;AAAA,IAAE,EAAE,GAChD,aAAaN,EAAO,QAAQI,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x","jsxs","AnnounceContext","warned","Announcer","clearAfter","children","polite","setPolite","assertive","setAssertive","timers","announce","message","options","politeness","set","said","pending","useAnnounce"],"sources":["../../../src/components/Announcer/Announcer.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nexport type Politeness = \"polite\" | \"assertive\";\n\nexport interface AnnounceOptions {\n /** `polite` (default) waits for the screen reader to finish; `assertive` interrupts. Keep assertive for errors. */\n politeness?: Politeness;\n}\n\nexport type Announce = (message: string, options?: AnnounceOptions) => void;\n\nexport interface AnnouncerProps {\n /** Milliseconds before an announcement is cleared from the hidden region. Default: 5000. */\n clearAfter?: number;\n /** Your app. Anything inside can announce through `useAnnounce()`. */\n children?: ReactNode;\n}\n\ninterface Said {\n text: string;\n /** Changes on every announcement, so the same text twice is a new node and is read again. */\n n: number;\n}\n\nconst AnnounceContext = createContext<Announce | null>(null);\nlet warned = false;\n\n/**\n * Hidden live regions for screen reader announcements, rendered where you put it (inside your app, never in `<body>`).\n * Render one near the root; `useAnnounce()` below it speaks through it.\n */\nexport function Announcer({ clearAfter = 5000, children }: AnnouncerProps) {\n const [polite, setPolite] = useState<Said>({ text: \"\", n: 0 });\n const [assertive, setAssertive] = useState<Said>({ text: \"\", n: 0 });\n const timers = useRef<Partial<Record<Politeness, ReturnType<typeof setTimeout>>>>({});\n\n const announce = useCallback<Announce>(\n (message, options) => {\n const politeness = options?.politeness ?? \"polite\";\n const set = politeness === \"assertive\" ? setAssertive : setPolite;\n set((said) => ({ text: message, n: said.n + 1 }));\n clearTimeout(timers.current[politeness]);\n timers.current[politeness] = setTimeout(() => set((said) => ({ ...said, text: \"\" })), clearAfter);\n },\n [clearAfter],\n );\n\n useEffect(() => {\n const pending = timers.current;\n return () => {\n clearTimeout(pending.polite);\n clearTimeout(pending.assertive);\n };\n }, []);\n\n return (\n <AnnounceContext.Provider value={announce}>\n {children}\n <div className=\"cy-announcer\">\n <div className=\"cy-announcer-region cy-reset\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n {polite.text && <span key={polite.n}>{polite.text}</span>}\n </div>\n <div className=\"cy-announcer-region cy-reset\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n {assertive.text && <span key={assertive.n}>{assertive.text}</span>}\n </div>\n </div>\n </AnnounceContext.Provider>\n );\n}\n\n/** Returns `announce(message, { politeness })`, spoken through the nearest `<Announcer>`. */\nexport function useAnnounce(): Announce {\n const announce = useContext(AnnounceContext);\n return useMemo(\n () =>\n announce ??\n (() => {\n if (warned) return;\n warned = true;\n console.warn(\"Cynosure: useAnnounce() needs an <Announcer> above it; nothing was announced.\");\n }),\n [announce],\n );\n}\n"],"mappings":";;;AAiCA,IAAMS,IAAkBT,EAA+B,IAAI,GACvDU,IAAS;AAMb,SAAgBC,EAAU,EAAE,YAAAC,IAAa,KAAM,UAAAC,EAAA,GAA4B;AACzE,QAAM,CAACC,GAAQC,CAAA,IAAaT,EAAe;AAAA,IAAE,MAAM;AAAA,IAAI,GAAG;AAAA,EAAE,CAAC,GACvD,CAACU,GAAWC,CAAA,IAAgBX,EAAe;AAAA,IAAE,MAAM;AAAA,IAAI,GAAG;AAAA,EAAE,CAAC,GAC7DY,IAASb,EAAmE,CAAC,CAAC,GAE9Ec,IAAWlB,EAAA,CACdmB,GAASC,MAAY;AACpB,UAAMC,IAAaD,GAAS,cAAc,UACpCE,IAAMD,MAAe,cAAcL,IAAeF;AACxD,IAAAQ,EAAA,CAAKC,OAAU;AAAA,MAAE,MAAMJ;AAAA,MAAS,GAAGI,EAAK,IAAI;AAAA,IAAE,EAAE,GAChD,aAAaN,EAAO,QAAQI,CAAA,CAAW,GACvCJ,EAAO,QAAQI,CAAA,IAAc,WAAA,MAAiBC,EAAA,CAAKC,OAAU;AAAA,MAAE,GAAGA;AAAA,MAAM,MAAM;AAAA,IAAG,EAAE,GAAGZ,CAAU;AAAA,EAClG,GACA,CAACA,CAAU,CACb;AAEA,SAAAT,EAAA,MAAgB;AACd,UAAMsB,IAAUP,EAAO;AACvB,WAAA,MAAa;AACX,mBAAaO,EAAQ,MAAM,GAC3B,aAAaA,EAAQ,SAAS;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,CAAC,GAGH,gBAAAjB,EAACC,EAAgB,UAAjB;AAAA,IAA0B,OAAOU;AAAA,IAAjC,UAAA,CACGN,GACD,gBAAAL,EAAC,OAAD;AAAA,MAAK,WAAU;AAAA,MAAf,UAAA,CACE,gBAAAD,EAAC,OAAD;AAAA,QAAK,WAAU;AAAA,QAA+B,MAAK;AAAA,QAAS,aAAU;AAAA,QAAS,eAAY;AAAA,QACxF,UAAAO,EAAO,QAAQ,gBAAAP,EAAC,QAAD,EAAA,UAAsBO,EAAO,KAAW,GAA7BA,EAAO,CAAsB;AAAA,MACrD,CAAA,GACL,gBAAAP,EAAC,OAAD;AAAA,QAAK,WAAU;AAAA,QAA+B,MAAK;AAAA,QAAQ,aAAU;AAAA,QAAY,eAAY;AAAA,QAC1F,UAAAS,EAAU,QAAQ,gBAAAT,EAAC,QAAD,EAAA,UAAyBS,EAAU,KAAW,GAAnCA,EAAU,CAAyB;AAAA,MAC9D,CAAA,CACF;AAAA,IACmB,CAAA,CAAA;AAAA,E;AAE9B;AAGA,SAAgBU,IAAwB;AACtC,QAAMP,IAAWjB,EAAWO,CAAe;AAC3C,SAAOL,EAAA,MAEHe,MAAA,MACO;AACL,IAAIT,MACJA,IAAS,IACT,QAAQ,KAAK,+EAA+E;AAAA,EAC9F,IACF,CAACS,CAAQ,CACX;AACF"}
@@ -37,13 +37,34 @@ export interface AppShellProps {
37
37
  * shell's width, not the window's, so it also works in side panels.
38
38
  */
39
39
  collapseBelow?: number;
40
+ /**
41
+ * Called with the new value each time the shell becomes narrow or wide again, for code outside the shell (inside
42
+ * it, use `useAppShell()`). The shell starts wide, so the first call is `true`, before the first paint, when it
43
+ * mounts narrow; a shell that mounts wide does not call it until it narrows.
44
+ */
45
+ onNarrowChange?: (narrow: boolean) => void;
46
+ /** Replace the built-in English text: the menu button, the drawer title and the skip link. */
40
47
  labels?: Partial<AppShellLabels>;
48
+ /** Added to the root element, for layout. */
41
49
  className?: string;
42
50
  /** Layout only. Restyle through --cy-app-shell-* tokens. */
43
51
  style?: CSSProperties;
44
52
  }
53
+ /** What `useAppShell()` returns. */
54
+ export interface AppShellState {
55
+ /**
56
+ * Whether the shell is narrower than its `collapseBelow`: the navigation is in the drawer and `tabs` show. `false`
57
+ * on the server, on the first client render (it is measured before the first paint) and outside an AppShell.
58
+ */
59
+ narrow: boolean;
60
+ }
61
+ /**
62
+ * The state of the nearest AppShell, for anything rendered in its `header`, `nav`, `tabs` or content: `{ narrow }`.
63
+ * Outside an AppShell it does not throw; it returns `{ narrow: false }`.
64
+ */
65
+ export declare function useAppShell(): AppShellState;
45
66
  /**
46
67
  * The frame of an app: a top bar, the navigation beside the content, and `<main>`. On narrow screens the navigation
47
68
  * moves into a drawer opened from a menu button in the bar; choosing a link closes it. Includes a skip link.
48
69
  */
49
- export declare function AppShell({ header, nav, tabs, children, collapseBelow, labels, className, style, }: AppShellProps): import("react").JSX.Element;
70
+ export declare function AppShell({ header, nav, tabs, children, collapseBelow, onNarrowChange, labels, className, style, }: AppShellProps): import("react").JSX.Element;
@@ -1,96 +1,108 @@
1
1
  "use client";
2
- import { useClientLayoutEffect as C } from "../../foundations/client-layout-effect.js";
3
- import { LinkBase as A } from "../../foundations/LinkBase/LinkBase.js";
4
- import { menu as L } from "../../icons/menu.js";
5
- import { IconButton as S } from "../IconButton/IconButton.js";
6
- import { Sheet as D } from "../Sheet/Sheet.js";
7
- import { useId as B, useRef as y, useState as v } from "react";
8
- import { jsx as e, jsxs as N } from "react/jsx-runtime";
9
- var E = {
2
+ import { useClientLayoutEffect as E } from "../../foundations/client-layout-effect.js";
3
+ import { LinkBase as B } from "../../foundations/LinkBase/LinkBase.js";
4
+ import { menu as I } from "../../icons/menu.js";
5
+ import { IconButton as O } from "../IconButton/IconButton.js";
6
+ import { Sheet as R } from "../Sheet/Sheet.js";
7
+ import { createContext as $, useContext as j, useEffect as z, useId as M, useMemo as P, useRef as a, useState as x } from "react";
8
+ import { jsx as t, jsxs as N } from "react/jsx-runtime";
9
+ var F = {
10
10
  openNav: "Open navigation",
11
11
  nav: "Navigation",
12
12
  skip: "Skip to content"
13
- };
14
- function P({ header: c, nav: t, tabs: n, children: b, collapseBelow: l = 768, labels: g, className: p, style: k }) {
15
- const i = {
16
- ...E,
17
- ...g
18
- }, d = B(), m = y(null), h = y(null), [r, w] = v(!1), [u, o] = v(!1);
19
- C(() => {
20
- const a = m.current;
21
- if (!a) return;
22
- const s = () => w(a.getBoundingClientRect().width < l);
13
+ }, C = $({ narrow: !1 });
14
+ function K() {
15
+ return j(C);
16
+ }
17
+ function Q({ header: l, nav: r, tabs: o, children: g, collapseBelow: p = 768, onNarrowChange: d, labels: w, className: u, style: A }) {
18
+ const c = {
19
+ ...F,
20
+ ...w
21
+ }, m = M(), f = a(null), h = a(null), [e, S] = x(!1), [v, i] = x(!1);
22
+ E(() => {
23
+ const n = f.current;
24
+ if (!n) return;
25
+ const s = () => S(n.getBoundingClientRect().width < p);
23
26
  s();
24
- const f = new ResizeObserver(s);
25
- return f.observe(a), () => f.disconnect();
26
- }, [l]);
27
- const x = (a) => {
28
- const s = a.target.closest("a[href], button");
29
- s && !s.hasAttribute("aria-expanded") && s.getAttribute("aria-disabled") !== "true" && o(!1);
27
+ const k = new ResizeObserver(s);
28
+ return k.observe(n), () => k.disconnect();
29
+ }, [p]);
30
+ const y = a(!1), b = a(d);
31
+ b.current = d, z(() => {
32
+ y.current !== e && (y.current = e, b.current?.(e));
33
+ }, [e]);
34
+ const L = P(() => ({ narrow: e }), [e]), D = (n) => {
35
+ const s = n.target.closest("a[href], button");
36
+ s && !s.hasAttribute("aria-expanded") && s.getAttribute("aria-disabled") !== "true" && i(!1);
30
37
  };
31
- return /* @__PURE__ */ N("div", {
32
- ref: m,
33
- className: p ? `cy-app-shell ${p}` : "cy-app-shell",
34
- "data-narrow": r ? "" : void 0,
35
- "data-nav": t ? "" : void 0,
36
- "data-tabs": n && r ? "" : void 0,
37
- style: k,
38
- children: [
39
- /* @__PURE__ */ e(A, {
40
- className: "cy-app-shell-skip cy-reset",
41
- href: `#${d}-main`,
42
- onClick: (a) => {
43
- a.preventDefault(), h.current?.focus();
44
- },
45
- children: i.skip
46
- }),
47
- (c || t && r) && /* @__PURE__ */ N("header", {
48
- className: "cy-app-shell-header cy-reset",
49
- children: [t && r && /* @__PURE__ */ e(S, {
50
- icon: L,
51
- label: i.openNav,
52
- variant: "ghost",
53
- tone: "neutral",
54
- tooltipPlacement: "end",
55
- "aria-expanded": u,
56
- onClick: () => o(!0)
57
- }), /* @__PURE__ */ e("div", {
58
- className: "cy-app-shell-bar cy-reset",
59
- children: c
60
- })]
61
- }),
62
- t && !r && /* @__PURE__ */ e("div", {
63
- className: "cy-app-shell-nav cy-reset",
64
- children: t
65
- }),
66
- /* @__PURE__ */ e("main", {
67
- ref: h,
68
- id: `${d}-main`,
69
- tabIndex: -1,
70
- className: "cy-app-shell-main cy-reset",
71
- children: b
72
- }),
73
- n && r && /* @__PURE__ */ e("div", {
74
- className: "cy-app-shell-tabs cy-reset",
75
- children: n
76
- }),
77
- t && r && /* @__PURE__ */ e(D, {
78
- open: u,
79
- onOpenChange: o,
80
- side: "start",
81
- size: "sm",
82
- title: i.nav,
83
- children: /* @__PURE__ */ e("div", {
84
- className: "cy-app-shell-drawer cy-reset",
85
- onClick: x,
86
- children: t
38
+ return /* @__PURE__ */ t(C.Provider, {
39
+ value: L,
40
+ children: /* @__PURE__ */ N("div", {
41
+ ref: f,
42
+ className: u ? `cy-app-shell ${u}` : "cy-app-shell",
43
+ "data-narrow": e ? "" : void 0,
44
+ "data-nav": r ? "" : void 0,
45
+ "data-tabs": o && e ? "" : void 0,
46
+ style: A,
47
+ children: [
48
+ /* @__PURE__ */ t(B, {
49
+ className: "cy-app-shell-skip cy-reset",
50
+ href: `#${m}-main`,
51
+ onClick: (n) => {
52
+ n.preventDefault(), h.current?.focus();
53
+ },
54
+ children: c.skip
55
+ }),
56
+ (l || r && e) && /* @__PURE__ */ N("header", {
57
+ className: "cy-app-shell-header cy-reset",
58
+ children: [r && e && /* @__PURE__ */ t(O, {
59
+ icon: I,
60
+ label: c.openNav,
61
+ variant: "ghost",
62
+ tone: "neutral",
63
+ tooltipPlacement: "end",
64
+ "aria-expanded": v,
65
+ onClick: () => i(!0)
66
+ }), /* @__PURE__ */ t("div", {
67
+ className: "cy-app-shell-bar cy-reset",
68
+ children: l
69
+ })]
70
+ }),
71
+ r && !e && /* @__PURE__ */ t("div", {
72
+ className: "cy-app-shell-nav cy-reset",
73
+ children: r
74
+ }),
75
+ /* @__PURE__ */ t("main", {
76
+ ref: h,
77
+ id: `${m}-main`,
78
+ tabIndex: -1,
79
+ className: "cy-app-shell-main cy-reset",
80
+ children: g
81
+ }),
82
+ o && e && /* @__PURE__ */ t("div", {
83
+ className: "cy-app-shell-tabs cy-reset",
84
+ children: o
85
+ }),
86
+ r && e && /* @__PURE__ */ t(R, {
87
+ open: v,
88
+ onOpenChange: i,
89
+ side: "start",
90
+ size: "sm",
91
+ title: c.nav,
92
+ keepMounted: !0,
93
+ children: /* @__PURE__ */ t("div", {
94
+ className: "cy-app-shell-drawer cy-reset",
95
+ onClick: D,
96
+ children: r
97
+ })
87
98
  })
88
- })
89
- ]
99
+ ]
100
+ })
90
101
  });
91
102
  }
92
103
  export {
93
- P as AppShell
104
+ Q as AppShell,
105
+ K as useAppShell
94
106
  };
95
107
 
96
108
  //# sourceMappingURL=AppShell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppShell.js","names":["useClientLayoutEffect","LinkBase","menu","IconButton","Sheet","useId","useRef","useState","jsx","jsxs","DEFAULT_LABELS","AppShell","header","nav","tabs","children","collapseBelow","labels","className","style","text","id","root","main","narrow","setNarrow","drawer","setDrawer","el","measure","observer","onDrawerClick","event","target"],"sources":["../../../src/components/AppShell/AppShell.tsx"],"sourcesContent":["import { type CSSProperties, type MouseEvent, type ReactNode, useId, useRef, useState } from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { LinkBase } from \"../../foundations/LinkBase/LinkBase.js\";\nimport { menu } from \"../../icons/menu.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Sheet } from \"../Sheet/Sheet.js\";\n\nexport interface AppShellTokens {\n /** Background of the navigation column. */\n navBackground: string;\n /** Background of the top bar. */\n headerBackground: string;\n /** Lines between the bar, the navigation and the content. */\n border: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n appShell: AppShellTokens;\n }\n}\n\nexport interface AppShellLabels {\n /** The menu button that opens the navigation on narrow screens. Default: \"Open navigation\". */\n openNav: string;\n /** Title of the navigation drawer. Default: \"Navigation\". */\n nav: string;\n /** The skip link, shown on keyboard focus. Default: \"Skip to content\". */\n skip: string;\n}\n\nexport interface AppShellProps {\n /** Top bar content: brand, search, account. */\n header?: ReactNode;\n /** The navigation, usually a `SideNav`. Beside the content when wide; in a drawer when narrow. */\n nav?: ReactNode;\n /**\n * A bottom tab bar on narrow screens, usually `<SideNav layout=\"bar\">` with the app's three to five main sections.\n * Hidden when wide, where `nav` shows instead.\n */\n tabs?: ReactNode;\n /** The page content, rendered in `<main>`. */\n children?: ReactNode;\n /**\n * Width (of the shell itself, in px) below which the navigation moves into a drawer. Default: 768. It follows the\n * shell's width, not the window's, so it also works in side panels.\n */\n collapseBelow?: number;\n labels?: Partial<AppShellLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-app-shell-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: AppShellLabels = {\n openNav: \"Open navigation\",\n nav: \"Navigation\",\n skip: \"Skip to content\",\n};\n\n/**\n * The frame of an app: a top bar, the navigation beside the content, and `<main>`. On narrow screens the navigation\n * moves into a drawer opened from a menu button in the bar; choosing a link closes it. Includes a skip link.\n */\nexport function AppShell({\n header,\n nav,\n tabs,\n children,\n collapseBelow = 768,\n labels,\n className,\n style,\n}: AppShellProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const root = useRef<HTMLDivElement>(null);\n const main = useRef<HTMLElement>(null);\n const [narrow, setNarrow] = useState(false);\n const [drawer, setDrawer] = useState(false);\n\n useClientLayoutEffect(() => {\n const el = root.current;\n if (!el) return;\n const measure = () => setNarrow(el.getBoundingClientRect().width < collapseBelow);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, [collapseBelow]);\n\n // Choosing a destination in the drawer closes it; group toggles (aria-expanded) keep it open.\n const onDrawerClick = (event: MouseEvent<HTMLElement>) => {\n const target = (event.target as Element).closest(\"a[href], button\");\n if (target && !target.hasAttribute(\"aria-expanded\") && target.getAttribute(\"aria-disabled\") !== \"true\")\n setDrawer(false);\n };\n\n return (\n <div\n ref={root}\n className={className ? `cy-app-shell ${className}` : \"cy-app-shell\"}\n data-narrow={narrow ? \"\" : undefined}\n data-nav={nav ? \"\" : undefined}\n data-tabs={tabs && narrow ? \"\" : undefined}\n style={style}\n >\n <LinkBase\n className=\"cy-app-shell-skip cy-reset\"\n href={`#${id}-main`}\n onClick={(event) => {\n // Move focus without touching the URL (the app's router owns it).\n event.preventDefault();\n main.current?.focus();\n }}\n >\n {text.skip}\n </LinkBase>\n {(header || (nav && narrow)) && (\n <header className=\"cy-app-shell-header cy-reset\">\n {nav && narrow && (\n <IconButton\n icon={menu}\n label={text.openNav}\n variant=\"ghost\"\n tone=\"neutral\"\n tooltipPlacement=\"end\"\n aria-expanded={drawer}\n onClick={() => setDrawer(true)}\n />\n )}\n <div className=\"cy-app-shell-bar cy-reset\">{header}</div>\n </header>\n )}\n {nav && !narrow && <div className=\"cy-app-shell-nav cy-reset\">{nav}</div>}\n <main ref={main} id={`${id}-main`} tabIndex={-1} className=\"cy-app-shell-main cy-reset\">\n {children}\n </main>\n {tabs && narrow && <div className=\"cy-app-shell-tabs cy-reset\">{tabs}</div>}\n {nav && narrow && (\n <Sheet open={drawer} onOpenChange={setDrawer} side=\"start\" size=\"sm\" title={text.nav}>\n {/* biome-ignore lint/a11y/noStaticElementInteractions: delegated click from the links and buttons inside */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: keyboard activation of a link or button is a click too */}\n <div className=\"cy-app-shell-drawer cy-reset\" onClick={onDrawerClick}>\n {nav}\n </div>\n </Sheet>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAsDA,IAAMU,IAAiC;AAAA,EACrC,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AACR;AAMA,SAAgBC,EAAS,EACvB,QAAAC,GACA,KAAAC,GACA,MAAAC,GACA,UAAAC,GACA,eAAAC,IAAgB,KAChB,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACgB;AAChB,QAAMC,IAAO;AAAA,IAAE,GAAGV;AAAA,IAAgB,GAAGO;AAAA,EAAO,GACtCI,IAAKhB,EAAM,GACXiB,IAAOhB,EAAuB,IAAI,GAClCiB,IAAOjB,EAAoB,IAAI,GAC/B,CAACkB,GAAQC,CAAA,IAAalB,EAAS,EAAK,GACpC,CAACmB,GAAQC,CAAA,IAAapB,EAAS,EAAK;AAE1C,EAAAP,EAAA,MAA4B;AAC1B,UAAM4B,IAAKN,EAAK;AAChB,QAAI,CAACM,EAAI;AACT,UAAMC,IAAA,MAAgBJ,EAAUG,EAAG,sBAAsB,EAAE,QAAQZ,CAAa;AAChF,IAAAa,EAAQ;AACR,UAAMC,IAAW,IAAI,eAAeD,CAAO;AAC3C,WAAAC,EAAS,QAAQF,CAAE,GACnB,MAAaE,EAAS,WAAW;AAAA,EACnC,GAAG,CAACd,CAAa,CAAC;AAGlB,QAAMe,IAAA,CAAiBC,MAAmC;AACxD,UAAMC,IAAUD,EAAM,OAAmB,QAAQ,iBAAiB;AAClE,IAAIC,KAAU,CAACA,EAAO,aAAa,eAAe,K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QAAK,WAAU;AAAA,QAA8B,UAAAM;AAAA,MAAU,CAAA;AAAA,MACzED,KAAOW,KACN,gBAAAhB,EAACJ,GAAD;AAAA,QAAO,MAAMsB;AAAA,QAAQ,cAAcC;AAAA,QAAW,MAAK;AAAA,QAAQ,MAAK;AAAA,QAAK,OAAOP,EAAK;AAAA,QAG/E,UAAA,gBAAAZ,EAAC,OAAD;AAAA,UAAK,WAAU;AAAA,UAA+B,SAASuB;AAAA,UACpD,UAAAlB;AAAA,QACE,CAAA;AAAA,MACA,CAAA;AAAA,IAEN;AAAA,E;AAET"}
1
+ {"version":3,"file":"AppShell.js","names":["useClientLayoutEffect","LinkBase","menu","IconButton","Sheet","createContext","useContext","useEffect","useId","useMemo","useRef","useState","jsx","jsxs","DEFAULT_LABELS","Context","useAppShell","AppShell","header","nav","tabs","children","collapseBelow","onNarrowChange","labels","className","style","text","id","root","main","narrow","setNarrow","drawer","setDrawer","el","measure","observer","told","notify","state","onDrawerClick","event","target"],"sources":["../../../src/components/AppShell/AppShell.tsx"],"sourcesContent":["import {\n type CSSProperties,\n createContext,\n type MouseEvent,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { LinkBase } from \"../../foundations/LinkBase/LinkBase.js\";\nimport { menu } from \"../../icons/menu.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Sheet } from \"../Sheet/Sheet.js\";\n\nexport interface AppShellTokens {\n /** Background of the navigation column. */\n navBackground: string;\n /** Background of the top bar. */\n headerBackground: string;\n /** Lines between the bar, the navigation and the content. */\n border: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n appShell: AppShellTokens;\n }\n}\n\nexport interface AppShellLabels {\n /** The menu button that opens the navigation on narrow screens. Default: \"Open navigation\". */\n openNav: string;\n /** Title of the navigation drawer. Default: \"Navigation\". */\n nav: string;\n /** The skip link, shown on keyboard focus. Default: \"Skip to content\". */\n skip: string;\n}\n\nexport interface AppShellProps {\n /** Top bar content: brand, search, account. */\n header?: ReactNode;\n /** The navigation, usually a `SideNav`. Beside the content when wide; in a drawer when narrow. */\n nav?: ReactNode;\n /**\n * A bottom tab bar on narrow screens, usually `<SideNav layout=\"bar\">` with the app's three to five main sections.\n * Hidden when wide, where `nav` shows instead.\n */\n tabs?: ReactNode;\n /** The page content, rendered in `<main>`. */\n children?: ReactNode;\n /**\n * Width (of the shell itself, in px) below which the navigation moves into a drawer. Default: 768. It follows the\n * shell's width, not the window's, so it also works in side panels.\n */\n collapseBelow?: number;\n /**\n * Called with the new value each time the shell becomes narrow or wide again, for code outside the shell (inside\n * it, use `useAppShell()`). The shell starts wide, so the first call is `true`, before the first paint, when it\n * mounts narrow; a shell that mounts wide does not call it until it narrows.\n */\n onNarrowChange?: (narrow: boolean) => void;\n /** Replace the built-in English text: the menu button, the drawer title and the skip link. */\n labels?: Partial<AppShellLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-app-shell-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: AppShellLabels = {\n openNav: \"Open navigation\",\n nav: \"Navigation\",\n skip: \"Skip to content\",\n};\n\n/** What `useAppShell()` returns. */\nexport interface AppShellState {\n /**\n * Whether the shell is narrower than its `collapseBelow`: the navigation is in the drawer and `tabs` show. `false`\n * on the server, on the first client render (it is measured before the first paint) and outside an AppShell.\n */\n narrow: boolean;\n}\n\nconst WIDE: AppShellState = { narrow: false };\nconst Context = createContext<AppShellState>(WIDE);\n\n/**\n * The state of the nearest AppShell, for anything rendered in its `header`, `nav`, `tabs` or content: `{ narrow }`.\n * Outside an AppShell it does not throw; it returns `{ narrow: false }`.\n */\nexport function useAppShell(): AppShellState {\n return useContext(Context);\n}\n\n/**\n * The frame of an app: a top bar, the navigation beside the content, and `<main>`. On narrow screens the navigation\n * moves into a drawer opened from a menu button in the bar; choosing a link closes it. Includes a skip link.\n */\nexport function AppShell({\n header,\n nav,\n tabs,\n children,\n collapseBelow = 768,\n onNarrowChange,\n labels,\n className,\n style,\n}: AppShellProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const root = useRef<HTMLDivElement>(null);\n const main = useRef<HTMLElement>(null);\n const [narrow, setNarrow] = useState(false);\n const [drawer, setDrawer] = useState(false);\n\n useClientLayoutEffect(() => {\n const el = root.current;\n if (!el) return;\n const measure = () => setNarrow(el.getBoundingClientRect().width < collapseBelow);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, [collapseBelow]);\n\n // Tell the outside once per change: never for the wide start, and not again when only the callback changes.\n const told = useRef(false);\n const notify = useRef(onNarrowChange);\n notify.current = onNarrowChange;\n useEffect(() => {\n if (told.current === narrow) return;\n told.current = narrow;\n notify.current?.(narrow);\n }, [narrow]);\n const state = useMemo(() => ({ narrow }), [narrow]);\n\n // Choosing a destination in the drawer closes it; group toggles (aria-expanded) keep it open.\n const onDrawerClick = (event: MouseEvent<HTMLElement>) => {\n const target = (event.target as Element).closest(\"a[href], button\");\n if (target && !target.hasAttribute(\"aria-expanded\") && target.getAttribute(\"aria-disabled\") !== \"true\")\n setDrawer(false);\n };\n\n return (\n <Context.Provider value={state}>\n <div\n ref={root}\n className={className ? `cy-app-shell ${className}` : \"cy-app-shell\"}\n data-narrow={narrow ? \"\" : undefined}\n data-nav={nav ? \"\" : undefined}\n data-tabs={tabs && narrow ? \"\" : undefined}\n style={style}\n >\n <LinkBase\n className=\"cy-app-shell-skip cy-reset\"\n href={`#${id}-main`}\n onClick={(event) => {\n // Move focus without touching the URL (the app's router owns it).\n event.preventDefault();\n main.current?.focus();\n }}\n >\n {text.skip}\n </LinkBase>\n {(header || (nav && narrow)) && (\n <header className=\"cy-app-shell-header cy-reset\">\n {nav && narrow && (\n <IconButton\n icon={menu}\n label={text.openNav}\n variant=\"ghost\"\n tone=\"neutral\"\n tooltipPlacement=\"end\"\n aria-expanded={drawer}\n onClick={() => setDrawer(true)}\n />\n )}\n <div className=\"cy-app-shell-bar cy-reset\">{header}</div>\n </header>\n )}\n {nav && !narrow && <div className=\"cy-app-shell-nav cy-reset\">{nav}</div>}\n <main ref={main} id={`${id}-main`} tabIndex={-1} className=\"cy-app-shell-main cy-reset\">\n {children}\n </main>\n {tabs && narrow && <div className=\"cy-app-shell-tabs cy-reset\">{tabs}</div>}\n {nav && narrow && (\n // Kept mounted while closed, so the navigation keeps its open sections and scroll position.\n <Sheet open={drawer} onOpenChange={setDrawer} side=\"start\" size=\"sm\" title={text.nav} keepMounted>\n {/* biome-ignore lint/a11y/noStaticElementInteractions: delegated click from the links and buttons inside */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: keyboard activation of a link or button is a click too */}\n <div className=\"cy-app-shell-drawer cy-reset\" onClick={onDrawerClick}>\n {nav}\n </div>\n </Sheet>\n )}\n </div>\n </Context.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAyEA,IAAMc,IAAiC;AAAA,EACrC,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AACR,GAYMC,IAAUV,EAA6B,EADf,QAAQ,GACO,CAAI;AAMjD,SAAgBW,IAA6B;AAC3C,SAAOV,EAAWS,CAAO;AAC3B;AAMA,SAAgBE,EAAS,EACvB,QAAAC,GACA,KAAAC,GACA,MAAAC,GACA,UAAAC,GACA,eAAAC,IAAgB,KAChB,gBAAAC,GACA,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACgB;AAChB,QAAMC,IAAO;AAAA,IAAE,GAAGb;AAAA,IAAgB,GAAGU;AAAA,EAAO,GACtCI,IAAKpB,EAAM,GACXqB,IAAOnB,EAAuB,IAAI,GAClCoB,IAAOpB,EAAoB,IAAI,GAC/B,CAACqB,GAAQC,CAAA,IAAarB,EAAS,EAAK,GACpC,CAACsB,GAAQC,CAAA,IAAavB,EAAS,EAAK;AAE1C,EAAAX,EAAA,MAA4B;AAC1B,UAAMmC,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
+ export { AppShell, type AppShellLabels, type AppShellProps, type AppShellState, type AppShellTokens, useAppShell, } from "./AppShell.js";
@@ -0,0 +1,29 @@
1
+ import { type CSSProperties, type ReactNode } from "react";
2
+ export interface AspectRatioTokens {
3
+ /** Corner radius of every AspectRatio, whatever its `radius` prop says. */
4
+ radius: string;
5
+ }
6
+ declare module "../../tokens/schema.js" {
7
+ interface ComponentTokens {
8
+ aspectRatio: AspectRatioTokens;
9
+ }
10
+ }
11
+ /** A step of the radius scale (`--cy-radius-*`), or `none` for square corners. */
12
+ export type AspectRatioRadius = "none" | "sm" | "md" | "lg" | "card" | "full";
13
+ export interface AspectRatioProps {
14
+ /**
15
+ * Width divided by height: a number (`16 / 9`, `1`) or a CSS ratio (`"4/3"`). A number that is not above zero uses
16
+ * the default. Default `16 / 9`.
17
+ */
18
+ ratio?: number | string | undefined;
19
+ /** Rounds the corners from the radius tokens; the content is clipped to them. Default "none". */
20
+ radius?: AspectRatioRadius;
21
+ /** Added to the root element, for layout. */
22
+ className?: string;
23
+ /** Layout only (width, margin, placement). The height always follows from the width. */
24
+ style?: CSSProperties;
25
+ /** What fills the box. Each child is stretched to it; an image, video or canvas covers it (`object-fit: cover`). */
26
+ children?: ReactNode;
27
+ }
28
+ /** A box that keeps a width-to-height ratio at any width, for an image, a video, a map, a chart or an embed. */
29
+ export declare const AspectRatio: import("react").ForwardRefExoticComponent<AspectRatioProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { forwardRef as n } from "react";
3
+ import { jsx as p } from "react/jsx-runtime";
4
+ var r = 16 / 9, d = n(function({ ratio: t = r, radius: o = "none", className: e, style: a, children: i }, s) {
5
+ const c = typeof t == "number" && !(t > 0 && Number.isFinite(t)) ? r : t;
6
+ return /* @__PURE__ */ p("div", {
7
+ ref: s,
8
+ className: e ? `cy-aspect-ratio ${e}` : "cy-aspect-ratio",
9
+ "data-radius": o,
10
+ style: {
11
+ "--_ratio": c,
12
+ ...a
13
+ },
14
+ children: i
15
+ });
16
+ });
17
+ export {
18
+ d as AspectRatio
19
+ };
20
+
21
+ //# sourceMappingURL=AspectRatio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AspectRatio.js","names":["forwardRef","jsx","DEFAULT_RATIO","AspectRatio","ratio","radius","className","style","children","ref","safe"],"sources":["../../../src/components/AspectRatio/AspectRatio.tsx"],"sourcesContent":["import { type CSSProperties, forwardRef, type ReactNode } from \"react\";\n\nexport interface AspectRatioTokens {\n /** Corner radius of every AspectRatio, whatever its `radius` prop says. */\n radius: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n aspectRatio: AspectRatioTokens;\n }\n}\n\n/** A step of the radius scale (`--cy-radius-*`), or `none` for square corners. */\nexport type AspectRatioRadius = \"none\" | \"sm\" | \"md\" | \"lg\" | \"card\" | \"full\";\n\nexport interface AspectRatioProps {\n /**\n * Width divided by height: a number (`16 / 9`, `1`) or a CSS ratio (`\"4/3\"`). A number that is not above zero uses\n * the default. Default `16 / 9`.\n */\n ratio?: number | string | undefined;\n /** Rounds the corners from the radius tokens; the content is clipped to them. Default \"none\". */\n radius?: AspectRatioRadius;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only (width, margin, placement). The height always follows from the width. */\n style?: CSSProperties;\n /** What fills the box. Each child is stretched to it; an image, video or canvas covers it (`object-fit: cover`). */\n children?: ReactNode;\n}\n\nconst DEFAULT_RATIO = 16 / 9;\n\n/** A box that keeps a width-to-height ratio at any width, for an image, a video, a map, a chart or an embed. */\nexport const AspectRatio = forwardRef<HTMLDivElement, AspectRatioProps>(function AspectRatio(\n { ratio = DEFAULT_RATIO, radius = \"none\", className, style, children },\n ref,\n) {\n const safe = typeof ratio === \"number\" && !(ratio > 0 && Number.isFinite(ratio)) ? DEFAULT_RATIO : ratio;\n return (\n <div\n ref={ref}\n className={className ? `cy-aspect-ratio ${className}` : \"cy-aspect-ratio\"}\n data-radius={radius}\n style={{ \"--_ratio\": safe, ...style } as CSSProperties}\n >\n {children}\n </div>\n );\n});\n"],"mappings":";;;AAgCA,IAAME,IAAgB,KAAK,GAGdC,IAAcH,EAA6C,SACtE,EAAE,OAAAI,IAAQF,GAAe,QAAAG,IAAS,QAAQ,WAAAC,GAAW,OAAAC,GAAO,UAAAC,EAAA,GAC5DC,GACA;AACA,QAAMC,IAAO,OAAON,KAAU,YAAY,EAAEA,IAAQ,KAAK,OAAO,SAASA,CAAK,KAAKF,IAAgBE;AACnG,SACE,gBAAAH,EAAC,OAAD;AAAA,IACO,KAAAQ;AAAA,IACL,WAAWH,IAAY,mBAAmBA,CAAA,KAAc;AAAA,IACxD,eAAaD;AAAA,IACb,OAAO;AAAA,MAAE,YAAYK;AAAA,MAAM,GAAGH;AAAA,IAAM;AAAA,IAEnC,UAAAC;AAAA,EACE,CAAA;AAET,CAAC"}
@@ -0,0 +1 @@
1
+ export { AspectRatio, type AspectRatioProps, type AspectRatioRadius, type AspectRatioTokens, } from "./AspectRatio.js";