oneslash-design-system 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +28 -4
  3. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  4. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  5. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  6. package/dist/cases/billing-page/self-serve.jsx +134 -0
  7. package/dist/cases/billing-page.md +247 -0
  8. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  9. package/dist/cases/breakdown-list/bars.jsx +47 -0
  10. package/dist/cases/breakdown-list/table.d.ts +1 -0
  11. package/dist/cases/breakdown-list/table.jsx +69 -0
  12. package/dist/cases/breakdown-list.md +158 -0
  13. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  14. package/dist/cases/composer-limit/notice.jsx +3 -3
  15. package/dist/cases/composer-limit.md +8 -8
  16. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  17. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  18. package/dist/cases/dashboard/work-first.d.ts +1 -0
  19. package/dist/cases/dashboard/work-first.jsx +165 -0
  20. package/dist/cases/dashboard.md +507 -0
  21. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  22. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  23. package/dist/cases/data-table-page/paged.d.ts +1 -0
  24. package/dist/cases/data-table-page/paged.jsx +284 -0
  25. package/dist/cases/data-table-page.md +771 -0
  26. package/dist/cases/invoice-list/table.d.ts +1 -0
  27. package/dist/cases/invoice-list/table.jsx +64 -0
  28. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  29. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  30. package/dist/cases/invoice-list.md +237 -0
  31. package/dist/cases/load-failure/inline.jsx +2 -2
  32. package/dist/cases/load-failure.md +2 -2
  33. package/dist/cases/members-list/rows.jsx +2 -1
  34. package/dist/cases/members-list/table.jsx +8 -9
  35. package/dist/cases/members-list.md +12 -13
  36. package/dist/cases/number-format.md +36 -0
  37. package/dist/cases/paged-card/pager.d.ts +1 -0
  38. package/dist/cases/paged-card/pager.jsx +41 -0
  39. package/dist/cases/paged-card/see-all.d.ts +1 -0
  40. package/dist/cases/paged-card/see-all.jsx +34 -0
  41. package/dist/cases/paged-card.md +147 -0
  42. package/dist/cases/payment-method/none.d.ts +1 -0
  43. package/dist/cases/payment-method/none.jsx +17 -0
  44. package/dist/cases/payment-method/on-file.d.ts +1 -0
  45. package/dist/cases/payment-method/on-file.jsx +92 -0
  46. package/dist/cases/payment-method.md +182 -0
  47. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  48. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  49. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  50. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  51. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  52. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  53. package/dist/cases/plan-change-confirm.md +261 -0
  54. package/dist/cases/plan-picker/cards.d.ts +1 -0
  55. package/dist/cases/plan-picker/cards.jsx +97 -0
  56. package/dist/cases/plan-picker/list.d.ts +1 -0
  57. package/dist/cases/plan-picker/list.jsx +103 -0
  58. package/dist/cases/plan-picker.md +297 -0
  59. package/dist/cases/range-switch/segmented.jsx +11 -7
  60. package/dist/cases/range-switch.md +16 -11
  61. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  62. package/dist/cases/settings-page.md +5 -4
  63. package/dist/cases/stat-row/featured.d.ts +1 -0
  64. package/dist/cases/stat-row/featured.jsx +17 -0
  65. package/dist/cases/stat-row/tiles.d.ts +1 -0
  66. package/dist/cases/stat-row/tiles.jsx +34 -0
  67. package/dist/cases/stat-row.md +104 -0
  68. package/dist/cases/status-label/dot.d.ts +1 -0
  69. package/dist/cases/status-label/dot.jsx +39 -0
  70. package/dist/cases/status-label/text.d.ts +1 -0
  71. package/dist/cases/status-label/text.jsx +44 -0
  72. package/dist/cases/status-label.md +143 -0
  73. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  74. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  75. package/dist/cases/upgrade-prompt.md +10 -6
  76. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  77. package/dist/cases/usage-meters/by-person.jsx +72 -0
  78. package/dist/cases/usage-meters/meters.d.ts +1 -0
  79. package/dist/cases/usage-meters/meters.jsx +49 -0
  80. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  81. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  82. package/dist/cases/usage-meters.md +303 -0
  83. package/dist/cases.json +956 -19
  84. package/dist/components/button.d.ts +1 -1
  85. package/dist/components/button.jsx +11 -5
  86. package/dist/components/formatNumber.d.ts +25 -0
  87. package/dist/components/formatNumber.js +125 -0
  88. package/dist/components/iconButton.jsx +12 -7
  89. package/dist/components/pagination.d.ts +28 -0
  90. package/dist/components/pagination.jsx +89 -0
  91. package/dist/components/progress.d.ts +33 -0
  92. package/dist/components/progress.jsx +50 -0
  93. package/dist/components/skeleton.d.ts +21 -0
  94. package/dist/components/skeleton.jsx +41 -0
  95. package/dist/components/statTile.d.ts +32 -0
  96. package/dist/components/statTile.jsx +61 -0
  97. package/dist/components/tableContainer.d.ts +5 -1
  98. package/dist/components/tableContainer.jsx +9 -1
  99. package/dist/components/tableHeaderCell.d.ts +3 -1
  100. package/dist/components/tableHeaderCell.jsx +2 -2
  101. package/dist/components/titleBar.d.ts +3 -1
  102. package/dist/components/titleBar.jsx +4 -3
  103. package/dist/index.d.ts +5 -0
  104. package/dist/index.js +5 -0
  105. package/dist/native-mapping.json +26 -2
  106. package/dist/stories/Button.stories.d.ts +1 -0
  107. package/dist/stories/Button.stories.jsx +19 -1
  108. package/dist/stories/Cases.generated.stories.d.ts +26 -0
  109. package/dist/stories/Cases.generated.stories.jsx +52 -0
  110. package/dist/stories/Pagination.stories.d.ts +9 -0
  111. package/dist/stories/Pagination.stories.jsx +75 -0
  112. package/dist/stories/Progress.stories.d.ts +9 -0
  113. package/dist/stories/Progress.stories.jsx +43 -0
  114. package/dist/stories/Skeleton.stories.d.ts +7 -0
  115. package/dist/stories/Skeleton.stories.jsx +27 -0
  116. package/dist/stories/StatTile.stories.d.ts +10 -0
  117. package/dist/stories/StatTile.stories.jsx +55 -0
  118. package/dist/stories/Table.stories.d.ts +1 -0
  119. package/dist/stories/Table.stories.jsx +49 -1
  120. package/dist/stories/TitleBar.stories.d.ts +1 -0
  121. package/dist/stories/TitleBar.stories.jsx +7 -0
  122. package/package.json +5 -1
package/dist/cases.json CHANGED
@@ -817,6 +817,147 @@
817
817
  }
818
818
  ]
819
819
  },
820
+ {
821
+ "id": "billing-page",
822
+ "title": "Billing page",
823
+ "kind": "design",
824
+ "level": "page",
825
+ "area": "dashboard",
826
+ "situation": "A workspace pays for a plan. One page says what it pays for, what it has used, how it pays and what it has paid.",
827
+ "do": [
828
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
829
+ "Put these `SettingsSection`s in this order under a `TitleBar` named 'Billing': Plan, Usage, Payment method, Invoices. The danger section, if any, comes last.",
830
+ "Show in Plan the plan's name, its price, 'Renews on Dec 1, 2026.' and one 'Change Plan' Button. The price names its unit: '$8.00 per member per month'.",
831
+ "Show the usage as the case 'Usage against limits' says, and the payment method as the case 'Payment method' says.",
832
+ "Show the last three invoices in a short table with a Download link on each row, and a 'See All Invoices' link to the case 'Invoices'.",
833
+ "Show a plan that ends as a `warning` dot `Tag` 'Canceling'. Add the line 'Pro ends on Dec 1, 2026.' and a primary 'Resume Plan' Button in place of 'Change Plan'.",
834
+ "Show a payment that failed as an `error` inline `Alert` at the top, with the date to fix it by: 'Your last payment did not go through. Update the payment method by Nov 30, 2026 to keep Pro.'",
835
+ "Add an error dot `Tag` 'Past due' by the plan name.",
836
+ "Put 'End plan' in a `SettingsSection tone=\"danger\"` as the case 'Danger zone' says. Confirm 'End Plan' in a small `Modal` that says what stays on until when and what is kept. It is confirmed because paid features stop on a date the person must see.",
837
+ "Show a person who cannot change billing every section as text, with no Buttons, and one line: 'Only admins can change billing.'",
838
+ "Say who pays and where for a plan billed elsewhere: 'Ben Carter pays for this plan through an app store.' Say who can change it.",
839
+ "Leave out every control, price, card and invoice on a plan billed elsewhere.",
840
+ "Show a status as the case 'Status in a row' says: 'Past due' and 'Canceling' as dots, 'Paid' as text."
841
+ ],
842
+ "dont": [
843
+ "Do not collect or show a card number. A card is only 'Visa ending in 4821', and it changes on the payment provider's own page.",
844
+ "Do not show Change Plan, Update or End Plan to someone who cannot use them. Show the text and the line that says who can.",
845
+ "Do not leave a failed payment without the date it must be fixed by.",
846
+ "Do not end the plan on the first click. Ask in a Modal first.",
847
+ "Do not name the action 'Cancel Plan'. It would sit beside 'Cancel' in the confirm.",
848
+ "Do not show a plan billed elsewhere with a 'Change Plan' Button that does nothing. Say where to change it.",
849
+ "Do not write 'Canceled' for a plan that is still on. Say 'Canceling' and when it ends."
850
+ ],
851
+ "native": "On Apple a plan bought in the app is managed in the system subscription sheet. Show who pays and open that sheet from one Button, never a card form.",
852
+ "options": [
853
+ {
854
+ "id": "self-serve",
855
+ "title": "An admin pays here",
856
+ "useWhen": "The person who manages billing changes the plan, the card and the cancel on this page.",
857
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Link from 'oneslash-design-system/components/link';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change billing.\nconst isAdmin = true;\n\n// A real app reads this from the server: set when the last payment failed.\nconst failedPayment: { fixBy: string } | null = { fixBy: 'Nov 30, 2026' };\n\nconst invoices = [\n { id: 'inv-0', date: 'Nov 1, 2026', amount: 24, status: 'Paid' },\n { id: 'inv-1', date: 'Oct 1, 2026', amount: 24, status: 'Paid' },\n { id: 'inv-2', date: 'Sep 1, 2026', amount: 24, status: 'Paid' },\n];\n\nexport default function BillingPageSelfServe() {\n const [canceling, setCanceling] = useState(false);\n const [confirmOpen, setConfirmOpen] = useState(false);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Stands in for the request to the server.\n function request(done: () => void) {\n if (busy) return;\n setBusy(true);\n timer.current = setTimeout(() => {\n setBusy(false);\n done();\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setConfirmOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <TitleBar title=\"Billing\" />\n {failedPayment && (\n <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={`Your last payment did not go through. Update the payment method by ${failedPayment.fixBy} to keep Pro.`} />\n )}\n <SettingsSection id=\"billing-page-plan\" title=\"Plan\" description=\"What Acme pays for.\">\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"h6\">Pro</Heading>\n {failedPayment && <Tag variant=\"dot\" size=\"small\" color=\"error\" label=\"Past due\" />}\n {canceling && <Tag variant=\"dot\" size=\"small\" color=\"warning\" label=\"Canceling\" />}\n </Cluster>\n <Paragraph size=\"body2\" measure=\"none\">{`${formatMoney(8)} per member per month`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{canceling ? 'Pro ends on Dec 1, 2026.' : 'Renews on Dec 1, 2026.'}</Paragraph>\n </Stack>\n {isAdmin ? (\n <Cluster gap=\"small\">\n {canceling ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Resume Plan\" loading={busy} onClickButton={() => request(() => setCanceling(false))} />\n ) : (\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" onClickButton={() => router.push('/settings/billing/plans')} />\n )}\n </Cluster>\n ) : (\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change billing.</Paragraph>\n )}\n </SettingsSection>\n <SettingsSection id=\"billing-page-usage\" title=\"Usage\" description=\"This month.\">\n <Stack gap=\"medium\">\n <Progress label=\"AI agent responses\" value={312} max={1000} unit=\"responses\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n <Progress label=\"Members\" value={3} max={null} unit=\"members\" />\n </Stack>\n </SettingsSection>\n <SettingsSection id=\"billing-page-payment\" title=\"Payment method\" description=\"Pays for Acme's plan.\">\n <Surface padding=\"small\">\n <Cluster justify=\"between\" gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">Visa ending in 4821</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Expires 08/28</Paragraph>\n </Stack>\n {isAdmin && (\n // A real app hands off to its payment provider's own page here. The page never takes card details.\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Update\" aria-label=\"Update Visa ending in 4821, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n )}\n </Cluster>\n </Surface>\n {/* Pro needs a card, so there is no Remove here. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Pro needs a card on file. Downgrade to Free to remove it.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"billing-page-invoices\" title=\"Invoices\" description=\"The last three.\">\n <TableContainer aria-label=\"Recent invoices\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"140px\">Date</TableHeaderCell>\n <TableHeaderCell width=\"110px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell>Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {invoices.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n <TableCell width=\"110px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell><Tag variant=\"textOnly\" size=\"small\" label={inv.status} /></TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. */}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Download\" aria-label={`Download invoice for ${inv.date}, opens in a new tab`} actionIcon=\"ExternalLink\" href={`https://acme.example/invoices/${inv.id}.pdf`} openInNewTab />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n <Link href=\"/settings/billing/invoices\" size=\"body2\">See All Invoices</Link>\n </SettingsSection>\n {isAdmin && !canceling && (\n // The last section on the page, in the danger color, as the case 'Danger zone' says.\n <SettingsSection id=\"billing-page-cancel\" tone=\"danger\" title=\"End plan\" description=\"Pro stays on until Dec 1, 2026.\">\n <Paragraph size=\"body2\" measure=\"none\">Acme goes back to Free on Dec 1, 2026. Its members and messages stay.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"End Plan\" onClickButton={() => setConfirmOpen(true)} />\n </Cluster>\n </SettingsSection>\n )}\n </Stack>\n <Modal\n isOpen={confirmOpen}\n size=\"small\"\n title=\"End Plan\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"End Plan\" loading={busy} onClickButton={() => request(() => { setConfirmOpen(false); setCanceling(true); })} />\n </>\n }\n >\n <Paragraph measure=\"none\">Pro stays on until Dec 1, 2026. After that Acme is on Free, which allows 3 members and 50 AI agent responses a month.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Nothing is deleted. You can resume the plan until then.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
858
+ "uses": [
859
+ "Alert",
860
+ "Button",
861
+ "Center",
862
+ "Cluster",
863
+ "Heading",
864
+ "Link",
865
+ "Modal",
866
+ "Paragraph",
867
+ "Progress",
868
+ "SettingsSection",
869
+ "Stack",
870
+ "Surface",
871
+ "TableCell",
872
+ "TableContainer",
873
+ "TableHeader",
874
+ "TableHeaderCell",
875
+ "TableRow",
876
+ "Tag",
877
+ "TitleBar",
878
+ "formatMoney"
879
+ ]
880
+ },
881
+ {
882
+ "id": "billed-elsewhere",
883
+ "title": "Billed elsewhere",
884
+ "useWhen": "An app store bills the plan, or another person pays for it, so this page only says who pays and where to change it.",
885
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function BillingPageBilledElsewhere() {\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <TitleBar title=\"Billing\" />\n <SettingsSection id=\"billing-elsewhere-plan\" title=\"Plan\" description=\"What Acme pays for.\">\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">Pro</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Renews on Dec 1, 2026.</Paragraph>\n </Stack>\n {/* No price, card or invoice: the app store that bills this plan keeps them. The page says who pays, where, and who can change it. */}\n <Paragraph size=\"body2\" measure=\"none\">Ben Carter pays for this plan through an app store. Only Ben Carter can change or cancel it, in the app store settings on the device that bought it.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"billing-elsewhere-usage\" title=\"Usage\" description=\"This month.\">\n <Stack gap=\"medium\">\n <Progress label=\"AI agent responses\" value={312} max={1000} unit=\"responses\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n </Stack>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
886
+ "uses": [
887
+ "Center",
888
+ "Heading",
889
+ "Paragraph",
890
+ "Progress",
891
+ "SettingsSection",
892
+ "Stack",
893
+ "TitleBar"
894
+ ]
895
+ }
896
+ ]
897
+ },
898
+ {
899
+ "id": "breakdown-list",
900
+ "title": "Breakdown of a total",
901
+ "kind": "design",
902
+ "level": "organism",
903
+ "area": "dashboard",
904
+ "situation": "A page shows how a total splits into parts, such as responses by model or comments by project.",
905
+ "do": [
906
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
907
+ "Say the total and its range above the list: '1,240 responses this week.'",
908
+ "Sort by the main number, largest first, in both options.",
909
+ "Use one `Progress kind=\"share\"` for each part in the bars, with `max` the total and `unit` the thing counted: '41%, 512 responses'. Put them in a `List`.",
910
+ "Show the largest seven parts and fold the rest into 'Other', so the list is never longer than eight rows.",
911
+ "Give the table's `TableContainer` an `aria-label` and a `minWidth`, mark the sorted column with `sort`, and right-align the numbers.",
912
+ "Show the exact number in a table, a share column from `formatPercent` and a cost from `formatMoney`. A cost under a cent reads '< $0.01'.",
913
+ "End the table with a Total row."
914
+ ],
915
+ "dont": [
916
+ "Do not use a donut or a stacked bar. Color carries nothing here, so no legend is needed.",
917
+ "Do not give each part its own color.",
918
+ "Do not show a part with no name, or a share with no count.",
919
+ "Do not list more than eight bars. Use the table.",
920
+ "Do not show a share of 0 for a part that has data. A small share reads '< 1%'."
921
+ ],
922
+ "native": "On Apple use a `List` of rows with a `Gauge` or a `ProgressView(value:total:)`, or a `Table` for the table. On Android use a `LazyColumn` of rows with a `LinearProgressIndicator`.",
923
+ "options": [
924
+ {
925
+ "id": "bars",
926
+ "title": "Ranked bars",
927
+ "useWhen": "There are up to about eight parts of one total, and the person reads them in order.",
928
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst models = [\n { name: 'Atlas Large', count: 512 },\n { name: 'Atlas Medium', count: 301 },\n { name: 'Birch 4', count: 168 },\n { name: 'Birch 4 Mini', count: 96 },\n { name: 'Cedar Pro', count: 62 },\n { name: 'Cedar Lite', count: 41 },\n { name: 'Delta 2', count: 28 },\n { name: 'Delta 1', count: 17 },\n { name: 'Elm', count: 9 },\n { name: 'Fern', count: 6 },\n];\n\n// The largest seven are listed and the rest fold into 'Other', so the list is never longer than eight rows.\nconst sorted = [...models].sort((a, b) => b.count - a.count);\nconst total = sorted.reduce((sum, m) => sum + m.count, 0);\nconst rest = sorted.slice(7).reduce((sum, m) => sum + m.count, 0);\nconst parts = [...sorted.slice(0, 7), ...(rest > 0 ? [{ name: 'Other', count: rest }] : [])];\n\nexport default function BreakdownListBars() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">Responses by model</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{formatCount(total)} responses this week.</Paragraph>\n </Stack>\n <List\n size=\"body2\"\n items={parts.map((p) => (\n // `max` is the total, so each bar is the part's share. A share is not a limit, so it never turns to a warning.\n <Progress key={p.name} kind=\"share\" label={p.name} value={p.count} max={total} unit=\"responses\" />\n ))}\n />\n </Stack>\n </Center>\n );\n}\n",
929
+ "uses": [
930
+ "Center",
931
+ "Heading",
932
+ "List",
933
+ "Paragraph",
934
+ "Progress",
935
+ "Stack",
936
+ "formatCount"
937
+ ]
938
+ },
939
+ {
940
+ "id": "table",
941
+ "title": "Table with a share column",
942
+ "useWhen": "There are more parts, or the parts are compared on two numbers, such as responses and cost.",
943
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney, formatPercent } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst models = [\n { name: 'Atlas Large', responses: 5120, cost: 61.4 },\n { name: 'Atlas Medium', responses: 3010, cost: 18.06 },\n { name: 'Birch 4', responses: 1680, cost: 12.3 },\n { name: 'Birch 4 Mini', responses: 960, cost: 1.92 },\n { name: 'Cedar Pro', responses: 620, cost: 4.65 },\n { name: 'Cedar Lite', responses: 410, cost: 0.41 },\n { name: 'Delta 2', responses: 280, cost: 0.84 },\n { name: 'Delta 1', responses: 170, cost: 0.17 },\n { name: 'Elm', responses: 90, cost: 0.004 },\n { name: 'Fern', responses: 60, cost: 0 },\n];\n\n// Largest first: the table is sorted by its main number.\nconst rows = [...models].sort((a, b) => b.responses - a.responses);\nconst total = rows.reduce((sum, m) => sum + m.responses, 0);\nconst totalCost = rows.reduce((sum, m) => sum + m.cost, 0);\n\nexport default function BreakdownListTable() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">Responses and cost by model</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{formatCount(total)} responses this month, largest first.</Paragraph>\n </Stack>\n {/* A named table sits in a region that scrolls sideways by itself, so the page never does. */}\n <TableContainer aria-label=\"Responses and cost by model\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Model</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"120px\" sort=\"descending\">Responses</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"90px\">Share</TableHeaderCell>\n <TableHeaderCell align=\"right\" width=\"110px\">Cost</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((m) => (\n <TableRow key={m.name}>\n <TableCell>{m.name}</TableCell>\n <TableCell align=\"right\" width=\"120px\">{formatCount(m.responses)}</TableCell>\n <TableCell align=\"right\" width=\"90px\">{formatPercent(m.responses / total)}</TableCell>\n <TableCell align=\"right\" width=\"110px\">{formatMoney(m.cost)}</TableCell>\n </TableRow>\n ))}\n <TableRow>\n <TableCell>Total</TableCell>\n <TableCell align=\"right\" width=\"120px\">{formatCount(total)}</TableCell>\n <TableCell align=\"right\" width=\"90px\">{formatPercent(1)}</TableCell>\n <TableCell align=\"right\" width=\"110px\">{formatMoney(totalCost)}</TableCell>\n </TableRow>\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
944
+ "uses": [
945
+ "Center",
946
+ "Heading",
947
+ "Paragraph",
948
+ "Stack",
949
+ "TableCell",
950
+ "TableContainer",
951
+ "TableHeader",
952
+ "TableHeaderCell",
953
+ "TableRow",
954
+ "formatCount",
955
+ "formatMoney",
956
+ "formatPercent"
957
+ ]
958
+ }
959
+ ]
960
+ },
820
961
  {
821
962
  "id": "check-your-email",
822
963
  "title": "Check your email",
@@ -929,7 +1070,7 @@
929
1070
  "kind": "design",
930
1071
  "level": "organism",
931
1072
  "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.",
1073
+ "situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its AI agent responses for the month.",
933
1074
  "do": [
934
1075
  "Follow the rule 'An agent refuses clearly' word for word: \"You've used all 50 AI agent responses this month.\"",
935
1076
  "Put the notice in the Composer's `above` slot: `<Alert variant=\"inline\" autoDismiss={false}>`, with no close button on the Alert itself.",
@@ -937,7 +1078,7 @@
937
1078
  "Give everyone 'Not Now', a tertiary Button, so the refusal can be closed. Put the Buttons in a `Cluster` under the Alert.",
938
1079
  "Give a person who can lift the limit the action after 'Not Now', as a primary Button, such as 'Upgrade to Pro'.",
939
1080
  "Keep the agent toggle pressable while the limit stands, as the case 'Upgrade prompt' says. Pressing it shows the notice again, and it does not turn on.",
940
- "Say in the placeholder when agent replies start again, once the person chose 'Not Now'.",
1081
+ "Say in the placeholder when AI agent responses start again, once the person chose 'Not Now'.",
941
1082
  "Move focus to the message box after 'Not Now', since the Button that had it is gone.",
942
1083
  "Keep the field and send working, so messages to people still go.",
943
1084
  "Follow the case 'Upgrade prompt' for a limit reached anywhere outside the message box."
@@ -955,7 +1096,7 @@
955
1096
  "id": "notice",
956
1097
  "title": "Notice",
957
1098
  "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",
1099
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNotice() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-notice-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when AI agent responses start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. AI agent responses start again on Dec 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person cannot change the plan, so it says who can. Everyone can close a refusal. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on Dec 1. Ask a workspace admin to upgrade Acme Design to Pro for more replies.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
959
1100
  "uses": [
960
1101
  "Alert",
961
1102
  "Button",
@@ -976,7 +1117,7 @@
976
1117
  "id": "notice-with-action",
977
1118
  "title": "Notice with an action",
978
1119
  "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",
1120
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNoticeWithAction() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-action-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when AI agent responses start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. AI agent responses start again on Dec 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person can change the plan, so they get the button that lifts the limit. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on Dec 1. The Pro plan gives Acme Design 1,000 AI agent responses a month.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
980
1121
  "uses": [
981
1122
  "Alert",
982
1123
  "Button",
@@ -1281,6 +1422,201 @@
1281
1422
  }
1282
1423
  ]
1283
1424
  },
1425
+ {
1426
+ "id": "dashboard",
1427
+ "title": "Dashboard",
1428
+ "kind": "design",
1429
+ "level": "page",
1430
+ "area": "dashboard",
1431
+ "situation": "A page that opens an app and says how things are going and what waits on the person.",
1432
+ "do": [
1433
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1434
+ "Put the page in `AppShell`, with a `TitleBar` named 'Dashboard' and a 'Range' `SegmentedControl` as its `actions`, as the case 'Range switch' says. Set `actionsBelow` so the switch takes its own line under the title on a phone.",
1435
+ "Let the one range drive every number on the page, and name it in every heading and caption: 'this week'.",
1436
+ "Show the stat row as the case 'Stat row' says, and a share of a total as the case 'Breakdown of a total' says.",
1437
+ "Make each section a `SettingsSection`: a hairline, a title and its content. Do not put a section in a box.",
1438
+ "Put the list of what waits on the person in a section titled with its count and unit: '3 comments waiting on you'. Make each row a link.",
1439
+ "Show a list that can be longer than its section as the case 'Short list on a dashboard' says.",
1440
+ "Show `EmptyBox size=\"small\"` in a section with nothing, as the rule 'An empty list says what will fill it' says: 'No questions from your agents this week'. Keep the section.",
1441
+ "Show a failed section as the case 'Load failure' says, inline with 'Try Again', and keep the rest of the page.",
1442
+ "Show a `Skeleton` or the tile's own loading state while the range changes. Do not show 0."
1443
+ ],
1444
+ "dont": [
1445
+ "Do not draw a chart. A trend is the change line on a tile, and a share is a ranked list.",
1446
+ "Do not count different sections over different ranges.",
1447
+ "Do not replace the whole page when one section failed.",
1448
+ "Do not put more than four tiles in the stat row.",
1449
+ "Do not hide a section that has nothing, or leave it blank.",
1450
+ "Do not box the sections in cards."
1451
+ ],
1452
+ "native": "On Apple use a `List` of `Section`s in a `NavigationStack`, with a `Picker` in the `.segmented` style in the toolbar. On Android use a `LazyColumn` with a `SingleChoiceSegmentedButtonRow` in the top bar.",
1453
+ "options": [
1454
+ {
1455
+ "id": "numbers-first",
1456
+ "title": "Numbers first",
1457
+ "useWhen": "The page reports how things went, for a lead who checks on a team.",
1458
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype Range = 'week' | 'month' | 'quarter';\nconst ranges = [\n { value: 'week', label: 'Week' },\n { value: 'month', label: 'Month' },\n { value: 'quarter', label: 'Quarter' },\n];\n\n// A real app counts these on the server. One range drives every number on the page.\nconst data = {\n week: {\n stats: { comments: [1240, 1106], done: [312, 280], people: [18, 18], reply: [8_640_000, 9_200_000] },\n projects: [['Website', 540], ['Mobile App', 380], ['Docs', 320]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ],\n questions: [],\n },\n month: {\n stats: { comments: [4820, 5210], done: [1190, 1004], people: [31, 27], reply: [7_800_000, 8_100_000] },\n projects: [['Website', 2010], ['Mobile App', 1500], ['Docs', 910], ['Help Center', 400]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ['Approve the new onboarding text', '/comments/5'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2']],\n },\n quarter: {\n stats: { comments: [15_880, 12_410], done: [3950, 3210], people: [44, 36], reply: [7_200_000, 7_900_000] },\n projects: [['Website', 6100], ['Mobile App', 4800], ['Docs', 3100], ['Help Center', 1880]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2'], ['Which logo should the launch page use?', '/questions/3']],\n },\n} as const;\n\nconst noun: Record<Range, string> = { week: 'this week', month: 'this month', quarter: 'this quarter' };\n\nexport default function DashboardNumbersFirst() {\n const [range, setRange] = useState<Range>('week');\n // The numbers load again when the range changes.\n const [loading, setLoading] = useState(false);\n // The projects section fails first, so the rest of the page shows that one section can fail alone.\n const [projectsFailed, setProjectsFailed] = useState(true);\n const [retrying, setRetrying] = useState(false);\n const [navOpen, setNavOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const retryTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the requests if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(retryTimer.current);\n }, []);\n\n function changeRange(next: string) {\n clearTimeout(timer.current);\n setRange(next as Range);\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 600);\n }\n\n function tryAgain() {\n if (retrying) return;\n setRetrying(true);\n retryTimer.current = setTimeout(() => {\n setRetrying(false);\n setProjectsFailed(false);\n }, 1200);\n }\n\n const d = data[range];\n const period = range;\n const projectTotal = d.projects.reduce((sum, p) => sum + p[1], 0);\n const waitingCount: number = d.waiting.length;\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {[\n ['Dashboard', 'LayoutDashboard', '/dashboard'],\n ['Comments', 'MessageSquare', '/comments'],\n ['Projects', 'FolderKanban', '/projects'],\n ].map(([label, icon, href]) => (\n <MenuItem\n key={href}\n size=\"small\"\n label={label}\n iconName={icon}\n href={href}\n isSelected={href === '/dashboard'}\n aria-current={href === '/dashboard' ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Navigation>\n );\n\n const statRow = (\n <SettingsSection key=\"stats\" title={`Numbers ${noun[range]}`} id=\"dashboard-stats\">\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />\n <StatTile label=\"Marked done\" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />\n <StatTile label=\"People engaged\" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />\n <StatTile label=\"Average reply time\" value={d.stats.reply[0]} format=\"duration\" previous={d.stats.reply[1]} period={period} loading={loading} />\n </Grid>\n </SettingsSection>\n );\n\n const projects = (\n <SettingsSection key=\"projects\" title=\"Projects\" description={`${formatCount(projectTotal)} comments ${noun[range]}, by project`} id=\"dashboard-projects\">\n {projectsFailed ? (\n <>\n {/* Only this section failed. The rest of the page still shows. */}\n <Alert type=\"error\" variant=\"inline\" message=\"Could not load projects.\" autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={retrying} onClickButton={tryAgain} />\n </Cluster>\n </>\n ) : loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading projects\" />\n ) : (\n <List\n size=\"body2\"\n items={d.projects.map(([name, count]) => (\n <Progress key={name} kind=\"share\" label={name} value={count} max={projectTotal} unit=\"comments\" />\n ))}\n />\n )}\n </SettingsSection>\n );\n\n const waiting = (\n <SettingsSection key=\"waiting\" title={loading ? 'Waiting on you' : `${formatCount(waitingCount)} ${waitingCount === 1 ? 'comment' : 'comments'} waiting on you`} description={`Asked of you ${noun[range]}`} id=\"dashboard-waiting\">\n {loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading what waits on you\" />\n ) : (\n <Stack gap=\"small\">\n {d.waiting.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n const questions = (\n <SettingsSection key=\"questions\" title=\"Questions from your agents\" id=\"dashboard-questions\">\n {loading ? (\n <Skeleton variant=\"text\" lines={2} label=\"Loading questions\" />\n ) : d.questions.length === 0 ? (\n // A section with nothing keeps its place and says what will fill it.\n <EmptyBox size=\"small\" text={`No questions from your agents ${noun[range]}`} secondText=\"Questions your agents ask you appear here.\" />\n ) : (\n <Stack gap=\"small\">\n {d.questions.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n return (\n <AppShell title=\"Dashboard\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Stack gap=\"xlarge\">\n {/* One range drives every number below, and each heading says which one. */}\n {/* Below md the range switch takes its own line under the title. */}\n <TitleBar\n title=\"Dashboard\"\n actionsBelow\n actions={<SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Range\" options={ranges} value={range} onChange={changeRange} />}\n />\n {statRow}\n {projects}\n {waiting}\n {questions}\n </Stack>\n </AppShell>\n );\n}\n",
1459
+ "uses": [
1460
+ "Alert",
1461
+ "AppShell",
1462
+ "Button",
1463
+ "Cluster",
1464
+ "EmptyBox",
1465
+ "Grid",
1466
+ "List",
1467
+ "MenuItem",
1468
+ "Navigation",
1469
+ "Paragraph",
1470
+ "Progress",
1471
+ "SegmentedControl",
1472
+ "SettingsSection",
1473
+ "Skeleton",
1474
+ "Stack",
1475
+ "StatTile",
1476
+ "TitleBar",
1477
+ "formatCount"
1478
+ ]
1479
+ },
1480
+ {
1481
+ "id": "work-first",
1482
+ "title": "Work first",
1483
+ "useWhen": "The person starts their day here, so what waits on them comes before the numbers.",
1484
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype Range = 'week' | 'month' | 'quarter';\nconst ranges = [\n { value: 'week', label: 'Week' },\n { value: 'month', label: 'Month' },\n { value: 'quarter', label: 'Quarter' },\n];\n\n// A real app counts these on the server. One range drives every number on the page.\nconst data = {\n week: {\n stats: { comments: [1240, 1106], done: [312, 280], people: [18, 18], reply: [8_640_000, 9_200_000] },\n projects: [['Website', 540], ['Mobile App', 380], ['Docs', 320]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ],\n questions: [],\n },\n month: {\n stats: { comments: [4820, 5210], done: [1190, 1004], people: [31, 27], reply: [7_800_000, 8_100_000] },\n projects: [['Website', 2010], ['Mobile App', 1500], ['Docs', 910], ['Help Center', 400]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ['Approve the new onboarding text', '/comments/5'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2']],\n },\n quarter: {\n stats: { comments: [15_880, 12_410], done: [3950, 3210], people: [44, 36], reply: [7_200_000, 7_900_000] },\n projects: [['Website', 6100], ['Mobile App', 4800], ['Docs', 3100], ['Help Center', 1880]],\n waiting: [\n ['Ben Carter asked for the new screens', '/comments/1'],\n ['Omar Reyes mentioned you in Launch plan', '/comments/2'],\n ['Review the pricing copy', '/comments/3'],\n ['Confirm the release date', '/comments/4'],\n ],\n questions: [['Is the new pricing public before Friday?', '/questions/1'], ['Who approves the final copy?', '/questions/2'], ['Which logo should the launch page use?', '/questions/3']],\n },\n} as const;\n\nconst noun: Record<Range, string> = { week: 'this week', month: 'this month', quarter: 'this quarter' };\n\nexport default function DashboardWorkFirst() {\n const [range, setRange] = useState<Range>('week');\n // The numbers load again when the range changes.\n const [loading, setLoading] = useState(false);\n // The projects section fails first, so the rest of the page shows that one section can fail alone.\n const [projectsFailed, setProjectsFailed] = useState(true);\n const [retrying, setRetrying] = useState(false);\n const [navOpen, setNavOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const retryTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the requests if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(retryTimer.current);\n }, []);\n\n function changeRange(next: string) {\n clearTimeout(timer.current);\n setRange(next as Range);\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 600);\n }\n\n function tryAgain() {\n if (retrying) return;\n setRetrying(true);\n retryTimer.current = setTimeout(() => {\n setRetrying(false);\n setProjectsFailed(false);\n }, 1200);\n }\n\n const d = data[range];\n const period = range;\n const projectTotal = d.projects.reduce((sum, p) => sum + p[1], 0);\n const waitingCount: number = d.waiting.length;\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {[\n ['Dashboard', 'LayoutDashboard', '/dashboard'],\n ['Comments', 'MessageSquare', '/comments'],\n ['Projects', 'FolderKanban', '/projects'],\n ].map(([label, icon, href]) => (\n <MenuItem\n key={href}\n size=\"small\"\n label={label}\n iconName={icon}\n href={href}\n isSelected={href === '/dashboard'}\n aria-current={href === '/dashboard' ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Navigation>\n );\n\n const statRow = (\n <SettingsSection key=\"stats\" title={`Numbers ${noun[range]}`} id=\"dashboard-stats\">\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />\n <StatTile label=\"Marked done\" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />\n <StatTile label=\"People engaged\" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />\n <StatTile label=\"Average reply time\" value={d.stats.reply[0]} format=\"duration\" previous={d.stats.reply[1]} period={period} loading={loading} />\n </Grid>\n </SettingsSection>\n );\n\n const projects = (\n <SettingsSection key=\"projects\" title=\"Projects\" description={`${formatCount(projectTotal)} comments ${noun[range]}, by project`} id=\"dashboard-projects\">\n {projectsFailed ? (\n <>\n {/* Only this section failed. The rest of the page still shows. */}\n <Alert type=\"error\" variant=\"inline\" message=\"Could not load projects.\" autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={retrying} onClickButton={tryAgain} />\n </Cluster>\n </>\n ) : loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading projects\" />\n ) : (\n <List\n size=\"body2\"\n items={d.projects.map(([name, count]) => (\n <Progress key={name} kind=\"share\" label={name} value={count} max={projectTotal} unit=\"comments\" />\n ))}\n />\n )}\n </SettingsSection>\n );\n\n const waiting = (\n <SettingsSection key=\"waiting\" title={loading ? 'Waiting on you' : `${formatCount(waitingCount)} ${waitingCount === 1 ? 'comment' : 'comments'} waiting on you`} description={`Asked of you ${noun[range]}`} id=\"dashboard-waiting\">\n {loading ? (\n <Skeleton variant=\"text\" lines={3} label=\"Loading what waits on you\" />\n ) : (\n <Stack gap=\"small\">\n {d.waiting.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n const questions = (\n <SettingsSection key=\"questions\" title=\"Questions from your agents\" id=\"dashboard-questions\">\n {loading ? (\n <Skeleton variant=\"text\" lines={2} label=\"Loading questions\" />\n ) : d.questions.length === 0 ? (\n // A section with nothing keeps its place and says what will fill it.\n <EmptyBox size=\"small\" text={`No questions from your agents ${noun[range]}`} secondText=\"Questions your agents ask you appear here.\" />\n ) : (\n <Stack gap=\"small\">\n {d.questions.map(([text, href]) => (\n <MenuItem\n key={href}\n size=\"medium\"\n label={text}\n href={href}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n )}\n </SettingsSection>\n );\n\n return (\n <AppShell title=\"Dashboard\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Stack gap=\"xlarge\">\n {/* One range drives every number below, and each heading says which one. */}\n {/* Below md the range switch takes its own line under the title. */}\n <TitleBar\n title=\"Dashboard\"\n actionsBelow\n actions={<SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Range\" options={ranges} value={range} onChange={changeRange} />}\n />\n {waiting}\n {questions}\n {statRow}\n {projects}\n </Stack>\n </AppShell>\n );\n}\n",
1485
+ "uses": [
1486
+ "Alert",
1487
+ "AppShell",
1488
+ "Button",
1489
+ "Cluster",
1490
+ "EmptyBox",
1491
+ "Grid",
1492
+ "List",
1493
+ "MenuItem",
1494
+ "Navigation",
1495
+ "Paragraph",
1496
+ "Progress",
1497
+ "SegmentedControl",
1498
+ "SettingsSection",
1499
+ "Skeleton",
1500
+ "Stack",
1501
+ "StatTile",
1502
+ "TitleBar",
1503
+ "formatCount"
1504
+ ]
1505
+ }
1506
+ ]
1507
+ },
1508
+ {
1509
+ "id": "data-table-page",
1510
+ "title": "Data table page",
1511
+ "kind": "design",
1512
+ "level": "page",
1513
+ "area": "dashboard",
1514
+ "situation": "A page is one long table of records, such as invoices or customers, that a person searches, sorts and acts on.",
1515
+ "do": [
1516
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
1517
+ "Put the page in `AppShell` as the case 'App shell' says, with a `TitleBar` named for the records: 'Invoices'. Under it say the total and its unit: '290 invoices'.",
1518
+ "Put search and a filter above the table, in a row at the end. Use the case 'Collapsible search' for the search, so the row fits a phone, and the case 'Filter menu' for the filter.",
1519
+ "Say what search and filter leave in the line under the title: '43 of 290 invoices match \"north\", past due.'",
1520
+ "Wait a moment after the last key before you ask the server for a search.",
1521
+ "Sort a column with the Button in its `TableHeaderCell`, as the case 'Members' says. Set `sort` on the header cell of the sorted column only, and leave it unset on the others. The Button is named by its label alone, such as 'Date'.",
1522
+ "Right-align a number column and its header, and show the exact amount: '$1,240.00'.",
1523
+ "Give each row one More menu, named for the row: 'More actions for INV-1290'. Follow the case 'More menu'. Keep every action in the menu, not as Buttons in the row.",
1524
+ "Show the status as the case 'Status in a row' says.",
1525
+ "Name the table with `TableContainer aria-label=\"Invoices\"` and give it a `minWidth`. A phone scrolls the table inside its named region, never the page.",
1526
+ "Show 25 rows a page when the pages come from the server, with `Pagination` named for the table below it: 'Invoice pages'. Pass `scrollTargetId` so a press of Next scrolls to the top of the page. Focus stays on Next.",
1527
+ "Pass ``getHref={(p) => '/invoices?page=' + p}`` when each page has its own address.",
1528
+ "Go back to page 1 after a sort, a search or a filter, and let the pager follow. With all the rows on the page, show no pager and no loading state.",
1529
+ "Keep the header and the pager while a page loads, and show 10 `Skeleton` rows. Give the first Skeleton a `label` such as 'Loading invoices', so a screen reader hears one status. Show a `Skeleton` in place of the count too.",
1530
+ "Show the case 'Empty list' in the table's place when there are no rows at all: 'No invoices yet', with 'Your first invoice appears here after your first payment.'",
1531
+ "Show the case 'Empty search' with the words searched for when no row matches. Its Button is 'Clear Search' when only words are on, and 'Clear Filter' when a filter is on too. It clears both. Focus goes to the search button.",
1532
+ "Show the case 'Load failure' in the table's place when a page fails to load. 'Try Again' is `loading` while it asks again and keeps its label. Keep the title and the pager.",
1533
+ "Reach the page from a card's 'See All' link, as the case 'Short list on a dashboard' says."
1534
+ ],
1535
+ "dont": [
1536
+ "Do not replace the page with a spinner while a page loads. Keep the header and the pager.",
1537
+ "Do not show 0 for a total that is loading or failed.",
1538
+ "Do not show page 4 of the old list after a new sort or filter. Go back to page 1.",
1539
+ "Do not show 'No results' with no words, or the list's own empty text when a search found nothing.",
1540
+ "Do not put a Button for every action in each row. Use one More menu.",
1541
+ "Do not leave a table that can scroll sideways without a name.",
1542
+ "Do not put `sort` on more than one header cell.",
1543
+ "Do not number the pages as a row of buttons. A phone has no room, and 500 pages have no end.",
1544
+ "Do not page a list of under 50 rows."
1545
+ ],
1546
+ "native": "On Apple use a `Table` with `KeyPathComparator` for the sort columns, `.searchable` for search, and a `Menu` in the toolbar for the filter. On Android use a `LazyColumn` of rows with a `SearchBar`, and load the next page when the end comes into view.",
1547
+ "options": [
1548
+ {
1549
+ "id": "paged",
1550
+ "title": "Pages from the server",
1551
+ "useWhen": "There are more rows than fit on a page, they come from the server, and the page holds 25 of them.",
1552
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Skeleton from 'oneslash-design-system/components/skeleton';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Status = 'Paid' | 'Past due' | 'Refunded';\ntype Invoice = { id: string; number: string; customer: string; day: number; date: string; cents: number; status: Status };\ntype SortBy = 'customer' | 'date' | 'amount';\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app asks the server for one page. This makes the 290 invoices the server would hold, newest first.\nconst all: Invoice[] = Array.from({ length: 290 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 28 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1290 - i}`,\n customer: customers[(i * 7 + 3) % customers.length],\n day: i,\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',\n };\n});\n\nconst statuses: Status[] = ['Paid', 'Past due', 'Refunded'];\nconst PAGE_SIZE = 25;\n\nexport default function DataTablePagePaged() {\n const [query, setQuery] = useState('');\n const [status, setStatus] = useState<Status | null>(null);\n // Opens newest first.\n const [sort, setSort] = useState<{ by: SortBy; dir: 'ascending' | 'descending' }>({ by: 'date', dir: 'descending' });\n const [page, setPage] = useState(1);\n const [loading, setLoading] = useState(false);\n const [failed, setFailed] = useState(false);\n\n const [searchAnchor, setSearchAnchor] = useState<HTMLElement | null>(null);\n const [searchOpen, setSearchOpen] = useState(false);\n const [filterAnchor, setFilterAnchor] = useState<HTMLElement | null>(null);\n const [filterOpen, setFilterOpen] = useState(false);\n const [menuRow, setMenuRow] = useState<Invoice | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const failedOnce = useRef(false);\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const searchButton = useRef<Focusable>(null);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // The server sorts and filters, so the page asks it again for every change. The header and the pager stay while it answers.\n function request(forPage: number) {\n clearTimeout(timer.current);\n setLoading(true);\n timer.current = setTimeout(() => {\n setLoading(false);\n // The failure stays on screen, with its Button, until the new answer arrives.\n setFailed(false);\n // Stands in for a network failure, once: page 3 fails the first time it is asked for.\n if (forPage === 3 && !failedOnce.current) {\n failedOnce.current = true;\n setFailed(true);\n }\n }, 600);\n }\n\n // A sort, a search or a filter goes back to page 1: page 4 of the old list means nothing in the new one.\n // A real app waits a moment after the last key before it asks the server for a search.\n function change(next: { query?: string; status?: Status | null; sort?: { by: SortBy; dir: 'ascending' | 'descending' } }) {\n if (next.query !== undefined) setQuery(next.query);\n if (next.status !== undefined) setStatus(next.status);\n if (next.sort !== undefined) setSort(next.sort);\n setPage(1);\n request(1);\n }\n\n function goToPage(next: number) {\n setPage(next);\n request(next);\n }\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: SortBy) {\n change({ sort: { by, dir: sort.by === by && sort.dir === 'ascending' ? 'descending' : 'ascending' } });\n }\n\n const words = query.trim();\n const found = all\n .filter((inv) => (status === null || inv.status === status) && (words === '' || `${inv.number} ${inv.customer}`.toLowerCase().includes(words.toLowerCase())))\n .sort((a, b) => {\n const order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;\n return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;\n });\n const pageCount = Math.ceil(found.length / PAGE_SIZE);\n const rows = found.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n const filtering = words !== '' || status !== null;\n\n // The line under the title says the total, and what the search and the filter leave.\n const matching = [words !== '' ? `\"${words}\"` : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');\n const countLine = filtering ? `${formatCount(found.length)} of ${formatCount(all.length)} invoices match ${matching}.` : `${formatCount(all.length)} ${all.length === 1 ? 'invoice' : 'invoices'}`;\n\n // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.\n function clearFilter() {\n change({ query: '', status: null });\n searchButton.current?.focus();\n }\n\n function openMenu(inv: Invoice, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === inv.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(inv);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n function choose(action: (inv: Invoice) => void) {\n if (!menuRow) return;\n const inv = menuRow;\n setMenuOpen(false);\n action(inv);\n }\n\n function sendReceipt(inv: Invoice) {\n toastIds.current.push(toast({ type: 'success', message: `Receipt for ${inv.number} sent to ${inv.customer}.` }));\n }\n\n // Only reads 'copied' when the number reached the clipboard.\n function copyNumber(inv: Invoice) {\n const failedCopy = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the number and copy it: ${inv.number}` }));\n };\n if (!navigator.clipboard) return failedCopy();\n navigator.clipboard.writeText(inv.number).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));\n }, failedCopy);\n }\n\n // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.\n function sortHeader(by: SortBy, label: string, width?: string, align?: 'right') {\n const active = sort.by === by;\n const button = (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n return (\n <TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>\n {align === 'right' ? <Cluster justify=\"end\">{button}</Cluster> : button}\n </TableHeaderCell>\n );\n }\n\n function statusTag(s: Status) {\n // The case 'Status in a row': a dot and a color only for a state that needs action.\n return s === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={s} /> : <Tag variant=\"textOnly\" size=\"small\" label={s} />;\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" id=\"data-table-page-paged-top\" />\n {loading ? <Skeleton variant=\"text\" width=\"medium\" /> : <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{countLine}</Paragraph>}\n </Stack>\n\n {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}\n <Cluster gap=\"small\" justify=\"end\">\n <Tooltip title={words !== '' ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={searchButton}\n color={words !== '' ? 'secondary' : 'iconOnly'}\n state={searchOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={words !== '' ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={searchOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setSearchAnchor(e.currentTarget);\n setSearchOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Tooltip title={status ? status : 'Filter by status'}>\n <IconButton\n color={status ? 'secondary' : 'iconOnly'}\n state={filterOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={status ? `Filter by status: ${status}` : 'Filter by status'}\n aria-haspopup=\"menu\"\n aria-expanded={filterOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setFilterAnchor(e.currentTarget);\n setFilterOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n\n {all.length === 0 ? (\n // A new workspace has none. The case 'Empty list' says what to write.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox size=\"large\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n </Surface>\n ) : failed ? (\n // The table's place: the header goes too, because nothing is left to sort. The pager stays.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load invoices\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={() => request(page)} />}\n />\n </Surface>\n ) : !loading && found.length === 0 ? (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={words !== '' ? `No ${status ? `${status.toLowerCase()} ` : ''}invoices match \"${words}\"` : `No ${status?.toLowerCase()} invoices`}\n secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'}\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n {sortHeader('customer', 'Customer')}\n {sortHeader('date', 'Date', '140px')}\n {sortHeader('amount', 'Amount', '130px', 'right')}\n <TableHeaderCell width=\"120px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"90px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {loading\n ? Array.from({ length: 10 }, (_, i) => (\n <TableRow key={i}>\n {/* One status for the ten rows: the Skeleton with a label is announced once. */}\n <TableCell width=\"110px\">{i === 0 ? <Skeleton label=\"Loading invoices\" /> : <Skeleton />}</TableCell>\n <TableCell><Skeleton width=\"large\" /></TableCell>\n <TableCell width=\"140px\"><Skeleton /></TableCell>\n <TableCell width=\"130px\"><Skeleton /></TableCell>\n <TableCell width=\"120px\"><Skeleton width=\"large\" /></TableCell>\n <TableCell width=\"90px\"><Skeleton width=\"small\" /></TableCell>\n </TableRow>\n ))\n : rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"130px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"120px\">{statusTag(inv.status)}</TableCell>\n <TableCell width=\"90px\">\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === inv.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${inv.number}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === inv.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(inv, e.currentTarget)}\n />\n </Tooltip>\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n\n {/* It shows nothing with one page. A real app also passes `getHref`, so each page has an address. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={goToPage} scrollTargetId=\"data-table-page-paged-top\" />\n </Stack>\n\n <Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>\n <Menu width={288}>\n <TextField\n id=\"data-table-page-paged-search\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => change({ query: e.target.value })}\n onKeyDown={(e) => {\n // Escape clears the search and closes. Enter closes and keeps it.\n if (e.key === 'Escape') {\n e.preventDefault();\n change({ query: '' });\n setSearchOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setSearchOpen(false);\n }\n }}\n />\n </Menu>\n </Popover>\n <Popover open={filterOpen} anchorEl={filterAnchor} onClose={() => setFilterOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by status\" width={200}>\n {statuses.map((s) => (\n <MenuItem\n key={s}\n size=\"small\"\n label={s === 'Past due' ? 'Past Due' : s}\n isSelected={s === status}\n role=\"menuitemradio\"\n onClick={() => {\n setFilterOpen(false);\n change({ status: s });\n }}\n />\n ))}\n {status && <Line />}\n {status && (\n <MenuItem\n size=\"small\"\n iconName=\"X\"\n label=\"Clear Filter\"\n onClick={() => {\n setFilterOpen(false);\n change({ status: null });\n }}\n />\n )}\n </Menu>\n </Popover>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.number}` : 'Invoice actions'} width={220}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy Invoice Number\" onClick={() => choose(copyNumber)} />\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipt\" onClick={() => choose(sendReceipt)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1553
+ "uses": [
1554
+ "Button",
1555
+ "Center",
1556
+ "Cluster",
1557
+ "EmptyBox",
1558
+ "IconButton",
1559
+ "Line",
1560
+ "Menu",
1561
+ "MenuItem",
1562
+ "Pagination",
1563
+ "Paragraph",
1564
+ "Popover",
1565
+ "Skeleton",
1566
+ "Stack",
1567
+ "Surface",
1568
+ "TableCell",
1569
+ "TableContainer",
1570
+ "TableHeader",
1571
+ "TableHeaderCell",
1572
+ "TableRow",
1573
+ "Tag",
1574
+ "TextField",
1575
+ "TitleBar",
1576
+ "Toaster",
1577
+ "Tooltip",
1578
+ "dismissToast",
1579
+ "formatCount",
1580
+ "formatMoney",
1581
+ "toast"
1582
+ ]
1583
+ },
1584
+ {
1585
+ "id": "all-rows",
1586
+ "title": "All rows, sorted in place",
1587
+ "useWhen": "There are under about 50 rows, so the page holds them all and sorts and filters them at once.",
1588
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Status = 'Paid' | 'Past due' | 'Refunded';\ntype Invoice = { id: string; number: string; customer: string; day: number; date: string; cents: number; status: Status };\ntype SortBy = 'customer' | 'date' | 'amount';\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app reads all of them in one request: 42 is few enough to hold, sort and filter in the page.\nconst all: Invoice[] = Array.from({ length: 42 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 28 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1042 - i}`,\n customer: customers[(i * 7 + 3) % customers.length],\n day: i,\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',\n };\n});\n\nconst statuses: Status[] = ['Paid', 'Past due', 'Refunded'];\n\nexport default function DataTablePageAllRows() {\n const [query, setQuery] = useState('');\n const [status, setStatus] = useState<Status | null>(null);\n // Opens newest first.\n const [sort, setSort] = useState<{ by: SortBy; dir: 'ascending' | 'descending' }>({ by: 'date', dir: 'descending' });\n\n const [searchAnchor, setSearchAnchor] = useState<HTMLElement | null>(null);\n const [searchOpen, setSearchOpen] = useState(false);\n const [filterAnchor, setFilterAnchor] = useState<HTMLElement | null>(null);\n const [filterOpen, setFilterOpen] = useState(false);\n const [menuRow, setMenuRow] = useState<Invoice | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const searchButton = useRef<Focusable>(null);\n\n // On unmount it closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // The first press on a column sorts it A to Z, and the next one reverses it. The rows are here, so it answers at once.\n function handleSort(by: SortBy) {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const words = query.trim();\n const rows = all\n .filter((inv) => (status === null || inv.status === status) && (words === '' || `${inv.number} ${inv.customer}`.toLowerCase().includes(words.toLowerCase())))\n .sort((a, b) => {\n const order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;\n return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;\n });\n const filtering = words !== '' || status !== null;\n\n // The line under the title says the total, and what the search and the filter leave.\n const matching = [words !== '' ? `\"${words}\"` : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');\n const countLine = filtering ? `${formatCount(rows.length)} of ${formatCount(all.length)} invoices match ${matching}.` : `${formatCount(all.length)} ${all.length === 1 ? 'invoice' : 'invoices'}`;\n\n // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.\n function clearFilter() {\n setQuery('');\n setStatus(null);\n searchButton.current?.focus();\n }\n\n function openMenu(inv: Invoice, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === inv.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(inv);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n function choose(action: (inv: Invoice) => void) {\n if (!menuRow) return;\n const inv = menuRow;\n setMenuOpen(false);\n action(inv);\n }\n\n function sendReceipt(inv: Invoice) {\n toastIds.current.push(toast({ type: 'success', message: `Receipt for ${inv.number} sent to ${inv.customer}.` }));\n }\n\n // Only reads 'copied' when the number reached the clipboard.\n function copyNumber(inv: Invoice) {\n const failedCopy = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the number and copy it: ${inv.number}` }));\n };\n if (!navigator.clipboard) return failedCopy();\n navigator.clipboard.writeText(inv.number).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));\n }, failedCopy);\n }\n\n // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.\n function sortHeader(by: SortBy, label: string, width?: string, align?: 'right') {\n const active = sort.by === by;\n const button = (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n return (\n <TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>\n {align === 'right' ? <Cluster justify=\"end\">{button}</Cluster> : button}\n </TableHeaderCell>\n );\n }\n\n function statusTag(s: Status) {\n // The case 'Status in a row': a dot and a color only for a state that needs action.\n return s === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={s} /> : <Tag variant=\"textOnly\" size=\"small\" label={s} />;\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{countLine}</Paragraph>\n </Stack>\n\n {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}\n <Cluster gap=\"small\" justify=\"end\">\n <Tooltip title={words !== '' ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={searchButton}\n color={words !== '' ? 'secondary' : 'iconOnly'}\n state={searchOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={words !== '' ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={searchOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setSearchAnchor(e.currentTarget);\n setSearchOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Tooltip title={status ? status : 'Filter by status'}>\n <IconButton\n color={status ? 'secondary' : 'iconOnly'}\n state={filterOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={status ? `Filter by status: ${status}` : 'Filter by status'}\n aria-haspopup=\"menu\"\n aria-expanded={filterOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setFilterAnchor(e.currentTarget);\n setFilterOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n\n {all.length === 0 ? (\n // A new workspace has none. The case 'Empty list' says what to write.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox size=\"large\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n </Surface>\n ) : rows.length === 0 ? (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={words !== '' ? `No ${status ? `${status.toLowerCase()} ` : ''}invoices match \"${words}\"` : `No ${status?.toLowerCase()} invoices`}\n secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'}\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n {sortHeader('customer', 'Customer')}\n {sortHeader('date', 'Date', '140px')}\n {sortHeader('amount', 'Amount', '130px', 'right')}\n <TableHeaderCell width=\"120px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"90px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"140px\">{inv.date}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"130px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"120px\">{statusTag(inv.status)}</TableCell>\n <TableCell width=\"90px\">\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === inv.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${inv.number}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === inv.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(inv, e.currentTarget)}\n />\n </Tooltip>\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n </Stack>\n\n <Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>\n <Menu width={288}>\n <TextField\n id=\"data-table-page-all-rows-search\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onKeyDown={(e) => {\n // Escape clears the search and closes. Enter closes and keeps it.\n if (e.key === 'Escape') {\n e.preventDefault();\n setQuery('');\n setSearchOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setSearchOpen(false);\n }\n }}\n />\n </Menu>\n </Popover>\n <Popover open={filterOpen} anchorEl={filterAnchor} onClose={() => setFilterOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by status\" width={200}>\n {statuses.map((s) => (\n <MenuItem\n key={s}\n size=\"small\"\n label={s === 'Past due' ? 'Past Due' : s}\n isSelected={s === status}\n role=\"menuitemradio\"\n onClick={() => {\n setFilterOpen(false);\n setStatus(s);\n }}\n />\n ))}\n {status && <Line />}\n {status && (\n <MenuItem\n size=\"small\"\n iconName=\"X\"\n label=\"Clear Filter\"\n onClick={() => {\n setFilterOpen(false);\n setStatus(null);\n }}\n />\n )}\n </Menu>\n </Popover>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.number}` : 'Invoice actions'} width={220}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy Invoice Number\" onClick={() => choose(copyNumber)} />\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipt\" onClick={() => choose(sendReceipt)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
1589
+ "uses": [
1590
+ "Button",
1591
+ "Center",
1592
+ "Cluster",
1593
+ "EmptyBox",
1594
+ "IconButton",
1595
+ "Line",
1596
+ "Menu",
1597
+ "MenuItem",
1598
+ "Paragraph",
1599
+ "Popover",
1600
+ "Stack",
1601
+ "Surface",
1602
+ "TableCell",
1603
+ "TableContainer",
1604
+ "TableHeader",
1605
+ "TableHeaderCell",
1606
+ "TableRow",
1607
+ "Tag",
1608
+ "TextField",
1609
+ "TitleBar",
1610
+ "Toaster",
1611
+ "Tooltip",
1612
+ "dismissToast",
1613
+ "formatCount",
1614
+ "formatMoney",
1615
+ "toast"
1616
+ ]
1617
+ }
1618
+ ]
1619
+ },
1284
1620
  {
1285
1621
  "id": "device-login",
1286
1622
  "title": "Device login",
@@ -2076,6 +2412,80 @@
2076
2412
  }
2077
2413
  ]
2078
2414
  },
2415
+ {
2416
+ "id": "invoice-list",
2417
+ "title": "Invoices",
2418
+ "kind": "design",
2419
+ "level": "organism",
2420
+ "area": "dashboard",
2421
+ "situation": "A billing page lists what the workspace has paid, so an admin can find an invoice, check an amount and keep a copy.",
2422
+ "do": [
2423
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
2424
+ "Show a `TableContainer` named 'Invoices', with `minWidth`, and the columns Date, Description, Amount, Status and Download.",
2425
+ "Write the amount exactly, with `formatMoney`, in a right-aligned column with a right-aligned header: '$24.00'.",
2426
+ "Show the status as the case 'Status in a row' says: 'Paid' and 'Refunded' as `Tag variant=\"textOnly\"`, and 'Past due' as a dot.",
2427
+ "Show the newest first. Add `Pagination` named 'Invoice pages' past 12 invoices, and show none under that.",
2428
+ "Give each 'Download' link a name with the date: 'Download invoice for Nov 1, 2026, opens in a new tab'. Use `Button` with `type=\"tertiary\"`, `href` and `openInNewTab`, with an external-link `actionIcon`.",
2429
+ "Put an upcoming charge in the first row with an 'Upcoming' `Tag variant=\"dot\" color=\"info\"`. Give it no Download link, because no invoice exists yet.",
2430
+ "Add a tertiary 'Why Is This Higher?' Button to that row when the charge is above the plan price. It shows the sum in words in the row, and sets `aria-expanded`. Its label never changes.",
2431
+ "Say in that explanation the regular charge, what is added and why, whether it happens once, and the charge after: 'Your regular charge is $32.00: 4 members at $8.00.'",
2432
+ "Show 'No invoices yet' in an `EmptyBox`, with one line on when the first arrives: 'Your first invoice appears here after your first payment.'",
2433
+ "Show only an amount and a status. Keep a card number, an account number and the name of the payment provider off the page."
2434
+ ],
2435
+ "dont": [
2436
+ "Do not show the amount as '$24' or '24.00'. A table shows the exact amount, with its symbol and two decimals.",
2437
+ "Do not show a card number, even a part of it, in an invoice row.",
2438
+ "Do not make the upcoming charge look like a paid invoice, or leave it out of the table when it differs from the plan price.",
2439
+ "Do not name every Download link 'Download'. A screen reader lists the links apart from their rows.",
2440
+ "Do not use an icon-only link named by its icon. Every row would read the same.",
2441
+ "Do not hide the explanation behind a tooltip.",
2442
+ "Do not change the Button's label when the explanation opens. Do not write it in sentence case, 'Why is this higher?'."
2443
+ ],
2444
+ "native": "On Apple use a `Table` of rows with a `Link` to the invoice, and a `DisclosureGroup` for the explanation. On Android use a list with a text button for the invoice.",
2445
+ "options": [
2446
+ {
2447
+ "id": "table",
2448
+ "title": "A table of past invoices",
2449
+ "useWhen": "A history of payments, the same amount each month or close to it.",
2450
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Button from 'oneslash-design-system/components/button';\nimport Tag from 'oneslash-design-system/components/tag';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Invoice = { id: string; date: string; description: string; amount: number; status: 'Paid' | 'Refunded' };\n\n// A real app reads these from the server, newest first.\nconst months = ['Nov 1, 2026', 'Oct 1, 2026', 'Sep 1, 2026', 'Aug 1, 2026', 'Jul 1, 2026', 'Jun 1, 2026', 'May 1, 2026', 'Apr 1, 2026', 'Mar 1, 2026', 'Feb 1, 2026', 'Jan 1, 2026', 'Dec 1, 2025', 'Nov 1, 2025', 'Oct 1, 2025'];\nconst invoices: Invoice[] = months.map((date, i) => ({\n id: `inv-${i}`,\n date,\n description: `Pro plan, ${date.split(' ')[0]} ${date.split(', ')[1]}`,\n amount: 24,\n status: i === 3 ? 'Refunded' : 'Paid',\n}));\n\nconst PAGE_SIZE = 12;\n\nexport default function InvoiceListTable() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(invoices.length / PAGE_SIZE);\n const rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Invoices</Heading>\n {invoices.length === 0 ? (\n // A new workspace has none. The line says when the first one arrives.\n <EmptyBox size=\"small\" text=\"No invoices yet\" secondText=\"Your first invoice appears here after your first payment.\" />\n ) : (\n <>\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell>Description</TableHeaderCell>\n <TableHeaderCell width=\"100px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"110px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell>{inv.description}</TableCell>\n {/* A table shows the exact amount, right-aligned. */}\n <TableCell width=\"100px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />\n </TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. The name says which invoice and that it opens a tab. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Download\"\n aria-label={`Download invoice for ${inv.date}, opens in a new tab`}\n actionIcon=\"ExternalLink\"\n href={`https://acme.example/invoices/${inv.id}.pdf`}\n openInNewTab\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n {/* Shows nothing under 13 invoices. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={setPage} />\n </>\n )}\n </Stack>\n </Center>\n );\n}\n",
2451
+ "uses": [
2452
+ "Button",
2453
+ "Center",
2454
+ "EmptyBox",
2455
+ "Heading",
2456
+ "Pagination",
2457
+ "Stack",
2458
+ "TableCell",
2459
+ "TableContainer",
2460
+ "TableHeader",
2461
+ "TableHeaderCell",
2462
+ "TableRow",
2463
+ "Tag",
2464
+ "formatMoney"
2465
+ ]
2466
+ },
2467
+ {
2468
+ "id": "with-upcoming",
2469
+ "title": "The next charge first",
2470
+ "useWhen": "The next charge is not the plan price, for example after a member joined mid-month, so it comes first and says why.",
2471
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The plan is $8.00 a member each month; a fourth member\n// joined on Nov 16, so the next charge also covers the 15 days left in November ($8.00 x 15/30).\nconst perMember = 8;\nconst members = 4;\nconst regular = perMember * members;\nconst added = 4;\nconst upcoming = { date: 'Dec 1, 2026', description: 'Pro plan, Dec 2026', amount: regular + added };\n\nconst paid = [\n { id: 'inv-0', date: 'Nov 1, 2026', description: 'Pro plan, Nov 2026', amount: 24, status: 'Paid' },\n { id: 'inv-1', date: 'Oct 1, 2026', description: 'Pro plan, Oct 2026', amount: 24, status: 'Paid' },\n { id: 'inv-2', date: 'Sep 1, 2026', description: 'Pro plan, Sep 2026', amount: 24, status: 'Paid' },\n];\n\nexport default function InvoiceListWithUpcoming() {\n const [explaining, setExplaining] = useState(false);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Invoices</Heading>\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell>Description</TableHeaderCell>\n <TableHeaderCell width=\"100px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"110px\">Status</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Download</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {/* The next charge is the first row. It has no invoice yet, so it has no Download link. */}\n <TableRow>\n <TableCell width=\"130px\">{upcoming.date}</TableCell>\n <TableCell>\n <Stack gap=\"small\" align=\"start\">\n {upcoming.description}\n {/* The label never changes. The state is in aria-expanded. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Why Is This Higher?\"\n aria-expanded={explaining}\n aria-controls=\"invoice-list-upcoming-why\"\n onClickButton={() => setExplaining((open) => !open)}\n />\n {explaining && (\n <Paragraph id=\"invoice-list-upcoming-why\" tone=\"secondary\" size=\"body2\" measure=\"none\">\n {`Your regular charge is ${formatMoney(regular)}: ${members} members at ${formatMoney(perMember)}. This one is ${formatMoney(upcoming.amount)} because it also adds ${formatMoney(added)} for Omar Reyes, who joined on Nov 16, for the 15 days left in November. It happens once. The charge after this is ${formatMoney(regular)}.`}\n </Paragraph>\n )}\n </Stack>\n </TableCell>\n <TableCell width=\"100px\" align=\"right\">{formatMoney(upcoming.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"dot\" size=\"small\" color=\"info\" label=\"Upcoming\" />\n </TableCell>\n <TableCell width=\"130px\">{''}</TableCell>\n </TableRow>\n {paid.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell>{inv.description}</TableCell>\n <TableCell width=\"100px\" align=\"right\">{formatMoney(inv.amount)}</TableCell>\n <TableCell width=\"110px\">\n <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />\n </TableCell>\n <TableCell width=\"130px\">\n {/* A real app links to the file on its own server. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state=\"enabled\"\n label=\"Download\"\n aria-label={`Download invoice for ${inv.date}, opens in a new tab`}\n actionIcon=\"ExternalLink\"\n href={`https://acme.example/invoices/${inv.id}.pdf`}\n openInNewTab\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
2472
+ "uses": [
2473
+ "Button",
2474
+ "Center",
2475
+ "Heading",
2476
+ "Paragraph",
2477
+ "Stack",
2478
+ "TableCell",
2479
+ "TableContainer",
2480
+ "TableHeader",
2481
+ "TableHeaderCell",
2482
+ "TableRow",
2483
+ "Tag",
2484
+ "formatMoney"
2485
+ ]
2486
+ }
2487
+ ]
2488
+ },
2079
2489
  {
2080
2490
  "id": "load-failure",
2081
2491
  "title": "Load failure",
@@ -2115,7 +2525,7 @@
2115
2525
  "id": "inline",
2116
2526
  "title": "One section failed",
2117
2527
  "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",
2528
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst invoices = ['November 2026: $24.00', 'October 2026: $24.00', 'September 2026: $24.00'];\n\nexport default function LoadFailureInline() {\n const [error, setError] = useState('Could not load your invoices.');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Plan</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Pro plan, 3 members, renews on Dec 1, 2026.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" />\n </Cluster>\n </Stack>\n </Surface>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Invoices</Heading>\n {error ? (\n <>\n {/* The section stays failed until it loads, so the Alert has no close button and does not close on its own. */}\n <Alert type=\"error\" variant=\"inline\" message={error} autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />\n </Cluster>\n </>\n ) : (\n <List items={invoices} size=\"body2\" />\n )}\n </Stack>\n </Surface>\n </Stack>\n </Center>\n );\n}\n",
2119
2529
  "uses": [
2120
2530
  "Alert",
2121
2531
  "Button",
@@ -2352,7 +2762,7 @@
2352
2762
  "Open the Modal of the case 'Member invite' from an 'Invite Member' Button. Count a pending invite as a seat, because it holds one until it is accepted or revoked.",
2353
2763
  "Keep 'Invite Member' pressable at the seat limit. Open the Modal of the case 'Upgrade prompt', titled 'Upgrade to Pro', that says all the seats are filled.",
2354
2764
  "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.'",
2765
+ "Sort a table by a Button in the header cell. Set `sort` on the `TableHeaderCell` of the sorted column only, and leave it unset on the others. The Button is named by its label alone: 'Name'.",
2356
2766
  "Use `state=\"selected\"` and an arrow on the Button of the column that is sorted. The first press sorts A to Z and the next one reverses it."
2357
2767
  ],
2358
2768
  "dont": [
@@ -2370,7 +2780,7 @@
2370
2780
  "id": "rows",
2371
2781
  "title": "A list of rows",
2372
2782
  "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",
2783
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2374
2784
  "uses": [
2375
2785
  "Alert",
2376
2786
  "Button",
@@ -2390,6 +2800,7 @@
2390
2800
  "Toaster",
2391
2801
  "UserImage",
2392
2802
  "dismissToast",
2803
+ "formatMoney",
2393
2804
  "toast"
2394
2805
  ]
2395
2806
  },
@@ -2397,7 +2808,7 @@
2397
2808
  "id": "table",
2398
2809
  "title": "A table with sorting",
2399
2810
  "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",
2811
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The sorted column's header cell has `sort`; the other cells leave it unset. The Button is named by its label alone.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer aria-label=\"Members\" minWidth=\"720px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell sort={sort.by === 'name' ? sort.dir : undefined}>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\" sort={sort.by === 'role' ? sort.dir : undefined}>{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer aria-label=\"Pending invites\" minWidth=\"720px\">\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2401
2812
  "uses": [
2402
2813
  "Alert",
2403
2814
  "Button",
@@ -2419,6 +2830,7 @@
2419
2830
  "Toaster",
2420
2831
  "UserImage",
2421
2832
  "dismissToast",
2833
+ "formatMoney",
2422
2834
  "toast"
2423
2835
  ]
2424
2836
  }
@@ -3059,6 +3471,36 @@
3059
3471
  }
3060
3472
  ]
3061
3473
  },
3474
+ {
3475
+ "id": "number-format",
3476
+ "title": "A number shows its unit and never shows 0 for unknown",
3477
+ "kind": "rule",
3478
+ "level": "rule",
3479
+ "area": "dashboard",
3480
+ "situation": "A page shows counts, money, sizes, shares or changes.",
3481
+ "answer": "Use the helpers in `formatNumber` (`formatCount`, `formatMoney`, `formatPercent`, `formatBytes`, `formatDuration`), `StatTile` and `Progress`. A count is whole and grouped: '1,240'. In a tile, a count or an amount from 10,000 up shows its short form: '12.4K', '$12.4K'. A table shows the exact number, right-aligned. Money has its symbol and two decimals: '$1,240.00'. A cost under a cent reads '< $0.01'. A share is a whole percent, and a small one reads '< 1%'. A size is base 1024: '52 MB', '1.2 GB'. A time reads '340 ms', '1.2 s', '2 h 24 min'. The unit is in the label or after the number in words: 'Responses', '7 of 8 seats', '340 responses, no limit'. A bare number is never shown, and a unit is never only in a tooltip. A change says its direction, its size and what it compares with: 'Up 12% from last week'. It reads 'New this week' when there was nothing before. It has no color, because more is not good or bad by itself. Unknown is never 0. `formatNumber` shows '–' for a value it cannot read. `StatTile` shows 'No data yet'. While a number loads, a `Skeleton` holds its place. On a failure, show the case 'Load failure'. A limit is a `Progress`, which says 'Limit reached' in words.",
3482
+ "why": "One page that rounds a cost to four decimals and another that rounds it to two make the same bill look like two different amounts. A 0 shown while a number loads reads as a real answer, so the person believes something that is not true.",
3483
+ "do": [
3484
+ "Show a count whole and grouped: '1,240'. In a tile, show a count or an amount from 10,000 up in its short form: '12.4K', '$12.4K'.",
3485
+ "Show the exact number in a table, right-aligned.",
3486
+ "Show money with its symbol and two decimals, and a cost under a cent as '< $0.01'.",
3487
+ "Show a time as '340 ms', '1.2 s' or '2 h 24 min'. Show a share as a whole percent, and a small one as '< 1%'. Show a size in base 1024: '52 MB', '1.2 GB'.",
3488
+ "Put the unit in the label or after the number in words: 'Responses', '7 of 8 seats', '340 responses, no limit'.",
3489
+ "Match the noun to the count: '1 invoice', '290 invoices'.",
3490
+ "Say a change's direction, size and comparison: 'Up 12% from last week'. Say 'New this week' when there was nothing before.",
3491
+ "Show a `Skeleton` while a number loads, 'No data yet' when there is none, and the case 'Load failure' when it could not load.",
3492
+ "Use the helpers in `formatNumber` (`formatCount`, `formatMoney`, `formatPercent`, `formatBytes`, `formatDuration`), `StatTile` and `Progress`. Do not format a number by hand."
3493
+ ],
3494
+ "dont": [
3495
+ "Do not show 0 for a number that is loading, missing or failed.",
3496
+ "Do not show a bare number, or a unit only in a tooltip.",
3497
+ "Do not round a cost to four decimals in one place and two in another.",
3498
+ "Do not color a change green or red. More is not good or bad by itself.",
3499
+ "Do not show the compact form ('12.4K') in a table, or give a screen reader only the compact form.",
3500
+ "Do not show 100% for a share that is not the whole."
3501
+ ],
3502
+ "native": "On Apple use `FormatStyle` for numbers, money and percents, and `ByteCountFormatStyle` with the `.memory` style for sizes, which is base 1024. On Android use `NumberFormat`."
3503
+ },
3062
3504
  {
3063
3505
  "id": "oauth-consent",
3064
3506
  "title": "OAuth consent",
@@ -3361,6 +3803,131 @@
3361
3803
  }
3362
3804
  ]
3363
3805
  },
3806
+ {
3807
+ "id": "paged-card",
3808
+ "title": "Short list on a dashboard",
3809
+ "kind": "design",
3810
+ "level": "organism",
3811
+ "area": "dashboard",
3812
+ "situation": "A dashboard section lists things that wait on the person, such as questions or comments, and the list may be longer than the section.",
3813
+ "do": [
3814
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3815
+ "Say the total in the title, as a number and its unit: '8 questions waiting on you'.",
3816
+ "Make every row a link to the thing it names, with a second line for when it was asked.",
3817
+ "Put `Pagination variant=\"compact\"` in the title row when the list pages, named for the card: 'Pages of questions waiting on you'.",
3818
+ "Keep the page length the same on every page. `Pagination` shows nothing when there is one page.",
3819
+ "Show five rows and a 'See All Questions' `Link` after them when the list does not page. The link goes to the full list, the case 'Data table page'.",
3820
+ "Show `EmptyBox size=\"small\"` when the list is empty, such as 'No questions waiting on you', with a `secondText` that says what will appear.",
3821
+ "Show the card as a hairline, a title and rows. Do not box it."
3822
+ ],
3823
+ "dont": [
3824
+ "Do not page a long list on the dashboard. Show five rows and a link.",
3825
+ "Do not leave the pager unnamed. Name it for the card, so a screen reader hears 'Pages of questions waiting on you'.",
3826
+ "Do not write the page as '1/3'. `Pagination` writes '1 of 3' in a card and 'Page 1 of 3' elsewhere.",
3827
+ "Do not make a row that is not a link, or a link with no name.",
3828
+ "Do not scroll a list inside the card."
3829
+ ],
3830
+ "native": "On Apple use a `Section` of a `List` with a `NavigationLink` for each row, and a `NavigationLink` named See All for the footer. On Android use a `LazyColumn` of clickable rows.",
3831
+ "options": [
3832
+ {
3833
+ "id": "pager",
3834
+ "title": "Pager in the title row",
3835
+ "useWhen": "The list is short and stays on the dashboard, a few rows a page.",
3836
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst questions = [\n { id: 'q1', text: 'Which logo file should the launch page use?', when: 'Asked 2 hours ago' },\n { id: 'q2', text: 'Is the new pricing public before Friday?', when: 'Asked 4 times, 5 hours ago' },\n { id: 'q3', text: 'Who approves the final copy for the home page?', when: 'Asked yesterday' },\n { id: 'q4', text: 'Should the export include archived projects?', when: 'Asked yesterday' },\n { id: 'q5', text: 'What is the limit for a free workspace?', when: 'Asked 2 times, 2 days ago' },\n { id: 'q6', text: 'Can a guest see the activity log?', when: 'Asked 3 days ago' },\n { id: 'q7', text: 'Which time zone do the reports use?', when: 'Asked 4 days ago' },\n { id: 'q8', text: 'Does a deleted comment count as marked done?', when: 'Asked 5 days ago' },\n];\n\nconst PER_PAGE = 4;\n\nexport default function PagedCardPager() {\n const [page, setPage] = useState(1);\n const pageCount = Math.ceil(questions.length / PER_PAGE);\n const rows = questions.slice((page - 1) * PER_PAGE, page * PER_PAGE);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Line />\n {/* The total is in the title, and the pager is in the title row, named for the card. */}\n <Cluster justify=\"between\">\n <Heading level={2} size=\"h6\">{`${formatCount(questions.length)} ${questions.length === 1 ? 'question' : 'questions'} waiting on you`}</Heading>\n <Pagination variant=\"compact\" aria-label=\"Pages of questions waiting on you\" page={page} pageCount={pageCount} onPageChange={setPage} />\n </Cluster>\n <Stack gap=\"small\">\n {rows.map((q) => (\n <MenuItem\n key={q.id}\n size=\"medium\"\n label={q.text}\n secondLabel={q.when}\n href={`/questions/${q.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the question's page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
3837
+ "uses": [
3838
+ "Center",
3839
+ "Cluster",
3840
+ "Heading",
3841
+ "Line",
3842
+ "MenuItem",
3843
+ "Pagination",
3844
+ "Stack",
3845
+ "formatCount"
3846
+ ]
3847
+ },
3848
+ {
3849
+ "id": "see-all",
3850
+ "title": "Five rows and See All",
3851
+ "useWhen": "The list is long, so the dashboard shows the newest five and a link to the full page.",
3852
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Link from 'oneslash-design-system/components/link';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server: the newest five, and how many there are in all.\nconst total = 142;\nconst questions = [\n { id: 'q1', text: 'Which logo file should the launch page use?', when: 'Asked 2 hours ago' },\n { id: 'q2', text: 'Is the new pricing public before Friday?', when: 'Asked 4 times, 5 hours ago' },\n { id: 'q3', text: 'Who approves the final copy for the home page?', when: 'Asked yesterday' },\n { id: 'q4', text: 'Should the export include archived projects?', when: 'Asked yesterday' },\n { id: 'q5', text: 'What is the limit for a free workspace?', when: 'Asked 2 times, 2 days ago' },\n];\n\nexport default function PagedCardSeeAll() {\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Line />\n <Heading level={2} size=\"h6\">{formatCount(total)} questions waiting on you</Heading>\n <Stack gap=\"small\">\n {questions.map((q) => (\n <MenuItem\n key={q.id}\n size=\"medium\"\n label={q.text}\n secondLabel={q.when}\n href={`/questions/${q.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the question's page. The example stays here.\n event.preventDefault();\n }}\n />\n ))}\n </Stack>\n {/* A real app links to the full list at '/questions', with its search and sorting. Link has no click handler to keep the example here, so it uses '#'. */}\n <Cluster>\n <Link href=\"#\" size=\"body2\">See All Questions</Link>\n </Cluster>\n </Stack>\n </Center>\n );\n}\n",
3853
+ "uses": [
3854
+ "Center",
3855
+ "Cluster",
3856
+ "Heading",
3857
+ "Line",
3858
+ "Link",
3859
+ "MenuItem",
3860
+ "Stack",
3861
+ "formatCount"
3862
+ ]
3863
+ }
3864
+ ]
3865
+ },
3866
+ {
3867
+ "id": "payment-method",
3868
+ "title": "Payment method",
3869
+ "kind": "design",
3870
+ "level": "organism",
3871
+ "area": "dashboard",
3872
+ "situation": "A workspace pays by card. The admin sees which card, changes it or removes it.",
3873
+ "do": [
3874
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3875
+ "Show only the brand as text, the last four digits and the expiry: 'Visa ending in 4821' and 'Expires 08/28'. Nothing else about the card is on the page.",
3876
+ "Make 'Update' and 'Add Payment Method' links to the payment provider's own page: a `Button` with `href`, `openInNewTab` and an external-link `actionIcon`. Name it with where it goes: 'Update Visa ending in 4821, opens in a new tab'.",
3877
+ "Confirm 'Remove' in a small `Modal` titled 'Remove Card', as the case 'Delete confirm' says: 'This removes Visa ending in 4821 from Acme. Your plan and invoices are not changed.' 'Cancel' comes first, then a danger 'Remove'.",
3878
+ "Name the card in the Remove Button's `aria-label`: 'Remove Visa ending in 4821'.",
3879
+ "Show a toast that names the card when it is removed: 'Visa ending in 4821 removed.' Then show the empty state in the same place.",
3880
+ "Offer no Remove while a paid plan needs a card, and say why in one line: 'Pro needs a card on file. Downgrade to Free to remove it.'",
3881
+ "Add an inline warning `Alert` above the row a month before the card expires: 'This card expires on 08/28. Update it before then.'",
3882
+ "Say in one line that there is no card, say whether one is needed, and offer 'Add Payment Method'."
3883
+ ],
3884
+ "dont": [
3885
+ "Do not add a `TextField` for a card number, a security code, a bank account or an address. ODS has no payment form.",
3886
+ "Do not show a full card number, or part of it beyond the last four digits.",
3887
+ "Do not name the payment provider, or copy the look or the words of its page.",
3888
+ "Do not show a card-network logo. The brand is the word.",
3889
+ "Do not title the Modal 'Are you sure?'. Name the action: 'Remove Card'.",
3890
+ "Do not remove the card on the first click.",
3891
+ "Do not offer Remove while a paid plan needs the card.",
3892
+ "Do not show Update or Remove to a person who cannot change billing."
3893
+ ],
3894
+ "native": "On Apple a plan bought in the app has no card on the page: open the system subscription sheet. For a web card, show the same text and a `Link` out.",
3895
+ "options": [
3896
+ {
3897
+ "id": "on-file",
3898
+ "title": "A card is saved",
3899
+ "useWhen": "The workspace has a card on file.",
3900
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. Only the brand, the last four digits and the expiry ever reach the page.\nconst card = { brand: 'Visa', last4: '4821', month: 8, year: 2028 };\nconst today = { month: 11, year: 2026 };\nconst plan: 'Free' | 'Pro' = 'Free';\n\n// A paid plan needs a card, so Remove is not offered. The Free plan needs none.\nconst planNeedsCard = plan !== 'Free';\nconst monthsLeft = (card.year - today.year) * 12 + (card.month - today.month);\nconst expiry = `${String(card.month).padStart(2, '0')}/${String(card.year % 100).padStart(2, '0')}`;\nconst name = `${card.brand} ending in ${card.last4}`;\n\nexport default function PaymentMethodOnFile() {\n const [removed, setRemoved] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [removing, setRemoving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const addRef = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // The Remove Button is gone with the card, so focus moves to what takes its place.\n useEffect(() => {\n if (removed) addRef.current?.focus();\n }, [removed]);\n\n // Escape, a click outside and Cancel all close it, except while the request runs. The Modal gives focus back to Remove.\n function handleClose() {\n if (removing) return;\n setConfirming(false);\n }\n\n function handleRemove() {\n if (removing) return;\n setRemoving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setRemoving(false);\n setConfirming(false);\n setRemoved(true);\n toastIds.current.push(toast({ type: 'success', message: `${name} removed.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <SettingsSection title=\"Payment method\" description=\"Pays for Acme's plan.\">\n {removed ? (\n <Stack gap=\"medium\" align=\"start\">\n <Paragraph measure=\"none\">No payment method.</Paragraph>\n {/* A real app hands off to its payment provider's own page here. The page never takes card details. */}\n <Button ref={addRef} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Payment Method\" aria-label=\"Add payment method, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n {/* A month ahead of the expiry, the page says so. */}\n {monthsLeft <= 1 && monthsLeft >= 0 && (\n <Alert type=\"warning\" variant=\"inline\" autoDismiss={false} message={`This card expires on ${expiry}. Update it before then.`} />\n )}\n <Surface padding=\"small\">\n <Cluster justify=\"between\" gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{name}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Expires ${expiry}`}</Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n {/* Updating the card happens on the provider's page, so Update is a link out. */}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Update\" aria-label={`Update ${name}, opens in a new tab`} actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n {!planNeedsCard && (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${name}`} onClickButton={() => setConfirming(true)} />\n )}\n </Cluster>\n </Cluster>\n </Surface>\n {planNeedsCard && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Pro needs a card on file. Downgrade to Free to remove it.</Paragraph>}\n </Stack>\n )}\n </SettingsSection>\n {/* One card is not a dense list, so the confirm is a small Modal. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Remove Card\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={removing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" loading={removing} onClickButton={handleRemove} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This removes ${name} from Acme. Your plan and invoices are not changed.`}</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3901
+ "uses": [
3902
+ "Alert",
3903
+ "Button",
3904
+ "Center",
3905
+ "Cluster",
3906
+ "Modal",
3907
+ "Paragraph",
3908
+ "SettingsSection",
3909
+ "Stack",
3910
+ "Surface",
3911
+ "Toaster",
3912
+ "dismissToast",
3913
+ "toast"
3914
+ ]
3915
+ },
3916
+ {
3917
+ "id": "none",
3918
+ "title": "No card yet",
3919
+ "useWhen": "The workspace has never added a card, or removed it.",
3920
+ "source": "'use client';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PaymentMethodNone() {\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Payment method\" description=\"Pays for Acme's plan.\">\n <Stack gap=\"medium\" align=\"start\">\n <Paragraph measure=\"none\">No payment method.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Acme is on Free, so it needs none. Add one to upgrade.</Paragraph>\n {/* A real app hands off to its payment provider's own page here. The page never takes card details. */}\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Payment Method\" aria-label=\"Add payment method, opens in a new tab\" actionIcon=\"ExternalLink\" href=\"https://acme.example/billing/payment-method\" openInNewTab />\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
3921
+ "uses": [
3922
+ "Button",
3923
+ "Center",
3924
+ "Paragraph",
3925
+ "SettingsSection",
3926
+ "Stack"
3927
+ ]
3928
+ }
3929
+ ]
3930
+ },
3364
3931
  {
3365
3932
  "id": "phone-navigation",
3366
3933
  "title": "On a phone, a sidebar opens as a drawer and a list opens its detail",
@@ -3387,6 +3954,158 @@
3387
3954
  ],
3388
3955
  "native": "On iPhone use a `TabView` or a `NavigationStack` that pushes the detail with the system back button, and a `.sheet` for a short task. On Android use a navigation drawer or a bottom bar, and push the detail with the system back."
3389
3956
  },
3957
+ {
3958
+ "id": "plan-change-confirm",
3959
+ "title": "Plan change confirm",
3960
+ "kind": "design",
3961
+ "level": "organism",
3962
+ "area": "dashboard",
3963
+ "situation": "An admin chose another plan. Before anything changes they need to know what it costs and when it starts.",
3964
+ "do": [
3965
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3966
+ "Follow the rule 'A confirm says exactly what will happen': a `Modal` with `size=\"small\"`, 'Cancel' first, then the action named with the title's verb. The title and the Button are the same words: 'Upgrade to Pro'.",
3967
+ "Say the amount today and for how long for an upgrade: 'You pay $12.00 today for the 15 days left in November, then $24.00 each month.'",
3968
+ "Keep the label of the action Button while it runs ('Upgrade to Pro'), as `loading`. When it works, close the Modal and show the new plan where the plan is: 'Acme is on Pro.' Show no toast.",
3969
+ "Say when a downgrade starts and what stops: 'Pro stays on until Dec 1, 2026.' Then list what Acme loses, each with its number.",
3970
+ "Show the date on the page after a downgrade, where the plan is: 'Acme is on Pro until Dec 1, 2026, then Free.' A toast would be gone before it starts.",
3971
+ "Check the smaller plan's limits before the Modal opens. Keep the Button's label while it checks.",
3972
+ "List each exceeded limit with both numbers: 'Free allows 3 members. Acme has 7.' Put a `Link` to fix it under each, and give the Modal 'Cancel' only.",
3973
+ "Show the card that pays, by its last four digits only: 'The card ending in 4821 pays for it.'",
3974
+ "Show these Buttons only to a person who can change the plan, as the case 'Upgrade prompt' says."
3975
+ ],
3976
+ "dont": [
3977
+ "Do not title the Modal 'Switch to Pro' or 'Confirm'. Name the action: 'Upgrade to Pro'.",
3978
+ "Do not label the action 'Confirm', 'Proceed' or 'Yes, downgrade'.",
3979
+ "Do not write 'prorated charges' with no amount. Say the amount.",
3980
+ "Do not change the Button's label while it runs, such as to 'Upgrading...'.",
3981
+ "Do not open the Modal and then refuse. Check the limits first.",
3982
+ "Do not offer a disabled action Button in the blocked Modal. Offer only Cancel and the links that fix it.",
3983
+ "Do not show a card field or a full card number in the confirm.",
3984
+ "Do not say a downgrade is done today when it starts later."
3985
+ ],
3986
+ "native": "On Apple use the system purchase sheet for an upgrade and a `confirmationDialog` for a downgrade that waits. The sheet shows the price, so the dialog states the date.",
3987
+ "options": [
3988
+ {
3989
+ "id": "upgrade",
3990
+ "title": "An upgrade charges now",
3991
+ "useWhen": "The new plan costs more and starts at once.",
3992
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PlanChangeConfirmUpgrade() {\n // Opens on the confirm, as if the person just chose Upgrade to Pro.\n const [open, setOpen] = useState(true);\n const [upgrading, setUpgrading] = useState(false);\n const [plan, setPlan] = useState('Free');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (upgrading) return;\n setOpen(false);\n }\n\n function handleUpgrade() {\n if (upgrading) return;\n setUpgrading(true);\n // Stands in for the request to the server. A real app charges the card on file here, never in this page.\n timer.current = setTimeout(() => {\n setUpgrading(false);\n setOpen(false);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n setPlan('Pro');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Acme is on ${plan}.`}</Paragraph>\n {plan === 'Free' && (\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setOpen(true)} />\n </Cluster>\n )}\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={upgrading ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" loading={upgrading} onClickButton={handleUpgrade} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`You pay ${formatMoney(12)} today for the 15 days left in November, then ${formatMoney(24)} each month.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`Pro is ${formatMoney(8)} per member per month. The card ending in 4821 pays for it.`}</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
3993
+ "uses": [
3994
+ "Button",
3995
+ "Center",
3996
+ "Cluster",
3997
+ "Heading",
3998
+ "Modal",
3999
+ "Paragraph",
4000
+ "Stack",
4001
+ "formatMoney"
4002
+ ]
4003
+ },
4004
+ {
4005
+ "id": "downgrade",
4006
+ "title": "A downgrade waits",
4007
+ "useWhen": "The new plan costs less. It starts when the paid period ends, so nothing is lost today.",
4008
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PlanChangeConfirmDowngrade() {\n // Opens on the confirm, as if the person just chose Downgrade to Free.\n const [open, setOpen] = useState(true);\n const [downgrading, setDowngrading] = useState(false);\n const [scheduled, setScheduled] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (downgrading) return;\n setOpen(false);\n }\n\n function handleDowngrade() {\n if (downgrading) return;\n setDowngrading(true);\n // Stands in for the request to the server. Nothing is charged or lost today.\n timer.current = setTimeout(() => {\n setDowngrading(false);\n setOpen(false);\n setScheduled(true);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n {/* The change starts later, so the page says when. A toast would be gone before Dec 1. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{scheduled ? 'Acme is on Pro until Dec 1, 2026, then Free.' : 'Acme is on Pro.'}</Paragraph>\n {!scheduled && (\n <Cluster>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Downgrade to Free\" onClickButton={() => setOpen(true)} />\n </Cluster>\n )}\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Downgrade to Free\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={downgrading ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Downgrade to Free\" loading={downgrading} onClickButton={handleDowngrade} />\n </>\n }\n >\n <Paragraph measure=\"none\">Pro stays on until Dec 1, 2026. Acme is not charged again.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List\n size=\"body2\"\n marker=\"dot\"\n items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']}\n />\n </Modal>\n </Center>\n );\n}\n",
4009
+ "uses": [
4010
+ "Button",
4011
+ "Center",
4012
+ "Cluster",
4013
+ "Heading",
4014
+ "List",
4015
+ "Modal",
4016
+ "Paragraph",
4017
+ "Stack"
4018
+ ]
4019
+ },
4020
+ {
4021
+ "id": "blocked",
4022
+ "title": "The smaller plan does not fit",
4023
+ "useWhen": "The workspace is over a limit of the smaller plan, so the downgrade cannot happen until the person fixes it.",
4024
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Link from 'oneslash-design-system/components/link';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server. Free allows 3 members and 1 connected repository.\nconst exceeded = [\n { id: 'members', text: 'Free allows 3 members. Acme has 7.', fix: 'Manage Members', href: '/settings/members' },\n { id: 'repos', text: 'Free allows 1 connected repository. Acme has 2.', fix: 'Manage Repositories', href: '/settings/repositories' },\n];\n\nexport default function PlanChangeConfirmBlocked() {\n const [open, setOpen] = useState(true);\n const [checking, setChecking] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the check if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The limits are checked before the Modal opens, so the person never reads 'Downgrade' and then a refusal.\n function handleCheck() {\n if (checking) return;\n setChecking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setChecking(false);\n setOpen(true);\n }, 600);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Acme is on Pro.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Downgrade to Free\" loading={checking} onClickButton={handleCheck} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Downgrade to Free\"\n onClose={() => setOpen(false)}\n actions={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Cancel\" onClickButton={() => setOpen(false)} />}\n >\n <Paragraph measure=\"none\">Acme cannot move to Free yet. It is over two limits.</Paragraph>\n <List\n size=\"body2\"\n marker=\"dot\"\n items={exceeded.map((e) => (\n <Stack key={e.id} gap=\"small\" align=\"start\">\n <Paragraph size=\"body2\" measure=\"none\">{e.text}</Paragraph>\n <Link href={e.href} size=\"body2\">{e.fix}</Link>\n </Stack>\n ))}\n />\n </Modal>\n </Center>\n );\n}\n",
4025
+ "uses": [
4026
+ "Button",
4027
+ "Center",
4028
+ "Cluster",
4029
+ "Heading",
4030
+ "Link",
4031
+ "List",
4032
+ "Modal",
4033
+ "Paragraph",
4034
+ "Stack"
4035
+ ]
4036
+ }
4037
+ ]
4038
+ },
4039
+ {
4040
+ "id": "plan-picker",
4041
+ "title": "Plan picker",
4042
+ "kind": "design",
4043
+ "level": "organism",
4044
+ "area": "dashboard",
4045
+ "situation": "An admin compares the plans a workspace can be on and chooses one.",
4046
+ "do": [
4047
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
4048
+ "Make each plan a `Surface` with its name as a heading, its price and a `List` of what it includes. Write each limit as a number with its unit: '3 members', '50 AI agent responses a month'.",
4049
+ "Put the cards in `Grid columns={3}`, which stacks them on a phone. Put the rows in one column.",
4050
+ "Mark the current plan with `Tag variant=\"textOnly\"` 'Current plan', and give it no Button.",
4051
+ "Give every other plan one Button named for the move: 'Upgrade to Pro' as primary, 'Downgrade to Free' as tertiary. It opens the case 'Plan change confirm'.",
4052
+ "Say a change that starts later with a Tag 'Starts Dec 1' on the new plan, and a line under the heading: 'Acme is on Pro until Dec 1, 2026, then Free.'",
4053
+ "Open the picker from 'Change Plan' on the case 'Billing page'. Show it only to a person who can change the plan.",
4054
+ "Add a `SegmentedControl` as the case 'Range switch' says once the plans bill by the year too. Leave it out while every plan bills monthly."
4055
+ ],
4056
+ "dont": [
4057
+ "Do not make a card clickable as a whole. Its Button is the one control, so a keyboard and a screen reader find it.",
4058
+ "Do not label the Buttons 'Select' or 'Choose'. Say the move: 'Upgrade to Pro'.",
4059
+ "Do not run the limits together in one line with dots between them. Use a `List`, one limit per item.",
4060
+ "Do not add a monthly and yearly switch when no plan bills yearly.",
4061
+ "Do not change a Button label to show it is busy, such as to 'Checking...'.",
4062
+ "Do not charge or change the plan from this page. The confirm does that."
4063
+ ],
4064
+ "native": "On Apple use a `List` of plans with the system purchase sheet, and mark the current plan with a checkmark and the words 'Current plan'. Never build a card by hand.",
4065
+ "options": [
4066
+ {
4067
+ "id": "cards",
4068
+ "title": "Cards side by side",
4069
+ "useWhen": "Two or three plans are compared at once, on a page with room for columns.",
4070
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\ntype PlanId = 'free' | 'pro' | 'business';\n\n// Made-up plans. A real app reads them from the server, with the limits as numbers.\nconst plans: { id: PlanId; name: string; price: string; includes: string[] }[] = [\n { id: 'free', name: 'Free', price: `${formatMoney(0)} per month`, includes: ['3 members', '50 AI agent responses a month', '1 GB of storage'] },\n { id: 'pro', name: 'Pro', price: `${formatMoney(8)} per member per month`, includes: ['Unlimited members', '1,000 AI agent responses a month', '50 GB of storage', 'Export to PDF'] },\n { id: 'business', name: 'Business', price: `${formatMoney(16)} per member per month`, includes: ['Unlimited members', '10,000 AI agent responses a month', '500 GB of storage', 'Export to PDF', 'Priority support'] },\n];\n\nconst rank: Record<PlanId, number> = { free: 0, pro: 1, business: 2 };\n\n// What the change costs. An upgrade charges now; a downgrade waits for the end of the period. A real app reads the amounts from the server.\nfunction describe(from: PlanId, to: PlanId) {\n const name = plans.find((p) => p.id === to)!.name;\n if (rank[to] > rank[from]) {\n // Three members, 15 of 30 days left in November: half of the first month today.\n const today = to === 'pro' ? 12 : from === 'free' ? 24 : 12;\n const monthly = to === 'pro' ? 24 : 48;\n const body = `You pay ${formatMoney(today)} today for the 15 days left in November, then ${formatMoney(monthly)} each month.`;\n return { title: `Upgrade to ${name}`, body, detail: false };\n }\n // A downgrade changes nothing today. It says when it starts and what stops.\n return { title: `Downgrade to ${name}`, body: `${plans.find((p) => p.id === from)!.name} stays on until Dec 1, 2026. Acme is not charged again.`, detail: true };\n}\n\nexport default function PlanPickerCards() {\n const [current, setCurrent] = useState<PlanId>('free');\n const [scheduled, setScheduled] = useState<PlanId | null>(null);\n const [target, setTarget] = useState<PlanId | null>(null);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setTarget(null);\n }\n\n function handleConfirm() {\n if (busy || !target) return;\n const to = target;\n setBusy(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setBusy(false);\n setTarget(null);\n if (rank[to] > rank[current]) {\n setCurrent(to);\n setScheduled(null);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n } else {\n // A downgrade changes nothing today, so the page says when it starts.\n setScheduled(to);\n }\n }, 1200);\n }\n\n const copy = target ? describe(current, target) : null;\n const currentName = plans.find((p) => p.id === current)!.name;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Plan\" description={scheduled ? `Acme is on ${currentName} until Dec 1, 2026, then ${plans.find((p) => p.id === scheduled)!.name}.` : `Acme is on ${currentName}.`}>\n {/* Two or three plans side by side from md up, stacked on a phone. A card is not itself clickable. */}\n <Grid columns={3}>\n {plans.map((p) => (\n <Surface key={p.id} padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">{p.name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.price}</Paragraph>\n </Stack>\n <List items={p.includes} size=\"body2\" marker=\"dot\" />\n {p.id === current ? (\n <Cluster><Tag variant=\"textOnly\" size=\"small\" label=\"Current plan\" /></Cluster>\n ) : p.id === scheduled ? (\n <Cluster><Tag variant=\"dot\" size=\"small\" label=\"Starts Dec 1\" /></Cluster>\n ) : rank[p.id] > rank[current] ? (\n <Cluster><Button size=\"small\" type=\"primary\" state=\"enabled\" label={`Upgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} /></Cluster>\n ) : (\n <Cluster><Button size=\"small\" type=\"tertiary\" state=\"enabled\" label={`Downgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} /></Cluster>\n )}\n </Stack>\n </Surface>\n ))}\n </Grid>\n </SettingsSection>\n <Modal\n isOpen={target !== null}\n size=\"small\"\n title={copy?.title ?? ''}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label={copy?.title ?? ''} loading={busy} onClickButton={handleConfirm} />\n </>\n }\n >\n <Paragraph measure=\"none\">{copy?.body}</Paragraph>\n {copy?.detail && (\n <>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List size=\"body2\" marker=\"dot\" items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']} />\n </>\n )}\n </Modal>\n </Center>\n );\n}\n",
4071
+ "uses": [
4072
+ "Button",
4073
+ "Center",
4074
+ "Cluster",
4075
+ "Grid",
4076
+ "Heading",
4077
+ "List",
4078
+ "Modal",
4079
+ "Paragraph",
4080
+ "SettingsSection",
4081
+ "Stack",
4082
+ "Surface",
4083
+ "Tag",
4084
+ "formatMoney"
4085
+ ]
4086
+ },
4087
+ {
4088
+ "id": "list",
4089
+ "title": "Rows in a settings column",
4090
+ "useWhen": "The picker sits in a narrow settings column, or the plans have long lists of what they include.",
4091
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype PlanId = 'free' | 'pro' | 'business';\n\n// Made-up plans. A real app reads them from the server, with the limits as numbers.\nconst plans: { id: PlanId; name: string; price: string; includes: string[] }[] = [\n { id: 'free', name: 'Free', price: `${formatMoney(0)} per month`, includes: ['3 members', '50 AI agent responses a month', '1 GB of storage'] },\n { id: 'pro', name: 'Pro', price: `${formatMoney(8)} per member per month`, includes: ['Unlimited members', '1,000 AI agent responses a month', '50 GB of storage', 'Export to PDF'] },\n { id: 'business', name: 'Business', price: `${formatMoney(16)} per member per month`, includes: ['Unlimited members', '10,000 AI agent responses a month', '500 GB of storage', 'Export to PDF', 'Priority support'] },\n];\n\nconst rank: Record<PlanId, number> = { free: 0, pro: 1, business: 2 };\n\n// What the change costs. An upgrade charges now; a downgrade waits for the end of the period. A real app reads the amounts from the server.\nfunction describe(from: PlanId, to: PlanId) {\n const name = plans.find((p) => p.id === to)!.name;\n if (rank[to] > rank[from]) {\n // Three members, 15 of 30 days left in November: half of the first month today.\n const today = to === 'pro' ? 12 : from === 'free' ? 24 : 12;\n const monthly = to === 'pro' ? 24 : 48;\n const body = `You pay ${formatMoney(today)} today for the 15 days left in November, then ${formatMoney(monthly)} each month.`;\n return { title: `Upgrade to ${name}`, body, detail: false };\n }\n // A downgrade changes nothing today. It says when it starts and what stops.\n return { title: `Downgrade to ${name}`, body: `${plans.find((p) => p.id === from)!.name} stays on until Dec 1, 2026. Acme is not charged again.`, detail: true };\n}\n\nexport default function PlanPickerList() {\n const [current, setCurrent] = useState<PlanId>('pro');\n const [scheduled, setScheduled] = useState<PlanId | null>(null);\n const [target, setTarget] = useState<PlanId | null>(null);\n const [busy, setBusy] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (busy) return;\n setTarget(null);\n }\n\n function handleConfirm() {\n if (busy || !target) return;\n const to = target;\n setBusy(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setBusy(false);\n setTarget(null);\n if (rank[to] > rank[current]) {\n setCurrent(to);\n setScheduled(null);\n // The plan line on the page says it: 'Acme is on Pro.' No toast.\n } else {\n // A downgrade changes nothing today, so the page says when it starts.\n setScheduled(to);\n }\n }, 1200);\n }\n\n const copy = target ? describe(current, target) : null;\n const currentName = plans.find((p) => p.id === current)!.name;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Plan\" description={scheduled ? `Acme is on ${currentName} until Dec 1, 2026, then ${plans.find((p) => p.id === scheduled)!.name}.` : `Acme is on ${currentName}.`}>\n {/* Rows in the settings column. The plan and what it includes on the left, the one action on the right. */}\n <Stack gap=\"medium\">\n {plans.map((p) => (\n <Surface key={p.id} padding=\"small\">\n <Cluster justify=\"between\" align=\"start\" gap=\"medium\">\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"h6\">{p.name}</Heading>\n {p.id === current && <Tag variant=\"textOnly\" size=\"small\" label=\"Current plan\" />}\n {p.id === scheduled && <Tag variant=\"dot\" size=\"small\" label=\"Starts Dec 1\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.price}</Paragraph>\n <List items={p.includes} size=\"body2\" marker=\"dot\" />\n </Stack>\n {p.id !== current && p.id !== scheduled && (\n rank[p.id] > rank[current]\n ? <Button size=\"small\" type=\"primary\" state=\"enabled\" label={`Upgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} />\n : <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label={`Downgrade to ${p.name}`} onClickButton={() => setTarget(p.id)} />\n )}\n </Cluster>\n </Surface>\n ))}\n </Stack>\n </SettingsSection>\n <Modal\n isOpen={target !== null}\n size=\"small\"\n title={copy?.title ?? ''}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={busy ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label={copy?.title ?? ''} loading={busy} onClickButton={handleConfirm} />\n </>\n }\n >\n <Paragraph measure=\"none\">{copy?.body}</Paragraph>\n {copy?.detail && (\n <>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">On Dec 1, 2026, Acme loses:</Paragraph>\n <List size=\"body2\" marker=\"dot\" items={['More than 3 members.', 'More than 50 AI agent responses a month. Pro gives 1,000.', 'More than 1 GB of storage. Pro gives 50 GB.', 'Export to PDF.']} />\n </>\n )}\n </Modal>\n </Center>\n );\n}\n",
4092
+ "uses": [
4093
+ "Button",
4094
+ "Center",
4095
+ "Cluster",
4096
+ "Heading",
4097
+ "List",
4098
+ "Modal",
4099
+ "Paragraph",
4100
+ "SettingsSection",
4101
+ "Stack",
4102
+ "Surface",
4103
+ "Tag",
4104
+ "formatMoney"
4105
+ ]
4106
+ }
4107
+ ]
4108
+ },
3390
4109
  {
3391
4110
  "id": "profile-form",
3392
4111
  "title": "Profile",
@@ -3496,10 +4215,11 @@
3496
4215
  "kind": "design",
3497
4216
  "level": "organism",
3498
4217
  "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.",
4218
+ "situation": "A person changes the time range of the numbers or a list on the same page, such as Week, Month or Quarter.",
3500
4219
  "do": [
4220
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
3501
4221
  "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.",
4222
+ "Put it beside the heading of the numbers or list it changes, with `width=\"fit\"` so it is as wide as its options.",
3503
4223
  "Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
3504
4224
  "Change the numbers in place and keep the page, the heading and the scroll position.",
3505
4225
  "Move between options with the arrow keys. They select as they move."
@@ -3516,14 +4236,15 @@
3516
4236
  "id": "segmented",
3517
4237
  "title": "Segmented control",
3518
4238
  "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",
4239
+ "source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst ranges: { value: string; label: string; period: 'week' | 'month' | 'quarter'; comments: number[]; done: number[]; people: number[] }[] = [\n { value: 'week', label: 'Week', period: 'week', comments: [18, 15], done: [11, 12], people: [7, 7] },\n { value: 'month', label: 'Month', period: 'month', comments: [64, 52], done: [40, 41], people: [12, 10] },\n { value: 'quarter', label: 'Quarter', period: 'quarter', comments: [171, 160], done: [118, 109], people: [19, 21] },\n];\n\nexport default function RangeSwitchSegmented() {\n const [range, setRange] = useState('week');\n const current = ranges.find((r) => r.value === range) ?? ranges[0];\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Overview</Heading>\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Range\"\n options={ranges.map(({ value, label }) => ({ value, label }))}\n value={range}\n onChange={setRange}\n />\n </Cluster>\n {/* The numbers change with the range. This page stays the same. */}\n <Grid compact columns={3}>\n <StatTile label=\"New comments\" value={current.comments[0]} previous={current.comments[1]} period={current.period} />\n <StatTile label=\"Marked done\" value={current.done[0]} previous={current.done[1]} period={current.period} />\n <StatTile label=\"People engaged\" value={current.people[0]} previous={current.people[1]} period={current.period} />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
3520
4240
  "uses": [
3521
4241
  "Center",
3522
4242
  "Cluster",
4243
+ "Grid",
3523
4244
  "Heading",
3524
- "Paragraph",
3525
4245
  "SegmentedControl",
3526
- "Stack"
4246
+ "Stack",
4247
+ "StatTile"
3527
4248
  ]
3528
4249
  }
3529
4250
  ]
@@ -3922,7 +4643,7 @@
3922
4643
  "id": "top-tabs",
3923
4644
  "title": "Tabs across the top",
3924
4645
  "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",
4646
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport SettingsSection, { SettingsColumns } from 'oneslash-design-system/components/settingsSection';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = 'profile' | 'notifications' | 'billing';\n\n// Four areas or fewer, each named with one short word, so the tabs fit on a phone. Each tab is a page of its own in a real app, so it has an `href`.\nconst areas: { id: Area; label: string }[] = [\n { id: 'profile', label: 'Profile' },\n { id: 'notifications', label: 'Notifications' },\n { id: 'billing', label: 'Billing' },\n];\n\nconst invoices = [`November 2026, ${formatMoney(24)}`, `October 2026, ${formatMoney(24)}`, `September 2026, ${formatMoney(24)}`];\n\nexport default function SettingsPageTopTabs() {\n const [area, setArea] = useState<Area>('profile');\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open area.\n const router = { push: (url: string) => setArea(url.split('/').pop() as Area) };\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-tabs-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-email\" title=\"Email\" description=\"Where Acme writes to you.\">\n <FormField id=\"settings-page-tabs-email-field\" label=\"Email\" help=\"Only support can change this. Write to help@acme.example.\">\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} value=\"dana@acme.example\" readOnly onChange={() => {}} />}\n </FormField>\n </SettingsSection>\n </SettingsColumns>\n );\n\n const notifications = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-email-alerts\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-tabs-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-tabs-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n </SettingsColumns>\n );\n\n const billing = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-plan\" title=\"Plan\" description=\"Pro plan, 3 members.\">\n <Paragraph size=\"body2\" measure=\"none\">Renews on Dec 1, 2026. Only owners can change the plan.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-invoices\" title=\"Invoices\" description=\"The last three months.\">\n <List items={invoices} size=\"body2\" />\n </SettingsSection>\n </SettingsColumns>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <TabsContainer>\n {areas.map((a) => (\n <Tab key={a.id} label={a.label} href={`/settings/${a.id}`} router={router} isSelected={area === a.id} onClickTab={() => setArea(a.id)} />\n ))}\n </TabsContainer>\n {area === 'profile' && profile}\n {area === 'notifications' && notifications}\n {area === 'billing' && billing}\n </Stack>\n </Center>\n );\n}\n",
3926
4647
  "uses": [
3927
4648
  "Button",
3928
4649
  "Center",
@@ -3938,7 +4659,8 @@
3938
4659
  "Switch",
3939
4660
  "Tab",
3940
4661
  "TabsContainer",
3941
- "TextField"
4662
+ "TextField",
4663
+ "formatMoney"
3942
4664
  ]
3943
4665
  },
3944
4666
  {
@@ -4385,6 +5107,126 @@
4385
5107
  }
4386
5108
  ]
4387
5109
  },
5110
+ {
5111
+ "id": "stat-row",
5112
+ "title": "Stat row",
5113
+ "kind": "design",
5114
+ "level": "organism",
5115
+ "area": "dashboard",
5116
+ "situation": "A page opens with the few numbers that say how things are going, counted over one range.",
5117
+ "do": [
5118
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'. Use `StatTile`, which does.",
5119
+ "Put the tiles in `<Grid compact columns={4}>`: two across on a phone, up to four from md up.",
5120
+ "Use four tiles at most. A fifth number goes in a table.",
5121
+ "Make each tile count one thing, with its unit in the label or the `unit` prop: 'New comments', 'Responses'.",
5122
+ "Count every tile over the same range, and say the range in the heading above the row: 'This week'.",
5123
+ "Pass `previous` and `period` to get the change line, such as 'Up 12% from last week'. Leave `previous` out when there is nothing to compare with.",
5124
+ "Pass `loading` while the numbers load, so a `Skeleton` holds each place. Pass `value={null}` when there is no data: the tile says 'No data yet'.",
5125
+ "Pass `format` for money, a percent, a size or a time, such as `format=\"money\"`. Do not format a number by hand.",
5126
+ "Give the one number that matters most `size=\"large\"` and a row of its own, with the others under it."
5127
+ ],
5128
+ "dont": [
5129
+ "Do not show 0 while a number loads or when it is missing.",
5130
+ "Do not color a change green or red. More is not good or bad by itself.",
5131
+ "Do not put more than four tiles in a row, or two things in one tile.",
5132
+ "Do not draw a chart or a sparkline in a tile. A trend is the change line.",
5133
+ "Do not box each tile in a card. The row sits on the page."
5134
+ ],
5135
+ "native": "On Apple use a `LabeledContent` or a `Grid` of `VStack`s with the number in `.title2` and `monospacedDigit()`. On Android use a `Row` of `Column`s with `headlineMedium` text.",
5136
+ "options": [
5137
+ {
5138
+ "id": "tiles",
5139
+ "title": "Tiles of equal weight",
5140
+ "useWhen": "Two to four numbers matter about the same, over one range.",
5141
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function StatRowTiles() {\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function reload() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setLoading(false), 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={2} size=\"h6\">This week</Heading>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Reload\" decoIcon=\"RefreshCw\" onClickButton={reload} />\n </Cluster>\n {/* Four tiles at most. Two across on a phone, four from md up. Each counts one thing over the same range. */}\n <Grid compact columns={4}>\n <StatTile label=\"New comments\" value={1240} previous={1106} loading={loading} />\n <StatTile label=\"Marked done\" value={312} previous={280} loading={loading} />\n <StatTile label=\"People engaged\" value={18} previous={18} loading={loading} />\n <StatTile label=\"Average reply time\" value={8_640_000} format=\"duration\" previous={9_200_000} loading={loading} />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
5142
+ "uses": [
5143
+ "Button",
5144
+ "Center",
5145
+ "Cluster",
5146
+ "Grid",
5147
+ "Heading",
5148
+ "Stack",
5149
+ "StatTile"
5150
+ ]
5151
+ },
5152
+ {
5153
+ "id": "featured",
5154
+ "title": "One number first",
5155
+ "useWhen": "One number matters most, with two others under it.",
5156
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport StatTile from 'oneslash-design-system/components/statTile';\nimport { Center, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function StatRowFeatured() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">This month</Heading>\n {/* The number that matters most is one step larger and has the row to itself. */}\n <StatTile label=\"Responses\" value={48210} previous={41980} period=\"month\" size=\"large\" />\n <Grid compact columns={2}>\n <StatTile label=\"Estimated cost\" value={96.4} format=\"money\" previous={88.2} period=\"month\" />\n <StatTile label=\"Data stored\" value={1_288_490_188} format=\"bytes\" previous={1_073_741_824} period=\"month\" />\n </Grid>\n </Stack>\n </Center>\n );\n}\n",
5157
+ "uses": [
5158
+ "Center",
5159
+ "Grid",
5160
+ "Heading",
5161
+ "Stack",
5162
+ "StatTile"
5163
+ ]
5164
+ }
5165
+ ]
5166
+ },
5167
+ {
5168
+ "id": "status-label",
5169
+ "title": "Status in a row",
5170
+ "kind": "design",
5171
+ "level": "organism",
5172
+ "area": "dashboard",
5173
+ "situation": "A row in a table or a list says what state its thing is in, such as an invoice, a plan or a connection. ODS has no separate Badge part, because `Tag` does a Badge's job.",
5174
+ "do": [
5175
+ "Use `Tag` for a state in a row, with `size=\"small\"`. ODS has no Badge part: a second part for the same job would mark the same states two ways.",
5176
+ "Show the word every time. The dot alone means nothing to a screen reader or to a person who cannot tell the colors apart.",
5177
+ "Use `variant=\"dot\"` for a state that changes and may need the person: 'Past due', 'Canceling', 'Connected'.",
5178
+ "Give the dot a color only when the state needs action: `color=\"error\"` for 'Past due', `color=\"warning\"` for 'Canceling'. One exception: `color=\"info\"` for a charge that has not happened yet, 'Upcoming', so it does not read as paid. A usual state, such as 'Connected', keeps the grey dot.",
5179
+ "Use `variant=\"textOnly\"` with no color for a settled record: 'Paid', 'Refunded'.",
5180
+ "Write one word or two, in sentence case: 'Past due', 'Needs reconnecting'.",
5181
+ "Put the Tag in a 'Status' column, or at the end of the row's text. It is not clickable."
5182
+ ],
5183
+ "dont": [
5184
+ "Do not show a dot with no word, or a color with no word.",
5185
+ "Do not color a settled state. A green 'Paid' on every row hides the one red 'Past due'.",
5186
+ "Do not write the word in Title Case ('Past Due') or as a sentence ('Your payment is late').",
5187
+ "Do not fill the Tag with `variant=\"contained\"` for a status in a row. A filled Tag is a label the person picks.",
5188
+ "Do not make the Tag a button. A status that opens something is a row action, in the More menu.",
5189
+ "Do not draw the dot by hand."
5190
+ ],
5191
+ "native": "On Apple use a `Label` with a small filled circle as its image and the word, colored with a semantic style only when the state needs action. On Android use a leading dot and the word in a `Text`.",
5192
+ "options": [
5193
+ {
5194
+ "id": "dot",
5195
+ "title": "A dot and a word",
5196
+ "useWhen": "The state changes and may need the person: Past due, Canceling, Connected.",
5197
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Color = 'error' | 'warning' | undefined;\n\n// A real app reads these from the server.\nconst workspaces: { id: string; name: string; plan: string; status: string; color: Color }[] = [\n { id: 'acme', name: 'Acme', plan: 'Pro', status: 'Past due', color: 'error' },\n { id: 'acme-labs', name: 'Acme Labs', plan: 'Pro', status: 'Canceling', color: 'warning' },\n { id: 'acme-studio', name: 'Acme Studio', plan: 'Pro', status: 'Active', color: undefined },\n];\n\nexport default function StatusLabelDot() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Workspaces</Heading>\n <TableContainer aria-label=\"Workspaces\" minWidth=\"480px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Workspace</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Plan</TableHeaderCell>\n <TableHeaderCell width=\"160px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {workspaces.map((w) => (\n <TableRow key={w.id}>\n <TableCell>{w.name}</TableCell>\n <TableCell width=\"100px\">{w.plan}</TableCell>\n <TableCell width=\"160px\">\n {/* The word is always there. Only a state that needs action gets a color: 'Active' keeps the grey dot. */}\n <Tag variant=\"dot\" size=\"small\" color={w.color} label={w.status} />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
5198
+ "uses": [
5199
+ "Center",
5200
+ "Heading",
5201
+ "Stack",
5202
+ "TableCell",
5203
+ "TableContainer",
5204
+ "TableHeader",
5205
+ "TableHeaderCell",
5206
+ "TableRow",
5207
+ "Tag"
5208
+ ]
5209
+ },
5210
+ {
5211
+ "id": "text",
5212
+ "title": "A word alone",
5213
+ "useWhen": "The record is settled and nothing is left to do: Paid, Refunded.",
5214
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst payments = [\n { id: 'p0', date: 'Dec 1, 2026', amount: 24, status: 'Upcoming' },\n { id: 'p1', date: 'Nov 1, 2026', amount: 24, status: 'Paid' },\n { id: 'p2', date: 'Oct 1, 2026', amount: 24, status: 'Paid' },\n { id: 'p3', date: 'Sep 1, 2026', amount: 24, status: 'Refunded' },\n];\n\nexport default function StatusLabelText() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Payments</Heading>\n <TableContainer aria-label=\"Payments\" minWidth=\"480px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Date</TableHeaderCell>\n <TableHeaderCell width=\"120px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"160px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {payments.map((p) => (\n <TableRow key={p.id}>\n <TableCell>{p.date}</TableCell>\n <TableCell width=\"120px\" align=\"right\">{formatMoney(p.amount)}</TableCell>\n <TableCell width=\"160px\">\n {p.status === 'Upcoming' ? (\n // The one exception: a charge that has not happened yet is an info dot, so it does not read as paid.\n <Tag variant=\"dot\" size=\"small\" color=\"info\" label={p.status} />\n ) : (\n // A settled record is a word with no dot and no color.\n <Tag variant=\"textOnly\" size=\"small\" label={p.status} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
5215
+ "uses": [
5216
+ "Center",
5217
+ "Heading",
5218
+ "Stack",
5219
+ "TableCell",
5220
+ "TableContainer",
5221
+ "TableHeader",
5222
+ "TableHeaderCell",
5223
+ "TableRow",
5224
+ "Tag",
5225
+ "formatMoney"
5226
+ ]
5227
+ }
5228
+ ]
5229
+ },
4388
5230
  {
4389
5231
  "id": "success-feedback",
4390
5232
  "title": "Success shows where the person is looking",
@@ -4703,12 +5545,13 @@
4703
5545
  "situation": "A person reaches something their plan does not include, or a limit of their plan.",
4704
5546
  "do": [
4705
5547
  "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.\"",
5548
+ "Say which limit was reached, with the number, and when it resets: \"You've used all 50 AI agent responses this month. They start again on Dec 1.\"",
4707
5549
  "Offer 'Not Now' as a tertiary Button, then 'Upgrade to Pro' as a primary Button.",
4708
5550
  "Show 'Upgrade to Pro' only to a person who can change the plan. Tell everyone else to ask a workspace admin, and give them only 'Not Now'.",
4709
5551
  "Title the Modal 'Upgrade to Pro' only for a person who can upgrade. For everyone else, title it 'Pro Feature'.",
4710
5552
  "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, and Escape or a click outside means 'Not Now'.",
4711
5553
  "Put the notice where the control was, with the same two Buttons, when a limit is reached inside a flow.",
5554
+ "At a limit, show a `Progress` above the notice that says 'Limit reached', and point it at the notice with `aria-describedby`.",
4712
5555
  "Follow the rule 'An agent refuses clearly' too when the agent is the one refused."
4713
5556
  ],
4714
5557
  "dont": [
@@ -4724,7 +5567,7 @@
4724
5567
  "id": "modal",
4725
5568
  "title": "Explain in a Modal",
4726
5569
  "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",
5570
+ "source": "'use client';\nimport { useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nexport default function UpgradePromptModal() {\n // Opens on the Modal, as if the person just chose Export PDF.\n const [open, setOpen] = useState(true);\n\n function handleUpgrade() {\n setOpen(false);\n router.push('/settings/billing?plan=pro');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Q3 plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* The locked control stays on the page, so the person can find out what unlocks it. */}\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Share\" />\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export PDF\" decoIcon=\"Lock\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n // The title names the action only for a person who can take it.\n title={canChangePlan ? 'Upgrade to Pro' : 'Pro Feature'}\n onClose={() => setOpen(false)}\n actions={\n canChangePlan ? (\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={handleUpgrade} />\n </>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n )\n }\n >\n <Paragraph measure=\"none\">Exporting to PDF is part of the Pro plan. Acme Design is on the Free plan.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? `Pro also adds version history and unlimited guests, for ${formatMoney(8)} per member each month.`\n : 'Ask a workspace admin to upgrade Acme Design to Pro.'}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4728
5571
  "uses": [
4729
5572
  "Button",
4730
5573
  "Center",
@@ -4732,26 +5575,120 @@
4732
5575
  "Heading",
4733
5576
  "Modal",
4734
5577
  "Paragraph",
4735
- "Stack"
5578
+ "Stack",
5579
+ "formatMoney"
4736
5580
  ]
4737
5581
  },
4738
5582
  {
4739
5583
  "id": "inline",
4740
5584
  "title": "Replace the control",
4741
5585
  "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",
5586
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nconst thread = [\n { id: 'm1', from: 'Dana Lee', text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme agent', text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Dana Lee', text: 'Draft the launch email, please.' },\n];\n\nexport default function UpgradePromptInline() {\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n <Stack gap=\"medium\">\n {thread.map((m) => (\n <Stack key={m.id} gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.from}</Paragraph>\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Stack>\n ))}\n </Stack>\n <Progress label=\"AI agent responses\" value={50} max={50} unit=\"responses\" aria-describedby={showNotice ? 'upgrade-prompt-notice' : undefined} />\n {showNotice ? (\n // The notice takes the place of the message box, where the person was about to type.\n <Surface padding=\"medium\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"upgrade-prompt-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme Design 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n ) : (\n // After 'Not Now' the message box comes back, closed until the replies start again.\n <TextField id=\"upgrade-prompt-message\" label=\"Message the agent\" value=\"\" placeholder=\"AI agent responses start again on Dec 1.\" disabled onChange={() => {}} />\n )}\n </Stack>\n </Center>\n );\n}\n",
4743
5587
  "uses": [
4744
5588
  "Button",
4745
5589
  "Center",
4746
5590
  "Cluster",
4747
5591
  "Heading",
4748
5592
  "Paragraph",
5593
+ "Progress",
4749
5594
  "Stack",
4750
5595
  "Surface",
4751
5596
  "TextField"
4752
5597
  ]
4753
5598
  }
4754
5599
  ]
5600
+ },
5601
+ {
5602
+ "id": "usage-meters",
5603
+ "title": "Usage against limits",
5604
+ "kind": "design",
5605
+ "level": "organism",
5606
+ "area": "dashboard",
5607
+ "situation": "A plan limits some things, such as AI agent responses, members and storage. The admin checks how close the workspace is.",
5608
+ "do": [
5609
+ "Follow the rule 'A number shows its unit and never shows 0 for unknown'.",
5610
+ "Show each limit as a `Progress` named for what it counts, with its unit: 'AI agent responses', '50 of 50 responses'. A limit is `kind=\"limit\"`, the default. A share of a total is not a limit.",
5611
+ "Say when a limit resets, for the ones that reset: 'Resets on Dec 1.' Members and storage do not reset, so leave it off them.",
5612
+ "Say 'Limit reached' in words at a limit. Put the inline notice of the case 'Upgrade prompt' under that meter, and point the meter at it with `aria-describedby`.",
5613
+ "Say a limit that is passed as it is: '53 of 50 responses, over the limit'. A count can pass its limit by a few, so do not stop it at 100%.",
5614
+ "Give a plan with no limit `max={null}`: the meter becomes text only, '3 members, no limit', with no bar.",
5615
+ "Show who used it in a sorted table under the meters, most first, with exact numbers and the numbers right-aligned.",
5616
+ "Set a spend cap as the rule 'A setting saves in place, or with one Save Button' says: a money `TextField` with one 'Save' Button, 'Saved' for 2 seconds. Empty means no cap, and the help text says so.",
5617
+ "Show spend against a cap in the same `Progress`. Say what is paused and when it starts again in an inline warning `Alert` once the cap is reached.",
5618
+ "Show a member who cannot change the cap the amount as text with the line 'Only admins can change it.'"
5619
+ ],
5620
+ "dont": [
5621
+ "Do not write a meter as '12 / 1,000'. Write '12 of 1,000 responses'.",
5622
+ "Do not show a limit by color alone. Say 'Limit reached' or 'Almost at the limit'.",
5623
+ "Do not draw the bar by hand. Use `Progress`.",
5624
+ "Do not show a bar for a plan with no limit, or write 'Unlimited' beside a number.",
5625
+ "Do not round a cost to four decimals. Show money with two: '$18.40'.",
5626
+ "Do not show the upgrade notice for a limit that is not reached.",
5627
+ "Do not show a cap field to a person who cannot set it."
5628
+ ],
5629
+ "native": "On Apple use a `Gauge` or a `ProgressView` for each limit, with its label and value text, and a `LabeledContent` row for a limit with no bar. On Android use a `LinearProgressIndicator` with the value in words beside it.",
5630
+ "options": [
5631
+ {
5632
+ "id": "meters",
5633
+ "title": "A meter for each limit",
5634
+ "useWhen": "The plan has a few limits and the admin needs to see how close each one is.",
5635
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { formatBytes } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\n// A real app reads the numbers from the server. This is Free: 50 responses, 3 members and 1 GB.\nconst GB = 1024 ** 3;\nconst storage = { used: Math.round(0.85 * GB), limit: GB };\n\nexport default function UsageMetersMeters() {\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description=\"This month, on the Free plan.\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n {/* At the limit the meter says 'Limit reached' in words. The notice sits under it and names the limit. */}\n <Progress id=\"usage-meters-responses\" label=\"AI agent responses\" value={50} max={50} unit=\"responses\" aria-describedby={showNotice ? 'usage-meters-notice' : undefined} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {showNotice && (\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"usage-meters-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n )}\n </Stack>\n <Progress label=\"Members\" value={2} max={3} unit=\"members\" />\n {/* Near the limit the bar turns to a warning, and says so in words. */}\n <Progress label=\"Storage\" value={storage.used} max={storage.limit} valueText={`${formatBytes(storage.used)} of ${formatBytes(storage.limit)}`} />\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5636
+ "uses": [
5637
+ "Button",
5638
+ "Center",
5639
+ "Cluster",
5640
+ "Paragraph",
5641
+ "Progress",
5642
+ "SettingsSection",
5643
+ "Stack",
5644
+ "Surface",
5645
+ "formatBytes"
5646
+ ]
5647
+ },
5648
+ {
5649
+ "id": "by-person",
5650
+ "title": "Who used it, under the meters",
5651
+ "useWhen": "People share one pool, and the admin asks who used it.",
5652
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\n// A real app counts these on the server, most first. A count can pass its limit by a few: replies that were\n// already running when the limit was reached still finish.\nconst people = [\n { id: 'dana', name: 'Dana Lee', responses: 21 },\n { id: 'ben', name: 'Ben Carter', responses: 19 },\n { id: 'omar', name: 'Omar Reyes', responses: 13 },\n];\nconst total = people.reduce((sum, p) => sum + p.responses, 0);\n\nexport default function UsageMetersByPerson() {\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description=\"This month, on the Free plan.\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Progress label=\"AI agent responses\" value={total} max={50} unit=\"responses\" aria-describedby={showNotice ? 'usage-meters-person-notice' : undefined} />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {showNotice && (\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph id=\"usage-meters-person-notice\" measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on Dec 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n )}\n </Stack>\n {/* Under the meters: who used it, most first, with exact numbers. */}\n <Stack gap=\"small\">\n <Heading level={3} size=\"h6\">Responses by person</Heading>\n <TableContainer aria-label=\"Responses by person\" minWidth=\"320px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Person</TableHeaderCell>\n <TableHeaderCell width=\"130px\" align=\"right\">Responses</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {people.map((p) => (\n <TableRow key={p.id}>\n <TableCell>{p.name}</TableCell>\n <TableCell width=\"130px\" align=\"right\">{formatCount(p.responses)}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5653
+ "uses": [
5654
+ "Button",
5655
+ "Center",
5656
+ "Cluster",
5657
+ "Heading",
5658
+ "Paragraph",
5659
+ "Progress",
5660
+ "SettingsSection",
5661
+ "Stack",
5662
+ "Surface",
5663
+ "TableCell",
5664
+ "TableContainer",
5665
+ "TableHeader",
5666
+ "TableHeaderCell",
5667
+ "TableRow",
5668
+ "formatCount"
5669
+ ]
5670
+ },
5671
+ {
5672
+ "id": "with-cap",
5673
+ "title": "Billed by the amount, with a cap",
5674
+ "useWhen": "Use is billed by the amount, and the admin sets a monthly spend cap that pauses use when it is reached.",
5675
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Progress from 'oneslash-design-system/components/progress';\nimport Button from 'oneslash-design-system/components/button';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. Extra AI agent responses cost $0.05 each, and $18.40 is spent so far.\nconst spent = 18.4;\n\n// A real app reads this from the person's role. Only an admin sets the cap.\nconst canChangeCap = true;\n\nexport default function UsageMetersWithCap() {\n const [cap, setCap] = useState<number | null>(20);\n const [draft, setDraft] = useState('20');\n const [error, setError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearTimeout(savedTimer.current);\n }, []);\n\n const next = draft.trim() === '' ? null : Number(draft);\n const changed = next !== cap;\n\n // The cap is one field with one Save Button. Empty means no cap.\n function handleSave() {\n if (saving || !changed) return;\n if (next !== null && !(Number.isInteger(next) && next >= 1 && next <= 10000)) {\n setError(`Enter a whole amount from ${formatMoney(1)} to ${formatMoney(10000)}, or leave it empty for no cap.`);\n return;\n }\n setError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCap(next);\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200);\n }\n\n const reached = cap !== null && spent >= cap;\n\n return (\n <Center width=\"page\">\n <SettingsSection title=\"Usage\" description={`This month, on the Pro plan. Extra AI agent responses cost ${formatMoney(0.05)} each.`}>\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n {/* A cap is a limit: the bar warns near it and says 'Limit reached' at it. With no cap there is no bar. */}\n <Progress\n label=\"Spend this month\"\n value={spent}\n max={cap}\n valueText={cap === null ? `${formatMoney(spent)} so far, no cap` : `${formatMoney(spent)} of ${formatMoney(cap)}`}\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Resets on Dec 1.</Paragraph>\n {reached && <Alert type=\"warning\" variant=\"inline\" autoDismiss={false} message=\"AI agent responses are paused. Raise the cap, or they start again on Dec 1.\" />}\n </Stack>\n {canChangeCap ? (\n <Form aria-label=\"Monthly spend cap\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"usage-meters-cap\" label=\"Monthly spend cap (USD)\" help=\"AI agent responses pause when the cap is reached. Leave it empty for no cap.\" error={error}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n type=\"number\"\n value={draft}\n disabled={saving}\n onChange={(e) => { setDraft(e.target.value); setError(''); setSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={changed || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n ) : (\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{`The monthly spend cap is ${cap === null ? 'not set' : formatMoney(cap)}. Only admins can change it.`}</Paragraph>\n )}\n </Stack>\n </SettingsSection>\n </Center>\n );\n}\n",
5676
+ "uses": [
5677
+ "Alert",
5678
+ "Button",
5679
+ "Center",
5680
+ "Cluster",
5681
+ "Form",
5682
+ "FormField",
5683
+ "Paragraph",
5684
+ "Progress",
5685
+ "SettingsSection",
5686
+ "Stack",
5687
+ "TextField",
5688
+ "formatMoney"
5689
+ ]
5690
+ }
5691
+ ]
4755
5692
  }
4756
5693
  ]
4757
5694
  }