oneslash-design-system 2.19.0 → 2.21.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 (264) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +62 -5
  3. package/dist/cases/about-page/profile.d.ts +1 -0
  4. package/dist/cases/about-page/profile.jsx +64 -0
  5. package/dist/cases/about-page.md +114 -0
  6. package/dist/cases/admin-inbox/list.d.ts +1 -0
  7. package/dist/cases/admin-inbox/list.jsx +104 -0
  8. package/dist/cases/admin-inbox/split.d.ts +1 -0
  9. package/dist/cases/admin-inbox/split.jsx +68 -0
  10. package/dist/cases/admin-inbox.md +254 -0
  11. package/dist/cases/api-keys.md +1 -1
  12. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  13. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  14. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  15. package/dist/cases/billing-page/self-serve.jsx +134 -0
  16. package/dist/cases/billing-page.md +247 -0
  17. package/dist/cases/blog-index/cards.d.ts +1 -0
  18. package/dist/cases/blog-index/cards.jsx +45 -0
  19. package/dist/cases/blog-index/list.d.ts +1 -0
  20. package/dist/cases/blog-index/list.jsx +46 -0
  21. package/dist/cases/blog-index.md +160 -0
  22. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  23. package/dist/cases/breakdown-list/bars.jsx +47 -0
  24. package/dist/cases/breakdown-list/table.d.ts +1 -0
  25. package/dist/cases/breakdown-list/table.jsx +69 -0
  26. package/dist/cases/breakdown-list.md +158 -0
  27. package/dist/cases/changelog/by-month.d.ts +1 -0
  28. package/dist/cases/changelog/by-month.jsx +70 -0
  29. package/dist/cases/changelog/one-page.d.ts +1 -0
  30. package/dist/cases/changelog/one-page.jsx +70 -0
  31. package/dist/cases/changelog.md +200 -0
  32. package/dist/cases/code-sample/block.d.ts +1 -0
  33. package/dist/cases/code-sample/block.jsx +19 -0
  34. package/dist/cases/code-sample/command.d.ts +1 -0
  35. package/dist/cases/code-sample/command.jsx +17 -0
  36. package/dist/cases/code-sample.md +96 -0
  37. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  38. package/dist/cases/composer-limit/notice.jsx +3 -3
  39. package/dist/cases/composer-limit.md +8 -8
  40. package/dist/cases/contact-page/form.d.ts +1 -0
  41. package/dist/cases/contact-page/form.jsx +83 -0
  42. package/dist/cases/contact-page/links.d.ts +1 -0
  43. package/dist/cases/contact-page/links.jsx +19 -0
  44. package/dist/cases/contact-page.md +142 -0
  45. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  46. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  47. package/dist/cases/dashboard/work-first.d.ts +1 -0
  48. package/dist/cases/dashboard/work-first.jsx +165 -0
  49. package/dist/cases/dashboard.md +507 -0
  50. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  51. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  52. package/dist/cases/data-table-page/paged.d.ts +1 -0
  53. package/dist/cases/data-table-page/paged.jsx +284 -0
  54. package/dist/cases/data-table-page.md +771 -0
  55. package/dist/cases/docs-component-page/reference.d.ts +1 -0
  56. package/dist/cases/docs-component-page/reference.jsx +93 -0
  57. package/dist/cases/docs-component-page.md +144 -0
  58. package/dist/cases/faq/accordion.d.ts +1 -0
  59. package/dist/cases/faq/accordion.jsx +25 -0
  60. package/dist/cases/faq/open-list.d.ts +1 -0
  61. package/dist/cases/faq/open-list.jsx +27 -0
  62. package/dist/cases/faq.md +110 -0
  63. package/dist/cases/feature-grid/cards.d.ts +1 -0
  64. package/dist/cases/feature-grid/cards.jsx +33 -0
  65. package/dist/cases/feature-grid/rows.d.ts +1 -0
  66. package/dist/cases/feature-grid/rows.jsx +30 -0
  67. package/dist/cases/feature-grid.md +132 -0
  68. package/dist/cases/image-viewer/gallery.d.ts +1 -0
  69. package/dist/cases/image-viewer/gallery.jsx +32 -0
  70. package/dist/cases/image-viewer/single.d.ts +1 -0
  71. package/dist/cases/image-viewer/single.jsx +25 -0
  72. package/dist/cases/image-viewer.md +123 -0
  73. package/dist/cases/invoice-list/table.d.ts +1 -0
  74. package/dist/cases/invoice-list/table.jsx +64 -0
  75. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  76. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  77. package/dist/cases/invoice-list.md +237 -0
  78. package/dist/cases/landing-hero/centered.d.ts +1 -0
  79. package/dist/cases/landing-hero/centered.jsx +22 -0
  80. package/dist/cases/landing-hero/split.d.ts +1 -0
  81. package/dist/cases/landing-hero/split.jsx +30 -0
  82. package/dist/cases/landing-hero.md +114 -0
  83. package/dist/cases/legal-page/sections.d.ts +1 -0
  84. package/dist/cases/legal-page/sections.jsx +61 -0
  85. package/dist/cases/legal-page.md +96 -0
  86. package/dist/cases/load-failure/inline.jsx +2 -2
  87. package/dist/cases/load-failure.md +2 -2
  88. package/dist/cases/long-form-page/article.d.ts +1 -0
  89. package/dist/cases/long-form-page/article.jsx +58 -0
  90. package/dist/cases/long-form-page/with-contents.d.ts +1 -0
  91. package/dist/cases/long-form-page/with-contents.jsx +41 -0
  92. package/dist/cases/long-form-page.md +170 -0
  93. package/dist/cases/members-list/rows.jsx +2 -1
  94. package/dist/cases/members-list/table.jsx +8 -9
  95. package/dist/cases/members-list.md +12 -13
  96. package/dist/cases/message-actions/hover-toolbar.jsx +11 -8
  97. package/dist/cases/message-actions/menu.jsx +10 -7
  98. package/dist/cases/message-actions.md +19 -13
  99. package/dist/cases/message-attachments/in-composer.jsx +2 -2
  100. package/dist/cases/message-attachments/in-message.jsx +16 -11
  101. package/dist/cases/message-attachments.md +29 -17
  102. package/dist/cases/number-format.md +36 -0
  103. package/dist/cases/one-main-action.md +33 -0
  104. package/dist/cases/overflow-menu/in-a-header.jsx +9 -6
  105. package/dist/cases/overflow-menu/on-a-row.jsx +9 -6
  106. package/dist/cases/overflow-menu.md +16 -10
  107. package/dist/cases/page-end/cta-band.d.ts +1 -0
  108. package/dist/cases/page-end/cta-band.jsx +24 -0
  109. package/dist/cases/page-end/next-link.d.ts +1 -0
  110. package/dist/cases/page-end/next-link.jsx +18 -0
  111. package/dist/cases/page-end.md +88 -0
  112. package/dist/cases/paged-card/pager.d.ts +1 -0
  113. package/dist/cases/paged-card/pager.jsx +41 -0
  114. package/dist/cases/paged-card/see-all.d.ts +1 -0
  115. package/dist/cases/paged-card/see-all.jsx +34 -0
  116. package/dist/cases/paged-card.md +147 -0
  117. package/dist/cases/password-gate/inline.d.ts +1 -0
  118. package/dist/cases/password-gate/inline.jsx +94 -0
  119. package/dist/cases/password-gate/modal.d.ts +1 -0
  120. package/dist/cases/password-gate/modal.jsx +81 -0
  121. package/dist/cases/password-gate/page.d.ts +1 -0
  122. package/dist/cases/password-gate/page.jsx +82 -0
  123. package/dist/cases/password-gate.md +351 -0
  124. package/dist/cases/payment-method/none.d.ts +1 -0
  125. package/dist/cases/payment-method/none.jsx +17 -0
  126. package/dist/cases/payment-method/on-file.d.ts +1 -0
  127. package/dist/cases/payment-method/on-file.jsx +92 -0
  128. package/dist/cases/payment-method.md +182 -0
  129. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  130. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  131. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  132. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  133. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  134. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  135. package/dist/cases/plan-change-confirm.md +261 -0
  136. package/dist/cases/plan-picker/cards.d.ts +1 -0
  137. package/dist/cases/plan-picker/cards.jsx +97 -0
  138. package/dist/cases/plan-picker/list.d.ts +1 -0
  139. package/dist/cases/plan-picker/list.jsx +103 -0
  140. package/dist/cases/plan-picker.md +297 -0
  141. package/dist/cases/pricing-section/cards.d.ts +1 -0
  142. package/dist/cases/pricing-section/cards.jsx +40 -0
  143. package/dist/cases/pricing-section.md +85 -0
  144. package/dist/cases/product-cards/grid.d.ts +1 -0
  145. package/dist/cases/product-cards/grid.jsx +20 -0
  146. package/dist/cases/product-cards.md +71 -0
  147. package/dist/cases/range-switch/segmented.jsx +11 -7
  148. package/dist/cases/range-switch.md +16 -11
  149. package/dist/cases/reply-feedback/thumbs.jsx +11 -8
  150. package/dist/cases/reply-feedback/with-reason.jsx +11 -8
  151. package/dist/cases/reply-feedback.md +20 -14
  152. package/dist/cases/section-index/cards.d.ts +1 -0
  153. package/dist/cases/section-index/cards.jsx +25 -0
  154. package/dist/cases/section-index/list.d.ts +1 -0
  155. package/dist/cases/section-index/list.jsx +56 -0
  156. package/dist/cases/section-index.md +140 -0
  157. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  158. package/dist/cases/settings-page.md +5 -4
  159. package/dist/cases/site-header.md +1 -1
  160. package/dist/cases/site-search/dialog.d.ts +1 -0
  161. package/dist/cases/site-search/dialog.jsx +131 -0
  162. package/dist/cases/site-search.md +176 -0
  163. package/dist/cases/stat-row/featured.d.ts +1 -0
  164. package/dist/cases/stat-row/featured.jsx +17 -0
  165. package/dist/cases/stat-row/tiles.d.ts +1 -0
  166. package/dist/cases/stat-row/tiles.jsx +34 -0
  167. package/dist/cases/stat-row.md +104 -0
  168. package/dist/cases/status-label/dot.d.ts +1 -0
  169. package/dist/cases/status-label/dot.jsx +39 -0
  170. package/dist/cases/status-label/text.d.ts +1 -0
  171. package/dist/cases/status-label/text.jsx +44 -0
  172. package/dist/cases/status-label.md +143 -0
  173. package/dist/cases/tabbed-panels/tabs.d.ts +1 -0
  174. package/dist/cases/tabbed-panels/tabs.jsx +40 -0
  175. package/dist/cases/tabbed-panels.md +81 -0
  176. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  177. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  178. package/dist/cases/upgrade-prompt.md +10 -6
  179. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  180. package/dist/cases/usage-meters/by-person.jsx +72 -0
  181. package/dist/cases/usage-meters/meters.d.ts +1 -0
  182. package/dist/cases/usage-meters/meters.jsx +49 -0
  183. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  184. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  185. package/dist/cases/usage-meters.md +303 -0
  186. package/dist/cases.json +2178 -97
  187. package/dist/components/accordion.d.ts +31 -0
  188. package/dist/components/accordion.jsx +103 -0
  189. package/dist/components/button.d.ts +1 -1
  190. package/dist/components/button.jsx +11 -5
  191. package/dist/components/codeBlock.d.ts +26 -0
  192. package/dist/components/codeBlock.jsx +101 -0
  193. package/dist/components/formatNumber.d.ts +25 -0
  194. package/dist/components/formatNumber.js +125 -0
  195. package/dist/components/iconButton.jsx +12 -7
  196. package/dist/components/lightbox.d.ts +31 -0
  197. package/dist/components/lightbox.jsx +161 -0
  198. package/dist/components/linkCard.d.ts +10 -1
  199. package/dist/components/linkCard.jsx +32 -6
  200. package/dist/components/modal.d.ts +10 -2
  201. package/dist/components/modal.jsx +17 -12
  202. package/dist/components/pageHeader.jsx +1 -1
  203. package/dist/components/pagination.d.ts +28 -0
  204. package/dist/components/pagination.jsx +89 -0
  205. package/dist/components/progress.d.ts +33 -0
  206. package/dist/components/progress.jsx +50 -0
  207. package/dist/components/searchDialog.d.ts +44 -0
  208. package/dist/components/searchDialog.jsx +152 -0
  209. package/dist/components/skeleton.d.ts +21 -0
  210. package/dist/components/skeleton.jsx +41 -0
  211. package/dist/components/statTile.d.ts +32 -0
  212. package/dist/components/statTile.jsx +61 -0
  213. package/dist/components/tab.d.ts +5 -1
  214. package/dist/components/tab.jsx +2 -2
  215. package/dist/components/tabPanel.d.ts +16 -0
  216. package/dist/components/tabPanel.jsx +12 -0
  217. package/dist/components/tableContainer.d.ts +5 -1
  218. package/dist/components/tableContainer.jsx +9 -1
  219. package/dist/components/tableHeaderCell.d.ts +3 -1
  220. package/dist/components/tableHeaderCell.jsx +2 -2
  221. package/dist/components/tabsContainer.d.ts +5 -1
  222. package/dist/components/tabsContainer.jsx +2 -2
  223. package/dist/components/titleBar.d.ts +3 -1
  224. package/dist/components/titleBar.jsx +4 -3
  225. package/dist/index.d.ts +10 -0
  226. package/dist/index.js +10 -0
  227. package/dist/internal/accordion.d.ts +4 -0
  228. package/dist/internal/accordion.js +53 -0
  229. package/dist/internal/combobox.d.ts +20 -0
  230. package/dist/internal/combobox.js +28 -0
  231. package/dist/internal/highlight.d.ts +5 -0
  232. package/dist/internal/highlight.js +18 -0
  233. package/dist/native-mapping.json +57 -3
  234. package/dist/stories/Accordion.stories.d.ts +11 -0
  235. package/dist/stories/Accordion.stories.jsx +93 -0
  236. package/dist/stories/Button.stories.d.ts +1 -0
  237. package/dist/stories/Button.stories.jsx +19 -1
  238. package/dist/stories/Cases.generated.stories.d.ts +60 -0
  239. package/dist/stories/Cases.generated.stories.jsx +120 -0
  240. package/dist/stories/CodeBlock.stories.d.ts +12 -0
  241. package/dist/stories/CodeBlock.stories.jsx +65 -0
  242. package/dist/stories/Lightbox.stories.d.ts +8 -0
  243. package/dist/stories/Lightbox.stories.jsx +40 -0
  244. package/dist/stories/LinkCard.stories.d.ts +6 -0
  245. package/dist/stories/LinkCard.stories.jsx +17 -0
  246. package/dist/stories/PageHeader.stories.d.ts +2 -0
  247. package/dist/stories/PageHeader.stories.jsx +13 -0
  248. package/dist/stories/Pagination.stories.d.ts +9 -0
  249. package/dist/stories/Pagination.stories.jsx +75 -0
  250. package/dist/stories/Progress.stories.d.ts +9 -0
  251. package/dist/stories/Progress.stories.jsx +43 -0
  252. package/dist/stories/SearchDialog.stories.d.ts +17 -0
  253. package/dist/stories/SearchDialog.stories.jsx +111 -0
  254. package/dist/stories/Skeleton.stories.d.ts +7 -0
  255. package/dist/stories/Skeleton.stories.jsx +27 -0
  256. package/dist/stories/StatTile.stories.d.ts +10 -0
  257. package/dist/stories/StatTile.stories.jsx +55 -0
  258. package/dist/stories/TabPanel.stories.d.ts +7 -0
  259. package/dist/stories/TabPanel.stories.jsx +31 -0
  260. package/dist/stories/Table.stories.d.ts +1 -0
  261. package/dist/stories/Table.stories.jsx +49 -1
  262. package/dist/stories/TitleBar.stories.d.ts +1 -0
  263. package/dist/stories/TitleBar.stories.jsx +7 -0
  264. package/package.json +5 -1
package/dist/cases.json CHANGED
@@ -1,5 +1,55 @@
1
1
  {
2
2
  "cases": [
3
+ {
4
+ "id": "about-page",
5
+ "title": "About page",
6
+ "kind": "design",
7
+ "level": "page",
8
+ "area": "content",
9
+ "situation": "A visitor wants to know who is behind the work and whether to get in touch.",
10
+ "do": [
11
+ "Open with a `PageHeader` whose title is the person's name and whose lede says what they do in one sentence.",
12
+ "Put the few facts a visitor asks first in the header's `facts`: role, company, where they are based, years of experience.",
13
+ "Show a portrait in a `Figure` with a caption. Give the image an `alt` that says what it shows.",
14
+ "Set the work history as `NumberedRow` rows, the newest first, with a plain years range in each title.",
15
+ "Set the skills as a `Cluster` of `Tag` with `variant=\"contained\"`. Keep it to the skills the work shows.",
16
+ "Put further reading in a `List` of `Link`. Write each link as the name of the piece, not 'Read more'.",
17
+ "End the page with one `LinkCard` to the next step, as the case 'Page end' says.",
18
+ "Give each section a `SectionIntro`, so every section has a heading and an address."
19
+ ],
20
+ "dont": [
21
+ "Do not write the page in the third person when one person owns the work.",
22
+ "Do not list every job. Keep the ones that explain the work.",
23
+ "Do not rate skills with bars or stars.",
24
+ "Do not add social links that the person does not use.",
25
+ "Do not put a resume in a modal that a keyboard cannot reach."
26
+ ],
27
+ "native": "On Apple a profile is a grouped list with the name in a large title. Use a `NavigationLink` for further reading.",
28
+ "options": [
29
+ {
30
+ "id": "profile",
31
+ "title": "One person introduces their work",
32
+ "useWhen": "One person, such as a designer, writes about their work in their own voice.",
33
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport NumberedRow from 'oneslash-design-system/components/numberedRow';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\nimport List from 'oneslash-design-system/components/list';\nimport Link from 'oneslash-design-system/components/link';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport { Cluster, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// A stand-in for the portrait. A real page passes its own picture.\nconst portrait =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 800'%3E%3Crect width='1200' height='800' fill='%23eef2f6'/%3E%3Ccircle cx='600' cy='330' r='110' fill='%23c2cfdb'/%3E%3Cpath d='M380 700c0-130 100-220 220-220s220 90 220 220z' fill='%23aab8c6'/%3E%3C/svg%3E\";\n\nconst skills = ['Forms and errors', 'Billing and plans', 'Settings', 'Writing for interfaces', 'Field research', 'Workshops'];\n\nexport default function AboutPageProfile() {\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageSection>\n <PageHeader\n level={1}\n eyebrow=\"About\"\n title=\"Dana Lee\"\n lede=\"Designer at Acme, working on billing and account settings.\"\n facts={[\n { label: 'Role', value: 'Designer' },\n { label: 'Company', value: 'Acme' },\n { label: 'Based', value: 'Denver' },\n { label: 'Experience', value: '9 years' },\n ]}\n />\n {/* A placeholder, never a photo in the design system. A real page gives the picture a caption. */}\n <Figure crop={3 / 2} caption=\"Dana at the Acme studio.\">\n <Image src={portrait} alt=\"A portrait of Dana Lee\" width={1200} height={800} />\n </Figure>\n </PageSection>\n <PageSection>\n <SectionIntro id=\"about-page-work\" name=\"Work\" statement=\"I design the parts of a product that people have to trust.\" />\n <Stack gap=\"xlarge\">\n <NumberedRow index={0} title=\"Designer, Acme, 2023 to now\">\n <Paragraph tone=\"secondary\" measure=\"none\">I lead the design of billing, plans and the settings people change most.</Paragraph>\n </NumberedRow>\n <NumberedRow index={1} title=\"Product designer at a design studio, 2019 to 2023\">\n <Paragraph tone=\"secondary\" measure=\"none\">I built a design system for six teams and wrote the rules for forms and errors.</Paragraph>\n </NumberedRow>\n <NumberedRow index={2} title=\"Interface designer for field tools, 2017 to 2019\">\n <Paragraph tone=\"secondary\" measure=\"none\">I designed tools for field crews that worked with a poor connection.</Paragraph>\n </NumberedRow>\n </Stack>\n </PageSection>\n <PageSection>\n <SectionIntro id=\"about-page-skills\" name=\"Skills\" />\n <Cluster>\n {skills.map((skill) => (\n <Tag key={skill} variant=\"contained\" size=\"medium\" state=\"enabled\" label={skill} />\n ))}\n </Cluster>\n </PageSection>\n <PageSection>\n <SectionIntro id=\"about-page-reading\" name=\"Further reading\" />\n <List\n size=\"body1\"\n items={[\n <Link key=\"a\" href=\"#how-we-write-errors\">How we write error messages</Link>,\n <Link key=\"b\" href=\"#a-design-system-for-six-teams\">A design system for six teams</Link>,\n <Link key=\"c\" href=\"#designing-for-a-poor-connection\">Designing for a poor connection</Link>,\n ]}\n />\n </PageSection>\n {/* The page ends by pointing to one next step. */}\n <LinkCard href=\"#contact\" title=\"Write a message\" caption=\"Next: Contact\" />\n </Stack>\n </PageShell>\n );\n}\n",
34
+ "uses": [
35
+ "Cluster",
36
+ "Figure",
37
+ "Image",
38
+ "Link",
39
+ "LinkCard",
40
+ "List",
41
+ "NumberedRow",
42
+ "PageHeader",
43
+ "PageSection",
44
+ "PageShell",
45
+ "Paragraph",
46
+ "SectionIntro",
47
+ "Stack",
48
+ "Tag"
49
+ ]
50
+ }
51
+ ]
52
+ },
3
53
  {
4
54
  "id": "accept-invite",
5
55
  "title": "Invite link page",
@@ -112,6 +162,73 @@
112
162
  }
113
163
  ]
114
164
  },
165
+ {
166
+ "id": "admin-inbox",
167
+ "title": "Admin inbox",
168
+ "kind": "design",
169
+ "level": "page",
170
+ "area": "content",
171
+ "situation": "The owner of a site reads the messages that visitors sent through its contact form.",
172
+ "do": [
173
+ "Open with a `PageHeader` titled 'Messages' and a lede that counts what is unread: '3 of 12 unread'.",
174
+ "Show the sender, the date and the first lines of each message. Write the date as plain text, such as Nov 12, 2026.",
175
+ "Mark an unread message with a `Tag` that says 'Unread', so it does not rely on color.",
176
+ "Give each row an `IconButton` that toggles read and unread, in a `Tooltip` with its name. Name it for the row's message: 'Mark message from Ben Carter as read'.",
177
+ "Follow the case 'List and detail' for `split`. Name its Button 'Mark as Read' or 'Mark as Unread'.",
178
+ "Keep the header while the list loads, and show `Skeleton` rows with one label: 'Loading messages'.",
179
+ "Follow the case 'Load failure' when the list fails to load: `EmptyBox` 'Could not load messages' with a 'Try Again' Button that is `loading` while it retries.",
180
+ "Show `EmptyBox` as the case 'Empty list' says when there are no messages: `size=\"large\"` in `list`, `size=\"small\"` in the list column of `split`. Text 'No messages yet', `secondText` 'Messages from the contact form appear here.'"
181
+ ],
182
+ "dont": [
183
+ "Do not replace the whole page with a loading screen while the list loads.",
184
+ "Do not show 'No messages yet' when the list failed to load.",
185
+ "Do not name every IconButton 'Mark as read'. Name the message it acts on.",
186
+ "Do not mark a message read only by opening it, with no way to undo.",
187
+ "Do not leave a failed read or unread change with no message."
188
+ ],
189
+ "native": "On Apple use a `List` with a swipe action to mark a message read or unread, and a `NavigationSplitView` for many messages.",
190
+ "options": [
191
+ {
192
+ "id": "list",
193
+ "title": "One column of messages",
194
+ "useWhen": "A few messages arrive each week, and each one is read in full in the list.",
195
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\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 Tag from 'oneslash-design-system/components/tag';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Button from 'oneslash-design-system/components/button';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Message = { id: string; from: string; date: string; text: string; read: boolean };\n\nconst first: Message[] = [\n { id: 'm1', from: 'Ben Carter', date: 'Nov 16, 2026', text: 'I saw your page about error messages. Do you give talks? We are planning a day for our design team in January.', read: false },\n { id: 'm2', from: 'Omar Reyes', date: 'Nov 15, 2026', text: 'Is the plan changes case study open to everyone? I would like to share it with my team.', read: false },\n { id: 'm3', from: 'Maya Brooks', date: 'Nov 14, 2026', text: 'Thank you for the reading list. I read the piece on poor connections twice.', read: false },\n { id: 'm4', from: 'Leo Park', date: 'Nov 12, 2026', text: 'Could you share the password for the case studies? I would like to show it to my team.', read: true },\n { id: 'm5', from: 'Sara Idris', date: 'Nov 10, 2026', text: 'We are hiring a designer in the spring. Would you like to talk?', read: true },\n { id: 'm6', from: 'Noah Quinn', date: 'Nov 9, 2026', text: 'Your design system notes helped our team. Is there a newsletter?', read: true },\n { id: 'm7', from: 'Ana Silva', date: 'Nov 7, 2026', text: 'A small thing: the link to the second case study on the About page does not open.', read: true },\n { id: 'm8', from: 'Tom Hale', date: 'Nov 6, 2026', text: 'Can I use one of your diagrams in a talk? I will credit you.', read: true },\n { id: 'm9', from: 'Iris Chen', date: 'Nov 4, 2026', text: 'I would like to ask about the tools you use for prototyping.', read: true },\n { id: 'm10', from: 'Sam Ortiz', date: 'Nov 2, 2026', text: 'Congratulations on the new page. The facts row is very clear.', read: true },\n { id: 'm11', from: 'Eve Lund', date: 'Oct 29, 2026', text: 'We met at the meetup in October. I would like to stay in touch.', read: true },\n { id: 'm12', from: 'Raj Patel', date: 'Oct 22, 2026', text: 'Is the About page available as a printable resume?', read: true },\n];\n\nexport default function AdminInboxList() {\n const [messages, setMessages] = useState(first);\n const [failed, setFailed] = useState(false);\n const [busy, setBusy] = useState(false);\n const [refreshes, setRefreshes] = useState(0);\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 const unread = messages.filter((m) => !m.read).length;\n\n function toggle(id: string) {\n setMessages((list) => list.map((m) => (m.id === id ? { ...m, read: !m.read } : m)));\n }\n\n function load() {\n if (busy) return;\n const attempt = refreshes + 1;\n setRefreshes(attempt);\n setBusy(true);\n // Stands in for the request to the server. The second refresh fails, so you can see Try Again.\n timer.current = setTimeout(() => {\n setBusy(false);\n setFailed(attempt === 2);\n }, 1000);\n }\n\n return (\n <PageShell>\n <Stack gap=\"xlarge\">\n {/* The header stays while the list loads or fails. */}\n <PageHeader level={1} title=\"Messages\" lede={`${unread} of ${messages.length} unread`} />\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Refresh\" decoIcon=\"RefreshCw\" loading={busy && !failed} onClickButton={load} />\n </Cluster>\n {busy && !failed && (\n <Stack gap=\"small\">\n <Skeleton variant=\"block\" height=\"large\" label=\"Loading messages\" />\n <Skeleton variant=\"block\" height=\"large\" />\n <Skeleton variant=\"block\" height=\"large\" />\n </Stack>\n )}\n {failed && (\n // The list fails as a region, as the case 'Load failure' shows: it stays until the list loads.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load messages\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={busy} onClickButton={load} />}\n />\n </Surface>\n )}\n {!busy && !failed && messages.length === 0 && <EmptyBox size=\"large\" text=\"No messages yet\" secondText=\"Messages from the contact form appear here.\" />}\n {!busy && !failed && (\n <Stack gap=\"small\">\n {messages.map((m) => (\n <Surface key={m.id} padding=\"small\" align=\"start\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{m.from}</Heading>\n {!m.read && <Tag variant=\"dot\" size=\"small\" color=\"info\" label=\"Unread\" />}\n </Cluster>\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"caption\">{m.date}</Paragraph>\n {/* The icon shows what the Button does: an open envelope marks the message read, a closed one marks it unread. */}\n <Tooltip title={`Mark message from ${m.from} as ${m.read ? 'unread' : 'read'}`}>\n <IconButton\n iconName={m.read ? 'Mail' : 'MailOpen'}\n ariaLabel={`Mark message from ${m.from} as ${m.read ? 'unread' : 'read'}`}\n color={m.read ? 'iconOnly' : 'primary'}\n state=\"enabled\"\n size=\"medium\"\n onClick={() => toggle(m.id)}\n />\n </Tooltip>\n </Cluster>\n </Cluster>\n <Paragraph size=\"body2\" measure=\"none\">{m.text}</Paragraph>\n </Stack>\n </Surface>\n ))}\n </Stack>\n )}\n </Stack>\n </PageShell>\n );\n}\n",
196
+ "uses": [
197
+ "Button",
198
+ "Cluster",
199
+ "EmptyBox",
200
+ "Heading",
201
+ "IconButton",
202
+ "PageHeader",
203
+ "PageShell",
204
+ "Paragraph",
205
+ "Skeleton",
206
+ "Stack",
207
+ "Surface",
208
+ "Tag",
209
+ "Tooltip"
210
+ ]
211
+ },
212
+ {
213
+ "id": "split",
214
+ "title": "List beside the message",
215
+ "useWhen": "Many messages arrive, and the owner works down them one after another.",
216
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\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 { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Message = { id: string; from: string; subject: string; date: string; body: string[]; read: boolean };\n\nconst first: Message[] = [\n { id: 'talk', from: 'Ben Carter', subject: 'A talk in January?', date: 'Nov 16, 2026', body: ['I saw your page about error messages. Do you give talks?', 'We are planning a day for our design team in January.'], read: false },\n { id: 'share', from: 'Omar Reyes', subject: 'Sharing the case study', date: 'Nov 15, 2026', body: ['Is the plan changes case study open to everyone?', 'I would like to share it with my team.'], read: false },\n { id: 'thanks', from: 'Maya Brooks', subject: 'Thank you for the reading list', date: 'Nov 14, 2026', body: ['I read the piece on poor connections twice.'], read: false },\n { id: 'password', from: 'Leo Park', subject: 'The case study password', date: 'Nov 12, 2026', body: ['Could you share the password for the case studies?', 'I would like to show it to my team.'], read: true },\n { id: 'hiring', from: 'Sara Idris', subject: 'We are hiring in the spring', date: 'Nov 10, 2026', body: ['We are hiring a designer in the spring. Would you like to talk?'], read: true },\n { id: 'newsletter', from: 'Noah Quinn', subject: 'Is there a newsletter?', date: 'Nov 9, 2026', body: ['Your design system notes helped our team.'], read: true },\n];\n\nexport default function AdminInboxSplit() {\n const [messages, setMessages] = useState(first);\n // One message is always open, the first at the start.\n const [openId, setOpenId] = useState(first[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 const unread = messages.filter((m) => !m.read).length;\n\n function toggle(id: string) {\n setMessages((list) => list.map((m) => (m.id === id ? { ...m, read: !m.read } : m)));\n }\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 tag={m.read ? undefined : { label: 'Unread', color: 'info' }}\n href={`/admin/messages/${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 <PageHeader level={1} title=\"Messages\" lede={`${unread} of ${messages.length} unread`} />\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 Messages\" 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.date}</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=\"secondary\" state=\"enabled\" decoIcon=\"CircleCheck\" label={message.read ? 'Mark as Unread' : 'Mark as Read'} onClickButton={() => toggle(message.id)} />\n </Cluster>\n </SettingsLayout>\n </Stack>\n </PageShell>\n );\n}\n",
217
+ "uses": [
218
+ "Button",
219
+ "Cluster",
220
+ "Heading",
221
+ "MenuItem",
222
+ "Navigation",
223
+ "PageHeader",
224
+ "PageShell",
225
+ "Paragraph",
226
+ "SettingsLayout",
227
+ "Stack"
228
+ ]
229
+ }
230
+ ]
231
+ },
115
232
  {
116
233
  "id": "agent-asks-before-risky-action",
117
234
  "title": "An agent asks before a risky action",
@@ -604,7 +721,7 @@
604
721
  "Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.",
605
722
  "Confirm 'Revoke' in the row, as the case 'Delete confirm' does: the row asks 'Revoke CI pipeline?' and shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'CI pipeline key revoked.'",
606
723
  "Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the key: 'Revoke CI pipeline' and 'Cancel revoking CI pipeline'.",
607
- "Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what is empty' says.",
724
+ "Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what will fill it' says.",
608
725
  "Disable the name field while the key is made, and show `loading` on the Button without changing its label."
609
726
  ],
610
727
  "dont": [
@@ -817,6 +934,267 @@
817
934
  }
818
935
  ]
819
936
  },
937
+ {
938
+ "id": "billing-page",
939
+ "title": "Billing page",
940
+ "kind": "design",
941
+ "level": "page",
942
+ "area": "dashboard",
943
+ "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.",
944
+ "do": [
945
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
946
+ "Put these `SettingsSection`s in this order under a `TitleBar` named 'Billing': Plan, Usage, Payment method, Invoices. The danger section, if any, comes last.",
947
+ "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'.",
948
+ "Show the usage as the case 'Usage against limits' says, and the payment method as the case 'Payment method' says.",
949
+ "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'.",
950
+ "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'.",
951
+ "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.'",
952
+ "Add an error dot `Tag` 'Past due' by the plan name.",
953
+ "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.",
954
+ "Show a person who cannot change billing every section as text, with no Buttons, and one line: 'Only admins can change billing.'",
955
+ "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.",
956
+ "Leave out every control, price, card and invoice on a plan billed elsewhere.",
957
+ "Show a status as the case 'Status in a row' says: 'Past due' and 'Canceling' as dots, 'Paid' as text."
958
+ ],
959
+ "dont": [
960
+ "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.",
961
+ "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.",
962
+ "Do not leave a failed payment without the date it must be fixed by.",
963
+ "Do not end the plan on the first click. Ask in a Modal first.",
964
+ "Do not name the action 'Cancel Plan'. It would sit beside 'Cancel' in the confirm.",
965
+ "Do not show a plan billed elsewhere with a 'Change Plan' Button that does nothing. Say where to change it.",
966
+ "Do not write 'Canceled' for a plan that is still on. Say 'Canceling' and when it ends."
967
+ ],
968
+ "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.",
969
+ "options": [
970
+ {
971
+ "id": "self-serve",
972
+ "title": "An admin pays here",
973
+ "useWhen": "The person who manages billing changes the plan, the card and the cancel on this page.",
974
+ "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",
975
+ "uses": [
976
+ "Alert",
977
+ "Button",
978
+ "Center",
979
+ "Cluster",
980
+ "Heading",
981
+ "Link",
982
+ "Modal",
983
+ "Paragraph",
984
+ "Progress",
985
+ "SettingsSection",
986
+ "Stack",
987
+ "Surface",
988
+ "TableCell",
989
+ "TableContainer",
990
+ "TableHeader",
991
+ "TableHeaderCell",
992
+ "TableRow",
993
+ "Tag",
994
+ "TitleBar",
995
+ "formatMoney"
996
+ ]
997
+ },
998
+ {
999
+ "id": "billed-elsewhere",
1000
+ "title": "Billed elsewhere",
1001
+ "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.",
1002
+ "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",
1003
+ "uses": [
1004
+ "Center",
1005
+ "Heading",
1006
+ "Paragraph",
1007
+ "Progress",
1008
+ "SettingsSection",
1009
+ "Stack",
1010
+ "TitleBar"
1011
+ ]
1012
+ }
1013
+ ]
1014
+ },
1015
+ {
1016
+ "id": "blog-index",
1017
+ "title": "Blog index",
1018
+ "kind": "design",
1019
+ "level": "page",
1020
+ "area": "content",
1021
+ "situation": "A visitor opens the blog to see what was written lately and to pick a post to read.",
1022
+ "do": [
1023
+ "Use `PageHeader` with `level={1}`: the title 'Blog' is the one level 1 heading, with a `lede` of one sentence about what the blog is for.",
1024
+ "Put the newest post first and say so nowhere. The order is the date.",
1025
+ "Make each row of `list` the date as 'Nov 12, 2026' in a secondary caption `Paragraph`, the title as a `Link` and one line of `Paragraph` under it. A row is one link, so the title is the link and the line is not.",
1026
+ "Use `LinkCard` for `cards`, with `image`, `title`, `description` and the date as `caption`, in `Grid columns={2}`. Give the cover `alt=\"\"` when the title says what the post is about, because a cover's alt text joins the link's name.",
1027
+ "Show 12 posts to a page. Past 12, add `Pagination` with `getHref`, such as `(p) => '/blog?page=' + p`, so each page has an address that works without script. Name it 'Blog pages'.",
1028
+ "Show `EmptyBox` with `size=\"large\"` when there are no posts yet: 'No posts yet', with `secondText` 'New posts appear here.' and no action.",
1029
+ "Follow the cases 'Empty search' and 'Load failure' for a search or a filter on the blog."
1030
+ ],
1031
+ "dont": [
1032
+ "Do not use `TimeStamp` for a post date. It writes '11/12/2026 Thu', and the site writes dates as 'Nov 12, 2026'.",
1033
+ "Do not show a post count or a count of readers.",
1034
+ "Do not mix a list and cards on one page. Pick the one that fits the posts.",
1035
+ "Do not put the whole text of a post in the index. One line is enough to choose.",
1036
+ "Do not use a picture of a person as a cover. A cover is a picture of the subject.",
1037
+ "Do not page by infinite scroll. A person cannot reach the footer, or come back to the same place."
1038
+ ],
1039
+ "native": "On Apple use a `List` of `NavigationLink`s for posts, or a `LazyVGrid` of cards for covers. On Android use a `LazyColumn` or `LazyVerticalGrid`.",
1040
+ "options": [
1041
+ {
1042
+ "id": "list",
1043
+ "title": "A list of posts, newest first",
1044
+ "useWhen": "The posts have no pictures, and a person scans the titles and the dates.",
1045
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Link from 'oneslash-design-system/components/link';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// Made-up posts, newest first. A real site loads one page of them from its own data.\nconst posts = [\n { id: 'task-threads', date: 'Nov 12, 2026', title: 'How task threads work', line: 'One piece of work and all of its talk, in one thread.' },\n { id: 'pinning', date: 'Nov 5, 2026', title: 'Pin what people need to find again', line: 'Pins stay at the top of a channel until you remove them.' },\n { id: 'agent-sources', date: 'Oct 29, 2026', title: 'Why the agent names its sources', line: 'An answer you can check is an answer you can use.' },\n { id: 'notes-export', date: 'Oct 22, 2026', title: 'Take your notes with you', line: 'Export a note or a whole workspace as PDF.' },\n { id: 'members', date: 'Oct 15, 2026', title: 'Inviting people to a workspace', line: 'Invite by email and choose what each person can do.' },\n { id: 'plans', date: 'Oct 8, 2026', title: 'Choosing a plan', line: 'What each plan includes, and when to move up.' },\n { id: 'search', date: 'Oct 1, 2026', title: 'Finding an old message', line: 'Search reads messages, notes and files together.' },\n { id: 'channels', date: 'Sep 24, 2026', title: 'How channels work', line: 'Make a channel for each team or project.' },\n { id: 'billing', date: 'Sep 17, 2026', title: 'Where your invoices are', line: 'Download any invoice from the billing page.' },\n { id: 'dark-mode', date: 'Sep 10, 2026', title: 'Light, dark or follow the system', line: 'Pick a theme once and every page follows it.' },\n { id: 'shortcuts', date: 'Sep 3, 2026', title: 'Keyboard shortcuts worth learning', line: 'Five keys that save the most time.' },\n { id: 'welcome', date: 'Aug 27, 2026', title: 'Welcome to the Acme blog', line: 'What we will write about here.' },\n { id: 'roadmap', date: 'Aug 20, 2026', title: 'What we are building next', line: 'A short look at the next three months.' },\n { id: 'hello', date: 'Aug 13, 2026', title: 'Hello from the team', line: 'Who we are and why we started.' },\n];\n\nconst PAGE_SIZE = 12;\n\nexport default function BlogIndexList() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(posts.length / PAGE_SIZE);\n const shown = posts.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Blog\" lede=\"Notes from the team on how Acme works and why.\" />\n {shown.length === 0 ? (\n <EmptyBox size=\"large\" text=\"No posts yet\" secondText=\"New posts appear here.\" />\n ) : (\n <Stack gap=\"xlarge\">\n {shown.map((post) => (\n <Stack key={post.id} gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{post.date}</Paragraph>\n <Link href={`#${post.id}`} size=\"subtitle1\">{post.title}</Link>\n <Paragraph tone=\"secondary\" size=\"body2\">{post.line}</Paragraph>\n </Stack>\n ))}\n </Stack>\n )}\n {/* A real blog passes an address that works without script, such as '/blog?page=2'. The example keeps the page in its hash. */}\n <Pagination page={page} pageCount={pageCount} onPageChange={setPage} getHref={(p) => `#page-${p}`} aria-label=\"Blog pages\" />\n </Stack>\n </PageShell>\n );\n}\n",
1046
+ "uses": [
1047
+ "EmptyBox",
1048
+ "Link",
1049
+ "PageHeader",
1050
+ "PageShell",
1051
+ "Pagination",
1052
+ "Paragraph",
1053
+ "Stack"
1054
+ ]
1055
+ },
1056
+ {
1057
+ "id": "cards",
1058
+ "title": "Cards with a cover",
1059
+ "useWhen": "Every post has a cover picture, and the picture helps a person choose.",
1060
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport { Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Stand-ins for the covers. A real post has its own picture.\nconst cover = (fill: string) =>\n `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 360'%3E%3Crect width='640' height='360' fill='${fill}'/%3E%3Crect x='80' y='80' width='300' height='200' rx='20' fill='%23ffffff'/%3E%3Crect x='420' y='120' width='140' height='140' rx='70' fill='%232f6b4f'/%3E%3C/svg%3E`;\nconst fills = ['%23eef2f6', '%23e6efe9', '%23f1ece4'];\n\n// Made-up posts, newest first. A real site loads one page of them from its own data.\nconst posts = [\n { id: 'task-threads', date: 'Nov 12, 2026', title: 'How task threads work', line: 'One piece of work and all of its talk, in one thread.' },\n { id: 'pinning', date: 'Nov 5, 2026', title: 'Pin what people need to find again', line: 'Pins stay at the top of a channel until you remove them.' },\n { id: 'agent-sources', date: 'Oct 29, 2026', title: 'Why the agent names its sources', line: 'An answer you can check is an answer you can use.' },\n { id: 'notes-export', date: 'Oct 22, 2026', title: 'Take your notes with you', line: 'Export a note or a whole workspace as PDF.' },\n { id: 'members', date: 'Oct 15, 2026', title: 'Inviting people to a workspace', line: 'Invite by email and choose what each person can do.' },\n { id: 'plans', date: 'Oct 8, 2026', title: 'Choosing a plan', line: 'What each plan includes, and when to move up.' },\n { id: 'search', date: 'Oct 1, 2026', title: 'Finding an old message', line: 'Search reads messages, notes and files together.' },\n { id: 'channels', date: 'Sep 24, 2026', title: 'How channels work', line: 'Make a channel for each team or project.' },\n { id: 'billing', date: 'Sep 17, 2026', title: 'Where your invoices are', line: 'Download any invoice from the billing page.' },\n { id: 'dark-mode', date: 'Sep 10, 2026', title: 'Light, dark or follow the system', line: 'Pick a theme once and every page follows it.' },\n { id: 'shortcuts', date: 'Sep 3, 2026', title: 'Keyboard shortcuts worth learning', line: 'Five keys that save the most time.' },\n { id: 'welcome', date: 'Aug 27, 2026', title: 'Welcome to the Acme blog', line: 'What we will write about here.' },\n { id: 'roadmap', date: 'Aug 20, 2026', title: 'What we are building next', line: 'A short look at the next three months.' },\n { id: 'hello', date: 'Aug 13, 2026', title: 'Hello from the team', line: 'Who we are and why we started.' },\n];\n\nconst PAGE_SIZE = 12;\n\nexport default function BlogIndexCards() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(posts.length / PAGE_SIZE);\n const shown = posts.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Blog\" lede=\"Notes from the team on how Acme works and why.\" />\n <Grid columns={2}>\n {shown.map((post, i) => (\n <LinkCard\n key={post.id}\n href={`#${post.id}`}\n title={post.title}\n description={post.line}\n caption={post.date}\n image={{ src: cover(fills[((page - 1) * PAGE_SIZE + i) % fills.length]), alt: '' }}\n />\n ))}\n </Grid>\n {/* A real blog passes an address that works without script, such as '/blog?page=2'. The example keeps the page in its hash. */}\n <Pagination page={page} pageCount={pageCount} onPageChange={setPage} getHref={(p) => `#page-${p}`} aria-label=\"Blog pages\" />\n </Stack>\n </PageShell>\n );\n}\n",
1061
+ "uses": [
1062
+ "Grid",
1063
+ "LinkCard",
1064
+ "PageHeader",
1065
+ "PageShell",
1066
+ "Pagination",
1067
+ "Stack"
1068
+ ]
1069
+ }
1070
+ ]
1071
+ },
1072
+ {
1073
+ "id": "breakdown-list",
1074
+ "title": "Breakdown of a total",
1075
+ "kind": "design",
1076
+ "level": "organism",
1077
+ "area": "dashboard",
1078
+ "situation": "A page shows how a total splits into parts, such as responses by model or comments by project.",
1079
+ "do": [
1080
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1081
+ "Say the total and its range above the list: '1,240 responses this week.'",
1082
+ "Sort by the main number, largest first, in both options.",
1083
+ "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`.",
1084
+ "Show the largest seven parts and fold the rest into 'Other', so the list is never longer than eight rows.",
1085
+ "Give the table's `TableContainer` an `aria-label` and a `minWidth`, mark the sorted column with `sort`, and right-align the numbers.",
1086
+ "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'.",
1087
+ "End the table with a Total row."
1088
+ ],
1089
+ "dont": [
1090
+ "Do not use a donut or a stacked bar. Color carries nothing here, so no legend is needed.",
1091
+ "Do not give each part its own color.",
1092
+ "Do not show a part with no name, or a share with no count.",
1093
+ "Do not list more than eight bars. Use the table.",
1094
+ "Do not show a share of 0 for a part that has data. A small share reads '< 1%'."
1095
+ ],
1096
+ "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`.",
1097
+ "options": [
1098
+ {
1099
+ "id": "bars",
1100
+ "title": "Ranked bars",
1101
+ "useWhen": "There are up to about eight parts of one total, and the person reads them in order.",
1102
+ "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",
1103
+ "uses": [
1104
+ "Center",
1105
+ "Heading",
1106
+ "List",
1107
+ "Paragraph",
1108
+ "Progress",
1109
+ "Stack",
1110
+ "formatCount"
1111
+ ]
1112
+ },
1113
+ {
1114
+ "id": "table",
1115
+ "title": "Table with a share column",
1116
+ "useWhen": "There are more parts, or the parts are compared on two numbers, such as responses and cost.",
1117
+ "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",
1118
+ "uses": [
1119
+ "Center",
1120
+ "Heading",
1121
+ "Paragraph",
1122
+ "Stack",
1123
+ "TableCell",
1124
+ "TableContainer",
1125
+ "TableHeader",
1126
+ "TableHeaderCell",
1127
+ "TableRow",
1128
+ "formatCount",
1129
+ "formatMoney",
1130
+ "formatPercent"
1131
+ ]
1132
+ }
1133
+ ]
1134
+ },
1135
+ {
1136
+ "id": "changelog",
1137
+ "title": "Changelog",
1138
+ "kind": "design",
1139
+ "level": "page",
1140
+ "area": "content",
1141
+ "situation": "A visitor or a customer wants to know what changed in the product lately, and may be sent to one change from a message.",
1142
+ "do": [
1143
+ "Use `PageHeader` with `level={1}`: the title 'Changelog' is the one level 1 heading, with a `lede` that says the order.",
1144
+ "Put the newest entry first.",
1145
+ "Make each entry a level 2 `Heading` with an `id` of its own. A link to `/changelog#pin-a-message` goes straight to it. `PageShell` gives it a scroll margin under a header only when it has an `aside`, as `one-page` does.",
1146
+ "Put the entry's kind and its date under its heading: a `Tag` ('New' in success, 'Improved' in info, 'Fixed' in the default color) and the date as 'Nov 12, 2026'. Both are plain text a screen reader reads.",
1147
+ "List what changed in a `List` with `marker=\"dot\"`, one change to a line, in words a customer uses.",
1148
+ "Put `OnThisPage` in the `aside` of `PageShell` for `one-page`, with the entries' titles, so a long log has a list of entries beside it.",
1149
+ "Show one month in `by-month`, and use `Pagination` with `getHref`, one page for each month, so the month is in the address (`'/changelog?month=2026-10'`). Name it 'Months', and say the month in the `lede`: 'October 2026, newest first.'",
1150
+ "Make Next go to the older month in `by-month`, as it does on the blog, so a person reads back in time."
1151
+ ],
1152
+ "dont": [
1153
+ "Do not leave an entry without a date. A person needs to know how old a change is.",
1154
+ "Do not write an entry as a post. It is a title and a list of changes, and a link to the full post when there is one.",
1155
+ "Do not use an `Accordion` for the entries. A person looks for a change with find in page.",
1156
+ "Do not name a kind that is a feeling, such as 'Exciting'. Use New, Improved or Fixed.",
1157
+ "Do not move the month by script only. The address must change, so a month can be shared and the Back button works.",
1158
+ "Do not add an infinite scroll. It hides the footer and the older months."
1159
+ ],
1160
+ "native": "On Apple show the log in a `List` with a section for each month. On Android use a `LazyColumn` with sticky month headers.",
1161
+ "options": [
1162
+ {
1163
+ "id": "one-page",
1164
+ "title": "All entries on one page",
1165
+ "useWhen": "A few entries a month, so the whole log is a page or two long.",
1166
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\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 Tag from 'oneslash-design-system/components/tag';\nimport List from 'oneslash-design-system/components/list';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Kind = 'New' | 'Improved' | 'Fixed';\n\n// Made-up entries, newest first. Each has an id, so a link can go straight to it.\n// The prefix keeps ids unique where several examples share a page. A real site uses the slug: '/changelog#pin-a-message'.\nconst entries: { id: string; date: string; kind: Kind; title: string; changes: string[] }[] = [\n {\n id: 'changelog-pin-a-message',\n date: 'Nov 12, 2026',\n kind: 'New',\n title: 'Pin a message to a channel',\n changes: ['Pin any message from its menu. Pins show at the top of the channel.', 'A channel holds up to 10 pins. Unpin one to add another.'],\n },\n {\n id: 'changelog-faster-notes',\n date: 'Nov 5, 2026',\n kind: 'Improved',\n title: 'Notes open faster',\n changes: ['A long note shows its first screen at once and loads the rest as you scroll.', 'Search results open on the line that matched.'],\n },\n {\n id: 'changelog-export-fix',\n date: 'Oct 29, 2026',\n kind: 'Fixed',\n title: 'Export keeps the order of a note',\n changes: ['A PDF export no longer puts a list after the text that followed it.', 'An export with a table no longer cuts off the last column.'],\n },\n {\n id: 'changelog-agent-sources',\n date: 'Oct 22, 2026',\n kind: 'New',\n title: 'The agent names its sources',\n changes: ['Every answer lists the notes and messages it used.', 'Open a source from the list to see it in place.'],\n },\n {\n id: 'changelog-invite-fix',\n date: 'Oct 15, 2026',\n kind: 'Fixed',\n title: 'Invitations to a second address',\n changes: ['An invitation sent to an address with a plus sign now arrives.'],\n },\n];\n\nconst kindColor = { New: 'success', Improved: 'info', Fixed: 'default' } as const;\n\nconst items = entries.map(({ id, title }) => ({ id, label: title }));\n\nexport default function ChangelogOnePage() {\n return (\n <PageShell aside={<OnThisPage items={items} aria-label=\"Entries\" />}>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Changelog\" lede=\"What changed in Acme, newest first.\" />\n <Stack gap=\"giant\">\n {entries.map((entry) => (\n <Stack key={entry.id} gap=\"large\">\n <Heading level={2} size=\"h5\" id={entry.id}>{entry.title}</Heading>\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color={kindColor[entry.kind]} label={entry.kind} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{entry.date}</Paragraph>\n </Cluster>\n <List marker=\"dot\" size=\"body1\" items={entry.changes} />\n </Stack>\n ))}\n </Stack>\n </Stack>\n </PageShell>\n );\n}\n",
1167
+ "uses": [
1168
+ "Cluster",
1169
+ "Heading",
1170
+ "List",
1171
+ "OnThisPage",
1172
+ "PageHeader",
1173
+ "PageShell",
1174
+ "Paragraph",
1175
+ "Stack",
1176
+ "Tag"
1177
+ ]
1178
+ },
1179
+ {
1180
+ "id": "by-month",
1181
+ "title": "One month at a time",
1182
+ "useWhen": "Many entries, so a page of the whole log would be long and slow.",
1183
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\nimport List from 'oneslash-design-system/components/list';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Kind = 'New' | 'Improved' | 'Fixed';\n\n// Made-up entries, newest month first. A real site loads the month named in the address.\n// The prefix keeps ids unique where several examples share a page. A real site uses the slug: '/changelog#pin-a-message'.\nconst months: { key: string; label: string; entries: { id: string; date: string; kind: Kind; title: string; changes: string[] }[] }[] = [\n {\n key: '2026-11',\n label: 'November 2026',\n entries: [\n { id: 'changelog-by-month-pin-a-message', date: 'Nov 12, 2026', kind: 'New', title: 'Pin a message to a channel', changes: ['Pin any message from its menu. Pins show at the top of the channel.'] },\n { id: 'changelog-by-month-faster-notes', date: 'Nov 5, 2026', kind: 'Improved', title: 'Notes open faster', changes: ['A long note shows its first screen at once.', 'Search results open on the line that matched.'] },\n ],\n },\n {\n key: '2026-10',\n label: 'October 2026',\n entries: [\n { id: 'changelog-by-month-export-fix', date: 'Oct 29, 2026', kind: 'Fixed', title: 'Export keeps the order of a note', changes: ['A PDF export no longer puts a list after the text that followed it.'] },\n { id: 'changelog-by-month-agent-sources', date: 'Oct 22, 2026', kind: 'New', title: 'The agent names its sources', changes: ['Every answer lists the notes and messages it used.'] },\n { id: 'changelog-by-month-invite-fix', date: 'Oct 15, 2026', kind: 'Fixed', title: 'Invitations to a second address', changes: ['An invitation sent to an address with a plus sign now arrives.'] },\n ],\n },\n {\n key: '2026-09',\n label: 'September 2026',\n entries: [\n { id: 'changelog-by-month-dark-theme', date: 'Sep 17, 2026', kind: 'New', title: 'A dark theme', changes: ['Choose light, dark or the system setting in your profile.'] },\n { id: 'changelog-by-month-channel-order', date: 'Sep 3, 2026', kind: 'Fixed', title: 'Channels keep their order', changes: ['The sidebar no longer re-sorts a channel you moved.'] },\n ],\n },\n {\n key: '2026-08',\n label: 'August 2026',\n entries: [\n { id: 'changelog-by-month-billing-page', date: 'Aug 20, 2026', kind: 'New', title: 'A billing page', changes: ['See your plan, your usage and your invoices in one place.'] },\n ],\n },\n];\n\nconst kindColor = { New: 'success', Improved: 'info', Fixed: 'default' } as const;\n\nexport default function ChangelogByMonth() {\n // Page 1 is the newest month. Next goes back in time.\n const [page, setPage] = useState(1);\n const month = months[page - 1] ?? months[0];\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Changelog\" lede={`${month.label}, newest first.`} />\n <Stack gap=\"giant\">\n {month.entries.map((entry) => (\n <Stack key={entry.id} gap=\"large\">\n <Heading level={2} size=\"h5\" id={entry.id}>{entry.title}</Heading>\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color={kindColor[entry.kind]} label={entry.kind} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{entry.date}</Paragraph>\n </Cluster>\n <List marker=\"dot\" size=\"body1\" items={entry.changes} />\n </Stack>\n ))}\n </Stack>\n {/* A real site passes an address that works without script, such as '/changelog?month=2026-10'. The example keeps the month in its hash. */}\n <Pagination page={page} pageCount={months.length} onPageChange={setPage} getHref={(p) => `#month-${months[p - 1].key}`} aria-label=\"Months\" />\n </Stack>\n </PageShell>\n );\n}\n",
1184
+ "uses": [
1185
+ "Cluster",
1186
+ "Heading",
1187
+ "List",
1188
+ "PageHeader",
1189
+ "PageShell",
1190
+ "Pagination",
1191
+ "Paragraph",
1192
+ "Stack",
1193
+ "Tag"
1194
+ ]
1195
+ }
1196
+ ]
1197
+ },
820
1198
  {
821
1199
  "id": "check-your-email",
822
1200
  "title": "Check your email",
@@ -873,6 +1251,60 @@
873
1251
  }
874
1252
  ]
875
1253
  },
1254
+ {
1255
+ "id": "code-sample",
1256
+ "title": "Code sample",
1257
+ "kind": "design",
1258
+ "level": "organism",
1259
+ "area": "content",
1260
+ "situation": "A page shows code that a person reads, or copies to run.",
1261
+ "do": [
1262
+ "Use `CodeBlock` for `block`, with a `label` that names what the code is, such as 'ask.ts' or 'Set up the client'. The label names the block, its scroll region and its Copy Button.",
1263
+ "Pass `language` as words for the reader ('TypeScript'). It does not color the code.",
1264
+ "Write the `code` as it will be copied, with its line breaks. Keep a block to about twenty lines; split a longer one under headings.",
1265
+ "Let a long line scroll inside the block. The block is a region that a keyboard can focus and scroll with the arrow keys; the page never scrolls sideways.",
1266
+ "Use `wrap` only for a short block of prose, such as a prompt, where every word should stay in view. Code keeps its lines and scrolls.",
1267
+ "Use `CopyField` for `command`, with `mono` and the `label` 'Install command'. A person sees the whole line and copies it with one Button.",
1268
+ "Say 'Copied' only after the clipboard took the text. `CodeBlock` and `CopyField` do this, and show a line to copy by hand when the browser refuses.",
1269
+ "Make each step of a task a `NumberedRow` with its title when the steps have code, and put its `CodeBlock` or `CopyField` under it. The order is clear and every command copies on its own."
1270
+ ],
1271
+ "dont": [
1272
+ "Do not put code in a `Paragraph` or a bare `pre`. It has no name, no Copy Button and no scroll region.",
1273
+ "Do not put a prompt `$` before a command people copy. It is pasted too.",
1274
+ "Do not use `CodeBlock` for one line. Use `CopyField`.",
1275
+ "Do not set the label to a sentence. Name the thing, as a file name or a task does.",
1276
+ "Do not show a screenshot of code. It cannot be copied, searched or read aloud."
1277
+ ],
1278
+ "native": "On Apple show code in a `Text` with a monospaced font in a horizontal `ScrollView`, and a `Button` that sets the pasteboard. On Android use a text block with a monospace font that scrolls sideways, and a button that copies.",
1279
+ "options": [
1280
+ {
1281
+ "id": "block",
1282
+ "title": "A block of code",
1283
+ "useWhen": "Several lines that a person reads or copies.",
1284
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport CodeBlock from 'oneslash-design-system/components/codeBlock';\nimport { PageSection } from 'oneslash-design-system/components/layout';\n\n// Made-up code for a made-up client. A real page shows code that runs.\nconst code = `import { createClient } from '@acme/sdk';\n\nconst acme = createClient({ workspace: 'design' });\n\nconst answer = await acme.agent.ask({\n channel: 'launch-plan',\n question: 'What is left before the launch?',\n});\n\nconsole.log(answer.text, answer.sources);`;\n\nexport default function CodeSampleBlock() {\n return (\n <PageShell>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"code-sample-block-intro\" name=\"Ask the agent\" statement=\"Make a client, then ask a question in a channel.\">\n <Paragraph tone=\"secondary\">The answer comes back with the notes and messages it used.</Paragraph>\n </SectionIntro>\n {/* The label names the block, its scroll region and its Copy Button. A long line scrolls inside the block, never the page. */}\n <CodeBlock id=\"code-sample-block\" label=\"ask.ts\" language=\"TypeScript\" code={code} />\n </PageSection>\n </PageShell>\n );\n}\n",
1285
+ "uses": [
1286
+ "CodeBlock",
1287
+ "PageSection",
1288
+ "PageShell",
1289
+ "Paragraph",
1290
+ "SectionIntro"
1291
+ ]
1292
+ },
1293
+ {
1294
+ "id": "command",
1295
+ "title": "A command to paste",
1296
+ "useWhen": "One line to paste in a terminal.",
1297
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport { PageSection } from 'oneslash-design-system/components/layout';\n\nexport default function CodeSampleCommand() {\n return (\n <PageShell>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"code-sample-command-intro\" name=\"Install\" statement=\"Add the client to your project.\">\n <Paragraph tone=\"secondary\">Run this in the folder of your project.</Paragraph>\n </SectionIntro>\n {/* One line to paste. The field shows it whole, the Button copies it, and 'Copied' shows only once the clipboard took it. */}\n <CopyField id=\"code-sample-command\" label=\"Install command\" value=\"npm install @acme/sdk\" mono />\n </PageSection>\n </PageShell>\n );\n}\n",
1298
+ "uses": [
1299
+ "CopyField",
1300
+ "PageSection",
1301
+ "PageShell",
1302
+ "Paragraph",
1303
+ "SectionIntro"
1304
+ ]
1305
+ }
1306
+ ]
1307
+ },
876
1308
  {
877
1309
  "id": "collapsible-search",
878
1310
  "title": "Collapsible search",
@@ -929,7 +1361,7 @@
929
1361
  "kind": "design",
930
1362
  "level": "organism",
931
1363
  "area": "chat",
932
- "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its agent replies for the month.",
1364
+ "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its AI agent responses for the month.",
933
1365
  "do": [
934
1366
  "Follow the rule 'An agent refuses clearly' word for word: \"You've used all 50 AI agent responses this month.\"",
935
1367
  "Put the notice in the Composer's `above` slot: `<Alert variant=\"inline\" autoDismiss={false}>`, with no close button on the Alert itself.",
@@ -937,7 +1369,7 @@
937
1369
  "Give everyone 'Not Now', a tertiary Button, so the refusal can be closed. Put the Buttons in a `Cluster` under the Alert.",
938
1370
  "Give a person who can lift the limit the action after 'Not Now', as a primary Button, such as 'Upgrade to Pro'.",
939
1371
  "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.",
940
- "Say in the placeholder when agent replies start again, once the person chose 'Not Now'.",
1372
+ "Say in the placeholder when AI agent responses start again, once the person chose 'Not Now'.",
941
1373
  "Move focus to the message box after 'Not Now', since the Button that had it is gone.",
942
1374
  "Keep the field and send working, so messages to people still go.",
943
1375
  "Follow the case 'Upgrade prompt' for a limit reached anywhere outside the message box."
@@ -955,7 +1387,7 @@
955
1387
  "id": "notice",
956
1388
  "title": "Notice",
957
1389
  "useWhen": "The person cannot lift the limit.",
958
- "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",
1390
+ "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",
959
1391
  "uses": [
960
1392
  "Alert",
961
1393
  "Button",
@@ -976,7 +1408,7 @@
976
1408
  "id": "notice-with-action",
977
1409
  "title": "Notice with an action",
978
1410
  "useWhen": "The person can lift the limit.",
979
- "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",
1411
+ "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",
980
1412
  "uses": [
981
1413
  "Alert",
982
1414
  "Button",
@@ -1087,6 +1519,64 @@
1087
1519
  ],
1088
1520
  "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm."
1089
1521
  },
1522
+ {
1523
+ "id": "contact-page",
1524
+ "title": "Contact page",
1525
+ "kind": "design",
1526
+ "level": "page",
1527
+ "area": "content",
1528
+ "situation": "A visitor wants to reach the person behind a site.",
1529
+ "do": [
1530
+ "Use a `Form` for `form`, with Name, Email and Message, and follow the rules 'A form error shows next to the problem' and 'Success shows where the person is looking'.",
1531
+ "Show a problem with one field under that field. Say what to do: 'Enter an email address, like name@example.com.'",
1532
+ "Keep the label 'Send' while sending, and make the Button `loading`. Disable the fields.",
1533
+ "Show success in an inline success `Alert` with `autoDismiss={false}`: 'Message sent. I reply within two days.' Clear it on the next edit, and clear the fields.",
1534
+ "Say how long a reply takes, in the lede or in the confirmation.",
1535
+ "Add a spam-trap input named `website` in your own code, hidden from sight and from screen readers, with `tabIndex={-1}` and `autoComplete=\"off\"`. The server drops a message that fills it. ODS has no hidden field, so the example leaves it out. Never show it as a visible `TextField`.",
1536
+ "Show a failed send above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`: 'Could not send your message. Try again.' Keep what the visitor typed.",
1537
+ "Give the address in `links` as a `Link` with `mailto:` and as a `CopyField`, so a visitor with no mail app can copy it.",
1538
+ "Use one address only: 'hello@acme.example'."
1539
+ ],
1540
+ "dont": [
1541
+ "Do not change the Send label to Sending while it runs.",
1542
+ "Do not clear what the visitor typed after a failed send.",
1543
+ "Do not open the mail app from a Button with `window.open`. Use a link with `mailto:`.",
1544
+ "Do not close the confirmation on a timer. It stays until the next edit.",
1545
+ "Do not show both options on one page. Pick one."
1546
+ ],
1547
+ "native": "On Apple a message form is a grouped `Form` with a Send button in the toolbar. For an address only, use a `Link` with a `mailto:` address.",
1548
+ "options": [
1549
+ {
1550
+ "id": "form",
1551
+ "title": "A message form",
1552
+ "useWhen": "A visitor writes a message here, and the person reads and answers it.",
1553
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\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 ContactPageForm() {\n const [name, setName] = useState('');\n const [email, setEmail] = useState('');\n const [message, setMessage] = useState('');\n const [errors, setErrors] = useState({ name: '', email: '', message: '' });\n const [sent, setSent] = useState(false);\n const [sending, setSending] = 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 // Any edit clears the confirmation and the problem with that field.\n function edit(field: 'name' | 'email' | 'message', set: (value: string) => void, value: string) {\n set(value);\n setSent(false);\n setErrors((current) => ({ ...current, [field]: '' }));\n }\n\n function handleSubmit() {\n if (sending) return;\n setSent(false);\n const next = {\n name: name.trim() ? '' : 'Enter your name.',\n email: !email.trim() ? 'Enter your email.' : looksLikeEmail(email.trim()) ? '' : 'Enter an email address, like name@example.com.',\n message: message.trim() ? '' : 'Write a message.',\n };\n setErrors(next);\n if (next.name || next.email || next.message) return;\n setSending(true);\n // A real page also has a hidden spam-trap input named `website`, in its own code. ODS has no hidden field, so the example leaves it out.\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSending(false);\n setSent(true);\n setName('');\n setEmail('');\n setMessage('');\n }, 1200);\n }\n\n return (\n <PageShell>\n <Stack gap=\"xxlarge\">\n <PageHeader level={1} title=\"Contact\" lede=\"I read every message and reply within two days.\" />\n <Form aria-label=\"Contact\" onSubmit={handleSubmit}>\n {/* The confirmation stays until the next edit, so it has no close button and does not close on its own. */}\n {sent && <Alert type=\"success\" variant=\"inline\" message=\"Message sent. I reply within two days.\" autoDismiss={false} />}\n <TextField id=\"contact-page-name\" label=\"Name\" autoComplete=\"name\" value={name} disabled={sending} error={Boolean(errors.name)} errorText={errors.name} onChange={(e) => edit('name', setName, e.target.value)} />\n <TextField id=\"contact-page-email\" label=\"Email\" type=\"email\" autoComplete=\"email\" value={email} disabled={sending} error={Boolean(errors.email)} errorText={errors.email} onChange={(e) => edit('email', setEmail, e.target.value)} />\n <Textarea id=\"contact-page-message\" label=\"Message\" maxRows={8} value={message} disabled={sending} error={Boolean(errors.message)} errorText={errors.message} onChange={(e) => edit('message', setMessage, e.target.value)} />\n <Stack align=\"start\">\n <Button size=\"large\" type=\"primary\" state=\"enabled\" label=\"Send\" htmlType=\"submit\" loading={sending} />\n </Stack>\n </Form>\n </Stack>\n </PageShell>\n );\n}\n",
1554
+ "uses": [
1555
+ "Alert",
1556
+ "Button",
1557
+ "Form",
1558
+ "PageHeader",
1559
+ "PageShell",
1560
+ "Stack",
1561
+ "TextField",
1562
+ "Textarea"
1563
+ ]
1564
+ },
1565
+ {
1566
+ "id": "links",
1567
+ "title": "An address only",
1568
+ "useWhen": "There is no inbox to read. The page gives an address and nothing else.",
1569
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Link from 'oneslash-design-system/components/link';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function ContactPageLinks() {\n return (\n <PageShell>\n <Stack gap=\"xxlarge\">\n <PageHeader level={1} title=\"Contact\" lede=\"Write to me at this address. I reply within two days.\" />\n <Stack gap=\"large\">\n {/* A mailto link opens the visitor's own mail app. */}\n <Link href=\"mailto:hello@acme.example\">hello@acme.example</Link>\n {/* For a visitor with no mail app: copy the address. */}\n <CopyField id=\"contact-page-address\" label=\"Email address\" value=\"hello@acme.example\" />\n </Stack>\n </Stack>\n </PageShell>\n );\n}\n",
1570
+ "uses": [
1571
+ "CopyField",
1572
+ "Link",
1573
+ "PageHeader",
1574
+ "PageShell",
1575
+ "Stack"
1576
+ ]
1577
+ }
1578
+ ]
1579
+ },
1090
1580
  {
1091
1581
  "id": "conversation-starters",
1092
1582
  "title": "Conversation starters",
@@ -1282,15 +1772,210 @@
1282
1772
  ]
1283
1773
  },
1284
1774
  {
1285
- "id": "device-login",
1286
- "title": "Device login",
1775
+ "id": "dashboard",
1776
+ "title": "Dashboard",
1287
1777
  "kind": "design",
1288
1778
  "level": "page",
1289
- "area": "auth",
1290
- "situation": "A CLI, an editor or another app opened the browser so the person can log in, and the login must reach that app.",
1779
+ "area": "dashboard",
1780
+ "situation": "A page that opens an app and says how things are going and what waits on the person.",
1291
1781
  "do": [
1292
- "Say in one line what the login connects: 'This connects Acme CLI on your computer to your account.'",
1293
- "Put the providers on top, then a `Line` with `label=\"or\"`, then email and password, as on the 'Login page' with providers first.",
1782
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1783
+ "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.",
1784
+ "Let the one range drive every number on the page, and name it in every heading and caption: 'this week'.",
1785
+ "Show the stat row as the case 'Stat row' says, and a share of a total as the case 'Breakdown of a total' says.",
1786
+ "Make each section a `SettingsSection`: a hairline, a title and its content. Do not put a section in a box.",
1787
+ "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.",
1788
+ "Show a list that can be longer than its section as the case 'Short list on a dashboard' says.",
1789
+ "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.",
1790
+ "Show a failed section as the case 'Load failure' says, inline with 'Try Again', and keep the rest of the page.",
1791
+ "Show a `Skeleton` or the tile's own loading state while the range changes. Do not show 0."
1792
+ ],
1793
+ "dont": [
1794
+ "Do not draw a chart. A trend is the change line on a tile, and a share is a ranked list.",
1795
+ "Do not count different sections over different ranges.",
1796
+ "Do not replace the whole page when one section failed.",
1797
+ "Do not put more than four tiles in the stat row.",
1798
+ "Do not hide a section that has nothing, or leave it blank.",
1799
+ "Do not box the sections in cards."
1800
+ ],
1801
+ "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.",
1802
+ "options": [
1803
+ {
1804
+ "id": "numbers-first",
1805
+ "title": "Numbers first",
1806
+ "useWhen": "The page reports how things went, for a lead who checks on a team.",
1807
+ "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",
1808
+ "uses": [
1809
+ "Alert",
1810
+ "AppShell",
1811
+ "Button",
1812
+ "Cluster",
1813
+ "EmptyBox",
1814
+ "Grid",
1815
+ "List",
1816
+ "MenuItem",
1817
+ "Navigation",
1818
+ "Paragraph",
1819
+ "Progress",
1820
+ "SegmentedControl",
1821
+ "SettingsSection",
1822
+ "Skeleton",
1823
+ "Stack",
1824
+ "StatTile",
1825
+ "TitleBar",
1826
+ "formatCount"
1827
+ ]
1828
+ },
1829
+ {
1830
+ "id": "work-first",
1831
+ "title": "Work first",
1832
+ "useWhen": "The person starts their day here, so what waits on them comes before the numbers.",
1833
+ "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",
1834
+ "uses": [
1835
+ "Alert",
1836
+ "AppShell",
1837
+ "Button",
1838
+ "Cluster",
1839
+ "EmptyBox",
1840
+ "Grid",
1841
+ "List",
1842
+ "MenuItem",
1843
+ "Navigation",
1844
+ "Paragraph",
1845
+ "Progress",
1846
+ "SegmentedControl",
1847
+ "SettingsSection",
1848
+ "Skeleton",
1849
+ "Stack",
1850
+ "StatTile",
1851
+ "TitleBar",
1852
+ "formatCount"
1853
+ ]
1854
+ }
1855
+ ]
1856
+ },
1857
+ {
1858
+ "id": "data-table-page",
1859
+ "title": "Data table page",
1860
+ "kind": "design",
1861
+ "level": "page",
1862
+ "area": "dashboard",
1863
+ "situation": "A page is one long table of records, such as invoices or customers, that a person searches, sorts and acts on.",
1864
+ "do": [
1865
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1866
+ "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'.",
1867
+ "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.",
1868
+ "Say what search and filter leave in the line under the title: '43 of 290 invoices match \"north\", past due.'",
1869
+ "Wait a moment after the last key before you ask the server for a search.",
1870
+ "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'.",
1871
+ "Right-align a number column and its header, and show the exact amount: '$1,240.00'.",
1872
+ "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.",
1873
+ "Show the status as the case 'Status in a row' says.",
1874
+ "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.",
1875
+ "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.",
1876
+ "Pass ``getHref={(p) => '/invoices?page=' + p}`` when each page has its own address.",
1877
+ "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.",
1878
+ "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.",
1879
+ "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.'",
1880
+ "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.",
1881
+ "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.",
1882
+ "Reach the page from a card's 'See All' link, as the case 'Short list on a dashboard' says."
1883
+ ],
1884
+ "dont": [
1885
+ "Do not replace the page with a spinner while a page loads. Keep the header and the pager.",
1886
+ "Do not show 0 for a total that is loading or failed.",
1887
+ "Do not show page 4 of the old list after a new sort or filter. Go back to page 1.",
1888
+ "Do not show 'No results' with no words, or the list's own empty text when a search found nothing.",
1889
+ "Do not put a Button for every action in each row. Use one More menu.",
1890
+ "Do not leave a table that can scroll sideways without a name.",
1891
+ "Do not put `sort` on more than one header cell.",
1892
+ "Do not number the pages as a row of buttons. A phone has no room, and 500 pages have no end.",
1893
+ "Do not page a list of under 50 rows."
1894
+ ],
1895
+ "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.",
1896
+ "options": [
1897
+ {
1898
+ "id": "paged",
1899
+ "title": "Pages from the server",
1900
+ "useWhen": "There are more rows than fit on a page, they come from the server, and the page holds 25 of them.",
1901
+ "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",
1902
+ "uses": [
1903
+ "Button",
1904
+ "Center",
1905
+ "Cluster",
1906
+ "EmptyBox",
1907
+ "IconButton",
1908
+ "Line",
1909
+ "Menu",
1910
+ "MenuItem",
1911
+ "Pagination",
1912
+ "Paragraph",
1913
+ "Popover",
1914
+ "Skeleton",
1915
+ "Stack",
1916
+ "Surface",
1917
+ "TableCell",
1918
+ "TableContainer",
1919
+ "TableHeader",
1920
+ "TableHeaderCell",
1921
+ "TableRow",
1922
+ "Tag",
1923
+ "TextField",
1924
+ "TitleBar",
1925
+ "Toaster",
1926
+ "Tooltip",
1927
+ "dismissToast",
1928
+ "formatCount",
1929
+ "formatMoney",
1930
+ "toast"
1931
+ ]
1932
+ },
1933
+ {
1934
+ "id": "all-rows",
1935
+ "title": "All rows, sorted in place",
1936
+ "useWhen": "There are under about 50 rows, so the page holds them all and sorts and filters them at once.",
1937
+ "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",
1938
+ "uses": [
1939
+ "Button",
1940
+ "Center",
1941
+ "Cluster",
1942
+ "EmptyBox",
1943
+ "IconButton",
1944
+ "Line",
1945
+ "Menu",
1946
+ "MenuItem",
1947
+ "Paragraph",
1948
+ "Popover",
1949
+ "Stack",
1950
+ "Surface",
1951
+ "TableCell",
1952
+ "TableContainer",
1953
+ "TableHeader",
1954
+ "TableHeaderCell",
1955
+ "TableRow",
1956
+ "Tag",
1957
+ "TextField",
1958
+ "TitleBar",
1959
+ "Toaster",
1960
+ "Tooltip",
1961
+ "dismissToast",
1962
+ "formatCount",
1963
+ "formatMoney",
1964
+ "toast"
1965
+ ]
1966
+ }
1967
+ ]
1968
+ },
1969
+ {
1970
+ "id": "device-login",
1971
+ "title": "Device login",
1972
+ "kind": "design",
1973
+ "level": "page",
1974
+ "area": "auth",
1975
+ "situation": "A CLI, an editor or another app opened the browser so the person can log in, and the login must reach that app.",
1976
+ "do": [
1977
+ "Say in one line what the login connects: 'This connects Acme CLI on your computer to your account.'",
1978
+ "Put the providers on top, then a `Line` with `label=\"or\"`, then email and password, as on the 'Login page' with providers first.",
1294
1979
  "Wait for the device to answer before showing success, with `LoadingScreen` and `label=\"Waiting for Acme CLI…\"`.",
1295
1980
  "End on \"You're logged in\" and 'You can close this tab.' once the device has answered.",
1296
1981
  "Go back to the form with an inline error Alert when the device does not answer, and say what to check.",
@@ -1336,6 +2021,62 @@
1336
2021
  }
1337
2022
  ]
1338
2023
  },
2024
+ {
2025
+ "id": "docs-component-page",
2026
+ "title": "Docs component page",
2027
+ "kind": "design",
2028
+ "level": "page",
2029
+ "area": "content",
2030
+ "situation": "A person opens the page of one part of a design system or a code library to see what it looks like, how to write it and what it takes.",
2031
+ "do": [
2032
+ "Use `PageHeader` with `level={1}`: the part's name is the one level 1 heading, with an `eyebrow` for its group and a `lede` of one sentence that says what it is for.",
2033
+ "Show the part live first, in a `Surface` with `align=\"center\"`, so a person sees it before reading about it.",
2034
+ "Put the code of that same example in a `CodeBlock` with a `label` such as 'Tag example', so the Copy Button and the scroll region have a name.",
2035
+ "Switch between the example and its code with `TabsContainer`, `Tab` and `TabPanel`: give each `Tab` an `id` and `controls`, and keep both panels in the page.",
2036
+ "Show the props in a `TableContainer` with an `aria-label` such as 'Tag props' and a `minWidth`, with the columns Prop, Type, Default and Description. A wide table then scrolls inside its own region.",
2037
+ "Write 'None, required' in Default for a prop that has no default, so an empty cell never means two things.",
2038
+ "Show Do and Don't as two lists side by side in a `Grid columns={2}`, each under a level 3 `Heading`. Start each Don't with \"Do not\".",
2039
+ "Put `OnThisPage` in the `aside` of `PageShell`, as the case 'On this page' says, with an `id` on each `SectionIntro`."
2040
+ ],
2041
+ "dont": [
2042
+ "Do not draw the example from a picture. A person must be able to click and tab it.",
2043
+ "Do not mount only the selected view. Keep both panels in the page with `TabPanel`, so the code is in the server HTML before scripts run.",
2044
+ "Do not let a wide props table scroll the page. Name the table so it scrolls inside its region.",
2045
+ "Do not leave a Default cell empty or write a dash.",
2046
+ "Do not copy the look or the wording of another documentation site. Use the parts and the words of this one."
2047
+ ],
2048
+ "native": "On Apple use a `List` with a `NavigationLink` to a detail view of the part, its preview on top. On Android use a detail screen under a top app bar, with the code in a text block that scrolls.",
2049
+ "options": [
2050
+ {
2051
+ "id": "reference",
2052
+ "title": "A page that documents one part",
2053
+ "useWhen": "Each part of a library has a page with an example, its code and its props.",
2054
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport OnThisPage from 'oneslash-design-system/components/onThisPage';\nimport Surface from 'oneslash-design-system/components/surface';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport TabPanel from 'oneslash-design-system/components/tabPanel';\nimport CodeBlock from 'oneslash-design-system/components/codeBlock';\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 Tag from 'oneslash-design-system/components/tag';\nimport Heading from 'oneslash-design-system/components/heading';\nimport List from 'oneslash-design-system/components/list';\nimport { Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// One part, documented. A real site builds the props and the code from the part's own source.\nconst sections = [\n { id: 'docs-component-page-example', label: 'Example' },\n { id: 'docs-component-page-props', label: 'Props' },\n { id: 'docs-component-page-use', label: 'When to use it' },\n];\n\nconst code = `<Tag\n variant=\"contained\"\n size=\"medium\"\n color=\"success\"\n label=\"Paid\"\n/>`;\n\n// Prop, Type, Default, Description\nconst props = [\n { name: 'variant', type: \"'contained' | 'textOnly' | 'dot'\", initial: 'None, required', text: 'How it is drawn: a filled pill, text only, or a dot before the text.' },\n { name: 'size', type: \"'medium' | 'small' | 'tiny'\", initial: 'None, required', text: 'How large it is set.' },\n { name: 'state', type: \"'enabled' | 'selected'\", initial: \"'enabled'\", text: 'Selected draws the tag as chosen, such as an active filter.' },\n { name: 'label', type: 'ReactNode', initial: 'None, required', text: 'The words in the tag.' },\n];\n\nexport default function DocsComponentPageReference() {\n const [view, setView] = useState<'example' | 'code'>('example');\n return (\n <PageShell aside={<OnThisPage items={sections} />}>\n <Stack gap=\"giant\">\n <PageHeader\n level={1}\n eyebrow=\"Components\"\n title=\"Tag\"\n lede=\"A short label that says what state something is in, such as Paid or Draft.\"\n />\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"docs-component-page-example\" name=\"Example\" />\n <Stack gap=\"large\">\n {/* The tabs only switch what is shown. Both panels are in the server HTML. */}\n <TabsContainer aria-label=\"Example views\">\n <Tab id=\"docs-component-page-tab-example\" controls=\"docs-component-page-panel-example\" size=\"small\" label=\"Example\" isSelected={view === 'example'} onClickTab={() => setView('example')} />\n <Tab id=\"docs-component-page-tab-code\" controls=\"docs-component-page-panel-code\" size=\"small\" label=\"Code\" isSelected={view === 'code'} onClickTab={() => setView('code')} />\n </TabsContainer>\n <TabPanel id=\"docs-component-page-panel-example\" labelledBy=\"docs-component-page-tab-example\" selected={view === 'example'}>\n <Surface align=\"center\" minHeight=\"short\">\n <Tag variant=\"contained\" size=\"medium\" color=\"success\" label=\"Paid\" />\n </Surface>\n </TabPanel>\n <TabPanel id=\"docs-component-page-panel-code\" labelledBy=\"docs-component-page-tab-code\" selected={view === 'code'}>\n <CodeBlock id=\"docs-component-page-code\" label=\"Tag example\" language=\"TypeScript\" code={code} />\n </TabPanel>\n </Stack>\n </PageSection>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"docs-component-page-props\" name=\"Props\" />\n {/* The name says which part's props these are. A wide table scrolls inside this region, not the page. */}\n <TableContainer aria-label=\"Tag props\" minWidth=\"720px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"120px\">Prop</TableHeaderCell>\n <TableHeaderCell width=\"260px\">Type</TableHeaderCell>\n <TableHeaderCell width=\"140px\">Default</TableHeaderCell>\n <TableHeaderCell>Description</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {props.map((p) => (\n <TableRow key={p.name}>\n <TableCell width=\"120px\">{p.name}</TableCell>\n <TableCell width=\"260px\">{p.type}</TableCell>\n <TableCell width=\"140px\">{p.initial}</TableCell>\n <TableCell>{p.text}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </PageSection>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"docs-component-page-use\" name=\"When to use it\" />\n <Grid columns={2} gap=\"xxlarge\">\n <Stack gap=\"medium\">\n <Heading level={3} size=\"h6\">Do</Heading>\n <List marker=\"dot\" items={['Say the state in the words, and use the color to back it up.', 'Keep a tag to one or two words.']} />\n </Stack>\n <Stack gap=\"medium\">\n <Heading level={3} size=\"h6\">Don't</Heading>\n <List marker=\"dot\" items={['Do not use a tag as a button. Use a Button.', 'Do not rely on the color alone to say the state.']} />\n </Stack>\n </Grid>\n </PageSection>\n </Stack>\n </PageShell>\n );\n}\n",
2055
+ "uses": [
2056
+ "CodeBlock",
2057
+ "Grid",
2058
+ "Heading",
2059
+ "List",
2060
+ "OnThisPage",
2061
+ "PageHeader",
2062
+ "PageSection",
2063
+ "PageShell",
2064
+ "SectionIntro",
2065
+ "Stack",
2066
+ "Surface",
2067
+ "Tab",
2068
+ "TabPanel",
2069
+ "TableCell",
2070
+ "TableContainer",
2071
+ "TableHeader",
2072
+ "TableHeaderCell",
2073
+ "TableRow",
2074
+ "TabsContainer",
2075
+ "Tag"
2076
+ ]
2077
+ }
2078
+ ]
2079
+ },
1339
2080
  {
1340
2081
  "id": "email-confirmed",
1341
2082
  "title": "Email confirmed",
@@ -1596,6 +2337,117 @@
1596
2337
  }
1597
2338
  ]
1598
2339
  },
2340
+ {
2341
+ "id": "faq",
2342
+ "title": "FAQ",
2343
+ "kind": "design",
2344
+ "level": "organism",
2345
+ "area": "marketing",
2346
+ "situation": "A marketing page answers the questions a visitor asks before signing up.",
2347
+ "do": [
2348
+ "Put the section's name in `SectionIntro`, so the section has a level 2 heading. Write each question as the visitor would ask it, in sentence case, ending in a question mark.",
2349
+ "Use `Accordion` for `accordion`, with the questions as the titles and `headingLevel={3}`, one level below the section's heading.",
2350
+ "Add `linkable` to the Accordion, so a link such as `#faq-refunds` opens that item and scrolls it under the `SiteHeader`, also on a page that only renders in the browser.",
2351
+ "Keep `multiple` on, its default, so a visitor can keep two answers open to compare. Use `multiple={false}` only when two open answers push the next question off the screen.",
2352
+ "Make each question a level 3 `Heading` for `open-list`, with its answer in a `Paragraph` under it.",
2353
+ "Write each answer as a `Paragraph` of one or two sentences. Name the one next step when there is one, such as the address to write to.",
2354
+ "Put a question that most visitors have first, and one that few have last."
2355
+ ],
2356
+ "dont": [
2357
+ "Do not build the open and close by hand. `Accordion` does the heading, the Button, `aria-expanded` and the keys.",
2358
+ "Do not use `<details>`, which has no heading and no deep link.",
2359
+ "Do not hide up to five short answers behind a click. Show them.",
2360
+ "Do not put a Button or a form inside an answer. An answer is for reading.",
2361
+ "Do not write answers that sound like a sales page."
2362
+ ],
2363
+ "native": "On Apple use a `List` of `DisclosureGroup` rows. On Android use a list with an expandable row. A short list is plain text under a heading.",
2364
+ "options": [
2365
+ {
2366
+ "id": "accordion",
2367
+ "title": "Questions that open",
2368
+ "useWhen": "There are more than about five questions, or the answers are long, and a visitor reads only some of them.",
2369
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Accordion from 'oneslash-design-system/components/accordion';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { PageSection } from 'oneslash-design-system/components/layout';\n\n// Made-up questions about Acme. A real site writes the ones its visitors ask.\nconst questions = [\n { id: 'members', title: 'Who can join a workspace?', content: 'Anyone you invite by email. A workspace on Free holds 3 members. Pro and Business have no limit.' },\n { id: 'yearly', title: 'Is there a yearly price?', content: 'Not yet. Every plan bills monthly, per member on Pro and Business.' },\n { id: 'responses', title: 'When do agent responses start again?', content: \"Each answer the agent posts uses one of the plan's responses. They start again on the 1st of each month.\" },\n { id: 'refunds', title: 'Can I get a refund?', content: 'Yes, within 30 days of a payment. Write to help@acme.example and say which workspace it was for.' },\n { id: 'export', title: 'Can I take my notes with me?', content: 'Yes. Export a note or a whole workspace as PDF on Pro and Business. On Free, copy the text of any note.' },\n { id: 'cancel', title: 'What happens when I cancel?', content: 'The workspace stays on its plan until the end of the period you paid for, then moves to Free. Nothing is deleted.' },\n { id: 'storage', title: 'What happens when storage is full?', content: 'You can still read everything. New files wait until you remove some or move to a plan with more room.' },\n];\n\nexport default function FaqAccordion() {\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"faq\" name=\"Common questions\" statement=\"What people ask before they sign up.\" />\n {/* The section's heading is an h2, so each question is an h3. `linkable` opens the item named by #faq-refunds and scrolls it under the header. */}\n <Accordion\n id=\"faq\"\n headingLevel={3}\n linkable\n items={questions.map((q) => ({ id: q.id, title: q.title, content: <Paragraph tone=\"secondary\" measure=\"none\">{q.content}</Paragraph> }))}\n />\n </PageSection>\n </PageShell>\n );\n}\n",
2370
+ "uses": [
2371
+ "Accordion",
2372
+ "PageSection",
2373
+ "PageShell",
2374
+ "Paragraph",
2375
+ "SectionIntro"
2376
+ ]
2377
+ },
2378
+ {
2379
+ "id": "open-list",
2380
+ "title": "Questions with their answers showing",
2381
+ "useWhen": "There are up to five short answers that everyone should read.",
2382
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// Four short answers that everyone should read, so none is hidden.\nconst questions = [\n { id: 'free', question: 'Is there a free plan?', answer: 'Yes. Free holds 3 members and needs no card.' },\n { id: 'members', question: 'Who can join a workspace?', answer: 'Anyone you invite by email.' },\n { id: 'refunds', question: 'Can I get a refund?', answer: 'Yes, within 30 days of a payment. Write to help@acme.example.' },\n { id: 'cancel', question: 'What happens when I cancel?', answer: 'The workspace moves to Free at the end of the period you paid for. Nothing is deleted.' },\n];\n\nexport default function FaqOpenList() {\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"faq-open-list\" name=\"Common questions\" statement=\"What people ask before they sign up.\" />\n <Stack gap=\"xlarge\">\n {questions.map((q) => (\n <Stack key={q.id} gap=\"small\">\n {/* The section's heading is an h2, so each question is an h3 and its answer is read in order. */}\n <Heading level={3} size=\"h6\">{q.question}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">{q.answer}</Paragraph>\n </Stack>\n ))}\n </Stack>\n </PageSection>\n </PageShell>\n );\n}\n",
2383
+ "uses": [
2384
+ "Heading",
2385
+ "PageSection",
2386
+ "PageShell",
2387
+ "Paragraph",
2388
+ "SectionIntro",
2389
+ "Stack"
2390
+ ]
2391
+ }
2392
+ ]
2393
+ },
2394
+ {
2395
+ "id": "feature-grid",
2396
+ "title": "Feature grid",
2397
+ "kind": "design",
2398
+ "level": "organism",
2399
+ "area": "marketing",
2400
+ "situation": "A marketing page lists what the product does, so a visitor can see if it fits.",
2401
+ "do": [
2402
+ "Follow the rule 'A marketing page asks for one main action, in the same words everywhere'. A feature section does not add its own action. The page's one Button stays in the header, the hero and the end.",
2403
+ "Open the section with `SectionIntro`: a name and one statement. Its name is the h2.",
2404
+ "Use `Grid columns={3}` of `Surface` for `cards`, each with an `Icon`, a level 3 `Heading` and one line in a `Paragraph`.",
2405
+ "Use `NumberedRow` with `visual` for `rows`. The picture is beside the words from the 2xl breakpoint, swaps sides each row, and sits under the words below it. Give the picture alt text that says what is in it.",
2406
+ "Keep to six cards or fewer, and four rows or fewer. A longer list is a page of its own.",
2407
+ "Make a card a link only when it goes somewhere. Then use `LinkCard`, and the card itself is one link."
2408
+ ],
2409
+ "dont": [
2410
+ "Do not put a Button in every card.",
2411
+ "Do not make a card look like a link when it is not one.",
2412
+ "Do not fill the grid with logos of other products.",
2413
+ "Do not mix cards and rows in one section."
2414
+ ],
2415
+ "native": "On Apple use a `List` of `Label`s, or a `TabView` of pages for a first-run tour. On Android use a list with leading icons.",
2416
+ "options": [
2417
+ {
2418
+ "id": "cards",
2419
+ "title": "Cards of equal weight",
2420
+ "useWhen": "Three to six features count the same, and each one fits an icon, a name and one line.",
2421
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\nconst features = [\n { icon: 'MessagesSquare', title: 'Channels', line: 'A channel for each subject, open to the whole team.' },\n { icon: 'ListChecks', title: 'Task threads', line: 'Every task keeps its own replies.' },\n { icon: 'BookOpen', title: 'Notes', line: 'Notes and decisions the whole team can search.' },\n { icon: 'Bot', title: 'Agent answers', line: 'Ask a question and see where the answer came from.' },\n { icon: 'Paperclip', title: 'Files', line: 'Keep a file next to the talk about it.' },\n { icon: 'Search', title: 'Search', line: 'Find any message, task or file from one box.' },\n] as const;\n\nexport default function FeatureGridCards() {\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"features\" name=\"Features\" statement=\"Everything your team needs to stay on the same page.\" />\n {/* Three across from md, one on a phone. Nothing here is a link, so nothing looks like one. */}\n <Grid columns={3}>\n {features.map((f) => (\n <Surface key={f.title} padding=\"medium\">\n <Stack gap=\"medium\">\n <Icon name={f.icon} size=\"medium\" color=\"secondary\" />\n <Heading level={3} size=\"h6\">{f.title}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{f.line}</Paragraph>\n </Stack>\n </Surface>\n ))}\n </Grid>\n </PageSection>\n </PageShell>\n );\n}\n",
2422
+ "uses": [
2423
+ "Grid",
2424
+ "Heading",
2425
+ "Icon",
2426
+ "PageSection",
2427
+ "PageShell",
2428
+ "Paragraph",
2429
+ "SectionIntro",
2430
+ "Stack",
2431
+ "Surface"
2432
+ ]
2433
+ },
2434
+ {
2435
+ "id": "rows",
2436
+ "title": "Rows with a picture",
2437
+ "useWhen": "Two to four features each need a picture to be understood.",
2438
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport NumberedRow from 'oneslash-design-system/components/numberedRow';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Image from 'oneslash-design-system/components/image';\nimport { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// Stand-ins for pictures of the product. A real page passes screenshots.\nconst channels =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 320'%3E%3Crect width='480' height='320' fill='%23eef2f6'/%3E%3Crect x='30' y='30' width='120' height='260' rx='10' fill='%23dfe7ef'/%3E%3Crect x='170' y='40' width='200' height='36' rx='10' fill='%23ffffff'/%3E%3Crect x='230' y='96' width='220' height='36' rx='10' fill='%232f6b4f'/%3E%3Crect x='170' y='152' width='180' height='36' rx='10' fill='%23ffffff'/%3E%3Crect x='170' y='250' width='280' height='36' rx='10' fill='%23ffffff'/%3E%3C/svg%3E\";\nconst knowledge =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 320'%3E%3Crect width='480' height='320' fill='%23efe9df'/%3E%3Crect x='40' y='40' width='400' height='40' rx='10' fill='%23ffffff'/%3E%3Crect x='40' y='100' width='190' height='170' rx='10' fill='%23ffffff'/%3E%3Crect x='250' y='100' width='190' height='80' rx='10' fill='%23dfe7ef'/%3E%3Crect x='250' y='190' width='190' height='80' rx='10' fill='%23dfe7ef'/%3E%3C/svg%3E\";\nconst agent =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 480 320'%3E%3Crect width='480' height='320' fill='%23e6efe9'/%3E%3Crect x='40' y='40' width='260' height='40' rx='10' fill='%23ffffff'/%3E%3Crect x='180' y='100' width='260' height='60' rx='10' fill='%232f6b4f'/%3E%3Crect x='40' y='180' width='300' height='60' rx='10' fill='%23ffffff'/%3E%3Crect x='40' y='256' width='200' height='30' rx='10' fill='%23dfe7ef'/%3E%3C/svg%3E\";\n\nexport default function FeatureGridRows() {\n return (\n <PageShell wide>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"features\" name=\"Features\" statement=\"Three things Acme does for your team.\" />\n {/* Each row is a number, a title, a few words and a picture. The picture is beside the words from 2xl and swaps sides each row, and under them below that. */}\n <Stack gap=\"giant\">\n <NumberedRow\n index={0}\n title=\"Channels and threads\"\n proof=\"One place for talk and for tasks.\"\n visual={<Image src={channels} alt=\"A channel with three messages and a list of channels beside it\" width={480} height={320} />}\n >\n <Paragraph tone=\"secondary\" measure=\"none\">Talk in channels. Turn any message into a task with its own thread.</Paragraph>\n </NumberedRow>\n <NumberedRow\n index={1}\n title=\"Notes the whole team can search\"\n proof=\"Search finds a decision, not only a message.\"\n visual={<Image src={knowledge} alt=\"A search box over a page of notes and two smaller notes\" width={480} height={320} />}\n >\n <Paragraph tone=\"secondary\" measure=\"none\">Write a note once. Everyone on the team finds it in the same place.</Paragraph>\n </NumberedRow>\n <NumberedRow\n index={2}\n title=\"Answers that show their source\"\n proof=\"Its answers say where they came from.\"\n visual={<Image src={agent} alt=\"The agent's reply to a question, with the message it used linked under it\" width={480} height={320} />}\n >\n <Paragraph tone=\"secondary\" measure=\"none\">Ask a question. The agent answers and links to the message it used.</Paragraph>\n </NumberedRow>\n </Stack>\n </PageSection>\n </PageShell>\n );\n}\n",
2439
+ "uses": [
2440
+ "Image",
2441
+ "NumberedRow",
2442
+ "PageSection",
2443
+ "PageShell",
2444
+ "Paragraph",
2445
+ "SectionIntro",
2446
+ "Stack"
2447
+ ]
2448
+ }
2449
+ ]
2450
+ },
1599
2451
  {
1600
2452
  "id": "feedback-form",
1601
2453
  "title": "Feedback form",
@@ -1802,6 +2654,65 @@
1802
2654
  "Do not change the submit Button's label while it is loading, such as to 'Saving…'."
1803
2655
  ]
1804
2656
  },
2657
+ {
2658
+ "id": "image-viewer",
2659
+ "title": "Image viewer",
2660
+ "kind": "design",
2661
+ "level": "organism",
2662
+ "area": "content",
2663
+ "situation": "A page shows images small, and a person wants to see one larger without leaving the page.",
2664
+ "do": [
2665
+ "Show each image as a `LightboxThumbnail` and keep the open state and the index of the shown image in your page. For `gallery`, put the thumbnails in a `Grid compact`, two across on a phone.",
2666
+ "Render one `Lightbox` for the page with the list of images, the `index`, `onIndexChange`, `isOpen` and `onClose`. Give it an `aria-label` that names the set, such as \"Pictures\".",
2667
+ "Write alt text that says what the image shows, such as \"A laptop on a wooden desk, its screen blue\". It names the thumbnail and stands in for an image that fails to load.",
2668
+ "Add a `caption` when the image needs words. The viewer shows it under the image and uses it as its title.",
2669
+ "Pass two or more images to get the arrows: the viewer shows 'Previous image', 'Next image' and '2 of 3' after the title. ArrowLeft, ArrowRight and a swipe step; the first and the last image stop there.",
2670
+ "Pass a single image in a list too, so the page keeps one way to open an image. The viewer then shows no arrows and no count.",
2671
+ "Let Escape, the backdrop and 'Close' close the viewer. Focus goes back to the thumbnail that opened it.",
2672
+ "Count on the viewer when an image fails to load: it shows 'This image could not be loaded.' with its alt text, and the arrows still work.",
2673
+ "Follow the case 'Attachments' for images that sit in a message."
2674
+ ],
2675
+ "dont": [
2676
+ "Do not open an image from a click on an `Image`. Use `LightboxThumbnail`, a button that a keyboard reaches.",
2677
+ "Do not leave the alt text empty on a thumbnail, or write \"image\" or a file name.",
2678
+ "Do not build a full-screen layer with a portal of your own. `Lightbox` is a dialog with a focus trap and the focus return.",
2679
+ "Do not handle Escape or the arrow keys with a listener of your own. The viewer does.",
2680
+ "Do not use the viewer for video, or for a page that has one image and nothing to see larger.",
2681
+ "Do not hide the arrows on a phone. A swipe is a second way to step, not the only one."
2682
+ ],
2683
+ "native": "On Apple use a `fullScreenCover` with a `TabView` in `page` style, and `accessibilityLabel` on each image. On Android use a full-screen dialog with a `HorizontalPager` and a content description on each image.",
2684
+ "options": [
2685
+ {
2686
+ "id": "gallery",
2687
+ "title": "Several images opened from thumbnails",
2688
+ "useWhen": "Two or more images that a person may want to step through.",
2689
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Lightbox, { LightboxThumbnail } from 'oneslash-design-system/components/lightbox';\nimport { Grid, PageSection } from 'oneslash-design-system/components/layout';\n\n// Three drawings stand in for the photos. A real page passes its own files.\nconst hillside =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E\";\nconst desk =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E\";\nconst board =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1280 720'%3E%3Crect width='1280' height='720' fill='%23eef2f6'/%3E%3Crect x='120' y='120' width='460' height='480' rx='24' fill='%23ffffff'/%3E%3Crect x='680' y='120' width='480' height='220' rx='24' fill='%23dfe7ef'/%3E%3Crect x='680' y='380' width='480' height='220' rx='24' fill='%232f6b4f'/%3E%3Crect x='160' y='170' width='240' height='20' rx='10' fill='%23aab8c6'/%3E%3Crect x='160' y='220' width='360' height='16' rx='8' fill='%23c2cfdb'/%3E%3Crect x='160' y='260' width='320' height='16' rx='8' fill='%23c2cfdb'/%3E%3C/svg%3E\";\n\nconst images = [\n { src: hillside, alt: 'A green hillside under a pale sky with the sun on the right', caption: 'The hill behind the new office.' },\n { src: desk, alt: 'A laptop on a wooden desk, its screen blue', caption: 'A desk set up for the first day.' },\n { src: board, alt: 'A thread beside a note, with the decision marked in green', caption: 'A decision, with the notes that led to it.' },\n];\n\nexport default function ImageViewerGallery() {\n const [open, setOpen] = useState(false);\n const [index, setIndex] = useState(0);\n return (\n <PageShell>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"image-viewer-gallery-intro\" name=\"Pictures\" statement=\"The office and a decision.\" />\n {/* Each thumbnail is a button named 'Open image: <alt>'. Closing the viewer gives focus back to the one that opened it. */}\n <Grid compact columns={3}>\n {images.map((image, i) => (\n <LightboxThumbnail\n key={image.alt}\n image={image}\n onOpen={() => {\n setIndex(i);\n setOpen(true);\n }}\n />\n ))}\n </Grid>\n </PageSection>\n <Lightbox images={images} index={index} onIndexChange={setIndex} isOpen={open} onClose={() => setOpen(false)} aria-label=\"Pictures\" />\n </PageShell>\n );\n}\n",
2690
+ "uses": [
2691
+ "Grid",
2692
+ "Lightbox",
2693
+ "LightboxThumbnail",
2694
+ "PageSection",
2695
+ "PageShell",
2696
+ "SectionIntro"
2697
+ ]
2698
+ },
2699
+ {
2700
+ "id": "single",
2701
+ "title": "One image opened larger",
2702
+ "useWhen": "One image whose detail is too small to read in the page.",
2703
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Lightbox, { LightboxThumbnail } from 'oneslash-design-system/components/lightbox';\nimport { Grid, PageSection } from 'oneslash-design-system/components/layout';\n\n// One drawing stands in for the photo. A real page passes its own file.\nconst board =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1280 720'%3E%3Crect width='1280' height='720' fill='%23eef2f6'/%3E%3Crect x='120' y='120' width='460' height='480' rx='24' fill='%23ffffff'/%3E%3Crect x='680' y='120' width='480' height='220' rx='24' fill='%23dfe7ef'/%3E%3Crect x='680' y='380' width='480' height='220' rx='24' fill='%232f6b4f'/%3E%3Crect x='160' y='170' width='240' height='20' rx='10' fill='%23aab8c6'/%3E%3Crect x='160' y='220' width='360' height='16' rx='8' fill='%23c2cfdb'/%3E%3Crect x='160' y='260' width='320' height='16' rx='8' fill='%23c2cfdb'/%3E%3C/svg%3E\";\n\nconst image = { src: board, alt: 'A thread beside a note, with the decision marked in green', caption: 'A decision, with the notes that led to it.' };\n\nexport default function ImageViewerSingle() {\n const [open, setOpen] = useState(false);\n return (\n <PageShell>\n <PageSection gap=\"xlarge\">\n <SectionIntro id=\"image-viewer-single-intro\" name=\"A decision\" statement=\"The thread and the note, side by side.\">\n <Paragraph tone=\"secondary\">Open the picture to read it at full size.</Paragraph>\n </SectionIntro>\n {/* One image: the viewer shows no arrows and no count. */}\n <Grid columns={2}>\n <LightboxThumbnail image={image} onOpen={() => setOpen(true)} />\n </Grid>\n </PageSection>\n <Lightbox images={[image]} index={0} onIndexChange={() => {}} isOpen={open} onClose={() => setOpen(false)} aria-label=\"Decision picture\" />\n </PageShell>\n );\n}\n",
2704
+ "uses": [
2705
+ "Grid",
2706
+ "Lightbox",
2707
+ "LightboxThumbnail",
2708
+ "PageSection",
2709
+ "PageShell",
2710
+ "Paragraph",
2711
+ "SectionIntro"
2712
+ ]
2713
+ }
2714
+ ]
2715
+ },
1805
2716
  {
1806
2717
  "id": "import-checklist",
1807
2718
  "title": "Import checklist",
@@ -2077,52 +2988,229 @@
2077
2988
  ]
2078
2989
  },
2079
2990
  {
2080
- "id": "load-failure",
2081
- "title": "Load failure",
2991
+ "id": "invoice-list",
2992
+ "title": "Invoices",
2082
2993
  "kind": "design",
2083
2994
  "level": "organism",
2084
- "area": "state",
2085
- "situation": "A list or a section could not load.",
2995
+ "area": "dashboard",
2996
+ "situation": "A billing page lists what the workspace has paid, so an admin can find an invoice, check an amount and keep a copy.",
2086
2997
  "do": [
2087
- "Say what could not load: 'Could not load projects'.",
2088
- "Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
2089
- "Show the list as soon as it loads.",
2090
- "Keep the rest of the page working when only one section failed.",
2091
- "Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
2998
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
2999
+ "Show a `TableContainer` named 'Invoices', with `minWidth`, and the columns Date, Description, Amount, Status and Download.",
3000
+ "Write the amount exactly, with `formatMoney`, in a right-aligned column with a right-aligned header: '$24.00'.",
3001
+ "Show the status as the case 'Status in a row' says: 'Paid' and 'Refunded' as `Tag variant=\"textOnly\"`, and 'Past due' as a dot.",
3002
+ "Show the newest first. Add `Pagination` named 'Invoice pages' past 12 invoices, and show none under that.",
3003
+ "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`.",
3004
+ "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.",
3005
+ "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.",
3006
+ "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.'",
3007
+ "Show 'No invoices yet' in an `EmptyBox`, with one line on when the first arrives: 'Your first invoice appears here after your first payment.'",
3008
+ "Show only an amount and a status. Keep a card number, an account number and the name of the payment provider off the page."
2092
3009
  ],
2093
3010
  "dont": [
2094
- "Do not show the empty text, such as 'No projects yet', when the list failed to load.",
2095
- "Do not show the error's own message, such as 'Failed to fetch'.",
2096
- "Do not replace the whole page when only one section failed."
2097
- ],
2098
- "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
3011
+ "Do not show the amount as '$24' or '24.00'. A table shows the exact amount, with its symbol and two decimals.",
3012
+ "Do not show a card number, even a part of it, in an invoice row.",
3013
+ "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.",
3014
+ "Do not name every Download link 'Download'. A screen reader lists the links apart from their rows.",
3015
+ "Do not use an icon-only link named by its icon. Every row would read the same.",
3016
+ "Do not hide the explanation behind a tooltip.",
3017
+ "Do not change the Button's label when the explanation opens. Do not write it in sentence case, 'Why is this higher?'."
3018
+ ],
3019
+ "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.",
2099
3020
  "options": [
2100
3021
  {
2101
- "id": "region",
2102
- "title": "Whole list failed",
2103
- "useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
2104
- "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",
3022
+ "id": "table",
3023
+ "title": "A table of past invoices",
3024
+ "useWhen": "A history of payments, the same amount each month or close to it.",
3025
+ "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",
2105
3026
  "uses": [
2106
3027
  "Button",
3028
+ "Center",
2107
3029
  "EmptyBox",
2108
3030
  "Heading",
2109
- "List",
3031
+ "Pagination",
2110
3032
  "Stack",
2111
- "Surface"
3033
+ "TableCell",
3034
+ "TableContainer",
3035
+ "TableHeader",
3036
+ "TableHeaderCell",
3037
+ "TableRow",
3038
+ "Tag",
3039
+ "formatMoney"
2112
3040
  ]
2113
3041
  },
2114
3042
  {
2115
- "id": "inline",
2116
- "title": "One section failed",
2117
- "useWhen": "One section failed to load and the rest of the page works.",
2118
- "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",
3043
+ "id": "with-upcoming",
3044
+ "title": "The next charge first",
3045
+ "useWhen": "The next charge is not the plan price, for example after a member joined mid-month, so it comes first and says why.",
3046
+ "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",
2119
3047
  "uses": [
2120
- "Alert",
2121
3048
  "Button",
2122
3049
  "Center",
2123
- "Cluster",
2124
3050
  "Heading",
2125
- "List",
3051
+ "Paragraph",
3052
+ "Stack",
3053
+ "TableCell",
3054
+ "TableContainer",
3055
+ "TableHeader",
3056
+ "TableHeaderCell",
3057
+ "TableRow",
3058
+ "Tag",
3059
+ "formatMoney"
3060
+ ]
3061
+ }
3062
+ ]
3063
+ },
3064
+ {
3065
+ "id": "landing-hero",
3066
+ "title": "Hero",
3067
+ "kind": "design",
3068
+ "level": "organism",
3069
+ "area": "marketing",
3070
+ "situation": "A marketing page opens by saying what the product is and asking for one thing.",
3071
+ "do": [
3072
+ "Follow the rule 'A marketing page asks for one main action, in the same words everywhere'.",
3073
+ "Use `PageHeader` with `level={1}`, an `eyebrow` that says what kind of product it is, a title and a lede. The page has one h1.",
3074
+ "Put the main action first, a primary `Button` labeled 'Sign Up', then one secondary action such as 'See How It Works'. Use `size=\"large\"`.",
3075
+ "Put a short line under the actions that removes a doubt: 'Start on Free with 3 members. No card needed.'",
3076
+ "Put the two actions in a `Cluster`. On a phone they sit side by side, and the second moves to its own line when they do not fit.",
3077
+ "Keep the words left aligned, also in `centered`. A centered block of text is hard to read past two lines.",
3078
+ "Let the title wrap. A long word breaks inside the column and nothing scrolls sideways.",
3079
+ "Name the picture for a screen reader: say what is in it. Use `Figure` with `crop`, so the picture keeps its shape at every width.",
3080
+ "Show the words first and the picture under them on a phone. `Grid columns={2}` stacks the two parts in the order you write them."
3081
+ ],
3082
+ "dont": [
3083
+ "Do not add a second primary Button to the hero, or a third action.",
3084
+ "Do not put a second h1 on the page.",
3085
+ "Do not move the title or swap its words with a timer.",
3086
+ "Do not hide the main action under the picture on a phone."
3087
+ ],
3088
+ "native": "On Apple and Android an app has no hero. The first screen is the product, or a short sign-in.",
3089
+ "options": [
3090
+ {
3091
+ "id": "centered",
3092
+ "title": "Words in one column",
3093
+ "useWhen": "The words carry the page: the product is easy to say and a picture would add little.",
3094
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function LandingHeroCentered() {\n return (\n <PageShell>\n <Stack gap=\"xxlarge\">\n {/* The only h1 on the page: level 1 is the default. */}\n <PageHeader\n level={1}\n eyebrow=\"Team workspace with an AI agent\"\n title=\"A shared workspace for your team and its agent\"\n lede=\"Plan the work in threads, keep notes the whole team can search, and ask the agent when you need an answer.\"\n />\n {/* The rule's one main action first, then one secondary. They wrap on a phone. */}\n <Stack gap=\"medium\">\n <Cluster>\n <Button size=\"large\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />\n <Button size=\"large\" type=\"secondary\" state=\"enabled\" label=\"See How It Works\" href=\"#how-it-works\" />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Start on Free with 3 members. No card needed.</Paragraph>\n </Stack>\n </Stack>\n </PageShell>\n );\n}\n",
3095
+ "uses": [
3096
+ "Button",
3097
+ "Cluster",
3098
+ "PageHeader",
3099
+ "PageShell",
3100
+ "Paragraph",
3101
+ "Stack"
3102
+ ]
3103
+ },
3104
+ {
3105
+ "id": "split",
3106
+ "title": "Words beside a picture",
3107
+ "useWhen": "A picture of the product explains it faster than words.",
3108
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\nimport { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// A stand-in for a picture of the product. A real page passes a screenshot.\nconst appPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 480'%3E%3Crect width='640' height='480' fill='%23eef2f6'/%3E%3Crect width='170' height='480' fill='%23dfe7ef'/%3E%3Crect x='20' y='28' width='90' height='12' rx='6' fill='%23aab8c6'/%3E%3Crect x='20' y='72' width='120' height='10' rx='5' fill='%23c2cfdb'/%3E%3Crect x='20' y='100' width='100' height='10' rx='5' fill='%23c2cfdb'/%3E%3Crect x='20' y='128' width='110' height='10' rx='5' fill='%23c2cfdb'/%3E%3Crect x='200' y='28' width='180' height='14' rx='7' fill='%23aab8c6'/%3E%3Crect x='200' y='80' width='300' height='44' rx='10' fill='%23ffffff'/%3E%3Crect x='260' y='148' width='340' height='44' rx='10' fill='%232f6b4f'/%3E%3Crect x='200' y='216' width='260' height='44' rx='10' fill='%23ffffff'/%3E%3Crect x='200' y='400' width='400' height='40' rx='10' fill='%23ffffff'/%3E%3C/svg%3E\";\n\nexport default function LandingHeroSplit() {\n return (\n <PageShell wide>\n {/* Two columns from md. On a phone the words come first and the picture sits under them. */}\n <Grid columns={2} gap=\"giant\">\n <Stack gap=\"xxlarge\">\n <PageHeader\n level={1}\n eyebrow=\"Team workspace with an AI agent\"\n title=\"A shared workspace for your team and its agent\"\n lede=\"Plan the work in threads, keep notes the whole team can search, and ask the agent when you need an answer.\"\n />\n <Stack gap=\"medium\">\n <Cluster>\n <Button size=\"large\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />\n <Button size=\"large\" type=\"secondary\" state=\"enabled\" label=\"See How It Works\" href=\"#how-it-works\" />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Start on Free with 3 members. No card needed.</Paragraph>\n </Stack>\n </Stack>\n <Figure crop={4 / 3}>\n <Image src={appPicture} alt=\"The Acme workspace: a list of channels beside a conversation with the agent\" width={640} height={480} />\n </Figure>\n </Grid>\n </PageShell>\n );\n}\n",
3109
+ "uses": [
3110
+ "Button",
3111
+ "Cluster",
3112
+ "Figure",
3113
+ "Grid",
3114
+ "Image",
3115
+ "PageHeader",
3116
+ "PageShell",
3117
+ "Paragraph",
3118
+ "Stack"
3119
+ ]
3120
+ }
3121
+ ]
3122
+ },
3123
+ {
3124
+ "id": "legal-page",
3125
+ "title": "Legal page",
3126
+ "kind": "design",
3127
+ "level": "page",
3128
+ "area": "content",
3129
+ "situation": "A person reads the terms or the privacy policy to find one answer in it, or reads all of it before they agree.",
3130
+ "do": [
3131
+ "Put an info `Alert` first with the words 'Sample text. This is not a real agreement.' on any page whose text is an example. Set `autoDismiss={false}`, so it stays. A real page has no such line and uses text written for the company.",
3132
+ "Use `PageHeader` with `level={1}`: one level 1 title, 'Terms of service', and `facts` with 'Last updated' 'Nov 16, 2026'. The date is the date of the text, not of the last deploy.",
3133
+ "Number the sections as level 2 headings: '1. Using Acme'. Give each an `id`, in the same order as the list beside the page.",
3134
+ "Put `OnThisPage` in the `aside` of `PageShell`, as the case 'On this page' says, with the same labels as the headings.",
3135
+ "Write paragraphs and `List`s at reading width, one idea to a paragraph. Use `marker=\"dot\"` for what a term covers and `marker=\"number\"` for steps in order.",
3136
+ "Name who the text is between, once, in the first section: 'Acme' and 'you'.",
3137
+ "End with a Contact section that names `help@acme.example` as the only address.",
3138
+ "Leave every section open. A person finds a word with find in page, and a closed panel hides what they look for."
3139
+ ],
3140
+ "dont": [
3141
+ "Do not put the sections in an accordion. Find in page does not search closed panels.",
3142
+ "Do not set each section in a card. A long text reads best in one column, with the headings doing the work.",
3143
+ "Do not copy the text of another company. A real page uses text a lawyer wrote for the company.",
3144
+ "Do not write a date without a year, or only \"recently updated\".",
3145
+ "Do not rely on the list of sections to make the page readable. It sits beside the page from the `xl` breakpoint, and a phone reads in order."
3146
+ ],
3147
+ "native": "On Apple open the text in an `SFSafariViewController`, so the address is the real one. On Android open it in a Custom Tab.",
3148
+ "options": [
3149
+ {
3150
+ "id": "sections",
3151
+ "title": "Numbered sections with a list beside them",
3152
+ "useWhen": "Terms or a privacy policy, which a person searches for one answer.",
3153
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport OnThisPage from 'oneslash-design-system/components/onThisPage';\nimport Alert from 'oneslash-design-system/components/alert';\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 { Stack } from 'oneslash-design-system/components/layout';\n\n// Generic sample text for a made-up service. A real page uses text written for the company.\nconst sections = [\n { id: 'legal-page-using', title: '1. Using Acme' },\n { id: 'legal-page-accounts', title: '2. Your account' },\n { id: 'legal-page-content', title: '3. Your content' },\n { id: 'legal-page-rules', title: '4. Rules of use' },\n { id: 'legal-page-ending', title: '5. Deleting your account' },\n { id: 'legal-page-contact', title: '6. Contact' },\n];\n\nconst items = sections.map(({ id, title }) => ({ id, label: title }));\n\nexport default function LegalPageSections() {\n return (\n <PageShell aside={<OnThisPage items={items} />}>\n <Stack gap=\"giant\">\n <Alert type=\"info\" variant=\"inline\" message=\"Sample text. This is not a real agreement.\" autoDismiss={false} />\n <PageHeader level={1} title=\"Terms of service\" facts={[{ label: 'Last updated', value: 'Nov 16, 2026' }]} />\n <Stack gap=\"xxlarge\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-using\">1. Using Acme</Heading>\n <Paragraph>These terms are between Acme and you. When you use the service, you agree to them. If you use it for a team, you say you may agree for that team.</Paragraph>\n <Paragraph>We may change the service and these terms. We tell you before a change that matters to you.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-accounts\">2. Your account</Heading>\n <Paragraph>You keep your login details to yourself and tell us when you think someone else knows them. You answer for what happens under your account.</Paragraph>\n <List marker=\"dot\" size=\"body1\" items={['Give true details when you sign up.', 'Use one account for yourself.', 'Tell us if you lose access.']} />\n </Stack>\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-content\">3. Your content</Heading>\n <Paragraph>What you write and upload stays yours. You let us store it and show it to the people you choose, so the service can work.</Paragraph>\n <Paragraph>You can export your content or delete it at any time. Deleted content leaves our systems within 30 days.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-rules\">4. Rules of use</Heading>\n <Paragraph>Use Acme only for lawful work, and treat other people with respect. Do not:</Paragraph>\n <List marker=\"dot\" size=\"body1\" items={['Break the law or ask others to.', 'Try to get into accounts that are not yours.', 'Send what harms the service or the people on it.']} />\n </Stack>\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-ending\">5. Deleting your account</Heading>\n <Paragraph>You can delete your account at any time from your settings. We may close it if you break these terms, and we tell you why when we do.</Paragraph>\n <List marker=\"number\" size=\"body1\" items={['Open Settings and choose Delete Account.', 'Confirm, and the account is deleted.', 'Export your content first if you want to keep it.']} />\n </Stack>\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\" id=\"legal-page-contact\">6. Contact</Heading>\n <Paragraph>Write to help@acme.example with any question about these terms.</Paragraph>\n </Stack>\n </Stack>\n </Stack>\n </PageShell>\n );\n}\n",
3154
+ "uses": [
3155
+ "Alert",
3156
+ "Heading",
3157
+ "List",
3158
+ "OnThisPage",
3159
+ "PageHeader",
3160
+ "PageShell",
3161
+ "Paragraph",
3162
+ "Stack"
3163
+ ]
3164
+ }
3165
+ ]
3166
+ },
3167
+ {
3168
+ "id": "load-failure",
3169
+ "title": "Load failure",
3170
+ "kind": "design",
3171
+ "level": "organism",
3172
+ "area": "state",
3173
+ "situation": "A list or a section could not load.",
3174
+ "do": [
3175
+ "Say what could not load: 'Could not load projects'.",
3176
+ "Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
3177
+ "Show the list as soon as it loads.",
3178
+ "Keep the rest of the page working when only one section failed.",
3179
+ "Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
3180
+ ],
3181
+ "dont": [
3182
+ "Do not show the empty text, such as 'No projects yet', when the list failed to load.",
3183
+ "Do not show the error's own message, such as 'Failed to fetch'.",
3184
+ "Do not replace the whole page when only one section failed."
3185
+ ],
3186
+ "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
3187
+ "options": [
3188
+ {
3189
+ "id": "region",
3190
+ "title": "Whole list failed",
3191
+ "useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
3192
+ "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",
3193
+ "uses": [
3194
+ "Button",
3195
+ "EmptyBox",
3196
+ "Heading",
3197
+ "List",
3198
+ "Stack",
3199
+ "Surface"
3200
+ ]
3201
+ },
3202
+ {
3203
+ "id": "inline",
3204
+ "title": "One section failed",
3205
+ "useWhen": "One section failed to load and the rest of the page works.",
3206
+ "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",
3207
+ "uses": [
3208
+ "Alert",
3209
+ "Button",
3210
+ "Center",
3211
+ "Cluster",
3212
+ "Heading",
3213
+ "List",
2126
3214
  "Paragraph",
2127
3215
  "Stack",
2128
3216
  "Surface"
@@ -2268,6 +3356,73 @@
2268
3356
  }
2269
3357
  ]
2270
3358
  },
3359
+ {
3360
+ "id": "long-form-page",
3361
+ "title": "Long-form page",
3362
+ "kind": "design",
3363
+ "level": "page",
3364
+ "area": "content",
3365
+ "situation": "A person reads one long piece, such as a post, a case study or a method, from the top down, and may come back to part of it.",
3366
+ "do": [
3367
+ "Use `PageHeader` with `level={1}`, a `title`, a `lede` of one or two sentences and `facts` for the date, the reading time and the author. The title is the one level 1 heading.",
3368
+ "Write the facts as 'Published' 'Nov 12, 2026', 'Reading time' '6 minutes' and 'Author' 'Dana Lee'. A number shows its unit, as the rule 'A number shows its unit and never shows 0 for unknown' says.",
3369
+ "Put one hero `Figure` after the header, with an `Image` that has alt text and a caption when it needs one.",
3370
+ "Make each section a `SectionIntro`, whose name is the level 2 heading and gets an id for a link. Put the body under it as `Paragraph`s at reading width.",
3371
+ "Show the decisions or steps of a case study as `NumberedRow`s, each with a short title and the reason beneath it.",
3372
+ "Put further reading in a `List` of `Link`s, each named for the page it goes to.",
3373
+ "End the page as the case 'Page end' says: one `LinkCard` that names the next page to read, with the caption 'Next: Task threads'.",
3374
+ "Put `OnThisPage` in the `aside` of `PageShell` for `with-contents`, as the case 'On this page' says. Give every `SectionIntro` an `id` and pass the same ids and names as the items.",
3375
+ "Make the page read in order without the list. Below the `xl` breakpoint the list is not shown, and a phone scrolls."
3376
+ ],
3377
+ "dont": [
3378
+ "Do not pick `with-contents` for a post of two to four sections that people read through. Pick `article`, and they find the sections by scrolling.",
3379
+ "Do not put the list of sections in the page as well as beside it.",
3380
+ "Do not set the text wider than reading width. Let the figure and the numbered rows use the column.",
3381
+ "Do not end the page on a sign-up banner. A reader who finished the page wants the next thing to read.",
3382
+ "Do not hide a section behind an accordion. A reader who is in the middle of the page needs to find a word with find in page.",
3383
+ "Do not use a second level 1 heading in a section."
3384
+ ],
3385
+ "native": "On Apple use a `ScrollView` with a large title, and a `Menu` of sections that scrolls to one. On Android use a `LazyColumn` under a collapsing top app bar.",
3386
+ "options": [
3387
+ {
3388
+ "id": "article",
3389
+ "title": "An article read top to bottom",
3390
+ "useWhen": "A post or a case study that most people read from the first line to the last.",
3391
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport NumberedRow from 'oneslash-design-system/components/numberedRow';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\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 LinkCard from 'oneslash-design-system/components/linkCard';\nimport { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// A stand-in for the hero picture. A real page passes its own.\nconst hero =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1280 720'%3E%3Crect width='1280' height='720' fill='%23eef2f6'/%3E%3Crect x='120' y='120' width='460' height='480' rx='24' fill='%23ffffff'/%3E%3Crect x='680' y='120' width='480' height='220' rx='24' fill='%23dfe7ef'/%3E%3Crect x='680' y='380' width='480' height='220' rx='24' fill='%232f6b4f'/%3E%3Crect x='160' y='170' width='240' height='20' rx='10' fill='%23aab8c6'/%3E%3Crect x='160' y='220' width='360' height='16' rx='8' fill='%23c2cfdb'/%3E%3Crect x='160' y='260' width='320' height='16' rx='8' fill='%23c2cfdb'/%3E%3C/svg%3E\";\n\nexport default function LongFormPageArticle() {\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader\n level={1}\n title=\"Why we keep decisions in threads\"\n lede=\"A decision made in a meeting is gone by Friday. We moved ours into the thread where the work happens, and this is what changed.\"\n facts={[\n { label: 'Published', value: 'Nov 12, 2026' },\n { label: 'Reading time', value: '6 minutes' },\n { label: 'Author', value: 'Dana Lee' },\n ]}\n />\n <Figure crop={16 / 9} caption=\"The thread for one decision, with the notes that led to it.\">\n <Image src={hero} alt=\"A thread beside a note, with the decision marked in green\" width={1280} height={720} />\n </Figure>\n <PageSection>\n <SectionIntro id=\"long-form-page-problem\" name=\"The problem\" statement=\"People remembered the decision. They did not remember why.\">\n <Paragraph>Every month someone asked why a screen worked the way it did. The answer was in a call that nobody wrote down.</Paragraph>\n <Paragraph>So the team spent the first ten minutes of each review arguing about a choice that was already made.</Paragraph>\n </SectionIntro>\n </PageSection>\n <PageSection>\n <SectionIntro id=\"long-form-page-decisions\" name=\"What we decided\" />\n <Stack gap=\"xlarge\">\n <NumberedRow index={0} title=\"A decision stays with the work it decides.\">\n <Paragraph>Anyone who opens the work sees the choice and the messages around it, so nobody has to ask.</Paragraph>\n </NumberedRow>\n <NumberedRow index={1} title=\"Each decision has one owner.\">\n <Paragraph>The owner writes it in a sentence and says what would change it. Ben Carter reviews it the same day.</Paragraph>\n </NumberedRow>\n <NumberedRow index={2} title=\"A decision can be reopened, with a reason.\" proof=\"The thread keeps both versions and the reason for the change.\">\n <Paragraph>Nothing is final for good. A new fact is a reason to look again, and the thread keeps both versions.</Paragraph>\n </NumberedRow>\n </Stack>\n </PageSection>\n <PageSection>\n <SectionIntro id=\"long-form-page-reading\" name=\"Further reading\" />\n <List\n size=\"body1\"\n items={[\n <Link key=\"a\" href=\"#how-channels-work\">How channels work</Link>,\n <Link key=\"b\" href=\"#writing-a-decision\">Writing a decision in one sentence</Link>,\n <Link key=\"c\" href=\"#reopening-a-decision\">Reopening a decision</Link>,\n ]}\n />\n </PageSection>\n {/* A reading page ends by pointing to the next page to read. */}\n <LinkCard href=\"#task-threads\" title=\"Task threads\" caption=\"Next: Task threads\" />\n </Stack>\n </PageShell>\n );\n}\n",
3392
+ "uses": [
3393
+ "Figure",
3394
+ "Image",
3395
+ "Link",
3396
+ "LinkCard",
3397
+ "List",
3398
+ "NumberedRow",
3399
+ "PageHeader",
3400
+ "PageSection",
3401
+ "PageShell",
3402
+ "Paragraph",
3403
+ "SectionIntro",
3404
+ "Stack"
3405
+ ]
3406
+ },
3407
+ {
3408
+ "id": "with-contents",
3409
+ "title": "With a list of sections beside it",
3410
+ "useWhen": "The page has five sections or more, and people jump between them or come back to one.",
3411
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport OnThisPage from 'oneslash-design-system/components/onThisPage';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// The same ids and names go to the sections and to the list. A real site builds both from one list.\nconst sections = [\n { id: 'long-form-page-start', name: 'Before you start', text: 'Pick one workspace for the trial. Invite two people who will use it every day, and keep the rest for later.' },\n { id: 'long-form-page-channels', name: 'Set up channels', text: 'Make a channel for each team or project. Name it for the subject, so a new member can tell where to write.' },\n { id: 'long-form-page-notes', name: 'Move your notes', text: 'Paste the notes you still use into a note. Leave old ones where they are until someone asks for them.' },\n { id: 'long-form-page-agent', name: 'Ask the agent', text: 'Ask a question in a channel. The agent answers from that workspace and names the notes it used.' },\n { id: 'long-form-page-review', name: 'Review after a week', text: 'Look at what the team used and what it left alone. Remove a channel that has had no message.' },\n];\n\nconst items = sections.map(({ id, name }) => ({ id, label: name }));\n\nconst filler = 'Write what you decide in the thread, in one sentence. Someone who opens the page next month should not need to ask you what happened.';\n\nexport default function LongFormPageWithContents() {\n return (\n <PageShell aside={<OnThisPage items={items} />}>\n <Stack gap=\"giant\">\n <PageHeader\n level={1}\n title=\"A first week with Acme\"\n lede=\"What to set up on day one, and what to leave until you need it.\"\n facts={[\n { label: 'Published', value: 'Nov 12, 2026' },\n { label: 'Reading time', value: '8 minutes' },\n { label: 'Author', value: 'Dana Lee' },\n ]}\n />\n {sections.map((s) => (\n <PageSection key={s.id}>\n <SectionIntro id={s.id} name={s.name}>\n <Paragraph>{s.text}</Paragraph>\n <Paragraph tone=\"secondary\">{filler}</Paragraph>\n {s.id === 'long-form-page-agent' && (\n <List marker=\"dot\" size=\"body1\" items={['Ask one question at a time.', 'Say which channel or note it is about.', 'Check the sources it names.']} />\n )}\n </SectionIntro>\n </PageSection>\n ))}\n <LinkCard href=\"#task-threads\" title=\"Task threads\" caption=\"Next: Task threads\" />\n </Stack>\n </PageShell>\n );\n}\n",
3412
+ "uses": [
3413
+ "LinkCard",
3414
+ "List",
3415
+ "OnThisPage",
3416
+ "PageHeader",
3417
+ "PageSection",
3418
+ "PageShell",
3419
+ "Paragraph",
3420
+ "SectionIntro",
3421
+ "Stack"
3422
+ ]
3423
+ }
3424
+ ]
3425
+ },
2271
3426
  {
2272
3427
  "id": "master-detail",
2273
3428
  "title": "List and detail",
@@ -2352,7 +3507,7 @@
2352
3507
  "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.",
2353
3508
  "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.",
2354
3509
  "Say how many seats are used under the title: '7 of 8 seats used on the Free plan.'",
2355
- "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.'",
3510
+ "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'.",
2356
3511
  "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."
2357
3512
  ],
2358
3513
  "dont": [
@@ -2370,7 +3525,7 @@
2370
3525
  "id": "rows",
2371
3526
  "title": "A list of rows",
2372
3527
  "useWhen": "A workspace of a few dozen people, so the whole list fits and a person finds someone by looking.",
2373
- "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",
3528
+ "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",
2374
3529
  "uses": [
2375
3530
  "Alert",
2376
3531
  "Button",
@@ -2390,6 +3545,7 @@
2390
3545
  "Toaster",
2391
3546
  "UserImage",
2392
3547
  "dismissToast",
3548
+ "formatMoney",
2393
3549
  "toast"
2394
3550
  ]
2395
3551
  },
@@ -2397,7 +3553,7 @@
2397
3553
  "id": "table",
2398
3554
  "title": "A table with sorting",
2399
3555
  "useWhen": "More people than a person can scan. The columns Name and Role sort.",
2400
- "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",
3556
+ "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",
2401
3557
  "uses": [
2402
3558
  "Alert",
2403
3559
  "Button",
@@ -2419,6 +3575,7 @@
2419
3575
  "Toaster",
2420
3576
  "UserImage",
2421
3577
  "dismissToast",
3578
+ "formatMoney",
2422
3579
  "toast"
2423
3580
  ]
2424
3581
  }
@@ -2516,7 +3673,7 @@
2516
3673
  "id": "hover-toolbar",
2517
3674
  "title": "Toolbar on the row",
2518
3675
  "useWhen": "A product used with a pointer, with three or four frequent actions.",
2519
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 Composer from 'oneslash-design-system/components/composer';\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; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsHoverToolbar() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [copiedId, setCopiedId] = useState<string | null>(null);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's buttons by row id, so focus can move to one when the thing that had it is gone.\n const reactButtons = useRef<Record<string, Focusable>>({});\n const editButtons = useRef<Record<string, Focusable>>({});\n const deleteButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(copyTimer.current);\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(id: string) {\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, reacted: !m.reacted } : m)));\n }\n\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n setCopiedId(m.id);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopiedId(null), 2000);\n }, () => {});\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's Edit button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => editButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(id: string) {\n setConfirmingId(id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Delete button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => deleteButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's first action, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? reactButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\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 {/* A real app mounts one Toaster near its root. */}\n <Toaster />\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) => {\n const own = m.from === me;\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n actions={\n editing || confirming ? undefined : (\n <>\n <Tooltip title=\"Add reaction\">\n <IconButton\n ref={(el) => { reactButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => react(m.id)}\n />\n </Tooltip>\n <Tooltip title={copiedId === m.id ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copiedId === m.id ? 'Check' : 'Copy'} ariaLabel={copiedId === m.id ? 'Copied' : `Copy message from ${m.from}`} onClick={() => copy(m)} />\n </Tooltip>\n {own && (\n <Tooltip title=\"Edit\">\n <IconButton ref={(el) => { editButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={() => startEditing(m)} />\n </Tooltip>\n )}\n {own && (\n <Tooltip title=\"Delete\">\n <IconButton ref={(el) => { deleteButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Trash2\" ariaLabel=\"Delete your message\" onClick={() => askToDelete(m.id)} />\n </Tooltip>\n )}\n </>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-hover-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-hover-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
3676
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 Composer from 'oneslash-design-system/components/composer';\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; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsHoverToolbar() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [copiedId, setCopiedId] = useState<string | null>(null);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's buttons by row id, so focus can move to one when the thing that had it is gone.\n const reactButtons = useRef<Record<string, Focusable>>({});\n const editButtons = useRef<Record<string, Focusable>>({});\n const deleteButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(copyTimer.current);\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(id: string) {\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, reacted: !m.reacted } : m)));\n }\n\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n setCopiedId(m.id);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopiedId(null), 2000);\n }, () => {});\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's Edit button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => editButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(id: string) {\n setConfirmingId(id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Delete button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => deleteButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's first action, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? reactButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\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 {/* A real app mounts one Toaster near its root. */}\n <Toaster />\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) => {\n const own = m.from === me;\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n actions={\n editing || confirming ? undefined : (\n <>\n <Tooltip title=\"Add reaction\">\n <IconButton\n ref={(el) => { reactButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => react(m.id)}\n />\n </Tooltip>\n <Tooltip title={copiedId === m.id ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copiedId === m.id ? 'Check' : 'Copy'} ariaLabel={copiedId === m.id ? 'Copied' : `Copy message from ${m.from}`} onClick={() => copy(m)} />\n </Tooltip>\n {own && (\n <Tooltip title=\"Edit\">\n <IconButton ref={(el) => { editButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={() => startEditing(m)} />\n </Tooltip>\n )}\n {own && (\n <Tooltip title=\"Delete\">\n <IconButton ref={(el) => { deleteButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Trash2\" ariaLabel=\"Delete your message\" onClick={() => askToDelete(m.id)} />\n </Tooltip>\n )}\n </>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-hover-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-hover-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
2520
3677
  "uses": [
2521
3678
  "Button",
2522
3679
  "Center",
@@ -2540,7 +3697,7 @@
2540
3697
  "id": "menu",
2541
3698
  "title": "More menu",
2542
3699
  "useWhen": "There are more than four actions, or the product is used on a touch screen.",
2543
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 Composer from 'oneslash-design-system/components/composer';\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 { 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; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsMenu() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Row | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(m: Row) {\n setThread((rows) => rows.map((r) => (r.id === m.id ? { ...r, reacted: !r.reacted } : r)));\n }\n\n // The menu closes when an item is chosen, so a copy shows a toast rather than a check.\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Message copied.' }));\n }, () => {});\n }\n\n // A real app sends the task to the server here.\n function createTask(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `Task created from ${m.from}'s message.` }));\n }\n\n // A real app asks for a reason in a Modal, then sends the report.\n function report(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `${m.from}'s message reported to the workspace admins.` }));\n }\n\n function openMenu(m: Row, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === m.id) {\n closeMenu();\n return;\n }\n setMenuRow(m);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Escape, a click outside and every item close the menu. Popover's returnFocus gives focus back to More.\n function closeMenu() {\n setMenuOpen(false);\n }\n\n function choose(action: (m: Row) => void) {\n if (!menuRow) return;\n const m = menuRow;\n closeMenu();\n action(m);\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's More button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(m: Row) {\n setConfirmingId(m.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's More button, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? moreButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\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 {/* A real app mounts one Toaster near its root. */}\n <Toaster />\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) => {\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // One More button. Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n // It stays on screen while its menu is open, though the pointer and focus are in the menu.\n actionsVisible={menuOpen && menuRow?.id === m.id}\n actions={\n editing || confirming ? undefined : (\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(m, e.currentTarget)}\n />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-menu-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-menu-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={closeMenu} returnFocus>\n <Menu navigable aria-label=\"Message actions\" width={200}>\n <MenuItem size=\"small\" iconName=\"SmilePlus\" label=\"Add Reaction\" onClick={() => choose(react)} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy\" onClick={() => choose(copy)} />\n {menuRow?.from === me && <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Edit\" onClick={() => choose(startEditing)} />}\n <MenuItem size=\"small\" iconName=\"ClipboardPlus\" label=\"Create Task\" onClick={() => choose(createTask)} />\n {menuRow?.from !== me && <MenuItem size=\"small\" iconName=\"Flag\" label=\"Report\" onClick={() => choose(report)} />}\n {menuRow?.from === me && <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
3700
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 Composer from 'oneslash-design-system/components/composer';\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 { 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; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsMenu() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Row | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(m: Row) {\n setThread((rows) => rows.map((r) => (r.id === m.id ? { ...r, reacted: !r.reacted } : r)));\n }\n\n // The menu closes when an item is chosen, so a copy shows a toast rather than a check.\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Message copied.' }));\n }, () => {});\n }\n\n // A real app sends the task to the server here.\n function createTask(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `Task created from ${m.from}'s message.` }));\n }\n\n // A real app asks for a reason in a Modal, then sends the report.\n function report(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `${m.from}'s message reported to the workspace admins.` }));\n }\n\n function openMenu(m: Row, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === m.id) {\n closeMenu();\n return;\n }\n setMenuRow(m);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Escape, a click outside and every item close the menu. Popover's returnFocus gives focus back to More.\n function closeMenu() {\n setMenuOpen(false);\n }\n\n function choose(action: (m: Row) => void) {\n if (!menuRow) return;\n const m = menuRow;\n closeMenu();\n action(m);\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's More button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(m: Row) {\n setConfirmingId(m.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's More button, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? moreButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\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 {/* A real app mounts one Toaster near its root. */}\n <Toaster />\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) => {\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // One More button. Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n // It stays on screen while its menu is open, though the pointer and focus are in the menu.\n actionsVisible={menuOpen && menuRow?.id === m.id}\n actions={\n editing || confirming ? undefined : (\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(m, e.currentTarget)}\n />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-menu-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-menu-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={closeMenu} returnFocus>\n <Menu navigable aria-label=\"Message actions\" width={200}>\n <MenuItem size=\"small\" iconName=\"SmilePlus\" label=\"Add Reaction\" onClick={() => choose(react)} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy\" onClick={() => choose(copy)} />\n {menuRow?.from === me && <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Edit\" onClick={() => choose(startEditing)} />}\n <MenuItem size=\"small\" iconName=\"ClipboardPlus\" label=\"Create Task\" onClick={() => choose(createTask)} />\n {menuRow?.from !== me && <MenuItem size=\"small\" iconName=\"Flag\" label=\"Report\" onClick={() => choose(report)} />}\n {menuRow?.from === me && <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
2544
3701
  "uses": [
2545
3702
  "Button",
2546
3703
  "Center",
@@ -2584,10 +3741,10 @@
2584
3741
  "Pass `canSubmit` so a message with files and no text can be sent.",
2585
3742
  "Keep the files and the text when a send fails. Show an inline error Alert above the message box, as the rule 'A form error shows next to the problem' says.",
2586
3743
  "Move focus to the next chip after a chip is removed, or to the message box when none is left, since the chip that had it is gone.",
2587
- "Show images in a sent message as thumbnails: a `Grid` of `<Figure crop>` with an `Image` each. Write `alt` text that says what the image shows.",
3744
+ "Show images in a sent message as thumbnails: a `Grid` of `LightboxThumbnail`s. Write `alt` text that says what the image shows.",
2588
3745
  "Show other files as `FileChip`s that open the file, with the kind ('PDF'), the name and the size.",
2589
- "Show a `FileChip` with the file's name in place of an image that fails to load, so the file can still be opened.",
2590
- "Let the person open an image at full size. The example shows the thumbnails only."
3746
+ "Keep each image's file reachable: when an image fails to load, the `Lightbox` shows 'This image could not be loaded.' with its alt text.",
3747
+ "Open an image at full size in a `Lightbox`: render one with the list of images, the `index`, `onIndexChange`, `isOpen` and `onClose`, as the case 'Image viewer' says. Closing it gives focus back to the thumbnail."
2591
3748
  ],
2592
3749
  "dont": [
2593
3750
  "Do not show a failed upload only in an Alert away from the file.",
@@ -2601,7 +3758,7 @@
2601
3758
  "id": "in-composer",
2602
3759
  "title": "In the composer",
2603
3760
  "useWhen": "Files are waiting to be sent with the next message.",
2604
- "source": "'use client';\nimport { useEffect, useRef, useState } from '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 FileChip from 'oneslash-design-system/components/fileChip';\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';\nconst MAX_FILES = 5;\n\ntype Upload = { id: string; name: string; kind: string; size: string; state: 'ready' | 'uploading' | 'failed'; error?: string };\ntype Row = { id: string; from: string; at: Date; text: string; files?: Upload[] };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Dana has the final versions.' },\n];\n\n// Opens with one file ready, one still uploading and one the server refused.\nconst firstFiles: Upload[] = [\n { id: 'f1', name: 'Launch brief.pdf', kind: 'PDF', size: '1.2 MB', state: 'ready' },\n { id: 'f2', name: 'Hero image.png', kind: 'PNG', size: '3.4 MB', state: 'uploading' },\n { id: 'f3', name: 'Product video.mov', kind: 'MOV', size: '48 MB', state: 'failed', error: 'Too large. The limit is 25 MB.' },\n];\n\n// What the attach button adds, in turn. A real app opens the file picker.\nconst sampleFiles = [\n { name: 'Press list.xlsx', kind: 'XLSX', size: '48 KB' },\n { name: 'Pricing sheet.pdf', kind: 'PDF', size: '320 KB' },\n { name: 'Logo.svg', kind: 'SVG', size: '12 KB' },\n];\n\n// Where a sent file opens. A real app links to the stored file.\nconst fileHref = (name: string) => `/files/${name.toLowerCase().replace(/\\s+/g, '-')}`;\n\n// The line that says why sending is blocked. The message box points at it with aria-describedby.\nconst blockedId = 'message-attachments-send-blocked';\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 MessageAttachmentsInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [files, setFiles] = useState(firstFiles);\n const added = useRef(0);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops every upload still running.\n useEffect(() => () => {\n timers.current.forEach((t) => clearTimeout(t));\n timers.current = [];\n }, []);\n\n const atLimit = files.length >= MAX_FILES;\n const uploading = files.some((f) => f.state === 'uploading');\n const failed = files.find((f) => f.state === 'failed');\n const blockedReason = failed ? `Remove ${failed.name} to send.` : uploading ? 'Wait for the upload to finish, then send.' : null;\n\n function attach() {\n if (atLimit) return;\n const sample = sampleFiles[added.current % sampleFiles.length];\n const id = `a${added.current + 1}`;\n added.current += 1;\n setFiles((list) => [...list, { ...sample, id, state: 'uploading' }]);\n // Stands in for the request to the server.\n timers.current.push(\n setTimeout(() => {\n setFiles((list) => list.map((f) => (f.id === id ? { ...f, state: 'ready' } : f)));\n }, 1200),\n );\n }\n\n // The chip that had focus is gone. A real app moves focus to the next chip, or to the message box when\n // none is left. FileChip does not pass a ref to its remove button, so this example always uses the message box.\n function remove(id: string) {\n setFiles((list) => list.filter((f) => f.id !== id));\n field.current?.focus();\n }\n\n // The Composer calls this only when canSubmit is true: no upload running, none failed.\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(), files }]);\n setText('');\n setFiles([]);\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 footer={\n m.files && m.files.length > 0 ? (\n <Cluster gap=\"small\">\n {m.files.map((f) => (\n // A sent file opens when its chip is pressed.\n <FileChip key={f.id} name={f.name} kind={f.kind} meta={f.size} href={fileHref(f.name)} openInNewTab />\n ))}\n </Cluster>\n ) : undefined\n }\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"message-attachments-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n aria-describedby={blockedReason ? blockedId : undefined}\n // Files alone can be sent, but not while one uploads or has failed.\n canSubmit={(text.trim() !== '' || files.length > 0) && !uploading && !failed}\n above={\n files.length > 0 ? (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {files.map((f) => (\n <FileChip\n key={f.id}\n name={f.name}\n kind={f.kind}\n state={f.state}\n meta={f.state === 'uploading' ? 'Uploading' : f.state === 'failed' ? f.error : f.size}\n onRemove={() => remove(f.id)}\n />\n ))}\n </Cluster>\n {/* A real app also says these in a polite live region when they change. */}\n {blockedReason && (\n <Paragraph id={blockedId} size=\"caption\" tone=\"secondary\" measure=\"none\">{blockedReason}</Paragraph>\n )}\n {atLimit && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`You can attach up to ${MAX_FILES} files.`}</Paragraph>\n )}\n </Stack>\n ) : undefined\n }\n tools={\n <Tooltip title=\"Attach files\">\n <IconButton\n color=\"iconOnly\"\n state={atLimit ? 'disabled' : 'enabled'}\n size=\"small\"\n iconName=\"Paperclip\"\n ariaLabel=\"Attach files\"\n onClick={attach}\n />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
3761
+ "source": "'use client';\nimport { useEffect, useRef, useState } from '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 FileChip from 'oneslash-design-system/components/fileChip';\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';\nconst MAX_FILES = 5;\n\ntype Upload = { id: string; name: string; kind: string; size: string; state: 'ready' | 'uploading' | 'failed'; error?: string };\ntype Row = { id: string; from: string; at: Date; text: string; files?: Upload[] };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2026-11-16T11:40:00Z'), text: 'Can someone send the launch assets?' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2026-11-16T11:42:00Z'), text: 'Dana has the final versions.' },\n];\n\n// Opens with one file ready, one still uploading and one the server refused.\nconst firstFiles: Upload[] = [\n { id: 'f1', name: 'Launch brief.pdf', kind: 'PDF', size: '1.2 MB', state: 'ready' },\n { id: 'f2', name: 'Hero image.png', kind: 'PNG', size: '3.4 MB', state: 'uploading' },\n { id: 'f3', name: 'Product video.mov', kind: 'MOV', size: '48 MB', state: 'failed', error: 'Too large. The limit is 25 MB.' },\n];\n\n// What the attach button adds, in turn. A real app opens the file picker.\nconst sampleFiles = [\n { name: 'Press list.xlsx', kind: 'XLSX', size: '48 KB' },\n { name: 'Pricing sheet.pdf', kind: 'PDF', size: '320 KB' },\n { name: 'Logo.svg', kind: 'SVG', size: '12 KB' },\n];\n\n// Where a sent file opens. A real app links to the stored file.\nconst fileHref = (name: string) => `/files/${name.toLowerCase().replace(/\\s+/g, '-')}`;\n\n// The line that says why sending is blocked. The message box points at it with aria-describedby.\nconst blockedId = 'message-attachments-send-blocked';\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 MessageAttachmentsInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [files, setFiles] = useState(firstFiles);\n const added = useRef(0);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops every upload still running.\n useEffect(() => () => {\n timers.current.forEach((t) => clearTimeout(t));\n timers.current = [];\n }, []);\n\n const atLimit = files.length >= MAX_FILES;\n const uploading = files.some((f) => f.state === 'uploading');\n const failed = files.find((f) => f.state === 'failed');\n const blockedReason = failed ? `Remove ${failed.name} to send.` : uploading ? 'Wait for the upload to finish, then send.' : null;\n\n function attach() {\n if (atLimit) return;\n const sample = sampleFiles[added.current % sampleFiles.length];\n const id = `a${added.current + 1}`;\n added.current += 1;\n setFiles((list) => [...list, { ...sample, id, state: 'uploading' }]);\n // Stands in for the request to the server.\n timers.current.push(\n setTimeout(() => {\n setFiles((list) => list.map((f) => (f.id === id ? { ...f, state: 'ready' } : f)));\n }, 1200),\n );\n }\n\n // The chip that had focus is gone. A real app moves focus to the next chip, or to the message box when\n // none is left. FileChip does not pass a ref to its remove button, so this example always uses the message box.\n function remove(id: string) {\n setFiles((list) => list.filter((f) => f.id !== id));\n field.current?.focus();\n }\n\n // The Composer calls this only when canSubmit is true: no upload running, none failed.\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(), files }]);\n setText('');\n setFiles([]);\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 footer={\n m.files && m.files.length > 0 ? (\n <Cluster gap=\"small\">\n {m.files.map((f) => (\n // A sent file opens when its chip is pressed.\n <FileChip key={f.id} name={f.name} kind={f.kind} meta={f.size} href={fileHref(f.name)} openInNewTab />\n ))}\n </Cluster>\n ) : undefined\n }\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"message-attachments-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n aria-describedby={blockedReason ? blockedId : undefined}\n // Files alone can be sent, but not while one uploads or has failed.\n canSubmit={(text.trim() !== '' || files.length > 0) && !uploading && !failed}\n above={\n files.length > 0 ? (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {files.map((f) => (\n <FileChip\n key={f.id}\n name={f.name}\n kind={f.kind}\n state={f.state}\n meta={f.state === 'uploading' ? 'Uploading' : f.state === 'failed' ? f.error : f.size}\n onRemove={() => remove(f.id)}\n />\n ))}\n </Cluster>\n {/* A real app also says these in a polite live region when they change. */}\n {blockedReason && (\n <Paragraph id={blockedId} size=\"caption\" tone=\"secondary\" measure=\"none\">{blockedReason}</Paragraph>\n )}\n {atLimit && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`You can attach up to ${MAX_FILES} files.`}</Paragraph>\n )}\n </Stack>\n ) : undefined\n }\n tools={\n <Tooltip title=\"Attach files\">\n <IconButton\n color=\"iconOnly\"\n state={atLimit ? 'disabled' : 'enabled'}\n size=\"small\"\n iconName=\"Paperclip\"\n ariaLabel=\"Attach files\"\n onClick={attach}\n />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
2605
3762
  "uses": [
2606
3763
  "Center",
2607
3764
  "Cluster",
@@ -2621,15 +3778,15 @@
2621
3778
  "id": "in-message",
2622
3779
  "title": "In a sent message",
2623
3780
  "useWhen": "Files are part of a message in the thread.",
2624
- "source": "'use client';\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 FileChip from 'oneslash-design-system/components/fileChip';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Two small drawings stand in for the uploaded photos.\nconst hillside =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E\";\nconst desk =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E\";\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst before: Row = { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' };\nconst withFiles: Row = { id: 'm2', from: 'Dana Lee', at: new Date('2025-01-15T11:44:00Z'), text: 'Here are the two hero options and the brief.' };\n\nexport default function MessageAttachmentsInMessage() {\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={before.from}\n avatar={<UserImage userHandle={before.from} decorative />}\n name={before.from}\n meta={<TimeStamp createdAt={before.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{before.text}</Paragraph>\n </Message>\n <Message\n aria-label={withFiles.from}\n avatar={<UserImage userHandle={withFiles.from} decorative />}\n name={withFiles.from}\n meta={<TimeStamp createdAt={withFiles.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Stack gap=\"small\">\n {/* Small thumbnails: four columns, two of them used. A real app opens the full image on click. */}\n <Grid columns={4} compact gap=\"small\">\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={hillside} alt=\"Hero option A: a green hillside under a pale sky with the sun on the right\" width={160} height={120} />\n </Figure>\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={desk} alt=\"Hero option B: a laptop on a wooden desk, its screen blue\" width={160} height={120} />\n </Figure>\n </Grid>\n <Cluster gap=\"small\">\n {/* Each chip opens the file. */}\n <FileChip name=\"Launch brief.pdf\" kind=\"PDF\" meta=\"1.2 MB\" href=\"/files/launch-brief.pdf\" openInNewTab />\n <FileChip name=\"Press list.xlsx\" kind=\"XLSX\" meta=\"48 KB\" href=\"/files/press-list.xlsx\" openInNewTab />\n </Cluster>\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{withFiles.text}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3781
+ "source": "'use client';\nimport { useState } from '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 FileChip from 'oneslash-design-system/components/fileChip';\nimport Lightbox, { LightboxThumbnail } from 'oneslash-design-system/components/lightbox';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Two small drawings stand in for the uploaded photos.\nconst hillside =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E\";\nconst desk =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E\";\n\nconst photos = [\n { src: hillside, alt: 'Hero option A, a green hillside under a pale sky with the sun on the right' },\n { src: desk, alt: 'Hero option B, a laptop on a wooden desk, its screen blue' },\n];\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst before: Row = { id: 'm1', from: 'Ben Carter', at: new Date('2026-11-16T11:40:00Z'), text: 'Can someone send the launch assets?' };\nconst withFiles: Row = { id: 'm2', from: 'Dana Lee', at: new Date('2026-11-16T11:44:00Z'), text: 'Here are the two hero options and the brief.' };\n\nexport default function MessageAttachmentsInMessage() {\n const [open, setOpen] = useState(false);\n const [index, setIndex] = useState(0);\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={before.from}\n avatar={<UserImage userHandle={before.from} decorative />}\n name={before.from}\n meta={<TimeStamp createdAt={before.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{before.text}</Paragraph>\n </Message>\n <Message\n aria-label={withFiles.from}\n avatar={<UserImage userHandle={withFiles.from} decorative />}\n name={withFiles.from}\n meta={<TimeStamp createdAt={withFiles.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Stack gap=\"small\">\n {/* Small thumbnails: four columns, two of them used. Each opens the Lightbox; closing it gives focus back to that thumbnail. */}\n <Grid columns={4} compact gap=\"small\">\n {photos.map((photo, i) => (\n <LightboxThumbnail\n key={photo.alt}\n image={photo}\n onOpen={() => {\n setIndex(i);\n setOpen(true);\n }}\n />\n ))}\n </Grid>\n <Cluster gap=\"small\">\n {/* Each chip opens the file. */}\n <FileChip name=\"Launch brief.pdf\" kind=\"PDF\" meta=\"1.2 MB\" href=\"/files/launch-brief.pdf\" openInNewTab />\n <FileChip name=\"Press list.xlsx\" kind=\"XLSX\" meta=\"48 KB\" href=\"/files/press-list.xlsx\" openInNewTab />\n </Cluster>\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{withFiles.text}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n <Lightbox images={photos} index={index} onIndexChange={setIndex} isOpen={open} onClose={() => setOpen(false)} aria-label=\"Launch images\" />\n </Center>\n );\n}\n",
2625
3782
  "uses": [
2626
3783
  "Center",
2627
3784
  "Cluster",
2628
- "Figure",
2629
3785
  "FileChip",
2630
3786
  "Grid",
2631
3787
  "Heading",
2632
- "Image",
3788
+ "Lightbox",
3789
+ "LightboxThumbnail",
2633
3790
  "Message",
2634
3791
  "Paragraph",
2635
3792
  "Stack",
@@ -3059,6 +4216,36 @@
3059
4216
  }
3060
4217
  ]
3061
4218
  },
4219
+ {
4220
+ "id": "number-format",
4221
+ "title": "A number shows its unit and never shows 0 for unknown",
4222
+ "kind": "rule",
4223
+ "level": "rule",
4224
+ "area": "dashboard",
4225
+ "situation": "A page shows counts, money, sizes, shares or changes.",
4226
+ "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.",
4227
+ "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.",
4228
+ "do": [
4229
+ "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'.",
4230
+ "Show the exact number in a table, right-aligned.",
4231
+ "Show money with its symbol and two decimals, and a cost under a cent as '< $0.01'.",
4232
+ "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'.",
4233
+ "Put the unit in the label or after the number in words: 'Responses', '7 of 8 seats', '340 responses, no limit'.",
4234
+ "Match the noun to the count: '1 invoice', '290 invoices'.",
4235
+ "Say a change's direction, size and comparison: 'Up 12% from last week'. Say 'New this week' when there was nothing before.",
4236
+ "Show a `Skeleton` while a number loads, 'No data yet' when there is none, and the case 'Load failure' when it could not load.",
4237
+ "Use the helpers in `formatNumber` (`formatCount`, `formatMoney`, `formatPercent`, `formatBytes`, `formatDuration`), `StatTile` and `Progress`. Do not format a number by hand."
4238
+ ],
4239
+ "dont": [
4240
+ "Do not show 0 for a number that is loading, missing or failed.",
4241
+ "Do not show a bare number, or a unit only in a tooltip.",
4242
+ "Do not round a cost to four decimals in one place and two in another.",
4243
+ "Do not color a change green or red. More is not good or bad by itself.",
4244
+ "Do not show the compact form ('12.4K') in a table, or give a screen reader only the compact form.",
4245
+ "Do not show 100% for a share that is not the whole."
4246
+ ],
4247
+ "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`."
4248
+ },
3062
4249
  {
3063
4250
  "id": "oauth-consent",
3064
4251
  "title": "OAuth consent",
@@ -3211,6 +4398,33 @@
3211
4398
  }
3212
4399
  ]
3213
4400
  },
4401
+ {
4402
+ "id": "one-main-action",
4403
+ "title": "A marketing page asks for one main action, in the same words everywhere",
4404
+ "kind": "rule",
4405
+ "level": "rule",
4406
+ "area": "marketing",
4407
+ "situation": "A marketing page asks the visitor to do something: sign up, open the app, buy a plan.",
4408
+ "answer": "A page has one main action. It is a primary `Button` with the same label in the header, the hero, the pricing section and the end of the page: 'Sign Up', or 'Sign Up for Pro' on a plan. A second action is a secondary `Button`, or a `Link` that teaches, such as 'See How It Works'. It is never a second primary. Write the label as the move, in Title Case, with short prepositions lowercase. Do not write 'Get Started Free' in one place and 'Try It' in another. The main action and the second action open in the same tab, unless one goes to a store or starts a download. A link to another site, in a list or a footer, uses `external`, as the case 'Site footer' says.",
4409
+ "why": "A visitor who sees three names for one move wonders if they are three moves. One label everywhere tells them where every button goes, and one primary Button tells them which one matters.",
4410
+ "do": [
4411
+ "Give the page one primary `Button`: 'Sign Up'. Use the same label in the header, the hero, the pricing section and the end of the page.",
4412
+ "Name the action for a plan with the plan: 'Sign Up for Pro'. Keep short prepositions lowercase.",
4413
+ "Make a second action a secondary `Button` or a `Link` that teaches: 'See How It Works'.",
4414
+ "Write each label as the move, in Title Case, and use the same words for the same move on every page.",
4415
+ "Name where an action goes when it leaves the site: 'Download the Desktop App'. Keep the main and second action in the same tab, unless one goes to a store or starts a download. Then use `openInNewTab`.",
4416
+ "Put the header's main action in `SiteHeader` as `phoneAction`, as the case 'Site header' says, so it stays in the bar on a phone.",
4417
+ "Use a `Button` with `href` for an action that goes to a page. Use `onClickButton` only for an action that stays on the page."
4418
+ ],
4419
+ "dont": [
4420
+ "Do not call one move 'Get Started Free' in one place and 'Try It' in another.",
4421
+ "Do not give a second, different move a primary Button. The header and the hero may both show 'Sign Up'.",
4422
+ "Do not open the main action or the second action in a new tab, unless it goes to a store or starts a download.",
4423
+ "Do not build your own call-to-action button for one section. Use `Button`.",
4424
+ "Do not leave a Button with no action. If it has nowhere to go, it is not on the page yet."
4425
+ ],
4426
+ "native": "On Apple an app has no marketing page. A product page in the App Store is the store. On Android the same holds for Google Play."
4427
+ },
3214
4428
  {
3215
4429
  "id": "overflow-menu",
3216
4430
  "title": "More menu",
@@ -3246,7 +4460,7 @@
3246
4460
  "id": "on-a-row",
3247
4461
  "title": "More button on a row",
3248
4462
  "useWhen": "The actions are for one item in a list, and each row has its own button.",
3249
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 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 EmptyBox from 'oneslash-design-system/components/emptyBox';\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 { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; name: string; updated: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the server.\nconst firstReports: Report[] = [\n { id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },\n { id: 'budget', name: 'Budget review', updated: 'Updated last week' },\n { id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },\n { id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },\n];\n\nexport default function OverflowMenuOnARow() {\n const [reports, setReports] = useState(firstReports);\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Report | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The row that asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const cancelDelete = useRef<Focusable>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n // Gives each copy its own id, so no two rows share a key.\n const copies = useRef(0);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function openMenu(r: Report, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === r.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(r);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function choose(action: (r: Report) => void) {\n if (!menuRow) return;\n const r = menuRow;\n setMenuOpen(false);\n action(r);\n }\n\n // The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.\n function duplicate(r: Report) {\n copies.current += 1;\n const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };\n setReports((list) => {\n const at = list.findIndex((x) => x.id === r.id);\n return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];\n });\n focusNext.current = () => moreButtons.current[copy.id]?.focus();\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,\n // in an error toast that stays until the person closes it.\n function copyLink(r: Report) {\n const link = `https://example.com/reports/${r.id}`;\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToDelete(r: Report) {\n setConfirmingId(r.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepReport() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const at = reports.findIndex((r) => r.id === id);\n const gone = reports[at];\n const neighbor = reports[at + 1] ?? reports[at - 1];\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setReports((list) => list.filter((r) => r.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));\n // The row is gone: focus goes to the next row's More button, or the one before it when it was the last.\n focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();\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=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n {reports.length > 0 ? (\n <TableContainer>\n {reports.map((r) => {\n const confirming = r.id === confirmingId;\n return (\n <TableRow key={r.id}>\n <TableCell>\n <Stack gap=\"small\">\n {r.name}\n {confirming && <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">Delete this report?</Paragraph>}\n </Stack>\n </TableCell>\n <TableCell width=\"160px\">{r.updated}</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=\"168px\" align=\"right\">\n {confirming ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n ) : (\n <Cluster justify=\"end\">\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[r.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${r.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === r.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" text=\"No reports yet\" secondText=\"Reports you create appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose(duplicate)} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={() => choose(copyLink)} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
4463
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\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 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 EmptyBox from 'oneslash-design-system/components/emptyBox';\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 { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; name: string; updated: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the server.\nconst firstReports: Report[] = [\n { id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },\n { id: 'budget', name: 'Budget review', updated: 'Updated last week' },\n { id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },\n { id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },\n];\n\nexport default function OverflowMenuOnARow() {\n const [reports, setReports] = useState(firstReports);\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Report | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The row that asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const cancelDelete = useRef<Focusable>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n // Gives each copy its own id, so no two rows share a key.\n const copies = useRef(0);\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 useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function openMenu(r: Report, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === r.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(r);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function choose(action: (r: Report) => void) {\n if (!menuRow) return;\n const r = menuRow;\n setMenuOpen(false);\n action(r);\n }\n\n // The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.\n function duplicate(r: Report) {\n copies.current += 1;\n const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };\n setReports((list) => {\n const at = list.findIndex((x) => x.id === r.id);\n return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];\n });\n focusNext.current = () => moreButtons.current[copy.id]?.focus();\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,\n // in an error toast that stays until the person closes it.\n function copyLink(r: Report) {\n const link = `https://example.com/reports/${r.id}`;\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToDelete(r: Report) {\n setConfirmingId(r.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepReport() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const at = reports.findIndex((r) => r.id === id);\n const gone = reports[at];\n const neighbor = reports[at + 1] ?? reports[at - 1];\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setReports((list) => list.filter((r) => r.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));\n // The row is gone: focus goes to the next row's More button, or the one before it when it was the last.\n focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();\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=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n {reports.length > 0 ? (\n <TableContainer>\n {reports.map((r) => {\n const confirming = r.id === confirmingId;\n return (\n <TableRow key={r.id}>\n <TableCell>\n <Stack gap=\"small\">\n {r.name}\n {confirming && <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">Delete this report?</Paragraph>}\n </Stack>\n </TableCell>\n <TableCell width=\"160px\">{r.updated}</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=\"168px\" align=\"right\">\n {confirming ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n ) : (\n <Cluster justify=\"end\">\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[r.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${r.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === r.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" text=\"No reports yet\" secondText=\"Reports you create appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose(duplicate)} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={() => choose(copyLink)} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
3250
4464
  "uses": [
3251
4465
  "Button",
3252
4466
  "Center",
@@ -3273,7 +4487,7 @@
3273
4487
  "id": "in-a-header",
3274
4488
  "title": "More button in a header",
3275
4489
  "useWhen": "The actions are for the whole page, and the header has one button.",
3276
- "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 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 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 { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];\n\nexport default function OverflowMenuInAHeader() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function duplicate() {\n setOpen(false);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.\n function copyLink() {\n setOpen(false);\n const link = 'https://example.com/reports/q3';\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n function askToDelete() {\n setOpen(false);\n setConfirming(true);\n }\n\n // The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.\n function keepReport() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n function confirmDelete() {\n if (deleting) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n // A real app goes back to the list of reports here.\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Surface padding=\"large\">\n <List items={otherReports} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Q3 report</Heading>\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Q3 report\"\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n )}\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Q3 report\" width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={duplicate} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={copyLink} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n {/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Report\"\n onClose={keepReport}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes &apos;Q3 report&apos; and its 12 tasks.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4490
+ "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 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 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 { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];\n\nexport default function OverflowMenuInAHeader() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\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 useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function duplicate() {\n setOpen(false);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.\n function copyLink() {\n setOpen(false);\n const link = 'https://example.com/reports/q3';\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n function askToDelete() {\n setOpen(false);\n setConfirming(true);\n }\n\n // The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.\n function keepReport() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n function confirmDelete() {\n if (deleting) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n // A real app goes back to the list of reports here.\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Surface padding=\"large\">\n <List items={otherReports} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Q3 report</Heading>\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Q3 report\"\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n )}\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Q3 report\" width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={duplicate} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={copyLink} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n {/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Report\"\n onClose={keepReport}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes &apos;Q3 report&apos; and its 12 tasks.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3277
4491
  "uses": [
3278
4492
  "Button",
3279
4493
  "Center",
@@ -3297,6 +4511,58 @@
3297
4511
  }
3298
4512
  ]
3299
4513
  },
4514
+ {
4515
+ "id": "page-end",
4516
+ "title": "Page end",
4517
+ "kind": "design",
4518
+ "level": "organism",
4519
+ "area": "marketing",
4520
+ "situation": "A page has said what it had to say, and its last block decides what the visitor does next.",
4521
+ "do": [
4522
+ "Follow the rule 'A marketing page asks for one main action, in the same words everywhere'. The closing block uses the same labels as the header and the hero.",
4523
+ "Use a `Surface` for `cta-band`, with a level 2 `Heading`, one line of lede and the page's actions: a primary 'Sign Up' and one secondary.",
4524
+ "Write the heading as a statement the visitor can say yes to, and the lede as the one doubt it removes.",
4525
+ "Use one `LinkCard` for `next-link`, with the next page's title and a caption that says it is next: 'Next: Task threads'.",
4526
+ "Put the block after the last section and before the `SiteFooter`."
4527
+ ],
4528
+ "dont": [
4529
+ "Do not use both blocks on one page. A page ends one way.",
4530
+ "Do not add a new action that the header and the hero do not have.",
4531
+ "Do not close a reading page on a sign-up banner.",
4532
+ "Do not name the link 'Next'. Name the page."
4533
+ ],
4534
+ "native": "On Apple a screen ends with its content. A flow moves on with a `NavigationLink` or a toolbar button. On Android use the same with a navigation bar.",
4535
+ "options": [
4536
+ {
4537
+ "id": "cta-band",
4538
+ "title": "Closing call to action",
4539
+ "useWhen": "A marketing page closes on its main action.",
4540
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\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\nexport default function PageEndCtaBand() {\n return (\n <PageShell>\n {/* The last block of the page: one statement, one line, and the same actions as the header and the hero. */}\n <Surface padding=\"xlarge\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h4\">Bring your team and its agent together</Heading>\n <Paragraph tone=\"secondary\" measure=\"lede\">Start on Free with 3 members, and add people when you need them.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"large\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />\n <Button size=\"large\" type=\"secondary\" state=\"enabled\" label=\"See How It Works\" href=\"#how-it-works\" />\n </Cluster>\n </Stack>\n </Surface>\n </PageShell>\n );\n}\n",
4541
+ "uses": [
4542
+ "Button",
4543
+ "Cluster",
4544
+ "Heading",
4545
+ "PageShell",
4546
+ "Paragraph",
4547
+ "Stack",
4548
+ "Surface"
4549
+ ]
4550
+ },
4551
+ {
4552
+ "id": "next-link",
4553
+ "title": "Link to the next page",
4554
+ "useWhen": "A reading page leads to the next thing to read.",
4555
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PageEndNextLink() {\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <Stack gap=\"xxlarge\">\n <PageHeader level={1} title=\"How channels work\" lede=\"A channel is a place for one subject. Everyone in it sees every message.\" />\n <Paragraph tone=\"secondary\">Make a channel for each team or project. Pin the messages people need to find again. Turn a message into a task when it needs an owner.</Paragraph>\n </Stack>\n {/* A reading page ends by pointing to the next page to read, and not to a sign-up. */}\n <LinkCard href=\"#task-threads\" title=\"Task threads\" caption=\"Next: Task threads\" />\n </Stack>\n </PageShell>\n );\n}\n",
4556
+ "uses": [
4557
+ "LinkCard",
4558
+ "PageHeader",
4559
+ "PageShell",
4560
+ "Paragraph",
4561
+ "Stack"
4562
+ ]
4563
+ }
4564
+ ]
4565
+ },
3300
4566
  {
3301
4567
  "id": "page-header",
3302
4568
  "title": "Page header with actions",
@@ -3337,55 +4603,503 @@
3337
4603
  "MenuItem",
3338
4604
  "PageShell",
3339
4605
  "Paragraph",
3340
- "Popover",
4606
+ "Popover",
4607
+ "Stack",
4608
+ "TitleBar",
4609
+ "Tooltip"
4610
+ ]
4611
+ },
4612
+ {
4613
+ "id": "sub-page",
4614
+ "title": "A page one step down, with Back",
4615
+ "useWhen": "The page opens from another page, such as a task from its project.",
4616
+ "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",
4617
+ "uses": [
4618
+ "Button",
4619
+ "Heading",
4620
+ "MenuItem",
4621
+ "Navigation",
4622
+ "PageShell",
4623
+ "Paragraph",
4624
+ "Stack",
4625
+ "TitleBar"
4626
+ ]
4627
+ }
4628
+ ]
4629
+ },
4630
+ {
4631
+ "id": "paged-card",
4632
+ "title": "Short list on a dashboard",
4633
+ "kind": "design",
4634
+ "level": "organism",
4635
+ "area": "dashboard",
4636
+ "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.",
4637
+ "do": [
4638
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4639
+ "Say the total in the title, as a number and its unit: '8 questions waiting on you'.",
4640
+ "Make every row a link to the thing it names, with a second line for when it was asked.",
4641
+ "Put `Pagination variant=\"compact\"` in the title row when the list pages, named for the card: 'Pages of questions waiting on you'.",
4642
+ "Keep the page length the same on every page. `Pagination` shows nothing when there is one page.",
4643
+ "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'.",
4644
+ "Show `EmptyBox size=\"small\"` when the list is empty, such as 'No questions waiting on you', with a `secondText` that says what will appear.",
4645
+ "Show the card as a hairline, a title and rows. Do not box it."
4646
+ ],
4647
+ "dont": [
4648
+ "Do not page a long list on the dashboard. Show five rows and a link.",
4649
+ "Do not leave the pager unnamed. Name it for the card, so a screen reader hears 'Pages of questions waiting on you'.",
4650
+ "Do not write the page as '1/3'. `Pagination` writes '1 of 3' in a card and 'Page 1 of 3' elsewhere.",
4651
+ "Do not make a row that is not a link, or a link with no name.",
4652
+ "Do not scroll a list inside the card."
4653
+ ],
4654
+ "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.",
4655
+ "options": [
4656
+ {
4657
+ "id": "pager",
4658
+ "title": "Pager in the title row",
4659
+ "useWhen": "The list is short and stays on the dashboard, a few rows a page.",
4660
+ "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",
4661
+ "uses": [
4662
+ "Center",
4663
+ "Cluster",
4664
+ "Heading",
4665
+ "Line",
4666
+ "MenuItem",
4667
+ "Pagination",
4668
+ "Stack",
4669
+ "formatCount"
4670
+ ]
4671
+ },
4672
+ {
4673
+ "id": "see-all",
4674
+ "title": "Five rows and See All",
4675
+ "useWhen": "The list is long, so the dashboard shows the newest five and a link to the full page.",
4676
+ "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",
4677
+ "uses": [
4678
+ "Center",
4679
+ "Cluster",
4680
+ "Heading",
4681
+ "Line",
4682
+ "Link",
4683
+ "MenuItem",
4684
+ "Stack",
4685
+ "formatCount"
4686
+ ]
4687
+ }
4688
+ ]
4689
+ },
4690
+ {
4691
+ "id": "password-gate",
4692
+ "title": "Password gate",
4693
+ "kind": "design",
4694
+ "level": "organism",
4695
+ "area": "content",
4696
+ "situation": "Some work is private. A visitor needs the password to read it, and someone who does not have it needs to know how to ask.",
4697
+ "do": [
4698
+ "Put the gate in a `Surface` with a heading that says what is behind it: 'This case study needs a password'. It is the h1 on a whole page and an h2 inside a page.",
4699
+ "Say in one line how to get access, with a `Link` to the contact page.",
4700
+ "Use a password `TextField` and a Button named 'View Work'. Put them in a `Form`, so Enter submits.",
4701
+ "Show a wrong password under the field: 'That password is not right.' Keep focus in the field and keep what was typed.",
4702
+ "Keep the Button's label while it checks, and make it `loading`.",
4703
+ "Keep the field enabled while it checks. A disabled field loses focus, and after a wrong password the cursor must still be in the field.",
4704
+ "Show the work when the password is right, and move focus to the first control in it.",
4705
+ "Follow the rule 'A confirm says exactly what will happen' for `modal`. Put 'Cancel' first and make the Modal title and its action the same words: 'View Work'.",
4706
+ "Let the server check the password and set the cookie. The server sends the private content only to a visitor with the cookie. The page never holds the password.",
4707
+ "Keep the summary and the facts in the page for `inline`, and leave the private part out of the HTML sent to a visitor without the cookie."
4708
+ ],
4709
+ "dont": [
4710
+ "Do not send private content to the browser and hide it there, with a style or a check in the page. A visitor can still read it.",
4711
+ "Do not put the password in the page, in a script or in the address.",
4712
+ "Do not say which part of a password was wrong.",
4713
+ "Do not show a bare field with no word on what is behind it or how to ask.",
4714
+ "Do not change the Button's label while it checks."
4715
+ ],
4716
+ "native": "On Apple use a `SecureField` in a grouped form, and let the server check it. A locked item opens a sheet with the field and Cancel first.",
4717
+ "options": [
4718
+ {
4719
+ "id": "page",
4720
+ "title": "The whole page is private",
4721
+ "useWhen": "The whole page is private, and nothing on it is public.",
4722
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\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 Link from 'oneslash-design-system/components/link';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// The example checks nothing real and sends nothing. It accepts one made-up passphrase, 'acme-demo', so you can see both outcomes.\n// A real page asks its server. The server checks the password and sets a cookie, and it sends the private content only to a visitor with that cookie. The page never holds the secret.\nconst PASSPHRASE = 'acme-demo';\n\nexport default function PasswordGatePage() {\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [checking, setChecking] = useState(false);\n const [unlocked, setUnlocked] = useState(false);\n // A new key remounts the field with focus, so a wrong password leaves the cursor in the field, even after a click on the Button.\n const [attempt, setAttempt] = useState(0);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const lockAgain = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The field is gone once the work shows, so focus moves to the first control in it.\n useEffect(() => {\n if (unlocked) lockAgain.current?.focus();\n }, [unlocked]);\n\n function handleSubmit() {\n if (checking) return;\n if (!password.trim()) {\n setError('Enter the password.');\n setAttempt((n) => n + 1);\n return;\n }\n setError('');\n setChecking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setChecking(false);\n if (password === PASSPHRASE) {\n setUnlocked(true);\n } else {\n setError('That password is not right.');\n setAttempt((n) => n + 1);\n }\n }, 600);\n }\n\n if (unlocked) {\n return (\n <PageShell>\n <Stack gap=\"xlarge\">\n <PageHeader level={1} title=\"Plan changes, a case study\" lede=\"How we made a plan change clear before anyone pays.\" />\n <Paragraph tone=\"secondary\">The screens, the notes and the decisions for this case study are here.</Paragraph>\n <Stack align=\"start\">\n <Button ref={lockAgain} size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Lock Again\" onClickButton={() => { setUnlocked(false); setPassword(''); }} />\n </Stack>\n </Stack>\n </PageShell>\n );\n }\n\n return (\n <PageShell>\n <Surface padding=\"xlarge\" minHeight=\"tall\" align=\"center\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">This case study needs a password</Heading>\n <Paragraph>\n The password comes by email. <Link href=\"#contact\">Ask for the password</Link>.\n </Paragraph>\n <Form aria-label=\"Private work\" onSubmit={handleSubmit}>\n <TextField key={attempt} id=\"password-gate-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" autoFocus={attempt > 0} value={password} error={Boolean(error)} errorText={error} onChange={(e) => { setPassword(e.target.value); setError(''); }} />\n <Stack align=\"start\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"View Work\" htmlType=\"submit\" loading={checking} />\n </Stack>\n </Form>\n </Stack>\n </Surface>\n </PageShell>\n );\n}\n",
4723
+ "uses": [
4724
+ "Button",
4725
+ "Form",
4726
+ "Heading",
4727
+ "Link",
4728
+ "PageHeader",
4729
+ "PageShell",
4730
+ "Paragraph",
4731
+ "Stack",
4732
+ "Surface",
4733
+ "TextField"
4734
+ ]
4735
+ },
4736
+ {
4737
+ "id": "inline",
4738
+ "title": "Part of the page is private",
4739
+ "useWhen": "The summary and the facts stay readable, and the rest is behind the gate.",
4740
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\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 Link from 'oneslash-design-system/components/link';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// The example checks nothing real and sends nothing. It accepts one made-up passphrase, 'acme-demo', so you can see both outcomes.\n// A real page asks its server. The server checks the password and sets a cookie, and it sends the private content only to a visitor with that cookie. The page never holds the secret.\n\n// A stand-in for a screen. A real page passes its own picture.\nconst screen =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1280 720'%3E%3Crect width='1280' height='720' fill='%23eef2f6'/%3E%3Crect x='120' y='120' width='460' height='480' rx='24' fill='%23ffffff'/%3E%3Crect x='680' y='120' width='480' height='220' rx='24' fill='%23dfe7ef'/%3E%3Crect x='680' y='380' width='480' height='220' rx='24' fill='%232f6b4f'/%3E%3C/svg%3E\";\n\nconst PASSPHRASE = 'acme-demo';\n\nexport default function PasswordGateInline() {\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [checking, setChecking] = useState(false);\n const [unlocked, setUnlocked] = useState(false);\n // A new key remounts the field with focus, so a wrong password leaves the cursor in the field, even after a click on the Button.\n const [attempt, setAttempt] = useState(0);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const lockAgain = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The field is gone once the work shows, so focus moves to the first control in it.\n useEffect(() => {\n if (unlocked) lockAgain.current?.focus();\n }, [unlocked]);\n\n function handleSubmit() {\n if (checking) return;\n if (!password.trim()) {\n setError('Enter the password.');\n setAttempt((n) => n + 1);\n return;\n }\n setError('');\n setChecking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setChecking(false);\n if (password === PASSPHRASE) {\n setUnlocked(true);\n } else {\n setError('That password is not right.');\n setAttempt((n) => n + 1);\n }\n }, 600);\n }\n\n const header = (\n <PageHeader\n level={1}\n title=\"Plan changes, a case study\"\n lede=\"How we made a plan change clear before anyone pays.\"\n facts={[\n { label: 'Role', value: 'Lead designer' },\n { label: 'Team', value: '4 people' },\n { label: 'Year', value: '2026' },\n ]}\n />\n );\n\n return (\n <PageShell>\n <Stack gap=\"giant\">\n {/* The summary and the facts stay readable. Only the screens are behind the gate. */}\n <Stack gap=\"xlarge\">\n {header}\n <Paragraph tone=\"secondary\">People could not tell what a new plan would cost them. We showed the new price and the day it starts before the last step, and fewer people wrote to ask.</Paragraph>\n </Stack>\n {unlocked ? (\n <Stack gap=\"xlarge\">\n <Figure crop={16 / 9} caption=\"The plan change, before the person pays.\">\n <Image src={screen} alt=\"A plan change screen: the current plan beside the new plan, with the new price in green\" width={1280} height={720} />\n </Figure>\n <Stack align=\"start\">\n <Button ref={lockAgain} size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Lock Again\" onClickButton={() => { setUnlocked(false); setPassword(''); }} />\n </Stack>\n </Stack>\n ) : (\n <Surface padding=\"large\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">This case study needs a password</Heading>\n <Paragraph>\n The password comes by email. <Link href=\"#contact\">Ask for the password</Link>.\n </Paragraph>\n <Form aria-label=\"Private work\" onSubmit={handleSubmit}>\n <TextField key={attempt} id=\"password-gate-inline-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" autoFocus={attempt > 0} value={password} error={Boolean(error)} errorText={error} onChange={(e) => { setPassword(e.target.value); setError(''); }} />\n <Stack align=\"start\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"View Work\" htmlType=\"submit\" loading={checking} />\n </Stack>\n </Form>\n </Stack>\n </Surface>\n )}\n </Stack>\n </PageShell>\n );\n}\n",
4741
+ "uses": [
4742
+ "Button",
4743
+ "Figure",
4744
+ "Form",
4745
+ "Heading",
4746
+ "Image",
4747
+ "Link",
4748
+ "PageHeader",
4749
+ "PageShell",
4750
+ "Paragraph",
4751
+ "Stack",
4752
+ "Surface",
4753
+ "TextField"
4754
+ ]
4755
+ },
4756
+ {
4757
+ "id": "modal",
4758
+ "title": "A link to private work asks first",
4759
+ "useWhen": "A list links to private work, and the gate should not leave the list.",
4760
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Link from 'oneslash-design-system/components/link';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// The example checks nothing real and sends nothing. It accepts one made-up passphrase, 'acme-demo', so you can see both outcomes.\n// A real page asks its server. The server checks the password and sets a cookie, and it sends the private content only to a visitor with that cookie. The page never holds the secret.\nconst PASSPHRASE = 'acme-demo';\n\nexport default function PasswordGateModal() {\n const [open, setOpen] = useState(false);\n const [unlocked, setUnlocked] = useState(false);\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [checking, setChecking] = useState(false);\n // A new key remounts the field with focus, so a wrong password leaves the cursor in the field, even after a click on the Button.\n const [attempt, setAttempt] = useState(0);\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 (checking) return;\n setOpen(false);\n setPassword('');\n setError('');\n }\n\n function handleSubmit() {\n if (checking) return;\n if (!password.trim()) {\n setError('Enter the password.');\n setAttempt((n) => n + 1);\n return;\n }\n setError('');\n setChecking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setChecking(false);\n if (password === PASSPHRASE) {\n setUnlocked(true);\n setOpen(false);\n setPassword('');\n } else {\n setError('That password is not right.');\n setAttempt((n) => n + 1);\n }\n }, 600);\n }\n\n return (\n <PageShell>\n <Stack gap=\"xlarge\">\n <PageHeader level={1} title=\"Selected work\" lede=\"Three case studies. The first is open. The others need a password.\" />\n <Stack gap=\"large\" align=\"start\">\n <Link href=\"#how-we-write-errors\">How we write error messages</Link>\n {/* A link to private work asks for the password first. A real page keeps the link's address, so the work opens there after the check. The trigger stays, so focus has somewhere to go back to. */}\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Read the Plan Changes Case Study\" onClickButton={() => { if (!unlocked) setOpen(true); }} />\n {unlocked && <Paragraph>It is open for you now.</Paragraph>}\n </Stack>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"View Work\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={checking ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"View Work\" loading={checking} onClickButton={handleSubmit} />\n </>\n }\n >\n <Form aria-label=\"Private work\" onSubmit={handleSubmit}>\n <TextField key={attempt} id=\"password-gate-modal-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" autoFocus={attempt > 0} value={password} error={Boolean(error)} errorText={error} onChange={(e) => { setPassword(e.target.value); setError(''); }} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n This case study needs a password, and it comes by email. <Link href=\"#contact\">Ask for the password</Link>.\n </Paragraph>\n </Form>\n </Modal>\n </PageShell>\n );\n}\n",
4761
+ "uses": [
4762
+ "Button",
4763
+ "Form",
4764
+ "Link",
4765
+ "Modal",
4766
+ "PageHeader",
4767
+ "PageShell",
4768
+ "Paragraph",
4769
+ "Stack",
4770
+ "TextField"
4771
+ ]
4772
+ }
4773
+ ]
4774
+ },
4775
+ {
4776
+ "id": "payment-method",
4777
+ "title": "Payment method",
4778
+ "kind": "design",
4779
+ "level": "organism",
4780
+ "area": "dashboard",
4781
+ "situation": "A workspace pays by card. The admin sees which card, changes it or removes it.",
4782
+ "do": [
4783
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4784
+ "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.",
4785
+ "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'.",
4786
+ "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'.",
4787
+ "Name the card in the Remove Button's `aria-label`: 'Remove Visa ending in 4821'.",
4788
+ "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.",
4789
+ "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.'",
4790
+ "Add an inline warning `Alert` above the row a month before the card expires: 'This card expires on 08/28. Update it before then.'",
4791
+ "Say in one line that there is no card, say whether one is needed, and offer 'Add Payment Method'."
4792
+ ],
4793
+ "dont": [
4794
+ "Do not add a `TextField` for a card number, a security code, a bank account or an address. ODS has no payment form.",
4795
+ "Do not show a full card number, or part of it beyond the last four digits.",
4796
+ "Do not name the payment provider, or copy the look or the words of its page.",
4797
+ "Do not show a card-network logo. The brand is the word.",
4798
+ "Do not title the Modal 'Are you sure?'. Name the action: 'Remove Card'.",
4799
+ "Do not remove the card on the first click.",
4800
+ "Do not offer Remove while a paid plan needs the card.",
4801
+ "Do not show Update or Remove to a person who cannot change billing."
4802
+ ],
4803
+ "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.",
4804
+ "options": [
4805
+ {
4806
+ "id": "on-file",
4807
+ "title": "A card is saved",
4808
+ "useWhen": "The workspace has a card on file.",
4809
+ "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",
4810
+ "uses": [
4811
+ "Alert",
4812
+ "Button",
4813
+ "Center",
4814
+ "Cluster",
4815
+ "Modal",
4816
+ "Paragraph",
4817
+ "SettingsSection",
4818
+ "Stack",
4819
+ "Surface",
4820
+ "Toaster",
4821
+ "dismissToast",
4822
+ "toast"
4823
+ ]
4824
+ },
4825
+ {
4826
+ "id": "none",
4827
+ "title": "No card yet",
4828
+ "useWhen": "The workspace has never added a card, or removed it.",
4829
+ "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",
4830
+ "uses": [
4831
+ "Button",
4832
+ "Center",
4833
+ "Paragraph",
4834
+ "SettingsSection",
4835
+ "Stack"
4836
+ ]
4837
+ }
4838
+ ]
4839
+ },
4840
+ {
4841
+ "id": "phone-navigation",
4842
+ "title": "On a phone, a sidebar opens as a drawer and a list opens its detail",
4843
+ "kind": "rule",
4844
+ "level": "rule",
4845
+ "area": "shell",
4846
+ "situation": "A layout with a sidebar, a list beside its detail, or a side pane meets a phone screen.",
4847
+ "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.",
4848
+ "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.",
4849
+ "do": [
4850
+ "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`.",
4851
+ "Close the drawer on a choice, Close, Escape, the scrim and when the window widens past `md`.",
4852
+ "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.",
4853
+ "Let a side pane take the whole content area on a phone, with a Close button.",
4854
+ "Put a site's links in the same kind of menu, and keep at most one main action in the bar.",
4855
+ "Give every place a way to be reached on a phone, even one that is only a link."
4856
+ ],
4857
+ "dont": [
4858
+ "Do not hide a link on a phone without a menu that holds it.",
4859
+ "Do not show a sidebar beside the page on a phone, or squeeze a side pane beside the content.",
4860
+ "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.",
4861
+ "Do not add a bottom tab bar on the web.",
4862
+ "Do not leave a drawer that Escape and a tap outside cannot close."
4863
+ ],
4864
+ "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."
4865
+ },
4866
+ {
4867
+ "id": "plan-change-confirm",
4868
+ "title": "Plan change confirm",
4869
+ "kind": "design",
4870
+ "level": "organism",
4871
+ "area": "dashboard",
4872
+ "situation": "An admin chose another plan. Before anything changes they need to know what it costs and when it starts.",
4873
+ "do": [
4874
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4875
+ "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'.",
4876
+ "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.'",
4877
+ "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.",
4878
+ "Say when a downgrade starts and what stops: 'Pro stays on until Dec 1, 2026.' Then list what Acme loses, each with its number.",
4879
+ "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.",
4880
+ "Check the smaller plan's limits before the Modal opens. Keep the Button's label while it checks.",
4881
+ "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.",
4882
+ "Show the card that pays, by its last four digits only: 'The card ending in 4821 pays for it.'",
4883
+ "Show these Buttons only to a person who can change the plan, as the case 'Upgrade prompt' says."
4884
+ ],
4885
+ "dont": [
4886
+ "Do not title the Modal 'Switch to Pro' or 'Confirm'. Name the action: 'Upgrade to Pro'.",
4887
+ "Do not label the action 'Confirm', 'Proceed' or 'Yes, downgrade'.",
4888
+ "Do not write 'prorated charges' with no amount. Say the amount.",
4889
+ "Do not change the Button's label while it runs, such as to 'Upgrading...'.",
4890
+ "Do not open the Modal and then refuse. Check the limits first.",
4891
+ "Do not offer a disabled action Button in the blocked Modal. Offer only Cancel and the links that fix it.",
4892
+ "Do not show a card field or a full card number in the confirm.",
4893
+ "Do not say a downgrade is done today when it starts later."
4894
+ ],
4895
+ "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.",
4896
+ "options": [
4897
+ {
4898
+ "id": "upgrade",
4899
+ "title": "An upgrade charges now",
4900
+ "useWhen": "The new plan costs more and starts at once.",
4901
+ "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",
4902
+ "uses": [
4903
+ "Button",
4904
+ "Center",
4905
+ "Cluster",
4906
+ "Heading",
4907
+ "Modal",
4908
+ "Paragraph",
4909
+ "Stack",
4910
+ "formatMoney"
4911
+ ]
4912
+ },
4913
+ {
4914
+ "id": "downgrade",
4915
+ "title": "A downgrade waits",
4916
+ "useWhen": "The new plan costs less. It starts when the paid period ends, so nothing is lost today.",
4917
+ "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",
4918
+ "uses": [
4919
+ "Button",
4920
+ "Center",
4921
+ "Cluster",
4922
+ "Heading",
4923
+ "List",
4924
+ "Modal",
4925
+ "Paragraph",
4926
+ "Stack"
4927
+ ]
4928
+ },
4929
+ {
4930
+ "id": "blocked",
4931
+ "title": "The smaller plan does not fit",
4932
+ "useWhen": "The workspace is over a limit of the smaller plan, so the downgrade cannot happen until the person fixes it.",
4933
+ "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",
4934
+ "uses": [
4935
+ "Button",
4936
+ "Center",
4937
+ "Cluster",
4938
+ "Heading",
4939
+ "Link",
4940
+ "List",
4941
+ "Modal",
4942
+ "Paragraph",
4943
+ "Stack"
4944
+ ]
4945
+ }
4946
+ ]
4947
+ },
4948
+ {
4949
+ "id": "plan-picker",
4950
+ "title": "Plan picker",
4951
+ "kind": "design",
4952
+ "level": "organism",
4953
+ "area": "dashboard",
4954
+ "situation": "An admin compares the plans a workspace can be on and chooses one.",
4955
+ "do": [
4956
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4957
+ "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'.",
4958
+ "Put the cards in `Grid columns={3}`, which stacks them on a phone. Put the rows in one column.",
4959
+ "Mark the current plan with `Tag variant=\"textOnly\"` 'Current plan', and give it no Button.",
4960
+ "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'.",
4961
+ "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.'",
4962
+ "Open the picker from 'Change Plan' on the case 'Billing page'. Show it only to a person who can change the plan.",
4963
+ "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."
4964
+ ],
4965
+ "dont": [
4966
+ "Do not make a card clickable as a whole. Its Button is the one control, so a keyboard and a screen reader find it.",
4967
+ "Do not label the Buttons 'Select' or 'Choose'. Say the move: 'Upgrade to Pro'.",
4968
+ "Do not run the limits together in one line with dots between them. Use a `List`, one limit per item.",
4969
+ "Do not add a monthly and yearly switch when no plan bills yearly.",
4970
+ "Do not change a Button label to show it is busy, such as to 'Checking...'.",
4971
+ "Do not charge or change the plan from this page. The confirm does that."
4972
+ ],
4973
+ "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.",
4974
+ "options": [
4975
+ {
4976
+ "id": "cards",
4977
+ "title": "Cards side by side",
4978
+ "useWhen": "Two or three plans are compared at once, on a page with room for columns.",
4979
+ "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",
4980
+ "uses": [
4981
+ "Button",
4982
+ "Center",
4983
+ "Cluster",
4984
+ "Grid",
4985
+ "Heading",
4986
+ "List",
4987
+ "Modal",
4988
+ "Paragraph",
4989
+ "SettingsSection",
4990
+ "Stack",
4991
+ "Surface",
4992
+ "Tag",
4993
+ "formatMoney"
4994
+ ]
4995
+ },
4996
+ {
4997
+ "id": "list",
4998
+ "title": "Rows in a settings column",
4999
+ "useWhen": "The picker sits in a narrow settings column, or the plans have long lists of what they include.",
5000
+ "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",
5001
+ "uses": [
5002
+ "Button",
5003
+ "Center",
5004
+ "Cluster",
5005
+ "Heading",
5006
+ "List",
5007
+ "Modal",
5008
+ "Paragraph",
5009
+ "SettingsSection",
3341
5010
  "Stack",
3342
- "TitleBar",
3343
- "Tooltip"
5011
+ "Surface",
5012
+ "Tag",
5013
+ "formatMoney"
3344
5014
  ]
3345
- },
5015
+ }
5016
+ ]
5017
+ },
5018
+ {
5019
+ "id": "pricing-section",
5020
+ "title": "Pricing section",
5021
+ "kind": "design",
5022
+ "level": "organism",
5023
+ "area": "marketing",
5024
+ "situation": "A visitor to the public site compares the plans and signs up for one.",
5025
+ "do": [
5026
+ "Follow the rule 'A marketing page asks for one main action, in the same words everywhere'.",
5027
+ "Show the same plans as the case 'Plan picker', word for word: the names, the prices and what each includes. A price comes from `formatMoney`, as the rule 'A number shows its unit and never shows 0 for unknown' says.",
5028
+ "Make each plan a `Surface` with its name as a level 3 heading, its price, a `List` of what it includes and one `Button`. Put them in `Grid columns={3}`, which stacks them on a phone.",
5029
+ "Name each Button for the plan: 'Sign Up for Free', 'Sign Up for Pro', 'Sign Up for Business'. Give it an `href` to the sign-up page with the plan in the address, so it works as a link.",
5030
+ "Make the Button of the plan most visitors start on primary, and the others secondary. A visitor has no current plan, so no card carries 'Current plan'.",
5031
+ "Put the section's name in `SectionIntro`, so the section has a level 2 heading and a link of its own.",
5032
+ "Put one line under the cards that says what the prices are in and who pays: 'Prices in USD. Pro and Business bill each member monthly.'",
5033
+ "Add a `SegmentedControl` for monthly and yearly as the case 'Range switch' says once a plan bills by the year. Leave it out while every plan bills monthly."
5034
+ ],
5035
+ "dont": [
5036
+ "Do not name a Button 'Get Started', 'Choose' or 'Select'. Name the plan it signs up for.",
5037
+ "Do not open the sign-up page in a new tab.",
5038
+ "Do not give two plans a primary Button.",
5039
+ "Do not change a price or a limit here without changing it in the case 'Plan picker' too. A visitor sees one set of plans.",
5040
+ "Do not make a card clickable as a whole. Its Button is the one control."
5041
+ ],
5042
+ "native": "On Apple an app has no pricing section. The plans are in the app as a `List` with the system purchase sheet, as the case 'Plan picker' says.",
5043
+ "options": [
3346
5044
  {
3347
- "id": "sub-page",
3348
- "title": "A page one step down, with Back",
3349
- "useWhen": "The page opens from another page, such as a task from its project.",
3350
- "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",
5045
+ "id": "cards",
5046
+ "title": "Plan cards side by side",
5047
+ "useWhen": "The plans a visitor can sign up for are shown on the public site, two or three at once.",
5048
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\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 Button from 'oneslash-design-system/components/button';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// The same plans as the case 'Plan picker': names, prices and what each includes. A real site reads them from one place.\nconst plans = [\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\nexport default function PricingSectionCards() {\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"pricing\" name=\"Pricing\" statement=\"Pick the plan that fits your team.\" />\n <Stack gap=\"medium\">\n {/* Three across from md, stacked on a phone. A visitor has no current plan, so each plan asks to sign up. */}\n <Grid columns={3}>\n {plans.map((p) => (\n <Surface key={p.id} padding=\"medium\">\n <Stack gap=\"large\">\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 {/* The one primary Button is the plan to start with. Each is a link, so it works without a script. */}\n <Button\n size=\"medium\"\n type={p.id === 'pro' ? 'primary' : 'secondary'}\n state=\"enabled\"\n label={`Sign Up for ${p.name}`}\n href={`https://acme.example/sign-up?plan=${p.id}`}\n />\n </Stack>\n </Surface>\n ))}\n </Grid>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Prices in USD. Pro and Business bill each member monthly.</Paragraph>\n </Stack>\n </PageSection>\n </PageShell>\n );\n}\n",
3351
5049
  "uses": [
3352
5050
  "Button",
5051
+ "Grid",
3353
5052
  "Heading",
3354
- "MenuItem",
3355
- "Navigation",
5053
+ "List",
5054
+ "PageSection",
3356
5055
  "PageShell",
3357
5056
  "Paragraph",
5057
+ "SectionIntro",
3358
5058
  "Stack",
3359
- "TitleBar"
5059
+ "Surface",
5060
+ "formatMoney"
3360
5061
  ]
3361
5062
  }
3362
5063
  ]
3363
5064
  },
3364
5065
  {
3365
- "id": "phone-navigation",
3366
- "title": "On a phone, a sidebar opens as a drawer and a list opens its detail",
3367
- "kind": "rule",
3368
- "level": "rule",
3369
- "area": "shell",
3370
- "situation": "A layout with a sidebar, a list beside its detail, or a side pane meets a phone screen.",
3371
- "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.",
3372
- "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.",
5066
+ "id": "product-cards",
5067
+ "title": "Product cards",
5068
+ "kind": "design",
5069
+ "level": "organism",
5070
+ "area": "marketing",
5071
+ "situation": "A maker lists its products on one page, and each product has its own site.",
3373
5072
  "do": [
3374
- "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`.",
3375
- "Close the drawer on a choice, Close, Escape, the scrim and when the window widens past `md`.",
3376
- "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.",
3377
- "Let a side pane take the whole content area on a phone, with a Close button.",
3378
- "Put a site's links in the same kind of menu, and keep at most one main action in the bar.",
3379
- "Give every place a way to be reached on a phone, even one that is only a link."
5073
+ "Follow the rule 'A marketing page asks for one main action, in the same words everywhere'. A list of products has no main action of its own: each card is a link, not a Button.",
5074
+ "Use `LinkCard` with `image`, `title`, `description` and `caption`, in `Grid columns={2}`.",
5075
+ "Pass `external`. The list stays open in its tab while the product opens in another, and a screen reader hears that the link opens in a new tab. This follows the case 'Site footer': a link to another site opens in a new tab and says so.",
5076
+ "Give each product a title that is its name, a description of one short line, and a caption that says what kind of product it is.",
5077
+ "Pass `alt: ''` for the picture when the title names the product, so a screen reader does not say it twice. Otherwise say what the picture shows.",
5078
+ "Open the section with `SectionIntro`, such as 'Products'.",
5079
+ "Keep to six cards or fewer."
3380
5080
  ],
3381
5081
  "dont": [
3382
- "Do not hide a link on a phone without a menu that holds it.",
3383
- "Do not show a sidebar beside the page on a phone, or squeeze a side pane beside the content.",
3384
- "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.",
3385
- "Do not add a bottom tab bar on the web.",
3386
- "Do not leave a drawer that Escape and a tap outside cannot close."
5082
+ "Do not put a Button inside a card. The card is the link.",
5083
+ "Do not link only the title or only the picture.",
5084
+ "Do not name the link 'Learn more'. The title is the name.",
5085
+ "Do not open a link to a page of your own site in a new tab."
3387
5086
  ],
3388
- "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."
5087
+ "native": "On Apple use a `Link` in a `List` row with an `Image`, which opens Safari. On Android use a card that opens a custom tab.",
5088
+ "options": [
5089
+ {
5090
+ "id": "grid",
5091
+ "title": "Cards in a grid",
5092
+ "useWhen": "A maker lists two to six products, and each one leads to its own site.",
5093
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport { Grid, PageSection } from 'oneslash-design-system/components/layout';\n\n// Stand-ins for a picture of each product. A real page passes a screenshot or the product's mark.\nconst notesPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 360'%3E%3Crect width='640' height='360' fill='%23efe9df'/%3E%3Crect x='200' y='50' width='240' height='260' rx='14' fill='%23ffffff'/%3E%3Crect x='224' y='84' width='120' height='12' rx='6' fill='%23aab8c6'/%3E%3Crect x='224' y='116' width='190' height='10' rx='5' fill='%23dfe7ef'/%3E%3Crect x='224' y='142' width='170' height='10' rx='5' fill='%23dfe7ef'/%3E%3Crect x='224' y='168' width='190' height='10' rx='5' fill='%23dfe7ef'/%3E%3Crect x='224' y='194' width='110' height='10' rx='5' fill='%23dfe7ef'/%3E%3C/svg%3E\";\nconst tasksPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 360'%3E%3Crect width='640' height='360' fill='%23e6efe9'/%3E%3Crect x='180' y='60' width='280' height='52' rx='12' fill='%23ffffff'/%3E%3Crect x='180' y='134' width='280' height='52' rx='12' fill='%23ffffff'/%3E%3Crect x='180' y='208' width='280' height='52' rx='12' fill='%23ffffff'/%3E%3Crect x='198' y='78' width='16' height='16' rx='4' fill='%232f6b4f'/%3E%3Crect x='198' y='152' width='16' height='16' rx='4' fill='%232f6b4f'/%3E%3Crect x='198' y='226' width='16' height='16' rx='4' fill='%23aab8c6'/%3E%3Crect x='230' y='82' width='160' height='8' rx='4' fill='%23dfe7ef'/%3E%3Crect x='230' y='156' width='120' height='8' rx='4' fill='%23dfe7ef'/%3E%3Crect x='230' y='230' width='140' height='8' rx='4' fill='%23dfe7ef'/%3E%3C/svg%3E\";\n\nexport default function ProductCardsGrid() {\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"products\" name=\"Products\" statement=\"Apps from Acme, each with its own site.\" />\n {/* Two across from md, one on a phone. Each card is one link to the product's own site, in a new tab, and says so to a screen reader. */}\n <Grid columns={2}>\n <LinkCard\n href=\"https://notes.acme.example\"\n title=\"Acme Notes\"\n description=\"Write a thing down once and find it again.\"\n caption=\"Notes app\"\n image={{ src: notesPicture, alt: '' }}\n external\n />\n <LinkCard\n href=\"https://tasks.acme.example\"\n title=\"Acme Tasks\"\n description=\"A short list for today, and a long one for later.\"\n caption=\"Task app\"\n image={{ src: tasksPicture, alt: '' }}\n external\n />\n </Grid>\n </PageSection>\n </PageShell>\n );\n}\n",
5094
+ "uses": [
5095
+ "Grid",
5096
+ "LinkCard",
5097
+ "PageSection",
5098
+ "PageShell",
5099
+ "SectionIntro"
5100
+ ]
5101
+ }
5102
+ ]
3389
5103
  },
3390
5104
  {
3391
5105
  "id": "profile-form",
@@ -3496,10 +5210,11 @@
3496
5210
  "kind": "design",
3497
5211
  "level": "organism",
3498
5212
  "area": "menu",
3499
- "situation": "A person changes the time range of a chart or a list on the same page, such as Week, Month or Quarter.",
5213
+ "situation": "A person changes the time range of the numbers or a list on the same page, such as Week, Month or Quarter.",
3500
5214
  "do": [
5215
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3501
5216
  "Use `SegmentedControl` with `size=\"small\"` and `aria-label=\"Range\"`: 'Week', 'Month', 'Quarter'.",
3502
- "Put it beside the heading of the chart or list it changes, with `width=\"fit\"` so it is as wide as its options.",
5217
+ "Put it beside the heading of the numbers or list it changes, with `width=\"fit\"` so it is as wide as its options.",
3503
5218
  "Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
3504
5219
  "Change the numbers in place and keep the page, the heading and the scroll position.",
3505
5220
  "Move between options with the arrow keys. They select as they move."
@@ -3516,14 +5231,15 @@
3516
5231
  "id": "segmented",
3517
5232
  "title": "Segmented control",
3518
5233
  "useWhen": "Two to four short choices change the numbers on one page, and one is always on.",
3519
- "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",
5234
+ "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",
3520
5235
  "uses": [
3521
5236
  "Center",
3522
5237
  "Cluster",
5238
+ "Grid",
3523
5239
  "Heading",
3524
- "Paragraph",
3525
5240
  "SegmentedControl",
3526
- "Stack"
5241
+ "Stack",
5242
+ "StatTile"
3527
5243
  ]
3528
5244
  }
3529
5245
  ]
@@ -3625,7 +5341,7 @@
3625
5341
  "id": "thumbs",
3626
5342
  "title": "Thumbs",
3627
5343
  "useWhen": "The team wants a signal and will not read reasons.",
3628
- "source": "'use client';\nimport { useEffect, 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 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 Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, 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: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackThumbs() {\n const [thumb, setThumb] = useState<Thumb>(null);\n const [thanks, setThanks] = useState(false);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n clearTimeout(thanksTimer.current);\n setThanks(value !== null);\n if (value !== null) thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</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(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
5344
+ "source": "'use client';\nimport { useEffect, 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 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 Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, 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: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackThumbs() {\n const [thumb, setThumb] = useState<Thumb>(null);\n const [thanks, setThanks] = useState(false);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n clearTimeout(thanksTimer.current);\n setThanks(value !== null);\n if (value !== null) thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</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(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3629
5345
  "uses": [
3630
5346
  "Button",
3631
5347
  "Center",
@@ -3646,7 +5362,7 @@
3646
5362
  "id": "with-reason",
3647
5363
  "title": "With reason",
3648
5364
  "useWhen": "Someone reads the reasons and acts on them.",
3649
- "source": "'use client';\nimport { useEffect, 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 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 Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, 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: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\n\n// A real app sends the reason with the mark, for the team to read.\nconst reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackWithReason() {\n // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.\n const [thumb, setThumb] = useState<Thumb>('down');\n const [thanks, setThanks] = useState(false);\n // The reason row, open after thumbs down until a reason or Skip is picked.\n const [asking, setAsking] = useState(true);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const thumbsDownButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n function showThanks() {\n clearTimeout(thanksTimer.current);\n setThanks(true);\n thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // Thumbs down asks what was wrong; the thanks waits for the answer.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n setAsking(value === 'down');\n clearTimeout(thanksTimer.current);\n setThanks(false);\n if (value === 'up') showThanks();\n }\n\n // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.\n function finish() {\n setAsking(false);\n showThanks();\n thumbsDownButton.current?.focus();\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setAsking(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</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(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton ref={thumbsDownButton} color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n {asking && (\n <Cluster gap=\"small\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">What was wrong?</Paragraph>\n {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:\n a real app groups the reasons under the question, named 'What was wrong?'. */}\n {reasons.map((r) => (\n <Tag key={r} variant=\"contained\" size=\"small\" toggle={false} label={r} onClick={finish} />\n ))}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Skip\" onClickButton={finish} />\n </Cluster>\n )}\n </Stack>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
5365
+ "source": "'use client';\nimport { useEffect, 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 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 Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, 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: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\n\n// A real app sends the reason with the mark, for the team to read.\nconst reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackWithReason() {\n // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.\n const [thumb, setThumb] = useState<Thumb>('down');\n const [thanks, setThanks] = useState(false);\n // The reason row, open after thumbs down until a reason or Skip is picked.\n const [asking, setAsking] = useState(true);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const thumbsDownButton = 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 // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n function showThanks() {\n clearTimeout(thanksTimer.current);\n setThanks(true);\n thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // Thumbs down asks what was wrong; the thanks waits for the answer.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n setAsking(value === 'down');\n clearTimeout(thanksTimer.current);\n setThanks(false);\n if (value === 'up') showThanks();\n }\n\n // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.\n function finish() {\n setAsking(false);\n showThanks();\n thumbsDownButton.current?.focus();\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setAsking(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</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(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton ref={thumbsDownButton} color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n {asking && (\n <Cluster gap=\"small\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">What was wrong?</Paragraph>\n {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:\n a real app groups the reasons under the question, named 'What was wrong?'. */}\n {reasons.map((r) => (\n <Tag key={r} variant=\"contained\" size=\"small\" toggle={false} label={r} onClick={finish} />\n ))}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Skip\" onClickButton={finish} />\n </Cluster>\n )}\n </Stack>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3650
5366
  "uses": [
3651
5367
  "Button",
3652
5368
  "Center",
@@ -3826,6 +5542,62 @@
3826
5542
  }
3827
5543
  ]
3828
5544
  },
5545
+ {
5546
+ "id": "section-index",
5547
+ "title": "Section index",
5548
+ "kind": "design",
5549
+ "level": "organism",
5550
+ "area": "content",
5551
+ "situation": "A section of a site, such as the guides, has its own first page that shows the places inside it, so a person can pick one.",
5552
+ "do": [
5553
+ "Use `PageHeader` with `level={1}`: the section's name is the one level 1 heading, with a `lede` of one sentence.",
5554
+ "Put the places in a `Grid columns={3}` for `cards`: three across from the medium breakpoint, one on a phone. Make each a `LinkCard` with a `title` and a `description` of one short line.",
5555
+ "Write the title as the name of the page it goes to, and the description as what a person finds there, not as a call to action.",
5556
+ "Keep a card that leaves the site, a `LinkCard` with `external`, in a group of its own, so a person is not sent away by surprise.",
5557
+ "Group the places under level 2 `SectionIntro`s for `list`, and put the places of each group in a `List`, each a `Link` with `size=\"subtitle1\"` and a `Paragraph` line under it. Put the places a new person needs first.",
5558
+ "Order the places the way a person does the work, not alphabetically, unless there are more than about twenty.",
5559
+ "Pass `image` to the `LinkCard` when a place has an image, with alt text that says what it shows, or `alt=\"\"` when the title says it all."
5560
+ ],
5561
+ "dont": [
5562
+ "Do not put more than about nine cards in a grid. A person cannot compare more, so use `list`.",
5563
+ "Do not repeat the section name in every title.",
5564
+ "Do not write a description that repeats its title.",
5565
+ "Do not make a card out of a place with nothing in it yet. Leave it out until it has a page.",
5566
+ "Do not wrap a `LinkCard` in a second link or put a Button inside it."
5567
+ ],
5568
+ "native": "On Apple use a `List` of `NavigationLink` rows with a subtitle, grouped in `Section`s. On Android use a `LazyColumn` of list items with supporting text, or a grid of cards for a few places.",
5569
+ "options": [
5570
+ {
5571
+ "id": "cards",
5572
+ "title": "Cards with a line each",
5573
+ "useWhen": "Up to about nine places, each with a short line that says what is there.",
5574
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport LinkCard from 'oneslash-design-system/components/linkCard';\nimport { Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Six places, each with a line that says what is there. A real site lists its own pages.\nconst guides = [\n { id: 'start', title: 'Get started', line: 'Name your workspace and add the first people.' },\n { id: 'channels', title: 'Channels', line: 'One place for the talk about each subject.' },\n { id: 'tasks', title: 'Tasks', line: 'Give work an owner and a due date.' },\n { id: 'notes', title: 'Notes', line: 'Write a decision once and find it later.' },\n { id: 'agent', title: 'The agent', line: 'Ask a question and see the sources it used.' },\n { id: 'billing', title: 'Plans and billing', line: 'Change plan and download invoices.' },\n];\n\nexport default function SectionIndexCards() {\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Guides\" lede=\"How to do each thing in Acme, one page for each.\" />\n {/* Three across from md, one on a phone. Every card is one link, named by its title and its line. */}\n <Grid columns={3}>\n {guides.map((g) => (\n <LinkCard key={g.id} href={`#${g.id}`} title={g.title} description={g.line} />\n ))}\n </Grid>\n </Stack>\n </PageShell>\n );\n}\n",
5575
+ "uses": [
5576
+ "Grid",
5577
+ "LinkCard",
5578
+ "PageHeader",
5579
+ "PageShell",
5580
+ "Stack"
5581
+ ]
5582
+ },
5583
+ {
5584
+ "id": "list",
5585
+ "title": "A list of links in groups",
5586
+ "useWhen": "More places than nine, or names that say enough without a line of their own.",
5587
+ "source": "'use client';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport PageHeader from 'oneslash-design-system/components/pageHeader';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Link from 'oneslash-design-system/components/link';\nimport List from 'oneslash-design-system/components/list';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// Many places, in groups. A real site builds this from its own list of pages.\nconst groups = [\n {\n id: 'section-index-start',\n name: 'Start here',\n pages: [\n { id: 'workspace', title: 'Make a workspace', line: 'Name it and choose a plan.' },\n { id: 'invite', title: 'Invite people', line: 'Invite by email and choose what each person can do.' },\n { id: 'tour', title: 'A tour of Acme', line: 'Channels, tasks, notes and the agent in one page.' },\n ],\n },\n {\n id: 'section-index-work',\n name: 'Everyday work',\n pages: [\n { id: 'channels', title: 'Channels', line: 'One place for the talk about each subject.' },\n { id: 'threads', title: 'Threads', line: 'Reply to one message without filling the channel.' },\n { id: 'tasks', title: 'Tasks', line: 'Give work an owner and a due date.' },\n { id: 'notes', title: 'Notes', line: 'Write a decision once and find it later.' },\n { id: 'search', title: 'Search', line: 'Find a message, a note or a file from one box.' },\n ],\n },\n {\n id: 'section-index-admin',\n name: 'Run a workspace',\n pages: [\n { id: 'members', title: 'Members and roles', line: 'Who can read, write and change settings.' },\n { id: 'billing', title: 'Plans and billing', line: 'Change plan and download invoices.' },\n { id: 'export', title: 'Export your notes', line: 'Take a note or a whole workspace as PDF.' },\n { id: 'delete', title: 'Delete a workspace', line: 'What is removed, and what you can get back.' },\n ],\n },\n];\n\nexport default function SectionIndexList() {\n return (\n <PageShell>\n <Stack gap=\"giant\">\n <PageHeader level={1} title=\"Guides\" lede=\"How to do each thing in Acme, one page for each.\" />\n {groups.map((group) => (\n <PageSection key={group.id} gap=\"xlarge\">\n {/* The group's name is the level 2 heading. Each link has its line under it. */}\n <SectionIntro id={group.id} name={group.name} />\n <List\n items={group.pages.map((p) => (\n <Stack key={p.id} gap=\"small\">\n <Link href={`#${p.id}`} size=\"subtitle1\">{p.title}</Link>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.line}</Paragraph>\n </Stack>\n ))}\n />\n </PageSection>\n ))}\n </Stack>\n </PageShell>\n );\n}\n",
5588
+ "uses": [
5589
+ "Link",
5590
+ "List",
5591
+ "PageHeader",
5592
+ "PageSection",
5593
+ "PageShell",
5594
+ "Paragraph",
5595
+ "SectionIntro",
5596
+ "Stack"
5597
+ ]
5598
+ }
5599
+ ]
5600
+ },
3829
5601
  {
3830
5602
  "id": "set-new-password",
3831
5603
  "title": "Set new password",
@@ -3922,7 +5694,7 @@
3922
5694
  "id": "top-tabs",
3923
5695
  "title": "Tabs across the top",
3924
5696
  "useWhen": "Four areas or fewer, with short names that fit on a phone.",
3925
- "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",
5697
+ "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",
3926
5698
  "uses": [
3927
5699
  "Button",
3928
5700
  "Center",
@@ -3938,7 +5710,8 @@
3938
5710
  "Switch",
3939
5711
  "Tab",
3940
5712
  "TabsContainer",
3941
- "TextField"
5713
+ "TextField",
5714
+ "formatMoney"
3942
5715
  ]
3943
5716
  },
3944
5717
  {
@@ -4288,7 +6061,7 @@
4288
6061
  "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.",
4289
6062
  "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.",
4290
6063
  "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'.",
4291
- "Open the theme menu as the case 'Theme switcher' says, and name the search `IconButton` 'Search'."
6064
+ "Open the theme menu as the case 'Theme switcher' says, and open search as the case 'Site search' says."
4292
6065
  ],
4293
6066
  "dont": [
4294
6067
  "Do not show more than five links in the bar.",
@@ -4335,6 +6108,53 @@
4335
6108
  }
4336
6109
  ]
4337
6110
  },
6111
+ {
6112
+ "id": "site-search",
6113
+ "title": "Site search",
6114
+ "kind": "design",
6115
+ "level": "organism",
6116
+ "area": "content",
6117
+ "situation": "A site has many pages, and a person wants to reach one by its name or by a word in it, from any page.",
6118
+ "do": [
6119
+ "Put a 'Search' `Button` with `decoIcon=\"Search\"` in the `SiteHeader`, in `phoneAction`, so it stays in the bar at every width. Give it `aria-haspopup=\"dialog\"` and `aria-keyshortcuts=\"Meta+K Control+K\"`.",
6120
+ "Put Search before 'Sign Up' in `phoneAction` on a site with a main action, as an `IconButton` named 'Search', so both fit on a phone.",
6121
+ "Open the same dialog with Cmd+K, or Ctrl+K on Windows, using `useHotkey('k', …)`. The shortcut does nothing while a person types in a field. Say it on the page in words, as the case 'Quick switcher' does.",
6122
+ "Use `SearchDialog`. Keep the query and the results in your page and pass them in with `status`. Focus stays in the field; the arrow keys move the highlight, Enter follows the highlighted link and Escape closes it.",
6123
+ "Group the results under names such as 'Components' and 'Cases', and give each a `secondLabel` that says where it is and an `excerpt` of the text around the match. The words typed are marked in the title and the excerpt, as written, so 'c++ (beta)' is not read as a pattern.",
6124
+ "Set `status` to 'loading' when you ask and 'done' when the answer comes. After 300 ms the dialog says 'Searching' once and keeps the old results, marked `aria-busy`. A search that is faster than that shows no flash.",
6125
+ "Number each request and drop a reply for an older query. Keep timers in a ref and clear them on unmount.",
6126
+ "Show `recent` places before anything is typed, at most six, newest first.",
6127
+ "Let the dialog say what was searched when nothing matches, with 'Clear Search' that puts focus back in the field, as the case 'Empty search' says. Set `status` to 'error' when the request fails: it says 'Search is not working right now.' with 'Try Again'; pass `onRetry`.",
6128
+ "Use the case 'Quick switcher' instead inside an app, with workspaces, channels and people."
6129
+ ],
6130
+ "dont": [
6131
+ "Do not put the Search Button in `actions`. On a phone it moves into the menu, which closes when it is chosen, so the dialog has no Button to give focus back to.",
6132
+ "Do not search on every key with no wait for the answer. Drop an answer that is out of date instead.",
6133
+ "Do not build the dialog, the list and the keys by hand. `SearchDialog` does the roles, the focus and the status.",
6134
+ "Do not write the match as a pattern. A person may type brackets or a plus sign.",
6135
+ "Do not show a spinner in place of the results. Keep the old results on screen while the new ones load.",
6136
+ "Do not close the dialog when 'Clear Search' is pressed. A person who cleared the words wants to search again."
6137
+ ],
6138
+ "native": "On Apple use `searchable` on a `NavigationStack`, with `searchSuggestions` for recent places and `searchScopes` for the groups. On Android use a `SearchBar` with a `DockedSearchBar` or a full-screen search view.",
6139
+ "options": [
6140
+ {
6141
+ "id": "dialog",
6142
+ "title": "Search in a dialog",
6143
+ "useWhen": "A site with many pages, searched from anywhere.",
6144
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport SearchDialog, { type SearchGroup, type SearchResult } from 'oneslash-design-system/components/searchDialog';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport Button from 'oneslash-design-system/components/button';\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 Entry = SearchResult & { group: 'Components' | 'Cases'; text: string };\n\n// A real site asks its server, which has every page. These are the pages of a made-up docs site.\nconst entries: Entry[] = [\n { id: 'button', group: 'Components', title: 'Button', secondLabel: 'Components', href: '#button', iconName: 'MousePointerClick', text: 'The control that starts an action, in four sizes.' },\n { id: 'tag', group: 'Components', title: 'Tag', secondLabel: 'Components', href: '#tag', iconName: 'Tag', text: 'A short label for a state, such as Paid or Draft.' },\n { id: 'tabs', group: 'Components', title: 'Tabs', secondLabel: 'Components', href: '#tabs', iconName: 'PanelTop', text: 'Switch between views of one thing on one page.' },\n { id: 'table', group: 'Components', title: 'Table', secondLabel: 'Components', href: '#table', iconName: 'Table', text: 'Rows and columns that scroll inside their own region.' },\n { id: 'accordion', group: 'Components', title: 'Accordion', secondLabel: 'Components', href: '#accordion', iconName: 'ChevronsUpDown', text: 'Headings that open a panel under them.' },\n { id: 'faq', group: 'Cases', title: 'FAQ', secondLabel: 'Cases', href: '#faq', iconName: 'CircleHelp', text: 'Answer the questions a visitor asks before signing up.' },\n { id: 'pricing', group: 'Cases', title: 'Pricing section', secondLabel: 'Cases', href: '#pricing', iconName: 'CreditCard', text: 'Show the plans side by side with one price each.' },\n { id: 'login', group: 'Cases', title: 'Login page', secondLabel: 'Cases', href: '#login', iconName: 'LogIn', text: 'Let a person log in with an email or a provider.' },\n { id: 'tabbed', group: 'Cases', title: 'Tabbed panels', secondLabel: 'Cases', href: '#tabbed', iconName: 'PanelTop', text: 'Four views of one thing, and a visitor reads one.' },\n];\n\nconst SEARCH_MS = 300;\n\n// A stand-in for the request. A real site calls its server here and may fail.\nfunction searchPages(query: string, keep: (t: ReturnType<typeof setTimeout>) => void): Promise<SearchGroup[]> {\n return new Promise((resolve) => {\n keep(setTimeout(() => {\n const words = query.toLowerCase().split(/\\s+/).filter(Boolean);\n const found = entries.filter((e) => words.every((w) => `${e.title} ${e.text}`.toLowerCase().includes(w)));\n const groups = (['Components', 'Cases'] as const)\n .map((label) => ({ label, items: found.filter((e) => e.group === label).map(({ group, text, ...item }) => ({ ...item, excerpt: text })) }))\n .filter((g) => g.items.length > 0);\n resolve(groups);\n }, SEARCH_MS));\n });\n}\n\n// Visited pages, most recent first. A real site keeps them for the person.\nconst recent: SearchResult[] = entries.slice(0, 3).map(({ group, text, ...item }) => item);\n\nexport default function SiteSearchDialog() {\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const [groups, setGroups] = useState<SearchGroup[]>([]);\n const [status, setStatus] = useState<'idle' | 'loading' | 'done' | 'error'>('idle');\n // Each request has a number; only the newest one may answer.\n const latest = useRef(0);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function run(next: string) {\n const id = ++latest.current;\n if (next.trim() === '') {\n setStatus('idle');\n setGroups([]);\n return;\n }\n setStatus('loading');\n // An older request's timer is cleared, so only one is ever pending and unmount clears it\n searchPages(next, (t) => {\n clearTimeout(timer.current);\n timer.current = t;\n })\n .then((found) => {\n // A reply for an older query is dropped\n if (id !== latest.current) return;\n setGroups(found);\n setStatus('done');\n })\n .catch(() => {\n if (id !== latest.current) return;\n setStatus('error');\n });\n }\n\n function change(next: string) {\n setQuery(next);\n run(next);\n }\n\n function show() {\n setQuery('');\n run('');\n setOpen(true);\n }\n\n // Cmd+K, or Ctrl+K on Windows, from anywhere on the page except a text field\n useHotkey('k', () => {\n if (!open) show();\n });\n\n return (\n <>\n {/* The Search Button is the main action of the bar, so it stays beside the brand at every width. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme' }}\n links={[\n { label: 'Guides', href: '#guides' },\n { label: 'Components', href: '#components', current: true },\n { label: 'Cases', href: '#cases' },\n ]}\n phoneAction={\n <Button\n size=\"medium\"\n type=\"secondary\"\n state=\"enabled\"\n label=\"Search\"\n decoIcon=\"Search\"\n aria-haspopup=\"dialog\"\n aria-keyshortcuts=\"Meta+K Control+K\"\n onClickButton={show}\n />\n }\n mainId=\"site-search-main\"\n />\n <PageShell id=\"site-search-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Components</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Press Cmd+K, or Ctrl+K on Windows, to search every page.</Paragraph>\n </Stack>\n </PageShell>\n <SearchDialog\n isOpen={open}\n onClose={() => setOpen(false)}\n query={query}\n onQueryChange={change}\n groups={groups}\n status={status}\n onRetry={() => run(query)}\n recent={recent}\n placeholder=\"Search components and cases\"\n />\n </>\n );\n}\n",
6145
+ "uses": [
6146
+ "Button",
6147
+ "Heading",
6148
+ "PageShell",
6149
+ "Paragraph",
6150
+ "SearchDialog",
6151
+ "SiteHeader",
6152
+ "Stack",
6153
+ "useHotkey"
6154
+ ]
6155
+ }
6156
+ ]
6157
+ },
4338
6158
  {
4339
6159
  "id": "slash-command-list",
4340
6160
  "title": "Command list",
@@ -4385,6 +6205,126 @@
4385
6205
  }
4386
6206
  ]
4387
6207
  },
6208
+ {
6209
+ "id": "stat-row",
6210
+ "title": "Stat row",
6211
+ "kind": "design",
6212
+ "level": "organism",
6213
+ "area": "dashboard",
6214
+ "situation": "A page opens with the few numbers that say how things are going, counted over one range.",
6215
+ "do": [
6216
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'. Use `StatTile`, which does.",
6217
+ "Put the tiles in `<Grid compact columns={4}>`: two across on a phone, up to four from md up.",
6218
+ "Use four tiles at most. A fifth number goes in a table.",
6219
+ "Make each tile count one thing, with its unit in the label or the `unit` prop: 'New comments', 'Responses'.",
6220
+ "Count every tile over the same range, and say the range in the heading above the row: 'This week'.",
6221
+ "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.",
6222
+ "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'.",
6223
+ "Pass `format` for money, a percent, a size or a time, such as `format=\"money\"`. Do not format a number by hand.",
6224
+ "Give the one number that matters most `size=\"large\"` and a row of its own, with the others under it."
6225
+ ],
6226
+ "dont": [
6227
+ "Do not show 0 while a number loads or when it is missing.",
6228
+ "Do not color a change green or red. More is not good or bad by itself.",
6229
+ "Do not put more than four tiles in a row, or two things in one tile.",
6230
+ "Do not draw a chart or a sparkline in a tile. A trend is the change line.",
6231
+ "Do not box each tile in a card. The row sits on the page."
6232
+ ],
6233
+ "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.",
6234
+ "options": [
6235
+ {
6236
+ "id": "tiles",
6237
+ "title": "Tiles of equal weight",
6238
+ "useWhen": "Two to four numbers matter about the same, over one range.",
6239
+ "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",
6240
+ "uses": [
6241
+ "Button",
6242
+ "Center",
6243
+ "Cluster",
6244
+ "Grid",
6245
+ "Heading",
6246
+ "Stack",
6247
+ "StatTile"
6248
+ ]
6249
+ },
6250
+ {
6251
+ "id": "featured",
6252
+ "title": "One number first",
6253
+ "useWhen": "One number matters most, with two others under it.",
6254
+ "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",
6255
+ "uses": [
6256
+ "Center",
6257
+ "Grid",
6258
+ "Heading",
6259
+ "Stack",
6260
+ "StatTile"
6261
+ ]
6262
+ }
6263
+ ]
6264
+ },
6265
+ {
6266
+ "id": "status-label",
6267
+ "title": "Status in a row",
6268
+ "kind": "design",
6269
+ "level": "organism",
6270
+ "area": "dashboard",
6271
+ "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.",
6272
+ "do": [
6273
+ "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.",
6274
+ "Show the word every time. The dot alone means nothing to a screen reader or to a person who cannot tell the colors apart.",
6275
+ "Use `variant=\"dot\"` for a state that changes and may need the person: 'Past due', 'Canceling', 'Connected'.",
6276
+ "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.",
6277
+ "Use `variant=\"textOnly\"` with no color for a settled record: 'Paid', 'Refunded'.",
6278
+ "Write one word or two, in sentence case: 'Past due', 'Needs reconnecting'.",
6279
+ "Put the Tag in a 'Status' column, or at the end of the row's text. It is not clickable."
6280
+ ],
6281
+ "dont": [
6282
+ "Do not show a dot with no word, or a color with no word.",
6283
+ "Do not color a settled state. A green 'Paid' on every row hides the one red 'Past due'.",
6284
+ "Do not write the word in Title Case ('Past Due') or as a sentence ('Your payment is late').",
6285
+ "Do not fill the Tag with `variant=\"contained\"` for a status in a row. A filled Tag is a label the person picks.",
6286
+ "Do not make the Tag a button. A status that opens something is a row action, in the More menu.",
6287
+ "Do not draw the dot by hand."
6288
+ ],
6289
+ "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`.",
6290
+ "options": [
6291
+ {
6292
+ "id": "dot",
6293
+ "title": "A dot and a word",
6294
+ "useWhen": "The state changes and may need the person: Past due, Canceling, Connected.",
6295
+ "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",
6296
+ "uses": [
6297
+ "Center",
6298
+ "Heading",
6299
+ "Stack",
6300
+ "TableCell",
6301
+ "TableContainer",
6302
+ "TableHeader",
6303
+ "TableHeaderCell",
6304
+ "TableRow",
6305
+ "Tag"
6306
+ ]
6307
+ },
6308
+ {
6309
+ "id": "text",
6310
+ "title": "A word alone",
6311
+ "useWhen": "The record is settled and nothing is left to do: Paid, Refunded.",
6312
+ "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",
6313
+ "uses": [
6314
+ "Center",
6315
+ "Heading",
6316
+ "Stack",
6317
+ "TableCell",
6318
+ "TableContainer",
6319
+ "TableHeader",
6320
+ "TableHeaderCell",
6321
+ "TableRow",
6322
+ "Tag",
6323
+ "formatMoney"
6324
+ ]
6325
+ }
6326
+ ]
6327
+ },
4388
6328
  {
4389
6329
  "id": "success-feedback",
4390
6330
  "title": "Success shows where the person is looking",
@@ -4410,6 +6350,52 @@
4410
6350
  ],
4411
6351
  "native": "On Apple there is no toast. Show the result in place."
4412
6352
  },
6353
+ {
6354
+ "id": "tabbed-panels",
6355
+ "title": "Tabbed panels",
6356
+ "kind": "design",
6357
+ "level": "organism",
6358
+ "area": "marketing",
6359
+ "situation": "A page shows several views of one thing, and a visitor reads one of them at a time.",
6360
+ "do": [
6361
+ "Put the section's name in `SectionIntro`, so the section has a level 2 heading. Give the panel's title a level 3 `Heading`.",
6362
+ "Use `TabsContainer` with one `Tab` for each view. Write each label in Title Case, as one short word, and use `size=\"small\"` so four fit on a phone.",
6363
+ "Give each `Tab` an `id` and `controls`, and put each view in a `TabPanel` named by its Tab. Every panel is in the page; only the selected one shows. Name the tablist with `aria-labelledby` on `TabsContainer`.",
6364
+ "Keep the selected tab in state. Put the view most visitors need first.",
6365
+ "Keep two to five tabs, and four when you can: they fit on a phone. A fifth scrolls inside the row and the page does not.",
6366
+ "Give every panel the same shape: a title, a line and a short `List`, so the page does not jump when a visitor changes tab.",
6367
+ "Use stacked sections, each with its own level 2 heading, for more than five views or for views everyone must read.",
6368
+ "Use `SegmentedControl` instead when the choice changes a value, as the case 'Range switch' says."
6369
+ ],
6370
+ "dont": [
6371
+ "Do not hide something a visitor must read behind a tab.",
6372
+ "Do not use these tabs for a site's sections or an app's areas. Those are `Tab`s with `href`, as the cases 'Site header' and 'Settings page' say.",
6373
+ "Do not give a tab an icon or a long label. It will not fit on a phone.",
6374
+ "Do not change the tab on a timer.",
6375
+ "Do not nest tabs inside a panel."
6376
+ ],
6377
+ "native": "On Apple use a segmented `Picker` for two to five views, and a `TabView` only for the app's own areas. On Android use a `TabRow`.",
6378
+ "options": [
6379
+ {
6380
+ "id": "tabs",
6381
+ "title": "Tabs over one panel",
6382
+ "useWhen": "There are two to five views of one thing, and a visitor reads one.",
6383
+ "source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport TabPanel from 'oneslash-design-system/components/tabPanel';\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 { PageSection, Stack } from 'oneslash-design-system/components/layout';\n\n// Four views of one thing, and a visitor reads one. The first is the one most visitors need.\nconst views = [\n { id: 'channels', label: 'Channels', title: 'One place for each subject', line: 'A channel holds the talk about one team or project.', points: ['Everyone in a channel sees every message.', 'Pin the messages people need again.', 'Turn a message into a task when it needs an owner.'] },\n { id: 'tasks', label: 'Tasks', title: 'A task and its talk together', line: 'A task keeps its owner, its status and its talk together.', points: ['Give a task one owner and one due date.', 'Reply in the task, not in the channel.', 'Close the task when the work is done.'] },\n { id: 'notes', label: 'Notes', title: 'Notes the whole team can search', line: 'Write a decision once and find it later.', points: ['Link a note to the task it came from.', 'Search every note from one box.', 'Export a note to PDF on Pro and Business.'] },\n { id: 'agent', label: 'Agent', title: 'Answers with their sources', line: 'Ask the agent a question in any channel or task.', points: ['It says which notes and messages it used.', 'It never reads a channel you are not in.', 'Each reply counts as one AI agent response.'] },\n];\n\nexport default function TabbedPanelsTabs() {\n const [selected, setSelected] = useState('channels');\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"how-it-works\" name=\"How it works\" statement=\"Four parts, each for one kind of work.\" />\n <Stack gap=\"xlarge\">\n {/* Title Case, one short word each. The tablist is named by the section's heading, and each Tab controls its panel. */}\n <TabsContainer aria-labelledby=\"how-it-works\">\n {views.map((v) => (\n <Tab key={v.id} id={`tabbed-panels-tab-${v.id}`} controls={`tabbed-panels-panel-${v.id}`} size=\"small\" label={v.label} isSelected={v.id === selected} onClickTab={() => setSelected(v.id)} />\n ))}\n </TabsContainer>\n {/* Every panel is in the page. Only the selected one shows. */}\n {views.map((v) => (\n <TabPanel key={v.id} id={`tabbed-panels-panel-${v.id}`} labelledBy={`tabbed-panels-tab-${v.id}`} selected={v.id === selected}>\n <Stack gap=\"medium\">\n <Heading level={3} size=\"h5\">{v.title}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">{v.line}</Paragraph>\n <List items={v.points} marker=\"dot\" />\n </Stack>\n </TabPanel>\n ))}\n </Stack>\n </PageSection>\n </PageShell>\n );\n}\n",
6384
+ "uses": [
6385
+ "Heading",
6386
+ "List",
6387
+ "PageSection",
6388
+ "PageShell",
6389
+ "Paragraph",
6390
+ "SectionIntro",
6391
+ "Stack",
6392
+ "Tab",
6393
+ "TabPanel",
6394
+ "TabsContainer"
6395
+ ]
6396
+ }
6397
+ ]
6398
+ },
4413
6399
  {
4414
6400
  "id": "tag-filter",
4415
6401
  "title": "Tag filter",
@@ -4703,12 +6689,13 @@
4703
6689
  "situation": "A person reaches something their plan does not include, or a limit of their plan.",
4704
6690
  "do": [
4705
6691
  "Say what is locked and which plan unlocks it: 'Exporting to PDF is part of the Pro plan.'",
4706
- "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.\"",
6692
+ "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.\"",
4707
6693
  "Offer 'Not Now' as a tertiary Button, then 'Upgrade to Pro' as a primary Button.",
4708
6694
  "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'.",
4709
6695
  "Title the Modal 'Upgrade to Pro' only for a person who can upgrade. For everyone else, title it 'Pro Feature'.",
4710
6696
  "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, and Escape or a click outside means 'Not Now'.",
4711
6697
  "Put the notice where the control was, with the same two Buttons, when a limit is reached inside a flow.",
6698
+ "At a limit, show a `Progress` above the notice that says 'Limit reached', and point it at the notice with `aria-describedby`.",
4712
6699
  "Follow the rule 'An agent refuses clearly' too when the agent is the one refused."
4713
6700
  ],
4714
6701
  "dont": [
@@ -4724,7 +6711,7 @@
4724
6711
  "id": "modal",
4725
6712
  "title": "Explain in a Modal",
4726
6713
  "useWhen": "The person pressed something their plan does not include.",
4727
- "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",
6714
+ "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",
4728
6715
  "uses": [
4729
6716
  "Button",
4730
6717
  "Center",
@@ -4732,26 +6719,120 @@
4732
6719
  "Heading",
4733
6720
  "Modal",
4734
6721
  "Paragraph",
4735
- "Stack"
6722
+ "Stack",
6723
+ "formatMoney"
4736
6724
  ]
4737
6725
  },
4738
6726
  {
4739
6727
  "id": "inline",
4740
6728
  "title": "Replace the control",
4741
6729
  "useWhen": "A limit was reached inside a flow. The notice takes the place of the control that hit it.",
4742
- "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",
6730
+ "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",
4743
6731
  "uses": [
4744
6732
  "Button",
4745
6733
  "Center",
4746
6734
  "Cluster",
4747
6735
  "Heading",
4748
6736
  "Paragraph",
6737
+ "Progress",
4749
6738
  "Stack",
4750
6739
  "Surface",
4751
6740
  "TextField"
4752
6741
  ]
4753
6742
  }
4754
6743
  ]
6744
+ },
6745
+ {
6746
+ "id": "usage-meters",
6747
+ "title": "Usage against limits",
6748
+ "kind": "design",
6749
+ "level": "organism",
6750
+ "area": "dashboard",
6751
+ "situation": "A plan limits some things, such as AI agent responses, members and storage. The admin checks how close the workspace is.",
6752
+ "do": [
6753
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
6754
+ "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.",
6755
+ "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.",
6756
+ "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`.",
6757
+ "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%.",
6758
+ "Give a plan with no limit `max={null}`: the meter becomes text only, '3 members, no limit', with no bar.",
6759
+ "Show who used it in a sorted table under the meters, most first, with exact numbers and the numbers right-aligned.",
6760
+ "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.",
6761
+ "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.",
6762
+ "Show a member who cannot change the cap the amount as text with the line 'Only admins can change it.'"
6763
+ ],
6764
+ "dont": [
6765
+ "Do not write a meter as '12 / 1,000'. Write '12 of 1,000 responses'.",
6766
+ "Do not show a limit by color alone. Say 'Limit reached' or 'Almost at the limit'.",
6767
+ "Do not draw the bar by hand. Use `Progress`.",
6768
+ "Do not show a bar for a plan with no limit, or write 'Unlimited' beside a number.",
6769
+ "Do not round a cost to four decimals. Show money with two: '$18.40'.",
6770
+ "Do not show the upgrade notice for a limit that is not reached.",
6771
+ "Do not show a cap field to a person who cannot set it."
6772
+ ],
6773
+ "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.",
6774
+ "options": [
6775
+ {
6776
+ "id": "meters",
6777
+ "title": "A meter for each limit",
6778
+ "useWhen": "The plan has a few limits and the admin needs to see how close each one is.",
6779
+ "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",
6780
+ "uses": [
6781
+ "Button",
6782
+ "Center",
6783
+ "Cluster",
6784
+ "Paragraph",
6785
+ "Progress",
6786
+ "SettingsSection",
6787
+ "Stack",
6788
+ "Surface",
6789
+ "formatBytes"
6790
+ ]
6791
+ },
6792
+ {
6793
+ "id": "by-person",
6794
+ "title": "Who used it, under the meters",
6795
+ "useWhen": "People share one pool, and the admin asks who used it.",
6796
+ "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",
6797
+ "uses": [
6798
+ "Button",
6799
+ "Center",
6800
+ "Cluster",
6801
+ "Heading",
6802
+ "Paragraph",
6803
+ "Progress",
6804
+ "SettingsSection",
6805
+ "Stack",
6806
+ "Surface",
6807
+ "TableCell",
6808
+ "TableContainer",
6809
+ "TableHeader",
6810
+ "TableHeaderCell",
6811
+ "TableRow",
6812
+ "formatCount"
6813
+ ]
6814
+ },
6815
+ {
6816
+ "id": "with-cap",
6817
+ "title": "Billed by the amount, with a cap",
6818
+ "useWhen": "Use is billed by the amount, and the admin sets a monthly spend cap that pauses use when it is reached.",
6819
+ "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",
6820
+ "uses": [
6821
+ "Alert",
6822
+ "Button",
6823
+ "Center",
6824
+ "Cluster",
6825
+ "Form",
6826
+ "FormField",
6827
+ "Paragraph",
6828
+ "Progress",
6829
+ "SettingsSection",
6830
+ "Stack",
6831
+ "TextField",
6832
+ "formatMoney"
6833
+ ]
6834
+ }
6835
+ ]
4755
6836
  }
4756
6837
  ]
4757
6838
  }