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
@@ -0,0 +1,410 @@
1
+ # More menu
2
+
3
+ A person opens a menu of less common actions, behind one button, for a thing or for the page.
4
+
5
+ ## Do
6
+
7
+ - Use an `IconButton` with `iconName="Ellipsis"` and a `Tooltip` of 'More'.
8
+ - Name the thing in the button's `ariaLabel`, in sentence case: 'More actions for Q3 report'. In a list, each row names its own item.
9
+ - Open `<Popover returnFocus>` around `<Menu navigable aria-label="Actions for Q3 report">` with `onClick` items, from the button the person pressed: pass `event.currentTarget` as `anchorEl`.
10
+ - Set `aria-haspopup="menu"` and `aria-expanded` on the button, and `state="selected"` while the menu is open.
11
+ - Order the items by how often they are used. Put a destructive item last, after a `Line`, as a `MenuItem` with `color="danger"`.
12
+ - Show a toast when an item has no other sign, such as 'Link copied.', since the menu is gone.
13
+ - Show no toast for Duplicate on a row: the copy shows under it. Move focus to the copy's More button.
14
+ - Confirm a delete on a row in the row, as the case 'Delete confirm' says: 'Cancel' and a danger 'Delete' take the place of the button, and focus goes to 'Cancel'.
15
+ - Move focus after a row is deleted to the next row's More button, or the one before it when it was the last.
16
+ - Confirm a delete from a header in a small Modal: 'Delete Report', 'Cancel' first, then a danger 'Delete'. 'Cancel' puts focus back on the More button.
17
+ - Go back to the list the thing was in after a delete from a header, and show a toast that names it.
18
+ - Show an error toast when Copy Link fails, because the clipboard is missing or refuses: 'Copying is blocked here. Select the link and copy it:' and the link. It stays until the person closes it.
19
+ - Check that the example is still mounted before the clipboard promise starts a toast, for success and failure.
20
+
21
+ ## Don't
22
+
23
+ - Do not name the button only 'More'. Say what it acts on.
24
+ - Do not put a frequent action only in the menu. A person needs it in one press.
25
+ - Do not put a destructive item first, or color it by hand. It is last, with `color="danger"`.
26
+ - Do not delete on the first click.
27
+ - Do not open a Modal to confirm a delete on a row in a dense list. The row keeps the place.
28
+
29
+ ## Option: More button on a row
30
+
31
+ Use when: The actions are for one item in a list, and each row has its own button.
32
+
33
+ Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `IconButton`, `Line`, `Menu`, `MenuItem`, `Paragraph`, `Popover`, `Stack`, `TableCell`, `TableContainer`, `TableRow`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
34
+
35
+ ```tsx
36
+ 'use client';
37
+ import { useEffect, useRef, useState } from 'react';
38
+ import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
39
+ import Heading from 'oneslash-design-system/components/heading';
40
+ import Paragraph from 'oneslash-design-system/components/paragraph';
41
+ import Button from 'oneslash-design-system/components/button';
42
+ import IconButton from 'oneslash-design-system/components/iconButton';
43
+ import Tooltip from 'oneslash-design-system/components/tooltip';
44
+ import Popover from 'oneslash-design-system/components/popover';
45
+ import Menu from 'oneslash-design-system/components/menu';
46
+ import MenuItem from 'oneslash-design-system/components/menuItem';
47
+ import Line from 'oneslash-design-system/components/line';
48
+ import EmptyBox from 'oneslash-design-system/components/emptyBox';
49
+ import TableContainer from 'oneslash-design-system/components/tableContainer';
50
+ import TableRow from 'oneslash-design-system/components/tableRow';
51
+ import TableCell from 'oneslash-design-system/components/tableCell';
52
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
53
+
54
+ type Report = { id: string; name: string; updated: string };
55
+ type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
56
+
57
+ // A real app reads these from the server.
58
+ const firstReports: Report[] = [
59
+ { id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },
60
+ { id: 'budget', name: 'Budget review', updated: 'Updated last week' },
61
+ { id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },
62
+ { id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },
63
+ ];
64
+
65
+ export default function OverflowMenuOnARow() {
66
+ const [reports, setReports] = useState(firstReports);
67
+ // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.
68
+ const [menuRow, setMenuRow] = useState<Report | null>(null);
69
+ const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
70
+ const [menuOpen, setMenuOpen] = useState(false);
71
+ // The row that asks to confirm the delete. One row at a time.
72
+ const [confirmingId, setConfirmingId] = useState<string | null>(null);
73
+ const [deleting, setDeleting] = useState(false);
74
+ const timer = useRef<ReturnType<typeof setTimeout>>();
75
+ const toastIds = useRef<string[]>([]);
76
+ const cancelDelete = useRef<Focusable>(null);
77
+ // Each row's More button by row id, so focus can move to one when the thing that had it is gone.
78
+ const moreButtons = useRef<Record<string, Focusable>>({});
79
+ // Where focus goes after the next render, once the element it goes to is on screen.
80
+ const focusNext = useRef<() => void>();
81
+ // The clipboard answers later; by then the example may be gone.
82
+ const mounted = useRef(true);
83
+ // Gives each copy its own id, so no two rows share a key.
84
+ const copies = useRef(0);
85
+
86
+ // On unmount it stops the request and closes every toast it opened.
87
+ useEffect(() => () => {
88
+ mounted.current = false;
89
+ clearTimeout(timer.current);
90
+ toastIds.current.forEach((id) => dismissToast(id));
91
+ toastIds.current = [];
92
+ }, []);
93
+
94
+ useEffect(() => {
95
+ const move = focusNext.current;
96
+ focusNext.current = undefined;
97
+ move?.();
98
+ });
99
+
100
+ function openMenu(r: Report, anchor: HTMLElement) {
101
+ if (menuOpen && menuRow?.id === r.id) {
102
+ setMenuOpen(false);
103
+ return;
104
+ }
105
+ setMenuRow(r);
106
+ setMenuAnchor(anchor);
107
+ setMenuOpen(true);
108
+ }
109
+
110
+ // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
111
+ function choose(action: (r: Report) => void) {
112
+ if (!menuRow) return;
113
+ const r = menuRow;
114
+ setMenuOpen(false);
115
+ action(r);
116
+ }
117
+
118
+ // The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.
119
+ function duplicate(r: Report) {
120
+ copies.current += 1;
121
+ const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };
122
+ setReports((list) => {
123
+ const at = list.findIndex((x) => x.id === r.id);
124
+ return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];
125
+ });
126
+ focusNext.current = () => moreButtons.current[copy.id]?.focus();
127
+ }
128
+
129
+ // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,
130
+ // in an error toast that stays until the person closes it.
131
+ function copyLink(r: Report) {
132
+ const link = `https://example.com/reports/${r.id}`;
133
+ const failed = () => {
134
+ if (!mounted.current) return;
135
+ toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));
136
+ };
137
+ if (!navigator.clipboard) return failed();
138
+ navigator.clipboard.writeText(link).then(() => {
139
+ if (!mounted.current) return;
140
+ toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
141
+ }, failed);
142
+ }
143
+
144
+ // The confirm opens in the row, with focus on 'Cancel'.
145
+ function askToDelete(r: Report) {
146
+ setConfirmingId(r.id);
147
+ focusNext.current = () => cancelDelete.current?.focus();
148
+ }
149
+
150
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.
151
+ function keepReport() {
152
+ if (deleting || !confirmingId) return;
153
+ const id = confirmingId;
154
+ setConfirmingId(null);
155
+ focusNext.current = () => moreButtons.current[id]?.focus();
156
+ }
157
+
158
+ function confirmDelete() {
159
+ if (deleting || !confirmingId) return;
160
+ const id = confirmingId;
161
+ const at = reports.findIndex((r) => r.id === id);
162
+ const gone = reports[at];
163
+ const neighbor = reports[at + 1] ?? reports[at - 1];
164
+ setDeleting(true);
165
+ // Stands in for the request to the server.
166
+ timer.current = setTimeout(() => {
167
+ setDeleting(false);
168
+ setConfirmingId(null);
169
+ setReports((list) => list.filter((r) => r.id !== id));
170
+ toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));
171
+ // The row is gone: focus goes to the next row's More button, or the one before it when it was the last.
172
+ focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();
173
+ }, 1200);
174
+ }
175
+
176
+ return (
177
+ <Center width="page">
178
+ {/* A real app mounts one Toaster near its root. */}
179
+ <Toaster />
180
+ <Stack gap="large">
181
+ <Heading level={1} size="h5">Reports</Heading>
182
+ {reports.length > 0 ? (
183
+ <TableContainer>
184
+ {reports.map((r) => {
185
+ const confirming = r.id === confirmingId;
186
+ return (
187
+ <TableRow key={r.id}>
188
+ <TableCell>
189
+ <Stack gap="small">
190
+ {r.name}
191
+ {confirming && <Paragraph size="body2" tone="secondary" measure="none">Delete this report?</Paragraph>}
192
+ </Stack>
193
+ </TableCell>
194
+ <TableCell width="160px">{r.updated}</TableCell>
195
+ {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}
196
+ <TableCell width="168px" align="right">
197
+ {confirming ? (
198
+ <Cluster gap="small" justify="end">
199
+ <Button ref={cancelDelete} size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />
200
+ <Button size="small" type="primary" color="danger" state="enabled" label="Delete" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />
201
+ </Cluster>
202
+ ) : (
203
+ <Cluster justify="end">
204
+ <Tooltip title="More">
205
+ <IconButton
206
+ ref={(el) => { moreButtons.current[r.id] = el; }}
207
+ color="iconOnly"
208
+ state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}
209
+ size="small"
210
+ iconName="Ellipsis"
211
+ ariaLabel={`More actions for ${r.name}`}
212
+ aria-haspopup="menu"
213
+ aria-expanded={menuOpen && menuRow?.id === r.id}
214
+ onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}
215
+ />
216
+ </Tooltip>
217
+ </Cluster>
218
+ )}
219
+ </TableCell>
220
+ </TableRow>
221
+ );
222
+ })}
223
+ </TableContainer>
224
+ ) : (
225
+ <EmptyBox size="small" text="No reports yet" secondText="Reports you create appear here." />
226
+ )}
227
+ </Stack>
228
+ <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>
229
+ <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>
230
+ <MenuItem size="small" iconName="Copy" label="Duplicate" onClick={() => choose(duplicate)} />
231
+ <MenuItem size="small" iconName="Link" label="Copy Link" onClick={() => choose(copyLink)} />
232
+ <Line />
233
+ {/* Delete is last, and danger. */}
234
+ <MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={() => choose(askToDelete)} />
235
+ </Menu>
236
+ </Popover>
237
+ </Center>
238
+ );
239
+ }
240
+ ```
241
+
242
+ ## Option: More button in a header
243
+
244
+ Use when: The actions are for the whole page, and the header has one button.
245
+
246
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `IconButton`, `Line`, `List`, `Menu`, `MenuItem`, `Modal`, `Paragraph`, `Popover`, `Stack`, `Surface`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
247
+
248
+ ```tsx
249
+ 'use client';
250
+ import { useEffect, useRef, useState } from 'react';
251
+ import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
252
+ import Modal from 'oneslash-design-system/components/modal';
253
+ import Surface from 'oneslash-design-system/components/surface';
254
+ import Heading from 'oneslash-design-system/components/heading';
255
+ import Paragraph from 'oneslash-design-system/components/paragraph';
256
+ import List from 'oneslash-design-system/components/list';
257
+ import Button from 'oneslash-design-system/components/button';
258
+ import IconButton from 'oneslash-design-system/components/iconButton';
259
+ import Tooltip from 'oneslash-design-system/components/tooltip';
260
+ import Popover from 'oneslash-design-system/components/popover';
261
+ import Menu from 'oneslash-design-system/components/menu';
262
+ import MenuItem from 'oneslash-design-system/components/menuItem';
263
+ import Line from 'oneslash-design-system/components/line';
264
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
265
+
266
+ const otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];
267
+
268
+ export default function OverflowMenuInAHeader() {
269
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
270
+ const [open, setOpen] = useState(false);
271
+ const [confirming, setConfirming] = useState(false);
272
+ const [deleting, setDeleting] = useState(false);
273
+ const [deleted, setDeleted] = useState(false);
274
+ const timer = useRef<ReturnType<typeof setTimeout>>();
275
+ const toastIds = useRef<string[]>([]);
276
+ const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
277
+ // Where focus goes after the next render, once the element it goes to is on screen.
278
+ const focusNext = useRef<() => void>();
279
+ // The clipboard answers later; by then the example may be gone.
280
+ const mounted = useRef(true);
281
+
282
+ // On unmount it stops the request and closes every toast it opened.
283
+ useEffect(() => () => {
284
+ mounted.current = false;
285
+ clearTimeout(timer.current);
286
+ toastIds.current.forEach((id) => dismissToast(id));
287
+ toastIds.current = [];
288
+ }, []);
289
+
290
+ useEffect(() => {
291
+ const move = focusNext.current;
292
+ focusNext.current = undefined;
293
+ move?.();
294
+ });
295
+
296
+ function toggle(anchorEl: HTMLElement) {
297
+ setAnchor(anchorEl);
298
+ setOpen((o) => !o);
299
+ }
300
+
301
+ // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
302
+ function duplicate() {
303
+ setOpen(false);
304
+ toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));
305
+ }
306
+
307
+ // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.
308
+ function copyLink() {
309
+ setOpen(false);
310
+ const link = 'https://example.com/reports/q3';
311
+ const failed = () => {
312
+ if (!mounted.current) return;
313
+ toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));
314
+ };
315
+ if (!navigator.clipboard) return failed();
316
+ navigator.clipboard.writeText(link).then(() => {
317
+ if (!mounted.current) return;
318
+ toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
319
+ }, failed);
320
+ }
321
+
322
+ function askToDelete() {
323
+ setOpen(false);
324
+ setConfirming(true);
325
+ }
326
+
327
+ // The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.
328
+ function keepReport() {
329
+ if (deleting) return;
330
+ setConfirming(false);
331
+ focusNext.current = () => moreButton.current?.focus();
332
+ }
333
+
334
+ function confirmDelete() {
335
+ if (deleting) return;
336
+ setDeleting(true);
337
+ // Stands in for the request to the server.
338
+ timer.current = setTimeout(() => {
339
+ setDeleting(false);
340
+ setConfirming(false);
341
+ setDeleted(true);
342
+ toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));
343
+ }, 1200);
344
+ }
345
+
346
+ return (
347
+ <Center width="page">
348
+ {/* A real app mounts one Toaster near its root. */}
349
+ <Toaster />
350
+ {deleted ? (
351
+ // A real app goes back to the list of reports here.
352
+ <Stack gap="large">
353
+ <Heading level={1} size="h5">Reports</Heading>
354
+ <Surface padding="large">
355
+ <List items={otherReports} size="body1" />
356
+ </Surface>
357
+ </Stack>
358
+ ) : (
359
+ <Stack gap="medium">
360
+ <Cluster justify="between">
361
+ <Heading level={1} size="h5">Q3 report</Heading>
362
+ <Tooltip title="More">
363
+ <IconButton
364
+ ref={moreButton}
365
+ color="iconOnly"
366
+ state={open ? 'selected' : 'enabled'}
367
+ size="small"
368
+ iconName="Ellipsis"
369
+ ariaLabel="More actions for Q3 report"
370
+ aria-haspopup="menu"
371
+ aria-expanded={open}
372
+ onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}
373
+ />
374
+ </Tooltip>
375
+ </Cluster>
376
+ <Paragraph tone="secondary" size="body2" measure="none">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>
377
+ </Stack>
378
+ )}
379
+ <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
380
+ <Menu navigable aria-label="Actions for Q3 report" width={200}>
381
+ <MenuItem size="small" iconName="Copy" label="Duplicate" onClick={duplicate} />
382
+ <MenuItem size="small" iconName="Link" label="Copy Link" onClick={copyLink} />
383
+ <Line />
384
+ {/* Delete is last, and danger. */}
385
+ <MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={askToDelete} />
386
+ </Menu>
387
+ </Popover>
388
+ {/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}
389
+ <Modal
390
+ isOpen={confirming}
391
+ size="small"
392
+ title="Delete Report"
393
+ onClose={keepReport}
394
+ actions={
395
+ <>
396
+ <Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={keepReport} />
397
+ <Button size="small" type="primary" color="danger" state="enabled" label="Delete" loading={deleting} onClickButton={confirmDelete} />
398
+ </>
399
+ }
400
+ >
401
+ <Paragraph measure="none">This deletes &apos;Q3 report&apos; and its 12 tasks.</Paragraph>
402
+ </Modal>
403
+ </Center>
404
+ );
405
+ }
406
+ ```
407
+
408
+ ## Native
409
+
410
+ On Apple use a toolbar `Menu` with an `ellipsis.circle` label, or a row's `contextMenu`, with Delete last in the `.destructive` role. Delete asks in a `confirmationDialog`. On Android use an `IconButton` with a `DropdownMenu`.
@@ -0,0 +1 @@
1
+ export default function ProfileForm(): import("react").JSX.Element;
@@ -0,0 +1,153 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Heading from '../../components/heading';
4
+ import Form from '../../components/form';
5
+ import FormField from '../../components/formField';
6
+ import TextField from '../../components/textField';
7
+ import Button from '../../components/button';
8
+ import Alert from '../../components/alert';
9
+ import UserImage from '../../components/userImage';
10
+ import SettingsSection from '../../components/settingsSection';
11
+ import { Center, Cluster, Stack } from '../../components/layout';
12
+ // A picture the person chose. A real app uploads the file and gets a URL back.
13
+ var chosenPicture = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E";
14
+ var minPasswordLength = 8;
15
+ // Stands in for the server's check. In this example every current password is right except this one.
16
+ var wrongCurrentPassword = 'incorrect';
17
+ export default function ProfileForm() {
18
+ var _a = useState(undefined), picture = _a[0], setPicture = _a[1];
19
+ // Which picture Button was pressed, so only that one shows `loading`.
20
+ var _b = useState(null), savingPicture = _b[0], setSavingPicture = _b[1];
21
+ var _c = useState(''), pictureError = _c[0], setPictureError = _c[1];
22
+ var _d = useState('Dana Lee'), savedName = _d[0], setSavedName = _d[1];
23
+ var _e = useState('Dana Lee'), name = _e[0], setName = _e[1];
24
+ var _f = useState(''), nameError = _f[0], setNameError = _f[1];
25
+ var _g = useState(false), savingName = _g[0], setSavingName = _g[1];
26
+ var _h = useState(false), nameSaved = _h[0], setNameSaved = _h[1];
27
+ var _j = useState(''), currentPassword = _j[0], setCurrentPassword = _j[1];
28
+ var _k = useState(''), currentPasswordError = _k[0], setCurrentPasswordError = _k[1];
29
+ var _l = useState(''), password = _l[0], setPassword = _l[1];
30
+ var _m = useState(''), passwordError = _m[0], setPasswordError = _m[1];
31
+ var _o = useState(false), savingPassword = _o[0], setSavingPassword = _o[1];
32
+ var _p = useState(false), passwordSaved = _p[0], setPasswordSaved = _p[1];
33
+ var timers = useRef([]);
34
+ // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.
35
+ var nameSavedTimer = useRef();
36
+ var passwordSavedTimer = useRef();
37
+ // The first picture save fails, as if the upload dropped, so the example shows both paths.
38
+ var pictureFails = useRef(true);
39
+ // Stops every request and every 'Saved' if the example goes away before they end.
40
+ useEffect(function () { return function () {
41
+ timers.current.forEach(clearTimeout);
42
+ clearTimeout(nameSavedTimer.current);
43
+ clearTimeout(passwordSavedTimer.current);
44
+ }; }, []);
45
+ // Stands in for the request to the server.
46
+ function later(callback, ms) {
47
+ timers.current.push(setTimeout(callback, ms));
48
+ }
49
+ // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.
50
+ // When it fails, the old picture stays and a line under the Buttons says why.
51
+ function savePicture(next, pressed) {
52
+ if (savingPicture)
53
+ return;
54
+ setPictureError('');
55
+ setSavingPicture(pressed);
56
+ later(function () {
57
+ setSavingPicture(null);
58
+ if (pictureFails.current) {
59
+ pictureFails.current = false;
60
+ setPictureError('Could not save. Try again.');
61
+ return;
62
+ }
63
+ setPicture(next);
64
+ }, 900);
65
+ }
66
+ // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
67
+ function handleSaveName() {
68
+ if (savingName)
69
+ return;
70
+ if (!name.trim()) {
71
+ setNameError('Enter your name.');
72
+ return;
73
+ }
74
+ setNameError('');
75
+ setSavingName(true);
76
+ later(function () {
77
+ setSavedName(name.trim());
78
+ setName(name.trim());
79
+ setSavingName(false);
80
+ setNameSaved(true);
81
+ clearTimeout(nameSavedTimer.current);
82
+ nameSavedTimer.current = setTimeout(function () { return setNameSaved(false); }, 2000);
83
+ }, 1200);
84
+ }
85
+ function handleUpdatePassword() {
86
+ if (savingPassword || !currentPassword || !password)
87
+ return;
88
+ setCurrentPasswordError('');
89
+ if (password.length < minPasswordLength) {
90
+ setPasswordError("Use at least ".concat(minPasswordLength, " characters."));
91
+ return;
92
+ }
93
+ setPasswordError('');
94
+ setSavingPassword(true);
95
+ later(function () {
96
+ setSavingPassword(false);
97
+ // A wrong current password shows under that field, and both fields keep what the person typed.
98
+ if (currentPassword === wrongCurrentPassword) {
99
+ setCurrentPasswordError('This is not your current password. Enter it again.');
100
+ return;
101
+ }
102
+ setCurrentPassword('');
103
+ setPassword('');
104
+ setPasswordSaved(true);
105
+ clearTimeout(passwordSavedTimer.current);
106
+ passwordSavedTimer.current = setTimeout(function () { return setPasswordSaved(false); }, 2000);
107
+ }, 1200);
108
+ }
109
+ var nameChanged = name !== savedName;
110
+ return (<Center width="page">
111
+ <Stack gap="xlarge">
112
+ <Heading level={1} size="h5">Profile</Heading>
113
+
114
+ <SettingsSection title="Picture" description="Shown beside your name in Acme.">
115
+ <Cluster gap="large">
116
+ <UserImage userHandle={savedName} userImgUrl={picture} size={64}/>
117
+ <Stack gap="small">
118
+ <Cluster gap="small">
119
+ <Button size="small" type="secondary" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label="Change Picture" loading={savingPicture === 'change'} onClickButton={function () { return savePicture(chosenPicture, 'change'); }}/>
120
+ {picture && <Button size="small" type="tertiary" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label="Remove" aria-label="Remove picture" loading={savingPicture === 'remove'} onClickButton={function () { return savePicture(undefined, 'remove'); }}/>}
121
+ </Cluster>
122
+ {pictureError && <Alert type="error" variant="inline" autoDismiss={false} message={pictureError}/>}
123
+ </Stack>
124
+ </Cluster>
125
+ </SettingsSection>
126
+
127
+ <SettingsSection title="Name" description="How people see you in messages and on tasks.">
128
+ <Form aria-label="Name" gap="medium" onSubmit={handleSaveName}>
129
+ <FormField id="profile-form-name" label="Name" error={nameError}>
130
+ {function (f) { return (<TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={savingName} autoComplete="name" onChange={function (e) { setName(e.target.value); setNameError(''); setNameSaved(false); }}/>); }}
131
+ </FormField>
132
+ <Cluster>
133
+ <Button size="medium" type="primary" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType="submit" loading={savingName}/>
134
+ </Cluster>
135
+ </Form>
136
+ </SettingsSection>
137
+
138
+ <SettingsSection title="Password" description="Sign in with dana@acme.example and a password.">
139
+ <Form aria-label="Password" gap="medium" onSubmit={handleUpdatePassword}>
140
+ <FormField id="profile-form-current-password" label="Current password" error={currentPasswordError}>
141
+ {function (f) { return (<TextField id={f.id} type="password" aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={currentPassword} disabled={savingPassword} autoComplete="current-password" onChange={function (e) { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}/>); }}
142
+ </FormField>
143
+ <FormField id="profile-form-password" label="New password" help={"Use at least ".concat(minPasswordLength, " characters.")} error={passwordError}>
144
+ {function (f) { return (<TextField id={f.id} type="password" aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={password} disabled={savingPassword} autoComplete="new-password" onChange={function (e) { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}/>); }}
145
+ </FormField>
146
+ <Cluster>
147
+ <Button size="medium" type="primary" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType="submit" loading={savingPassword}/>
148
+ </Cluster>
149
+ </Form>
150
+ </SettingsSection>
151
+ </Stack>
152
+ </Center>);
153
+ }