oneslash-design-system 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +54 -5
  3. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  4. package/dist/cases/app-shell/sidebar.jsx +124 -0
  5. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  6. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  7. package/dist/cases/app-shell.md +364 -0
  8. package/dist/cases/artifact-card/card.jsx +32 -6
  9. package/dist/cases/artifact-card.md +55 -7
  10. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  11. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  12. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  13. package/dist/cases/billing-page/self-serve.jsx +134 -0
  14. package/dist/cases/billing-page.md +247 -0
  15. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  16. package/dist/cases/breakdown-list/bars.jsx +47 -0
  17. package/dist/cases/breakdown-list/table.d.ts +1 -0
  18. package/dist/cases/breakdown-list/table.jsx +69 -0
  19. package/dist/cases/breakdown-list.md +158 -0
  20. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  21. package/dist/cases/composer-limit/notice.jsx +3 -3
  22. package/dist/cases/composer-limit.md +8 -8
  23. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  24. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  25. package/dist/cases/dashboard/work-first.d.ts +1 -0
  26. package/dist/cases/dashboard/work-first.jsx +165 -0
  27. package/dist/cases/dashboard.md +507 -0
  28. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  29. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  30. package/dist/cases/data-table-page/paged.d.ts +1 -0
  31. package/dist/cases/data-table-page/paged.jsx +284 -0
  32. package/dist/cases/data-table-page.md +771 -0
  33. package/dist/cases/error-page/in-shell.jsx +26 -17
  34. package/dist/cases/error-page.md +42 -21
  35. package/dist/cases/invoice-list/table.d.ts +1 -0
  36. package/dist/cases/invoice-list/table.jsx +64 -0
  37. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  38. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  39. package/dist/cases/invoice-list.md +237 -0
  40. package/dist/cases/load-failure/inline.jsx +2 -2
  41. package/dist/cases/load-failure.md +2 -2
  42. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  43. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  44. package/dist/cases/master-detail/split.d.ts +1 -0
  45. package/dist/cases/master-detail/split.jsx +49 -0
  46. package/dist/cases/master-detail.md +213 -0
  47. package/dist/cases/members-list/rows.jsx +2 -1
  48. package/dist/cases/members-list/table.jsx +8 -9
  49. package/dist/cases/members-list.md +12 -13
  50. package/dist/cases/mobile-menu/links.d.ts +1 -0
  51. package/dist/cases/mobile-menu/links.jsx +24 -0
  52. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  53. package/dist/cases/mobile-menu/sections.jsx +61 -0
  54. package/dist/cases/mobile-menu.md +170 -0
  55. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  56. package/dist/cases/not-found-page.md +41 -20
  57. package/dist/cases/number-format.md +36 -0
  58. package/dist/cases/on-this-page/aside.d.ts +1 -0
  59. package/dist/cases/on-this-page/aside.jsx +39 -0
  60. package/dist/cases/on-this-page.md +80 -0
  61. package/dist/cases/page-header/actions.d.ts +1 -0
  62. package/dist/cases/page-header/actions.jsx +65 -0
  63. package/dist/cases/page-header/sub-page.d.ts +1 -0
  64. package/dist/cases/page-header/sub-page.jsx +37 -0
  65. package/dist/cases/page-header.md +195 -0
  66. package/dist/cases/paged-card/pager.d.ts +1 -0
  67. package/dist/cases/paged-card/pager.jsx +41 -0
  68. package/dist/cases/paged-card/see-all.d.ts +1 -0
  69. package/dist/cases/paged-card/see-all.jsx +34 -0
  70. package/dist/cases/paged-card.md +147 -0
  71. package/dist/cases/payment-method/none.d.ts +1 -0
  72. package/dist/cases/payment-method/none.jsx +17 -0
  73. package/dist/cases/payment-method/on-file.d.ts +1 -0
  74. package/dist/cases/payment-method/on-file.jsx +92 -0
  75. package/dist/cases/payment-method.md +182 -0
  76. package/dist/cases/phone-navigation.md +32 -0
  77. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  78. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  79. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  80. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  81. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  82. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  83. package/dist/cases/plan-change-confirm.md +261 -0
  84. package/dist/cases/plan-picker/cards.d.ts +1 -0
  85. package/dist/cases/plan-picker/cards.jsx +97 -0
  86. package/dist/cases/plan-picker/list.d.ts +1 -0
  87. package/dist/cases/plan-picker/list.jsx +103 -0
  88. package/dist/cases/plan-picker.md +297 -0
  89. package/dist/cases/range-switch/segmented.jsx +11 -7
  90. package/dist/cases/range-switch.md +16 -11
  91. package/dist/cases/route-loading/region.jsx +27 -18
  92. package/dist/cases/route-loading.md +42 -21
  93. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  94. package/dist/cases/settings-page.md +5 -4
  95. package/dist/cases/side-pane/beside.d.ts +1 -0
  96. package/dist/cases/side-pane/beside.jsx +79 -0
  97. package/dist/cases/side-pane/over.d.ts +1 -0
  98. package/dist/cases/side-pane/over.jsx +58 -0
  99. package/dist/cases/side-pane.md +238 -0
  100. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  101. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  102. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  103. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  104. package/dist/cases/sidebar-nav.md +261 -0
  105. package/dist/cases/site-footer/columns.d.ts +1 -0
  106. package/dist/cases/site-footer/columns.jsx +51 -0
  107. package/dist/cases/site-footer/simple.d.ts +1 -0
  108. package/dist/cases/site-footer/simple.jsx +24 -0
  109. package/dist/cases/site-footer.md +133 -0
  110. package/dist/cases/site-header/links.d.ts +1 -0
  111. package/dist/cases/site-header/links.jsx +26 -0
  112. package/dist/cases/site-header/sections.d.ts +1 -0
  113. package/dist/cases/site-header/sections.jsx +64 -0
  114. package/dist/cases/site-header.md +183 -0
  115. package/dist/cases/stat-row/featured.d.ts +1 -0
  116. package/dist/cases/stat-row/featured.jsx +17 -0
  117. package/dist/cases/stat-row/tiles.d.ts +1 -0
  118. package/dist/cases/stat-row/tiles.jsx +34 -0
  119. package/dist/cases/stat-row.md +104 -0
  120. package/dist/cases/status-label/dot.d.ts +1 -0
  121. package/dist/cases/status-label/dot.jsx +39 -0
  122. package/dist/cases/status-label/text.d.ts +1 -0
  123. package/dist/cases/status-label/text.jsx +44 -0
  124. package/dist/cases/status-label.md +143 -0
  125. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  126. package/dist/cases/theme-switcher/menu.jsx +47 -0
  127. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  128. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  129. package/dist/cases/theme-switcher.md +149 -0
  130. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  131. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  132. package/dist/cases/upgrade-prompt.md +10 -6
  133. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  134. package/dist/cases/usage-meters/by-person.jsx +72 -0
  135. package/dist/cases/usage-meters/meters.d.ts +1 -0
  136. package/dist/cases/usage-meters/meters.jsx +49 -0
  137. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  138. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  139. package/dist/cases/usage-meters.md +303 -0
  140. package/dist/cases.json +1756 -172
  141. package/dist/components/appShell.d.ts +44 -0
  142. package/dist/components/appShell.jsx +121 -0
  143. package/dist/components/button.d.ts +1 -1
  144. package/dist/components/button.jsx +11 -5
  145. package/dist/components/drawer.d.ts +31 -0
  146. package/dist/components/drawer.jsx +121 -0
  147. package/dist/components/formatNumber.d.ts +25 -0
  148. package/dist/components/formatNumber.js +125 -0
  149. package/dist/components/heading.d.ts +3 -1
  150. package/dist/components/heading.jsx +2 -2
  151. package/dist/components/iconButton.jsx +12 -7
  152. package/dist/components/link.d.ts +6 -1
  153. package/dist/components/link.jsx +11 -3
  154. package/dist/components/menuItem.d.ts +7 -1
  155. package/dist/components/menuItem.jsx +4 -3
  156. package/dist/components/modal.jsx +12 -23
  157. package/dist/components/onThisPage.d.ts +29 -0
  158. package/dist/components/onThisPage.jsx +151 -0
  159. package/dist/components/pageShell.d.ts +7 -1
  160. package/dist/components/pageShell.jsx +14 -1
  161. package/dist/components/pagination.d.ts +28 -0
  162. package/dist/components/pagination.jsx +89 -0
  163. package/dist/components/popover.jsx +4 -0
  164. package/dist/components/progress.d.ts +33 -0
  165. package/dist/components/progress.jsx +50 -0
  166. package/dist/components/settingsSection.d.ts +6 -1
  167. package/dist/components/settingsSection.jsx +10 -3
  168. package/dist/components/sidePane.d.ts +32 -0
  169. package/dist/components/sidePane.jsx +128 -0
  170. package/dist/components/siteFooter.d.ts +24 -0
  171. package/dist/components/siteFooter.jsx +48 -0
  172. package/dist/components/siteHeader.d.ts +55 -0
  173. package/dist/components/siteHeader.jsx +125 -0
  174. package/dist/components/skeleton.d.ts +21 -0
  175. package/dist/components/skeleton.jsx +41 -0
  176. package/dist/components/statTile.d.ts +32 -0
  177. package/dist/components/statTile.jsx +61 -0
  178. package/dist/components/tableContainer.d.ts +5 -1
  179. package/dist/components/tableContainer.jsx +9 -1
  180. package/dist/components/tableHeaderCell.d.ts +3 -1
  181. package/dist/components/tableHeaderCell.jsx +2 -2
  182. package/dist/components/titleBar.d.ts +19 -0
  183. package/dist/components/titleBar.jsx +18 -0
  184. package/dist/index.d.ts +12 -0
  185. package/dist/index.js +12 -0
  186. package/dist/internal/overlayStack.d.ts +24 -0
  187. package/dist/internal/overlayStack.js +71 -0
  188. package/dist/internal/resize.d.ts +9 -0
  189. package/dist/internal/resize.js +31 -0
  190. package/dist/internal/scrollSpy.d.ts +24 -0
  191. package/dist/internal/scrollSpy.js +53 -0
  192. package/dist/internal/siteBrand.d.ts +6 -0
  193. package/dist/internal/siteBrand.jsx +11 -0
  194. package/dist/native-mapping.json +69 -3
  195. package/dist/stories/AppShell.stories.d.ts +15 -0
  196. package/dist/stories/AppShell.stories.jsx +137 -0
  197. package/dist/stories/Button.stories.d.ts +1 -0
  198. package/dist/stories/Button.stories.jsx +19 -1
  199. package/dist/stories/Cases.generated.stories.d.ts +45 -0
  200. package/dist/stories/Cases.generated.stories.jsx +90 -0
  201. package/dist/stories/Drawer.stories.d.ts +10 -0
  202. package/dist/stories/Drawer.stories.jsx +123 -0
  203. package/dist/stories/Link.stories.d.ts +1 -0
  204. package/dist/stories/Link.stories.jsx +8 -0
  205. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  206. package/dist/stories/OnThisPage.stories.jsx +105 -0
  207. package/dist/stories/Pagination.stories.d.ts +9 -0
  208. package/dist/stories/Pagination.stories.jsx +75 -0
  209. package/dist/stories/Progress.stories.d.ts +9 -0
  210. package/dist/stories/Progress.stories.jsx +43 -0
  211. package/dist/stories/SettingsSection.stories.d.ts +1 -0
  212. package/dist/stories/SettingsSection.stories.jsx +27 -0
  213. package/dist/stories/SidePane.stories.d.ts +6 -0
  214. package/dist/stories/SidePane.stories.jsx +37 -0
  215. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  216. package/dist/stories/SiteFooter.stories.jsx +63 -0
  217. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  218. package/dist/stories/SiteHeader.stories.jsx +94 -0
  219. package/dist/stories/Skeleton.stories.d.ts +7 -0
  220. package/dist/stories/Skeleton.stories.jsx +27 -0
  221. package/dist/stories/StatTile.stories.d.ts +10 -0
  222. package/dist/stories/StatTile.stories.jsx +55 -0
  223. package/dist/stories/Table.stories.d.ts +1 -0
  224. package/dist/stories/Table.stories.jsx +49 -1
  225. package/dist/stories/TitleBar.stories.d.ts +7 -0
  226. package/dist/stories/TitleBar.stories.jsx +41 -0
  227. package/package.json +5 -1
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Surface from '../../components/surface';
4
+ import Paragraph from '../../components/paragraph';
5
+ import Progress from '../../components/progress';
6
+ import Button from '../../components/button';
7
+ import SettingsSection from '../../components/settingsSection';
8
+ import { formatBytes } from '../../components/formatNumber';
9
+ import { Center, Cluster, Stack } from '../../components/layout';
10
+ // A real app passes the router from its framework, such as Next's useRouter().
11
+ var router = { push: function (url) { return console.info("Go to ".concat(url)); } };
12
+ // A real app reads this from the person's role. Only an admin can change the plan.
13
+ var canChangePlan = true;
14
+ // A real app reads the numbers from the server. This is Free: 50 responses, 3 members and 1 GB.
15
+ var GB = Math.pow(1024, 3);
16
+ var storage = { used: Math.round(0.85 * GB), limit: GB };
17
+ export default function UsageMetersMeters() {
18
+ var _a = useState(true), showNotice = _a[0], setShowNotice = _a[1];
19
+ return (<Center width="page">
20
+ <SettingsSection title="Usage" description="This month, on the Free plan.">
21
+ <Stack gap="large">
22
+ <Stack gap="small">
23
+ {/* At the limit the meter says 'Limit reached' in words. The notice sits under it and names the limit. */}
24
+ <Progress id="usage-meters-responses" label="AI agent responses" value={50} max={50} unit="responses" aria-describedby={showNotice ? 'usage-meters-notice' : undefined}/>
25
+ <Paragraph tone="secondary" size="body2" measure="none">Resets on Dec 1.</Paragraph>
26
+ {showNotice && (<Surface padding="small">
27
+ <Stack gap="medium">
28
+ <Stack gap="small">
29
+ <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>
30
+ <Paragraph tone="secondary" size="body2" measure="none">
31
+ {canChangePlan
32
+ ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'
33
+ : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}
34
+ </Paragraph>
35
+ </Stack>
36
+ <Cluster gap="small">
37
+ <Button size="small" type="tertiary" state="enabled" label="Not Now" onClickButton={function () { return setShowNotice(false); }}/>
38
+ {canChangePlan && (<Button size="small" type="primary" state="enabled" label="Upgrade to Pro" onClickButton={function () { return router.push('/settings/billing?plan=pro'); }}/>)}
39
+ </Cluster>
40
+ </Stack>
41
+ </Surface>)}
42
+ </Stack>
43
+ <Progress label="Members" value={2} max={3} unit="members"/>
44
+ {/* Near the limit the bar turns to a warning, and says so in words. */}
45
+ <Progress label="Storage" value={storage.used} max={storage.limit} valueText={"".concat(formatBytes(storage.used), " of ").concat(formatBytes(storage.limit))}/>
46
+ </Stack>
47
+ </SettingsSection>
48
+ </Center>);
49
+ }
@@ -0,0 +1 @@
1
+ export default function UsageMetersWithCap(): import("react").JSX.Element;
@@ -0,0 +1,73 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Alert from '../../components/alert';
4
+ import Paragraph from '../../components/paragraph';
5
+ import Progress from '../../components/progress';
6
+ import Button from '../../components/button';
7
+ import Form from '../../components/form';
8
+ import FormField from '../../components/formField';
9
+ import TextField from '../../components/textField';
10
+ import SettingsSection from '../../components/settingsSection';
11
+ import { formatMoney } from '../../components/formatNumber';
12
+ import { Center, Cluster, Stack } from '../../components/layout';
13
+ // A real app reads these from the server. Extra AI agent responses cost $0.05 each, and $18.40 is spent so far.
14
+ var spent = 18.4;
15
+ // A real app reads this from the person's role. Only an admin sets the cap.
16
+ var canChangeCap = true;
17
+ export default function UsageMetersWithCap() {
18
+ var _a = useState(20), cap = _a[0], setCap = _a[1];
19
+ var _b = useState('20'), draft = _b[0], setDraft = _b[1];
20
+ var _c = useState(''), error = _c[0], setError = _c[1];
21
+ var _d = useState(false), saving = _d[0], setSaving = _d[1];
22
+ var _e = useState(false), saved = _e[0], setSaved = _e[1];
23
+ var timer = useRef();
24
+ // Cleared before a new 'Saved' starts, so an old timer cannot end it early.
25
+ var savedTimer = useRef();
26
+ // Stops the request and the 'Saved' if the example goes away before they end.
27
+ useEffect(function () { return function () {
28
+ clearTimeout(timer.current);
29
+ clearTimeout(savedTimer.current);
30
+ }; }, []);
31
+ var next = draft.trim() === '' ? null : Number(draft);
32
+ var changed = next !== cap;
33
+ // The cap is one field with one Save Button. Empty means no cap.
34
+ function handleSave() {
35
+ if (saving || !changed)
36
+ return;
37
+ if (next !== null && !(Number.isInteger(next) && next >= 1 && next <= 10000)) {
38
+ setError("Enter a whole amount from ".concat(formatMoney(1), " to ").concat(formatMoney(10000), ", or leave it empty for no cap."));
39
+ return;
40
+ }
41
+ setError('');
42
+ setSaving(true);
43
+ // Stands in for the request to the server.
44
+ timer.current = setTimeout(function () {
45
+ setCap(next);
46
+ setSaving(false);
47
+ setSaved(true);
48
+ clearTimeout(savedTimer.current);
49
+ savedTimer.current = setTimeout(function () { return setSaved(false); }, 2000);
50
+ }, 1200);
51
+ }
52
+ var reached = cap !== null && spent >= cap;
53
+ return (<Center width="page">
54
+ <SettingsSection title="Usage" description={"This month, on the Pro plan. Extra AI agent responses cost ".concat(formatMoney(0.05), " each.")}>
55
+ <Stack gap="large">
56
+ <Stack gap="small">
57
+ {/* A cap is a limit: the bar warns near it and says 'Limit reached' at it. With no cap there is no bar. */}
58
+ <Progress label="Spend this month" value={spent} max={cap} valueText={cap === null ? "".concat(formatMoney(spent), " so far, no cap") : "".concat(formatMoney(spent), " of ").concat(formatMoney(cap))}/>
59
+ <Paragraph tone="secondary" size="body2" measure="none">Resets on Dec 1.</Paragraph>
60
+ {reached && <Alert type="warning" variant="inline" autoDismiss={false} message="AI agent responses are paused. Raise the cap, or they start again on Dec 1."/>}
61
+ </Stack>
62
+ {canChangeCap ? (<Form aria-label="Monthly spend cap" gap="medium" onSubmit={handleSave}>
63
+ <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}>
64
+ {function (f) { return (<TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} type="number" value={draft} disabled={saving} onChange={function (e) { setDraft(e.target.value); setError(''); setSaved(false); }}/>); }}
65
+ </FormField>
66
+ <Cluster>
67
+ <Button size="medium" type="primary" state={changed || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType="submit" loading={saving}/>
68
+ </Cluster>
69
+ </Form>) : (<Paragraph tone="secondary" size="body2" measure="none">{"The monthly spend cap is ".concat(cap === null ? 'not set' : formatMoney(cap), ". Only admins can change it.")}</Paragraph>)}
70
+ </Stack>
71
+ </SettingsSection>
72
+ </Center>);
73
+ }
@@ -0,0 +1,303 @@
1
+ # Usage against limits
2
+
3
+ A plan limits some things, such as AI agent responses, members and storage. The admin checks how close the workspace is.
4
+
5
+ ## Do
6
+
7
+ - Follow the rule 'A number shows its unit and never shows 0 for unknown'.
8
+ - 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.
9
+ - 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.
10
+ - 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`.
11
+ - 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%.
12
+ - Give a plan with no limit `max={null}`: the meter becomes text only, '3 members, no limit', with no bar.
13
+ - Show who used it in a sorted table under the meters, most first, with exact numbers and the numbers right-aligned.
14
+ - 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.
15
+ - 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.
16
+ - Show a member who cannot change the cap the amount as text with the line 'Only admins can change it.'
17
+
18
+ ## Don't
19
+
20
+ - Do not write a meter as '12 / 1,000'. Write '12 of 1,000 responses'.
21
+ - Do not show a limit by color alone. Say 'Limit reached' or 'Almost at the limit'.
22
+ - Do not draw the bar by hand. Use `Progress`.
23
+ - Do not show a bar for a plan with no limit, or write 'Unlimited' beside a number.
24
+ - Do not round a cost to four decimals. Show money with two: '$18.40'.
25
+ - Do not show the upgrade notice for a limit that is not reached.
26
+ - Do not show a cap field to a person who cannot set it.
27
+
28
+ ## Option: A meter for each limit
29
+
30
+ Use when: The plan has a few limits and the admin needs to see how close each one is.
31
+
32
+ Uses: `Button`, `Center`, `Cluster`, `Paragraph`, `Progress`, `SettingsSection`, `Stack`, `Surface`, `formatBytes`
33
+
34
+ ```tsx
35
+ 'use client';
36
+ import { useState } from 'react';
37
+ import Surface from 'oneslash-design-system/components/surface';
38
+ import Paragraph from 'oneslash-design-system/components/paragraph';
39
+ import Progress from 'oneslash-design-system/components/progress';
40
+ import Button from 'oneslash-design-system/components/button';
41
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
42
+ import { formatBytes } from 'oneslash-design-system/components/formatNumber';
43
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
44
+
45
+ // A real app passes the router from its framework, such as Next's useRouter().
46
+ const router = { push: (url: string) => console.info(`Go to ${url}`) };
47
+
48
+ // A real app reads this from the person's role. Only an admin can change the plan.
49
+ const canChangePlan = true;
50
+
51
+ // A real app reads the numbers from the server. This is Free: 50 responses, 3 members and 1 GB.
52
+ const GB = 1024 ** 3;
53
+ const storage = { used: Math.round(0.85 * GB), limit: GB };
54
+
55
+ export default function UsageMetersMeters() {
56
+ const [showNotice, setShowNotice] = useState(true);
57
+
58
+ return (
59
+ <Center width="page">
60
+ <SettingsSection title="Usage" description="This month, on the Free plan.">
61
+ <Stack gap="large">
62
+ <Stack gap="small">
63
+ {/* At the limit the meter says 'Limit reached' in words. The notice sits under it and names the limit. */}
64
+ <Progress id="usage-meters-responses" label="AI agent responses" value={50} max={50} unit="responses" aria-describedby={showNotice ? 'usage-meters-notice' : undefined} />
65
+ <Paragraph tone="secondary" size="body2" measure="none">Resets on Dec 1.</Paragraph>
66
+ {showNotice && (
67
+ <Surface padding="small">
68
+ <Stack gap="medium">
69
+ <Stack gap="small">
70
+ <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>
71
+ <Paragraph tone="secondary" size="body2" measure="none">
72
+ {canChangePlan
73
+ ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'
74
+ : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}
75
+ </Paragraph>
76
+ </Stack>
77
+ <Cluster gap="small">
78
+ <Button size="small" type="tertiary" state="enabled" label="Not Now" onClickButton={() => setShowNotice(false)} />
79
+ {canChangePlan && (
80
+ <Button size="small" type="primary" state="enabled" label="Upgrade to Pro" onClickButton={() => router.push('/settings/billing?plan=pro')} />
81
+ )}
82
+ </Cluster>
83
+ </Stack>
84
+ </Surface>
85
+ )}
86
+ </Stack>
87
+ <Progress label="Members" value={2} max={3} unit="members" />
88
+ {/* Near the limit the bar turns to a warning, and says so in words. */}
89
+ <Progress label="Storage" value={storage.used} max={storage.limit} valueText={`${formatBytes(storage.used)} of ${formatBytes(storage.limit)}`} />
90
+ </Stack>
91
+ </SettingsSection>
92
+ </Center>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ## Option: Who used it, under the meters
98
+
99
+ Use when: People share one pool, and the admin asks who used it.
100
+
101
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `Paragraph`, `Progress`, `SettingsSection`, `Stack`, `Surface`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `formatCount`
102
+
103
+ ```tsx
104
+ 'use client';
105
+ import { useState } from 'react';
106
+ import Surface from 'oneslash-design-system/components/surface';
107
+ import Paragraph from 'oneslash-design-system/components/paragraph';
108
+ import Heading from 'oneslash-design-system/components/heading';
109
+ import Progress from 'oneslash-design-system/components/progress';
110
+ import Button from 'oneslash-design-system/components/button';
111
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
112
+ import TableContainer from 'oneslash-design-system/components/tableContainer';
113
+ import TableHeader from 'oneslash-design-system/components/tableHeader';
114
+ import TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';
115
+ import TableRow from 'oneslash-design-system/components/tableRow';
116
+ import TableCell from 'oneslash-design-system/components/tableCell';
117
+ import { formatCount } from 'oneslash-design-system/components/formatNumber';
118
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
119
+
120
+ // A real app passes the router from its framework, such as Next's useRouter().
121
+ const router = { push: (url: string) => console.info(`Go to ${url}`) };
122
+
123
+ // A real app reads this from the person's role. Only an admin can change the plan.
124
+ const canChangePlan = true;
125
+
126
+ // A real app counts these on the server, most first. A count can pass its limit by a few: replies that were
127
+ // already running when the limit was reached still finish.
128
+ const people = [
129
+ { id: 'dana', name: 'Dana Lee', responses: 21 },
130
+ { id: 'ben', name: 'Ben Carter', responses: 19 },
131
+ { id: 'omar', name: 'Omar Reyes', responses: 13 },
132
+ ];
133
+ const total = people.reduce((sum, p) => sum + p.responses, 0);
134
+
135
+ export default function UsageMetersByPerson() {
136
+ const [showNotice, setShowNotice] = useState(true);
137
+
138
+ return (
139
+ <Center width="page">
140
+ <SettingsSection title="Usage" description="This month, on the Free plan.">
141
+ <Stack gap="large">
142
+ <Stack gap="small">
143
+ <Progress label="AI agent responses" value={total} max={50} unit="responses" aria-describedby={showNotice ? 'usage-meters-person-notice' : undefined} />
144
+ <Paragraph tone="secondary" size="body2" measure="none">Resets on Dec 1.</Paragraph>
145
+ {showNotice && (
146
+ <Surface padding="small">
147
+ <Stack gap="medium">
148
+ <Stack gap="small">
149
+ <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>
150
+ <Paragraph tone="secondary" size="body2" measure="none">
151
+ {canChangePlan
152
+ ? 'The Pro plan gives Acme 1,000 AI agent responses a month.'
153
+ : 'Ask a workspace admin to upgrade Acme to Pro for more replies.'}
154
+ </Paragraph>
155
+ </Stack>
156
+ <Cluster gap="small">
157
+ <Button size="small" type="tertiary" state="enabled" label="Not Now" onClickButton={() => setShowNotice(false)} />
158
+ {canChangePlan && (
159
+ <Button size="small" type="primary" state="enabled" label="Upgrade to Pro" onClickButton={() => router.push('/settings/billing?plan=pro')} />
160
+ )}
161
+ </Cluster>
162
+ </Stack>
163
+ </Surface>
164
+ )}
165
+ </Stack>
166
+ {/* Under the meters: who used it, most first, with exact numbers. */}
167
+ <Stack gap="small">
168
+ <Heading level={3} size="h6">Responses by person</Heading>
169
+ <TableContainer aria-label="Responses by person" minWidth="320px">
170
+ <TableHeader>
171
+ <TableRow>
172
+ <TableHeaderCell>Person</TableHeaderCell>
173
+ <TableHeaderCell width="130px" align="right">Responses</TableHeaderCell>
174
+ </TableRow>
175
+ </TableHeader>
176
+ {people.map((p) => (
177
+ <TableRow key={p.id}>
178
+ <TableCell>{p.name}</TableCell>
179
+ <TableCell width="130px" align="right">{formatCount(p.responses)}</TableCell>
180
+ </TableRow>
181
+ ))}
182
+ </TableContainer>
183
+ </Stack>
184
+ </Stack>
185
+ </SettingsSection>
186
+ </Center>
187
+ );
188
+ }
189
+ ```
190
+
191
+ ## Option: Billed by the amount, with a cap
192
+
193
+ Use when: Use is billed by the amount, and the admin sets a monthly spend cap that pauses use when it is reached.
194
+
195
+ Uses: `Alert`, `Button`, `Center`, `Cluster`, `Form`, `FormField`, `Paragraph`, `Progress`, `SettingsSection`, `Stack`, `TextField`, `formatMoney`
196
+
197
+ ```tsx
198
+ 'use client';
199
+ import { useEffect, useRef, useState } from 'react';
200
+ import Alert from 'oneslash-design-system/components/alert';
201
+ import Paragraph from 'oneslash-design-system/components/paragraph';
202
+ import Progress from 'oneslash-design-system/components/progress';
203
+ import Button from 'oneslash-design-system/components/button';
204
+ import Form from 'oneslash-design-system/components/form';
205
+ import FormField from 'oneslash-design-system/components/formField';
206
+ import TextField from 'oneslash-design-system/components/textField';
207
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
208
+ import { formatMoney } from 'oneslash-design-system/components/formatNumber';
209
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
210
+
211
+ // A real app reads these from the server. Extra AI agent responses cost $0.05 each, and $18.40 is spent so far.
212
+ const spent = 18.4;
213
+
214
+ // A real app reads this from the person's role. Only an admin sets the cap.
215
+ const canChangeCap = true;
216
+
217
+ export default function UsageMetersWithCap() {
218
+ const [cap, setCap] = useState<number | null>(20);
219
+ const [draft, setDraft] = useState('20');
220
+ const [error, setError] = useState('');
221
+ const [saving, setSaving] = useState(false);
222
+ const [saved, setSaved] = useState(false);
223
+ const timer = useRef<ReturnType<typeof setTimeout>>();
224
+ // Cleared before a new 'Saved' starts, so an old timer cannot end it early.
225
+ const savedTimer = useRef<ReturnType<typeof setTimeout>>();
226
+
227
+ // Stops the request and the 'Saved' if the example goes away before they end.
228
+ useEffect(() => () => {
229
+ clearTimeout(timer.current);
230
+ clearTimeout(savedTimer.current);
231
+ }, []);
232
+
233
+ const next = draft.trim() === '' ? null : Number(draft);
234
+ const changed = next !== cap;
235
+
236
+ // The cap is one field with one Save Button. Empty means no cap.
237
+ function handleSave() {
238
+ if (saving || !changed) return;
239
+ if (next !== null && !(Number.isInteger(next) && next >= 1 && next <= 10000)) {
240
+ setError(`Enter a whole amount from ${formatMoney(1)} to ${formatMoney(10000)}, or leave it empty for no cap.`);
241
+ return;
242
+ }
243
+ setError('');
244
+ setSaving(true);
245
+ // Stands in for the request to the server.
246
+ timer.current = setTimeout(() => {
247
+ setCap(next);
248
+ setSaving(false);
249
+ setSaved(true);
250
+ clearTimeout(savedTimer.current);
251
+ savedTimer.current = setTimeout(() => setSaved(false), 2000);
252
+ }, 1200);
253
+ }
254
+
255
+ const reached = cap !== null && spent >= cap;
256
+
257
+ return (
258
+ <Center width="page">
259
+ <SettingsSection title="Usage" description={`This month, on the Pro plan. Extra AI agent responses cost ${formatMoney(0.05)} each.`}>
260
+ <Stack gap="large">
261
+ <Stack gap="small">
262
+ {/* A cap is a limit: the bar warns near it and says 'Limit reached' at it. With no cap there is no bar. */}
263
+ <Progress
264
+ label="Spend this month"
265
+ value={spent}
266
+ max={cap}
267
+ valueText={cap === null ? `${formatMoney(spent)} so far, no cap` : `${formatMoney(spent)} of ${formatMoney(cap)}`}
268
+ />
269
+ <Paragraph tone="secondary" size="body2" measure="none">Resets on Dec 1.</Paragraph>
270
+ {reached && <Alert type="warning" variant="inline" autoDismiss={false} message="AI agent responses are paused. Raise the cap, or they start again on Dec 1." />}
271
+ </Stack>
272
+ {canChangeCap ? (
273
+ <Form aria-label="Monthly spend cap" gap="medium" onSubmit={handleSave}>
274
+ <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}>
275
+ {(f) => (
276
+ <TextField
277
+ id={f.id}
278
+ aria-describedby={f['aria-describedby']}
279
+ aria-invalid={f['aria-invalid']}
280
+ type="number"
281
+ value={draft}
282
+ disabled={saving}
283
+ onChange={(e) => { setDraft(e.target.value); setError(''); setSaved(false); }}
284
+ />
285
+ )}
286
+ </FormField>
287
+ <Cluster>
288
+ <Button size="medium" type="primary" state={changed || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType="submit" loading={saving} />
289
+ </Cluster>
290
+ </Form>
291
+ ) : (
292
+ <Paragraph tone="secondary" size="body2" measure="none">{`The monthly spend cap is ${cap === null ? 'not set' : formatMoney(cap)}. Only admins can change it.`}</Paragraph>
293
+ )}
294
+ </Stack>
295
+ </SettingsSection>
296
+ </Center>
297
+ );
298
+ }
299
+ ```
300
+
301
+ ## Native
302
+
303
+ 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.