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,236 @@
1
+ # Profile
2
+
3
+ A person changes how they appear and how they sign in: their picture, their name and their password.
4
+
5
+ ## Do
6
+
7
+ - Follow the rule 'A setting saves in place, or with one Save Button'.
8
+ - Put the picture, the name and the password in their own `SettingsSection`s. Do not mix a control that saves on change and a Save Button in one section.
9
+ - Save the picture as soon as the person chooses it, with 'Change Picture' and 'Remove'. Show `loading` on the Button that was pressed while it saves, and nothing when it works.
10
+ - When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'
11
+ - Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.
12
+ - Give the name one Save Button inside a `Form`. It is `state="disabled"` while the name has not changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.
13
+ - Give the password one 'Update Password' Button. Ask for the current password and the new one. It is disabled while either field is empty, and reads 'Saved' for 2 seconds. Then clear both fields.
14
+ - Show a wrong current password under that field, and keep what the person typed in both.
15
+ - Use `<TextField type="password">` for both, with `autoComplete="current-password"` and `autoComplete="new-password"`.
16
+ - Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. This ties its label, help and error to it.
17
+ - Show a problem with a field under it, as the rule 'A form error shows next to the problem' says: 'Enter your name.' and 'Use at least 8 characters.'
18
+ - Disable the field while its request runs, and keep what the person typed when the save fails.
19
+ - Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial.
20
+
21
+ ## Don't
22
+
23
+ - Do not add one Save Button for the whole page. Each group saves by itself.
24
+ - Do not label the Button 'Saving…' while it runs. It keeps its label.
25
+ - Do not show a toast when the name or the password is saved. The Button says it.
26
+ - Do not keep the passwords in the fields after they are saved.
27
+ - Do not ask for the new password twice. Show one field and the length rule.
28
+
29
+ ## Example: Picture, name and password
30
+
31
+ Uses: `Alert`, `Button`, `Center`, `Cluster`, `Form`, `FormField`, `Heading`, `SettingsSection`, `Stack`, `TextField`, `UserImage`
32
+
33
+ ```tsx
34
+ 'use client';
35
+ import { useEffect, useRef, useState } from 'react';
36
+ import Heading from 'oneslash-design-system/components/heading';
37
+ import Form from 'oneslash-design-system/components/form';
38
+ import FormField from 'oneslash-design-system/components/formField';
39
+ import TextField from 'oneslash-design-system/components/textField';
40
+ import Button from 'oneslash-design-system/components/button';
41
+ import Alert from 'oneslash-design-system/components/alert';
42
+ import UserImage from 'oneslash-design-system/components/userImage';
43
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
44
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
45
+
46
+ // A picture the person chose. A real app uploads the file and gets a URL back.
47
+ const chosenPicture =
48
+ "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";
49
+
50
+ const minPasswordLength = 8;
51
+ // Stands in for the server's check. In this example every current password is right except this one.
52
+ const wrongCurrentPassword = 'incorrect';
53
+
54
+ export default function ProfileForm() {
55
+ const [picture, setPicture] = useState<string | undefined>(undefined);
56
+ // Which picture Button was pressed, so only that one shows `loading`.
57
+ const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);
58
+ const [pictureError, setPictureError] = useState('');
59
+
60
+ const [savedName, setSavedName] = useState('Dana Lee');
61
+ const [name, setName] = useState('Dana Lee');
62
+ const [nameError, setNameError] = useState('');
63
+ const [savingName, setSavingName] = useState(false);
64
+ const [nameSaved, setNameSaved] = useState(false);
65
+
66
+ const [currentPassword, setCurrentPassword] = useState('');
67
+ const [currentPasswordError, setCurrentPasswordError] = useState('');
68
+ const [password, setPassword] = useState('');
69
+ const [passwordError, setPasswordError] = useState('');
70
+ const [savingPassword, setSavingPassword] = useState(false);
71
+ const [passwordSaved, setPasswordSaved] = useState(false);
72
+
73
+ const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
74
+ // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.
75
+ const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();
76
+ const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();
77
+ // The first picture save fails, as if the upload dropped, so the example shows both paths.
78
+ const pictureFails = useRef(true);
79
+
80
+ // Stops every request and every 'Saved' if the example goes away before they end.
81
+ useEffect(() => () => {
82
+ timers.current.forEach(clearTimeout);
83
+ clearTimeout(nameSavedTimer.current);
84
+ clearTimeout(passwordSavedTimer.current);
85
+ }, []);
86
+
87
+ // Stands in for the request to the server.
88
+ function later(callback: () => void, ms: number) {
89
+ timers.current.push(setTimeout(callback, ms));
90
+ }
91
+
92
+ // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.
93
+ // When it fails, the old picture stays and a line under the Buttons says why.
94
+ function savePicture(next: string | undefined, pressed: 'change' | 'remove') {
95
+ if (savingPicture) return;
96
+ setPictureError('');
97
+ setSavingPicture(pressed);
98
+ later(() => {
99
+ setSavingPicture(null);
100
+ if (pictureFails.current) {
101
+ pictureFails.current = false;
102
+ setPictureError('Could not save. Try again.');
103
+ return;
104
+ }
105
+ setPicture(next);
106
+ }, 900);
107
+ }
108
+
109
+ // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
110
+ function handleSaveName() {
111
+ if (savingName) return;
112
+ if (!name.trim()) {
113
+ setNameError('Enter your name.');
114
+ return;
115
+ }
116
+ setNameError('');
117
+ setSavingName(true);
118
+ later(() => {
119
+ setSavedName(name.trim());
120
+ setName(name.trim());
121
+ setSavingName(false);
122
+ setNameSaved(true);
123
+ clearTimeout(nameSavedTimer.current);
124
+ nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);
125
+ }, 1200);
126
+ }
127
+
128
+ function handleUpdatePassword() {
129
+ if (savingPassword || !currentPassword || !password) return;
130
+ setCurrentPasswordError('');
131
+ if (password.length < minPasswordLength) {
132
+ setPasswordError(`Use at least ${minPasswordLength} characters.`);
133
+ return;
134
+ }
135
+ setPasswordError('');
136
+ setSavingPassword(true);
137
+ later(() => {
138
+ setSavingPassword(false);
139
+ // A wrong current password shows under that field, and both fields keep what the person typed.
140
+ if (currentPassword === wrongCurrentPassword) {
141
+ setCurrentPasswordError('This is not your current password. Enter it again.');
142
+ return;
143
+ }
144
+ setCurrentPassword('');
145
+ setPassword('');
146
+ setPasswordSaved(true);
147
+ clearTimeout(passwordSavedTimer.current);
148
+ passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);
149
+ }, 1200);
150
+ }
151
+
152
+ const nameChanged = name !== savedName;
153
+
154
+ return (
155
+ <Center width="page">
156
+ <Stack gap="xlarge">
157
+ <Heading level={1} size="h5">Profile</Heading>
158
+
159
+ <SettingsSection title="Picture" description="Shown beside your name in Acme.">
160
+ <Cluster gap="large">
161
+ <UserImage userHandle={savedName} userImgUrl={picture} size={64} />
162
+ <Stack gap="small">
163
+ <Cluster gap="small">
164
+ <Button size="small" type="secondary" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label="Change Picture" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />
165
+ {picture && <Button size="small" type="tertiary" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label="Remove" aria-label="Remove picture" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}
166
+ </Cluster>
167
+ {pictureError && <Alert type="error" variant="inline" autoDismiss={false} message={pictureError} />}
168
+ </Stack>
169
+ </Cluster>
170
+ </SettingsSection>
171
+
172
+ <SettingsSection title="Name" description="How people see you in messages and on tasks.">
173
+ <Form aria-label="Name" gap="medium" onSubmit={handleSaveName}>
174
+ <FormField id="profile-form-name" label="Name" error={nameError}>
175
+ {(f) => (
176
+ <TextField
177
+ id={f.id}
178
+ aria-describedby={f['aria-describedby']}
179
+ aria-invalid={f['aria-invalid']}
180
+ value={name}
181
+ disabled={savingName}
182
+ autoComplete="name"
183
+ onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}
184
+ />
185
+ )}
186
+ </FormField>
187
+ <Cluster>
188
+ <Button size="medium" type="primary" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType="submit" loading={savingName} />
189
+ </Cluster>
190
+ </Form>
191
+ </SettingsSection>
192
+
193
+ <SettingsSection title="Password" description="Sign in with dana@acme.example and a password.">
194
+ <Form aria-label="Password" gap="medium" onSubmit={handleUpdatePassword}>
195
+ <FormField id="profile-form-current-password" label="Current password" error={currentPasswordError}>
196
+ {(f) => (
197
+ <TextField
198
+ id={f.id}
199
+ type="password"
200
+ aria-describedby={f['aria-describedby']}
201
+ aria-invalid={f['aria-invalid']}
202
+ value={currentPassword}
203
+ disabled={savingPassword}
204
+ autoComplete="current-password"
205
+ onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}
206
+ />
207
+ )}
208
+ </FormField>
209
+ <FormField id="profile-form-password" label="New password" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>
210
+ {(f) => (
211
+ <TextField
212
+ id={f.id}
213
+ type="password"
214
+ aria-describedby={f['aria-describedby']}
215
+ aria-invalid={f['aria-invalid']}
216
+ value={password}
217
+ disabled={savingPassword}
218
+ autoComplete="new-password"
219
+ onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}
220
+ />
221
+ )}
222
+ </FormField>
223
+ <Cluster>
224
+ <Button size="medium" type="primary" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType="submit" loading={savingPassword} />
225
+ </Cluster>
226
+ </Form>
227
+ </SettingsSection>
228
+ </Stack>
229
+ </Center>
230
+ );
231
+ }
232
+ ```
233
+
234
+ ## Native
235
+
236
+ On Apple use a grouped `Form` with the name in a `TextField` and a `SecureField` for the password, and a `PhotosPicker` for the picture. The picture saves when it is chosen.
@@ -0,0 +1 @@
1
+ export default function QuickSwitcherModal(): import("react").JSX.Element;
@@ -0,0 +1,114 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Modal from '../../components/modal';
4
+ import Heading from '../../components/heading';
5
+ import Paragraph from '../../components/paragraph';
6
+ import TextField from '../../components/textField';
7
+ import Button from '../../components/button';
8
+ import EmptyBox from '../../components/emptyBox';
9
+ import Menu from '../../components/menu';
10
+ import MenuItem from '../../components/menuItem';
11
+ import useHotkey from '../../components/useHotkey';
12
+ import { Center, Cluster, Stack } from '../../components/layout';
13
+ var places = [
14
+ { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },
15
+ { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },
16
+ { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },
17
+ { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },
18
+ { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },
19
+ { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },
20
+ ];
21
+ var icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' };
22
+ // At most this many rows show, so the list never needs to scroll; typing more letters narrows it.
23
+ var MAX_RESULTS = 6;
24
+ var listId = 'quick-switcher-results';
25
+ var optionId = function (p) { return "quick-switcher-option-".concat(p.id); };
26
+ // Places with a word that starts with what was typed. With nothing typed it shows the most recent.
27
+ function matches(query) {
28
+ var q = query.trim().toLowerCase();
29
+ if (!q)
30
+ return places.slice(0, MAX_RESULTS);
31
+ return places.filter(function (p) { return p.title.toLowerCase().split(/[\s-]+/).some(function (w) { return w.startsWith(q); }); }).slice(0, MAX_RESULTS);
32
+ }
33
+ export default function QuickSwitcherModal() {
34
+ // Opens with the switcher showing, as if the person just pressed Cmd+K.
35
+ var _a = useState(true), open = _a[0], setOpen = _a[1];
36
+ var _b = useState('la'), query = _b[0], setQuery = _b[1];
37
+ var _c = useState(0), active = _c[0], setActive = _c[1];
38
+ var _d = useState(places[0]), here = _d[0], setHere = _d[1];
39
+ // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field
40
+ // instead of being lost with the Button that the list replaces.
41
+ var _e = useState(0), fieldKey = _e[0], setFieldKey = _e[1];
42
+ var results = matches(query);
43
+ var listOpen = results.length > 0;
44
+ function openSwitcher() {
45
+ setQuery('');
46
+ setActive(0);
47
+ setOpen(true);
48
+ }
49
+ // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.
50
+ useHotkey('k', function () {
51
+ if (!open)
52
+ openSwitcher();
53
+ });
54
+ function change(value) {
55
+ setQuery(value);
56
+ setActive(0);
57
+ }
58
+ // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.
59
+ function go(place) {
60
+ setHere(place);
61
+ setOpen(false);
62
+ }
63
+ function clearSearch() {
64
+ setQuery('');
65
+ setActive(0);
66
+ setFieldKey(function (k) { return k + 1; });
67
+ }
68
+ // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.
69
+ function keyDown(e) {
70
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
71
+ if (e.nativeEvent.isComposing || e.keyCode === 229)
72
+ return;
73
+ if (!listOpen)
74
+ return;
75
+ if (e.key === 'ArrowDown') {
76
+ e.preventDefault();
77
+ setActive(function (i) { return Math.min(i + 1, results.length - 1); });
78
+ }
79
+ else if (e.key === 'ArrowUp') {
80
+ e.preventDefault();
81
+ setActive(function (i) { return Math.max(i - 1, 0); });
82
+ }
83
+ else if (e.key === 'Enter') {
84
+ e.preventDefault();
85
+ go(results[active]);
86
+ }
87
+ }
88
+ return (<Center width="page">
89
+ <Stack gap="large">
90
+ <Cluster justify="between">
91
+ <Heading level={1} size="h5">{here.title}</Heading>
92
+ {/* A shortcut alone is not found by most people, so a Button opens it too. */}
93
+ <Button size="small" type="secondary" state="enabled" label="Go to" decoIcon="Search" aria-haspopup="dialog" aria-keyshortcuts="Meta+K Control+K" onClickButton={openSwitcher}/>
94
+ </Cluster>
95
+ <Paragraph tone="secondary" size="body2" measure="none">
96
+ {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.
97
+ </Paragraph>
98
+ </Stack>
99
+ <Modal isOpen={open} size="small" title="Go to" initialFocus="body" onClose={function () { return setOpen(false); }}>
100
+ <Stack gap="medium">
101
+ <TextField key={fieldKey} id="quick-switcher-query" type="search"
102
+ // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.
103
+ autoFocus={fieldKey > 0} aria-label="Go to" placeholder="Search channels, tasks and documents" value={query} onChange={function (e) { return change(e.target.value); }} onKeyDown={keyDown}
104
+ // Focus stays in the field; the field points at the list and at the highlighted row.
105
+ role="combobox" aria-autocomplete="list" aria-expanded={listOpen} aria-controls={listOpen ? listId : undefined} aria-activedescendant={listOpen ? optionId(results[active]) : undefined}/>
106
+ {listOpen ? (<Menu role="listbox" id={listId} aria-label="Places" width="100%">
107
+ {results.map(function (p, i) { return (<MenuItem key={p.id} id={optionId(p)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small" iconName={icons[p.kind]} label={p.title} secondLabel={p.workspace} onClick={function () { return go(p); }}/>); })}
108
+ </Menu>) : (
109
+ // The case 'Empty search' says what to show: the words searched for, and a way to clear them.
110
+ <EmptyBox size="small" icon="Search" text={"No places match \"".concat(query.trim(), "\"")} secondText="Check the spelling, or search for fewer words." action={<Button size="medium" type="secondary" state="enabled" label="Clear Search" onClickButton={clearSearch}/>}/>)}
111
+ </Stack>
112
+ </Modal>
113
+ </Center>);
114
+ }
@@ -0,0 +1,205 @@
1
+ # Quick switcher
2
+
3
+ A person jumps to a channel, task or document by typing part of its name, from anywhere in the product.
4
+
5
+ ## Do
6
+
7
+ - Open it with Cmd+K, or Ctrl+K on Windows, and with a visible 'Go to' Button. A shortcut alone is not found.
8
+ - Add the shortcut with `useHotkey('k', …)`. It is removed when the page goes away, and it does nothing while the person types in a field.
9
+ - Open a small `Modal` with `initialFocus="body"`, so focus lands in the search field. Closing gives focus back to where it was.
10
+ - Build it as a combobox, as the case 'Mention list' says. The field gets `role="combobox"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`.
11
+ - Make the list a `Menu role="listbox"` of `MenuItem role="option"` rows, with `isActive` and `aria-selected` on the highlighted one.
12
+ - Name the field with `aria-label="Go to"`, since it has no visible label.
13
+ - Show the most recent places, at most 6, before the person types.
14
+ - Show each place with its icon and name, and where it lives in `secondLabel`.
15
+ - Move the highlight with the arrow keys. Enter opens the highlighted place and closes the Modal. Escape closes it.
16
+ - Leave Enter and the arrow keys to an input method while it is still composing.
17
+ - Follow the case 'Empty search' when nothing matches: the words searched for and a 'Clear Search' Button, which puts focus back in the field.
18
+
19
+ ## Don't
20
+
21
+ - Do not use the shortcut as the only way in.
22
+ - Do not take Cmd+K while the person types in a field. Some fields use it for their own commands.
23
+ - Do not move focus into the list. The person keeps typing in the field.
24
+ - Do not keep the last search. It opens empty.
25
+ - Do not show a toast after going to a place. The page changing says it.
26
+
27
+ ## Example: Small Modal with a search field and a list
28
+
29
+ Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `Menu`, `MenuItem`, `Modal`, `Paragraph`, `Stack`, `TextField`, `useHotkey`
30
+
31
+ ```tsx
32
+ 'use client';
33
+ import { useState, type KeyboardEvent } from 'react';
34
+ import Modal from 'oneslash-design-system/components/modal';
35
+ import Heading from 'oneslash-design-system/components/heading';
36
+ import Paragraph from 'oneslash-design-system/components/paragraph';
37
+ import TextField from 'oneslash-design-system/components/textField';
38
+ import Button from 'oneslash-design-system/components/button';
39
+ import EmptyBox from 'oneslash-design-system/components/emptyBox';
40
+ import Menu from 'oneslash-design-system/components/menu';
41
+ import MenuItem from 'oneslash-design-system/components/menuItem';
42
+ import useHotkey from 'oneslash-design-system/components/useHotkey';
43
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
44
+
45
+ // A real app reads these from the server. The most recent place comes first.
46
+ type Place = { id: string; title: string; kind: 'channel' | 'task' | 'doc'; workspace: string };
47
+ const places: Place[] = [
48
+ { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },
49
+ { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },
50
+ { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },
51
+ { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },
52
+ { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },
53
+ { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },
54
+ ];
55
+ const icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' } as const;
56
+
57
+ // At most this many rows show, so the list never needs to scroll; typing more letters narrows it.
58
+ const MAX_RESULTS = 6;
59
+ const listId = 'quick-switcher-results';
60
+ const optionId = (p: Place) => `quick-switcher-option-${p.id}`;
61
+
62
+ // Places with a word that starts with what was typed. With nothing typed it shows the most recent.
63
+ function matches(query: string) {
64
+ const q = query.trim().toLowerCase();
65
+ if (!q) return places.slice(0, MAX_RESULTS);
66
+ return places.filter((p) => p.title.toLowerCase().split(/[\s-]+/).some((w) => w.startsWith(q))).slice(0, MAX_RESULTS);
67
+ }
68
+
69
+ export default function QuickSwitcherModal() {
70
+ // Opens with the switcher showing, as if the person just pressed Cmd+K.
71
+ const [open, setOpen] = useState(true);
72
+ const [query, setQuery] = useState('la');
73
+ const [active, setActive] = useState(0);
74
+ const [here, setHere] = useState<Place>(places[0]);
75
+ // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field
76
+ // instead of being lost with the Button that the list replaces.
77
+ const [fieldKey, setFieldKey] = useState(0);
78
+
79
+ const results = matches(query);
80
+ const listOpen = results.length > 0;
81
+
82
+ function openSwitcher() {
83
+ setQuery('');
84
+ setActive(0);
85
+ setOpen(true);
86
+ }
87
+
88
+ // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.
89
+ useHotkey('k', () => {
90
+ if (!open) openSwitcher();
91
+ });
92
+
93
+ function change(value: string) {
94
+ setQuery(value);
95
+ setActive(0);
96
+ }
97
+
98
+ // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.
99
+ function go(place: Place) {
100
+ setHere(place);
101
+ setOpen(false);
102
+ }
103
+
104
+ function clearSearch() {
105
+ setQuery('');
106
+ setActive(0);
107
+ setFieldKey((k) => k + 1);
108
+ }
109
+
110
+ // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.
111
+ function keyDown(e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {
112
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
113
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return;
114
+ if (!listOpen) return;
115
+ if (e.key === 'ArrowDown') {
116
+ e.preventDefault();
117
+ setActive((i) => Math.min(i + 1, results.length - 1));
118
+ } else if (e.key === 'ArrowUp') {
119
+ e.preventDefault();
120
+ setActive((i) => Math.max(i - 1, 0));
121
+ } else if (e.key === 'Enter') {
122
+ e.preventDefault();
123
+ go(results[active]);
124
+ }
125
+ }
126
+
127
+ return (
128
+ <Center width="page">
129
+ <Stack gap="large">
130
+ <Cluster justify="between">
131
+ <Heading level={1} size="h5">{here.title}</Heading>
132
+ {/* A shortcut alone is not found by most people, so a Button opens it too. */}
133
+ <Button
134
+ size="small"
135
+ type="secondary"
136
+ state="enabled"
137
+ label="Go to"
138
+ decoIcon="Search"
139
+ aria-haspopup="dialog"
140
+ aria-keyshortcuts="Meta+K Control+K"
141
+ onClickButton={openSwitcher}
142
+ />
143
+ </Cluster>
144
+ <Paragraph tone="secondary" size="body2" measure="none">
145
+ {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.
146
+ </Paragraph>
147
+ </Stack>
148
+ <Modal isOpen={open} size="small" title="Go to" initialFocus="body" onClose={() => setOpen(false)}>
149
+ <Stack gap="medium">
150
+ <TextField
151
+ key={fieldKey}
152
+ id="quick-switcher-query"
153
+ type="search"
154
+ // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.
155
+ autoFocus={fieldKey > 0}
156
+ aria-label="Go to"
157
+ placeholder="Search channels, tasks and documents"
158
+ value={query}
159
+ onChange={(e) => change(e.target.value)}
160
+ onKeyDown={keyDown}
161
+ // Focus stays in the field; the field points at the list and at the highlighted row.
162
+ role="combobox"
163
+ aria-autocomplete="list"
164
+ aria-expanded={listOpen}
165
+ aria-controls={listOpen ? listId : undefined}
166
+ aria-activedescendant={listOpen ? optionId(results[active]) : undefined}
167
+ />
168
+ {listOpen ? (
169
+ <Menu role="listbox" id={listId} aria-label="Places" width="100%">
170
+ {results.map((p, i) => (
171
+ <MenuItem
172
+ key={p.id}
173
+ id={optionId(p)}
174
+ role="option"
175
+ tabIndex={-1}
176
+ isActive={i === active}
177
+ aria-selected={i === active}
178
+ size="small"
179
+ iconName={icons[p.kind]}
180
+ label={p.title}
181
+ secondLabel={p.workspace}
182
+ onClick={() => go(p)}
183
+ />
184
+ ))}
185
+ </Menu>
186
+ ) : (
187
+ // The case 'Empty search' says what to show: the words searched for, and a way to clear them.
188
+ <EmptyBox
189
+ size="small"
190
+ icon="Search"
191
+ text={`No places match "${query.trim()}"`}
192
+ secondText="Check the spelling, or search for fewer words."
193
+ action={<Button size="medium" type="secondary" state="enabled" label="Clear Search" onClickButton={clearSearch} />}
194
+ />
195
+ )}
196
+ </Stack>
197
+ </Modal>
198
+ </Center>
199
+ );
200
+ }
201
+ ```
202
+
203
+ ## Native
204
+
205
+ On Apple use a sheet with a `TextField` over a `List`, opened with `.keyboardShortcut("k")`, and `ContentUnavailableView.search(text:)` when nothing matches. A phone needs no switcher: use the search tab.
@@ -0,0 +1 @@
1
+ export default function RangeSwitchSegmented(): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Heading from '../../components/heading';
4
+ import Paragraph from '../../components/paragraph';
5
+ import SegmentedControl from '../../components/segmentedControl';
6
+ import { Center, Cluster, Stack } from '../../components/layout';
7
+ // A real app counts these on the server.
8
+ var ranges = [
9
+ { value: 'week', label: 'Week', count: 18 },
10
+ { value: 'month', label: 'Month', count: 64 },
11
+ { value: 'quarter', label: 'Quarter', count: 171 },
12
+ ];
13
+ export default function RangeSwitchSegmented() {
14
+ var _a;
15
+ var _b = useState('week'), range = _b[0], setRange = _b[1];
16
+ var current = (_a = ranges.find(function (r) { return r.value === range; })) !== null && _a !== void 0 ? _a : ranges[0];
17
+ return (<Center width="page">
18
+ <Stack gap="large">
19
+ <Cluster justify="between">
20
+ <Heading level={1} size="h5">Overview</Heading>
21
+ <SegmentedControl size="small" width="fit" aria-label="Range" options={ranges.map(function (_a) {
22
+ var value = _a.value, label = _a.label;
23
+ return ({ value: value, label: label });
24
+ })} value={range} onChange={setRange}/>
25
+ </Cluster>
26
+ {/* The chart or list below changes with the range. This page stays the same. */}
27
+ <Paragraph size="body2" measure="none">{current.count} comments this {current.label.toLowerCase()}.</Paragraph>
28
+ </Stack>
29
+ </Center>);
30
+ }
@@ -0,0 +1,67 @@
1
+ # Range switch
2
+
3
+ A person changes the time range of a chart or a list on the same page, such as Week, Month or Quarter.
4
+
5
+ ## Do
6
+
7
+ - Use `SegmentedControl` with `size="small"` and `aria-label="Range"`: 'Week', 'Month', 'Quarter'.
8
+ - Put it beside the heading of the chart or list it changes, with `width="fit"` so it is as wide as its options.
9
+ - Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.
10
+ - Change the numbers in place and keep the page, the heading and the scroll position.
11
+ - Move between options with the arrow keys. They select as they move.
12
+
13
+ ## Don't
14
+
15
+ - Do not use tabs. Tabs switch panels, and this changes one value on the same page.
16
+ - Do not use more than four options. Use a menu, as the case 'Filter menu' says.
17
+ - Do not let the person turn every option off.
18
+ - Do not hide a range of three choices behind a menu.
19
+
20
+ ## Example: Segmented control
21
+
22
+ Uses: `Center`, `Cluster`, `Heading`, `Paragraph`, `SegmentedControl`, `Stack`
23
+
24
+ ```tsx
25
+ 'use client';
26
+ import { useState } from 'react';
27
+ import Heading from 'oneslash-design-system/components/heading';
28
+ import Paragraph from 'oneslash-design-system/components/paragraph';
29
+ import SegmentedControl from 'oneslash-design-system/components/segmentedControl';
30
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
31
+
32
+ // A real app counts these on the server.
33
+ const ranges = [
34
+ { value: 'week', label: 'Week', count: 18 },
35
+ { value: 'month', label: 'Month', count: 64 },
36
+ { value: 'quarter', label: 'Quarter', count: 171 },
37
+ ];
38
+
39
+ export default function RangeSwitchSegmented() {
40
+ const [range, setRange] = useState('week');
41
+ const current = ranges.find((r) => r.value === range) ?? ranges[0];
42
+
43
+ return (
44
+ <Center width="page">
45
+ <Stack gap="large">
46
+ <Cluster justify="between">
47
+ <Heading level={1} size="h5">Overview</Heading>
48
+ <SegmentedControl
49
+ size="small"
50
+ width="fit"
51
+ aria-label="Range"
52
+ options={ranges.map(({ value, label }) => ({ value, label }))}
53
+ value={range}
54
+ onChange={setRange}
55
+ />
56
+ </Cluster>
57
+ {/* The chart or list below changes with the range. This page stays the same. */}
58
+ <Paragraph size="body2" measure="none">{current.count} comments this {current.label.toLowerCase()}.</Paragraph>
59
+ </Stack>
60
+ </Center>
61
+ );
62
+ }
63
+ ```
64
+
65
+ ## Native
66
+
67
+ On Apple use a `Picker` with the `.segmented` style, and on Android a `SingleChoiceSegmentedButtonRow`.