oneslash-design-system 2.17.0 → 2.19.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 (282) hide show
  1. package/README.md +2 -2
  2. package/dist/DESIGN.md +55 -14
  3. package/dist/cases/accept-invite.md +1 -5
  4. package/dist/cases/account-menu/menu.d.ts +1 -0
  5. package/dist/cases/account-menu/menu.jsx +99 -0
  6. package/dist/cases/account-menu.md +164 -0
  7. package/dist/cases/agent-asks-before-risky-action.md +0 -4
  8. package/dist/cases/agent-cancels-when-unanswered.md +0 -4
  9. package/dist/cases/agent-options.md +0 -4
  10. package/dist/cases/agent-pending-reply.md +0 -4
  11. package/dist/cases/agent-plan-proposal.md +0 -4
  12. package/dist/cases/agent-question.md +0 -4
  13. package/dist/cases/agent-refuses-clearly.md +0 -4
  14. package/dist/cases/agent-says-what-it-is.md +0 -2
  15. package/dist/cases/agent-settings/form.d.ts +1 -0
  16. package/dist/cases/agent-settings/form.jsx +164 -0
  17. package/dist/cases/agent-settings.md +259 -0
  18. package/dist/cases/agent-shows-progress.md +0 -2
  19. package/dist/cases/agent-shows-sources.md +0 -2
  20. package/dist/cases/api-keys/list.d.ts +1 -0
  21. package/dist/cases/api-keys/list.jsx +162 -0
  22. package/dist/cases/api-keys.md +229 -0
  23. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  24. package/dist/cases/app-shell/sidebar.jsx +124 -0
  25. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  26. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  27. package/dist/cases/app-shell.md +364 -0
  28. package/dist/cases/artifact-card/card.jsx +32 -6
  29. package/dist/cases/artifact-card.md +55 -11
  30. package/dist/cases/auth-gate-loading.md +0 -4
  31. package/dist/cases/check-your-email.md +0 -4
  32. package/dist/cases/collapsible-search/popover.d.ts +1 -0
  33. package/dist/cases/collapsible-search/popover.jsx +74 -0
  34. package/dist/cases/collapsible-search.md +143 -0
  35. package/dist/cases/composer-limit.md +0 -4
  36. package/dist/cases/confirm-destructive-action.md +0 -4
  37. package/dist/cases/confirm-dialogs.md +0 -4
  38. package/dist/cases/conversation-starters.md +0 -4
  39. package/dist/cases/create-modal.md +0 -4
  40. package/dist/cases/danger-zone/collapsed.d.ts +1 -0
  41. package/dist/cases/danger-zone/collapsed.jsx +75 -0
  42. package/dist/cases/danger-zone/shown.d.ts +1 -0
  43. package/dist/cases/danger-zone/shown.jsx +95 -0
  44. package/dist/cases/danger-zone.md +263 -0
  45. package/dist/cases/device-login.md +0 -4
  46. package/dist/cases/email-confirmed.md +0 -4
  47. package/dist/cases/empty-list.md +0 -4
  48. package/dist/cases/empty-lists.md +0 -4
  49. package/dist/cases/empty-not-set-up.md +0 -4
  50. package/dist/cases/empty-search.md +0 -4
  51. package/dist/cases/error-page/in-shell.jsx +26 -17
  52. package/dist/cases/error-page.md +42 -25
  53. package/dist/cases/feedback-form.md +0 -4
  54. package/dist/cases/filter-menu/presets.d.ts +1 -0
  55. package/dist/cases/filter-menu/presets.jsx +53 -0
  56. package/dist/cases/filter-menu/with-clear.d.ts +1 -0
  57. package/dist/cases/filter-menu/with-clear.jsx +56 -0
  58. package/dist/cases/filter-menu.md +204 -0
  59. package/dist/cases/forgot-password.md +0 -4
  60. package/dist/cases/form-errors.md +0 -4
  61. package/dist/cases/import-checklist.md +0 -4
  62. package/dist/cases/inline-form-feedback.md +0 -4
  63. package/dist/cases/integrations-list/nested.d.ts +1 -0
  64. package/dist/cases/integrations-list/nested.jsx +164 -0
  65. package/dist/cases/integrations-list/rows.d.ts +1 -0
  66. package/dist/cases/integrations-list/rows.jsx +134 -0
  67. package/dist/cases/integrations-list.md +379 -0
  68. package/dist/cases/invite-member.md +0 -4
  69. package/dist/cases/load-failure.md +0 -4
  70. package/dist/cases/log-out-confirm.md +0 -4
  71. package/dist/cases/login-page.md +0 -4
  72. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  73. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  74. package/dist/cases/master-detail/split.d.ts +1 -0
  75. package/dist/cases/master-detail/split.jsx +49 -0
  76. package/dist/cases/master-detail.md +213 -0
  77. package/dist/cases/members-list/rows.d.ts +1 -0
  78. package/dist/cases/members-list/rows.jsx +318 -0
  79. package/dist/cases/members-list/table.d.ts +1 -0
  80. package/dist/cases/members-list/table.jsx +351 -0
  81. package/dist/cases/members-list.md +799 -0
  82. package/dist/cases/mention-list.md +0 -4
  83. package/dist/cases/message-actions.md +0 -4
  84. package/dist/cases/message-attachments.md +0 -4
  85. package/dist/cases/message-composer.md +0 -4
  86. package/dist/cases/message-edit.md +0 -4
  87. package/dist/cases/message-reactions.md +0 -4
  88. package/dist/cases/message-row.md +0 -4
  89. package/dist/cases/mobile-menu/links.d.ts +1 -0
  90. package/dist/cases/mobile-menu/links.jsx +24 -0
  91. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  92. package/dist/cases/mobile-menu/sections.jsx +61 -0
  93. package/dist/cases/mobile-menu.md +170 -0
  94. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  95. package/dist/cases/not-found-page.md +41 -24
  96. package/dist/cases/notification-menu/menu.d.ts +1 -0
  97. package/dist/cases/notification-menu/menu.jsx +74 -0
  98. package/dist/cases/notification-menu.md +135 -0
  99. package/dist/cases/oauth-consent.md +0 -4
  100. package/dist/cases/on-off-settings/list.d.ts +1 -0
  101. package/dist/cases/on-off-settings/list.jsx +97 -0
  102. package/dist/cases/on-off-settings.md +116 -0
  103. package/dist/cases/on-this-page/aside.d.ts +1 -0
  104. package/dist/cases/on-this-page/aside.jsx +39 -0
  105. package/dist/cases/on-this-page.md +80 -0
  106. package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
  107. package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
  108. package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
  109. package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
  110. package/dist/cases/overflow-menu.md +410 -0
  111. package/dist/cases/page-header/actions.d.ts +1 -0
  112. package/dist/cases/page-header/actions.jsx +65 -0
  113. package/dist/cases/page-header/sub-page.d.ts +1 -0
  114. package/dist/cases/page-header/sub-page.jsx +37 -0
  115. package/dist/cases/page-header.md +195 -0
  116. package/dist/cases/phone-navigation.md +32 -0
  117. package/dist/cases/profile-form/form.d.ts +1 -0
  118. package/dist/cases/profile-form/form.jsx +153 -0
  119. package/dist/cases/profile-form.md +236 -0
  120. package/dist/cases/quick-switcher/modal.d.ts +1 -0
  121. package/dist/cases/quick-switcher/modal.jsx +114 -0
  122. package/dist/cases/quick-switcher.md +205 -0
  123. package/dist/cases/range-switch/segmented.d.ts +1 -0
  124. package/dist/cases/range-switch/segmented.jsx +30 -0
  125. package/dist/cases/range-switch.md +67 -0
  126. package/dist/cases/rename.md +0 -4
  127. package/dist/cases/reply-feedback.md +0 -4
  128. package/dist/cases/reply-sources.md +0 -4
  129. package/dist/cases/route-loading/region.jsx +27 -18
  130. package/dist/cases/route-loading.md +42 -23
  131. package/dist/cases/scope-picker/menu.d.ts +1 -0
  132. package/dist/cases/scope-picker/menu.jsx +47 -0
  133. package/dist/cases/scope-picker.md +97 -0
  134. package/dist/cases/set-new-password.md +0 -4
  135. package/dist/cases/settings-page/side-nav.d.ts +1 -0
  136. package/dist/cases/settings-page/side-nav.jsx +171 -0
  137. package/dist/cases/settings-page/top-tabs.d.ts +1 -0
  138. package/dist/cases/settings-page/top-tabs.jsx +129 -0
  139. package/dist/cases/settings-page.md +378 -0
  140. package/dist/cases/settings-save.md +35 -0
  141. package/dist/cases/side-pane/beside.d.ts +1 -0
  142. package/dist/cases/side-pane/beside.jsx +79 -0
  143. package/dist/cases/side-pane/over.d.ts +1 -0
  144. package/dist/cases/side-pane/over.jsx +58 -0
  145. package/dist/cases/side-pane.md +238 -0
  146. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  147. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  148. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  149. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  150. package/dist/cases/sidebar-nav.md +261 -0
  151. package/dist/cases/sign-up-page.md +1 -5
  152. package/dist/cases/site-footer/columns.d.ts +1 -0
  153. package/dist/cases/site-footer/columns.jsx +51 -0
  154. package/dist/cases/site-footer/simple.d.ts +1 -0
  155. package/dist/cases/site-footer/simple.jsx +24 -0
  156. package/dist/cases/site-footer.md +133 -0
  157. package/dist/cases/site-header/links.d.ts +1 -0
  158. package/dist/cases/site-header/links.jsx +26 -0
  159. package/dist/cases/site-header/sections.d.ts +1 -0
  160. package/dist/cases/site-header/sections.jsx +64 -0
  161. package/dist/cases/site-header.md +183 -0
  162. package/dist/cases/slash-command-list.md +0 -4
  163. package/dist/cases/success-feedback.md +0 -4
  164. package/dist/cases/tag-filter/tags.d.ts +1 -0
  165. package/dist/cases/tag-filter/tags.jsx +226 -0
  166. package/dist/cases/tag-filter.md +298 -0
  167. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  168. package/dist/cases/theme-switcher/menu.jsx +47 -0
  169. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  170. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  171. package/dist/cases/theme-switcher.md +149 -0
  172. package/dist/cases/type-to-confirm.md +0 -4
  173. package/dist/cases/typing-and-status.md +0 -4
  174. package/dist/cases/unsaved-changes-guard.md +0 -4
  175. package/dist/cases/upgrade-prompt.md +0 -4
  176. package/dist/cases.json +1737 -315
  177. package/dist/components/alert.d.ts +3 -1
  178. package/dist/components/alert.jsx +2 -2
  179. package/dist/components/appShell.d.ts +44 -0
  180. package/dist/components/appShell.jsx +121 -0
  181. package/dist/components/button.jsx +5 -2
  182. package/dist/components/checkBox.d.ts +5 -1
  183. package/dist/components/checkBox.jsx +2 -2
  184. package/dist/components/copyField.d.ts +20 -0
  185. package/dist/components/copyField.jsx +99 -0
  186. package/dist/components/drawer.d.ts +31 -0
  187. package/dist/components/drawer.jsx +121 -0
  188. package/dist/components/formField.d.ts +34 -0
  189. package/dist/components/formField.jsx +28 -0
  190. package/dist/components/heading.d.ts +5 -1
  191. package/dist/components/heading.jsx +2 -2
  192. package/dist/components/link.d.ts +6 -1
  193. package/dist/components/link.jsx +11 -3
  194. package/dist/components/menu.jsx +2 -2
  195. package/dist/components/menuItem.d.ts +10 -2
  196. package/dist/components/menuItem.jsx +4 -3
  197. package/dist/components/modal.jsx +12 -23
  198. package/dist/components/navigation.d.ts +9 -1
  199. package/dist/components/navigation.jsx +15 -3
  200. package/dist/components/onThisPage.d.ts +29 -0
  201. package/dist/components/onThisPage.jsx +151 -0
  202. package/dist/components/pageShell.d.ts +7 -1
  203. package/dist/components/pageShell.jsx +14 -1
  204. package/dist/components/popover.jsx +4 -0
  205. package/dist/components/radioGroup.d.ts +5 -1
  206. package/dist/components/radioGroup.jsx +2 -2
  207. package/dist/components/segmentedControl.d.ts +22 -0
  208. package/dist/components/segmentedControl.jsx +54 -0
  209. package/dist/components/select.d.ts +5 -1
  210. package/dist/components/select.jsx +2 -2
  211. package/dist/components/settingsSection.d.ts +36 -0
  212. package/dist/components/settingsSection.jsx +65 -0
  213. package/dist/components/sidePane.d.ts +32 -0
  214. package/dist/components/sidePane.jsx +128 -0
  215. package/dist/components/siteFooter.d.ts +24 -0
  216. package/dist/components/siteFooter.jsx +48 -0
  217. package/dist/components/siteHeader.d.ts +55 -0
  218. package/dist/components/siteHeader.jsx +125 -0
  219. package/dist/components/slidingIndicator.d.ts +50 -0
  220. package/dist/components/slidingIndicator.jsx +102 -0
  221. package/dist/components/switch.d.ts +25 -0
  222. package/dist/components/switch.jsx +55 -0
  223. package/dist/components/tab.jsx +5 -11
  224. package/dist/components/tabsContainer.jsx +5 -67
  225. package/dist/components/textField.d.ts +12 -2
  226. package/dist/components/textField.jsx +11 -4
  227. package/dist/components/textarea.d.ts +5 -1
  228. package/dist/components/textarea.jsx +3 -3
  229. package/dist/components/titleBar.d.ts +17 -0
  230. package/dist/components/titleBar.jsx +17 -0
  231. package/dist/components/useHotkey.d.ts +7 -0
  232. package/dist/components/useHotkey.js +24 -0
  233. package/dist/index.d.ts +13 -0
  234. package/dist/index.js +13 -0
  235. package/dist/internal/copyField.d.ts +5 -0
  236. package/dist/internal/copyField.js +61 -0
  237. package/dist/internal/hotkey.d.ts +16 -0
  238. package/dist/internal/hotkey.js +20 -0
  239. package/dist/internal/overlayStack.d.ts +24 -0
  240. package/dist/internal/overlayStack.js +71 -0
  241. package/dist/internal/resize.d.ts +9 -0
  242. package/dist/internal/resize.js +31 -0
  243. package/dist/internal/scrollSpy.d.ts +24 -0
  244. package/dist/internal/scrollSpy.js +53 -0
  245. package/dist/internal/siteBrand.d.ts +6 -0
  246. package/dist/internal/siteBrand.jsx +11 -0
  247. package/dist/internal/switch.d.ts +5 -0
  248. package/dist/internal/switch.js +9 -0
  249. package/dist/native-mapping.json +72 -0
  250. package/dist/stories/AppShell.stories.d.ts +15 -0
  251. package/dist/stories/AppShell.stories.jsx +137 -0
  252. package/dist/stories/Cases.generated.stories.d.ts +42 -0
  253. package/dist/stories/Cases.generated.stories.jsx +84 -0
  254. package/dist/stories/CopyField.stories.d.ts +11 -0
  255. package/dist/stories/CopyField.stories.jsx +65 -0
  256. package/dist/stories/Drawer.stories.d.ts +10 -0
  257. package/dist/stories/Drawer.stories.jsx +123 -0
  258. package/dist/stories/FormField.stories.d.ts +6 -0
  259. package/dist/stories/FormField.stories.jsx +44 -0
  260. package/dist/stories/Link.stories.d.ts +1 -0
  261. package/dist/stories/Link.stories.jsx +8 -0
  262. package/dist/stories/Navigation.stories.d.ts +1 -0
  263. package/dist/stories/Navigation.stories.jsx +17 -1
  264. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  265. package/dist/stories/OnThisPage.stories.jsx +105 -0
  266. package/dist/stories/SegmentedControl.stories.d.ts +8 -0
  267. package/dist/stories/SegmentedControl.stories.jsx +33 -0
  268. package/dist/stories/SettingsSection.stories.d.ts +12 -0
  269. package/dist/stories/SettingsSection.stories.jsx +91 -0
  270. package/dist/stories/SidePane.stories.d.ts +6 -0
  271. package/dist/stories/SidePane.stories.jsx +37 -0
  272. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  273. package/dist/stories/SiteFooter.stories.jsx +63 -0
  274. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  275. package/dist/stories/SiteHeader.stories.jsx +94 -0
  276. package/dist/stories/Switch.stories.d.ts +14 -0
  277. package/dist/stories/Switch.stories.jsx +87 -0
  278. package/dist/stories/TextField.stories.d.ts +1 -0
  279. package/dist/stories/TextField.stories.jsx +13 -0
  280. package/dist/stories/TitleBar.stories.d.ts +6 -0
  281. package/dist/stories/TitleBar.stories.jsx +34 -0
  282. package/package.json +5 -1
@@ -0,0 +1,298 @@
1
+ # Tag filter
2
+
3
+ A person filters a list by a tag, and adds, renames and deletes the tags themselves.
4
+
5
+ ## Do
6
+
7
+ - Use a row of `Tag` with `variant="contained"` and `size="medium"` in a `Cluster`. Put 'All' first, then each tag. The row wraps.
8
+ - Mark the chosen one with `state="selected"`. A clickable `Tag` is a toggle and reports `aria-pressed`.
9
+ - Choose Tags over a `SegmentedControl`. A `SegmentedControl` is for a fixed set of two to four, as in the case 'Range switch'. It cannot grow, wrap or hold a field.
10
+ - Show one More `IconButton` after the selected tag: `ariaLabel="More actions for tag Design"`. The row gets one extra stop, not one for each tag.
11
+ - Open a navigable menu from it: `<Popover returnFocus>` around `<Menu navigable aria-label="Tag actions">` with 'Rename', then a danger 'Delete'.
12
+ - Rename in place, as the case 'Rename' says. The row becomes a field with `aria-label="Rename tag Design"`. Enter and a click away save, and Escape cancels.
13
+ - Add a tag with an 'Add Tag' Button that turns the row into the same field, with `aria-label="New tag name"`. The new tag is chosen once it is added.
14
+ - Show a name that is taken under the field with `error` and `errorText`, and keep what the person typed.
15
+ - Confirm Delete in a small Modal, as the case 'Delete confirm' says: 'Cancel' first, then a danger 'Delete'.
16
+ - Say where the items go: 'Its 3 items stay in All, with no tag.' Name the tag in a toast when it is gone.
17
+ - Put focus on the More button after Rename or Cancel, and on 'Add Tag' after a delete, since the tag and its More button are gone.
18
+
19
+ ## Don't
20
+
21
+ - Do not use a `SegmentedControl` for tags that people add and delete.
22
+ - Do not delete the items with their tag.
23
+ - Do not say 'Are you sure?' in the confirm. Say what is deleted and where the items go.
24
+ - Do not add a 'Delete' that has no confirm. A tag may be on many items.
25
+ - Do not leave the row on a tag that was just deleted. It goes back to All.
26
+
27
+ ## Example: Row of toggle Tags
28
+
29
+ Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `IconButton`, `Menu`, `MenuItem`, `Modal`, `Paragraph`, `Popover`, `Stack`, `TableCell`, `TableContainer`, `TableRow`, `Tag`, `TextField`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
30
+
31
+ ```tsx
32
+ 'use client';
33
+ import { useEffect, useRef, useState } from 'react';
34
+ import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
35
+ import Modal from 'oneslash-design-system/components/modal';
36
+ import Heading from 'oneslash-design-system/components/heading';
37
+ import Paragraph from 'oneslash-design-system/components/paragraph';
38
+ import TextField from 'oneslash-design-system/components/textField';
39
+ import Tag from 'oneslash-design-system/components/tag';
40
+ import Button from 'oneslash-design-system/components/button';
41
+ import IconButton from 'oneslash-design-system/components/iconButton';
42
+ import Tooltip from 'oneslash-design-system/components/tooltip';
43
+ import Popover from 'oneslash-design-system/components/popover';
44
+ import Menu from 'oneslash-design-system/components/menu';
45
+ import MenuItem from 'oneslash-design-system/components/menuItem';
46
+ import EmptyBox from 'oneslash-design-system/components/emptyBox';
47
+ import TableContainer from 'oneslash-design-system/components/tableContainer';
48
+ import TableRow from 'oneslash-design-system/components/tableRow';
49
+ import TableCell from 'oneslash-design-system/components/tableCell';
50
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
51
+
52
+ // A real app reads these from the server. 'All' is not a tag: it shows every item.
53
+ type Item = { id: string; title: string; tagId: string | null };
54
+ const firstTags = [
55
+ { id: 'design', name: 'Design' },
56
+ { id: 'research', name: 'Research' },
57
+ { id: 'ideas', name: 'Ideas' },
58
+ ];
59
+ const firstItems: Item[] = [
60
+ { id: 'i1', title: 'Pricing page teardown', tagId: 'research' },
61
+ { id: 'i2', title: 'Color tokens for dark mode', tagId: 'design' },
62
+ { id: 'i3', title: 'Onboarding checklist patterns', tagId: 'design' },
63
+ { id: 'i4', title: 'Interview notes, March', tagId: 'research' },
64
+ { id: 'i5', title: 'A weekly digest email', tagId: 'ideas' },
65
+ { id: 'i6', title: 'Keyboard shortcut cheat sheet', tagId: null },
66
+ ];
67
+
68
+ // What the field is for: a new tag, or the selected tag's new name.
69
+ type Editing = 'add' | 'rename' | null;
70
+
71
+ export default function TagFilterTags() {
72
+ const [tags, setTags] = useState(firstTags);
73
+ const [items, setItems] = useState(firstItems);
74
+ // null is 'All'.
75
+ const [selected, setSelected] = useState<string | null>('design');
76
+ const [editing, setEditing] = useState<Editing>(null);
77
+ const [draft, setDraft] = useState('');
78
+ const [taken, setTaken] = useState(false);
79
+ const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
80
+ const [menuOpen, setMenuOpen] = useState(false);
81
+ const [confirming, setConfirming] = useState(false);
82
+ const [deleting, setDeleting] = useState(false);
83
+ // The tag the confirm is about, kept until the Modal is closed, so its text stays while it fades out.
84
+ const [doomed, setDoomed] = useState<{ name: string; count: number }>({ name: '', count: 0 });
85
+ const timer = useRef<ReturnType<typeof setTimeout>>();
86
+ const toastIds = useRef<string[]>([]);
87
+ const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
88
+ const addButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
89
+ // Enter and Escape end the edit before the field goes away, so its blur must not save again.
90
+ const ended = useRef(false);
91
+ // Where focus goes after the next render, once the element it goes to is on screen.
92
+ const focusNext = useRef<() => void>();
93
+
94
+ const tag = tags.find((t) => t.id === selected);
95
+ const shown = selected === null ? items : items.filter((i) => i.tagId === selected);
96
+ const nameOf = (tagId: string | null) => tags.find((t) => t.id === tagId)?.name ?? 'No tag';
97
+
98
+ // On unmount it stops the request and closes every toast it opened.
99
+ useEffect(() => () => {
100
+ clearTimeout(timer.current);
101
+ toastIds.current.forEach((id) => dismissToast(id));
102
+ toastIds.current = [];
103
+ }, []);
104
+
105
+ useEffect(() => {
106
+ const move = focusNext.current;
107
+ focusNext.current = undefined;
108
+ move?.();
109
+ });
110
+
111
+ function startEditing(kind: 'add' | 'rename') {
112
+ ended.current = false;
113
+ setDraft(kind === 'rename' && tag ? tag.name : '');
114
+ setTaken(false);
115
+ setEditing(kind);
116
+ }
117
+
118
+ // Enter and a click away save. An empty or unchanged name cancels. A name that is taken stays in the field with
119
+ // the error, so what the person typed is not lost. `byKey` is true for Enter, where focus goes back to where it was.
120
+ function finish(byKey: boolean) {
121
+ if (ended.current || !editing) return;
122
+ const name = draft.trim();
123
+ const unchanged = editing === 'rename' && name === tag?.name;
124
+ if (!name || unchanged) return cancel(byKey);
125
+ if (tags.some((t) => !(editing === 'rename' && t.id === selected) && t.name.toLowerCase() === name.toLowerCase())) {
126
+ setTaken(true);
127
+ return;
128
+ }
129
+ ended.current = true;
130
+ // A real app sends the name to the server here and shows it at once.
131
+ if (editing === 'rename') {
132
+ setTags((list) => list.map((t) => (t.id === selected ? { ...t, name } : t)));
133
+ } else {
134
+ const id = `tag-${name.toLowerCase().replace(/\s+/g, '-')}`;
135
+ setTags((list) => [...list, { id, name }]);
136
+ setSelected(id);
137
+ }
138
+ leave(byKey);
139
+ }
140
+
141
+ function cancel(byKey: boolean) {
142
+ if (ended.current) return;
143
+ ended.current = true;
144
+ leave(byKey);
145
+ }
146
+
147
+ function leave(byKey: boolean) {
148
+ const kind = editing;
149
+ setEditing(null);
150
+ setTaken(false);
151
+ if (byKey) focusNext.current = () => (kind === 'rename' ? moreButton.current : addButton.current)?.focus();
152
+ }
153
+
154
+ function openMenu(anchorEl: HTMLElement) {
155
+ setMenuAnchor(anchorEl);
156
+ setMenuOpen((o) => !o);
157
+ }
158
+
159
+ // The menu closes on any choice. Its Popover gives focus back to the More button.
160
+ function rename() {
161
+ setMenuOpen(false);
162
+ startEditing('rename');
163
+ }
164
+
165
+ function askToDelete() {
166
+ setMenuOpen(false);
167
+ if (tag) setDoomed({ name: tag.name, count: items.filter((i) => i.tagId === tag.id).length });
168
+ setConfirming(true);
169
+ }
170
+
171
+ // 'Cancel' ends the confirm; the More button is still there, so focus goes back to it.
172
+ function keepTag() {
173
+ if (deleting) return;
174
+ setConfirming(false);
175
+ focusNext.current = () => moreButton.current?.focus();
176
+ }
177
+
178
+ // The items keep their place in 'All' and lose the tag. The tag and its More button are gone, so focus goes to 'Add Tag'.
179
+ function confirmDelete() {
180
+ if (deleting || !tag) return;
181
+ const gone = tag;
182
+ setDeleting(true);
183
+ // Stands in for the request to the server.
184
+ timer.current = setTimeout(() => {
185
+ setDeleting(false);
186
+ setConfirming(false);
187
+ setTags((list) => list.filter((t) => t.id !== gone.id));
188
+ setItems((list) => list.map((i) => (i.tagId === gone.id ? { ...i, tagId: null } : i)));
189
+ setSelected(null);
190
+ toastIds.current.push(toast({ type: 'success', message: `${gone.name} tag deleted.` }));
191
+ focusNext.current = () => addButton.current?.focus();
192
+ }, 1200);
193
+ }
194
+
195
+ return (
196
+ <Center width="page">
197
+ {/* A real app mounts one Toaster near its root. */}
198
+ <Toaster />
199
+ <Stack gap="large">
200
+ <Heading level={1} size="h5">Reading list</Heading>
201
+ {editing ? (
202
+ // The row of tags becomes the field, as the case 'Rename' says for a name that is on screen. Enter and a click away save, Escape cancels.
203
+ <TextField
204
+ key={editing}
205
+ id="tag-filter-name"
206
+ size="small"
207
+ autoFocus
208
+ aria-label={editing === 'rename' ? `Rename tag ${tag?.name}` : 'New tag name'}
209
+ placeholder={editing === 'add' ? 'Tag name' : undefined}
210
+ value={draft}
211
+ error={taken}
212
+ errorText="A tag with this name already exists."
213
+ onChange={(e) => {
214
+ setDraft(e.target.value);
215
+ setTaken(false);
216
+ }}
217
+ onKeyDown={(e) => {
218
+ if (e.key === 'Enter') {
219
+ e.preventDefault();
220
+ finish(true);
221
+ } else if (e.key === 'Escape') {
222
+ e.preventDefault();
223
+ cancel(true);
224
+ }
225
+ }}
226
+ onBlur={() => finish(false)}
227
+ />
228
+ ) : (
229
+ // Tags that people add, rename and delete are not a fixed short set, so they are toggle Tags in a row that wraps.
230
+ <Cluster gap="small">
231
+ <Tag variant="contained" size="medium" label="All" state={selected === null ? 'selected' : 'enabled'} onClick={() => setSelected(null)} />
232
+ {tags.map((t) => (
233
+ <Tag key={t.id} variant="contained" size="medium" label={t.name} state={t.id === selected ? 'selected' : 'enabled'} onClick={() => setSelected(t.id)} />
234
+ ))}
235
+ {/* One More button, for the tag that is selected, so the row has one extra stop and not one per tag. */}
236
+ {tag && (
237
+ <Tooltip title="More">
238
+ <IconButton
239
+ ref={moreButton}
240
+ color="iconOnly"
241
+ state={menuOpen ? 'selected' : 'enabled'}
242
+ size="small"
243
+ iconName="Ellipsis"
244
+ ariaLabel={`More actions for tag ${tag.name}`}
245
+ aria-haspopup="menu"
246
+ aria-expanded={menuOpen}
247
+ onClick={(e: { currentTarget: HTMLElement }) => openMenu(e.currentTarget)}
248
+ />
249
+ </Tooltip>
250
+ )}
251
+ <Button ref={addButton} size="small" type="tertiary" state="enabled" label="Add Tag" decoIcon="Plus" onClickButton={() => startEditing('add')} />
252
+ </Cluster>
253
+ )}
254
+ {shown.length > 0 ? (
255
+ <TableContainer>
256
+ {shown.map((i) => (
257
+ <TableRow key={i.id}>
258
+ <TableCell>{i.title}</TableCell>
259
+ <TableCell width="120px">{nameOf(i.tagId)}</TableCell>
260
+ </TableRow>
261
+ ))}
262
+ </TableContainer>
263
+ ) : (
264
+ <EmptyBox size="small" icon="Tag" text={`No items tagged '${tag?.name}'`} secondText="Items you tag appear here." />
265
+ )}
266
+ </Stack>
267
+ <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>
268
+ <Menu navigable aria-label="Tag actions" width={180}>
269
+ <MenuItem size="small" iconName="Pencil" label="Rename" onClick={rename} />
270
+ {/* Delete is last, and danger. */}
271
+ <MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={askToDelete} />
272
+ </Menu>
273
+ </Popover>
274
+ <Modal
275
+ isOpen={confirming}
276
+ size="small"
277
+ title="Delete Tag"
278
+ onClose={keepTag}
279
+ actions={
280
+ <>
281
+ <Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={keepTag} />
282
+ <Button size="small" type="primary" color="danger" state="enabled" label="Delete" loading={deleting} onClickButton={confirmDelete} />
283
+ </>
284
+ }
285
+ >
286
+ <Paragraph measure="none">{`This deletes the tag '${doomed.name}'.`}</Paragraph>
287
+ <Paragraph tone="secondary" size="body2" measure="none">
288
+ {doomed.count === 1 ? 'Its 1 item stays in All, with no tag.' : `Its ${doomed.count} items stay in All, with no tag.`}
289
+ </Paragraph>
290
+ </Modal>
291
+ </Center>
292
+ );
293
+ }
294
+ ```
295
+
296
+ ## Native
297
+
298
+ On Apple use a horizontal `ScrollView` of toggle `Button`s, with a `.contextMenu` on each tag: Rename, then Delete in the `.destructive` role, which asks in a `confirmationDialog`. On Android use `FilterChip`s in a `LazyRow`.
@@ -0,0 +1 @@
1
+ export default function ThemeSwitcherMenu(): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import IconButton from '../../components/iconButton';
4
+ import Tooltip from '../../components/tooltip';
5
+ import Popover from '../../components/popover';
6
+ import Menu from '../../components/menu';
7
+ import MenuItem from '../../components/menuItem';
8
+ import PageShell from '../../components/pageShell';
9
+ import Heading from '../../components/heading';
10
+ import Paragraph from '../../components/paragraph';
11
+ import Link from '../../components/link';
12
+ import { Cluster, Stack } from '../../components/layout';
13
+ var modes = [
14
+ { value: 'light', label: 'Light', icon: 'Sun' },
15
+ { value: 'dark', label: 'Dark', icon: 'Moon' },
16
+ { value: 'system', label: 'System', icon: 'Monitor' },
17
+ ];
18
+ export default function ThemeSwitcherMenu() {
19
+ var _a;
20
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
21
+ var _b = useState('system'), mode = _b[0], setMode = _b[1];
22
+ var _c = useState(null), anchor = _c[0], setAnchor = _c[1];
23
+ var _d = useState(false), open = _d[0], setOpen = _d[1];
24
+ var current = (_a = modes.find(function (m) { return m.value === mode; })) !== null && _a !== void 0 ? _a : modes[2];
25
+ return (<PageShell>
26
+ <Stack gap="large">
27
+ <Cluster justify="between">
28
+ <Link href="#top" size="subtitle1">Acme</Link>
29
+ <Tooltip title={"Theme: ".concat(current.label)}>
30
+ <IconButton color="iconOnly" state={open ? 'selected' : 'enabled'} size="medium" iconName={current.icon} ariaLabel={"Theme: ".concat(current.label)} aria-haspopup="menu" aria-expanded={open} onClick={function (e) {
31
+ setAnchor(e.currentTarget);
32
+ setOpen(function (o) { return !o; });
33
+ }}/>
34
+ </Tooltip>
35
+ </Cluster>
36
+ <Heading level={1} size="h5">Welcome back, Dana</Heading>
37
+ <Paragraph tone="secondary" measure="none">
38
+ {mode === 'system' ? 'Acme follows your device.' : "Acme is set to ".concat(mode, ".")} In a real app the page changes now.
39
+ </Paragraph>
40
+ </Stack>
41
+ <Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
42
+ <Menu navigable aria-label="Theme" width={180}>
43
+ {modes.map(function (m) { return (<MenuItem key={m.value} size="small" iconName={m.icon} label={m.label} isSelected={m.value === mode} role="menuitemradio" onClick={function () { setMode(m.value); setOpen(false); }}/>); })}
44
+ </Menu>
45
+ </Popover>
46
+ </PageShell>);
47
+ }
@@ -0,0 +1 @@
1
+ export default function ThemeSwitcherSegmented(): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Heading from '../../components/heading';
4
+ import SettingsSection from '../../components/settingsSection';
5
+ import SegmentedControl from '../../components/segmentedControl';
6
+ import { Center, Cluster, Stack } from '../../components/layout';
7
+ var options = [
8
+ { value: 'light', label: 'Light' },
9
+ { value: 'dark', label: 'Dark' },
10
+ { value: 'system', label: 'System' },
11
+ ];
12
+ export default function ThemeSwitcherSegmented() {
13
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
14
+ var _a = useState('system'), mode = _a[0], setMode = _a[1];
15
+ return (<Center width="page">
16
+ <Stack gap="large">
17
+ <Heading level={1} size="h5">Settings</Heading>
18
+ <SettingsSection title="Appearance" description="System follows your device.">
19
+ {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}
20
+ <Cluster>
21
+ <SegmentedControl size="small" width="fit" aria-label="Theme" options={options} value={mode} onChange={setMode}/>
22
+ </Cluster>
23
+ </SettingsSection>
24
+ </Stack>
25
+ </Center>);
26
+ }
@@ -0,0 +1,149 @@
1
+ # Theme switcher
2
+
3
+ A person chooses between a light page, a dark page, or the one their device uses.
4
+
5
+ ## Do
6
+
7
+ - Offer three choices, in this order: 'Light', 'Dark' and 'System'. 'System' follows the device and is the default.
8
+ - Name the menu's `IconButton` for the current choice, in sentence case: 'Theme: Dark'. Show the icon of the current choice: a sun, a moon or a monitor.
9
+ - Open a navigable menu: `<Popover returnFocus>` around `<Menu navigable aria-label="Theme">`. Set `aria-haspopup="menu"` and `aria-expanded` on the button, and `state="selected"` while the menu is open.
10
+ - Give each item `role="menuitemradio"` and `isSelected` on the current one, and close the menu on a choice.
11
+ - Use a `SegmentedControl` named 'Theme' with `width="fit"` in a `SettingsSection` on a settings page. It saves in place and shows nothing, as the rule 'A setting saves in place, or with one Save Button' says.
12
+ - Change the page as soon as a choice is made. A choice kept on the device cannot fail, so show no message and no toast.
13
+ - Keep the choice on the device, such as in a cookie or local storage, and read it before the page paints, so the page never flashes the wrong theme.
14
+ - For 'System', set no class and follow `prefers-color-scheme`, and change the page when the device changes.
15
+ - Set the choice's class on `<html>`. The example keeps the choice in state, because it must not touch the document.
16
+
17
+ ## Don't
18
+
19
+ - Do not add a brand theme as a fourth choice. A brand theme is another setting.
20
+ - Do not name the button for the action, such as 'Dark mode'. Name it for what is on.
21
+ - Do not use a toggle that only flips between light and dark. It hides System.
22
+ - Do not mark the current choice with color only.
23
+ - Do not show both the menu and the segmented control on the same page.
24
+ - Do not save the theme to the person's account with this case. A save that can fail follows the rule 'A setting saves in place, or with one Save Button'.
25
+
26
+ ## Option: Menu in the header
27
+
28
+ Use when: The site has no settings page, or the person should reach the theme from every page.
29
+
30
+ Uses: `Cluster`, `Heading`, `IconButton`, `Link`, `Menu`, `MenuItem`, `PageShell`, `Paragraph`, `Popover`, `Stack`, `Tooltip`
31
+
32
+ ```tsx
33
+ 'use client';
34
+ import { useState } from 'react';
35
+ import IconButton from 'oneslash-design-system/components/iconButton';
36
+ import Tooltip from 'oneslash-design-system/components/tooltip';
37
+ import Popover from 'oneslash-design-system/components/popover';
38
+ import Menu from 'oneslash-design-system/components/menu';
39
+ import MenuItem from 'oneslash-design-system/components/menuItem';
40
+ import PageShell from 'oneslash-design-system/components/pageShell';
41
+ import Heading from 'oneslash-design-system/components/heading';
42
+ import Paragraph from 'oneslash-design-system/components/paragraph';
43
+ import Link from 'oneslash-design-system/components/link';
44
+ import { Cluster, Stack } from 'oneslash-design-system/components/layout';
45
+
46
+ type Mode = 'light' | 'dark' | 'system';
47
+
48
+ const modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [
49
+ { value: 'light', label: 'Light', icon: 'Sun' },
50
+ { value: 'dark', label: 'Dark', icon: 'Moon' },
51
+ { value: 'system', label: 'System', icon: 'Monitor' },
52
+ ];
53
+
54
+ export default function ThemeSwitcherMenu() {
55
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
56
+ const [mode, setMode] = useState<Mode>('system');
57
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
58
+ const [open, setOpen] = useState(false);
59
+ const current = modes.find((m) => m.value === mode) ?? modes[2];
60
+
61
+ return (
62
+ <PageShell>
63
+ <Stack gap="large">
64
+ <Cluster justify="between">
65
+ <Link href="#top" size="subtitle1">Acme</Link>
66
+ <Tooltip title={`Theme: ${current.label}`}>
67
+ <IconButton
68
+ color="iconOnly"
69
+ state={open ? 'selected' : 'enabled'}
70
+ size="medium"
71
+ iconName={current.icon}
72
+ ariaLabel={`Theme: ${current.label}`}
73
+ aria-haspopup="menu"
74
+ aria-expanded={open}
75
+ onClick={(e: { currentTarget: HTMLElement }) => {
76
+ setAnchor(e.currentTarget);
77
+ setOpen((o) => !o);
78
+ }}
79
+ />
80
+ </Tooltip>
81
+ </Cluster>
82
+ <Heading level={1} size="h5">Welcome back, Dana</Heading>
83
+ <Paragraph tone="secondary" measure="none">
84
+ {mode === 'system' ? 'Acme follows your device.' : `Acme is set to ${mode}.`} In a real app the page changes now.
85
+ </Paragraph>
86
+ </Stack>
87
+ <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
88
+ <Menu navigable aria-label="Theme" width={180}>
89
+ {modes.map((m) => (
90
+ <MenuItem
91
+ key={m.value}
92
+ size="small"
93
+ iconName={m.icon}
94
+ label={m.label}
95
+ isSelected={m.value === mode}
96
+ role="menuitemradio"
97
+ onClick={() => { setMode(m.value); setOpen(false); }}
98
+ />
99
+ ))}
100
+ </Menu>
101
+ </Popover>
102
+ </PageShell>
103
+ );
104
+ }
105
+ ```
106
+
107
+ ## Option: Segmented control on a settings page
108
+
109
+ Use when: The choice is a setting among others, on a settings page.
110
+
111
+ Uses: `Center`, `Cluster`, `Heading`, `SegmentedControl`, `SettingsSection`, `Stack`
112
+
113
+ ```tsx
114
+ 'use client';
115
+ import { useState } from 'react';
116
+ import Heading from 'oneslash-design-system/components/heading';
117
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
118
+ import SegmentedControl from 'oneslash-design-system/components/segmentedControl';
119
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
120
+
121
+ const options = [
122
+ { value: 'light', label: 'Light' },
123
+ { value: 'dark', label: 'Dark' },
124
+ { value: 'system', label: 'System' },
125
+ ];
126
+
127
+ export default function ThemeSwitcherSegmented() {
128
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
129
+ const [mode, setMode] = useState('system');
130
+
131
+ return (
132
+ <Center width="page">
133
+ <Stack gap="large">
134
+ <Heading level={1} size="h5">Settings</Heading>
135
+ <SettingsSection title="Appearance" description="System follows your device.">
136
+ {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}
137
+ <Cluster>
138
+ <SegmentedControl size="small" width="fit" aria-label="Theme" options={options} value={mode} onChange={setMode} />
139
+ </Cluster>
140
+ </SettingsSection>
141
+ </Stack>
142
+ </Center>
143
+ );
144
+ }
145
+ ```
146
+
147
+ ## Native
148
+
149
+ On Apple and Android follow the system appearance and offer no switcher. If the app has one, use a `Picker` of Light, Dark and System in settings.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person asks to delete something large that cannot be brought back, such as a workspace or an account.
4
4
 
5
- **Not built yet:** Commentify matches its phrase with any case and ignores spaces around it, and labels its Button 'Deleting…' while it runs. Scindo labels its Button 'Deleting...' on the web and on Apple. On the web its Delete Workspace Modal shows a failed request as a red caption written by hand.
6
-
7
5
  ## Do
8
6
 
9
7
  - Ask for typing only when the loss is permanent and large, such as a workspace with everything in it, or an account.
@@ -218,5 +216,3 @@ export default function TypeToConfirmInline() {
218
216
  ## Native
219
217
 
220
218
  On Apple use an `.alert` with a `TextField` in it. Put the action in the `.destructive` role and disable it until the text matches.
221
-
222
- Seen in: Commentify, Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  Other people in the thread are writing a message that has not arrived yet.
4
4
 
5
- **Not built yet:** Scindo on the web names people by their full name and ends the line with three dots.
6
-
7
5
  ## Do
8
6
 
9
7
  - Show one line just above the Composer, in small secondary text: `<Paragraph size="caption" tone="secondary">`.
@@ -92,5 +90,3 @@ export default function TypingAndStatusLine() {
92
90
  );
93
91
  }
94
92
  ```
95
-
96
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person closes or leaves something they changed and did not save.
4
4
 
5
- **Not built yet:** Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.
6
-
7
5
  ## Do
8
6
 
9
7
  - Ask only when there are changes. With nothing changed, close at once.
@@ -235,5 +233,3 @@ export default function UnsavedChangesDiscard() {
235
233
  ## Native
236
234
 
237
235
  On macOS a document window that closes with changes asks with the system alert: 'Save', 'Don't Save' and 'Cancel'. When the product cannot save, use a `confirmationDialog` with 'Discard' in the `.destructive` role and 'Keep Editing' in the `.cancel` role.
238
-
239
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person reaches something their plan does not include, or a limit of their plan.
4
4
 
5
- **Not built yet:** Scindo's upgrade prompt on the web is an overlay built by hand that does not close on Escape, is titled 'Upgrade Required' and shows Upgrade to everyone. Commentify's upgrade Modal labels its Buttons 'Maybe Later' and 'Upgrade'.
6
-
7
5
  ## Do
8
6
 
9
7
  - Say what is locked and which plan unlocks it: 'Exporting to PDF is part of the Pro plan.'
@@ -170,5 +168,3 @@ export default function UpgradePromptInline() {
170
168
  ## Native
171
169
 
172
170
  On Apple show the notice in place, with an Upgrade Button only for admins. It opens the plan sheet in the app, never a link to a web page.
173
-
174
- Seen in: Commentify, Scindo.