oneslash-design-system 2.18.0 → 2.20.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 (227) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +54 -5
  3. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  4. package/dist/cases/app-shell/sidebar.jsx +124 -0
  5. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  6. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  7. package/dist/cases/app-shell.md +364 -0
  8. package/dist/cases/artifact-card/card.jsx +32 -6
  9. package/dist/cases/artifact-card.md +55 -7
  10. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  11. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  12. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  13. package/dist/cases/billing-page/self-serve.jsx +134 -0
  14. package/dist/cases/billing-page.md +247 -0
  15. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  16. package/dist/cases/breakdown-list/bars.jsx +47 -0
  17. package/dist/cases/breakdown-list/table.d.ts +1 -0
  18. package/dist/cases/breakdown-list/table.jsx +69 -0
  19. package/dist/cases/breakdown-list.md +158 -0
  20. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  21. package/dist/cases/composer-limit/notice.jsx +3 -3
  22. package/dist/cases/composer-limit.md +8 -8
  23. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  24. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  25. package/dist/cases/dashboard/work-first.d.ts +1 -0
  26. package/dist/cases/dashboard/work-first.jsx +165 -0
  27. package/dist/cases/dashboard.md +507 -0
  28. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  29. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  30. package/dist/cases/data-table-page/paged.d.ts +1 -0
  31. package/dist/cases/data-table-page/paged.jsx +284 -0
  32. package/dist/cases/data-table-page.md +771 -0
  33. package/dist/cases/error-page/in-shell.jsx +26 -17
  34. package/dist/cases/error-page.md +42 -21
  35. package/dist/cases/invoice-list/table.d.ts +1 -0
  36. package/dist/cases/invoice-list/table.jsx +64 -0
  37. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  38. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  39. package/dist/cases/invoice-list.md +237 -0
  40. package/dist/cases/load-failure/inline.jsx +2 -2
  41. package/dist/cases/load-failure.md +2 -2
  42. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  43. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  44. package/dist/cases/master-detail/split.d.ts +1 -0
  45. package/dist/cases/master-detail/split.jsx +49 -0
  46. package/dist/cases/master-detail.md +213 -0
  47. package/dist/cases/members-list/rows.jsx +2 -1
  48. package/dist/cases/members-list/table.jsx +8 -9
  49. package/dist/cases/members-list.md +12 -13
  50. package/dist/cases/mobile-menu/links.d.ts +1 -0
  51. package/dist/cases/mobile-menu/links.jsx +24 -0
  52. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  53. package/dist/cases/mobile-menu/sections.jsx +61 -0
  54. package/dist/cases/mobile-menu.md +170 -0
  55. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  56. package/dist/cases/not-found-page.md +41 -20
  57. package/dist/cases/number-format.md +36 -0
  58. package/dist/cases/on-this-page/aside.d.ts +1 -0
  59. package/dist/cases/on-this-page/aside.jsx +39 -0
  60. package/dist/cases/on-this-page.md +80 -0
  61. package/dist/cases/page-header/actions.d.ts +1 -0
  62. package/dist/cases/page-header/actions.jsx +65 -0
  63. package/dist/cases/page-header/sub-page.d.ts +1 -0
  64. package/dist/cases/page-header/sub-page.jsx +37 -0
  65. package/dist/cases/page-header.md +195 -0
  66. package/dist/cases/paged-card/pager.d.ts +1 -0
  67. package/dist/cases/paged-card/pager.jsx +41 -0
  68. package/dist/cases/paged-card/see-all.d.ts +1 -0
  69. package/dist/cases/paged-card/see-all.jsx +34 -0
  70. package/dist/cases/paged-card.md +147 -0
  71. package/dist/cases/payment-method/none.d.ts +1 -0
  72. package/dist/cases/payment-method/none.jsx +17 -0
  73. package/dist/cases/payment-method/on-file.d.ts +1 -0
  74. package/dist/cases/payment-method/on-file.jsx +92 -0
  75. package/dist/cases/payment-method.md +182 -0
  76. package/dist/cases/phone-navigation.md +32 -0
  77. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  78. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  79. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  80. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  81. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  82. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  83. package/dist/cases/plan-change-confirm.md +261 -0
  84. package/dist/cases/plan-picker/cards.d.ts +1 -0
  85. package/dist/cases/plan-picker/cards.jsx +97 -0
  86. package/dist/cases/plan-picker/list.d.ts +1 -0
  87. package/dist/cases/plan-picker/list.jsx +103 -0
  88. package/dist/cases/plan-picker.md +297 -0
  89. package/dist/cases/range-switch/segmented.jsx +11 -7
  90. package/dist/cases/range-switch.md +16 -11
  91. package/dist/cases/route-loading/region.jsx +27 -18
  92. package/dist/cases/route-loading.md +42 -21
  93. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  94. package/dist/cases/settings-page.md +5 -4
  95. package/dist/cases/side-pane/beside.d.ts +1 -0
  96. package/dist/cases/side-pane/beside.jsx +79 -0
  97. package/dist/cases/side-pane/over.d.ts +1 -0
  98. package/dist/cases/side-pane/over.jsx +58 -0
  99. package/dist/cases/side-pane.md +238 -0
  100. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  101. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  102. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  103. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  104. package/dist/cases/sidebar-nav.md +261 -0
  105. package/dist/cases/site-footer/columns.d.ts +1 -0
  106. package/dist/cases/site-footer/columns.jsx +51 -0
  107. package/dist/cases/site-footer/simple.d.ts +1 -0
  108. package/dist/cases/site-footer/simple.jsx +24 -0
  109. package/dist/cases/site-footer.md +133 -0
  110. package/dist/cases/site-header/links.d.ts +1 -0
  111. package/dist/cases/site-header/links.jsx +26 -0
  112. package/dist/cases/site-header/sections.d.ts +1 -0
  113. package/dist/cases/site-header/sections.jsx +64 -0
  114. package/dist/cases/site-header.md +183 -0
  115. package/dist/cases/stat-row/featured.d.ts +1 -0
  116. package/dist/cases/stat-row/featured.jsx +17 -0
  117. package/dist/cases/stat-row/tiles.d.ts +1 -0
  118. package/dist/cases/stat-row/tiles.jsx +34 -0
  119. package/dist/cases/stat-row.md +104 -0
  120. package/dist/cases/status-label/dot.d.ts +1 -0
  121. package/dist/cases/status-label/dot.jsx +39 -0
  122. package/dist/cases/status-label/text.d.ts +1 -0
  123. package/dist/cases/status-label/text.jsx +44 -0
  124. package/dist/cases/status-label.md +143 -0
  125. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  126. package/dist/cases/theme-switcher/menu.jsx +47 -0
  127. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  128. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  129. package/dist/cases/theme-switcher.md +149 -0
  130. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  131. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  132. package/dist/cases/upgrade-prompt.md +10 -6
  133. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  134. package/dist/cases/usage-meters/by-person.jsx +72 -0
  135. package/dist/cases/usage-meters/meters.d.ts +1 -0
  136. package/dist/cases/usage-meters/meters.jsx +49 -0
  137. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  138. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  139. package/dist/cases/usage-meters.md +303 -0
  140. package/dist/cases.json +1756 -172
  141. package/dist/components/appShell.d.ts +44 -0
  142. package/dist/components/appShell.jsx +121 -0
  143. package/dist/components/button.d.ts +1 -1
  144. package/dist/components/button.jsx +11 -5
  145. package/dist/components/drawer.d.ts +31 -0
  146. package/dist/components/drawer.jsx +121 -0
  147. package/dist/components/formatNumber.d.ts +25 -0
  148. package/dist/components/formatNumber.js +125 -0
  149. package/dist/components/heading.d.ts +3 -1
  150. package/dist/components/heading.jsx +2 -2
  151. package/dist/components/iconButton.jsx +12 -7
  152. package/dist/components/link.d.ts +6 -1
  153. package/dist/components/link.jsx +11 -3
  154. package/dist/components/menuItem.d.ts +7 -1
  155. package/dist/components/menuItem.jsx +4 -3
  156. package/dist/components/modal.jsx +12 -23
  157. package/dist/components/onThisPage.d.ts +29 -0
  158. package/dist/components/onThisPage.jsx +151 -0
  159. package/dist/components/pageShell.d.ts +7 -1
  160. package/dist/components/pageShell.jsx +14 -1
  161. package/dist/components/pagination.d.ts +28 -0
  162. package/dist/components/pagination.jsx +89 -0
  163. package/dist/components/popover.jsx +4 -0
  164. package/dist/components/progress.d.ts +33 -0
  165. package/dist/components/progress.jsx +50 -0
  166. package/dist/components/settingsSection.d.ts +6 -1
  167. package/dist/components/settingsSection.jsx +10 -3
  168. package/dist/components/sidePane.d.ts +32 -0
  169. package/dist/components/sidePane.jsx +128 -0
  170. package/dist/components/siteFooter.d.ts +24 -0
  171. package/dist/components/siteFooter.jsx +48 -0
  172. package/dist/components/siteHeader.d.ts +55 -0
  173. package/dist/components/siteHeader.jsx +125 -0
  174. package/dist/components/skeleton.d.ts +21 -0
  175. package/dist/components/skeleton.jsx +41 -0
  176. package/dist/components/statTile.d.ts +32 -0
  177. package/dist/components/statTile.jsx +61 -0
  178. package/dist/components/tableContainer.d.ts +5 -1
  179. package/dist/components/tableContainer.jsx +9 -1
  180. package/dist/components/tableHeaderCell.d.ts +3 -1
  181. package/dist/components/tableHeaderCell.jsx +2 -2
  182. package/dist/components/titleBar.d.ts +19 -0
  183. package/dist/components/titleBar.jsx +18 -0
  184. package/dist/index.d.ts +12 -0
  185. package/dist/index.js +12 -0
  186. package/dist/internal/overlayStack.d.ts +24 -0
  187. package/dist/internal/overlayStack.js +71 -0
  188. package/dist/internal/resize.d.ts +9 -0
  189. package/dist/internal/resize.js +31 -0
  190. package/dist/internal/scrollSpy.d.ts +24 -0
  191. package/dist/internal/scrollSpy.js +53 -0
  192. package/dist/internal/siteBrand.d.ts +6 -0
  193. package/dist/internal/siteBrand.jsx +11 -0
  194. package/dist/native-mapping.json +69 -3
  195. package/dist/stories/AppShell.stories.d.ts +15 -0
  196. package/dist/stories/AppShell.stories.jsx +137 -0
  197. package/dist/stories/Button.stories.d.ts +1 -0
  198. package/dist/stories/Button.stories.jsx +19 -1
  199. package/dist/stories/Cases.generated.stories.d.ts +45 -0
  200. package/dist/stories/Cases.generated.stories.jsx +90 -0
  201. package/dist/stories/Drawer.stories.d.ts +10 -0
  202. package/dist/stories/Drawer.stories.jsx +123 -0
  203. package/dist/stories/Link.stories.d.ts +1 -0
  204. package/dist/stories/Link.stories.jsx +8 -0
  205. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  206. package/dist/stories/OnThisPage.stories.jsx +105 -0
  207. package/dist/stories/Pagination.stories.d.ts +9 -0
  208. package/dist/stories/Pagination.stories.jsx +75 -0
  209. package/dist/stories/Progress.stories.d.ts +9 -0
  210. package/dist/stories/Progress.stories.jsx +43 -0
  211. package/dist/stories/SettingsSection.stories.d.ts +1 -0
  212. package/dist/stories/SettingsSection.stories.jsx +27 -0
  213. package/dist/stories/SidePane.stories.d.ts +6 -0
  214. package/dist/stories/SidePane.stories.jsx +37 -0
  215. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  216. package/dist/stories/SiteFooter.stories.jsx +63 -0
  217. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  218. package/dist/stories/SiteHeader.stories.jsx +94 -0
  219. package/dist/stories/Skeleton.stories.d.ts +7 -0
  220. package/dist/stories/Skeleton.stories.jsx +27 -0
  221. package/dist/stories/StatTile.stories.d.ts +10 -0
  222. package/dist/stories/StatTile.stories.jsx +55 -0
  223. package/dist/stories/Table.stories.d.ts +1 -0
  224. package/dist/stories/Table.stories.jsx +49 -1
  225. package/dist/stories/TitleBar.stories.d.ts +7 -0
  226. package/dist/stories/TitleBar.stories.jsx +41 -0
  227. package/package.json +5 -1
package/dist/cases.json CHANGED
@@ -646,6 +646,86 @@
646
646
  }
647
647
  ]
648
648
  },
649
+ {
650
+ "id": "app-shell",
651
+ "title": "App shell",
652
+ "kind": "design",
653
+ "level": "page",
654
+ "area": "shell",
655
+ "situation": "A person opens the product and moves between its places, such as Inbox, Tasks and Settings, from every page.",
656
+ "do": [
657
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
658
+ "Build the sidebar frame with `AppShell`. Its places are a `Navigation` of `NavigationGroup`s.",
659
+ "Make each place a `MenuItem` with an `href`, and mark the open one with `isSelected` and `aria-current=\"page\"`.",
660
+ "Put the account menu last in the sidebar, built as the case 'Account menu' says.",
661
+ "Give the page's `TitleBar` the page's name as the level 1 heading, and give `AppShell` the place's name as `title`. When the page is the place, the two are the same.",
662
+ "Pass `onSidebarHiddenChange` to `AppShell` so a person can hide the sidebar from `md` up. It adds a 'Hide sidebar' IconButton at the top of the column and a 'Show sidebar' IconButton when it is hidden, and moves focus between them. The phone menu has neither.",
663
+ "Add Cmd+B, or Ctrl+B, with `useHotkey('b', …)`, and have it change the same state. It does nothing while the person types in a field. Ignore it while a Modal, such as the 'Log Out' confirm, is open.",
664
+ "Close the phone menu in the `onClick` of an item in a Popover, such as Settings in the account menu. A choice in a Popover does not close the Drawer by itself.",
665
+ "Render a Modal that the sidebar opens, such as the 'Log Out' confirm, inside the sidebar node, so it is mounted once: in the column or in the Drawer.",
666
+ "Use `TabsContainer fill` with a `Tab` for each place, each with an `href` and the app's `router`, when there are four places or fewer. Name each with one short word.",
667
+ "With tabs across the top, put the name of the app at the start of the bar and the account menu at the end."
668
+ ],
669
+ "dont": [
670
+ "Do not use tabs for more than four places, or for places the person makes.",
671
+ "Do not show the sidebar beside the page on a phone.",
672
+ "Do not hide the sidebar with the shortcut alone. Give a person a visible 'Hide sidebar' button as well.",
673
+ "Do not let the tabs scroll sideways. When they do not fit at 375px, use the sidebar.",
674
+ "Do not mount the sidebar twice, once for the column and once for the menu."
675
+ ],
676
+ "native": "On macOS and iPad use a `NavigationSplitView` with a sidebar `List` in `Section`s. The system adds the hide button and its shortcut. On iPhone use a `TabView` for five places or fewer. On Android use a navigation drawer.",
677
+ "options": [
678
+ {
679
+ "id": "sidebar",
680
+ "title": "Sidebar in groups",
681
+ "useWhen": "There are more than four places, or the person makes some of them, such as projects or channels.",
682
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport Line from 'oneslash-design-system/components/line';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; icon: string; group: string; page: string; text: string };\n\n// The places. The top bar on a phone names the place; the page's own title is the level 1 heading, so a phone never shows the same words twice.\nconst places: Place[] = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox', group: 'Mail', page: 'Unread messages', text: 'Ben Carter shared the launch plan. Omar Reyes asked for the new screens by Friday.' },\n { id: 'sent', label: 'Sent', icon: 'Send', group: 'Mail', page: 'Sent this week', text: 'You sent 4 messages this week.' },\n { id: 'website', label: 'Website', icon: 'Globe', group: 'Projects', page: 'Home page redesign', text: '12 tasks are open. The next review is on Thursday.' },\n { id: 'mobile', label: 'Mobile App', icon: 'Smartphone', group: 'Projects', page: 'Version 2 release', text: '5 tasks are open. Dana Lee owns the release.' },\n];\n\nconst groups = ['Mail', 'Projects'];\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AppShellSidebar() {\n const [placeId, setPlaceId] = useState('inbox');\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n // From md up the person can hide the column for room. The phone menu still has it.\n const [hidden, setHidden] = useState(false);\n const [accountAnchor, setAccountAnchor] = useState<HTMLElement | null>(null);\n const [accountOpen, setAccountOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const accountButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Cmd+B, or Ctrl+B. It does nothing while the person types in a field, and nothing while the Log Out confirm is open.\n useHotkey('b', () => {\n if (!confirming) setHidden((h) => !h);\n });\n\n const place = places.find((p) => p.id === placeId) ?? places[0];\n\n // Cancel, Escape and a click outside. 'Cancel' puts focus back on the account Button, inside the Drawer on a phone.\n function cancelLogOut() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => accountButton.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setPlaceId('inbox'); }} />\n </Cluster>\n </Center>\n );\n }\n\n // The sidebar is mounted once: in the column from md up, in the Drawer below it. Its Modal lives inside it.\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {places.filter((p) => p.group === group).map((p) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === place.id}\n aria-current={p.id === place.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPlaceId(p.id);\n }}\n />\n ))}\n </NavigationGroup>\n ))}\n <Line />\n {/* The account menu is last. */}\n <Cluster>\n <Button\n ref={accountButton}\n size=\"small\"\n type=\"tertiary\"\n state={accountOpen ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={accountOpen}\n onClickButton={(e: { currentTarget: HTMLElement }) => {\n setAccountAnchor(e.currentTarget);\n setAccountOpen((o) => !o);\n }}\n />\n </Cluster>\n <Popover open={accountOpen} anchorEl={accountAnchor} onClose={() => setAccountOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n {/* A choice in a Popover does not close the phone menu: close it here. */}\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => { setAccountOpen(false); setNavOpen(false); }} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => { setAccountOpen(false); setNavOpen(false); }} />\n <Line />\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={() => { setAccountOpen(false); setConfirming(true); }} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancelLogOut}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelLogOut} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Navigation>\n );\n\n const newMessage = <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Message\" decoIcon=\"Plus\" />;\n\n return (\n <AppShell title={place.label} navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar} sidebarHidden={hidden} onSidebarHiddenChange={setHidden}>\n <Stack gap=\"large\">\n <TitleBar\n title={place.page}\n actions={newMessage}\n />\n <Paragraph tone=\"secondary\" measure=\"none\">{place.text}</Paragraph>\n </Stack>\n </AppShell>\n );\n}\n",
683
+ "uses": [
684
+ "AppShell",
685
+ "Button",
686
+ "Center",
687
+ "Cluster",
688
+ "Heading",
689
+ "Line",
690
+ "Menu",
691
+ "MenuItem",
692
+ "Modal",
693
+ "Navigation",
694
+ "NavigationGroup",
695
+ "Paragraph",
696
+ "Popover",
697
+ "Stack",
698
+ "TitleBar",
699
+ "UserImage",
700
+ "useHotkey"
701
+ ]
702
+ },
703
+ {
704
+ "id": "top-tabs",
705
+ "title": "Tabs across the top",
706
+ "useWhen": "There are four places or fewer, all fixed, each with a short name that fits on a phone.",
707
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; page: string; text: string };\n\n// Four fixed places, one short word each, so the tabs fit on a phone.\nconst places: Place[] = [\n { id: 'inbox', label: 'Inbox', page: 'Unread messages', text: 'Ben Carter shared the launch plan. Omar Reyes asked for the new screens by Friday.' },\n { id: 'tasks', label: 'Tasks', page: 'My tasks', text: '7 tasks are open. 2 are due this week.' },\n { id: 'files', label: 'Files', page: 'Recent files', text: 'Omar Reyes added the new screens an hour ago.' },\n { id: 'team', label: 'Team', page: 'People and roles', text: 'Dana Lee, Ben Carter and Omar Reyes are in Acme.' },\n];\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AppShellTopTabs() {\n const [placeId, setPlaceId] = useState('inbox');\n const [accountAnchor, setAccountAnchor] = useState<HTMLElement | null>(null);\n const [accountOpen, setAccountOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const accountButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const place = places.find((p) => p.id === placeId) ?? places[0];\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open place.\n const router = { push: (url: string) => setPlaceId(url.split('/').pop() ?? 'inbox') };\n\n // 'Cancel' puts focus back on the account Button.\n function cancelLogOut() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => accountButton.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setPlaceId('inbox'); }} />\n </Cluster>\n </Center>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* The app's name at the start, the account menu at the end. */}\n <Cluster justify=\"between\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n <Button\n ref={accountButton}\n size=\"small\"\n type=\"tertiary\"\n state={accountOpen ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={accountOpen}\n onClickButton={(e: { currentTarget: HTMLElement }) => {\n setAccountAnchor(e.currentTarget);\n setAccountOpen((o) => !o);\n }}\n />\n </Cluster>\n <TabsContainer fill>\n {places.map((p) => (\n <Tab key={p.id} label={p.label} href={`/${p.id}`} router={router} isSelected={p.id === place.id} onClickTab={() => setPlaceId(p.id)} />\n ))}\n </TabsContainer>\n <TitleBar title={place.page} actions={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Message\" decoIcon=\"Plus\" />} />\n <Paragraph tone=\"secondary\" measure=\"none\">{place.text}</Paragraph>\n </Stack>\n <Popover open={accountOpen} anchorEl={accountAnchor} onClose={() => setAccountOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => setAccountOpen(false)} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => setAccountOpen(false)} />\n <Line />\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={() => { setAccountOpen(false); setConfirming(true); }} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancelLogOut}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelLogOut} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </PageShell>\n );\n}\n",
708
+ "uses": [
709
+ "Button",
710
+ "Center",
711
+ "Cluster",
712
+ "Heading",
713
+ "Line",
714
+ "Menu",
715
+ "MenuItem",
716
+ "Modal",
717
+ "PageShell",
718
+ "Paragraph",
719
+ "Popover",
720
+ "Stack",
721
+ "Tab",
722
+ "TabsContainer",
723
+ "TitleBar",
724
+ "UserImage"
725
+ ]
726
+ }
727
+ ]
728
+ },
649
729
  {
650
730
  "id": "artifact-card",
651
731
  "title": "Document card",
@@ -674,13 +754,16 @@
674
754
  "id": "card",
675
755
  "title": "In the thread",
676
756
  "useWhen": "A reply made a document.",
677
- "source": "'use client';\nimport { Bot, FileText } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Center, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// One sentence on what the agent made. The document itself stays out of the thread.\nconst reply = 'I wrote the launch plan for March 3 as a document.';\n\nconst doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\n// A real app opens the document in a pane beside the thread and moves focus into it.\n// ODS has no side pane part yet, so this example shows the card only.\nfunction openDocument() {}\n\nexport default function ArtifactCardCard() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={FileText} title={doc.title} meta={doc.meta} action=\"Open\" onClick={openDocument} />\n </Grid>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
757
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot, FileText } from 'lucide-react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport SidePane, { type SidePaneHandle } from 'oneslash-design-system/components/sidePane';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// One sentence on what the agent made. The document itself stays out of the thread.\nconst reply = 'I wrote the launch plan for March 3 as a document.';\n\nconst doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nconst docParagraphs = [\n 'Acme ships the new home page on March 3. Omar Reyes owns the copy and Dana Lee the screens.',\n 'Ben Carter writes the announcement once the screens are approved.',\n];\n\n// The threads. A real app lets each link go to its page.\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <MenuItem\n size=\"small\"\n label=\"Launch plan\"\n iconName=\"MessageSquare\"\n href=\"/launch-plan\"\n isSelected\n aria-current=\"page\"\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n </Navigation>\n);\n\nexport default function ArtifactCardCard() {\n const [navOpen, setNavOpen] = useState(false);\n // The pane opens from the card, so focus moves into it and goes back to the card on close.\n const [open, setOpen] = useState(false);\n const pane = useRef<SidePaneHandle>(null);\n\n // Pressed again while the pane is open, the card brings the pane forward instead of opening a second one.\n function openDocument() {\n if (open) pane.current?.focus();\n else setOpen(true);\n }\n\n return (\n <AppShell\n title=\"Launch plan\"\n navOpen={navOpen}\n onNavOpenChange={setNavOpen}\n sidebar={sidebar}\n pane={\n open && (\n <SidePane ref={pane} title={doc.title} onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n {docParagraphs.map((text) => (\n <Paragraph key={text} measure=\"none\">{text}</Paragraph>\n ))}\n </Stack>\n </SidePane>\n )\n }\n >\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={FileText} title={doc.title} meta={doc.meta} action=\"Open\" onClick={openDocument} />\n </Grid>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </AppShell>\n );\n}\n",
678
758
  "uses": [
679
- "Center",
759
+ "AppShell",
680
760
  "Grid",
681
761
  "Heading",
762
+ "MenuItem",
682
763
  "Message",
764
+ "Navigation",
683
765
  "Paragraph",
766
+ "SidePane",
684
767
  "SourceCard",
685
768
  "Stack",
686
769
  "Tag",
@@ -734,6 +817,147 @@
734
817
  }
735
818
  ]
736
819
  },
820
+ {
821
+ "id": "billing-page",
822
+ "title": "Billing page",
823
+ "kind": "design",
824
+ "level": "page",
825
+ "area": "dashboard",
826
+ "situation": "A workspace pays for a plan. One page says what it pays for, what it has used, how it pays and what it has paid.",
827
+ "do": [
828
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
829
+ "Put these `SettingsSection`s in this order under a `TitleBar` named 'Billing': Plan, Usage, Payment method, Invoices. The danger section, if any, comes last.",
830
+ "Show in Plan the plan's name, its price, 'Renews on Dec 1, 2026.' and one 'Change Plan' Button. The price names its unit: '$8.00 per member per month'.",
831
+ "Show the usage as the case 'Usage against limits' says, and the payment method as the case 'Payment method' says.",
832
+ "Show the last three invoices in a short table with a Download link on each row, and a 'See All Invoices' link to the case 'Invoices'.",
833
+ "Show a plan that ends as a `warning` dot `Tag` 'Canceling'. Add the line 'Pro ends on Dec 1, 2026.' and a primary 'Resume Plan' Button in place of 'Change Plan'.",
834
+ "Show a payment that failed as an `error` inline `Alert` at the top, with the date to fix it by: 'Your last payment did not go through. Update the payment method by Nov 30, 2026 to keep Pro.'",
835
+ "Add an error dot `Tag` 'Past due' by the plan name.",
836
+ "Put 'End plan' in a `SettingsSection tone=\"danger\"` as the case 'Danger zone' says. Confirm 'End Plan' in a small `Modal` that says what stays on until when and what is kept. It is confirmed because paid features stop on a date the person must see.",
837
+ "Show a person who cannot change billing every section as text, with no Buttons, and one line: 'Only admins can change billing.'",
838
+ "Say who pays and where for a plan billed elsewhere: 'Ben Carter pays for this plan through an app store.' Say who can change it.",
839
+ "Leave out every control, price, card and invoice on a plan billed elsewhere.",
840
+ "Show a status as the case 'Status in a row' says: 'Past due' and 'Canceling' as dots, 'Paid' as text."
841
+ ],
842
+ "dont": [
843
+ "Do not collect or show a card number. A card is only 'Visa ending in 4821', and it changes on the payment provider's own page.",
844
+ "Do not show Change Plan, Update or End Plan to someone who cannot use them. Show the text and the line that says who can.",
845
+ "Do not leave a failed payment without the date it must be fixed by.",
846
+ "Do not end the plan on the first click. Ask in a Modal first.",
847
+ "Do not name the action 'Cancel Plan'. It would sit beside 'Cancel' in the confirm.",
848
+ "Do not show a plan billed elsewhere with a 'Change Plan' Button that does nothing. Say where to change it.",
849
+ "Do not write 'Canceled' for a plan that is still on. Say 'Canceling' and when it ends."
850
+ ],
851
+ "native": "On Apple a plan bought in the app is managed in the system subscription sheet. Show who pays and open that sheet from one Button, never a card form.",
852
+ "options": [
853
+ {
854
+ "id": "self-serve",
855
+ "title": "An admin pays here",
856
+ "useWhen": "The person who manages billing changes the plan, the card and the cancel on this page.",
857
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Link from 'oneslash-design-system/components/link';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change billing.\nconst isAdmin = true;\n\n// A real app reads this from the server: set when the last payment failed.\nconst failedPayment: { fixBy: string } | null = { fixBy: 'Nov 30, 2026' };\n\nconst invoices = [\n { id: 'inv-0', date: 'Nov 1, 2026', amount: 24, status: 'Paid' },\n { id: 'inv-1', date: 'Oct 1, 2026', amount: 24, status: 'Paid' },\n { id: 'inv-2', date: 'Sep 1, 2026', amount: 24, status: 'Paid' },\n];\n\nexport default function BillingPageSelfServe() {\n const [canceling, setCanceling] = useState(false);\n const [confirmOpen, setConfirmOpen] = useState(false);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Stands in for the request to the server.\n function request(done: () => void) {\n if (busy) return;\n setBusy(true);\n timer.current = setTimeout(() => {\n setBusy(false);\n done();\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setConfirmOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <TitleBar title=\"Billing\" />\n {failedPayment && (\n <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={`Your last payment did not go through. Update the payment method by ${failedPayment.fixBy} to keep Pro.`} />\n )}\n <SettingsSection id=\"billing-page-plan\" title=\"Plan\" description=\"What Acme pays for.\">\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"h6\">Pro</Heading>\n {failedPayment && <Tag variant=\"dot\" size=\"small\" color=\"error\" label=\"Past due\" />}\n {canceling && <Tag variant=\"dot\" size=\"small\" color=\"warning\" label=\"Canceling\" />}\n </Cluster>\n <Paragraph size=\"body2\" measure=\"none\">{`${formatMoney(8)} per member per month`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{canceling ? 'Pro ends on Dec 1, 2026.' : 'Renews on Dec 1, 2026.'}</Paragraph>\n </Stack>\n {isAdmin ? (\n <Cluster gap=\"small\">\n {canceling ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Resume Plan\" loading={busy} onClickButton={() => request(() => setCanceling(false))} />\n ) : (\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" onClickButton={() => router.push('/settings/billing/plans')} />\n )}\n </Cluster>\n ) : (\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change billing.</Paragraph>\n )}\n </SettingsSection>\n <SettingsSection id=\"billing-page-usage\" title=\"Usage\" description=\"This month.\">\n <Stack gap=\"medium\">\n <Progress label=\"AI agent responses\" value={312} max={1000} unit=\"responses\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n <Progress label=\"Members\" value={3} max={null} unit=\"members\" />\n </Stack>\n </SettingsSection>\n <SettingsSection id=\"billing-page-payment\" title=\"Payment method\" description=\"Pays for Acme's plan.\">\n <Surface padding=\"small\">\n <Cluster justify=\"between\" gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">Visa ending in 4821</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Expires 08/28</Paragraph>\n </Stack>\n {isAdmin && (\n // A real app hands off to its payment provider's own page here. The page never takes card details.\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Update\" aria-label=\"Update Visa ending in 4821, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n )}\n </Cluster>\n </Surface>\n {/* Pro needs a card, so there is no Remove here. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Pro needs a card on file. Downgrade to Free to remove it.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"billing-page-invoices\" title=\"Invoices\" description=\"The last three.\">\n <TableContainer aria-label=\"Recent invoices\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"140px\">Date</TableHeaderCell>\n <TableHeaderCell width=\"110px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell>Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {invoices.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n <TableCell width=\"110px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell><Tag variant=\"textOnly\" size=\"small\" label={inv.status} /></TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. */}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Download\" aria-label={`Download invoice for ${inv.date}, opens in a new tab`} actionIcon=\"ExternalLink\" href={`https://acme.example/invoices/${inv.id}.pdf`} openInNewTab />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n <Link href=\"/settings/billing/invoices\" size=\"body2\">See All Invoices</Link>\n </SettingsSection>\n {isAdmin && !canceling && (\n // The last section on the page, in the danger color, as the case 'Danger zone' says.\n <SettingsSection id=\"billing-page-cancel\" tone=\"danger\" title=\"End plan\" description=\"Pro stays on until Dec 1, 2026.\">\n <Paragraph size=\"body2\" measure=\"none\">Acme goes back to Free on Dec 1, 2026. Its members and messages stay.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"End Plan\" onClickButton={() => setConfirmOpen(true)} />\n </Cluster>\n </SettingsSection>\n )}\n </Stack>\n <Modal\n isOpen={confirmOpen}\n size=\"small\"\n title=\"End Plan\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"End Plan\" loading={busy} onClickButton={() => request(() => { setConfirmOpen(false); setCanceling(true); })} />\n </>\n }\n >\n <Paragraph measure=\"none\">Pro stays on until Dec 1, 2026. After that Acme is on Free, which allows 3 members and 50 AI agent responses a month.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Nothing is deleted. You can resume the plan until then.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
858
+ "uses": [
859
+ "Alert",
860
+ "Button",
861
+ "Center",
862
+ "Cluster",
863
+ "Heading",
864
+ "Link",
865
+ "Modal",
866
+ "Paragraph",
867
+ "Progress",
868
+ "SettingsSection",
869
+ "Stack",
870
+ "Surface",
871
+ "TableCell",
872
+ "TableContainer",
873
+ "TableHeader",
874
+ "TableHeaderCell",
875
+ "TableRow",
876
+ "Tag",
877
+ "TitleBar",
878
+ "formatMoney"
879
+ ]
880
+ },
881
+ {
882
+ "id": "billed-elsewhere",
883
+ "title": "Billed elsewhere",
884
+ "useWhen": "An app store bills the plan, or another person pays for it, so this page only says who pays and where to change it.",
885
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function BillingPageBilledElsewhere() {\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <TitleBar title=\"Billing\" />\n <SettingsSection id=\"billing-elsewhere-plan\" title=\"Plan\" description=\"What Acme pays for.\">\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">Pro</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Renews on Dec 1, 2026.</Paragraph>\n </Stack>\n {/* No price, card or invoice: the app store that bills this plan keeps them. The page says who pays, where, and who can change it. */}\n <Paragraph size=\"body2\" measure=\"none\">Ben Carter pays for this plan through an app store. Only Ben Carter can change or cancel it, in the app store settings on the device that bought it.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"billing-elsewhere-usage\" title=\"Usage\" description=\"This month.\">\n <Stack gap=\"medium\">\n <Progress label=\"AI agent responses\" value={312} max={1000} unit=\"responses\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n </Stack>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
886
+ "uses": [
887
+ "Center",
888
+ "Heading",
889
+ "Paragraph",
890
+ "Progress",
891
+ "SettingsSection",
892
+ "Stack",
893
+ "TitleBar"
894
+ ]
895
+ }
896
+ ]
897
+ },
898
+ {
899
+ "id": "breakdown-list",
900
+ "title": "Breakdown of a total",
901
+ "kind": "design",
902
+ "level": "organism",
903
+ "area": "dashboard",
904
+ "situation": "A page shows how a total splits into parts, such as responses by model or comments by project.",
905
+ "do": [
906
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
907
+ "Say the total and its range above the list: '1,240 responses this week.'",
908
+ "Sort by the main number, largest first, in both options.",
909
+ "Use one `Progress kind=\"share\"` for each part in the bars, with `max` the total and `unit` the thing counted: '41%, 512 responses'. Put them in a `List`.",
910
+ "Show the largest seven parts and fold the rest into 'Other', so the list is never longer than eight rows.",
911
+ "Give the table's `TableContainer` an `aria-label` and a `minWidth`, mark the sorted column with `sort`, and right-align the numbers.",
912
+ "Show the exact number in a table, a share column from `formatPercent` and a cost from `formatMoney`. A cost under a cent reads '< $0.01'.",
913
+ "End the table with a Total row."
914
+ ],
915
+ "dont": [
916
+ "Do not use a donut or a stacked bar. Color carries nothing here, so no legend is needed.",
917
+ "Do not give each part its own color.",
918
+ "Do not show a part with no name, or a share with no count.",
919
+ "Do not list more than eight bars. Use the table.",
920
+ "Do not show a share of 0 for a part that has data. A small share reads '< 1%'."
921
+ ],
922
+ "native": "On Apple use a `List` of rows with a `Gauge` or a `ProgressView(value:total:)`, or a `Table` for the table. On Android use a `LazyColumn` of rows with a `LinearProgressIndicator`.",
923
+ "options": [
924
+ {
925
+ "id": "bars",
926
+ "title": "Ranked bars",
927
+ "useWhen": "There are up to about eight parts of one total, and the person reads them in order.",
928
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst models = [\n { name: 'Atlas Large', count: 512 },\n { name: 'Atlas Medium', count: 301 },\n { name: 'Birch 4', count: 168 },\n { name: 'Birch 4 Mini', count: 96 },\n { name: 'Cedar Pro', count: 62 },\n { name: 'Cedar Lite', count: 41 },\n { name: 'Delta 2', count: 28 },\n { name: 'Delta 1', count: 17 },\n { name: 'Elm', count: 9 },\n { name: 'Fern', count: 6 },\n];\n\n// The largest seven are listed and the rest fold into 'Other', so the list is never longer than eight rows.\nconst sorted = [...models].sort((a, b) => b.count - a.count);\nconst total = sorted.reduce((sum, m) => sum + m.count, 0);\nconst rest = sorted.slice(7).reduce((sum, m) => sum + m.count, 0);\nconst parts = [...sorted.slice(0, 7), ...(rest > 0 ? [{ name: 'Other', count: rest }] : [])];\n\nexport default function BreakdownListBars() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">Responses by model</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{formatCount(total)} responses this week.</Paragraph>\n </Stack>\n <List\n size=\"body2\"\n items={parts.map((p) => (\n // `max` is the total, so each bar is the part's share. A share is not a limit, so it never turns to a warning.\n <Progress key={p.name} kind=\"share\" label={p.name} value={p.count} max={total} unit=\"responses\" />\n ))}\n />\n </Stack>\n </Center>\n );\n}\n",
929
+ "uses": [
930
+ "Center",
931
+ "Heading",
932
+ "List",
933
+ "Paragraph",
934
+ "Progress",
935
+ "Stack",
936
+ "formatCount"
937
+ ]
938
+ },
939
+ {
940
+ "id": "table",
941
+ "title": "Table with a share column",
942
+ "useWhen": "There are more parts, or the parts are compared on two numbers, such as responses and cost.",
943
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney, formatPercent } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst models = [\n { name: 'Atlas Large', responses: 5120, cost: 61.4 },\n { name: 'Atlas Medium', responses: 3010, cost: 18.06 },\n { name: 'Birch 4', responses: 1680, cost: 12.3 },\n { name: 'Birch 4 Mini', responses: 960, cost: 1.92 },\n { name: 'Cedar Pro', responses: 620, cost: 4.65 },\n { name: 'Cedar Lite', responses: 410, cost: 0.41 },\n { name: 'Delta 2', responses: 280, cost: 0.84 },\n { name: 'Delta 1', responses: 170, cost: 0.17 },\n { name: 'Elm', responses: 90, cost: 0.004 },\n { name: 'Fern', responses: 60, cost: 0 },\n];\n\n// Largest first: the table is sorted by its main number.\nconst rows = [...models].sort((a, b) => b.responses - a.responses);\nconst total = rows.reduce((sum, m) => sum + m.responses, 0);\nconst totalCost = rows.reduce((sum, m) => sum + m.cost, 0);\n\nexport default function BreakdownListTable() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">Responses and cost by model</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{formatCount(total)} responses this month, largest first.</Paragraph>\n </Stack>\n {/* A named table sits in a region that scrolls sideways by itself, so the page never does. */}\n <TableContainer aria-label=\"Responses and cost by model\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Model</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"120px\" sort=\"descending\">Responses</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"90px\">Share</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"110px\">Cost</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((m) => (\n <TableRow key={m.name}>\n <TableCell>{m.name}</TableCell>\n <TableCell align=\"right\" width=\"120px\">{formatCount(m.responses)}</TableCell>\n <TableCell align=\"right\" width=\"90px\">{formatPercent(m.responses / total)}</TableCell>\n <TableCell align=\"right\" width=\"110px\">{formatMoney(m.cost)}</TableCell>\n </TableRow>\n ))}\n <TableRow>\n <TableCell>Total</TableCell>\n <TableCell align=\"right\" width=\"120px\">{formatCount(total)}</TableCell>\n <TableCell align=\"right\" width=\"90px\">{formatPercent(1)}</TableCell>\n <TableCell align=\"right\" width=\"110px\">{formatMoney(totalCost)}</TableCell>\n </TableRow>\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
944
+ "uses": [
945
+ "Center",
946
+ "Heading",
947
+ "Paragraph",
948
+ "Stack",
949
+ "TableCell",
950
+ "TableContainer",
951
+ "TableHeader",
952
+ "TableHeaderCell",
953
+ "TableRow",
954
+ "formatCount",
955
+ "formatMoney",
956
+ "formatPercent"
957
+ ]
958
+ }
959
+ ]
960
+ },
737
961
  {
738
962
  "id": "check-your-email",
739
963
  "title": "Check your email",
@@ -846,7 +1070,7 @@
846
1070
  "kind": "design",
847
1071
  "level": "organism",
848
1072
  "area": "chat",
849
- "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its agent replies for the month.",
1073
+ "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its AI agent responses for the month.",
850
1074
  "do": [
851
1075
  "Follow the rule 'An agent refuses clearly' word for word: \"You've used all 50 AI agent responses this month.\"",
852
1076
  "Put the notice in the Composer's `above` slot: `<Alert variant=\"inline\" autoDismiss={false}>`, with no close button on the Alert itself.",
@@ -854,7 +1078,7 @@
854
1078
  "Give everyone 'Not Now', a tertiary Button, so the refusal can be closed. Put the Buttons in a `Cluster` under the Alert.",
855
1079
  "Give a person who can lift the limit the action after 'Not Now', as a primary Button, such as 'Upgrade to Pro'.",
856
1080
  "Keep the agent toggle pressable while the limit stands, as the case 'Upgrade prompt' says. Pressing it shows the notice again, and it does not turn on.",
857
- "Say in the placeholder when agent replies start again, once the person chose 'Not Now'.",
1081
+ "Say in the placeholder when AI agent responses start again, once the person chose 'Not Now'.",
858
1082
  "Move focus to the message box after 'Not Now', since the Button that had it is gone.",
859
1083
  "Keep the field and send working, so messages to people still go.",
860
1084
  "Follow the case 'Upgrade prompt' for a limit reached anywhere outside the message box."
@@ -872,7 +1096,7 @@
872
1096
  "id": "notice",
873
1097
  "title": "Notice",
874
1098
  "useWhen": "The person cannot lift the limit.",
875
- "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNotice() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-notice-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person cannot change the plan, so it says who can. Everyone can close a refusal. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. Ask a workspace admin to upgrade Acme Design to Pro for more replies.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
1099
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNotice() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-notice-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when AI agent responses start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. AI agent responses start again on Dec 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person cannot change the plan, so it says who can. Everyone can close a refusal. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on Dec 1. Ask a workspace admin to upgrade Acme Design to Pro for more replies.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
876
1100
  "uses": [
877
1101
  "Alert",
878
1102
  "Button",
@@ -893,7 +1117,7 @@
893
1117
  "id": "notice-with-action",
894
1118
  "title": "Notice with an action",
895
1119
  "useWhen": "The person can lift the limit.",
896
- "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNoticeWithAction() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-action-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person can change the plan, so they get the button that lifts the limit. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. The Pro plan gives Acme Design 1,000 AI agent responses a month.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
1120
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNoticeWithAction() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-action-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when AI agent responses start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. AI agent responses start again on Dec 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person can change the plan, so they get the button that lifts the limit. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on Dec 1. The Pro plan gives Acme Design 1,000 AI agent responses a month.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
897
1121
  "uses": [
898
1122
  "Alert",
899
1123
  "Button",
@@ -1198,6 +1422,201 @@
1198
1422
  }
1199
1423
  ]
1200
1424
  },
1425
+ {
1426
+ "id": "dashboard",
1427
+ "title": "Dashboard",
1428
+ "kind": "design",
1429
+ "level": "page",
1430
+ "area": "dashboard",
1431
+ "situation": "A page that opens an app and says how things are going and what waits on the person.",
1432
+ "do": [
1433
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1434
+ "Put the page in `AppShell`, with a `TitleBar` named 'Dashboard' and a 'Range' `SegmentedControl` as its `actions`, as the case 'Range switch' says. Set `actionsBelow` so the switch takes its own line under the title on a phone.",
1435
+ "Let the one range drive every number on the page, and name it in every heading and caption: 'this week'.",
1436
+ "Show the stat row as the case 'Stat row' says, and a share of a total as the case 'Breakdown of a total' says.",
1437
+ "Make each section a `SettingsSection`: a hairline, a title and its content. Do not put a section in a box.",
1438
+ "Put the list of what waits on the person in a section titled with its count and unit: '3 comments waiting on you'. Make each row a link.",
1439
+ "Show a list that can be longer than its section as the case 'Short list on a dashboard' says.",
1440
+ "Show `EmptyBox size=\"small\"` in a section with nothing, as the rule 'An empty list says what will fill it' says: 'No questions from your agents this week'. Keep the section.",
1441
+ "Show a failed section as the case 'Load failure' says, inline with 'Try Again', and keep the rest of the page.",
1442
+ "Show a `Skeleton` or the tile's own loading state while the range changes. Do not show 0."
1443
+ ],
1444
+ "dont": [
1445
+ "Do not draw a chart. A trend is the change line on a tile, and a share is a ranked list.",
1446
+ "Do not count different sections over different ranges.",
1447
+ "Do not replace the whole page when one section failed.",
1448
+ "Do not put more than four tiles in the stat row.",
1449
+ "Do not hide a section that has nothing, or leave it blank.",
1450
+ "Do not box the sections in cards."
1451
+ ],
1452
+ "native": "On Apple use a `List` of `Section`s in a `NavigationStack`, with a `Picker` in the `.segmented` style in the toolbar. On Android use a `LazyColumn` with a `SingleChoiceSegmentedButtonRow` in the top bar.",
1453
+ "options": [
1454
+ {
1455
+ "id": "numbers-first",
1456
+ "title": "Numbers first",
1457
+ "useWhen": "The page reports how things went, for a lead who checks on a team.",
1458
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype Range = 'week' | 'month' | 'quarter';\nconst ranges = [\n { value: 'week', label: 'Week' },\n { value: 'month', label: 'Month' },\n { value: 'quarter', label: 'Quarter' },\n];\n\n// A real app counts these on the server. One range drives every number on the page.\nconst data = {\n week: {\n stats: { comments: [1240, 1106], done: [312, 280], people: [18, 18], reply: [8_640_000, 9_200_000] },\n projects: [['Website', 540], ['Mobile App', 380], ['Docs', 320]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ],\n questions: [],\n },\n month: {\n stats: { comments: [4820, 5210], done: [1190, 1004], people: [31, 27], reply: [7_800_000, 8_100_000] },\n projects: [['Website', 2010], ['Mobile App', 1500], ['Docs', 910], ['Help Center', 400]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ['Approve the new onboarding text', '/comments/5'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2']],\n },\n quarter: {\n stats: { comments: [15_880, 12_410], done: [3950, 3210], people: [44, 36], reply: [7_200_000, 7_900_000] },\n projects: [['Website', 6100], ['Mobile App', 4800], ['Docs', 3100], ['Help Center', 1880]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2'], ['Which logo should the launch page use?', '/questions/3']],\n },\n} as const;\n\nconst noun: Record<Range, string> = { week: 'this week', month: 'this month', quarter: 'this quarter' };\n\nexport default function DashboardNumbersFirst() {\n const [range, setRange] = useState<Range>('week');\n // The numbers load again when the range changes.\n const [loading, setLoading] = useState(false);\n // The projects section fails first, so the rest of the page shows that one section can fail alone.\n const [projectsFailed, setProjectsFailed] = useState(true);\n const [retrying, setRetrying] = useState(false);\n const [navOpen, setNavOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const retryTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the requests if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(retryTimer.current);\n }, []);\n\n function changeRange(next: string) {\n clearTimeout(timer.current);\n setRange(next as Range);\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 600);\n }\n\n function tryAgain() {\n if (retrying) return;\n setRetrying(true);\n retryTimer.current = setTimeout(() => {\n setRetrying(false);\n setProjectsFailed(false);\n }, 1200);\n }\n\n const d = data[range];\n const period = range;\n const projectTotal = d.projects.reduce((sum, p) => sum + p[1], 0);\n const waitingCount: number = d.waiting.length;\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {[\n ['Dashboard', 'LayoutDashboard', '/dashboard'],\n ['Comments', 'MessageSquare', '/comments'],\n ['Projects', 'FolderKanban', '/projects'],\n ].map(([label, icon, href]) => (\n <MenuItem\n key={href}\n size=\"small\"\n label={label}\n iconName={icon}\n href={href}\n isSelected={href === '/dashboard'}\n aria-current={href === '/dashboard' ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Navigation>\n );\n\n const statRow = (\n <SettingsSection key=\"stats\" title={`Numbers ${noun[range]}`} id=\"dashboard-stats\">\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />\n <StatTile label=\"Marked done\" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />\n <StatTile label=\"People engaged\" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />\n <StatTile label=\"Average reply time\" value={d.stats.reply[0]} format=\"duration\" previous={d.stats.reply[1]} period={period} loading={loading} />\n </Grid>\n </SettingsSection>\n );\n\n const projects = (\n <SettingsSection key=\"projects\" title=\"Projects\" description={`${formatCount(projectTotal)} comments ${noun[range]}, by project`} id=\"dashboard-projects\">\n {projectsFailed ? (\n <>\n {/* Only this section failed. The rest of the page still shows. */}\n <Alert type=\"error\" variant=\"inline\" message=\"Could not load projects.\" autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={retrying} onClickButton={tryAgain} />\n </Cluster>\n </>\n ) : loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading projects\" />\n ) : (\n <List\n size=\"body2\"\n items={d.projects.map(([name, count]) => (\n <Progress key={name} kind=\"share\" label={name} value={count} max={projectTotal} unit=\"comments\" />\n ))}\n />\n )}\n </SettingsSection>\n );\n\n const waiting = (\n <SettingsSection key=\"waiting\" title={loading ? 'Waiting on you' : `${formatCount(waitingCount)} ${waitingCount === 1 ? 'comment' : 'comments'} waiting on you`} description={`Asked of you ${noun[range]}`} id=\"dashboard-waiting\">\n {loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading what waits on you\" />\n ) : (\n <Stack gap=\"small\">\n {d.waiting.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n const questions = (\n <SettingsSection key=\"questions\" title=\"Questions from your agents\" id=\"dashboard-questions\">\n {loading ? (\n <Skeleton variant=\"text\" lines={2} label=\"Loading questions\" />\n ) : d.questions.length === 0 ? (\n // A section with nothing keeps its place and says what will fill it.\n <EmptyBox size=\"small\" text={`No questions from your agents ${noun[range]}`} secondText=\"Questions your agents ask you appear here.\" />\n ) : (\n <Stack gap=\"small\">\n {d.questions.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n return (\n <AppShell title=\"Dashboard\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Stack gap=\"xlarge\">\n {/* One range drives every number below, and each heading says which one. */}\n {/* Below md the range switch takes its own line under the title. */}\n <TitleBar\n title=\"Dashboard\"\n actionsBelow\n actions={<SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Range\" options={ranges} value={range} onChange={changeRange} />}\n />\n {statRow}\n {projects}\n {waiting}\n {questions}\n </Stack>\n </AppShell>\n );\n}\n",
1459
+ "uses": [
1460
+ "Alert",
1461
+ "AppShell",
1462
+ "Button",
1463
+ "Cluster",
1464
+ "EmptyBox",
1465
+ "Grid",
1466
+ "List",
1467
+ "MenuItem",
1468
+ "Navigation",
1469
+ "Paragraph",
1470
+ "Progress",
1471
+ "SegmentedControl",
1472
+ "SettingsSection",
1473
+ "Skeleton",
1474
+ "Stack",
1475
+ "StatTile",
1476
+ "TitleBar",
1477
+ "formatCount"
1478
+ ]
1479
+ },
1480
+ {
1481
+ "id": "work-first",
1482
+ "title": "Work first",
1483
+ "useWhen": "The person starts their day here, so what waits on them comes before the numbers.",
1484
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype Range = 'week' | 'month' | 'quarter';\nconst ranges = [\n { value: 'week', label: 'Week' },\n { value: 'month', label: 'Month' },\n { value: 'quarter', label: 'Quarter' },\n];\n\n// A real app counts these on the server. One range drives every number on the page.\nconst data = {\n week: {\n stats: { comments: [1240, 1106], done: [312, 280], people: [18, 18], reply: [8_640_000, 9_200_000] },\n projects: [['Website', 540], ['Mobile App', 380], ['Docs', 320]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ],\n questions: [],\n },\n month: {\n stats: { comments: [4820, 5210], done: [1190, 1004], people: [31, 27], reply: [7_800_000, 8_100_000] },\n projects: [['Website', 2010], ['Mobile App', 1500], ['Docs', 910], ['Help Center', 400]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ['Approve the new onboarding text', '/comments/5'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2']],\n },\n quarter: {\n stats: { comments: [15_880, 12_410], done: [3950, 3210], people: [44, 36], reply: [7_200_000, 7_900_000] },\n projects: [['Website', 6100], ['Mobile App', 4800], ['Docs', 3100], ['Help Center', 1880]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2'], ['Which logo should the launch page use?', '/questions/3']],\n },\n} as const;\n\nconst noun: Record<Range, string> = { week: 'this week', month: 'this month', quarter: 'this quarter' };\n\nexport default function DashboardWorkFirst() {\n const [range, setRange] = useState<Range>('week');\n // The numbers load again when the range changes.\n const [loading, setLoading] = useState(false);\n // The projects section fails first, so the rest of the page shows that one section can fail alone.\n const [projectsFailed, setProjectsFailed] = useState(true);\n const [retrying, setRetrying] = useState(false);\n const [navOpen, setNavOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const retryTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the requests if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(retryTimer.current);\n }, []);\n\n function changeRange(next: string) {\n clearTimeout(timer.current);\n setRange(next as Range);\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 600);\n }\n\n function tryAgain() {\n if (retrying) return;\n setRetrying(true);\n retryTimer.current = setTimeout(() => {\n setRetrying(false);\n setProjectsFailed(false);\n }, 1200);\n }\n\n const d = data[range];\n const period = range;\n const projectTotal = d.projects.reduce((sum, p) => sum + p[1], 0);\n const waitingCount: number = d.waiting.length;\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {[\n ['Dashboard', 'LayoutDashboard', '/dashboard'],\n ['Comments', 'MessageSquare', '/comments'],\n ['Projects', 'FolderKanban', '/projects'],\n ].map(([label, icon, href]) => (\n <MenuItem\n key={href}\n size=\"small\"\n label={label}\n iconName={icon}\n href={href}\n isSelected={href === '/dashboard'}\n aria-current={href === '/dashboard' ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Navigation>\n );\n\n const statRow = (\n <SettingsSection key=\"stats\" title={`Numbers ${noun[range]}`} id=\"dashboard-stats\">\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />\n <StatTile label=\"Marked done\" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />\n <StatTile label=\"People engaged\" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />\n <StatTile label=\"Average reply time\" value={d.stats.reply[0]} format=\"duration\" previous={d.stats.reply[1]} period={period} loading={loading} />\n </Grid>\n </SettingsSection>\n );\n\n const projects = (\n <SettingsSection key=\"projects\" title=\"Projects\" description={`${formatCount(projectTotal)} comments ${noun[range]}, by project`} id=\"dashboard-projects\">\n {projectsFailed ? (\n <>\n {/* Only this section failed. The rest of the page still shows. */}\n <Alert type=\"error\" variant=\"inline\" message=\"Could not load projects.\" autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={retrying} onClickButton={tryAgain} />\n </Cluster>\n </>\n ) : loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading projects\" />\n ) : (\n <List\n size=\"body2\"\n items={d.projects.map(([name, count]) => (\n <Progress key={name} kind=\"share\" label={name} value={count} max={projectTotal} unit=\"comments\" />\n ))}\n />\n )}\n </SettingsSection>\n );\n\n const waiting = (\n <SettingsSection key=\"waiting\" title={loading ? 'Waiting on you' : `${formatCount(waitingCount)} ${waitingCount === 1 ? 'comment' : 'comments'} waiting on you`} description={`Asked of you ${noun[range]}`} id=\"dashboard-waiting\">\n {loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading what waits on you\" />\n ) : (\n <Stack gap=\"small\">\n {d.waiting.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n const questions = (\n <SettingsSection key=\"questions\" title=\"Questions from your agents\" id=\"dashboard-questions\">\n {loading ? (\n <Skeleton variant=\"text\" lines={2} label=\"Loading questions\" />\n ) : d.questions.length === 0 ? (\n // A section with nothing keeps its place and says what will fill it.\n <EmptyBox size=\"small\" text={`No questions from your agents ${noun[range]}`} secondText=\"Questions your agents ask you appear here.\" />\n ) : (\n <Stack gap=\"small\">\n {d.questions.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n return (\n <AppShell title=\"Dashboard\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Stack gap=\"xlarge\">\n {/* One range drives every number below, and each heading says which one. */}\n {/* Below md the range switch takes its own line under the title. */}\n <TitleBar\n title=\"Dashboard\"\n actionsBelow\n actions={<SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Range\" options={ranges} value={range} onChange={changeRange} />}\n />\n {waiting}\n {questions}\n {statRow}\n {projects}\n </Stack>\n </AppShell>\n );\n}\n",
1485
+ "uses": [
1486
+ "Alert",
1487
+ "AppShell",
1488
+ "Button",
1489
+ "Cluster",
1490
+ "EmptyBox",
1491
+ "Grid",
1492
+ "List",
1493
+ "MenuItem",
1494
+ "Navigation",
1495
+ "Paragraph",
1496
+ "Progress",
1497
+ "SegmentedControl",
1498
+ "SettingsSection",
1499
+ "Skeleton",
1500
+ "Stack",
1501
+ "StatTile",
1502
+ "TitleBar",
1503
+ "formatCount"
1504
+ ]
1505
+ }
1506
+ ]
1507
+ },
1508
+ {
1509
+ "id": "data-table-page",
1510
+ "title": "Data table page",
1511
+ "kind": "design",
1512
+ "level": "page",
1513
+ "area": "dashboard",
1514
+ "situation": "A page is one long table of records, such as invoices or customers, that a person searches, sorts and acts on.",
1515
+ "do": [
1516
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1517
+ "Put the page in `AppShell` as the case 'App shell' says, with a `TitleBar` named for the records: 'Invoices'. Under it say the total and its unit: '290 invoices'.",
1518
+ "Put search and a filter above the table, in a row at the end. Use the case 'Collapsible search' for the search, so the row fits a phone, and the case 'Filter menu' for the filter.",
1519
+ "Say what search and filter leave in the line under the title: '43 of 290 invoices match \"north\", past due.'",
1520
+ "Wait a moment after the last key before you ask the server for a search.",
1521
+ "Sort a column with the Button in its `TableHeaderCell`, as the case 'Members' says. Set `sort` on the header cell of the sorted column only, and leave it unset on the others. The Button is named by its label alone, such as 'Date'.",
1522
+ "Right-align a number column and its header, and show the exact amount: '$1,240.00'.",
1523
+ "Give each row one More menu, named for the row: 'More actions for INV-1290'. Follow the case 'More menu'. Keep every action in the menu, not as Buttons in the row.",
1524
+ "Show the status as the case 'Status in a row' says.",
1525
+ "Name the table with `TableContainer aria-label=\"Invoices\"` and give it a `minWidth`. A phone scrolls the table inside its named region, never the page.",
1526
+ "Show 25 rows a page when the pages come from the server, with `Pagination` named for the table below it: 'Invoice pages'. Pass `scrollTargetId` so a press of Next scrolls to the top of the page. Focus stays on Next.",
1527
+ "Pass ``getHref={(p) => '/invoices?page=' + p}`` when each page has its own address.",
1528
+ "Go back to page 1 after a sort, a search or a filter, and let the pager follow. With all the rows on the page, show no pager and no loading state.",
1529
+ "Keep the header and the pager while a page loads, and show 10 `Skeleton` rows. Give the first Skeleton a `label` such as 'Loading invoices', so a screen reader hears one status. Show a `Skeleton` in place of the count too.",
1530
+ "Show the case 'Empty list' in the table's place when there are no rows at all: 'No invoices yet', with 'Your first invoice appears here after your first payment.'",
1531
+ "Show the case 'Empty search' with the words searched for when no row matches. Its Button is 'Clear Search' when only words are on, and 'Clear Filter' when a filter is on too. It clears both. Focus goes to the search button.",
1532
+ "Show the case 'Load failure' in the table's place when a page fails to load. 'Try Again' is `loading` while it asks again and keeps its label. Keep the title and the pager.",
1533
+ "Reach the page from a card's 'See All' link, as the case 'Short list on a dashboard' says."
1534
+ ],
1535
+ "dont": [
1536
+ "Do not replace the page with a spinner while a page loads. Keep the header and the pager.",
1537
+ "Do not show 0 for a total that is loading or failed.",
1538
+ "Do not show page 4 of the old list after a new sort or filter. Go back to page 1.",
1539
+ "Do not show 'No results' with no words, or the list's own empty text when a search found nothing.",
1540
+ "Do not put a Button for every action in each row. Use one More menu.",
1541
+ "Do not leave a table that can scroll sideways without a name.",
1542
+ "Do not put `sort` on more than one header cell.",
1543
+ "Do not number the pages as a row of buttons. A phone has no room, and 500 pages have no end.",
1544
+ "Do not page a list of under 50 rows."
1545
+ ],
1546
+ "native": "On Apple use a `Table` with `KeyPathComparator` for the sort columns, `.searchable` for search, and a `Menu` in the toolbar for the filter. On Android use a `LazyColumn` of rows with a `SearchBar`, and load the next page when the end comes into view.",
1547
+ "options": [
1548
+ {
1549
+ "id": "paged",
1550
+ "title": "Pages from the server",
1551
+ "useWhen": "There are more rows than fit on a page, they come from the server, and the page holds 25 of them.",
1552
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Status = 'Paid' | 'Past due' | 'Refunded';\ntype Invoice = { id: string; number: string; customer: string; day: number; date: string; cents: number; status: Status };\ntype SortBy = 'customer' | 'date' | 'amount';\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app asks the server for one page. This makes the 290 invoices the server would hold, newest first.\nconst all: Invoice[] = Array.from({ length: 290 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 28 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1290 - i}`,\n customer: customers[(i * 7 + 3) % customers.length],\n day: i,\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',\n };\n});\n\nconst statuses: Status[] = ['Paid', 'Past due', 'Refunded'];\nconst PAGE_SIZE = 25;\n\nexport default function DataTablePagePaged() {\n const [query, setQuery] = useState('');\n const [status, setStatus] = useState<Status | null>(null);\n // Opens newest first.\n const [sort, setSort] = useState<{ by: SortBy; dir: 'ascending' | 'descending' }>({ by: 'date', dir: 'descending' });\n const [page, setPage] = useState(1);\n const [loading, setLoading] = useState(false);\n const [failed, setFailed] = useState(false);\n\n const [searchAnchor, setSearchAnchor] = useState<HTMLElement | null>(null);\n const [searchOpen, setSearchOpen] = useState(false);\n const [filterAnchor, setFilterAnchor] = useState<HTMLElement | null>(null);\n const [filterOpen, setFilterOpen] = useState(false);\n const [menuRow, setMenuRow] = useState<Invoice | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const failedOnce = useRef(false);\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const searchButton = useRef<Focusable>(null);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // The server sorts and filters, so the page asks it again for every change. The header and the pager stay while it answers.\n function request(forPage: number) {\n clearTimeout(timer.current);\n setLoading(true);\n timer.current = setTimeout(() => {\n setLoading(false);\n // The failure stays on screen, with its Button, until the new answer arrives.\n setFailed(false);\n // Stands in for a network failure, once: page 3 fails the first time it is asked for.\n if (forPage === 3 && !failedOnce.current) {\n failedOnce.current = true;\n setFailed(true);\n }\n }, 600);\n }\n\n // A sort, a search or a filter goes back to page 1: page 4 of the old list means nothing in the new one.\n // A real app waits a moment after the last key before it asks the server for a search.\n function change(next: { query?: string; status?: Status | null; sort?: { by: SortBy; dir: 'ascending' | 'descending' } }) {\n if (next.query !== undefined) setQuery(next.query);\n if (next.status !== undefined) setStatus(next.status);\n if (next.sort !== undefined) setSort(next.sort);\n setPage(1);\n request(1);\n }\n\n function goToPage(next: number) {\n setPage(next);\n request(next);\n }\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: SortBy) {\n change({ sort: { by, dir: sort.by === by && sort.dir === 'ascending' ? 'descending' : 'ascending' } });\n }\n\n const words = query.trim();\n const found = all\n .filter((inv) => (status === null || inv.status === status) && (words === '' || `${inv.number} ${inv.customer}`.toLowerCase().includes(words.toLowerCase())))\n .sort((a, b) => {\n const order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;\n return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;\n });\n const pageCount = Math.ceil(found.length / PAGE_SIZE);\n const rows = found.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n const filtering = words !== '' || status !== null;\n\n // The line under the title says the total, and what the search and the filter leave.\n const matching = [words !== '' ? `\"${words}\"` : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');\n const countLine = filtering ? `${formatCount(found.length)} of ${formatCount(all.length)} invoices match ${matching}.` : `${formatCount(all.length)} ${all.length === 1 ? 'invoice' : 'invoices'}`;\n\n // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.\n function clearFilter() {\n change({ query: '', status: null });\n searchButton.current?.focus();\n }\n\n function openMenu(inv: Invoice, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === inv.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(inv);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n function choose(action: (inv: Invoice) => void) {\n if (!menuRow) return;\n const inv = menuRow;\n setMenuOpen(false);\n action(inv);\n }\n\n function sendReceipt(inv: Invoice) {\n toastIds.current.push(toast({ type: 'success', message: `Receipt for ${inv.number} sent to ${inv.customer}.` }));\n }\n\n // Only reads 'copied' when the number reached the clipboard.\n function copyNumber(inv: Invoice) {\n const failedCopy = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the number and copy it: ${inv.number}` }));\n };\n if (!navigator.clipboard) return failedCopy();\n navigator.clipboard.writeText(inv.number).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));\n }, failedCopy);\n }\n\n // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.\n function sortHeader(by: SortBy, label: string, width?: string, align?: 'right') {\n const active = sort.by === by;\n const button = (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n return (\n <TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>\n {align === 'right' ? <Cluster justify=\"end\">{button}</Cluster> : button}\n </TableHeaderCell>\n );\n }\n\n function statusTag(s: Status) {\n // The case 'Status in a row': a dot and a color only for a state that needs action.\n return s === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={s} /> : <Tag variant=\"textOnly\" size=\"small\" label={s} />;\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" id=\"data-table-page-paged-top\" />\n {loading ? <Skeleton variant=\"text\" width=\"medium\" /> : <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{countLine}</Paragraph>}\n </Stack>\n\n {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}\n <Cluster gap=\"small\" justify=\"end\">\n <Tooltip title={words !== '' ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={searchButton}\n color={words !== '' ? 'secondary' : 'iconOnly'}\n state={searchOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={words !== '' ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={searchOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setSearchAnchor(e.currentTarget);\n setSearchOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Tooltip title={status ? status : 'Filter by status'}>\n <IconButton\n color={status ? 'secondary' : 'iconOnly'}\n state={filterOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={status ? `Filter by status: ${status}` : 'Filter by status'}\n aria-haspopup=\"menu\"\n aria-expanded={filterOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setFilterAnchor(e.currentTarget);\n setFilterOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n\n {all.length === 0 ? (\n // A new workspace has none. The case 'Empty list' says what to write.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox size=\"large\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n </Surface>\n ) : failed ? (\n // The table's place: the header goes too, because nothing is left to sort. The pager stays.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load invoices\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={() => request(page)} />}\n />\n </Surface>\n ) : !loading && found.length === 0 ? (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={words !== '' ? `No ${status ? `${status.toLowerCase()} ` : ''}invoices match \"${words}\"` : `No ${status?.toLowerCase()} invoices`}\n secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'}\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n {sortHeader('customer', 'Customer')}\n {sortHeader('date', 'Date', '140px')}\n {sortHeader('amount', 'Amount', '130px', 'right')}\n <TableHeaderCell width=\"120px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"90px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {loading\n ? Array.from({ length: 10 }, (_, i) => (\n <TableRow key={i}>\n {/* One status for the ten rows: the Skeleton with a label is announced once. */}\n <TableCell width=\"110px\">{i === 0 ? <Skeleton label=\"Loading invoices\" /> : <Skeleton />}</TableCell>\n <TableCell><Skeleton width=\"large\" /></TableCell>\n <TableCell width=\"140px\"><Skeleton /></TableCell>\n <TableCell width=\"130px\"><Skeleton /></TableCell>\n <TableCell width=\"120px\"><Skeleton width=\"large\" /></TableCell>\n <TableCell width=\"90px\"><Skeleton width=\"small\" /></TableCell>\n </TableRow>\n ))\n : rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"130px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"120px\">{statusTag(inv.status)}</TableCell>\n <TableCell width=\"90px\">\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === inv.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${inv.number}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === inv.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(inv, e.currentTarget)}\n />\n </Tooltip>\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n\n {/* It shows nothing with one page. A real app also passes `getHref`, so each page has an address. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={goToPage} scrollTargetId=\"data-table-page-paged-top\" />\n </Stack>\n\n <Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>\n <Menu width={288}>\n <TextField\n id=\"data-table-page-paged-search\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => change({ query: e.target.value })}\n onKeyDown={(e) => {\n // Escape clears the search and closes. Enter closes and keeps it.\n if (e.key === 'Escape') {\n e.preventDefault();\n change({ query: '' });\n setSearchOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setSearchOpen(false);\n }\n }}\n />\n </Menu>\n </Popover>\n <Popover open={filterOpen} anchorEl={filterAnchor} onClose={() => setFilterOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by status\" width={200}>\n {statuses.map((s) => (\n <MenuItem\n key={s}\n size=\"small\"\n label={s === 'Past due' ? 'Past Due' : s}\n isSelected={s === status}\n role=\"menuitemradio\"\n onClick={() => {\n setFilterOpen(false);\n change({ status: s });\n }}\n />\n ))}\n {status && <Line />}\n {status && (\n <MenuItem\n size=\"small\"\n iconName=\"X\"\n label=\"Clear Filter\"\n onClick={() => {\n setFilterOpen(false);\n change({ status: null });\n }}\n />\n )}\n </Menu>\n </Popover>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.number}` : 'Invoice actions'} width={220}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy Invoice Number\" onClick={() => choose(copyNumber)} />\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipt\" onClick={() => choose(sendReceipt)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1553
+ "uses": [
1554
+ "Button",
1555
+ "Center",
1556
+ "Cluster",
1557
+ "EmptyBox",
1558
+ "IconButton",
1559
+ "Line",
1560
+ "Menu",
1561
+ "MenuItem",
1562
+ "Pagination",
1563
+ "Paragraph",
1564
+ "Popover",
1565
+ "Skeleton",
1566
+ "Stack",
1567
+ "Surface",
1568
+ "TableCell",
1569
+ "TableContainer",
1570
+ "TableHeader",
1571
+ "TableHeaderCell",
1572
+ "TableRow",
1573
+ "Tag",
1574
+ "TextField",
1575
+ "TitleBar",
1576
+ "Toaster",
1577
+ "Tooltip",
1578
+ "dismissToast",
1579
+ "formatCount",
1580
+ "formatMoney",
1581
+ "toast"
1582
+ ]
1583
+ },
1584
+ {
1585
+ "id": "all-rows",
1586
+ "title": "All rows, sorted in place",
1587
+ "useWhen": "There are under about 50 rows, so the page holds them all and sorts and filters them at once.",
1588
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Status = 'Paid' | 'Past due' | 'Refunded';\ntype Invoice = { id: string; number: string; customer: string; day: number; date: string; cents: number; status: Status };\ntype SortBy = 'customer' | 'date' | 'amount';\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app reads all of them in one request: 42 is few enough to hold, sort and filter in the page.\nconst all: Invoice[] = Array.from({ length: 42 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 28 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1042 - i}`,\n customer: customers[(i * 7 + 3) % customers.length],\n day: i,\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',\n };\n});\n\nconst statuses: Status[] = ['Paid', 'Past due', 'Refunded'];\n\nexport default function DataTablePageAllRows() {\n const [query, setQuery] = useState('');\n const [status, setStatus] = useState<Status | null>(null);\n // Opens newest first.\n const [sort, setSort] = useState<{ by: SortBy; dir: 'ascending' | 'descending' }>({ by: 'date', dir: 'descending' });\n\n const [searchAnchor, setSearchAnchor] = useState<HTMLElement | null>(null);\n const [searchOpen, setSearchOpen] = useState(false);\n const [filterAnchor, setFilterAnchor] = useState<HTMLElement | null>(null);\n const [filterOpen, setFilterOpen] = useState(false);\n const [menuRow, setMenuRow] = useState<Invoice | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const searchButton = useRef<Focusable>(null);\n\n // On unmount it closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // The first press on a column sorts it A to Z, and the next one reverses it. The rows are here, so it answers at once.\n function handleSort(by: SortBy) {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const words = query.trim();\n const rows = all\n .filter((inv) => (status === null || inv.status === status) && (words === '' || `${inv.number} ${inv.customer}`.toLowerCase().includes(words.toLowerCase())))\n .sort((a, b) => {\n const order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;\n return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;\n });\n const filtering = words !== '' || status !== null;\n\n // The line under the title says the total, and what the search and the filter leave.\n const matching = [words !== '' ? `\"${words}\"` : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');\n const countLine = filtering ? `${formatCount(rows.length)} of ${formatCount(all.length)} invoices match ${matching}.` : `${formatCount(all.length)} ${all.length === 1 ? 'invoice' : 'invoices'}`;\n\n // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.\n function clearFilter() {\n setQuery('');\n setStatus(null);\n searchButton.current?.focus();\n }\n\n function openMenu(inv: Invoice, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === inv.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(inv);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n function choose(action: (inv: Invoice) => void) {\n if (!menuRow) return;\n const inv = menuRow;\n setMenuOpen(false);\n action(inv);\n }\n\n function sendReceipt(inv: Invoice) {\n toastIds.current.push(toast({ type: 'success', message: `Receipt for ${inv.number} sent to ${inv.customer}.` }));\n }\n\n // Only reads 'copied' when the number reached the clipboard.\n function copyNumber(inv: Invoice) {\n const failedCopy = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the number and copy it: ${inv.number}` }));\n };\n if (!navigator.clipboard) return failedCopy();\n navigator.clipboard.writeText(inv.number).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));\n }, failedCopy);\n }\n\n // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.\n function sortHeader(by: SortBy, label: string, width?: string, align?: 'right') {\n const active = sort.by === by;\n const button = (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n return (\n <TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>\n {align === 'right' ? <Cluster justify=\"end\">{button}</Cluster> : button}\n </TableHeaderCell>\n );\n }\n\n function statusTag(s: Status) {\n // The case 'Status in a row': a dot and a color only for a state that needs action.\n return s === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={s} /> : <Tag variant=\"textOnly\" size=\"small\" label={s} />;\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{countLine}</Paragraph>\n </Stack>\n\n {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}\n <Cluster gap=\"small\" justify=\"end\">\n <Tooltip title={words !== '' ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={searchButton}\n color={words !== '' ? 'secondary' : 'iconOnly'}\n state={searchOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={words !== '' ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={searchOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setSearchAnchor(e.currentTarget);\n setSearchOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Tooltip title={status ? status : 'Filter by status'}>\n <IconButton\n color={status ? 'secondary' : 'iconOnly'}\n state={filterOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={status ? `Filter by status: ${status}` : 'Filter by status'}\n aria-haspopup=\"menu\"\n aria-expanded={filterOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setFilterAnchor(e.currentTarget);\n setFilterOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n\n {all.length === 0 ? (\n // A new workspace has none. The case 'Empty list' says what to write.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox size=\"large\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n </Surface>\n ) : rows.length === 0 ? (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={words !== '' ? `No ${status ? `${status.toLowerCase()} ` : ''}invoices match \"${words}\"` : `No ${status?.toLowerCase()} invoices`}\n secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'}\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n {sortHeader('customer', 'Customer')}\n {sortHeader('date', 'Date', '140px')}\n {sortHeader('amount', 'Amount', '130px', 'right')}\n <TableHeaderCell width=\"120px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"90px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"130px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"120px\">{statusTag(inv.status)}</TableCell>\n <TableCell width=\"90px\">\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === inv.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${inv.number}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === inv.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(inv, e.currentTarget)}\n />\n </Tooltip>\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n </Stack>\n\n <Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>\n <Menu width={288}>\n <TextField\n id=\"data-table-page-all-rows-search\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onKeyDown={(e) => {\n // Escape clears the search and closes. Enter closes and keeps it.\n if (e.key === 'Escape') {\n e.preventDefault();\n setQuery('');\n setSearchOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setSearchOpen(false);\n }\n }}\n />\n </Menu>\n </Popover>\n <Popover open={filterOpen} anchorEl={filterAnchor} onClose={() => setFilterOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by status\" width={200}>\n {statuses.map((s) => (\n <MenuItem\n key={s}\n size=\"small\"\n label={s === 'Past due' ? 'Past Due' : s}\n isSelected={s === status}\n role=\"menuitemradio\"\n onClick={() => {\n setFilterOpen(false);\n setStatus(s);\n }}\n />\n ))}\n {status && <Line />}\n {status && (\n <MenuItem\n size=\"small\"\n iconName=\"X\"\n label=\"Clear Filter\"\n onClick={() => {\n setFilterOpen(false);\n setStatus(null);\n }}\n />\n )}\n </Menu>\n </Popover>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.number}` : 'Invoice actions'} width={220}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy Invoice Number\" onClick={() => choose(copyNumber)} />\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipt\" onClick={() => choose(sendReceipt)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1589
+ "uses": [
1590
+ "Button",
1591
+ "Center",
1592
+ "Cluster",
1593
+ "EmptyBox",
1594
+ "IconButton",
1595
+ "Line",
1596
+ "Menu",
1597
+ "MenuItem",
1598
+ "Paragraph",
1599
+ "Popover",
1600
+ "Stack",
1601
+ "Surface",
1602
+ "TableCell",
1603
+ "TableContainer",
1604
+ "TableHeader",
1605
+ "TableHeaderCell",
1606
+ "TableRow",
1607
+ "Tag",
1608
+ "TextField",
1609
+ "TitleBar",
1610
+ "Toaster",
1611
+ "Tooltip",
1612
+ "dismissToast",
1613
+ "formatCount",
1614
+ "formatMoney",
1615
+ "toast"
1616
+ ]
1617
+ }
1618
+ ]
1619
+ },
1201
1620
  {
1202
1621
  "id": "device-login",
1203
1622
  "title": "Device login",
@@ -1497,17 +1916,18 @@
1497
1916
  "id": "in-shell",
1498
1917
  "title": "Inside the shell",
1499
1918
  "useWhen": "One route failed and the navigation still works.",
1500
- "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.\nconst reset = () => console.info('Render the page again');\n\nexport default function ErrorPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Something went wrong</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page could not load. Try again, or go back to the home page.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" onClickButton={reset} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
1919
+ "source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.\nconst reset = () => console.info('Render the page again');\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function ErrorPageInShell() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Something went wrong</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page could not load. Try again, or go back to the home page.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" onClickButton={reset} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </AppShell>\n );\n}\n",
1501
1920
  "uses": [
1921
+ "AppShell",
1502
1922
  "Button",
1503
1923
  "Cluster",
1504
1924
  "Heading",
1505
- "Image",
1925
+ "MenuItem",
1926
+ "Navigation",
1927
+ "NavigationGroup",
1506
1928
  "Paragraph",
1507
1929
  "Stack",
1508
- "Surface",
1509
- "Tab",
1510
- "TabsContainer"
1930
+ "Surface"
1511
1931
  ]
1512
1932
  }
1513
1933
  ]
@@ -1993,31 +2413,105 @@
1993
2413
  ]
1994
2414
  },
1995
2415
  {
1996
- "id": "load-failure",
1997
- "title": "Load failure",
2416
+ "id": "invoice-list",
2417
+ "title": "Invoices",
1998
2418
  "kind": "design",
1999
2419
  "level": "organism",
2000
- "area": "state",
2001
- "situation": "A list or a section could not load.",
2420
+ "area": "dashboard",
2421
+ "situation": "A billing page lists what the workspace has paid, so an admin can find an invoice, check an amount and keep a copy.",
2002
2422
  "do": [
2003
- "Say what could not load: 'Could not load projects'.",
2004
- "Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
2005
- "Show the list as soon as it loads.",
2006
- "Keep the rest of the page working when only one section failed.",
2007
- "Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
2423
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
2424
+ "Show a `TableContainer` named 'Invoices', with `minWidth`, and the columns Date, Description, Amount, Status and Download.",
2425
+ "Write the amount exactly, with `formatMoney`, in a right-aligned column with a right-aligned header: '$24.00'.",
2426
+ "Show the status as the case 'Status in a row' says: 'Paid' and 'Refunded' as `Tag variant=\"textOnly\"`, and 'Past due' as a dot.",
2427
+ "Show the newest first. Add `Pagination` named 'Invoice pages' past 12 invoices, and show none under that.",
2428
+ "Give each 'Download' link a name with the date: 'Download invoice for Nov 1, 2026, opens in a new tab'. Use `Button` with `type=\"tertiary\"`, `href` and `openInNewTab`, with an external-link `actionIcon`.",
2429
+ "Put an upcoming charge in the first row with an 'Upcoming' `Tag variant=\"dot\" color=\"info\"`. Give it no Download link, because no invoice exists yet.",
2430
+ "Add a tertiary 'Why Is This Higher?' Button to that row when the charge is above the plan price. It shows the sum in words in the row, and sets `aria-expanded`. Its label never changes.",
2431
+ "Say in that explanation the regular charge, what is added and why, whether it happens once, and the charge after: 'Your regular charge is $32.00: 4 members at $8.00.'",
2432
+ "Show 'No invoices yet' in an `EmptyBox`, with one line on when the first arrives: 'Your first invoice appears here after your first payment.'",
2433
+ "Show only an amount and a status. Keep a card number, an account number and the name of the payment provider off the page."
2008
2434
  ],
2009
2435
  "dont": [
2010
- "Do not show the empty text, such as 'No projects yet', when the list failed to load.",
2011
- "Do not show the error's own message, such as 'Failed to fetch'.",
2012
- "Do not replace the whole page when only one section failed."
2013
- ],
2014
- "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
2436
+ "Do not show the amount as '$24' or '24.00'. A table shows the exact amount, with its symbol and two decimals.",
2437
+ "Do not show a card number, even a part of it, in an invoice row.",
2438
+ "Do not make the upcoming charge look like a paid invoice, or leave it out of the table when it differs from the plan price.",
2439
+ "Do not name every Download link 'Download'. A screen reader lists the links apart from their rows.",
2440
+ "Do not use an icon-only link named by its icon. Every row would read the same.",
2441
+ "Do not hide the explanation behind a tooltip.",
2442
+ "Do not change the Button's label when the explanation opens. Do not write it in sentence case, 'Why is this higher?'."
2443
+ ],
2444
+ "native": "On Apple use a `Table` of rows with a `Link` to the invoice, and a `DisclosureGroup` for the explanation. On Android use a list with a text button for the invoice.",
2015
2445
  "options": [
2016
2446
  {
2017
- "id": "region",
2018
- "title": "Whole list failed",
2019
- "useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
2020
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst projects = ['Website refresh', 'Hiring plan', 'Q4 budget', 'Office move'];\n\nexport default function LoadFailureRegion() {\n const [loaded, setLoaded] = useState(false);\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setLoaded(true);\n }, 1200);\n }\n\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Projects</Heading>\n {loaded ? (\n <Surface minHeight=\"tall\">\n <List items={projects} size=\"body1\" />\n </Surface>\n ) : (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load projects\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />}\n />\n </Surface>\n )}\n </Stack>\n );\n}\n",
2447
+ "id": "table",
2448
+ "title": "A table of past invoices",
2449
+ "useWhen": "A history of payments, the same amount each month or close to it.",
2450
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Button from 'oneslash-design-system/components/button';\nimport Tag from 'oneslash-design-system/components/tag';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Invoice = { id: string; date: string; description: string; amount: number; status: 'Paid' | 'Refunded' };\n\n// A real app reads these from the server, newest first.\nconst months = ['Nov 1, 2026', 'Oct 1, 2026', 'Sep 1, 2026', 'Aug 1, 2026', 'Jul 1, 2026', 'Jun 1, 2026', 'May 1, 2026', 'Apr 1, 2026', 'Mar 1, 2026', 'Feb 1, 2026', 'Jan 1, 2026', 'Dec 1, 2025', 'Nov 1, 2025', 'Oct 1, 2025'];\nconst invoices: Invoice[] = months.map((date, i) => ({\n id: `inv-${i}`,\n date,\n description: `Pro plan, ${date.split(' ')[0]} ${date.split(', ')[1]}`,\n amount: 24,\n status: i === 3 ? 'Refunded' : 'Paid',\n}));\n\nconst PAGE_SIZE = 12;\n\nexport default function InvoiceListTable() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(invoices.length / PAGE_SIZE);\n const rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Invoices</Heading>\n {invoices.length === 0 ? (\n // A new workspace has none. The line says when the first one arrives.\n <EmptyBox size=\"small\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n ) : (\n <>\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell>Description</TableHeaderCell>\n <TableHeaderCell width=\"100px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"110px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell>{inv.description}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"100px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />\n </TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. The name says which invoice and that it opens a tab. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Download\"\n aria-label={`Download invoice for ${inv.date}, opens in a new tab`}\n actionIcon=\"ExternalLink\"\n href={`https://acme.example/invoices/${inv.id}.pdf`}\n openInNewTab\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n {/* Shows nothing under 13 invoices. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={setPage} />\n </>\n )}\n </Stack>\n </Center>\n );\n}\n",
2451
+ "uses": [
2452
+ "Button",
2453
+ "Center",
2454
+ "EmptyBox",
2455
+ "Heading",
2456
+ "Pagination",
2457
+ "Stack",
2458
+ "TableCell",
2459
+ "TableContainer",
2460
+ "TableHeader",
2461
+ "TableHeaderCell",
2462
+ "TableRow",
2463
+ "Tag",
2464
+ "formatMoney"
2465
+ ]
2466
+ },
2467
+ {
2468
+ "id": "with-upcoming",
2469
+ "title": "The next charge first",
2470
+ "useWhen": "The next charge is not the plan price, for example after a member joined mid-month, so it comes first and says why.",
2471
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The plan is $8.00 a member each month; a fourth member\n// joined on Nov 16, so the next charge also covers the 15 days left in November ($8.00 x 15/30).\nconst perMember = 8;\nconst members = 4;\nconst regular = perMember * members;\nconst added = 4;\nconst upcoming = { date: 'Dec 1, 2026', description: 'Pro plan, Dec 2026', amount: regular + added };\n\nconst paid = [\n { id: 'inv-0', date: 'Nov 1, 2026', description: 'Pro plan, Nov 2026', amount: 24, status: 'Paid' },\n { id: 'inv-1', date: 'Oct 1, 2026', description: 'Pro plan, Oct 2026', amount: 24, status: 'Paid' },\n { id: 'inv-2', date: 'Sep 1, 2026', description: 'Pro plan, Sep 2026', amount: 24, status: 'Paid' },\n];\n\nexport default function InvoiceListWithUpcoming() {\n const [explaining, setExplaining] = useState(false);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Invoices</Heading>\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell>Description</TableHeaderCell>\n <TableHeaderCell width=\"100px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"110px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {/* The next charge is the first row. It has no invoice yet, so it has no Download link. */}\n <TableRow>\n <TableCell width=\"130px\">{upcoming.date}</TableCell>\n <TableCell>\n <Stack gap=\"small\" align=\"start\">\n {upcoming.description}\n {/* The label never changes. The state is in aria-expanded. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Why Is This Higher?\"\n aria-expanded={explaining}\n aria-controls=\"invoice-list-upcoming-why\"\n onClickButton={() => setExplaining((open) => !open)}\n />\n {explaining && (\n <Paragraph id=\"invoice-list-upcoming-why\" tone=\"secondary\" size=\"body2\" measure=\"none\">\n {`Your regular charge is ${formatMoney(regular)}: ${members} members at ${formatMoney(perMember)}. This one is ${formatMoney(upcoming.amount)} because it also adds ${formatMoney(added)} for Omar Reyes, who joined on Nov 16, for the 15 days left in November. It happens once. The charge after this is ${formatMoney(regular)}.`}\n </Paragraph>\n )}\n </Stack>\n </TableCell>\n <TableCell width=\"100px\" align=\"right\">{formatMoney(upcoming.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"dot\" size=\"small\" color=\"info\" label=\"Upcoming\" />\n </TableCell>\n <TableCell width=\"130px\">{''}</TableCell>\n </TableRow>\n {paid.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell>{inv.description}</TableCell>\n <TableCell width=\"100px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />\n </TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Download\"\n aria-label={`Download invoice for ${inv.date}, opens in a new tab`}\n actionIcon=\"ExternalLink\"\n href={`https://acme.example/invoices/${inv.id}.pdf`}\n openInNewTab\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
2472
+ "uses": [
2473
+ "Button",
2474
+ "Center",
2475
+ "Heading",
2476
+ "Paragraph",
2477
+ "Stack",
2478
+ "TableCell",
2479
+ "TableContainer",
2480
+ "TableHeader",
2481
+ "TableHeaderCell",
2482
+ "TableRow",
2483
+ "Tag",
2484
+ "formatMoney"
2485
+ ]
2486
+ }
2487
+ ]
2488
+ },
2489
+ {
2490
+ "id": "load-failure",
2491
+ "title": "Load failure",
2492
+ "kind": "design",
2493
+ "level": "organism",
2494
+ "area": "state",
2495
+ "situation": "A list or a section could not load.",
2496
+ "do": [
2497
+ "Say what could not load: 'Could not load projects'.",
2498
+ "Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
2499
+ "Show the list as soon as it loads.",
2500
+ "Keep the rest of the page working when only one section failed.",
2501
+ "Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
2502
+ ],
2503
+ "dont": [
2504
+ "Do not show the empty text, such as 'No projects yet', when the list failed to load.",
2505
+ "Do not show the error's own message, such as 'Failed to fetch'.",
2506
+ "Do not replace the whole page when only one section failed."
2507
+ ],
2508
+ "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
2509
+ "options": [
2510
+ {
2511
+ "id": "region",
2512
+ "title": "Whole list failed",
2513
+ "useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
2514
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst projects = ['Website refresh', 'Hiring plan', 'Q4 budget', 'Office move'];\n\nexport default function LoadFailureRegion() {\n const [loaded, setLoaded] = useState(false);\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setLoaded(true);\n }, 1200);\n }\n\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Projects</Heading>\n {loaded ? (\n <Surface minHeight=\"tall\">\n <List items={projects} size=\"body1\" />\n </Surface>\n ) : (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load projects\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />}\n />\n </Surface>\n )}\n </Stack>\n );\n}\n",
2021
2515
  "uses": [
2022
2516
  "Button",
2023
2517
  "EmptyBox",
@@ -2031,7 +2525,7 @@
2031
2525
  "id": "inline",
2032
2526
  "title": "One section failed",
2033
2527
  "useWhen": "One section failed to load and the rest of the page works.",
2034
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst invoices = ['November 2026: $240', 'October 2026: $240', 'September 2026: $180'];\n\nexport default function LoadFailureInline() {\n const [error, setError] = useState('Could not load your invoices.');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Plan</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Team plan, 12 seats, renews on December 1.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" />\n </Cluster>\n </Stack>\n </Surface>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Invoices</Heading>\n {error ? (\n <>\n {/* The section stays failed until it loads, so the Alert has no close button and does not close on its own. */}\n <Alert type=\"error\" variant=\"inline\" message={error} autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />\n </Cluster>\n </>\n ) : (\n <List items={invoices} size=\"body2\" />\n )}\n </Stack>\n </Surface>\n </Stack>\n </Center>\n );\n}\n",
2528
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst invoices = ['November 2026: $24.00', 'October 2026: $24.00', 'September 2026: $24.00'];\n\nexport default function LoadFailureInline() {\n const [error, setError] = useState('Could not load your invoices.');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Plan</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Pro plan, 3 members, renews on Dec 1, 2026.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" />\n </Cluster>\n </Stack>\n </Surface>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Invoices</Heading>\n {error ? (\n <>\n {/* The section stays failed until it loads, so the Alert has no close button and does not close on its own. */}\n <Alert type=\"error\" variant=\"inline\" message={error} autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />\n </Cluster>\n </>\n ) : (\n <List items={invoices} size=\"body2\" />\n )}\n </Stack>\n </Surface>\n </Stack>\n </Center>\n );\n}\n",
2035
2529
  "uses": [
2036
2530
  "Alert",
2037
2531
  "Button",
@@ -2184,6 +2678,69 @@
2184
2678
  }
2185
2679
  ]
2186
2680
  },
2681
+ {
2682
+ "id": "master-detail",
2683
+ "title": "List and detail",
2684
+ "kind": "design",
2685
+ "level": "page",
2686
+ "area": "shell",
2687
+ "situation": "A person opens an item from a list, such as a message or a report, and reads or acts on it.",
2688
+ "do": [
2689
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
2690
+ "Use `SettingsLayout` with `navWidth=\"wide\"` for a list beside its detail. The list is a `Navigation` of `MenuItem` rows.",
2691
+ "Make each row a link with an `href`, so the open item has an address that can be shared and reloaded. Mark the open row with `isSelected` and `aria-current=\"page\"`.",
2692
+ "Keep one item open at all times from `md` up, the first at the start.",
2693
+ "Name the row with the sender or the title, and put the subject or the summary in `secondLabel`.",
2694
+ "Show the list first on a phone, then the detail alone with a Back Button named for the list: 'Back to Inbox'. Pass it as `back` of `SettingsLayout`.",
2695
+ "Title the page with a level 1 heading, such as 'Inbox'. The open item's title is a level 2 heading.",
2696
+ "Make each row of a list of long items a link to a page of its own. Put 'Back to Reports' in the page's `TitleBar` as `back`.",
2697
+ "Let 'Back to Reports' call the router's `back()` when the person came from the list, so the list keeps its scroll. Otherwise link to the list's address.",
2698
+ "After the person acts on an item, such as Archive, open the next one."
2699
+ ],
2700
+ "dont": [
2701
+ "Do not show the list and the detail together on a phone.",
2702
+ "Do not leave the detail empty with nothing open on a wide screen. Open the first item.",
2703
+ "Do not keep the open item only in state. Give it an address.",
2704
+ "Do not name the Back Button 'Back'. Name the list it goes to.",
2705
+ "Do not use a split for long items that need the whole width."
2706
+ ],
2707
+ "native": "On Apple use a `NavigationSplitView` with a list and a detail. On iPhone it shows the list, then pushes the detail with the system back button. On Android use a list-detail layout that shows one pane on a phone.",
2708
+ "options": [
2709
+ {
2710
+ "id": "split",
2711
+ "title": "List beside the detail",
2712
+ "useWhen": "The person works down the list, one item after another, such as an inbox.",
2713
+ "source": "'use client';\nimport { useState } from 'react';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { SettingsLayout } from 'oneslash-design-system/components/settingsSection';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Message = { id: string; from: string; subject: string; time: string; body: string[] };\n\nconst messages: Message[] = [\n { id: 'launch-plan', from: 'Ben Carter', subject: 'Launch plan is ready', time: '9:12 AM', body: ['The plan is in the shared folder. It covers the announcement, the pricing page and the support hand-off.', 'Can you read the pricing part before noon? Omar Reyes is waiting on it.'] },\n { id: 'new-screens', from: 'Omar Reyes', subject: 'New screens for Friday', time: '8:40 AM', body: ['I added the new home page screens. The sign-up form now sits above the pricing table.', 'Tell me what to change by Thursday.'] },\n { id: 'invoice', from: 'Ben Carter', subject: 'Invoice for October', time: 'Yesterday', body: ['The invoice for October is attached. It includes the three new seats.'] },\n { id: 'offsite', from: 'Omar Reyes', subject: 'Team offsite in March', time: 'Monday', body: ['I found two dates for the offsite. Please say which one works for you.'] },\n];\n\nexport default function MasterDetailSplit() {\n // One message is always open, the first at the start.\n const [openId, setOpenId] = useState(messages[0].id);\n // On a phone the list is the screen until a message is chosen, and Back returns to it.\n const [showDetail, setShowDetail] = useState(false);\n\n const message = messages.find((m) => m.id === openId) ?? messages[0];\n\n const list = (\n <Navigation aria-label=\"Messages\">\n {messages.map((m) => (\n <MenuItem\n key={m.id}\n size=\"medium\"\n label={m.from}\n secondLabel={m.subject}\n href={`/inbox/${m.id}`}\n isSelected={m.id === message.id}\n aria-current={m.id === message.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the message's own address, so it can be shared and reloaded. The example keeps the choice in state.\n event.preventDefault();\n setOpenId(m.id);\n setShowDetail(true);\n }}\n />\n ))}\n </Navigation>\n );\n\n return (\n <PageShell>\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Inbox</Heading>\n <SettingsLayout\n navWidth=\"wide\"\n nav={list}\n showContent={showDetail}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Inbox\" onClickButton={() => setShowDetail(false)} />}\n >\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">{message.subject}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{message.from}, {message.time}</Paragraph>\n </Stack>\n <Stack gap=\"medium\">\n {message.body.map((paragraph) => (\n <Paragraph key={paragraph} measure=\"none\">{paragraph}</Paragraph>\n ))}\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Reply\" decoIcon=\"Reply\" />\n </Cluster>\n </SettingsLayout>\n </Stack>\n </PageShell>\n );\n}\n",
2714
+ "uses": [
2715
+ "Button",
2716
+ "Cluster",
2717
+ "Heading",
2718
+ "MenuItem",
2719
+ "Navigation",
2720
+ "PageShell",
2721
+ "Paragraph",
2722
+ "SettingsLayout",
2723
+ "Stack"
2724
+ ]
2725
+ },
2726
+ {
2727
+ "id": "list-then-page",
2728
+ "title": "List, then a page for each item",
2729
+ "useWhen": "Each item is long and has its own address, such as a report.",
2730
+ "source": "'use client';\nimport { useState } from 'react';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; title: string; summary: string; body: string[] };\n\nconst reports: Report[] = [\n {\n id: 'q3-review',\n title: 'Q3 review',\n summary: 'Revenue, churn and what changed since June.',\n body: [\n 'Revenue grew 12 percent over the quarter, led by the new team plan. Churn fell to 2.1 percent.',\n 'Support tickets about sign-up dropped by a third after the new form shipped in August.',\n 'The main risk is the pricing page, which still sends people to a contact form. Ben Carter owns the fix.',\n ],\n },\n {\n id: 'hiring-plan',\n title: 'Hiring plan',\n summary: 'Roles to open next half, and why.',\n body: [\n 'Two roles open in January: a designer for the web app and a support lead.',\n 'Omar Reyes will write both job posts. Dana Lee approves the budget on Monday.',\n ],\n },\n {\n id: 'roadmap',\n title: 'Roadmap',\n summary: 'What ships, in order, through March.',\n body: [\n 'The mobile app and the new billing page ship first. Integrations follow in February.',\n 'Each item lists its owner, its date and what must be true before it starts.',\n ],\n },\n];\n\nexport default function MasterDetailListThenPage() {\n const [openId, setOpenId] = useState<string | null>(null);\n const report = reports.find((r) => r.id === openId);\n\n // A real app goes to the page's address. Back calls the router's back() when the person came from the list, so the list keeps its scroll,\n // and otherwise links to the list's address. The example swaps the view.\n if (report) {\n return (\n <PageShell>\n <Stack gap=\"large\">\n <TitleBar\n title={report.title}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Reports\" onClickButton={() => setOpenId(null)} />}\n />\n {report.body.map((paragraph) => (\n <Paragraph key={paragraph} measure=\"body\">{paragraph}</Paragraph>\n ))}\n </Stack>\n </PageShell>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Navigation aria-label=\"Reports\">\n {reports.map((r) => (\n <MenuItem\n key={r.id}\n size=\"medium\"\n label={r.title}\n secondLabel={r.summary}\n iconRight=\"ChevronRight\"\n href={`/reports/${r.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n event.preventDefault();\n setOpenId(r.id);\n }}\n />\n ))}\n </Navigation>\n </Stack>\n </PageShell>\n );\n}\n",
2731
+ "uses": [
2732
+ "Button",
2733
+ "Heading",
2734
+ "MenuItem",
2735
+ "Navigation",
2736
+ "PageShell",
2737
+ "Paragraph",
2738
+ "Stack",
2739
+ "TitleBar"
2740
+ ]
2741
+ }
2742
+ ]
2743
+ },
2187
2744
  {
2188
2745
  "id": "members-list",
2189
2746
  "title": "Members",
@@ -2205,7 +2762,7 @@
2205
2762
  "Open the Modal of the case 'Member invite' from an 'Invite Member' Button. Count a pending invite as a seat, because it holds one until it is accepted or revoked.",
2206
2763
  "Keep 'Invite Member' pressable at the seat limit. Open the Modal of the case 'Upgrade prompt', titled 'Upgrade to Pro', that says all the seats are filled.",
2207
2764
  "Say how many seats are used under the title: '7 of 8 seats used on the Free plan.'",
2208
- "Sort a table by a Button in the header cell. `TableHeaderCell` has no `aria-sort`, so the Button's `aria-label` says the state and what a press does: 'Name, sorted ascending. Sort descending.'",
2765
+ "Sort a table by a Button in the header cell. Set `sort` on the `TableHeaderCell` of the sorted column only, and leave it unset on the others. The Button is named by its label alone: 'Name'.",
2209
2766
  "Use `state=\"selected\"` and an arrow on the Button of the column that is sorted. The first press sorts A to Z and the next one reverses it."
2210
2767
  ],
2211
2768
  "dont": [
@@ -2223,7 +2780,7 @@
2223
2780
  "id": "rows",
2224
2781
  "title": "A list of rows",
2225
2782
  "useWhen": "A workspace of a few dozen people, so the whole list fits and a person finds someone by looking.",
2226
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2783
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2227
2784
  "uses": [
2228
2785
  "Alert",
2229
2786
  "Button",
@@ -2243,6 +2800,7 @@
2243
2800
  "Toaster",
2244
2801
  "UserImage",
2245
2802
  "dismissToast",
2803
+ "formatMoney",
2246
2804
  "toast"
2247
2805
  ]
2248
2806
  },
@@ -2250,7 +2808,7 @@
2250
2808
  "id": "table",
2251
2809
  "title": "A table with sorting",
2252
2810
  "useWhen": "More people than a person can scan. The columns Name and Role sort.",
2253
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The header cell has no `aria-sort`, so the Button's name says the state and what a press does.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n const next = active && sort.dir === 'ascending' ? 'descending' : 'ascending';\n const now = active ? `sorted ${sort.dir}` : 'not sorted';\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n aria-label={`${label}, ${now}. Sort ${next}.`}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\">{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2811
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The sorted column's header cell has `sort`; the other cells leave it unset. The Button is named by its label alone.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer aria-label=\"Members\" minWidth=\"720px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell sort={sort.by === 'name' ? sort.dir : undefined}>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\" sort={sort.by === 'role' ? sort.dir : undefined}>{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer aria-label=\"Pending invites\" minWidth=\"720px\">\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2254
2812
  "uses": [
2255
2813
  "Alert",
2256
2814
  "Button",
@@ -2272,6 +2830,7 @@
2272
2830
  "Toaster",
2273
2831
  "UserImage",
2274
2832
  "dismissToast",
2833
+ "formatMoney",
2275
2834
  "toast"
2276
2835
  ]
2277
2836
  }
@@ -2748,6 +3307,68 @@
2748
3307
  }
2749
3308
  ]
2750
3309
  },
3310
+ {
3311
+ "id": "mobile-menu",
3312
+ "title": "Menu on a phone",
3313
+ "kind": "design",
3314
+ "level": "organism",
3315
+ "area": "shell",
3316
+ "situation": "A site's links and actions do not fit in the bar on a phone, and the person still needs to reach every one.",
3317
+ "do": [
3318
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'. The menu is a `Drawer` from the start side.",
3319
+ "Open it from an `IconButton` named 'Menu' at the start of the bar, with `aria-expanded` and `aria-controls`.",
3320
+ "Use the menu that `SiteHeader` builds for a few links. The links come first, then the actions. One main action stays in the bar as `phoneAction`.",
3321
+ "Build the menu from a `Drawer` for sections: the pages of the open section as `MenuItem` links in a `Navigation`. Put a `TabsContainer` of section `Tab`s above them when the bar does not show the sections.",
3322
+ "Put the 'Menu' IconButton in a real bar with a skip link, as `SiteHeader` builds.",
3323
+ "Open the menu on the section of the current page, and mark the current page with `isSelected` and `aria-current=\"page\"`.",
3324
+ "Close the menu when a page is chosen. A `Drawer` also closes on Close, Escape and the scrim.",
3325
+ "Close the menu when the window widens past `md`, so the page is never left locked. A `SiteHeader` does it; give your own `Drawer` `closeFrom=\"md\"`.",
3326
+ "Give the Drawer a name with `aria-label`, the same as the button that opens it."
3327
+ ],
3328
+ "dont": [
3329
+ "Do not leave a link without a way to reach it on a phone.",
3330
+ "Do not keep the menu open after a page is chosen.",
3331
+ "Do not put a Button that opens a Modal in the menu. On a phone the menu closes when it is chosen, so the Modal has no Button to give focus back to. Link to a page instead.",
3332
+ "Do not name the button only by its icon. Name it 'Menu'.",
3333
+ "Do not use more than four section tabs, or long names. They will not fit on a phone."
3334
+ ],
3335
+ "native": "On iPhone use a `TabView` for the main places and a `NavigationStack` for the pages in a section. On Android use a navigation drawer.",
3336
+ "options": [
3337
+ {
3338
+ "id": "links",
3339
+ "title": "Links and actions in one menu",
3340
+ "useWhen": "A site has a few links and its actions, such as 'Log In'.",
3341
+ "source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Button from 'oneslash-design-system/components/button';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Features', href: '#features', current: true },\n { label: 'Pricing', href: '#pricing' },\n { label: 'Docs', href: '#docs' },\n];\n\nexport default function MobileMenuLinks() {\n return (\n <>\n {/* Below md the Menu IconButton opens a Drawer: the links first, then 'Log In'. Choosing one closes it. 'Sign Up' stays in the bar. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n actions={<Button size=\"medium\" type=\"tertiary\" state=\"enabled\" label=\"Log In\" href=\"#log-in\" />}\n phoneAction={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />}\n mainId=\"mobile-menu-links-main\"\n />\n <PageShell id=\"mobile-menu-links-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Features</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">On a phone, open Menu to reach every page. It closes when you choose one.</Paragraph>\n </Stack>\n </PageShell>\n </>\n );\n}\n",
3342
+ "uses": [
3343
+ "Button",
3344
+ "Heading",
3345
+ "PageShell",
3346
+ "Paragraph",
3347
+ "SiteHeader",
3348
+ "Stack"
3349
+ ]
3350
+ },
3351
+ {
3352
+ "id": "sections",
3353
+ "title": "Sections with their pages",
3354
+ "useWhen": "A site has sections that each hold many pages, and the person picks a section first.",
3355
+ "source": "'use client';\nimport { useState } from 'react';\nimport Drawer from 'oneslash-design-system/components/drawer';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Page = { id: string; label: string };\ntype Section = { id: string; label: string; pages: Page[] };\n\n// Four sections, one short word each. A real site reads these from its navigation.\nconst sections: Section[] = [\n { id: 'start', label: 'Start', pages: [{ id: 'install', label: 'Install' }, { id: 'first-steps', label: 'First steps' }] },\n { id: 'guides', label: 'Guides', pages: [{ id: 'sharing', label: 'Share a folder' }, { id: 'roles', label: 'Roles and access' }, { id: 'billing', label: 'Billing' }] },\n { id: 'reference', label: 'API', pages: [{ id: 'api', label: 'Endpoints' }, { id: 'limits', label: 'Limits' }] },\n { id: 'updates', label: 'News', pages: [{ id: 'changelog', label: 'Changelog' }] },\n];\n\nconst drawerId = 'mobile-menu-sections-drawer';\n\nexport default function MobileMenuSections() {\n const [open, setOpen] = useState(false);\n const [pageId, setPageId] = useState('sharing');\n const currentSection = sections.find((s) => s.pages.some((p) => p.id === pageId)) ?? sections[0];\n // The tabs show the section of the current page each time the menu opens.\n const [sectionId, setSectionId] = useState(currentSection.id);\n const shown = sections.find((s) => s.id === sectionId) ?? sections[0];\n const page = currentSection.pages.find((p) => p.id === pageId) ?? currentSection.pages[0];\n\n function openMenu() {\n setSectionId(currentSection.id);\n setOpen(true);\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Cluster gap=\"small\">\n {/* A real site shows this IconButton only below md, where the links are not in the bar. */}\n <IconButton\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"medium\"\n iconName=\"Menu\"\n ariaLabel=\"Menu\"\n aria-expanded={open}\n aria-controls={drawerId}\n onClick={openMenu}\n />\n <Paragraph size=\"body1\" measure=\"none\">Acme Docs</Paragraph>\n </Cluster>\n <Heading level={1} size=\"h5\">{page.label}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page is in {currentSection.label}. Open Menu to move to another section.</Paragraph>\n </Stack>\n {/* Section tabs at the top, the section's pages under them, the current page marked. A choice closes the Drawer. */}\n <Drawer id={drawerId} isOpen={open} onClose={() => setOpen(false)} aria-label=\"Menu\" side=\"start\" size=\"small\" closeFrom=\"md\">\n <Stack gap=\"large\">\n <TabsContainer fill>\n {sections.map((s) => (\n <Tab key={s.id} label={s.label} size=\"small\" isSelected={s.id === shown.id} onClickTab={() => setSectionId(s.id)} />\n ))}\n </TabsContainer>\n <Navigation aria-label={`${shown.label} pages`}>\n {shown.pages.map((p) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n href={`/${shown.id}/${p.id}`}\n isSelected={p.id === pageId}\n aria-current={p.id === pageId ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPageId(p.id);\n setOpen(false);\n }}\n />\n ))}\n </Navigation>\n </Stack>\n </Drawer>\n </PageShell>\n );\n}\n",
3356
+ "uses": [
3357
+ "Cluster",
3358
+ "Drawer",
3359
+ "Heading",
3360
+ "IconButton",
3361
+ "MenuItem",
3362
+ "Navigation",
3363
+ "PageShell",
3364
+ "Paragraph",
3365
+ "Stack",
3366
+ "Tab",
3367
+ "TabsContainer"
3368
+ ]
3369
+ }
3370
+ ]
3371
+ },
2751
3372
  {
2752
3373
  "id": "not-found-page",
2753
3374
  "title": "Page not found",
@@ -2784,17 +3405,18 @@
2784
3405
  "id": "in-shell",
2785
3406
  "title": "Inside the shell",
2786
3407
  "useWhen": "The address is inside the app and the navigation still works.",
2787
- "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function NotFoundPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
3408
+ "source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function NotFoundPageInShell() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </AppShell>\n );\n}\n",
2788
3409
  "uses": [
3410
+ "AppShell",
2789
3411
  "Button",
2790
3412
  "Cluster",
2791
3413
  "Heading",
2792
- "Image",
3414
+ "MenuItem",
3415
+ "Navigation",
3416
+ "NavigationGroup",
2793
3417
  "Paragraph",
2794
3418
  "Stack",
2795
- "Surface",
2796
- "Tab",
2797
- "TabsContainer"
3419
+ "Surface"
2798
3420
  ]
2799
3421
  }
2800
3422
  ]
@@ -2849,6 +3471,36 @@
2849
3471
  }
2850
3472
  ]
2851
3473
  },
3474
+ {
3475
+ "id": "number-format",
3476
+ "title": "A number shows its unit and never shows 0 for unknown",
3477
+ "kind": "rule",
3478
+ "level": "rule",
3479
+ "area": "dashboard",
3480
+ "situation": "A page shows counts, money, sizes, shares or changes.",
3481
+ "answer": "Use the helpers in `formatNumber` (`formatCount`, `formatMoney`, `formatPercent`, `formatBytes`, `formatDuration`), `StatTile` and `Progress`. A count is whole and grouped: '1,240'. In a tile, a count or an amount from 10,000 up shows its short form: '12.4K', '$12.4K'. A table shows the exact number, right-aligned. Money has its symbol and two decimals: '$1,240.00'. A cost under a cent reads '< $0.01'. A share is a whole percent, and a small one reads '< 1%'. A size is base 1024: '52 MB', '1.2 GB'. A time reads '340 ms', '1.2 s', '2 h 24 min'. The unit is in the label or after the number in words: 'Responses', '7 of 8 seats', '340 responses, no limit'. A bare number is never shown, and a unit is never only in a tooltip. A change says its direction, its size and what it compares with: 'Up 12% from last week'. It reads 'New this week' when there was nothing before. It has no color, because more is not good or bad by itself. Unknown is never 0. `formatNumber` shows '–' for a value it cannot read. `StatTile` shows 'No data yet'. While a number loads, a `Skeleton` holds its place. On a failure, show the case 'Load failure'. A limit is a `Progress`, which says 'Limit reached' in words.",
3482
+ "why": "One page that rounds a cost to four decimals and another that rounds it to two make the same bill look like two different amounts. A 0 shown while a number loads reads as a real answer, so the person believes something that is not true.",
3483
+ "do": [
3484
+ "Show a count whole and grouped: '1,240'. In a tile, show a count or an amount from 10,000 up in its short form: '12.4K', '$12.4K'.",
3485
+ "Show the exact number in a table, right-aligned.",
3486
+ "Show money with its symbol and two decimals, and a cost under a cent as '< $0.01'.",
3487
+ "Show a time as '340 ms', '1.2 s' or '2 h 24 min'. Show a share as a whole percent, and a small one as '< 1%'. Show a size in base 1024: '52 MB', '1.2 GB'.",
3488
+ "Put the unit in the label or after the number in words: 'Responses', '7 of 8 seats', '340 responses, no limit'.",
3489
+ "Match the noun to the count: '1 invoice', '290 invoices'.",
3490
+ "Say a change's direction, size and comparison: 'Up 12% from last week'. Say 'New this week' when there was nothing before.",
3491
+ "Show a `Skeleton` while a number loads, 'No data yet' when there is none, and the case 'Load failure' when it could not load.",
3492
+ "Use the helpers in `formatNumber` (`formatCount`, `formatMoney`, `formatPercent`, `formatBytes`, `formatDuration`), `StatTile` and `Progress`. Do not format a number by hand."
3493
+ ],
3494
+ "dont": [
3495
+ "Do not show 0 for a number that is loading, missing or failed.",
3496
+ "Do not show a bare number, or a unit only in a tooltip.",
3497
+ "Do not round a cost to four decimals in one place and two in another.",
3498
+ "Do not color a change green or red. More is not good or bad by itself.",
3499
+ "Do not show the compact form ('12.4K') in a table, or give a screen reader only the compact form.",
3500
+ "Do not show 100% for a share that is not the whole."
3501
+ ],
3502
+ "native": "On Apple use `FormatStyle` for numbers, money and percents, and `ByteCountFormatStyle` with the `.memory` style for sizes, which is base 1024. On Android use `NumberFormat`."
3503
+ },
2852
3504
  {
2853
3505
  "id": "oauth-consent",
2854
3506
  "title": "OAuth consent",
@@ -2960,6 +3612,47 @@
2960
3612
  }
2961
3613
  ]
2962
3614
  },
3615
+ {
3616
+ "id": "on-this-page",
3617
+ "title": "On this page",
3618
+ "kind": "design",
3619
+ "level": "organism",
3620
+ "area": "shell",
3621
+ "situation": "A person reads a long page and wants to see its sections, jump to one and know which one they are in.",
3622
+ "do": [
3623
+ "Put `OnThisPage` in the `aside` of `PageShell`. It sticks below a `SiteHeader` and shows from `xl`. `PageShell` gives each level 2 and 3 heading with an `id` a scroll margin, so `#sharing` lands below the header.",
3624
+ "Build `items` from the headings of the page, in page order: the level 2 headings and the level 3 headings under them. Give each heading an `id`.",
3625
+ "Use it when the page has two items or more. With fewer it renders nothing.",
3626
+ "Keep the labels the same as the headings, in the same case.",
3627
+ "Name the nav 'On this page', which is the default, or pass an `aria-label` that fits the page.",
3628
+ "Let a click scroll the heading to just under the header and keep its item current until the scroll ends. With reduced motion it jumps.",
3629
+ "Keep the aside to the list. A phone does not show it, so the page must read in order without it. The sections are not places: on a phone the person scrolls to them."
3630
+ ],
3631
+ "dont": [
3632
+ "Do not take the arrow keys to jump between sections. They scroll the page and move the cursor in a field.",
3633
+ "Do not list a page with one section.",
3634
+ "Do not add the items by hand for a page whose headings change. Build them from the headings.",
3635
+ "Do not mark the current item with color only. The bar beside it moves too.",
3636
+ "Do not put a second contents list in the page."
3637
+ ],
3638
+ "native": "On Apple use a `ScrollViewReader` with a `Menu` or `List` of sections that scrolls to an id. On Android use a `LazyColumn` with a `scrollToItem` list.",
3639
+ "options": [
3640
+ {
3641
+ "id": "aside",
3642
+ "title": "List of sections beside the page",
3643
+ "useWhen": "The page has two or more level 2 or 3 headings, and people jump between them.",
3644
+ "source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport OnThisPage from 'oneslash-design-system/components/onThisPage';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// The page's level 2 and 3 headings, in page order. A real site builds this from the page.\nconst sections = [\n { id: 'on-this-page-overview', label: 'Overview', level: 2 as const, text: 'Acme keeps your files in folders that the whole team can open. Everyone sees the same files.' },\n { id: 'on-this-page-sharing', label: 'Sharing', level: 2 as const, text: 'Share a folder with a person or a team. Dana Lee can share any folder she owns.' },\n { id: 'on-this-page-links', label: 'Share by link', level: 3 as const, text: 'A link opens the folder for anyone who has it. Turn the link off to stop it.' },\n { id: 'on-this-page-people', label: 'Share with people', level: 3 as const, text: 'Choose people by name. Ben Carter and Omar Reyes can view or edit.' },\n { id: 'on-this-page-roles', label: 'Roles and access', level: 2 as const, text: 'Owners change who has access. Editors change files. Viewers read them.' },\n { id: 'on-this-page-limits', label: 'Limits', level: 2 as const, text: 'A free team holds up to 5 GB. Paid teams hold as much as they need.' },\n];\n\n// Filler for the example, so each section is long enough to scroll.\nconst more = 'A change shows for everyone at once, so there is one copy of each file to look after. Older versions stay for 30 days, and an owner can bring one back.';\n\nconst items = sections.map(({ id, label, level }) => ({ id, label, level }));\n\nexport default function OnThisPageAside() {\n return (\n <>\n <SiteHeader\n brand={{ href: '#top', name: 'Acme Docs' }}\n links={[{ label: 'Guides', href: '#guides', current: true }, { label: 'Reference', href: '#reference' }]}\n mainId=\"on-this-page-main\"\n />\n {/* The list sticks below the header from xl. Below xl the page reads in order without it. */}\n <PageShell id=\"on-this-page-main\" tabIndex={-1} aside={<OnThisPage items={items} />}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Share a folder</Heading>\n {sections.map((s) => (\n <Stack key={s.id} gap=\"medium\">\n <Heading level={s.level} size={s.level === 2 ? 'h6' : 'subtitle1'} id={s.id}>{s.label}</Heading>\n <Paragraph measure=\"none\">{s.text}</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">{more}</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">{more}</Paragraph>\n </Stack>\n ))}\n </Stack>\n </PageShell>\n </>\n );\n}\n",
3645
+ "uses": [
3646
+ "Heading",
3647
+ "OnThisPage",
3648
+ "PageShell",
3649
+ "Paragraph",
3650
+ "SiteHeader",
3651
+ "Stack"
3652
+ ]
3653
+ }
3654
+ ]
3655
+ },
2963
3656
  {
2964
3657
  "id": "overflow-menu",
2965
3658
  "title": "More menu",
@@ -3047,125 +3740,493 @@
3047
3740
  ]
3048
3741
  },
3049
3742
  {
3050
- "id": "profile-form",
3051
- "title": "Profile",
3743
+ "id": "page-header",
3744
+ "title": "Page header with actions",
3052
3745
  "kind": "design",
3053
3746
  "level": "organism",
3054
- "area": "settings",
3055
- "situation": "A person changes how they appear and how they sign in: their picture, their name and their password.",
3747
+ "area": "shell",
3748
+ "situation": "A page names itself at the top and offers what the person can do with it.",
3056
3749
  "do": [
3057
- "Follow the rule 'A setting saves in place, or with one Save Button'.",
3058
- "Put the picture, the name and the password in their own `SettingsSection`s. Do not mix a control that saves on change and a Save Button in one section.",
3059
- "Save the picture as soon as the person chooses it, with 'Change Picture' and 'Remove'. Show `loading` on the Button that was pressed while it saves, and nothing when it works.",
3060
- "When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'",
3061
- "Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.",
3062
- "Give the name one Save Button inside a `Form`. It is `state=\"disabled\"` while the name has not changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.",
3063
- "Give the password one 'Update Password' Button. Ask for the current password and the new one. It is disabled while either field is empty, and reads 'Saved' for 2 seconds. Then clear both fields.",
3064
- "Show a wrong current password under that field, and keep what the person typed in both.",
3065
- "Use `<TextField type=\"password\">` for both, with `autoComplete=\"current-password\"` and `autoComplete=\"new-password\"`.",
3066
- "Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. This ties its label, help and error to it.",
3067
- "Show a problem with a field under it, as the rule 'A form error shows next to the problem' says: 'Enter your name.' and 'Use at least 8 characters.'",
3068
- "Disable the field while its request runs, and keep what the person typed when the save fails.",
3069
- "Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial."
3750
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
3751
+ "Use `TitleBar` with the page's name as the level 1 heading. Inside `AppShell` the top bar names the place on a phone. When the page is the place, the two are the same.",
3752
+ "Give the page one primary Button, first in `actions`.",
3753
+ "Put icon buttons after it, each in a `Tooltip` and named for what they act on: 'Search Home page'.",
3754
+ "Put a More menu last, as the case 'More menu' says: an `IconButton` with `iconName=\"Ellipsis\"`, `aria-haspopup=\"menu\"` and a name such as 'More actions for Home page'.",
3755
+ "Pass `phoneActions` with the primary Button and More. Below `md` they replace `actions`.",
3756
+ "Fold the icon buttons you leave out into the More menu, in the same order, so every action is still there. Put them first, before a `Line`. Keep a frequent action, such as Search, as an icon button in `phoneActions`.",
3757
+ "Pass `back` on a sub-page, a tertiary Button named for the page it goes to: 'Back to Website'. Below `md` it takes its own line.",
3758
+ "Let a long title wrap. Never cut it short."
3070
3759
  ],
3071
3760
  "dont": [
3072
- "Do not add one Save Button for the whole page. Each group saves by itself.",
3073
- "Do not label the Button 'Saving…' while it runs. It keeps its label.",
3074
- "Do not show a toast when the name or the password is saved. The Button says it.",
3075
- "Do not keep the passwords in the fields after they are saved.",
3076
- "Do not ask for the new password twice. Show one field and the length rule."
3761
+ "Do not add a breadcrumb. Back goes one step up, and the title says where the person is.",
3762
+ "Do not show two primary Buttons.",
3763
+ "Do not name an icon button only by its icon, or More only by the word.",
3764
+ "Do not leave an action out on a phone without a way to reach it.",
3765
+ "Do not name the Back Button 'Back'. Name the page."
3077
3766
  ],
3078
- "native": "On Apple use a grouped `Form` with the name in a `TextField` and a `SecureField` for the password, and a `PhotosPicker` for the picture. The picture saves when it is chosen.",
3767
+ "native": "On Apple use a navigation title with `.toolbar` items: the primary action as a `ToolbarItem`, the rest in a `Menu`. The system back button names the page before it. On Android use a top app bar with an overflow menu.",
3079
3768
  "options": [
3080
3769
  {
3081
- "id": "form",
3082
- "title": "Picture, name and password",
3083
- "useWhen": "People sign in with a password and can change their own picture and name.",
3084
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Alert from 'oneslash-design-system/components/alert';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A picture the person chose. A real app uploads the file and gets a URL back.\nconst chosenPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E\";\n\nconst minPasswordLength = 8;\n// Stands in for the server's check. In this example every current password is right except this one.\nconst wrongCurrentPassword = 'incorrect';\n\nexport default function ProfileForm() {\n const [picture, setPicture] = useState<string | undefined>(undefined);\n // Which picture Button was pressed, so only that one shows `loading`.\n const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);\n const [pictureError, setPictureError] = useState('');\n\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [savingName, setSavingName] = useState(false);\n const [nameSaved, setNameSaved] = useState(false);\n\n const [currentPassword, setCurrentPassword] = useState('');\n const [currentPasswordError, setCurrentPasswordError] = useState('');\n const [password, setPassword] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [savingPassword, setSavingPassword] = useState(false);\n const [passwordSaved, setPasswordSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n // The first picture save fails, as if the upload dropped, so the example shows both paths.\n const pictureFails = useRef(true);\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(nameSavedTimer.current);\n clearTimeout(passwordSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.\n // When it fails, the old picture stays and a line under the Buttons says why.\n function savePicture(next: string | undefined, pressed: 'change' | 'remove') {\n if (savingPicture) return;\n setPictureError('');\n setSavingPicture(pressed);\n later(() => {\n setSavingPicture(null);\n if (pictureFails.current) {\n pictureFails.current = false;\n setPictureError('Could not save. Try again.');\n return;\n }\n setPicture(next);\n }, 900);\n }\n\n // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveName() {\n if (savingName) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSavingName(true);\n later(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSavingName(false);\n setNameSaved(true);\n clearTimeout(nameSavedTimer.current);\n nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);\n }, 1200);\n }\n\n function handleUpdatePassword() {\n if (savingPassword || !currentPassword || !password) return;\n setCurrentPasswordError('');\n if (password.length < minPasswordLength) {\n setPasswordError(`Use at least ${minPasswordLength} characters.`);\n return;\n }\n setPasswordError('');\n setSavingPassword(true);\n later(() => {\n setSavingPassword(false);\n // A wrong current password shows under that field, and both fields keep what the person typed.\n if (currentPassword === wrongCurrentPassword) {\n setCurrentPasswordError('This is not your current password. Enter it again.');\n return;\n }\n setCurrentPassword('');\n setPassword('');\n setPasswordSaved(true);\n clearTimeout(passwordSavedTimer.current);\n passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);\n }, 1200);\n }\n\n const nameChanged = name !== savedName;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Profile</Heading>\n\n <SettingsSection title=\"Picture\" description=\"Shown beside your name in Acme.\">\n <Cluster gap=\"large\">\n <UserImage userHandle={savedName} userImgUrl={picture} size={64} />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label=\"Change Picture\" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />\n {picture && <Button size=\"small\" type=\"tertiary\" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label=\"Remove\" aria-label=\"Remove picture\" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}\n </Cluster>\n {pictureError && <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={pictureError} />}\n </Stack>\n </Cluster>\n </SettingsSection>\n\n <SettingsSection title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSaveName}>\n <FormField id=\"profile-form-name\" label=\"Name\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={savingName}\n autoComplete=\"name\"\n onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={savingName} />\n </Cluster>\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Password\" description=\"Sign in with dana@acme.example and a password.\">\n <Form aria-label=\"Password\" gap=\"medium\" onSubmit={handleUpdatePassword}>\n <FormField id=\"profile-form-current-password\" label=\"Current password\" error={currentPasswordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={currentPassword}\n disabled={savingPassword}\n autoComplete=\"current-password\"\n onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <FormField id=\"profile-form-password\" label=\"New password\" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={password}\n disabled={savingPassword}\n autoComplete=\"new-password\"\n onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType=\"submit\" loading={savingPassword} />\n </Cluster>\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
3770
+ "id": "actions",
3771
+ "title": "The page's own actions",
3772
+ "useWhen": "The page is a place of its own, and the person can add to it, search it or change it.",
3773
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PageHeaderActions() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n // Which More button opened the menu: on a phone the menu also holds Search and Filter.\n const [from, setFrom] = useState<'wide' | 'phone'>('wide');\n const [open, setOpen] = useState(false);\n const [chosen, setChosen] = useState('');\n\n function openMore(kind: 'wide' | 'phone', el: HTMLElement) {\n setFrom(kind);\n setAnchor(el);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu. Its Popover gives focus back to the More button.\n function choose(label: string) {\n setOpen(false);\n setChosen(label);\n }\n\n const newTask = <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Task\" decoIcon=\"Plus\" onClickButton={() => setChosen('New Task')} />;\n\n const more = (kind: 'wide' | 'phone') => (\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={open && from === kind ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Home page\"\n aria-haspopup=\"menu\"\n aria-expanded={open && from === kind}\n onClick={(e: { currentTarget: HTMLElement }) => openMore(kind, e.currentTarget)}\n />\n </Tooltip>\n );\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* The title is the page's level 1 heading. One primary Button, then icon buttons, then More last. Below md only the primary and More stay. */}\n <TitleBar\n title=\"Home page\"\n actions={\n <>\n {newTask}\n <Tooltip title=\"Search\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Search\" ariaLabel=\"Search Home page\" onClick={() => setChosen('Search')} />\n </Tooltip>\n <Tooltip title=\"Filter\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Filter\" ariaLabel=\"Filter Home page\" onClick={() => setChosen('Filter')} />\n </Tooltip>\n {more('wide')}\n </>\n }\n phoneActions={\n <>\n {newTask}\n {more('phone')}\n </>\n }\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{chosen ? `You chose ${chosen}.` : '12 tasks are open. Updated 2 days ago by Dana Lee.'}</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Home page\" width={200}>\n {from === 'phone' && (\n <>\n <MenuItem size=\"small\" iconName=\"Search\" label=\"Search\" onClick={() => choose('Search')} />\n <MenuItem size=\"small\" iconName=\"Filter\" label=\"Filter\" onClick={() => choose('Filter')} />\n <Line />\n </>\n )}\n <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Rename\" onClick={() => choose('Rename')} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose('Duplicate')} />\n <MenuItem size=\"small\" iconName=\"Archive\" label=\"Archive\" onClick={() => choose('Archive')} />\n </Menu>\n </Popover>\n </PageShell>\n );\n}\n",
3774
+ "uses": [
3775
+ "Button",
3776
+ "IconButton",
3777
+ "Line",
3778
+ "Menu",
3779
+ "MenuItem",
3780
+ "PageShell",
3781
+ "Paragraph",
3782
+ "Popover",
3783
+ "Stack",
3784
+ "TitleBar",
3785
+ "Tooltip"
3786
+ ]
3787
+ },
3788
+ {
3789
+ "id": "sub-page",
3790
+ "title": "A page one step down, with Back",
3791
+ "useWhen": "The page opens from another page, such as a task from its project.",
3792
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Button from 'oneslash-design-system/components/button';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst taskTitle = 'Move the sign-up form above the pricing table on the home page';\n\nexport default function PageHeaderSubPage() {\n // The task is a page one step down from the project's page.\n const [view, setView] = useState<'task' | 'project'>('task');\n const [done, setDone] = useState(false);\n\n if (view === 'project') {\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Website</Heading>\n <Navigation aria-label=\"Tasks\">\n <MenuItem\n size=\"medium\"\n label={taskTitle}\n secondLabel={done ? 'Done' : 'Open'}\n iconRight=\"ChevronRight\"\n href=\"/website/tasks/sign-up-form\"\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the task's page. The example keeps the choice in state.\n event.preventDefault();\n setView('task');\n }}\n />\n </Navigation>\n </Stack>\n </PageShell>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* Back names the page it goes to. Below md it takes its own line above the title, and a long title wraps. */}\n <TitleBar\n title={taskTitle}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Website\" onClickButton={() => setView('project')} />}\n actions={<Button size=\"medium\" type=\"primary\" state={done ? 'disabled' : 'enabled'} label=\"Mark Done\" onClickButton={() => setDone(true)} />}\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{done ? 'Done. Marked by Dana Lee.' : 'Assigned to Ben Carter. Due on Friday.'}</Paragraph>\n </Stack>\n </PageShell>\n );\n}\n",
3085
3793
  "uses": [
3086
- "Alert",
3087
3794
  "Button",
3088
- "Center",
3089
- "Cluster",
3090
- "Form",
3091
- "FormField",
3092
3795
  "Heading",
3093
- "SettingsSection",
3796
+ "MenuItem",
3797
+ "Navigation",
3798
+ "PageShell",
3799
+ "Paragraph",
3094
3800
  "Stack",
3095
- "TextField",
3096
- "UserImage"
3801
+ "TitleBar"
3097
3802
  ]
3098
3803
  }
3099
3804
  ]
3100
3805
  },
3101
3806
  {
3102
- "id": "quick-switcher",
3103
- "title": "Quick switcher",
3807
+ "id": "paged-card",
3808
+ "title": "Short list on a dashboard",
3104
3809
  "kind": "design",
3105
3810
  "level": "organism",
3106
- "area": "menu",
3107
- "situation": "A person jumps to a channel, task or document by typing part of its name, from anywhere in the product.",
3811
+ "area": "dashboard",
3812
+ "situation": "A dashboard section lists things that wait on the person, such as questions or comments, and the list may be longer than the section.",
3108
3813
  "do": [
3109
- "Open it with Cmd+K, or Ctrl+K on Windows, and with a visible 'Go to' Button. A shortcut alone is not found.",
3110
- "Add the shortcut with `useHotkey('k', …)`. It is removed when the page goes away, and it does nothing while the person types in a field.",
3111
- "Open a small `Modal` with `initialFocus=\"body\"`, so focus lands in the search field. Closing gives focus back to where it was.",
3112
- "Build it as a combobox, as the case 'Mention list' says. The field gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`.",
3113
- "Make the list a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows, with `isActive` and `aria-selected` on the highlighted one.",
3114
- "Name the field with `aria-label=\"Go to\"`, since it has no visible label.",
3115
- "Show the most recent places, at most 6, before the person types.",
3116
- "Show each place with its icon and name, and where it lives in `secondLabel`.",
3117
- "Move the highlight with the arrow keys. Enter opens the highlighted place and closes the Modal. Escape closes it.",
3118
- "Leave Enter and the arrow keys to an input method while it is still composing.",
3119
- "Follow the case 'Empty search' when nothing matches: the words searched for and a 'Clear Search' Button, which puts focus back in the field."
3814
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3815
+ "Say the total in the title, as a number and its unit: '8 questions waiting on you'.",
3816
+ "Make every row a link to the thing it names, with a second line for when it was asked.",
3817
+ "Put `Pagination variant=\"compact\"` in the title row when the list pages, named for the card: 'Pages of questions waiting on you'.",
3818
+ "Keep the page length the same on every page. `Pagination` shows nothing when there is one page.",
3819
+ "Show five rows and a 'See All Questions' `Link` after them when the list does not page. The link goes to the full list, the case 'Data table page'.",
3820
+ "Show `EmptyBox size=\"small\"` when the list is empty, such as 'No questions waiting on you', with a `secondText` that says what will appear.",
3821
+ "Show the card as a hairline, a title and rows. Do not box it."
3120
3822
  ],
3121
3823
  "dont": [
3122
- "Do not use the shortcut as the only way in.",
3123
- "Do not take Cmd+K while the person types in a field. Some fields use it for their own commands.",
3124
- "Do not move focus into the list. The person keeps typing in the field.",
3125
- "Do not keep the last search. It opens empty.",
3126
- "Do not show a toast after going to a place. The page changing says it."
3824
+ "Do not page a long list on the dashboard. Show five rows and a link.",
3825
+ "Do not leave the pager unnamed. Name it for the card, so a screen reader hears 'Pages of questions waiting on you'.",
3826
+ "Do not write the page as '1/3'. `Pagination` writes '1 of 3' in a card and 'Page 1 of 3' elsewhere.",
3827
+ "Do not make a row that is not a link, or a link with no name.",
3828
+ "Do not scroll a list inside the card."
3127
3829
  ],
3128
- "native": "On Apple use a sheet with a `TextField` over a `List`, opened with `.keyboardShortcut(\"k\")`, and `ContentUnavailableView.search(text:)` when nothing matches. A phone needs no switcher: use the search tab.",
3830
+ "native": "On Apple use a `Section` of a `List` with a `NavigationLink` for each row, and a `NavigationLink` named See All for the footer. On Android use a `LazyColumn` of clickable rows.",
3129
3831
  "options": [
3130
3832
  {
3131
- "id": "modal",
3132
- "title": "Small Modal with a search field and a list",
3133
- "useWhen": "The product has many places to go to, and people work with a keyboard.",
3134
- "source": "'use client';\nimport { useState, type KeyboardEvent } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The most recent place comes first.\ntype Place = { id: string; title: string; kind: 'channel' | 'task' | 'doc'; workspace: string };\nconst places: Place[] = [\n { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },\n { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },\n { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },\n { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },\n { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },\n { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },\n];\nconst icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' } as const;\n\n// At most this many rows show, so the list never needs to scroll; typing more letters narrows it.\nconst MAX_RESULTS = 6;\nconst listId = 'quick-switcher-results';\nconst optionId = (p: Place) => `quick-switcher-option-${p.id}`;\n\n// Places with a word that starts with what was typed. With nothing typed it shows the most recent.\nfunction matches(query: string) {\n const q = query.trim().toLowerCase();\n if (!q) return places.slice(0, MAX_RESULTS);\n return places.filter((p) => p.title.toLowerCase().split(/[\\s-]+/).some((w) => w.startsWith(q))).slice(0, MAX_RESULTS);\n}\n\nexport default function QuickSwitcherModal() {\n // Opens with the switcher showing, as if the person just pressed Cmd+K.\n const [open, setOpen] = useState(true);\n const [query, setQuery] = useState('la');\n const [active, setActive] = useState(0);\n const [here, setHere] = useState<Place>(places[0]);\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field\n // instead of being lost with the Button that the list replaces.\n const [fieldKey, setFieldKey] = useState(0);\n\n const results = matches(query);\n const listOpen = results.length > 0;\n\n function openSwitcher() {\n setQuery('');\n setActive(0);\n setOpen(true);\n }\n\n // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.\n useHotkey('k', () => {\n if (!open) openSwitcher();\n });\n\n function change(value: string) {\n setQuery(value);\n setActive(0);\n }\n\n // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.\n function go(place: Place) {\n setHere(place);\n setOpen(false);\n }\n\n function clearSearch() {\n setQuery('');\n setActive(0);\n setFieldKey((k) => k + 1);\n }\n\n // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.\n function keyDown(e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!listOpen) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n go(results[active]);\n }\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">{here.title}</Heading>\n {/* A shortcut alone is not found by most people, so a Button opens it too. */}\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label=\"Go to\"\n decoIcon=\"Search\"\n aria-haspopup=\"dialog\"\n aria-keyshortcuts=\"Meta+K Control+K\"\n onClickButton={openSwitcher}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.\n </Paragraph>\n </Stack>\n <Modal isOpen={open} size=\"small\" title=\"Go to\" initialFocus=\"body\" onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n <TextField\n key={fieldKey}\n id=\"quick-switcher-query\"\n type=\"search\"\n // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.\n autoFocus={fieldKey > 0}\n aria-label=\"Go to\"\n placeholder=\"Search channels, tasks and documents\"\n value={query}\n onChange={(e) => change(e.target.value)}\n onKeyDown={keyDown}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listId : undefined}\n aria-activedescendant={listOpen ? optionId(results[active]) : undefined}\n />\n {listOpen ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Places\" width=\"100%\">\n {results.map((p, i) => (\n <MenuItem\n key={p.id}\n id={optionId(p)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName={icons[p.kind]}\n label={p.title}\n secondLabel={p.workspace}\n onClick={() => go(p)}\n />\n ))}\n </Menu>\n ) : (\n // The case 'Empty search' says what to show: the words searched for, and a way to clear them.\n <EmptyBox\n size=\"small\"\n icon=\"Search\"\n text={`No places match \"${query.trim()}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n )}\n </Stack>\n </Modal>\n </Center>\n );\n}\n",
3833
+ "id": "pager",
3834
+ "title": "Pager in the title row",
3835
+ "useWhen": "The list is short and stays on the dashboard, a few rows a page.",
3836
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst questions = [\n { id: 'q1', text: 'Which logo file should the launch page use?', when: 'Asked 2 hours ago' },\n { id: 'q2', text: 'Is the new pricing public before Friday?', when: 'Asked 4 times, 5 hours ago' },\n { id: 'q3', text: 'Who approves the final copy for the home page?', when: 'Asked yesterday' },\n { id: 'q4', text: 'Should the export include archived projects?', when: 'Asked yesterday' },\n { id: 'q5', text: 'What is the limit for a free workspace?', when: 'Asked 2 times, 2 days ago' },\n { id: 'q6', text: 'Can a guest see the activity log?', when: 'Asked 3 days ago' },\n { id: 'q7', text: 'Which time zone do the reports use?', when: 'Asked 4 days ago' },\n { id: 'q8', text: 'Does a deleted comment count as marked done?', when: 'Asked 5 days ago' },\n];\n\nconst PER_PAGE = 4;\n\nexport default function PagedCardPager() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(questions.length / PER_PAGE);\n const rows = questions.slice((page - 1) * PER_PAGE, page * PER_PAGE);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Line />\n {/* The total is in the title, and the pager is in the title row, named for the card. */}\n <Cluster justify=\"between\">\n <Heading level={2} size=\"h6\">{`${formatCount(questions.length)} ${questions.length === 1 ? 'question' : 'questions'} waiting on you`}</Heading>\n <Pagination variant=\"compact\" aria-label=\"Pages of questions waiting on you\" page={page} pageCount={pageCount} onPageChange={setPage} />\n </Cluster>\n <Stack gap=\"small\">\n {rows.map((q) => (\n <MenuItem\n key={q.id}\n size=\"medium\"\n label={q.text}\n secondLabel={q.when}\n href={`/questions/${q.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the question's page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3135
3837
  "uses": [
3136
- "Button",
3137
3838
  "Center",
3138
3839
  "Cluster",
3139
- "EmptyBox",
3140
3840
  "Heading",
3141
- "Menu",
3841
+ "Line",
3142
3842
  "MenuItem",
3143
- "Modal",
3144
- "Paragraph",
3843
+ "Pagination",
3145
3844
  "Stack",
3146
- "TextField",
3147
- "useHotkey"
3845
+ "formatCount"
3846
+ ]
3847
+ },
3848
+ {
3849
+ "id": "see-all",
3850
+ "title": "Five rows and See All",
3851
+ "useWhen": "The list is long, so the dashboard shows the newest five and a link to the full page.",
3852
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Link from 'oneslash-design-system/components/link';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server: the newest five, and how many there are in all.\nconst total = 142;\nconst questions = [\n { id: 'q1', text: 'Which logo file should the launch page use?', when: 'Asked 2 hours ago' },\n { id: 'q2', text: 'Is the new pricing public before Friday?', when: 'Asked 4 times, 5 hours ago' },\n { id: 'q3', text: 'Who approves the final copy for the home page?', when: 'Asked yesterday' },\n { id: 'q4', text: 'Should the export include archived projects?', when: 'Asked yesterday' },\n { id: 'q5', text: 'What is the limit for a free workspace?', when: 'Asked 2 times, 2 days ago' },\n];\n\nexport default function PagedCardSeeAll() {\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Line />\n <Heading level={2} size=\"h6\">{formatCount(total)} questions waiting on you</Heading>\n <Stack gap=\"small\">\n {questions.map((q) => (\n <MenuItem\n key={q.id}\n size=\"medium\"\n label={q.text}\n secondLabel={q.when}\n href={`/questions/${q.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the question's page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n {/* A real app links to the full list at '/questions', with its search and sorting. Link has no click handler to keep the example here, so it uses '#'. */}\n <Cluster>\n <Link href=\"#\" size=\"body2\">See All Questions</Link>\n </Cluster>\n </Stack>\n </Center>\n );\n}\n",
3853
+ "uses": [
3854
+ "Center",
3855
+ "Cluster",
3856
+ "Heading",
3857
+ "Line",
3858
+ "Link",
3859
+ "MenuItem",
3860
+ "Stack",
3861
+ "formatCount"
3148
3862
  ]
3149
3863
  }
3150
3864
  ]
3151
3865
  },
3152
3866
  {
3153
- "id": "range-switch",
3154
- "title": "Range switch",
3867
+ "id": "payment-method",
3868
+ "title": "Payment method",
3155
3869
  "kind": "design",
3156
3870
  "level": "organism",
3157
- "area": "menu",
3158
- "situation": "A person changes the time range of a chart or a list on the same page, such as Week, Month or Quarter.",
3871
+ "area": "dashboard",
3872
+ "situation": "A workspace pays by card. The admin sees which card, changes it or removes it.",
3159
3873
  "do": [
3160
- "Use `SegmentedControl` with `size=\"small\"` and `aria-label=\"Range\"`: 'Week', 'Month', 'Quarter'.",
3161
- "Put it beside the heading of the chart or list it changes, with `width=\"fit\"` so it is as wide as its options.",
3162
- "Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
3163
- "Change the numbers in place and keep the page, the heading and the scroll position.",
3164
- "Move between options with the arrow keys. They select as they move."
3874
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3875
+ "Show only the brand as text, the last four digits and the expiry: 'Visa ending in 4821' and 'Expires 08/28'. Nothing else about the card is on the page.",
3876
+ "Make 'Update' and 'Add Payment Method' links to the payment provider's own page: a `Button` with `href`, `openInNewTab` and an external-link `actionIcon`. Name it with where it goes: 'Update Visa ending in 4821, opens in a new tab'.",
3877
+ "Confirm 'Remove' in a small `Modal` titled 'Remove Card', as the case 'Delete confirm' says: 'This removes Visa ending in 4821 from Acme. Your plan and invoices are not changed.' 'Cancel' comes first, then a danger 'Remove'.",
3878
+ "Name the card in the Remove Button's `aria-label`: 'Remove Visa ending in 4821'.",
3879
+ "Show a toast that names the card when it is removed: 'Visa ending in 4821 removed.' Then show the empty state in the same place.",
3880
+ "Offer no Remove while a paid plan needs a card, and say why in one line: 'Pro needs a card on file. Downgrade to Free to remove it.'",
3881
+ "Add an inline warning `Alert` above the row a month before the card expires: 'This card expires on 08/28. Update it before then.'",
3882
+ "Say in one line that there is no card, say whether one is needed, and offer 'Add Payment Method'."
3165
3883
  ],
3166
3884
  "dont": [
3167
- "Do not use tabs. Tabs switch panels, and this changes one value on the same page.",
3168
- "Do not use more than four options. Use a menu, as the case 'Filter menu' says.",
3885
+ "Do not add a `TextField` for a card number, a security code, a bank account or an address. ODS has no payment form.",
3886
+ "Do not show a full card number, or part of it beyond the last four digits.",
3887
+ "Do not name the payment provider, or copy the look or the words of its page.",
3888
+ "Do not show a card-network logo. The brand is the word.",
3889
+ "Do not title the Modal 'Are you sure?'. Name the action: 'Remove Card'.",
3890
+ "Do not remove the card on the first click.",
3891
+ "Do not offer Remove while a paid plan needs the card.",
3892
+ "Do not show Update or Remove to a person who cannot change billing."
3893
+ ],
3894
+ "native": "On Apple a plan bought in the app has no card on the page: open the system subscription sheet. For a web card, show the same text and a `Link` out.",
3895
+ "options": [
3896
+ {
3897
+ "id": "on-file",
3898
+ "title": "A card is saved",
3899
+ "useWhen": "The workspace has a card on file.",
3900
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. Only the brand, the last four digits and the expiry ever reach the page.\nconst card = { brand: 'Visa', last4: '4821', month: 8, year: 2028 };\nconst today = { month: 11, year: 2026 };\nconst plan: 'Free' | 'Pro' = 'Free';\n\n// A paid plan needs a card, so Remove is not offered. The Free plan needs none.\nconst planNeedsCard = plan !== 'Free';\nconst monthsLeft = (card.year - today.year) * 12 + (card.month - today.month);\nconst expiry = `${String(card.month).padStart(2, '0')}/${String(card.year % 100).padStart(2, '0')}`;\nconst name = `${card.brand} ending in ${card.last4}`;\n\nexport default function PaymentMethodOnFile() {\n const [removed, setRemoved] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [removing, setRemoving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const addRef = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // The Remove Button is gone with the card, so focus moves to what takes its place.\n useEffect(() => {\n if (removed) addRef.current?.focus();\n }, [removed]);\n\n // Escape, a click outside and Cancel all close it, except while the request runs. The Modal gives focus back to Remove.\n function handleClose() {\n if (removing) return;\n setConfirming(false);\n }\n\n function handleRemove() {\n if (removing) return;\n setRemoving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setRemoving(false);\n setConfirming(false);\n setRemoved(true);\n toastIds.current.push(toast({ type: 'success', message: `${name} removed.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <SettingsSection title=\"Payment method\" description=\"Pays for Acme's plan.\">\n {removed ? (\n <Stack gap=\"medium\" align=\"start\">\n <Paragraph measure=\"none\">No payment method.</Paragraph>\n {/* A real app hands off to its payment provider's own page here. The page never takes card details. */}\n <Button ref={addRef} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Payment Method\" aria-label=\"Add payment method, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n {/* A month ahead of the expiry, the page says so. */}\n {monthsLeft <= 1 && monthsLeft >= 0 && (\n <Alert type=\"warning\" variant=\"inline\" autoDismiss={false} message={`This card expires on ${expiry}. Update it before then.`} />\n )}\n <Surface padding=\"small\">\n <Cluster justify=\"between\" gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{name}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Expires ${expiry}`}</Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n {/* Updating the card happens on the provider's page, so Update is a link out. */}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Update\" aria-label={`Update ${name}, opens in a new tab`} actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n {!planNeedsCard && (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${name}`} onClickButton={() => setConfirming(true)} />\n )}\n </Cluster>\n </Cluster>\n </Surface>\n {planNeedsCard && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Pro needs a card on file. Downgrade to Free to remove it.</Paragraph>}\n </Stack>\n )}\n </SettingsSection>\n {/* One card is not a dense list, so the confirm is a small Modal. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Remove Card\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={removing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" loading={removing} onClickButton={handleRemove} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This removes ${name} from Acme. Your plan and invoices are not changed.`}</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3901
+ "uses": [
3902
+ "Alert",
3903
+ "Button",
3904
+ "Center",
3905
+ "Cluster",
3906
+ "Modal",
3907
+ "Paragraph",
3908
+ "SettingsSection",
3909
+ "Stack",
3910
+ "Surface",
3911
+ "Toaster",
3912
+ "dismissToast",
3913
+ "toast"
3914
+ ]
3915
+ },
3916
+ {
3917
+ "id": "none",
3918
+ "title": "No card yet",
3919
+ "useWhen": "The workspace has never added a card, or removed it.",
3920
+ "source": "'use client';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PaymentMethodNone() {\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Payment method\" description=\"Pays for Acme's plan.\">\n <Stack gap=\"medium\" align=\"start\">\n <Paragraph measure=\"none\">No payment method.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Acme is on Free, so it needs none. Add one to upgrade.</Paragraph>\n {/* A real app hands off to its payment provider's own page here. The page never takes card details. */}\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Payment Method\" aria-label=\"Add payment method, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
3921
+ "uses": [
3922
+ "Button",
3923
+ "Center",
3924
+ "Paragraph",
3925
+ "SettingsSection",
3926
+ "Stack"
3927
+ ]
3928
+ }
3929
+ ]
3930
+ },
3931
+ {
3932
+ "id": "phone-navigation",
3933
+ "title": "On a phone, a sidebar opens as a drawer and a list opens its detail",
3934
+ "kind": "rule",
3935
+ "level": "rule",
3936
+ "area": "shell",
3937
+ "situation": "A layout with a sidebar, a list beside its detail, or a side pane meets a phone screen.",
3938
+ "answer": "An app's sidebar opens in a `Drawer` from the start side, from a 'Menu' `IconButton` at the start of a top bar that names the place. `AppShell` does this. The Drawer closes on a choice, on Close, on Escape, on the scrim and when the window widens. A list beside its detail becomes two screens: the list, then the detail with a Back Button named for the list, as `SettingsLayout` does. A settings nav is such a list. A side pane takes the whole content area and has Close. It is never squeezed beside the content. A site's links go into the same kind of menu, and one main action may stay in the bar. Nothing is hidden on a phone without a way to reach it. There is no bottom tab bar on the web.",
3939
+ "why": "A drawer opens over the page, so the person still sees where they are, and closing it puts them back on the same page. One drawer, built into `AppShell`, works the same way in every app.",
3940
+ "do": [
3941
+ "Open the sidebar in a `Drawer` from the start side, from a 'Menu' `IconButton` at the start of a top bar that names the place. Use `AppShell`.",
3942
+ "Close the drawer on a choice, Close, Escape, the scrim and when the window widens past `md`.",
3943
+ "Turn a list beside its detail into two screens on a phone: the list first, then the detail with a Back Button named for the list.",
3944
+ "Let a side pane take the whole content area on a phone, with a Close button.",
3945
+ "Put a site's links in the same kind of menu, and keep at most one main action in the bar.",
3946
+ "Give every place a way to be reached on a phone, even one that is only a link."
3947
+ ],
3948
+ "dont": [
3949
+ "Do not hide a link on a phone without a menu that holds it.",
3950
+ "Do not show a sidebar beside the page on a phone, or squeeze a side pane beside the content.",
3951
+ "Do not replace the page with the app's sidebar. Open the drawer over it. A settings nav is a list beside its detail, so it is the first screen on a phone.",
3952
+ "Do not add a bottom tab bar on the web.",
3953
+ "Do not leave a drawer that Escape and a tap outside cannot close."
3954
+ ],
3955
+ "native": "On iPhone use a `TabView` or a `NavigationStack` that pushes the detail with the system back button, and a `.sheet` for a short task. On Android use a navigation drawer or a bottom bar, and push the detail with the system back."
3956
+ },
3957
+ {
3958
+ "id": "plan-change-confirm",
3959
+ "title": "Plan change confirm",
3960
+ "kind": "design",
3961
+ "level": "organism",
3962
+ "area": "dashboard",
3963
+ "situation": "An admin chose another plan. Before anything changes they need to know what it costs and when it starts.",
3964
+ "do": [
3965
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3966
+ "Follow the rule 'A confirm says exactly what will happen': a `Modal` with `size=\"small\"`, 'Cancel' first, then the action named with the title's verb. The title and the Button are the same words: 'Upgrade to Pro'.",
3967
+ "Say the amount today and for how long for an upgrade: 'You pay $12.00 today for the 15 days left in November, then $24.00 each month.'",
3968
+ "Keep the label of the action Button while it runs ('Upgrade to Pro'), as `loading`. When it works, close the Modal and show the new plan where the plan is: 'Acme is on Pro.' Show no toast.",
3969
+ "Say when a downgrade starts and what stops: 'Pro stays on until Dec 1, 2026.' Then list what Acme loses, each with its number.",
3970
+ "Show the date on the page after a downgrade, where the plan is: 'Acme is on Pro until Dec 1, 2026, then Free.' A toast would be gone before it starts.",
3971
+ "Check the smaller plan's limits before the Modal opens. Keep the Button's label while it checks.",
3972
+ "List each exceeded limit with both numbers: 'Free allows 3 members. Acme has 7.' Put a `Link` to fix it under each, and give the Modal 'Cancel' only.",
3973
+ "Show the card that pays, by its last four digits only: 'The card ending in 4821 pays for it.'",
3974
+ "Show these Buttons only to a person who can change the plan, as the case 'Upgrade prompt' says."
3975
+ ],
3976
+ "dont": [
3977
+ "Do not title the Modal 'Switch to Pro' or 'Confirm'. Name the action: 'Upgrade to Pro'.",
3978
+ "Do not label the action 'Confirm', 'Proceed' or 'Yes, downgrade'.",
3979
+ "Do not write 'prorated charges' with no amount. Say the amount.",
3980
+ "Do not change the Button's label while it runs, such as to 'Upgrading...'.",
3981
+ "Do not open the Modal and then refuse. Check the limits first.",
3982
+ "Do not offer a disabled action Button in the blocked Modal. Offer only Cancel and the links that fix it.",
3983
+ "Do not show a card field or a full card number in the confirm.",
3984
+ "Do not say a downgrade is done today when it starts later."
3985
+ ],
3986
+ "native": "On Apple use the system purchase sheet for an upgrade and a `confirmationDialog` for a downgrade that waits. The sheet shows the price, so the dialog states the date.",
3987
+ "options": [
3988
+ {
3989
+ "id": "upgrade",
3990
+ "title": "An upgrade charges now",
3991
+ "useWhen": "The new plan costs more and starts at once.",
3992
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PlanChangeConfirmUpgrade() {\n // Opens on the confirm, as if the person just chose Upgrade to Pro.\n const [open, setOpen] = useState(true);\n const [upgrading, setUpgrading] = useState(false);\n const [plan, setPlan] = useState('Free');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (upgrading) return;\n setOpen(false);\n }\n\n function handleUpgrade() {\n if (upgrading) return;\n setUpgrading(true);\n // Stands in for the request to the server. A real app charges the card on file here, never in this page.\n timer.current = setTimeout(() => {\n setUpgrading(false);\n setOpen(false);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n setPlan('Pro');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Acme is on ${plan}.`}</Paragraph>\n {plan === 'Free' && (\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setOpen(true)} />\n </Cluster>\n )}\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={upgrading ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" loading={upgrading} onClickButton={handleUpgrade} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`You pay ${formatMoney(12)} today for the 15 days left in November, then ${formatMoney(24)} each month.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Pro is ${formatMoney(8)} per member per month. The card ending in 4821 pays for it.`}</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3993
+ "uses": [
3994
+ "Button",
3995
+ "Center",
3996
+ "Cluster",
3997
+ "Heading",
3998
+ "Modal",
3999
+ "Paragraph",
4000
+ "Stack",
4001
+ "formatMoney"
4002
+ ]
4003
+ },
4004
+ {
4005
+ "id": "downgrade",
4006
+ "title": "A downgrade waits",
4007
+ "useWhen": "The new plan costs less. It starts when the paid period ends, so nothing is lost today.",
4008
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PlanChangeConfirmDowngrade() {\n // Opens on the confirm, as if the person just chose Downgrade to Free.\n const [open, setOpen] = useState(true);\n const [downgrading, setDowngrading] = useState(false);\n const [scheduled, setScheduled] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (downgrading) return;\n setOpen(false);\n }\n\n function handleDowngrade() {\n if (downgrading) return;\n setDowngrading(true);\n // Stands in for the request to the server. Nothing is charged or lost today.\n timer.current = setTimeout(() => {\n setDowngrading(false);\n setOpen(false);\n setScheduled(true);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n {/* The change starts later, so the page says when. A toast would be gone before Dec 1. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{scheduled ? 'Acme is on Pro until Dec 1, 2026, then Free.' : 'Acme is on Pro.'}</Paragraph>\n {!scheduled && (\n <Cluster>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Downgrade to Free\" onClickButton={() => setOpen(true)} />\n </Cluster>\n )}\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Downgrade to Free\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={downgrading ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Downgrade to Free\" loading={downgrading} onClickButton={handleDowngrade} />\n </>\n }\n >\n <Paragraph measure=\"none\">Pro stays on until Dec 1, 2026. Acme is not charged again.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List\n size=\"body2\"\n marker=\"dot\"\n items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']}\n />\n </Modal>\n </Center>\n );\n}\n",
4009
+ "uses": [
4010
+ "Button",
4011
+ "Center",
4012
+ "Cluster",
4013
+ "Heading",
4014
+ "List",
4015
+ "Modal",
4016
+ "Paragraph",
4017
+ "Stack"
4018
+ ]
4019
+ },
4020
+ {
4021
+ "id": "blocked",
4022
+ "title": "The smaller plan does not fit",
4023
+ "useWhen": "The workspace is over a limit of the smaller plan, so the downgrade cannot happen until the person fixes it.",
4024
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Link from 'oneslash-design-system/components/link';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server. Free allows 3 members and 1 connected repository.\nconst exceeded = [\n { id: 'members', text: 'Free allows 3 members. Acme has 7.', fix: 'Manage Members', href: '/settings/members' },\n { id: 'repos', text: 'Free allows 1 connected repository. Acme has 2.', fix: 'Manage Repositories', href: '/settings/repositories' },\n];\n\nexport default function PlanChangeConfirmBlocked() {\n const [open, setOpen] = useState(true);\n const [checking, setChecking] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the check if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The limits are checked before the Modal opens, so the person never reads 'Downgrade' and then a refusal.\n function handleCheck() {\n if (checking) return;\n setChecking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setChecking(false);\n setOpen(true);\n }, 600);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Acme is on Pro.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Downgrade to Free\" loading={checking} onClickButton={handleCheck} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Downgrade to Free\"\n onClose={() => setOpen(false)}\n actions={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Cancel\" onClickButton={() => setOpen(false)} />}\n >\n <Paragraph measure=\"none\">Acme cannot move to Free yet. It is over two limits.</Paragraph>\n <List\n size=\"body2\"\n marker=\"dot\"\n items={exceeded.map((e) => (\n <Stack key={e.id} gap=\"small\" align=\"start\">\n <Paragraph size=\"body2\" measure=\"none\">{e.text}</Paragraph>\n <Link href={e.href} size=\"body2\">{e.fix}</Link>\n </Stack>\n ))}\n />\n </Modal>\n </Center>\n );\n}\n",
4025
+ "uses": [
4026
+ "Button",
4027
+ "Center",
4028
+ "Cluster",
4029
+ "Heading",
4030
+ "Link",
4031
+ "List",
4032
+ "Modal",
4033
+ "Paragraph",
4034
+ "Stack"
4035
+ ]
4036
+ }
4037
+ ]
4038
+ },
4039
+ {
4040
+ "id": "plan-picker",
4041
+ "title": "Plan picker",
4042
+ "kind": "design",
4043
+ "level": "organism",
4044
+ "area": "dashboard",
4045
+ "situation": "An admin compares the plans a workspace can be on and chooses one.",
4046
+ "do": [
4047
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4048
+ "Make each plan a `Surface` with its name as a heading, its price and a `List` of what it includes. Write each limit as a number with its unit: '3 members', '50 AI agent responses a month'.",
4049
+ "Put the cards in `Grid columns={3}`, which stacks them on a phone. Put the rows in one column.",
4050
+ "Mark the current plan with `Tag variant=\"textOnly\"` 'Current plan', and give it no Button.",
4051
+ "Give every other plan one Button named for the move: 'Upgrade to Pro' as primary, 'Downgrade to Free' as tertiary. It opens the case 'Plan change confirm'.",
4052
+ "Say a change that starts later with a Tag 'Starts Dec 1' on the new plan, and a line under the heading: 'Acme is on Pro until Dec 1, 2026, then Free.'",
4053
+ "Open the picker from 'Change Plan' on the case 'Billing page'. Show it only to a person who can change the plan.",
4054
+ "Add a `SegmentedControl` as the case 'Range switch' says once the plans bill by the year too. Leave it out while every plan bills monthly."
4055
+ ],
4056
+ "dont": [
4057
+ "Do not make a card clickable as a whole. Its Button is the one control, so a keyboard and a screen reader find it.",
4058
+ "Do not label the Buttons 'Select' or 'Choose'. Say the move: 'Upgrade to Pro'.",
4059
+ "Do not run the limits together in one line with dots between them. Use a `List`, one limit per item.",
4060
+ "Do not add a monthly and yearly switch when no plan bills yearly.",
4061
+ "Do not change a Button label to show it is busy, such as to 'Checking...'.",
4062
+ "Do not charge or change the plan from this page. The confirm does that."
4063
+ ],
4064
+ "native": "On Apple use a `List` of plans with the system purchase sheet, and mark the current plan with a checkmark and the words 'Current plan'. Never build a card by hand.",
4065
+ "options": [
4066
+ {
4067
+ "id": "cards",
4068
+ "title": "Cards side by side",
4069
+ "useWhen": "Two or three plans are compared at once, on a page with room for columns.",
4070
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype PlanId = 'free' | 'pro' | 'business';\n\n// Made-up plans. A real app reads them from the server, with the limits as numbers.\nconst plans: { id: PlanId; name: string; price: string; includes: string[] }[] = [\n { id: 'free', name: 'Free', price: `${formatMoney(0)} per month`, includes: ['3 members', '50 AI agent responses a month', '1 GB of storage'] },\n { id: 'pro', name: 'Pro', price: `${formatMoney(8)} per member per month`, includes: ['Unlimited members', '1,000 AI agent responses a month', '50 GB of storage', 'Export to PDF'] },\n { id: 'business', name: 'Business', price: `${formatMoney(16)} per member per month`, includes: ['Unlimited members', '10,000 AI agent responses a month', '500 GB of storage', 'Export to PDF', 'Priority support'] },\n];\n\nconst rank: Record<PlanId, number> = { free: 0, pro: 1, business: 2 };\n\n// What the change costs. An upgrade charges now; a downgrade waits for the end of the period. A real app reads the amounts from the server.\nfunction describe(from: PlanId, to: PlanId) {\n const name = plans.find((p) => p.id === to)!.name;\n if (rank[to] > rank[from]) {\n // Three members, 15 of 30 days left in November: half of the first month today.\n const today = to === 'pro' ? 12 : from === 'free' ? 24 : 12;\n const monthly = to === 'pro' ? 24 : 48;\n const body = `You pay ${formatMoney(today)} today for the 15 days left in November, then ${formatMoney(monthly)} each month.`;\n return { title: `Upgrade to ${name}`, body, detail: false };\n }\n // A downgrade changes nothing today. It says when it starts and what stops.\n return { title: `Downgrade to ${name}`, body: `${plans.find((p) => p.id === from)!.name} stays on until Dec 1, 2026. Acme is not charged again.`, detail: true };\n}\n\nexport default function PlanPickerCards() {\n const [current, setCurrent] = useState<PlanId>('free');\n const [scheduled, setScheduled] = useState<PlanId | null>(null);\n const [target, setTarget] = useState<PlanId | null>(null);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setTarget(null);\n }\n\n function handleConfirm() {\n if (busy || !target) return;\n const to = target;\n setBusy(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setBusy(false);\n setTarget(null);\n if (rank[to] > rank[current]) {\n setCurrent(to);\n setScheduled(null);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n } else {\n // A downgrade changes nothing today, so the page says when it starts.\n setScheduled(to);\n }\n }, 1200);\n }\n\n const copy = target ? describe(current, target) : null;\n const currentName = plans.find((p) => p.id === current)!.name;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Plan\" description={scheduled ? `Acme is on ${currentName} until Dec 1, 2026, then ${plans.find((p) => p.id === scheduled)!.name}.` : `Acme is on ${currentName}.`}>\n {/* Two or three plans side by side from md up, stacked on a phone. A card is not itself clickable. */}\n <Grid columns={3}>\n {plans.map((p) => (\n <Surface key={p.id} padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">{p.name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.price}</Paragraph>\n </Stack>\n <List items={p.includes} size=\"body2\" marker=\"dot\" />\n {p.id === current ? (\n <Cluster><Tag variant=\"textOnly\" size=\"small\" label=\"Current plan\" /></Cluster>\n ) : p.id === scheduled ? (\n <Cluster><Tag variant=\"dot\" size=\"small\" label=\"Starts Dec 1\" /></Cluster>\n ) : rank[p.id] > rank[current] ? (\n <Cluster><Button size=\"small\" type=\"primary\" state=\"enabled\" label={`Upgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} /></Cluster>\n ) : (\n <Cluster><Button size=\"small\" type=\"tertiary\" state=\"enabled\" label={`Downgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} /></Cluster>\n )}\n </Stack>\n </Surface>\n ))}\n </Grid>\n </SettingsSection>\n <Modal\n isOpen={target !== null}\n size=\"small\"\n title={copy?.title ?? ''}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label={copy?.title ?? ''} loading={busy} onClickButton={handleConfirm} />\n </>\n }\n >\n <Paragraph measure=\"none\">{copy?.body}</Paragraph>\n {copy?.detail && (\n <>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List size=\"body2\" marker=\"dot\" items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']} />\n </>\n )}\n </Modal>\n </Center>\n );\n}\n",
4071
+ "uses": [
4072
+ "Button",
4073
+ "Center",
4074
+ "Cluster",
4075
+ "Grid",
4076
+ "Heading",
4077
+ "List",
4078
+ "Modal",
4079
+ "Paragraph",
4080
+ "SettingsSection",
4081
+ "Stack",
4082
+ "Surface",
4083
+ "Tag",
4084
+ "formatMoney"
4085
+ ]
4086
+ },
4087
+ {
4088
+ "id": "list",
4089
+ "title": "Rows in a settings column",
4090
+ "useWhen": "The picker sits in a narrow settings column, or the plans have long lists of what they include.",
4091
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype PlanId = 'free' | 'pro' | 'business';\n\n// Made-up plans. A real app reads them from the server, with the limits as numbers.\nconst plans: { id: PlanId; name: string; price: string; includes: string[] }[] = [\n { id: 'free', name: 'Free', price: `${formatMoney(0)} per month`, includes: ['3 members', '50 AI agent responses a month', '1 GB of storage'] },\n { id: 'pro', name: 'Pro', price: `${formatMoney(8)} per member per month`, includes: ['Unlimited members', '1,000 AI agent responses a month', '50 GB of storage', 'Export to PDF'] },\n { id: 'business', name: 'Business', price: `${formatMoney(16)} per member per month`, includes: ['Unlimited members', '10,000 AI agent responses a month', '500 GB of storage', 'Export to PDF', 'Priority support'] },\n];\n\nconst rank: Record<PlanId, number> = { free: 0, pro: 1, business: 2 };\n\n// What the change costs. An upgrade charges now; a downgrade waits for the end of the period. A real app reads the amounts from the server.\nfunction describe(from: PlanId, to: PlanId) {\n const name = plans.find((p) => p.id === to)!.name;\n if (rank[to] > rank[from]) {\n // Three members, 15 of 30 days left in November: half of the first month today.\n const today = to === 'pro' ? 12 : from === 'free' ? 24 : 12;\n const monthly = to === 'pro' ? 24 : 48;\n const body = `You pay ${formatMoney(today)} today for the 15 days left in November, then ${formatMoney(monthly)} each month.`;\n return { title: `Upgrade to ${name}`, body, detail: false };\n }\n // A downgrade changes nothing today. It says when it starts and what stops.\n return { title: `Downgrade to ${name}`, body: `${plans.find((p) => p.id === from)!.name} stays on until Dec 1, 2026. Acme is not charged again.`, detail: true };\n}\n\nexport default function PlanPickerList() {\n const [current, setCurrent] = useState<PlanId>('pro');\n const [scheduled, setScheduled] = useState<PlanId | null>(null);\n const [target, setTarget] = useState<PlanId | null>(null);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setTarget(null);\n }\n\n function handleConfirm() {\n if (busy || !target) return;\n const to = target;\n setBusy(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setBusy(false);\n setTarget(null);\n if (rank[to] > rank[current]) {\n setCurrent(to);\n setScheduled(null);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n } else {\n // A downgrade changes nothing today, so the page says when it starts.\n setScheduled(to);\n }\n }, 1200);\n }\n\n const copy = target ? describe(current, target) : null;\n const currentName = plans.find((p) => p.id === current)!.name;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Plan\" description={scheduled ? `Acme is on ${currentName} until Dec 1, 2026, then ${plans.find((p) => p.id === scheduled)!.name}.` : `Acme is on ${currentName}.`}>\n {/* Rows in the settings column. The plan and what it includes on the left, the one action on the right. */}\n <Stack gap=\"medium\">\n {plans.map((p) => (\n <Surface key={p.id} padding=\"small\">\n <Cluster justify=\"between\" align=\"start\" gap=\"medium\">\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"h6\">{p.name}</Heading>\n {p.id === current && <Tag variant=\"textOnly\" size=\"small\" label=\"Current plan\" />}\n {p.id === scheduled && <Tag variant=\"dot\" size=\"small\" label=\"Starts Dec 1\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.price}</Paragraph>\n <List items={p.includes} size=\"body2\" marker=\"dot\" />\n </Stack>\n {p.id !== current && p.id !== scheduled && (\n rank[p.id] > rank[current]\n ? <Button size=\"small\" type=\"primary\" state=\"enabled\" label={`Upgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} />\n : <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label={`Downgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} />\n )}\n </Cluster>\n </Surface>\n ))}\n </Stack>\n </SettingsSection>\n <Modal\n isOpen={target !== null}\n size=\"small\"\n title={copy?.title ?? ''}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label={copy?.title ?? ''} loading={busy} onClickButton={handleConfirm} />\n </>\n }\n >\n <Paragraph measure=\"none\">{copy?.body}</Paragraph>\n {copy?.detail && (\n <>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List size=\"body2\" marker=\"dot\" items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']} />\n </>\n )}\n </Modal>\n </Center>\n );\n}\n",
4092
+ "uses": [
4093
+ "Button",
4094
+ "Center",
4095
+ "Cluster",
4096
+ "Heading",
4097
+ "List",
4098
+ "Modal",
4099
+ "Paragraph",
4100
+ "SettingsSection",
4101
+ "Stack",
4102
+ "Surface",
4103
+ "Tag",
4104
+ "formatMoney"
4105
+ ]
4106
+ }
4107
+ ]
4108
+ },
4109
+ {
4110
+ "id": "profile-form",
4111
+ "title": "Profile",
4112
+ "kind": "design",
4113
+ "level": "organism",
4114
+ "area": "settings",
4115
+ "situation": "A person changes how they appear and how they sign in: their picture, their name and their password.",
4116
+ "do": [
4117
+ "Follow the rule 'A setting saves in place, or with one Save Button'.",
4118
+ "Put the picture, the name and the password in their own `SettingsSection`s. Do not mix a control that saves on change and a Save Button in one section.",
4119
+ "Save the picture as soon as the person chooses it, with 'Change Picture' and 'Remove'. Show `loading` on the Button that was pressed while it saves, and nothing when it works.",
4120
+ "When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'",
4121
+ "Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.",
4122
+ "Give the name one Save Button inside a `Form`. It is `state=\"disabled\"` while the name has not changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.",
4123
+ "Give the password one 'Update Password' Button. Ask for the current password and the new one. It is disabled while either field is empty, and reads 'Saved' for 2 seconds. Then clear both fields.",
4124
+ "Show a wrong current password under that field, and keep what the person typed in both.",
4125
+ "Use `<TextField type=\"password\">` for both, with `autoComplete=\"current-password\"` and `autoComplete=\"new-password\"`.",
4126
+ "Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. This ties its label, help and error to it.",
4127
+ "Show a problem with a field under it, as the rule 'A form error shows next to the problem' says: 'Enter your name.' and 'Use at least 8 characters.'",
4128
+ "Disable the field while its request runs, and keep what the person typed when the save fails.",
4129
+ "Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial."
4130
+ ],
4131
+ "dont": [
4132
+ "Do not add one Save Button for the whole page. Each group saves by itself.",
4133
+ "Do not label the Button 'Saving…' while it runs. It keeps its label.",
4134
+ "Do not show a toast when the name or the password is saved. The Button says it.",
4135
+ "Do not keep the passwords in the fields after they are saved.",
4136
+ "Do not ask for the new password twice. Show one field and the length rule."
4137
+ ],
4138
+ "native": "On Apple use a grouped `Form` with the name in a `TextField` and a `SecureField` for the password, and a `PhotosPicker` for the picture. The picture saves when it is chosen.",
4139
+ "options": [
4140
+ {
4141
+ "id": "form",
4142
+ "title": "Picture, name and password",
4143
+ "useWhen": "People sign in with a password and can change their own picture and name.",
4144
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Alert from 'oneslash-design-system/components/alert';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A picture the person chose. A real app uploads the file and gets a URL back.\nconst chosenPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E\";\n\nconst minPasswordLength = 8;\n// Stands in for the server's check. In this example every current password is right except this one.\nconst wrongCurrentPassword = 'incorrect';\n\nexport default function ProfileForm() {\n const [picture, setPicture] = useState<string | undefined>(undefined);\n // Which picture Button was pressed, so only that one shows `loading`.\n const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);\n const [pictureError, setPictureError] = useState('');\n\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [savingName, setSavingName] = useState(false);\n const [nameSaved, setNameSaved] = useState(false);\n\n const [currentPassword, setCurrentPassword] = useState('');\n const [currentPasswordError, setCurrentPasswordError] = useState('');\n const [password, setPassword] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [savingPassword, setSavingPassword] = useState(false);\n const [passwordSaved, setPasswordSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n // The first picture save fails, as if the upload dropped, so the example shows both paths.\n const pictureFails = useRef(true);\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(nameSavedTimer.current);\n clearTimeout(passwordSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.\n // When it fails, the old picture stays and a line under the Buttons says why.\n function savePicture(next: string | undefined, pressed: 'change' | 'remove') {\n if (savingPicture) return;\n setPictureError('');\n setSavingPicture(pressed);\n later(() => {\n setSavingPicture(null);\n if (pictureFails.current) {\n pictureFails.current = false;\n setPictureError('Could not save. Try again.');\n return;\n }\n setPicture(next);\n }, 900);\n }\n\n // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveName() {\n if (savingName) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSavingName(true);\n later(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSavingName(false);\n setNameSaved(true);\n clearTimeout(nameSavedTimer.current);\n nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);\n }, 1200);\n }\n\n function handleUpdatePassword() {\n if (savingPassword || !currentPassword || !password) return;\n setCurrentPasswordError('');\n if (password.length < minPasswordLength) {\n setPasswordError(`Use at least ${minPasswordLength} characters.`);\n return;\n }\n setPasswordError('');\n setSavingPassword(true);\n later(() => {\n setSavingPassword(false);\n // A wrong current password shows under that field, and both fields keep what the person typed.\n if (currentPassword === wrongCurrentPassword) {\n setCurrentPasswordError('This is not your current password. Enter it again.');\n return;\n }\n setCurrentPassword('');\n setPassword('');\n setPasswordSaved(true);\n clearTimeout(passwordSavedTimer.current);\n passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);\n }, 1200);\n }\n\n const nameChanged = name !== savedName;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Profile</Heading>\n\n <SettingsSection title=\"Picture\" description=\"Shown beside your name in Acme.\">\n <Cluster gap=\"large\">\n <UserImage userHandle={savedName} userImgUrl={picture} size={64} />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label=\"Change Picture\" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />\n {picture && <Button size=\"small\" type=\"tertiary\" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label=\"Remove\" aria-label=\"Remove picture\" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}\n </Cluster>\n {pictureError && <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={pictureError} />}\n </Stack>\n </Cluster>\n </SettingsSection>\n\n <SettingsSection title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSaveName}>\n <FormField id=\"profile-form-name\" label=\"Name\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={savingName}\n autoComplete=\"name\"\n onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={savingName} />\n </Cluster>\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Password\" description=\"Sign in with dana@acme.example and a password.\">\n <Form aria-label=\"Password\" gap=\"medium\" onSubmit={handleUpdatePassword}>\n <FormField id=\"profile-form-current-password\" label=\"Current password\" error={currentPasswordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={currentPassword}\n disabled={savingPassword}\n autoComplete=\"current-password\"\n onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <FormField id=\"profile-form-password\" label=\"New password\" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={password}\n disabled={savingPassword}\n autoComplete=\"new-password\"\n onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType=\"submit\" loading={savingPassword} />\n </Cluster>\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
4145
+ "uses": [
4146
+ "Alert",
4147
+ "Button",
4148
+ "Center",
4149
+ "Cluster",
4150
+ "Form",
4151
+ "FormField",
4152
+ "Heading",
4153
+ "SettingsSection",
4154
+ "Stack",
4155
+ "TextField",
4156
+ "UserImage"
4157
+ ]
4158
+ }
4159
+ ]
4160
+ },
4161
+ {
4162
+ "id": "quick-switcher",
4163
+ "title": "Quick switcher",
4164
+ "kind": "design",
4165
+ "level": "organism",
4166
+ "area": "menu",
4167
+ "situation": "A person jumps to a channel, task or document by typing part of its name, from anywhere in the product.",
4168
+ "do": [
4169
+ "Open it with Cmd+K, or Ctrl+K on Windows, and with a visible 'Go to' Button. A shortcut alone is not found.",
4170
+ "Add the shortcut with `useHotkey('k', …)`. It is removed when the page goes away, and it does nothing while the person types in a field.",
4171
+ "Open a small `Modal` with `initialFocus=\"body\"`, so focus lands in the search field. Closing gives focus back to where it was.",
4172
+ "Build it as a combobox, as the case 'Mention list' says. The field gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`.",
4173
+ "Make the list a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows, with `isActive` and `aria-selected` on the highlighted one.",
4174
+ "Name the field with `aria-label=\"Go to\"`, since it has no visible label.",
4175
+ "Show the most recent places, at most 6, before the person types.",
4176
+ "Show each place with its icon and name, and where it lives in `secondLabel`.",
4177
+ "Move the highlight with the arrow keys. Enter opens the highlighted place and closes the Modal. Escape closes it.",
4178
+ "Leave Enter and the arrow keys to an input method while it is still composing.",
4179
+ "Follow the case 'Empty search' when nothing matches: the words searched for and a 'Clear Search' Button, which puts focus back in the field."
4180
+ ],
4181
+ "dont": [
4182
+ "Do not use the shortcut as the only way in.",
4183
+ "Do not take Cmd+K while the person types in a field. Some fields use it for their own commands.",
4184
+ "Do not move focus into the list. The person keeps typing in the field.",
4185
+ "Do not keep the last search. It opens empty.",
4186
+ "Do not show a toast after going to a place. The page changing says it."
4187
+ ],
4188
+ "native": "On Apple use a sheet with a `TextField` over a `List`, opened with `.keyboardShortcut(\"k\")`, and `ContentUnavailableView.search(text:)` when nothing matches. A phone needs no switcher: use the search tab.",
4189
+ "options": [
4190
+ {
4191
+ "id": "modal",
4192
+ "title": "Small Modal with a search field and a list",
4193
+ "useWhen": "The product has many places to go to, and people work with a keyboard.",
4194
+ "source": "'use client';\nimport { useState, type KeyboardEvent } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The most recent place comes first.\ntype Place = { id: string; title: string; kind: 'channel' | 'task' | 'doc'; workspace: string };\nconst places: Place[] = [\n { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },\n { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },\n { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },\n { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },\n { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },\n { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },\n];\nconst icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' } as const;\n\n// At most this many rows show, so the list never needs to scroll; typing more letters narrows it.\nconst MAX_RESULTS = 6;\nconst listId = 'quick-switcher-results';\nconst optionId = (p: Place) => `quick-switcher-option-${p.id}`;\n\n// Places with a word that starts with what was typed. With nothing typed it shows the most recent.\nfunction matches(query: string) {\n const q = query.trim().toLowerCase();\n if (!q) return places.slice(0, MAX_RESULTS);\n return places.filter((p) => p.title.toLowerCase().split(/[\\s-]+/).some((w) => w.startsWith(q))).slice(0, MAX_RESULTS);\n}\n\nexport default function QuickSwitcherModal() {\n // Opens with the switcher showing, as if the person just pressed Cmd+K.\n const [open, setOpen] = useState(true);\n const [query, setQuery] = useState('la');\n const [active, setActive] = useState(0);\n const [here, setHere] = useState<Place>(places[0]);\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field\n // instead of being lost with the Button that the list replaces.\n const [fieldKey, setFieldKey] = useState(0);\n\n const results = matches(query);\n const listOpen = results.length > 0;\n\n function openSwitcher() {\n setQuery('');\n setActive(0);\n setOpen(true);\n }\n\n // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.\n useHotkey('k', () => {\n if (!open) openSwitcher();\n });\n\n function change(value: string) {\n setQuery(value);\n setActive(0);\n }\n\n // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.\n function go(place: Place) {\n setHere(place);\n setOpen(false);\n }\n\n function clearSearch() {\n setQuery('');\n setActive(0);\n setFieldKey((k) => k + 1);\n }\n\n // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.\n function keyDown(e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!listOpen) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n go(results[active]);\n }\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">{here.title}</Heading>\n {/* A shortcut alone is not found by most people, so a Button opens it too. */}\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label=\"Go to\"\n decoIcon=\"Search\"\n aria-haspopup=\"dialog\"\n aria-keyshortcuts=\"Meta+K Control+K\"\n onClickButton={openSwitcher}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.\n </Paragraph>\n </Stack>\n <Modal isOpen={open} size=\"small\" title=\"Go to\" initialFocus=\"body\" onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n <TextField\n key={fieldKey}\n id=\"quick-switcher-query\"\n type=\"search\"\n // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.\n autoFocus={fieldKey > 0}\n aria-label=\"Go to\"\n placeholder=\"Search channels, tasks and documents\"\n value={query}\n onChange={(e) => change(e.target.value)}\n onKeyDown={keyDown}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listId : undefined}\n aria-activedescendant={listOpen ? optionId(results[active]) : undefined}\n />\n {listOpen ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Places\" width=\"100%\">\n {results.map((p, i) => (\n <MenuItem\n key={p.id}\n id={optionId(p)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName={icons[p.kind]}\n label={p.title}\n secondLabel={p.workspace}\n onClick={() => go(p)}\n />\n ))}\n </Menu>\n ) : (\n // The case 'Empty search' says what to show: the words searched for, and a way to clear them.\n <EmptyBox\n size=\"small\"\n icon=\"Search\"\n text={`No places match \"${query.trim()}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n )}\n </Stack>\n </Modal>\n </Center>\n );\n}\n",
4195
+ "uses": [
4196
+ "Button",
4197
+ "Center",
4198
+ "Cluster",
4199
+ "EmptyBox",
4200
+ "Heading",
4201
+ "Menu",
4202
+ "MenuItem",
4203
+ "Modal",
4204
+ "Paragraph",
4205
+ "Stack",
4206
+ "TextField",
4207
+ "useHotkey"
4208
+ ]
4209
+ }
4210
+ ]
4211
+ },
4212
+ {
4213
+ "id": "range-switch",
4214
+ "title": "Range switch",
4215
+ "kind": "design",
4216
+ "level": "organism",
4217
+ "area": "menu",
4218
+ "situation": "A person changes the time range of the numbers or a list on the same page, such as Week, Month or Quarter.",
4219
+ "do": [
4220
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4221
+ "Use `SegmentedControl` with `size=\"small\"` and `aria-label=\"Range\"`: 'Week', 'Month', 'Quarter'.",
4222
+ "Put it beside the heading of the numbers or list it changes, with `width=\"fit\"` so it is as wide as its options.",
4223
+ "Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
4224
+ "Change the numbers in place and keep the page, the heading and the scroll position.",
4225
+ "Move between options with the arrow keys. They select as they move."
4226
+ ],
4227
+ "dont": [
4228
+ "Do not use tabs. Tabs switch panels, and this changes one value on the same page.",
4229
+ "Do not use more than four options. Use a menu, as the case 'Filter menu' says.",
3169
4230
  "Do not let the person turn every option off.",
3170
4231
  "Do not hide a range of three choices behind a menu."
3171
4232
  ],
@@ -3175,14 +4236,15 @@
3175
4236
  "id": "segmented",
3176
4237
  "title": "Segmented control",
3177
4238
  "useWhen": "Two to four short choices change the numbers on one page, and one is always on.",
3178
- "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst ranges = [\n { value: 'week', label: 'Week', count: 18 },\n { value: 'month', label: 'Month', count: 64 },\n { value: 'quarter', label: 'Quarter', count: 171 },\n];\n\nexport default function RangeSwitchSegmented() {\n const [range, setRange] = useState('week');\n const current = ranges.find((r) => r.value === range) ?? ranges[0];\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Overview</Heading>\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Range\"\n options={ranges.map(({ value, label }) => ({ value, label }))}\n value={range}\n onChange={setRange}\n />\n </Cluster>\n {/* The chart or list below changes with the range. This page stays the same. */}\n <Paragraph size=\"body2\" measure=\"none\">{current.count} comments this {current.label.toLowerCase()}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
4239
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst ranges: { value: string; label: string; period: 'week' | 'month' | 'quarter'; comments: number[]; done: number[]; people: number[] }[] = [\n { value: 'week', label: 'Week', period: 'week', comments: [18, 15], done: [11, 12], people: [7, 7] },\n { value: 'month', label: 'Month', period: 'month', comments: [64, 52], done: [40, 41], people: [12, 10] },\n { value: 'quarter', label: 'Quarter', period: 'quarter', comments: [171, 160], done: [118, 109], people: [19, 21] },\n];\n\nexport default function RangeSwitchSegmented() {\n const [range, setRange] = useState('week');\n const current = ranges.find((r) => r.value === range) ?? ranges[0];\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Overview</Heading>\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Range\"\n options={ranges.map(({ value, label }) => ({ value, label }))}\n value={range}\n onChange={setRange}\n />\n </Cluster>\n {/* The numbers change with the range. This page stays the same. */}\n <Grid compact columns={3}>\n <StatTile label=\"New comments\" value={current.comments[0]} previous={current.comments[1]} period={current.period} />\n <StatTile label=\"Marked done\" value={current.done[0]} previous={current.done[1]} period={current.period} />\n <StatTile label=\"People engaged\" value={current.people[0]} previous={current.people[1]} period={current.period} />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
3179
4240
  "uses": [
3180
4241
  "Center",
3181
4242
  "Cluster",
4243
+ "Grid",
3182
4244
  "Heading",
3183
- "Paragraph",
3184
4245
  "SegmentedControl",
3185
- "Stack"
4246
+ "Stack",
4247
+ "StatTile"
3186
4248
  ]
3187
4249
  }
3188
4250
  ]
@@ -3428,15 +4490,15 @@
3428
4490
  "id": "region",
3429
4491
  "title": "In one pane",
3430
4492
  "useWhen": "The shell shows and one pane loads.",
3431
- "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function RouteLoadingRegion() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <LoadingScreen />\n </Surface>\n </Stack>\n );\n}\n",
4493
+ "source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Surface from 'oneslash-design-system/components/surface';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function RouteLoadingRegion() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <LoadingScreen />\n </Surface>\n </AppShell>\n );\n}\n",
3432
4494
  "uses": [
3433
- "Cluster",
3434
- "Image",
4495
+ "AppShell",
3435
4496
  "LoadingScreen",
3436
- "Stack",
3437
- "Surface",
3438
- "Tab",
3439
- "TabsContainer"
4497
+ "MenuItem",
4498
+ "Navigation",
4499
+ "NavigationGroup",
4500
+ "Paragraph",
4501
+ "Surface"
3440
4502
  ]
3441
4503
  }
3442
4504
  ]
@@ -3581,7 +4643,7 @@
3581
4643
  "id": "top-tabs",
3582
4644
  "title": "Tabs across the top",
3583
4645
  "useWhen": "Four areas or fewer, with short names that fit on a phone.",
3584
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport SettingsSection, { SettingsColumns } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = 'profile' | 'notifications' | 'billing';\n\n// Four areas or fewer, each named with one short word, so the tabs fit on a phone. Each tab is a page of its own in a real app, so it has an `href`.\nconst areas: { id: Area; label: string }[] = [\n { id: 'profile', label: 'Profile' },\n { id: 'notifications', label: 'Notifications' },\n { id: 'billing', label: 'Billing' },\n];\n\nconst invoices = ['January 2025, $40.00', 'December 2024, $40.00', 'November 2024, $40.00'];\n\nexport default function SettingsPageTopTabs() {\n const [area, setArea] = useState<Area>('profile');\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open area.\n const router = { push: (url: string) => setArea(url.split('/').pop() as Area) };\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-tabs-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-email\" title=\"Email\" description=\"Where Acme writes to you.\">\n <FormField id=\"settings-page-tabs-email-field\" label=\"Email\" help=\"Only support can change this. Write to help@acme.example.\">\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} value=\"dana@acme.example\" readOnly onChange={() => {}} />}\n </FormField>\n </SettingsSection>\n </SettingsColumns>\n );\n\n const notifications = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-email-alerts\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-tabs-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-tabs-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n </SettingsColumns>\n );\n\n const billing = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-plan\" title=\"Plan\" description=\"Team plan, 5 seats.\">\n <Paragraph size=\"body2\" measure=\"none\">Renews on January 15. Only owners can change the plan.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-invoices\" title=\"Invoices\" description=\"The last three months.\">\n <List items={invoices} size=\"body2\" />\n </SettingsSection>\n </SettingsColumns>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <TabsContainer>\n {areas.map((a) => (\n <Tab key={a.id} label={a.label} href={`/settings/${a.id}`} router={router} isSelected={area === a.id} onClickTab={() => setArea(a.id)} />\n ))}\n </TabsContainer>\n {area === 'profile' && profile}\n {area === 'notifications' && notifications}\n {area === 'billing' && billing}\n </Stack>\n </Center>\n );\n}\n",
4646
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport SettingsSection, { SettingsColumns } from 'oneslash-design-system/components/settingsSection';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = 'profile' | 'notifications' | 'billing';\n\n// Four areas or fewer, each named with one short word, so the tabs fit on a phone. Each tab is a page of its own in a real app, so it has an `href`.\nconst areas: { id: Area; label: string }[] = [\n { id: 'profile', label: 'Profile' },\n { id: 'notifications', label: 'Notifications' },\n { id: 'billing', label: 'Billing' },\n];\n\nconst invoices = [`November 2026, ${formatMoney(24)}`, `October 2026, ${formatMoney(24)}`, `September 2026, ${formatMoney(24)}`];\n\nexport default function SettingsPageTopTabs() {\n const [area, setArea] = useState<Area>('profile');\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open area.\n const router = { push: (url: string) => setArea(url.split('/').pop() as Area) };\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-tabs-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-email\" title=\"Email\" description=\"Where Acme writes to you.\">\n <FormField id=\"settings-page-tabs-email-field\" label=\"Email\" help=\"Only support can change this. Write to help@acme.example.\">\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} value=\"dana@acme.example\" readOnly onChange={() => {}} />}\n </FormField>\n </SettingsSection>\n </SettingsColumns>\n );\n\n const notifications = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-email-alerts\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-tabs-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-tabs-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n </SettingsColumns>\n );\n\n const billing = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-plan\" title=\"Plan\" description=\"Pro plan, 3 members.\">\n <Paragraph size=\"body2\" measure=\"none\">Renews on Dec 1, 2026. Only owners can change the plan.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-invoices\" title=\"Invoices\" description=\"The last three months.\">\n <List items={invoices} size=\"body2\" />\n </SettingsSection>\n </SettingsColumns>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <TabsContainer>\n {areas.map((a) => (\n <Tab key={a.id} label={a.label} href={`/settings/${a.id}`} router={router} isSelected={area === a.id} onClickTab={() => setArea(a.id)} />\n ))}\n </TabsContainer>\n {area === 'profile' && profile}\n {area === 'notifications' && notifications}\n {area === 'billing' && billing}\n </Stack>\n </Center>\n );\n}\n",
3585
4647
  "uses": [
3586
4648
  "Button",
3587
4649
  "Center",
@@ -3597,7 +4659,8 @@
3597
4659
  "Switch",
3598
4660
  "Tab",
3599
4661
  "TabsContainer",
3600
- "TextField"
4662
+ "TextField",
4663
+ "formatMoney"
3601
4664
  ]
3602
4665
  },
3603
4666
  {
@@ -3606,55 +4669,183 @@
3606
4669
  "useWhen": "There are more areas, and they fall into groups.",
3607
4670
  "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport SettingsSection, { SettingsLayout } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = { id: string; label: string; icon: string; group: string; description: string };\n\n// Areas in groups, as the side nav lists them. Each is a page of its own in a real app, so it has an `href`.\nconst areas: Area[] = [\n { id: 'profile', label: 'Profile', icon: 'User', group: 'Account', description: 'How people see you in Acme.' },\n { id: 'notifications', label: 'Notifications', icon: 'Bell', group: 'Account', description: 'Choose what reaches you.' },\n { id: 'general', label: 'General', icon: 'Settings', group: 'Workspace', description: 'The name and defaults of the Acme workspace.' },\n { id: 'members', label: 'Members', icon: 'Users', group: 'Workspace', description: 'Who is in Acme, and what they can do.' },\n { id: 'billing', label: 'Billing', icon: 'CreditCard', group: 'Workspace', description: 'Your plan and invoices.' },\n { id: 'api-keys', label: 'API Keys', icon: 'Key', group: 'Developers', description: 'Keys for tools that use Acme.' },\n { id: 'webhooks', label: 'Webhooks', icon: 'Webhook', group: 'Developers', description: 'Send Acme events to other tools.' },\n];\n\nconst groups = ['Account', 'Workspace', 'Developers'];\n\nexport default function SettingsPageSideNav() {\n const [areaId, setAreaId] = useState('profile');\n // On a phone the nav is the page: it shows until the person opens an area, and 'Back to Settings' returns to it.\n const [opened, setOpened] = useState(false);\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n const [confirmingLogOut, setConfirmingLogOut] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n const area = areas.find((a) => a.id === areaId) ?? areas[0];\n\n function handleOpen(id: string) {\n setAreaId(id);\n setOpened(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleLogOutClose() {\n if (loggingOut) return;\n setConfirmingLogOut(false);\n }\n\n function handleLogOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n timers.current.push(setTimeout(() => {\n setLoggingOut(false);\n setConfirmingLogOut(false);\n setLoggedOut(true);\n }, 1200));\n }\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsSection id=\"settings-page-nav-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-nav-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n );\n\n const notifications = (\n <SettingsSection id=\"settings-page-nav-email\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-nav-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-nav-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n );\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => setLoggedOut(false)} />\n </Cluster>\n </Center>\n );\n }\n\n const nav = (\n <Navigation aria-label=\"Settings\">\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {areas.filter((a) => a.group === group).map((a) => (\n <MenuItem\n key={a.id}\n size=\"small\"\n label={a.label}\n iconName={a.icon}\n href={`/settings/${a.id}`}\n isSelected={a.id === area.id}\n aria-current={a.id === area.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n handleOpen(a.id);\n }}\n />\n ))}\n </NavigationGroup>\n ))}\n <NavigationGroup label=\"Session\">\n <MenuItem size=\"small\" label=\"Log Out\" iconName=\"LogOut\" role=\"button\" onClick={() => setConfirmingLogOut(true)} />\n </NavigationGroup>\n </Navigation>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <SettingsLayout\n nav={nav}\n showContent={opened}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Settings\" onClickButton={() => setOpened(false)} />}\n >\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">{area.label}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{area.description}</Paragraph>\n </Stack>\n {area.id === 'profile' && profile}\n {area.id === 'notifications' && notifications}\n {area.id !== 'profile' && area.id !== 'notifications' && (\n <Paragraph size=\"body2\" measure=\"none\">Nothing to show for {area.label} in this example.</Paragraph>\n )}\n </SettingsLayout>\n </Stack>\n <Modal\n isOpen={confirmingLogOut}\n size=\"small\"\n title=\"Log Out\"\n onClose={handleLogOutClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleLogOutClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={handleLogOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3608
4671
  "uses": [
3609
- "Button",
4672
+ "Button",
4673
+ "Center",
4674
+ "Cluster",
4675
+ "Form",
4676
+ "FormField",
4677
+ "Heading",
4678
+ "MenuItem",
4679
+ "Modal",
4680
+ "Navigation",
4681
+ "NavigationGroup",
4682
+ "Paragraph",
4683
+ "SettingsLayout",
4684
+ "SettingsSection",
4685
+ "Stack",
4686
+ "Switch",
4687
+ "TextField"
4688
+ ]
4689
+ }
4690
+ ]
4691
+ },
4692
+ {
4693
+ "id": "settings-save",
4694
+ "title": "A setting saves in place, or with one Save Button",
4695
+ "kind": "rule",
4696
+ "level": "rule",
4697
+ "area": "settings",
4698
+ "situation": "A person changes a setting.",
4699
+ "answer": "A control that stands alone saves as soon as it changes: a `Switch`, a choice in a `RadioGroup` or a `Select`, or a picture the person chooses. It shows nothing on success, because the control already shows the new value. While the request runs it is busy: a `Switch` takes `busy`, and a `RadioGroup` or `Select` is disabled. If the save fails, the control goes back to its old value and says why next to itself: in a Switch's `error`, in the error line of its `FormField`, or in an inline error `Alert` under a control with no visible label, such as a role in a row. A group of fields that belong together, such as a name, a profile, instructions or a budget, has one Save Button for the whole group. The Button is `loading` while it saves, keeps its label, then reads 'Saved' for 2 seconds. It is disabled while nothing has changed. A group that fails to save follows the rule 'A form error shows next to the problem'. Leaving with unsaved changes follows the case 'Unsaved changes'. Never mix both in one group: a Switch beside a Save Button leaves the person unsure which one is saved. Never show a toast for a setting saved in place. The one exception is a setting chosen from a menu: the menu closes, so a failed save shows in a toast and the control goes back to its old value. A person who cannot change a setting sees it read-only, with one line that says who can change it.",
4700
+ "why": "A control that saves by itself needs no button, and a group needs one place to say it is saved. Mixing the two makes people guess what is saved and what is not.",
4701
+ "do": [
4702
+ "Save a `Switch`, a `RadioGroup` or a `Select` that stands alone as soon as it changes.",
4703
+ "Set the Switch `busy`, or disable the `RadioGroup` or `Select`, while the request runs, and show nothing when it works.",
4704
+ "Put the old value back when a save fails, and say why next to the control: 'Could not save. Try again.'",
4705
+ "Give a group of fields that belong together one Save Button.",
4706
+ "Show `loading` on the Save Button while it saves, keep its label, then show 'Saved' for 2 seconds.",
4707
+ "Keep the Save Button `state=\"disabled\"` while nothing has changed.",
4708
+ "Show a failed group save as the rule 'A form error shows next to the problem' says.",
4709
+ "Follow the case 'Unsaved changes' when the person leaves a group with changes.",
4710
+ "Show a setting the person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
4711
+ ],
4712
+ "dont": [
4713
+ "Do not mix a control that saves on change and a Save Button in one group.",
4714
+ "Do not show a toast for a setting saved in place, except a failed save of a setting chosen from a menu.",
4715
+ "Do not change the Button's label while it is loading, such as to 'Saving…'.",
4716
+ "Do not leave a failed save without a message.",
4717
+ "Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`."
4718
+ ],
4719
+ "native": "On Apple use the system `Toggle` and `Picker` that save as they change, and a `Form` with one Save Button for a group of fields. On Android use a `Switch`."
4720
+ },
4721
+ {
4722
+ "id": "side-pane",
4723
+ "title": "Side pane",
4724
+ "kind": "design",
4725
+ "level": "organism",
4726
+ "area": "shell",
4727
+ "situation": "A person opens more about the page, such as its members, its history or a document, without leaving the page.",
4728
+ "do": [
4729
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail': on a phone a pane takes the whole content area.",
4730
+ "Put the pane in the `pane` of `AppShell`, as a `SidePane` with a `title` and `onClose`. Render it only while it is open.",
4731
+ "Open it from an `IconButton` with a name and `aria-expanded`, and give it `state=\"selected\"` while the pane is open.",
4732
+ "Show one pane at a time. Opening another replaces the first. Pressing the opener of the open pane calls `focus()` on the pane's ref instead of opening a second one.",
4733
+ "Let Close and Escape close the pane. Focus goes back to the opener.",
4734
+ "Open a pane only from the person's own action. It takes focus when it mounts.",
4735
+ "Make a pane resizable only when it holds a document: pass `width` and `onWidthChange`. The start edge then moves with the pointer and with the arrow keys.",
4736
+ "Use `Drawer side=\"end\"` with a `title` for a short task. On a phone it is a sheet from the bottom.",
4737
+ "Give a Drawer `initialFocus=\"body\"` when it holds a control, so focus lands on the control. Keep the Drawer open while its request runs.",
4738
+ "Show the result of a task in the page behind the Drawer, such as 'Assigned to Ben Carter.' Show no toast.",
4739
+ "Title a Drawer for its action in Title Case, as a Modal: 'Assign Task'. Title a pane that shows one thing with its name.",
4740
+ "Put 'Cancel' first and the action last, named with the title's verb: 'Assign Task' has an 'Assign' Button. If the request fails, keep the Drawer open and show an inline error Alert at its top, as the rule 'A form error shows next to the problem' says."
4741
+ ],
4742
+ "dont": [
4743
+ "Do not squeeze a pane beside the page on a phone.",
4744
+ "Do not open two panes at once.",
4745
+ "Do not open a pane when the page loads, or from a timer. It takes focus away from the person.",
4746
+ "Do not make a list of members resizable. Only a document needs room.",
4747
+ "Do not use a Drawer for something the person reads together with the page."
4748
+ ],
4749
+ "native": "On Apple use an inspector (`.inspector`) for a pane beside the page, and a `.sheet` with `presentationDetents` for a short task. On Android use a `ModalBottomSheet` for a short task.",
4750
+ "options": [
4751
+ {
4752
+ "id": "beside",
4753
+ "title": "Pane beside the page",
4754
+ "useWhen": "The person reads the pane and the page together, such as members, history or a document.",
4755
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport SidePane, { type SidePaneHandle } from 'oneslash-design-system/components/sidePane';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype PaneId = 'members' | 'brief';\n\nconst members = [\n { name: 'Dana Lee', role: 'Owner' },\n { name: 'Ben Carter', role: 'Editor' },\n { name: 'Omar Reyes', role: 'Editor' },\n];\n\nconst places = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox' },\n { id: 'tasks', label: 'Tasks', icon: 'ListChecks' },\n { id: 'files', label: 'Files', icon: 'Files' },\n];\n// The projects the person made\nconst projects = [\n { id: 'website', label: 'Website', icon: 'Globe' },\n { id: 'mobile-app', label: 'Mobile App', icon: 'Smartphone' },\n];\n\nexport default function SidePaneBeside() {\n const [navOpen, setNavOpen] = useState(false);\n const [placeId, setPlaceId] = useState('tasks');\n // One pane at a time. Opening another replaces it.\n const [open, setOpen] = useState<PaneId | null>(null);\n // Only the pane that holds a document can be resized.\n const [briefWidth, setBriefWidth] = useState(448);\n const pane = useRef<SidePaneHandle>(null);\n\n const place = [...places, ...projects].find((p) => p.id === placeId) ?? places[0];\n\n // Pressed again while its pane is open, the opener brings the pane forward instead of opening a second one.\n function opener(id: PaneId, label: string, icon: 'Users' | 'FileText') {\n return (\n <Tooltip title={label}>\n <IconButton\n color=\"iconOnly\"\n state={open === id ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={icon}\n ariaLabel={label}\n aria-expanded={open === id}\n onClick={() => (open === id ? pane.current?.focus() : setOpen(id))}\n />\n </Tooltip>\n );\n }\n\n const row = (p: { id: string; label: string; icon: string }) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === place.id}\n aria-current={p.id === place.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPlaceId(p.id);\n }}\n />\n );\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n );\n\n return (\n <AppShell\n title={place.label}\n navOpen={navOpen}\n onNavOpenChange={setNavOpen}\n sidebar={sidebar}\n pane={\n open && (\n <SidePane\n key={open}\n ref={pane}\n title={open === 'members' ? 'Members' : 'Brief'}\n onClose={() => setOpen(null)}\n width={open === 'brief' ? briefWidth : undefined}\n onWidthChange={open === 'brief' ? setBriefWidth : undefined}\n >\n {open === 'members' ? (\n <Stack gap=\"medium\">\n {members.map((m) => (\n <Cluster key={m.name}>\n <UserImage userHandle={m.name} decorative />\n <Paragraph size=\"body1\" measure=\"none\">{m.name}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.role}</Paragraph>\n </Cluster>\n ))}\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Acme ships the new home page on Friday. Omar Reyes owns the copy and Dana Lee the screens.</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">The pane stays beside the page, so the task and the brief are read together. Drag its edge, or use the arrow keys on it, to make it wider.</Paragraph>\n </Stack>\n )}\n </SidePane>\n )\n }\n >\n <Stack gap=\"large\">\n <TitleBar title=\"Launch plan\" actions={<>{opener('members', 'Members', 'Users')}{opener('brief', 'Brief', 'FileText')}</>} />\n <Paragraph tone=\"secondary\" measure=\"none\">Ben Carter is writing the announcement. Omar Reyes is waiting for the new screens.</Paragraph>\n </Stack>\n </AppShell>\n );\n}\n",
4756
+ "uses": [
4757
+ "AppShell",
4758
+ "Cluster",
4759
+ "IconButton",
4760
+ "MenuItem",
4761
+ "Navigation",
4762
+ "NavigationGroup",
4763
+ "Paragraph",
4764
+ "SidePane",
4765
+ "Stack",
4766
+ "TitleBar",
4767
+ "Tooltip",
4768
+ "UserImage"
4769
+ ]
4770
+ },
4771
+ {
4772
+ "id": "over",
4773
+ "title": "Drawer over the page",
4774
+ "useWhen": "The task is short and the page can be hidden for a moment, such as picking a person.",
4775
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Drawer from 'oneslash-design-system/components/drawer';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst people = [\n { label: 'Dana Lee', value: 'dana' },\n { label: 'Ben Carter', value: 'ben' },\n { label: 'Omar Reyes', value: 'omar' },\n];\n\nexport default function SidePaneOver() {\n const [open, setOpen] = useState(false);\n // The person on the task, and the one picked in the sheet before Assign.\n const [assigned, setAssigned] = useState('');\n const [picked, setPicked] = useState('dana');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, the scrim, Close and Cancel all close it, except while the request runs.\n function close() {\n if (saving) return;\n setOpen(false);\n }\n\n function assign() {\n if (saving) return;\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n setAssigned(people.find((p) => p.value === picked)?.label ?? '');\n setOpen(false);\n }, 1200);\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <TitleBar title=\"Launch plan\" actions={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Assign\" decoIcon=\"UserPlus\" onClickButton={() => setOpen(true)} />} />\n {/* The result shows here, where the person is looking, so there is no toast. */}\n <Paragraph tone=\"secondary\" measure=\"none\">{assigned ? `Assigned to ${assigned}.` : 'Nobody is assigned yet.'}</Paragraph>\n </Stack>\n <Drawer isOpen={open} onClose={close} side=\"end\" size=\"small\" title=\"Assign Task\" initialFocus=\"body\">\n <Stack gap=\"large\">\n <RadioGroup aria-label=\"Person\" options={people} selectedValue={picked} disabled={saving} onChange={setPicked} />\n <Cluster justify=\"end\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={close} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Assign\" loading={saving} onClickButton={assign} />\n </Cluster>\n </Stack>\n </Drawer>\n </PageShell>\n );\n}\n",
4776
+ "uses": [
4777
+ "Button",
4778
+ "Cluster",
4779
+ "Drawer",
4780
+ "PageShell",
4781
+ "Paragraph",
4782
+ "RadioGroup",
4783
+ "Stack",
4784
+ "TitleBar"
4785
+ ]
4786
+ }
4787
+ ]
4788
+ },
4789
+ {
4790
+ "id": "sidebar-nav",
4791
+ "title": "Sidebar with sections and counts",
4792
+ "kind": "design",
4793
+ "level": "organism",
4794
+ "area": "shell",
4795
+ "situation": "A person looks down the sidebar for a place, and for what has something new in it.",
4796
+ "do": [
4797
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
4798
+ "Build it as a `Navigation` with `aria-label=\"Main\"`, and put the places in `NavigationGroup`s with a short `label`, such as 'Mail' and 'Tasks'.",
4799
+ "Make each place a `MenuItem` with an `href`. Mark the open one with `isSelected` and `aria-current=\"page\"`.",
4800
+ "Show the count of what has not been read, never a total, as a `tag` with `variant=\"textOnly\"`.",
4801
+ "Put the count in the row's name too: `aria-label=\"Inbox, 3 unread\"`. Start the name with the visible label.",
4802
+ "Show nothing at zero. Opening a place reads it, so its count goes away.",
4803
+ "Put 'New Task' at the top of its group, as a `MenuItem` with `role=\"button\"`. The new task opens at the top of the group.",
4804
+ "Make the row that holds the others a `MenuItem` with `role=\"button\"`, `aria-expanded` and a chevron in `iconRight`. Name it for the place: 'Acme'.",
4805
+ "Keep a place the person closed closed when they return. Save it for the person, such as in local storage or their profile.",
4806
+ "Show the sum of what is unread under a closed place on its own row, so nothing unread is out of sight.",
4807
+ "Show a place inside another with `level={2}` on its `MenuItem`, and keep its own icon.",
4808
+ "Give each 'New Task' a name that says where it goes: `aria-label=\"New task in Acme\"`. In a phone menu, close the menu in its `onClick`, since a button row does not close it."
4809
+ ],
4810
+ "dont": [
4811
+ "Do not show a total of everything, such as every task. A count is what needs the person.",
4812
+ "Do not show '0'. Leave the count out.",
4813
+ "Do not color a count red, even for a mention. A count is quiet text.",
4814
+ "Do not close a place with no sign of what is inside it. A closed place keeps its count.",
4815
+ "Do not close a place without `aria-expanded` on its row."
4816
+ ],
4817
+ "native": "On Apple use a sidebar `List` with `Section`s, a `.badge(count)` on each row, and a `DisclosureGroup` for places that hold places. On Android use a navigation drawer with a `Badge`.",
4818
+ "options": [
4819
+ {
4820
+ "id": "flat",
4821
+ "title": "One list in a few groups",
4822
+ "useWhen": "Each place is one row, and the places fall into a few groups.",
4823
+ "source": "'use client';\nimport { useState } from 'react';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; icon: string; group: string };\n\nconst initialPlaces: Place[] = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox', group: 'Mail' },\n { id: 'mentions', label: 'Mentions', icon: 'AtSign', group: 'Mail' },\n { id: 'sent', label: 'Sent', icon: 'Send', group: 'Mail' },\n { id: 'launch', label: 'Launch plan', icon: 'ListChecks', group: 'Tasks' },\n { id: 'review', label: 'Design review', icon: 'ListChecks', group: 'Tasks' },\n { id: 'pricing', label: 'Pricing page', icon: 'ListChecks', group: 'Tasks' },\n];\n\nconst groups = ['Mail', 'Tasks'];\n\n// What has not been read, by place. A place with none has no entry, and shows no count.\nconst initialUnread: Record<string, number> = { inbox: 3, mentions: 1, launch: 2 };\n\nexport default function SidebarNavFlat() {\n const [places, setPlaces] = useState(initialPlaces);\n const [currentId, setCurrentId] = useState('sent');\n const [unread, setUnread] = useState(initialUnread);\n const [created, setCreated] = useState(0);\n\n const current = places.find((p) => p.id === currentId) ?? places[0];\n\n // Opening a place reads it, so its count goes away.\n function open(id: string) {\n setCurrentId(id);\n setUnread((u) => ({ ...u, [id]: 0 }));\n }\n\n // The new task goes to the top of its group, and opens.\n function newTask() {\n const id = `new-${created + 1}`;\n setCreated(created + 1);\n setPlaces((all) => [{ id, label: `New task ${created + 1}`, icon: 'ListChecks', group: 'Tasks' }, ...all]);\n setCurrentId(id);\n }\n\n return (\n <Center>\n <Stack gap=\"large\">\n <Navigation aria-label=\"Main\">\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {group === 'Tasks' && <MenuItem size=\"small\" iconName=\"Plus\" label=\"New Task\" role=\"button\" onClick={newTask} />}\n {places.filter((p) => p.group === group).map((p) => {\n const count = unread[p.id] ?? 0;\n return (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === current.id}\n aria-current={p.id === current.id ? 'page' : undefined}\n // A count is what has not been read, as quiet text. Nothing shows at zero, and the name says the count.\n tag={count > 0 ? { label: String(count), variant: 'textOnly' } : undefined}\n aria-label={count > 0 ? `${p.label}, ${count} unread` : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n open(p.id);\n }}\n />\n );\n })}\n </NavigationGroup>\n ))}\n </Navigation>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">You are in {current.label}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
4824
+ "uses": [
4825
+ "Center",
4826
+ "MenuItem",
4827
+ "Navigation",
4828
+ "NavigationGroup",
4829
+ "Paragraph",
4830
+ "Stack"
4831
+ ]
4832
+ },
4833
+ {
4834
+ "id": "nested",
4835
+ "title": "Places that hold places",
4836
+ "useWhen": "A place holds others, such as a workspace and its tasks, and the person wants to hide what they do not use.",
4837
+ "source": "'use client';\nimport { useEffect, useState } from 'react';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Task = { id: string; label: string };\ntype Workspace = { id: string; name: string; tasks: Task[] };\n\nconst initialWorkspaces: Workspace[] = [\n {\n id: 'acme',\n name: 'Acme',\n tasks: [\n { id: 'launch', label: 'Launch plan' },\n { id: 'pricing', label: 'Pricing page' },\n ],\n },\n {\n id: 'studio',\n name: 'Side Studio',\n tasks: [\n { id: 'logo', label: 'New logo' },\n { id: 'site', label: 'Landing page' },\n ],\n },\n];\n\n// What has not been read, by place. A place with none has no entry, and shows no count.\nconst initialUnread: Record<string, number> = { pricing: 2, site: 1 };\n\nconst STORAGE_KEY = 'sidebar-nav-hidden-groups';\n\nexport default function SidebarNavNested() {\n const [workspaces, setWorkspaces] = useState(initialWorkspaces);\n const [currentId, setCurrentId] = useState('launch');\n const [unread, setUnread] = useState(initialUnread);\n const [created, setCreated] = useState(0);\n // The groups the person hid. They stay hidden when the person comes back, so a real app saves them per person.\n const [hiddenGroups, setHiddenGroups] = useState<string[]>([]);\n\n // Read after the first render, so the server and the browser start from the same page.\n useEffect(() => {\n try {\n const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]');\n if (Array.isArray(saved)) setHiddenGroups(saved.filter((id) => typeof id === 'string'));\n } catch {\n // Storage can be blocked. The groups then start shown.\n }\n }, []);\n\n function toggleGroup(id: string) {\n const next = hiddenGroups.includes(id) ? hiddenGroups.filter((g) => g !== id) : [...hiddenGroups, id];\n setHiddenGroups(next);\n try {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(next));\n } catch {\n // Storage can be blocked. The choice then lasts until the page closes.\n }\n }\n\n function open(id: string) {\n setCurrentId(id);\n setUnread((u) => ({ ...u, [id]: 0 }));\n }\n\n // The new task goes to the top of its group, and opens.\n function newTask(workspaceId: string) {\n const id = `new-${created + 1}`;\n setCreated(created + 1);\n setWorkspaces((all) => all.map((w) => (w.id === workspaceId ? { ...w, tasks: [{ id, label: `New task ${created + 1}` }, ...w.tasks] } : w)));\n setCurrentId(id);\n }\n\n const currentName = workspaces.flatMap((w) => w.tasks).find((t) => t.id === currentId)?.label ?? '';\n\n return (\n <Center>\n <Stack gap=\"large\">\n <Navigation aria-label=\"Main\">\n <NavigationGroup label=\"Workspaces\">\n {workspaces.map((w) => {\n const hidden = hiddenGroups.includes(w.id);\n // A closed place keeps its count, on its own row, so nothing unread is out of sight.\n const hiddenUnread = hidden ? w.tasks.reduce((sum, t) => sum + (unread[t.id] ?? 0), 0) : 0;\n return (\n <Stack key={w.id} gap=\"small\">\n {/* The row that holds the others shows or hides them. It keeps its name; aria-expanded says which. */}\n <MenuItem\n size=\"small\"\n label={w.name}\n iconName=\"Building2\"\n iconRight={hidden ? 'ChevronRight' : 'ChevronDown'}\n role=\"button\"\n aria-expanded={!hidden}\n // A closed place keeps its count here, and the name says it.\n tag={hiddenUnread > 0 ? { label: String(hiddenUnread), variant: 'textOnly' } : undefined}\n aria-label={hiddenUnread > 0 ? `${w.name}, ${hiddenUnread} unread` : undefined}\n onClick={() => toggleGroup(w.id)}\n />\n {/* Each workspace has its own New Task, so its name says which. In a phone menu, close the menu in this onClick. */}\n {!hidden && <MenuItem size=\"small\" level={2} iconName=\"Plus\" label=\"New Task\" aria-label={`New task in ${w.name}`} role=\"button\" onClick={() => newTask(w.id)} />}\n {!hidden && w.tasks.map((t) => (\n <MenuItem\n key={t.id}\n size=\"small\"\n label={t.label}\n level={2}\n iconName=\"ListChecks\"\n href={`/${w.id}/${t.id}`}\n isSelected={t.id === currentId}\n aria-current={t.id === currentId ? 'page' : undefined}\n tag={(unread[t.id] ?? 0) > 0 ? { label: String(unread[t.id]), variant: 'textOnly' } : undefined}\n aria-label={(unread[t.id] ?? 0) > 0 ? `${t.label}, ${unread[t.id]} unread` : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n event.preventDefault();\n open(t.id);\n }}\n />\n ))}\n </Stack>\n );\n })}\n </NavigationGroup>\n </Navigation>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">You are in {currentName}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
4838
+ "uses": [
3610
4839
  "Center",
3611
- "Cluster",
3612
- "Form",
3613
- "FormField",
3614
- "Heading",
3615
4840
  "MenuItem",
3616
- "Modal",
3617
4841
  "Navigation",
3618
4842
  "NavigationGroup",
3619
4843
  "Paragraph",
3620
- "SettingsLayout",
3621
- "SettingsSection",
3622
- "Stack",
3623
- "Switch",
3624
- "TextField"
4844
+ "Stack"
3625
4845
  ]
3626
4846
  }
3627
4847
  ]
3628
4848
  },
3629
- {
3630
- "id": "settings-save",
3631
- "title": "A setting saves in place, or with one Save Button",
3632
- "kind": "rule",
3633
- "level": "rule",
3634
- "area": "settings",
3635
- "situation": "A person changes a setting.",
3636
- "answer": "A control that stands alone saves as soon as it changes: a `Switch`, a choice in a `RadioGroup` or a `Select`, or a picture the person chooses. It shows nothing on success, because the control already shows the new value. While the request runs it is busy: a `Switch` takes `busy`, and a `RadioGroup` or `Select` is disabled. If the save fails, the control goes back to its old value and says why next to itself: in a Switch's `error`, in the error line of its `FormField`, or in an inline error `Alert` under a control with no visible label, such as a role in a row. A group of fields that belong together, such as a name, a profile, instructions or a budget, has one Save Button for the whole group. The Button is `loading` while it saves, keeps its label, then reads 'Saved' for 2 seconds. It is disabled while nothing has changed. A group that fails to save follows the rule 'A form error shows next to the problem'. Leaving with unsaved changes follows the case 'Unsaved changes'. Never mix both in one group: a Switch beside a Save Button leaves the person unsure which one is saved. Never show a toast for a setting saved in place. The one exception is a setting chosen from a menu: the menu closes, so a failed save shows in a toast and the control goes back to its old value. A person who cannot change a setting sees it read-only, with one line that says who can change it.",
3637
- "why": "A control that saves by itself needs no button, and a group needs one place to say it is saved. Mixing the two makes people guess what is saved and what is not.",
3638
- "do": [
3639
- "Save a `Switch`, a `RadioGroup` or a `Select` that stands alone as soon as it changes.",
3640
- "Set the Switch `busy`, or disable the `RadioGroup` or `Select`, while the request runs, and show nothing when it works.",
3641
- "Put the old value back when a save fails, and say why next to the control: 'Could not save. Try again.'",
3642
- "Give a group of fields that belong together one Save Button.",
3643
- "Show `loading` on the Save Button while it saves, keep its label, then show 'Saved' for 2 seconds.",
3644
- "Keep the Save Button `state=\"disabled\"` while nothing has changed.",
3645
- "Show a failed group save as the rule 'A form error shows next to the problem' says.",
3646
- "Follow the case 'Unsaved changes' when the person leaves a group with changes.",
3647
- "Show a setting the person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
3648
- ],
3649
- "dont": [
3650
- "Do not mix a control that saves on change and a Save Button in one group.",
3651
- "Do not show a toast for a setting saved in place, except a failed save of a setting chosen from a menu.",
3652
- "Do not change the Button's label while it is loading, such as to 'Saving…'.",
3653
- "Do not leave a failed save without a message.",
3654
- "Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`."
3655
- ],
3656
- "native": "On Apple use the system `Toggle` and `Picker` that save as they change, and a `Form` with one Save Button for a group of fields. On Android use a `Switch`."
3657
- },
3658
4849
  {
3659
4850
  "id": "sign-up-page",
3660
4851
  "title": "Sign-up page",
@@ -3751,6 +4942,121 @@
3751
4942
  }
3752
4943
  ]
3753
4944
  },
4945
+ {
4946
+ "id": "site-footer",
4947
+ "title": "Site footer",
4948
+ "kind": "design",
4949
+ "level": "organism",
4950
+ "area": "shell",
4951
+ "situation": "A person reaches the end of a site's page and looks for the pages that are not in the header, and who runs the site.",
4952
+ "do": [
4953
+ "Use `SiteFooter` at the end of the page, after `PageShell`. It is a `<footer>` with a `<nav aria-label=\"Footer\">`.",
4954
+ "Pass the brand, so the person can go home, and the links. Use `links` for a few and `columns` for many.",
4955
+ "Give each column a short `title`, such as 'Product', 'Company' and 'Legal'. A phone shows two columns across and a wide window up to four.",
4956
+ "Put the legal line last, in `legal`: the year and the name, and the license if there is one, such as '© 2026 Acme. Released under the MIT License.'",
4957
+ "Mark a link to another site with `external`. It opens in a new tab and the icon and the hidden words '(opens in a new tab)' say so.",
4958
+ "Keep the footer to links and the legal line. It holds every page the header leaves out, in plain words."
4959
+ ],
4960
+ "dont": [
4961
+ "Do not put a sales pitch, a heading or a Button in the footer. Use a call to action band above it.",
4962
+ "Do not open an external link in a new tab without saying so.",
4963
+ "Do not repeat a long sentence of the page in the footer.",
4964
+ "Do not hide a link on a phone. The columns sit two across.",
4965
+ "Do not put the legal line before the links."
4966
+ ],
4967
+ "native": "On Apple and Android an app has no footer. Put the links in a settings or an About screen, as a `List` of rows.",
4968
+ "options": [
4969
+ {
4970
+ "id": "simple",
4971
+ "title": "A row of links",
4972
+ "useWhen": "The site has a few links to show.",
4973
+ "source": "'use client';\nimport SiteFooter from 'oneslash-design-system/components/siteFooter';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Pricing', href: '#pricing' },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Privacy', href: '#privacy' },\n { label: 'GitHub', href: 'https://github.com/acme/acme', external: true },\n];\n\nexport default function SiteFooterSimple() {\n return (\n <>\n {/* A real page puts its content in PageShell, then SiteFooter. Center keeps the footer in view here. */}\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Changelog</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Version 2.4 adds shared folders. Ben Carter wrote the notes.</Paragraph>\n </Stack>\n </Center>\n {/* A few links in one row that wraps, then the legal line last. */}\n <SiteFooter\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n legal=\"© 2026 Acme. Released under the MIT License.\"\n />\n </>\n );\n}\n",
4974
+ "uses": [
4975
+ "Center",
4976
+ "Heading",
4977
+ "Paragraph",
4978
+ "SiteFooter",
4979
+ "Stack"
4980
+ ]
4981
+ },
4982
+ {
4983
+ "id": "columns",
4984
+ "title": "Links in groups",
4985
+ "useWhen": "The site has many links that fall into groups, such as product, company and legal.",
4986
+ "source": "'use client';\nimport SiteFooter from 'oneslash-design-system/components/siteFooter';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nconst columns = [\n {\n title: 'Product',\n links: [\n { label: 'Features', href: '#features' },\n { label: 'Pricing', href: '#pricing' },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Docs', href: '#docs' },\n ],\n },\n {\n title: 'Company',\n links: [\n { label: 'About', href: '#about' },\n { label: 'Blog', href: '#blog' },\n { label: 'Contact', href: '#contact' },\n ],\n },\n {\n title: 'Follow',\n links: [\n { label: 'GitHub', href: 'https://github.com/acme/acme', external: true },\n { label: 'Newsletter', href: 'https://acme.example/newsletter', external: true },\n ],\n },\n {\n title: 'Legal',\n links: [\n { label: 'Terms', href: '#terms' },\n { label: 'Privacy', href: '#privacy' },\n ],\n },\n];\n\nexport default function SiteFooterColumns() {\n return (\n <>\n {/* A real page puts its content in PageShell, then SiteFooter. Center keeps the footer in view here. */}\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">About Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Acme helps small teams share files and decide together.</Paragraph>\n </Stack>\n </Center>\n {/* Groups of links, two across on a phone and four across from md. The legal line is last. */}\n <SiteFooter\n brand={{ href: '#top', name: 'Acme' }}\n columns={columns}\n legal=\"© 2026 Acme. All rights reserved.\"\n />\n </>\n );\n}\n",
4987
+ "uses": [
4988
+ "Center",
4989
+ "Heading",
4990
+ "Paragraph",
4991
+ "SiteFooter",
4992
+ "Stack"
4993
+ ]
4994
+ }
4995
+ ]
4996
+ },
4997
+ {
4998
+ "id": "site-header",
4999
+ "title": "Site header",
5000
+ "kind": "design",
5001
+ "level": "organism",
5002
+ "area": "shell",
5003
+ "situation": "A site's pages name the site at the top and show the person where to go and what to do next.",
5004
+ "do": [
5005
+ "Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail': below `md` the links go into a menu and one main action stays in the bar.",
5006
+ "Use `SiteHeader` for a few pages. Pass the brand, at most five `links`, and mark the page the person is on with `current`.",
5007
+ "Pass what must stay in the bar on a phone as `phoneAction`. On a product site that is the main action, named 'Open App' or 'Sign Up'. It is last at every width. Do not repeat it in `actions`.",
5008
+ "Pass the secondary Buttons, such as 'Log In', as `actions`. They go into the menu on a phone.",
5009
+ "Give `PageShell` `id` and `tabIndex={-1}` to match `mainId`, so the 'Skip to content' link moves focus into the page.",
5010
+ "Give a site with sections one `TabsContainer` of `Tab`s with `href`, four sections or fewer and one short word each. Pass it as `nav` to `SiteHeader` with `links` empty: it is a second row of the bar at every width.",
5011
+ "Pass search and the theme menu as `phoneAction`, so they stay at the end of the bar on a phone. With no `links` and no `actions` there is no menu.",
5012
+ "Keep the section tabs in the bar, so no section is hidden. On a phone, put the pages of the open section in a menu, as the case 'Menu on a phone' shows in 'Sections with their pages'.",
5013
+ "Open the theme menu as the case 'Theme switcher' says, and name the search `IconButton` 'Search'."
5014
+ ],
5015
+ "dont": [
5016
+ "Do not show more than five links in the bar.",
5017
+ "Do not show two primary Buttons in the bar.",
5018
+ "Do not hide a link on a phone without a menu that holds it.",
5019
+ "Do not put a Button that opens a Modal in `actions`. On a phone the menu closes when it is chosen, so the Modal has no Button to give focus back to. Link to a page instead.",
5020
+ "Do not turn a product site's few pages into tabs. Use `links`. Tabs are for sections that each hold many pages."
5021
+ ],
5022
+ "native": "On Apple a site header has no counterpart: an app uses a `NavigationStack` with a navigation bar. On Android use a top app bar.",
5023
+ "options": [
5024
+ {
5025
+ "id": "links",
5026
+ "title": "Links and one main action",
5027
+ "useWhen": "A product site has a few pages and one main action, such as 'Sign Up'.",
5028
+ "source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Button from 'oneslash-design-system/components/button';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Features', href: '#features' },\n { label: 'Pricing', href: '#pricing', current: true },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Docs', href: '#docs' },\n];\n\nexport default function SiteHeaderLinks() {\n return (\n <>\n {/* From md the links are a row in the bar. Below md they and 'Log In' are in the Menu; Sign Up stays beside it. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n actions={<Button size=\"medium\" type=\"tertiary\" state=\"enabled\" label=\"Log In\" href=\"#log-in\" />}\n phoneAction={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />}\n mainId=\"site-header-main\"\n />\n {/* The skip link goes here: the id matches mainId, and tabIndex -1 lets focus move in. */}\n <PageShell id=\"site-header-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Acme is free for up to three people. Add more people when your team grows.</Paragraph>\n </Stack>\n </PageShell>\n </>\n );\n}\n",
5029
+ "uses": [
5030
+ "Button",
5031
+ "Heading",
5032
+ "PageShell",
5033
+ "Paragraph",
5034
+ "SiteHeader",
5035
+ "Stack"
5036
+ ]
5037
+ },
5038
+ {
5039
+ "id": "sections",
5040
+ "title": "Sections with their own tabs",
5041
+ "useWhen": "A docs site has sections that each hold many pages.",
5042
+ "source": "'use client';\nimport { useState } from 'react';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\ntype Mode = 'light' | 'dark' | 'system';\n\n// Four sections, one short word each. Each holds many pages.\nconst sections = [\n { id: 'start', label: 'Start', page: 'Start here' },\n { id: 'guides', label: 'Guides', page: 'Guides' },\n { id: 'reference', label: 'API', page: 'API reference' },\n { id: 'updates', label: 'News', page: 'News' },\n];\n\nconst modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [\n { value: 'light', label: 'Light', icon: 'Sun' },\n { value: 'dark', label: 'Dark', icon: 'Moon' },\n { value: 'system', label: 'System', icon: 'Monitor' },\n];\n\nexport default function SiteHeaderSections() {\n const [sectionId, setSectionId] = useState('guides');\n const [mode, setMode] = useState<Mode>('system');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const section = sections.find((s) => s.id === sectionId) ?? sections[0];\n const current = modes.find((m) => m.value === mode) ?? modes[2];\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open section.\n const router = { push: (url: string) => setSectionId(url.split('/').pop() ?? 'start') };\n\n return (\n <>\n {/* The brand, then search and the theme menu as `phoneAction`, so they stay in the bar at every width. The section Tabs are `nav`, a second row of the bar. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme Docs' }}\n links={[]}\n phoneAction={\n <>\n <Tooltip title=\"Search\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Search\" ariaLabel=\"Search\" />\n </Tooltip>\n <Tooltip title={`Theme: ${current.label}`}>\n <IconButton\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={current.icon}\n ariaLabel={`Theme: ${current.label}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setAnchor(e.currentTarget);\n setOpen((o) => !o);\n }}\n />\n </Tooltip>\n </>\n }\n nav={\n <TabsContainer fill>\n {sections.map((s) => (\n <Tab key={s.id} label={s.label} href={`/${s.id}`} router={router} isSelected={s.id === section.id} onClickTab={() => setSectionId(s.id)} />\n ))}\n </TabsContainer>\n }\n mainId=\"site-header-sections-main\"\n />\n <PageShell id=\"site-header-sections-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">{section.page}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The pages in {section.label} are listed beside this page on a wide screen, and in the menu on a phone.</Paragraph>\n </Stack>\n </PageShell>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Theme\" width={180}>\n {modes.map((m) => (\n <MenuItem\n key={m.value}\n size=\"small\"\n iconName={m.icon}\n label={m.label}\n isSelected={m.value === mode}\n role=\"menuitemradio\"\n onClick={() => { setMode(m.value); setOpen(false); }}\n />\n ))}\n </Menu>\n </Popover>\n </>\n );\n}\n",
5043
+ "uses": [
5044
+ "Heading",
5045
+ "IconButton",
5046
+ "Menu",
5047
+ "MenuItem",
5048
+ "PageShell",
5049
+ "Paragraph",
5050
+ "Popover",
5051
+ "SiteHeader",
5052
+ "Stack",
5053
+ "Tab",
5054
+ "TabsContainer",
5055
+ "Tooltip"
5056
+ ]
5057
+ }
5058
+ ]
5059
+ },
3754
5060
  {
3755
5061
  "id": "slash-command-list",
3756
5062
  "title": "Command list",
@@ -3801,6 +5107,126 @@
3801
5107
  }
3802
5108
  ]
3803
5109
  },
5110
+ {
5111
+ "id": "stat-row",
5112
+ "title": "Stat row",
5113
+ "kind": "design",
5114
+ "level": "organism",
5115
+ "area": "dashboard",
5116
+ "situation": "A page opens with the few numbers that say how things are going, counted over one range.",
5117
+ "do": [
5118
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'. Use `StatTile`, which does.",
5119
+ "Put the tiles in `<Grid compact columns={4}>`: two across on a phone, up to four from md up.",
5120
+ "Use four tiles at most. A fifth number goes in a table.",
5121
+ "Make each tile count one thing, with its unit in the label or the `unit` prop: 'New comments', 'Responses'.",
5122
+ "Count every tile over the same range, and say the range in the heading above the row: 'This week'.",
5123
+ "Pass `previous` and `period` to get the change line, such as 'Up 12% from last week'. Leave `previous` out when there is nothing to compare with.",
5124
+ "Pass `loading` while the numbers load, so a `Skeleton` holds each place. Pass `value={null}` when there is no data: the tile says 'No data yet'.",
5125
+ "Pass `format` for money, a percent, a size or a time, such as `format=\"money\"`. Do not format a number by hand.",
5126
+ "Give the one number that matters most `size=\"large\"` and a row of its own, with the others under it."
5127
+ ],
5128
+ "dont": [
5129
+ "Do not show 0 while a number loads or when it is missing.",
5130
+ "Do not color a change green or red. More is not good or bad by itself.",
5131
+ "Do not put more than four tiles in a row, or two things in one tile.",
5132
+ "Do not draw a chart or a sparkline in a tile. A trend is the change line.",
5133
+ "Do not box each tile in a card. The row sits on the page."
5134
+ ],
5135
+ "native": "On Apple use a `LabeledContent` or a `Grid` of `VStack`s with the number in `.title2` and `monospacedDigit()`. On Android use a `Row` of `Column`s with `headlineMedium` text.",
5136
+ "options": [
5137
+ {
5138
+ "id": "tiles",
5139
+ "title": "Tiles of equal weight",
5140
+ "useWhen": "Two to four numbers matter about the same, over one range.",
5141
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function StatRowTiles() {\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function reload() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={2} size=\"h6\">This week</Heading>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Reload\" decoIcon=\"RefreshCw\" onClickButton={reload} />\n </Cluster>\n {/* Four tiles at most. Two across on a phone, four from md up. Each counts one thing over the same range. */}\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={1240} previous={1106} loading={loading} />\n <StatTile label=\"Marked done\" value={312} previous={280} loading={loading} />\n <StatTile label=\"People engaged\" value={18} previous={18} loading={loading} />\n <StatTile label=\"Average reply time\" value={8_640_000} format=\"duration\" previous={9_200_000} loading={loading} />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
5142
+ "uses": [
5143
+ "Button",
5144
+ "Center",
5145
+ "Cluster",
5146
+ "Grid",
5147
+ "Heading",
5148
+ "Stack",
5149
+ "StatTile"
5150
+ ]
5151
+ },
5152
+ {
5153
+ "id": "featured",
5154
+ "title": "One number first",
5155
+ "useWhen": "One number matters most, with two others under it.",
5156
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport { Center, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function StatRowFeatured() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">This month</Heading>\n {/* The number that matters most is one step larger and has the row to itself. */}\n <StatTile label=\"Responses\" value={48210} previous={41980} period=\"month\" size=\"large\" />\n <Grid compact columns={2}>\n <StatTile label=\"Estimated cost\" value={96.4} format=\"money\" previous={88.2} period=\"month\" />\n <StatTile label=\"Data stored\" value={1_288_490_188} format=\"bytes\" previous={1_073_741_824} period=\"month\" />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
5157
+ "uses": [
5158
+ "Center",
5159
+ "Grid",
5160
+ "Heading",
5161
+ "Stack",
5162
+ "StatTile"
5163
+ ]
5164
+ }
5165
+ ]
5166
+ },
5167
+ {
5168
+ "id": "status-label",
5169
+ "title": "Status in a row",
5170
+ "kind": "design",
5171
+ "level": "organism",
5172
+ "area": "dashboard",
5173
+ "situation": "A row in a table or a list says what state its thing is in, such as an invoice, a plan or a connection. ODS has no separate Badge part, because `Tag` does a Badge's job.",
5174
+ "do": [
5175
+ "Use `Tag` for a state in a row, with `size=\"small\"`. ODS has no Badge part: a second part for the same job would mark the same states two ways.",
5176
+ "Show the word every time. The dot alone means nothing to a screen reader or to a person who cannot tell the colors apart.",
5177
+ "Use `variant=\"dot\"` for a state that changes and may need the person: 'Past due', 'Canceling', 'Connected'.",
5178
+ "Give the dot a color only when the state needs action: `color=\"error\"` for 'Past due', `color=\"warning\"` for 'Canceling'. One exception: `color=\"info\"` for a charge that has not happened yet, 'Upcoming', so it does not read as paid. A usual state, such as 'Connected', keeps the grey dot.",
5179
+ "Use `variant=\"textOnly\"` with no color for a settled record: 'Paid', 'Refunded'.",
5180
+ "Write one word or two, in sentence case: 'Past due', 'Needs reconnecting'.",
5181
+ "Put the Tag in a 'Status' column, or at the end of the row's text. It is not clickable."
5182
+ ],
5183
+ "dont": [
5184
+ "Do not show a dot with no word, or a color with no word.",
5185
+ "Do not color a settled state. A green 'Paid' on every row hides the one red 'Past due'.",
5186
+ "Do not write the word in Title Case ('Past Due') or as a sentence ('Your payment is late').",
5187
+ "Do not fill the Tag with `variant=\"contained\"` for a status in a row. A filled Tag is a label the person picks.",
5188
+ "Do not make the Tag a button. A status that opens something is a row action, in the More menu.",
5189
+ "Do not draw the dot by hand."
5190
+ ],
5191
+ "native": "On Apple use a `Label` with a small filled circle as its image and the word, colored with a semantic style only when the state needs action. On Android use a leading dot and the word in a `Text`.",
5192
+ "options": [
5193
+ {
5194
+ "id": "dot",
5195
+ "title": "A dot and a word",
5196
+ "useWhen": "The state changes and may need the person: Past due, Canceling, Connected.",
5197
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Color = 'error' | 'warning' | undefined;\n\n// A real app reads these from the server.\nconst workspaces: { id: string; name: string; plan: string; status: string; color: Color }[] = [\n { id: 'acme', name: 'Acme', plan: 'Pro', status: 'Past due', color: 'error' },\n { id: 'acme-labs', name: 'Acme Labs', plan: 'Pro', status: 'Canceling', color: 'warning' },\n { id: 'acme-studio', name: 'Acme Studio', plan: 'Pro', status: 'Active', color: undefined },\n];\n\nexport default function StatusLabelDot() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Workspaces</Heading>\n <TableContainer aria-label=\"Workspaces\" minWidth=\"480px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Workspace</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Plan</TableHeaderCell>\n <TableHeaderCell width=\"160px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {workspaces.map((w) => (\n <TableRow key={w.id}>\n <TableCell>{w.name}</TableCell>\n <TableCell width=\"100px\">{w.plan}</TableCell>\n <TableCell width=\"160px\">\n {/* The word is always there. Only a state that needs action gets a color: 'Active' keeps the grey dot. */}\n <Tag variant=\"dot\" size=\"small\" color={w.color} label={w.status} />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
5198
+ "uses": [
5199
+ "Center",
5200
+ "Heading",
5201
+ "Stack",
5202
+ "TableCell",
5203
+ "TableContainer",
5204
+ "TableHeader",
5205
+ "TableHeaderCell",
5206
+ "TableRow",
5207
+ "Tag"
5208
+ ]
5209
+ },
5210
+ {
5211
+ "id": "text",
5212
+ "title": "A word alone",
5213
+ "useWhen": "The record is settled and nothing is left to do: Paid, Refunded.",
5214
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst payments = [\n { id: 'p0', date: 'Dec 1, 2026', amount: 24, status: 'Upcoming' },\n { id: 'p1', date: 'Nov 1, 2026', amount: 24, status: 'Paid' },\n { id: 'p2', date: 'Oct 1, 2026', amount: 24, status: 'Paid' },\n { id: 'p3', date: 'Sep 1, 2026', amount: 24, status: 'Refunded' },\n];\n\nexport default function StatusLabelText() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Payments</Heading>\n <TableContainer aria-label=\"Payments\" minWidth=\"480px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Date</TableHeaderCell>\n <TableHeaderCell width=\"120px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"160px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {payments.map((p) => (\n <TableRow key={p.id}>\n <TableCell>{p.date}</TableCell>\n <TableCell width=\"120px\" align=\"right\">{formatMoney(p.amount)}</TableCell>\n <TableCell width=\"160px\">\n {p.status === 'Upcoming' ? (\n // The one exception: a charge that has not happened yet is an info dot, so it does not read as paid.\n <Tag variant=\"dot\" size=\"small\" color=\"info\" label={p.status} />\n ) : (\n // A settled record is a word with no dot and no color.\n <Tag variant=\"textOnly\" size=\"small\" label={p.status} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
5215
+ "uses": [
5216
+ "Center",
5217
+ "Heading",
5218
+ "Stack",
5219
+ "TableCell",
5220
+ "TableContainer",
5221
+ "TableHeader",
5222
+ "TableHeaderCell",
5223
+ "TableRow",
5224
+ "Tag",
5225
+ "formatMoney"
5226
+ ]
5227
+ }
5228
+ ]
5229
+ },
3804
5230
  {
3805
5231
  "id": "success-feedback",
3806
5232
  "title": "Success shows where the person is looking",
@@ -3886,6 +5312,69 @@
3886
5312
  }
3887
5313
  ]
3888
5314
  },
5315
+ {
5316
+ "id": "theme-switcher",
5317
+ "title": "Theme switcher",
5318
+ "kind": "design",
5319
+ "level": "organism",
5320
+ "area": "shell",
5321
+ "situation": "A person chooses between a light page, a dark page, or the one their device uses.",
5322
+ "do": [
5323
+ "Offer three choices, in this order: 'Light', 'Dark' and 'System'. 'System' follows the device and is the default.",
5324
+ "Name the menu's `IconButton` for the current choice, in sentence case: 'Theme: Dark'. Show the icon of the current choice: a sun, a moon or a monitor.",
5325
+ "Open a navigable menu: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Theme\">`. Set `aria-haspopup=\"menu\"` and `aria-expanded` on the button, and `state=\"selected\"` while the menu is open.",
5326
+ "Give each item `role=\"menuitemradio\"` and `isSelected` on the current one, and close the menu on a choice.",
5327
+ "Use a `SegmentedControl` named 'Theme' with `width=\"fit\"` in a `SettingsSection` on a settings page. It saves in place and shows nothing, as the rule 'A setting saves in place, or with one Save Button' says.",
5328
+ "Change the page as soon as a choice is made. A choice kept on the device cannot fail, so show no message and no toast.",
5329
+ "Keep the choice on the device, such as in a cookie or local storage, and read it before the page paints, so the page never flashes the wrong theme.",
5330
+ "For 'System', set no class and follow `prefers-color-scheme`, and change the page when the device changes.",
5331
+ "Set the choice's class on `<html>`. The example keeps the choice in state, because it must not touch the document."
5332
+ ],
5333
+ "dont": [
5334
+ "Do not add a brand theme as a fourth choice. A brand theme is another setting.",
5335
+ "Do not name the button for the action, such as 'Dark mode'. Name it for what is on.",
5336
+ "Do not use a toggle that only flips between light and dark. It hides System.",
5337
+ "Do not mark the current choice with color only.",
5338
+ "Do not show both the menu and the segmented control on the same page.",
5339
+ "Do not save the theme to the person's account with this case. A save that can fail follows the rule 'A setting saves in place, or with one Save Button'."
5340
+ ],
5341
+ "native": "On Apple and Android follow the system appearance and offer no switcher. If the app has one, use a `Picker` of Light, Dark and System in settings.",
5342
+ "options": [
5343
+ {
5344
+ "id": "menu",
5345
+ "title": "Menu in the header",
5346
+ "useWhen": "The site has no settings page, or the person should reach the theme from every page.",
5347
+ "source": "'use client';\nimport { useState } from 'react';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Link from 'oneslash-design-system/components/link';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Mode = 'light' | 'dark' | 'system';\n\nconst modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [\n { value: 'light', label: 'Light', icon: 'Sun' },\n { value: 'dark', label: 'Dark', icon: 'Moon' },\n { value: 'system', label: 'System', icon: 'Monitor' },\n];\n\nexport default function ThemeSwitcherMenu() {\n // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.\n const [mode, setMode] = useState<Mode>('system');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = modes.find((m) => m.value === mode) ?? modes[2];\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Link href=\"#top\" size=\"subtitle1\">Acme</Link>\n <Tooltip title={`Theme: ${current.label}`}>\n <IconButton\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={current.icon}\n ariaLabel={`Theme: ${current.label}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setAnchor(e.currentTarget);\n setOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n <Heading level={1} size=\"h5\">Welcome back, Dana</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">\n {mode === 'system' ? 'Acme follows your device.' : `Acme is set to ${mode}.`} In a real app the page changes now.\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Theme\" width={180}>\n {modes.map((m) => (\n <MenuItem\n key={m.value}\n size=\"small\"\n iconName={m.icon}\n label={m.label}\n isSelected={m.value === mode}\n role=\"menuitemradio\"\n onClick={() => { setMode(m.value); setOpen(false); }}\n />\n ))}\n </Menu>\n </Popover>\n </PageShell>\n );\n}\n",
5348
+ "uses": [
5349
+ "Cluster",
5350
+ "Heading",
5351
+ "IconButton",
5352
+ "Link",
5353
+ "Menu",
5354
+ "MenuItem",
5355
+ "PageShell",
5356
+ "Paragraph",
5357
+ "Popover",
5358
+ "Stack",
5359
+ "Tooltip"
5360
+ ]
5361
+ },
5362
+ {
5363
+ "id": "segmented",
5364
+ "title": "Segmented control on a settings page",
5365
+ "useWhen": "The choice is a setting among others, on a settings page.",
5366
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst options = [\n { value: 'light', label: 'Light' },\n { value: 'dark', label: 'Dark' },\n { value: 'system', label: 'System' },\n];\n\nexport default function ThemeSwitcherSegmented() {\n // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.\n const [mode, setMode] = useState('system');\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <SettingsSection title=\"Appearance\" description=\"System follows your device.\">\n {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}\n <Cluster>\n <SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Theme\" options={options} value={mode} onChange={setMode} />\n </Cluster>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
5367
+ "uses": [
5368
+ "Center",
5369
+ "Cluster",
5370
+ "Heading",
5371
+ "SegmentedControl",
5372
+ "SettingsSection",
5373
+ "Stack"
5374
+ ]
5375
+ }
5376
+ ]
5377
+ },
3889
5378
  {
3890
5379
  "id": "type-to-confirm",
3891
5380
  "title": "Type to confirm",
@@ -4056,12 +5545,13 @@
4056
5545
  "situation": "A person reaches something their plan does not include, or a limit of their plan.",
4057
5546
  "do": [
4058
5547
  "Say what is locked and which plan unlocks it: 'Exporting to PDF is part of the Pro plan.'",
4059
- "Say which limit was reached, with the number, and when it resets: \"You've used all 50 AI agent responses this month. They start again on December 1.\"",
5548
+ "Say which limit was reached, with the number, and when it resets: \"You've used all 50 AI agent responses this month. They start again on Dec 1.\"",
4060
5549
  "Offer 'Not Now' as a tertiary Button, then 'Upgrade to Pro' as a primary Button.",
4061
5550
  "Show 'Upgrade to Pro' only to a person who can change the plan. Tell everyone else to ask a workspace admin, and give them only 'Not Now'.",
4062
5551
  "Title the Modal 'Upgrade to Pro' only for a person who can upgrade. For everyone else, title it 'Pro Feature'.",
4063
5552
  "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, and Escape or a click outside means 'Not Now'.",
4064
5553
  "Put the notice where the control was, with the same two Buttons, when a limit is reached inside a flow.",
5554
+ "At a limit, show a `Progress` above the notice that says 'Limit reached', and point it at the notice with `aria-describedby`.",
4065
5555
  "Follow the rule 'An agent refuses clearly' too when the agent is the one refused."
4066
5556
  ],
4067
5557
  "dont": [
@@ -4077,7 +5567,7 @@
4077
5567
  "id": "modal",
4078
5568
  "title": "Explain in a Modal",
4079
5569
  "useWhen": "The person pressed something their plan does not include.",
4080
- "source": "'use client';\nimport { useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nexport default function UpgradePromptModal() {\n // Opens on the Modal, as if the person just chose Export PDF.\n const [open, setOpen] = useState(true);\n\n function handleUpgrade() {\n setOpen(false);\n router.push('/settings/billing?plan=pro');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Q3 plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* The locked control stays on the page, so the person can find out what unlocks it. */}\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Share\" />\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export PDF\" decoIcon=\"Lock\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n // The title names the action only for a person who can take it.\n title={canChangePlan ? 'Upgrade to Pro' : 'Pro Feature'}\n onClose={() => setOpen(false)}\n actions={\n canChangePlan ? (\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={handleUpgrade} />\n </>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n )\n }\n >\n <Paragraph measure=\"none\">Exporting to PDF is part of the Pro plan. Acme Design is on the Free plan.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'Pro also adds version history and unlimited guests, for $8 per member each month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro.'}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
5570
+ "source": "'use client';\nimport { useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nexport default function UpgradePromptModal() {\n // Opens on the Modal, as if the person just chose Export PDF.\n const [open, setOpen] = useState(true);\n\n function handleUpgrade() {\n setOpen(false);\n router.push('/settings/billing?plan=pro');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Q3 plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* The locked control stays on the page, so the person can find out what unlocks it. */}\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Share\" />\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export PDF\" decoIcon=\"Lock\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n // The title names the action only for a person who can take it.\n title={canChangePlan ? 'Upgrade to Pro' : 'Pro Feature'}\n onClose={() => setOpen(false)}\n actions={\n canChangePlan ? (\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={handleUpgrade} />\n </>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n )\n }\n >\n <Paragraph measure=\"none\">Exporting to PDF is part of the Pro plan. Acme Design is on the Free plan.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? `Pro also adds version history and unlimited guests, for ${formatMoney(8)} per member each month.`\n : 'Ask a workspace admin to upgrade Acme Design to Pro.'}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4081
5571
  "uses": [
4082
5572
  "Button",
4083
5573
  "Center",
@@ -4085,26 +5575,120 @@
4085
5575
  "Heading",
4086
5576
  "Modal",
4087
5577
  "Paragraph",
4088
- "Stack"
5578
+ "Stack",
5579
+ "formatMoney"
4089
5580
  ]
4090
5581
  },
4091
5582
  {
4092
5583
  "id": "inline",
4093
5584
  "title": "Replace the control",
4094
5585
  "useWhen": "A limit was reached inside a flow. The notice takes the place of the control that hit it.",
4095
- "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nconst thread = [\n { id: 'm1', from: 'Dana Lee', text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme agent', text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Dana Lee', text: 'Draft the launch email, please.' },\n];\n\nexport default function UpgradePromptInline() {\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n <Stack gap=\"medium\">\n {thread.map((m) => (\n <Stack key={m.id} gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.from}</Paragraph>\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Stack>\n ))}\n </Stack>\n {showNotice ? (\n // The notice takes the place of the message box, where the person was about to type.\n <Surface padding=\"medium\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on December 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme Design 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n ) : (\n // After 'Not Now' the message box comes back, closed until the replies start again.\n <TextField id=\"upgrade-prompt-message\" label=\"Message the agent\" value=\"\" placeholder=\"Agent replies start again on December 1.\" disabled onChange={() => {}} />\n )}\n </Stack>\n </Center>\n );\n}\n",
5586
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nconst thread = [\n { id: 'm1', from: 'Dana Lee', text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme agent', text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Dana Lee', text: 'Draft the launch email, please.' },\n];\n\nexport default function UpgradePromptInline() {\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n <Stack gap=\"medium\">\n {thread.map((m) => (\n <Stack key={m.id} gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.from}</Paragraph>\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Stack>\n ))}\n </Stack>\n <Progress label=\"AI agent responses\" value={50} max={50} unit=\"responses\" aria-describedby={showNotice ? 'upgrade-prompt-notice' : undefined} />\n {showNotice ? (\n // The notice takes the place of the message box, where the person was about to type.\n <Surface padding=\"medium\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"upgrade-prompt-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme Design 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n ) : (\n // After 'Not Now' the message box comes back, closed until the replies start again.\n <TextField id=\"upgrade-prompt-message\" label=\"Message the agent\" value=\"\" placeholder=\"AI agent responses start again on Dec 1.\" disabled onChange={() => {}} />\n )}\n </Stack>\n </Center>\n );\n}\n",
4096
5587
  "uses": [
4097
5588
  "Button",
4098
5589
  "Center",
4099
5590
  "Cluster",
4100
5591
  "Heading",
4101
5592
  "Paragraph",
5593
+ "Progress",
4102
5594
  "Stack",
4103
5595
  "Surface",
4104
5596
  "TextField"
4105
5597
  ]
4106
5598
  }
4107
5599
  ]
5600
+ },
5601
+ {
5602
+ "id": "usage-meters",
5603
+ "title": "Usage against limits",
5604
+ "kind": "design",
5605
+ "level": "organism",
5606
+ "area": "dashboard",
5607
+ "situation": "A plan limits some things, such as AI agent responses, members and storage. The admin checks how close the workspace is.",
5608
+ "do": [
5609
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
5610
+ "Show each limit as a `Progress` named for what it counts, with its unit: 'AI agent responses', '50 of 50 responses'. A limit is `kind=\"limit\"`, the default. A share of a total is not a limit.",
5611
+ "Say when a limit resets, for the ones that reset: 'Resets on Dec 1.' Members and storage do not reset, so leave it off them.",
5612
+ "Say 'Limit reached' in words at a limit. Put the inline notice of the case 'Upgrade prompt' under that meter, and point the meter at it with `aria-describedby`.",
5613
+ "Say a limit that is passed as it is: '53 of 50 responses, over the limit'. A count can pass its limit by a few, so do not stop it at 100%.",
5614
+ "Give a plan with no limit `max={null}`: the meter becomes text only, '3 members, no limit', with no bar.",
5615
+ "Show who used it in a sorted table under the meters, most first, with exact numbers and the numbers right-aligned.",
5616
+ "Set a spend cap as the rule 'A setting saves in place, or with one Save Button' says: a money `TextField` with one 'Save' Button, 'Saved' for 2 seconds. Empty means no cap, and the help text says so.",
5617
+ "Show spend against a cap in the same `Progress`. Say what is paused and when it starts again in an inline warning `Alert` once the cap is reached.",
5618
+ "Show a member who cannot change the cap the amount as text with the line 'Only admins can change it.'"
5619
+ ],
5620
+ "dont": [
5621
+ "Do not write a meter as '12 / 1,000'. Write '12 of 1,000 responses'.",
5622
+ "Do not show a limit by color alone. Say 'Limit reached' or 'Almost at the limit'.",
5623
+ "Do not draw the bar by hand. Use `Progress`.",
5624
+ "Do not show a bar for a plan with no limit, or write 'Unlimited' beside a number.",
5625
+ "Do not round a cost to four decimals. Show money with two: '$18.40'.",
5626
+ "Do not show the upgrade notice for a limit that is not reached.",
5627
+ "Do not show a cap field to a person who cannot set it."
5628
+ ],
5629
+ "native": "On Apple use a `Gauge` or a `ProgressView` for each limit, with its label and value text, and a `LabeledContent` row for a limit with no bar. On Android use a `LinearProgressIndicator` with the value in words beside it.",
5630
+ "options": [
5631
+ {
5632
+ "id": "meters",
5633
+ "title": "A meter for each limit",
5634
+ "useWhen": "The plan has a few limits and the admin needs to see how close each one is.",
5635
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { formatBytes } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\n// A real app reads the numbers from the server. This is Free: 50 responses, 3 members and 1 GB.\nconst GB = 1024 ** 3;\nconst storage = { used: Math.round(0.85 * GB), limit: GB };\n\nexport default function UsageMetersMeters() {\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description=\"This month, on the Free plan.\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n {/* At the limit the meter says 'Limit reached' in words. The notice sits under it and names the limit. */}\n <Progress id=\"usage-meters-responses\" label=\"AI agent responses\" value={50} max={50} unit=\"responses\" aria-describedby={showNotice ? 'usage-meters-notice' : undefined} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {showNotice && (\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"usage-meters-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n )}\n </Stack>\n <Progress label=\"Members\" value={2} max={3} unit=\"members\" />\n {/* Near the limit the bar turns to a warning, and says so in words. */}\n <Progress label=\"Storage\" value={storage.used} max={storage.limit} valueText={`${formatBytes(storage.used)} of ${formatBytes(storage.limit)}`} />\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5636
+ "uses": [
5637
+ "Button",
5638
+ "Center",
5639
+ "Cluster",
5640
+ "Paragraph",
5641
+ "Progress",
5642
+ "SettingsSection",
5643
+ "Stack",
5644
+ "Surface",
5645
+ "formatBytes"
5646
+ ]
5647
+ },
5648
+ {
5649
+ "id": "by-person",
5650
+ "title": "Who used it, under the meters",
5651
+ "useWhen": "People share one pool, and the admin asks who used it.",
5652
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\n// A real app counts these on the server, most first. A count can pass its limit by a few: replies that were\n// already running when the limit was reached still finish.\nconst people = [\n { id: 'dana', name: 'Dana Lee', responses: 21 },\n { id: 'ben', name: 'Ben Carter', responses: 19 },\n { id: 'omar', name: 'Omar Reyes', responses: 13 },\n];\nconst total = people.reduce((sum, p) => sum + p.responses, 0);\n\nexport default function UsageMetersByPerson() {\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description=\"This month, on the Free plan.\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Progress label=\"AI agent responses\" value={total} max={50} unit=\"responses\" aria-describedby={showNotice ? 'usage-meters-person-notice' : undefined} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {showNotice && (\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"usage-meters-person-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n )}\n </Stack>\n {/* Under the meters: who used it, most first, with exact numbers. */}\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">Responses by person</Heading>\n <TableContainer aria-label=\"Responses by person\" minWidth=\"320px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Person</TableHeaderCell>\n <TableHeaderCell width=\"130px\" align=\"right\">Responses</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {people.map((p) => (\n <TableRow key={p.id}>\n <TableCell>{p.name}</TableCell>\n <TableCell width=\"130px\" align=\"right\">{formatCount(p.responses)}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5653
+ "uses": [
5654
+ "Button",
5655
+ "Center",
5656
+ "Cluster",
5657
+ "Heading",
5658
+ "Paragraph",
5659
+ "Progress",
5660
+ "SettingsSection",
5661
+ "Stack",
5662
+ "Surface",
5663
+ "TableCell",
5664
+ "TableContainer",
5665
+ "TableHeader",
5666
+ "TableHeaderCell",
5667
+ "TableRow",
5668
+ "formatCount"
5669
+ ]
5670
+ },
5671
+ {
5672
+ "id": "with-cap",
5673
+ "title": "Billed by the amount, with a cap",
5674
+ "useWhen": "Use is billed by the amount, and the admin sets a monthly spend cap that pauses use when it is reached.",
5675
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. Extra AI agent responses cost $0.05 each, and $18.40 is spent so far.\nconst spent = 18.4;\n\n// A real app reads this from the person's role. Only an admin sets the cap.\nconst canChangeCap = true;\n\nexport default function UsageMetersWithCap() {\n const [cap, setCap] = useState<number | null>(20);\n const [draft, setDraft] = useState('20');\n const [error, setError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(savedTimer.current);\n }, []);\n\n const next = draft.trim() === '' ? null : Number(draft);\n const changed = next !== cap;\n\n // The cap is one field with one Save Button. Empty means no cap.\n function handleSave() {\n if (saving || !changed) return;\n if (next !== null && !(Number.isInteger(next) && next >= 1 && next <= 10000)) {\n setError(`Enter a whole amount from ${formatMoney(1)} to ${formatMoney(10000)}, or leave it empty for no cap.`);\n return;\n }\n setError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCap(next);\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200);\n }\n\n const reached = cap !== null && spent >= cap;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description={`This month, on the Pro plan. Extra AI agent responses cost ${formatMoney(0.05)} each.`}>\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n {/* A cap is a limit: the bar warns near it and says 'Limit reached' at it. With no cap there is no bar. */}\n <Progress\n label=\"Spend this month\"\n value={spent}\n max={cap}\n valueText={cap === null ? `${formatMoney(spent)} so far, no cap` : `${formatMoney(spent)} of ${formatMoney(cap)}`}\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {reached && <Alert type=\"warning\" variant=\"inline\" autoDismiss={false} message=\"AI agent responses are paused. Raise the cap, or they start again on Dec 1.\" />}\n </Stack>\n {canChangeCap ? (\n <Form aria-label=\"Monthly spend cap\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"usage-meters-cap\" label=\"Monthly spend cap (USD)\" help=\"AI agent responses pause when the cap is reached. Leave it empty for no cap.\" error={error}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n type=\"number\"\n value={draft}\n disabled={saving}\n onChange={(e) => { setDraft(e.target.value); setError(''); setSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={changed || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n ) : (\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`The monthly spend cap is ${cap === null ? 'not set' : formatMoney(cap)}. Only admins can change it.`}</Paragraph>\n )}\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5676
+ "uses": [
5677
+ "Alert",
5678
+ "Button",
5679
+ "Center",
5680
+ "Cluster",
5681
+ "Form",
5682
+ "FormField",
5683
+ "Paragraph",
5684
+ "Progress",
5685
+ "SettingsSection",
5686
+ "Stack",
5687
+ "TextField",
5688
+ "formatMoney"
5689
+ ]
5690
+ }
5691
+ ]
4108
5692
  }
4109
5693
  ]
4110
5694
  }