oneslash-design-system 2.17.0 → 2.18.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 (185) hide show
  1. package/README.md +2 -2
  2. package/dist/DESIGN.md +30 -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/artifact-card.md +0 -4
  24. package/dist/cases/auth-gate-loading.md +0 -4
  25. package/dist/cases/check-your-email.md +0 -4
  26. package/dist/cases/collapsible-search/popover.d.ts +1 -0
  27. package/dist/cases/collapsible-search/popover.jsx +74 -0
  28. package/dist/cases/collapsible-search.md +143 -0
  29. package/dist/cases/composer-limit.md +0 -4
  30. package/dist/cases/confirm-destructive-action.md +0 -4
  31. package/dist/cases/confirm-dialogs.md +0 -4
  32. package/dist/cases/conversation-starters.md +0 -4
  33. package/dist/cases/create-modal.md +0 -4
  34. package/dist/cases/danger-zone/collapsed.d.ts +1 -0
  35. package/dist/cases/danger-zone/collapsed.jsx +75 -0
  36. package/dist/cases/danger-zone/shown.d.ts +1 -0
  37. package/dist/cases/danger-zone/shown.jsx +95 -0
  38. package/dist/cases/danger-zone.md +263 -0
  39. package/dist/cases/device-login.md +0 -4
  40. package/dist/cases/email-confirmed.md +0 -4
  41. package/dist/cases/empty-list.md +0 -4
  42. package/dist/cases/empty-lists.md +0 -4
  43. package/dist/cases/empty-not-set-up.md +0 -4
  44. package/dist/cases/empty-search.md +0 -4
  45. package/dist/cases/error-page.md +0 -4
  46. package/dist/cases/feedback-form.md +0 -4
  47. package/dist/cases/filter-menu/presets.d.ts +1 -0
  48. package/dist/cases/filter-menu/presets.jsx +53 -0
  49. package/dist/cases/filter-menu/with-clear.d.ts +1 -0
  50. package/dist/cases/filter-menu/with-clear.jsx +56 -0
  51. package/dist/cases/filter-menu.md +204 -0
  52. package/dist/cases/forgot-password.md +0 -4
  53. package/dist/cases/form-errors.md +0 -4
  54. package/dist/cases/import-checklist.md +0 -4
  55. package/dist/cases/inline-form-feedback.md +0 -4
  56. package/dist/cases/integrations-list/nested.d.ts +1 -0
  57. package/dist/cases/integrations-list/nested.jsx +164 -0
  58. package/dist/cases/integrations-list/rows.d.ts +1 -0
  59. package/dist/cases/integrations-list/rows.jsx +134 -0
  60. package/dist/cases/integrations-list.md +379 -0
  61. package/dist/cases/invite-member.md +0 -4
  62. package/dist/cases/load-failure.md +0 -4
  63. package/dist/cases/log-out-confirm.md +0 -4
  64. package/dist/cases/login-page.md +0 -4
  65. package/dist/cases/members-list/rows.d.ts +1 -0
  66. package/dist/cases/members-list/rows.jsx +318 -0
  67. package/dist/cases/members-list/table.d.ts +1 -0
  68. package/dist/cases/members-list/table.jsx +351 -0
  69. package/dist/cases/members-list.md +799 -0
  70. package/dist/cases/mention-list.md +0 -4
  71. package/dist/cases/message-actions.md +0 -4
  72. package/dist/cases/message-attachments.md +0 -4
  73. package/dist/cases/message-composer.md +0 -4
  74. package/dist/cases/message-edit.md +0 -4
  75. package/dist/cases/message-reactions.md +0 -4
  76. package/dist/cases/message-row.md +0 -4
  77. package/dist/cases/not-found-page.md +0 -4
  78. package/dist/cases/notification-menu/menu.d.ts +1 -0
  79. package/dist/cases/notification-menu/menu.jsx +74 -0
  80. package/dist/cases/notification-menu.md +135 -0
  81. package/dist/cases/oauth-consent.md +0 -4
  82. package/dist/cases/on-off-settings/list.d.ts +1 -0
  83. package/dist/cases/on-off-settings/list.jsx +97 -0
  84. package/dist/cases/on-off-settings.md +116 -0
  85. package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
  86. package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
  87. package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
  88. package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
  89. package/dist/cases/overflow-menu.md +410 -0
  90. package/dist/cases/profile-form/form.d.ts +1 -0
  91. package/dist/cases/profile-form/form.jsx +153 -0
  92. package/dist/cases/profile-form.md +236 -0
  93. package/dist/cases/quick-switcher/modal.d.ts +1 -0
  94. package/dist/cases/quick-switcher/modal.jsx +114 -0
  95. package/dist/cases/quick-switcher.md +205 -0
  96. package/dist/cases/range-switch/segmented.d.ts +1 -0
  97. package/dist/cases/range-switch/segmented.jsx +30 -0
  98. package/dist/cases/range-switch.md +67 -0
  99. package/dist/cases/rename.md +0 -4
  100. package/dist/cases/reply-feedback.md +0 -4
  101. package/dist/cases/reply-sources.md +0 -4
  102. package/dist/cases/route-loading.md +0 -2
  103. package/dist/cases/scope-picker/menu.d.ts +1 -0
  104. package/dist/cases/scope-picker/menu.jsx +47 -0
  105. package/dist/cases/scope-picker.md +97 -0
  106. package/dist/cases/set-new-password.md +0 -4
  107. package/dist/cases/settings-page/side-nav.d.ts +1 -0
  108. package/dist/cases/settings-page/side-nav.jsx +171 -0
  109. package/dist/cases/settings-page/top-tabs.d.ts +1 -0
  110. package/dist/cases/settings-page/top-tabs.jsx +129 -0
  111. package/dist/cases/settings-page.md +378 -0
  112. package/dist/cases/settings-save.md +35 -0
  113. package/dist/cases/sign-up-page.md +1 -5
  114. package/dist/cases/slash-command-list.md +0 -4
  115. package/dist/cases/success-feedback.md +0 -4
  116. package/dist/cases/tag-filter/tags.d.ts +1 -0
  117. package/dist/cases/tag-filter/tags.jsx +226 -0
  118. package/dist/cases/tag-filter.md +298 -0
  119. package/dist/cases/type-to-confirm.md +0 -4
  120. package/dist/cases/typing-and-status.md +0 -4
  121. package/dist/cases/unsaved-changes-guard.md +0 -4
  122. package/dist/cases/upgrade-prompt.md +0 -4
  123. package/dist/cases.json +1038 -263
  124. package/dist/components/alert.d.ts +3 -1
  125. package/dist/components/alert.jsx +2 -2
  126. package/dist/components/button.jsx +5 -2
  127. package/dist/components/checkBox.d.ts +5 -1
  128. package/dist/components/checkBox.jsx +2 -2
  129. package/dist/components/copyField.d.ts +20 -0
  130. package/dist/components/copyField.jsx +99 -0
  131. package/dist/components/formField.d.ts +34 -0
  132. package/dist/components/formField.jsx +28 -0
  133. package/dist/components/heading.d.ts +3 -1
  134. package/dist/components/heading.jsx +2 -2
  135. package/dist/components/menu.jsx +2 -2
  136. package/dist/components/menuItem.d.ts +4 -2
  137. package/dist/components/menuItem.jsx +3 -3
  138. package/dist/components/navigation.d.ts +9 -1
  139. package/dist/components/navigation.jsx +15 -3
  140. package/dist/components/radioGroup.d.ts +5 -1
  141. package/dist/components/radioGroup.jsx +2 -2
  142. package/dist/components/segmentedControl.d.ts +22 -0
  143. package/dist/components/segmentedControl.jsx +54 -0
  144. package/dist/components/select.d.ts +5 -1
  145. package/dist/components/select.jsx +2 -2
  146. package/dist/components/settingsSection.d.ts +31 -0
  147. package/dist/components/settingsSection.jsx +58 -0
  148. package/dist/components/slidingIndicator.d.ts +50 -0
  149. package/dist/components/slidingIndicator.jsx +102 -0
  150. package/dist/components/switch.d.ts +25 -0
  151. package/dist/components/switch.jsx +55 -0
  152. package/dist/components/tab.jsx +5 -11
  153. package/dist/components/tabsContainer.jsx +5 -67
  154. package/dist/components/textField.d.ts +12 -2
  155. package/dist/components/textField.jsx +11 -4
  156. package/dist/components/textarea.d.ts +5 -1
  157. package/dist/components/textarea.jsx +3 -3
  158. package/dist/components/useHotkey.d.ts +7 -0
  159. package/dist/components/useHotkey.js +24 -0
  160. package/dist/index.d.ts +6 -0
  161. package/dist/index.js +6 -0
  162. package/dist/internal/copyField.d.ts +5 -0
  163. package/dist/internal/copyField.js +61 -0
  164. package/dist/internal/hotkey.d.ts +16 -0
  165. package/dist/internal/hotkey.js +20 -0
  166. package/dist/internal/switch.d.ts +5 -0
  167. package/dist/internal/switch.js +9 -0
  168. package/dist/native-mapping.json +30 -0
  169. package/dist/stories/Cases.generated.stories.d.ts +23 -0
  170. package/dist/stories/Cases.generated.stories.jsx +46 -0
  171. package/dist/stories/CopyField.stories.d.ts +11 -0
  172. package/dist/stories/CopyField.stories.jsx +65 -0
  173. package/dist/stories/FormField.stories.d.ts +6 -0
  174. package/dist/stories/FormField.stories.jsx +44 -0
  175. package/dist/stories/Navigation.stories.d.ts +1 -0
  176. package/dist/stories/Navigation.stories.jsx +17 -1
  177. package/dist/stories/SegmentedControl.stories.d.ts +8 -0
  178. package/dist/stories/SegmentedControl.stories.jsx +33 -0
  179. package/dist/stories/SettingsSection.stories.d.ts +11 -0
  180. package/dist/stories/SettingsSection.stories.jsx +64 -0
  181. package/dist/stories/Switch.stories.d.ts +14 -0
  182. package/dist/stories/Switch.stories.jsx +87 -0
  183. package/dist/stories/TextField.stories.d.ts +1 -0
  184. package/dist/stories/TextField.stories.jsx +13 -0
  185. package/package.json +5 -1
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person types @ in the message box to name someone, or the agent.
4
4
 
5
- **Not built yet:** Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which name is highlighted. It shows no 'Agent' tag on the agent's row.
6
-
7
5
  ## Do
8
6
 
9
7
  - Open the list when the person types @ at the start of the text or after a space. A bare @ opens it, and each letter after it narrows it.
@@ -248,5 +246,3 @@ export default function MentionListInComposer() {
248
246
  ## Native
249
247
 
250
248
  On Apple the list shows above the field, the agent with a sparkles icon and people with a person icon. A name is picked with a click or a tap.
251
-
252
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person acts on one message: reacts to it, copies it, edits or deletes it.
4
4
 
5
- **Not built yet:** Scindo on the web deletes a message with no confirm and has no Copy. Its row actions show only while the pointer is on the row, so a keyboard or a phone cannot reach them.
6
-
7
5
  ## Do
8
6
 
9
7
  - Put the actions in the Message's `actions`. They show while the pointer is on the row or focus is in it.
@@ -647,5 +645,3 @@ export default function MessageActionsMenu() {
647
645
  ## Native
648
646
 
649
647
  On Apple put the actions in the row's `contextMenu`: Copy, Edit, Add Reaction, Create Task and Report, with Delete last in the `.destructive` role. Delete asks in a system `confirmationDialog`, not in the row.
650
-
651
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person adds files to a message, and people open the files in a message that was sent.
4
4
 
5
- **Not built yet:** No product shows upload progress or a failed upload on the file itself. Scindo on the web shows a rejected file in an error Alert above the field, and its images use the file name as `alt` text.
6
-
7
5
  ## Do
8
6
 
9
7
  - Show each waiting file as a `FileChip` in the Composer's `above` slot, with `onRemove`.
@@ -306,5 +304,3 @@ export default function MessageAttachmentsInMessage() {
306
304
  ## Native
307
305
 
308
306
  On Apple the attach button opens a menu with Photo Library and Files on iPhone, and opens Files on a Mac. Waiting files show as chips with a remove button. Sent images open full screen.
309
-
310
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person writes a message at the bottom of a thread.
4
4
 
5
- **Not built yet:** Scindo's Apple app shows only 'Message' as its placeholder when the agent is not called, so it does not say who will read the message.
6
-
7
5
  ## Do
8
6
 
9
7
  - Use `Composer` under the thread, with an `aria-label`, since it has no visible label.
@@ -352,5 +350,3 @@ export default function MessageComposerWithTools() {
352
350
  ## Native
353
351
 
354
352
  On Apple use a `TextField` with `axis: .vertical`. On a Mac, Return sends and Shift-Return adds a line. On an iPhone, Return adds a line. While the agent works, Send becomes Stop.
355
-
356
- Seen in: Commentify, Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person changes the text of a message they sent.
4
4
 
5
- **Not built yet:** Scindo on the web saves and cancels with two icon buttons, a check and a cross, under the field. Scindo's Apple app shows 'Saving...' on its Save button while it saves.
6
-
7
5
  ## Do
8
6
 
9
7
  - Replace the row's body with a `Composer` that holds the text, and focus it with the caret after the text.
@@ -175,5 +173,3 @@ export default function MessageEditInPlace() {
175
173
  ## Native
176
174
 
177
175
  On Apple the text becomes a field in the row, with 'Cancel' and 'Save', and the row shows '(edited)' after.
178
-
179
- Seen in: Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  People answer a message with an emoji instead of a reply.
4
4
 
5
- **Not built yet:** Commentify's reaction chips do not show which are the person's, and cannot be pressed. Commentify adds a reaction from a full emoji picker.
6
-
7
5
  ## Do
8
6
 
9
7
  - Put the reactions in the Message's `footer`: a `Cluster` of `Tag`s, then a small 'Add reaction' `IconButton`.
@@ -367,5 +365,3 @@ export default function MessageReactionsQuickPick() {
367
365
  ## Native
368
366
 
369
367
  On Apple a reaction is added from the row's `contextMenu`, with Add Reaction.
370
-
371
- Seen in: Commentify, Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A thread shows messages from people, and sometimes from an agent.
4
4
 
5
- **Not built yet:** Scindo on the web shows no 'Agent' tag on an agent's row, and its message list is not a log for screen readers. Scindo's Apple app shows no model name and does not group messages.
6
-
7
5
  ## Do
8
6
 
9
7
  - Show each row with `Message`: the sender's `UserImage`, their name and the time. A person's avatar is their picture or their initial.
@@ -185,5 +183,3 @@ export default function MessageRowGrouped() {
185
183
  ## Native
186
184
 
187
185
  On Apple a row shows the avatar, the name and the time, with an 'Agent' label next to an agent's name.
188
-
189
- Seen in: Commentify, Scindo.
@@ -2,8 +2,6 @@
2
2
 
3
3
  A person opens a link to a page that does not exist.
4
4
 
5
- **Not built yet:** Commentify's page not found is one line of bare text, 'Page not found.', with no way home. Scindo on the web shows '404' as its heading, then bare text and a text link home. jinhwankim.com has no heading: it puts '404:' at the start of its `EmptyBox` text and labels its Button 'Go to Home'.
6
-
7
5
  ## Do
8
6
 
9
7
  - Say 'Page not found' in a `Heading` with `level={1}`.
@@ -94,5 +92,3 @@ export default function NotFoundPageInShell() {
94
92
  );
95
93
  }
96
94
  ```
97
-
98
- Seen in: Commentify, Scindo, jinhwankim.com.
@@ -0,0 +1 @@
1
+ export default function NotificationMenuExample(): import("react").JSX.Element;
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Toaster, { toast, dismissToast } from '../../components/toaster';
4
+ import Heading from '../../components/heading';
5
+ import Paragraph from '../../components/paragraph';
6
+ import IconButton from '../../components/iconButton';
7
+ import Tooltip from '../../components/tooltip';
8
+ import Popover from '../../components/popover';
9
+ import Menu from '../../components/menu';
10
+ import MenuItem from '../../components/menuItem';
11
+ import { Center, Cluster, Stack } from '../../components/layout';
12
+ var choices = [
13
+ { value: 'all', label: 'All Messages', line: 'Every message in this channel.', current: 'All messages' },
14
+ { value: 'mentions', label: 'Mentions Only', line: 'Only when someone mentions you.', current: 'Mentions only' },
15
+ { value: 'none', label: 'Muted', line: 'No notifications from this channel.', current: 'Muted' },
16
+ ];
17
+ export default function NotificationMenuExample() {
18
+ var _a;
19
+ var _b = useState('all'), pref = _b[0], setPref = _b[1];
20
+ var _c = useState(false), saving = _c[0], setSaving = _c[1];
21
+ var _d = useState(null), anchor = _d[0], setAnchor = _d[1];
22
+ var _e = useState(false), open = _e[0], setOpen = _e[1];
23
+ var timer = useRef();
24
+ var toastIds = useRef([]);
25
+ var current = (_a = choices.find(function (c) { return c.value === pref; })) !== null && _a !== void 0 ? _a : choices[0];
26
+ // On unmount it stops the request and closes the toast it opened.
27
+ useEffect(function () { return function () {
28
+ clearTimeout(timer.current);
29
+ toastIds.current.forEach(function (id) { return dismissToast(id); });
30
+ toastIds.current = [];
31
+ }; }, []);
32
+ function toggle(anchorEl) {
33
+ if (saving)
34
+ return;
35
+ setAnchor(anchorEl);
36
+ setOpen(function (o) { return !o; });
37
+ }
38
+ // Saves at once and shows nothing when it works: the bell already shows the new value.
39
+ // The menu is gone by now, so a failure says so in a toast, and the bell goes back.
40
+ function choose(next) {
41
+ var previous = pref;
42
+ setOpen(false);
43
+ if (next === previous)
44
+ return;
45
+ setPref(next);
46
+ setSaving(true);
47
+ // Stands in for the request to the server. 'Muted' never saves, as if the connection were down.
48
+ timer.current = setTimeout(function () {
49
+ setSaving(false);
50
+ if (next === 'none') {
51
+ setPref(previous);
52
+ toastIds.current.push(toast({ type: 'error', message: 'Could not save your notification setting. Try again.' }));
53
+ }
54
+ }, 900);
55
+ }
56
+ return (<Center width="page">
57
+ {/* A real app mounts one Toaster near its root. */}
58
+ <Toaster />
59
+ <Stack gap="large">
60
+ <Cluster justify="between">
61
+ <Heading level={1} size="h5">Design team</Heading>
62
+ <Tooltip title={current.current}>
63
+ <IconButton color={pref === 'none' ? 'secondary' : 'iconOnly'} state={open ? 'selected' : 'enabled'} size="small" iconName={pref === 'none' ? 'BellOff' : 'Bell'} ariaLabel={"Notifications: ".concat(current.current)} aria-haspopup="menu" aria-expanded={open} aria-busy={saving} onClick={function (e) { return toggle(e.currentTarget); }}/>
64
+ </Tooltip>
65
+ </Cluster>
66
+ <Paragraph tone="secondary" size="body2" measure="none">Ben Carter: The press kit is in the shared folder.</Paragraph>
67
+ </Stack>
68
+ <Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
69
+ <Menu navigable aria-label="Notifications" width={260}>
70
+ {choices.map(function (c) { return (<MenuItem key={c.value} size="small" label={c.label} secondLabel={c.line} isSelected={c.value === pref} role="menuitemradio" onClick={function () { return choose(c.value); }}/>); })}
71
+ </Menu>
72
+ </Popover>
73
+ </Center>);
74
+ }
@@ -0,0 +1,135 @@
1
+ # Notification setting
2
+
3
+ A person chooses how much a channel or a thread notifies them.
4
+
5
+ ## Do
6
+
7
+ - Use an `IconButton` with `iconName="Bell"`, and `BellOff` when the channel is muted.
8
+ - Say the current value in the button's `ariaLabel`: 'Notifications: All messages'. Show it in a `Tooltip` too.
9
+ - Open a navigable menu of three choices: `<Popover returnFocus>` around `<Menu navigable aria-label="Notifications">`.
10
+ - Give each choice a `secondLabel` of one line: 'All Messages', then 'Every message in this channel.'
11
+ - Give each item `role="menuitemradio"` and mark the current choice with `isSelected`, which sets `aria-checked`.
12
+ - Save as soon as a choice is made, as the rule 'A setting saves in place, or with one Save Button' says. Close the menu and show nothing when it works.
13
+ - Set `aria-busy` on the bell while the request runs.
14
+ - Put the bell back to its old value when the save fails, and show an error toast: 'Could not save your notification setting. Try again.' This is the exception in the rule 'A setting saves in place, or with one Save Button': a setting chosen from a menu shows a failed save in a toast, because the menu closes.
15
+ - Dismiss the toast when the example goes away.
16
+
17
+ ## Don't
18
+
19
+ - Do not add a Save Button to the menu.
20
+ - Do not show a toast when the save works.
21
+ - Do not leave the bell on the new value when the save failed.
22
+ - Do not show a failure inside the menu. It has already closed.
23
+ - Do not use only the icon to say muted. The button's name says it too.
24
+
25
+ ## Example: Bell with a menu
26
+
27
+ Uses: `Center`, `Cluster`, `Heading`, `IconButton`, `Menu`, `MenuItem`, `Paragraph`, `Popover`, `Stack`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
28
+
29
+ ```tsx
30
+ 'use client';
31
+ import { useEffect, useRef, useState } from 'react';
32
+ import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
33
+ import Heading from 'oneslash-design-system/components/heading';
34
+ import Paragraph from 'oneslash-design-system/components/paragraph';
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 { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
41
+
42
+ type Pref = 'all' | 'mentions' | 'none';
43
+
44
+ const choices: { value: Pref; label: string; line: string; current: string }[] = [
45
+ { value: 'all', label: 'All Messages', line: 'Every message in this channel.', current: 'All messages' },
46
+ { value: 'mentions', label: 'Mentions Only', line: 'Only when someone mentions you.', current: 'Mentions only' },
47
+ { value: 'none', label: 'Muted', line: 'No notifications from this channel.', current: 'Muted' },
48
+ ];
49
+
50
+ export default function NotificationMenuExample() {
51
+ const [pref, setPref] = useState<Pref>('all');
52
+ const [saving, setSaving] = useState(false);
53
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
54
+ const [open, setOpen] = useState(false);
55
+ const timer = useRef<ReturnType<typeof setTimeout>>();
56
+ const toastIds = useRef<string[]>([]);
57
+ const current = choices.find((c) => c.value === pref) ?? choices[0];
58
+
59
+ // On unmount it stops the request and closes the toast it opened.
60
+ useEffect(() => () => {
61
+ clearTimeout(timer.current);
62
+ toastIds.current.forEach((id) => dismissToast(id));
63
+ toastIds.current = [];
64
+ }, []);
65
+
66
+ function toggle(anchorEl: HTMLElement) {
67
+ if (saving) return;
68
+ setAnchor(anchorEl);
69
+ setOpen((o) => !o);
70
+ }
71
+
72
+ // Saves at once and shows nothing when it works: the bell already shows the new value.
73
+ // The menu is gone by now, so a failure says so in a toast, and the bell goes back.
74
+ function choose(next: Pref) {
75
+ const previous = pref;
76
+ setOpen(false);
77
+ if (next === previous) return;
78
+ setPref(next);
79
+ setSaving(true);
80
+ // Stands in for the request to the server. 'Muted' never saves, as if the connection were down.
81
+ timer.current = setTimeout(() => {
82
+ setSaving(false);
83
+ if (next === 'none') {
84
+ setPref(previous);
85
+ toastIds.current.push(toast({ type: 'error', message: 'Could not save your notification setting. Try again.' }));
86
+ }
87
+ }, 900);
88
+ }
89
+
90
+ return (
91
+ <Center width="page">
92
+ {/* A real app mounts one Toaster near its root. */}
93
+ <Toaster />
94
+ <Stack gap="large">
95
+ <Cluster justify="between">
96
+ <Heading level={1} size="h5">Design team</Heading>
97
+ <Tooltip title={current.current}>
98
+ <IconButton
99
+ color={pref === 'none' ? 'secondary' : 'iconOnly'}
100
+ state={open ? 'selected' : 'enabled'}
101
+ size="small"
102
+ iconName={pref === 'none' ? 'BellOff' : 'Bell'}
103
+ ariaLabel={`Notifications: ${current.current}`}
104
+ aria-haspopup="menu"
105
+ aria-expanded={open}
106
+ aria-busy={saving}
107
+ onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}
108
+ />
109
+ </Tooltip>
110
+ </Cluster>
111
+ <Paragraph tone="secondary" size="body2" measure="none">Ben Carter: The press kit is in the shared folder.</Paragraph>
112
+ </Stack>
113
+ <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
114
+ <Menu navigable aria-label="Notifications" width={260}>
115
+ {choices.map((c) => (
116
+ <MenuItem
117
+ key={c.value}
118
+ size="small"
119
+ label={c.label}
120
+ secondLabel={c.line}
121
+ isSelected={c.value === pref}
122
+ role="menuitemradio"
123
+ onClick={() => choose(c.value)}
124
+ />
125
+ ))}
126
+ </Menu>
127
+ </Popover>
128
+ </Center>
129
+ );
130
+ }
131
+ ```
132
+
133
+ ## Native
134
+
135
+ On Apple use a toolbar `Menu` with a `Picker` inside it, with the bell symbol changing to `bell.slash`. On Android use a dropdown menu with radio items.
@@ -2,8 +2,6 @@
2
2
 
3
3
  Another app, such as a CLI or an MCP client, asks to act for a person who is logged in, and the person must allow it.
4
4
 
5
- **Not built yet:** Scindo on the web turns on access to every workspace for the person, and shows its spinner on neither Button while the request runs. Commentify puts 'Allow' before 'Deny', writes its error in a red caption by hand, and says nothing about how to remove the access.
6
-
7
5
  ## Do
8
6
 
9
7
  - Name the app in a `Heading` with `level={1}`: 'Acme CLI wants to connect to Acme'.
@@ -229,5 +227,3 @@ export default function OAuthConsentWithScope() {
229
227
  );
230
228
  }
231
229
  ```
232
-
233
- Seen in: Commentify, Scindo.
@@ -0,0 +1 @@
1
+ export default function OnOffSettingsList(): import("react").JSX.Element;
@@ -0,0 +1,97 @@
1
+ 'use client';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ import { useEffect, useRef, useState } from 'react';
23
+ import Heading from '../../components/heading';
24
+ import Paragraph from '../../components/paragraph';
25
+ import Switch from '../../components/switch';
26
+ import SettingsSection from '../../components/settingsSection';
27
+ import { Center, Stack } from '../../components/layout';
28
+ var failedMessage = 'Could not save. Try again.';
29
+ var emailSettings = [
30
+ { id: 'mentions', label: 'Mentions', description: 'An email when someone mentions you.', on: true },
31
+ { id: 'replies', label: 'Replies', description: 'An email when someone replies to your message.', on: true },
32
+ { id: 'digest', label: 'Weekly digest', description: 'A summary of last week, every Monday.', on: false },
33
+ ];
34
+ // Stands in for a connection that is down: this one never saves.
35
+ var appSettings = [
36
+ { id: 'slack', label: 'Slack digest', description: 'Post the weekly digest in #general.', on: false, fails: true },
37
+ { id: 'push', label: 'Push on your phone', description: 'Mentions and replies, while the app is closed.', on: true },
38
+ ];
39
+ var everySetting = __spreadArray(__spreadArray([], emailSettings, true), appSettings, true);
40
+ export default function OnOffSettingsList() {
41
+ var _a = useState(function () { return Object.fromEntries(everySetting.map(function (s) { return [s.id, s.on]; })); }), values = _a[0], setValues = _a[1];
42
+ var _b = useState({}), busy = _b[0], setBusy = _b[1];
43
+ // Opens on a failed save, as if the person just turned Slack digest on.
44
+ var _c = useState({ slack: failedMessage }), errors = _c[0], setErrors = _c[1];
45
+ var timers = useRef({});
46
+ // Stops every request if the example goes away before they end.
47
+ useEffect(function () { return function () { return Object.values(timers.current).forEach(clearTimeout); }; }, []);
48
+ // Saves as soon as it changes. Nothing shows when it works. When it fails, the switch goes back and says why.
49
+ function handleChange(setting, next) {
50
+ setErrors(function (current) {
51
+ var _a;
52
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = '', _a)));
53
+ });
54
+ setBusy(function (current) {
55
+ var _a;
56
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = true, _a)));
57
+ });
58
+ setValues(function (current) {
59
+ var _a;
60
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = next, _a)));
61
+ });
62
+ // Stands in for the request to the server.
63
+ timers.current[setting.id] = setTimeout(function () {
64
+ setBusy(function (current) {
65
+ var _a;
66
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = false, _a)));
67
+ });
68
+ if (setting.fails) {
69
+ setValues(function (current) {
70
+ var _a;
71
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = !next, _a)));
72
+ });
73
+ setErrors(function (current) {
74
+ var _a;
75
+ return (__assign(__assign({}, current), (_a = {}, _a[setting.id] = failedMessage, _a)));
76
+ });
77
+ }
78
+ }, 900);
79
+ }
80
+ function renderSwitch(setting) {
81
+ return (<Switch key={setting.id} id={"on-off-settings-".concat(setting.id)} label={setting.label} description={setting.description} checked={values[setting.id]} busy={Boolean(busy[setting.id])} error={errors[setting.id] || undefined} onChange={function (next) { return handleChange(setting, next); }}/>);
82
+ }
83
+ return (<Center width="page">
84
+ <Stack gap="xlarge">
85
+ <Stack gap="small">
86
+ <Heading level={1} size="h5">Notifications</Heading>
87
+ <Paragraph tone="secondary" size="body2" measure="none">Each switch saves as soon as you change it.</Paragraph>
88
+ </Stack>
89
+ <SettingsSection title="Email" description="Sent to dana@acme.example.">
90
+ {emailSettings.map(renderSwitch)}
91
+ </SettingsSection>
92
+ <SettingsSection title="Apps" description="Where else Acme tells you.">
93
+ {appSettings.map(renderSwitch)}
94
+ </SettingsSection>
95
+ </Stack>
96
+ </Center>);
97
+ }
@@ -0,0 +1,116 @@
1
+ # On and off settings
2
+
3
+ A person turns things on and off, such as which notifications they get.
4
+
5
+ ## Do
6
+
7
+ - Follow the rule 'A setting saves in place, or with one Save Button'. Every `Switch` saves as soon as it changes, and the page has no Save Button.
8
+ - Give each `Switch` a visible `label` and a `description` that says what happens when it is on.
9
+ - Group the switches in `SettingsSection`s with a title and one line under it.
10
+ - Set `busy` on the switch while its request runs. It keeps its position and ignores presses. Show nothing when the save works.
11
+ - Put the switch back to its old value when the save fails, and set `error` to a short line: 'Could not save. Try again.'
12
+ - Clear the `error` when the person presses the switch again.
13
+ - Use a `Checkbox` for an on/off choice only inside a form that has a Save Button, such as a consent line above a Submit Button.
14
+ - Give each switch a unique `id`.
15
+
16
+ ## Don't
17
+
18
+ - Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`.
19
+ - Do not add a Save Button to a list of switches.
20
+ - Do not show a toast when a switch saves.
21
+ - Do not leave a switch in its new position when the save failed.
22
+ - Do not put 'On' or 'Off' in the label. The switch shows it.
23
+
24
+ ## Example: A list of switches
25
+
26
+ Uses: `Center`, `Heading`, `Paragraph`, `SettingsSection`, `Stack`, `Switch`
27
+
28
+ ```tsx
29
+ 'use client';
30
+ import { useEffect, useRef, useState } from 'react';
31
+ import Heading from 'oneslash-design-system/components/heading';
32
+ import Paragraph from 'oneslash-design-system/components/paragraph';
33
+ import Switch from 'oneslash-design-system/components/switch';
34
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
35
+ import { Center, Stack } from 'oneslash-design-system/components/layout';
36
+
37
+ type Setting = { id: string; label: string; description: string; on: boolean; fails?: boolean };
38
+
39
+ const failedMessage = 'Could not save. Try again.';
40
+
41
+ const emailSettings: Setting[] = [
42
+ { id: 'mentions', label: 'Mentions', description: 'An email when someone mentions you.', on: true },
43
+ { id: 'replies', label: 'Replies', description: 'An email when someone replies to your message.', on: true },
44
+ { id: 'digest', label: 'Weekly digest', description: 'A summary of last week, every Monday.', on: false },
45
+ ];
46
+
47
+ // Stands in for a connection that is down: this one never saves.
48
+ const appSettings: Setting[] = [
49
+ { id: 'slack', label: 'Slack digest', description: 'Post the weekly digest in #general.', on: false, fails: true },
50
+ { id: 'push', label: 'Push on your phone', description: 'Mentions and replies, while the app is closed.', on: true },
51
+ ];
52
+
53
+ const everySetting = [...emailSettings, ...appSettings];
54
+
55
+ export default function OnOffSettingsList() {
56
+ const [values, setValues] = useState<Record<string, boolean>>(() => Object.fromEntries(everySetting.map((s) => [s.id, s.on])));
57
+ const [busy, setBusy] = useState<Record<string, boolean>>({});
58
+ // Opens on a failed save, as if the person just turned Slack digest on.
59
+ const [errors, setErrors] = useState<Record<string, string>>({ slack: failedMessage });
60
+ const timers = useRef<Record<string, ReturnType<typeof setTimeout>>>({});
61
+
62
+ // Stops every request if the example goes away before they end.
63
+ useEffect(() => () => Object.values(timers.current).forEach(clearTimeout), []);
64
+
65
+ // Saves as soon as it changes. Nothing shows when it works. When it fails, the switch goes back and says why.
66
+ function handleChange(setting: Setting, next: boolean) {
67
+ setErrors((current) => ({ ...current, [setting.id]: '' }));
68
+ setBusy((current) => ({ ...current, [setting.id]: true }));
69
+ setValues((current) => ({ ...current, [setting.id]: next }));
70
+ // Stands in for the request to the server.
71
+ timers.current[setting.id] = setTimeout(() => {
72
+ setBusy((current) => ({ ...current, [setting.id]: false }));
73
+ if (setting.fails) {
74
+ setValues((current) => ({ ...current, [setting.id]: !next }));
75
+ setErrors((current) => ({ ...current, [setting.id]: failedMessage }));
76
+ }
77
+ }, 900);
78
+ }
79
+
80
+ function renderSwitch(setting: Setting) {
81
+ return (
82
+ <Switch
83
+ key={setting.id}
84
+ id={`on-off-settings-${setting.id}`}
85
+ label={setting.label}
86
+ description={setting.description}
87
+ checked={values[setting.id]}
88
+ busy={Boolean(busy[setting.id])}
89
+ error={errors[setting.id] || undefined}
90
+ onChange={(next) => handleChange(setting, next)}
91
+ />
92
+ );
93
+ }
94
+
95
+ return (
96
+ <Center width="page">
97
+ <Stack gap="xlarge">
98
+ <Stack gap="small">
99
+ <Heading level={1} size="h5">Notifications</Heading>
100
+ <Paragraph tone="secondary" size="body2" measure="none">Each switch saves as soon as you change it.</Paragraph>
101
+ </Stack>
102
+ <SettingsSection title="Email" description="Sent to dana@acme.example.">
103
+ {emailSettings.map(renderSwitch)}
104
+ </SettingsSection>
105
+ <SettingsSection title="Apps" description="Where else Acme tells you.">
106
+ {appSettings.map(renderSwitch)}
107
+ </SettingsSection>
108
+ </Stack>
109
+ </Center>
110
+ );
111
+ }
112
+ ```
113
+
114
+ ## Native
115
+
116
+ On Apple use a `Toggle` in a grouped `Form`, and on Android a `Switch`. Both save as they change.
@@ -0,0 +1 @@
1
+ export default function OverflowMenuInAHeader(): import("react").JSX.Element;