oneslash-design-system 2.16.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 (301) hide show
  1. package/README.md +2 -2
  2. package/dist/DESIGN.md +56 -17
  3. package/dist/cases/accept-invite/signed-in.jsx +1 -1
  4. package/dist/cases/accept-invite/signed-out.jsx +1 -1
  5. package/dist/cases/accept-invite.md +3 -7
  6. package/dist/cases/account-menu/menu.d.ts +1 -0
  7. package/dist/cases/account-menu/menu.jsx +99 -0
  8. package/dist/cases/account-menu.md +164 -0
  9. package/dist/cases/agent-asks-before-risky-action.md +0 -4
  10. package/dist/cases/agent-cancels-when-unanswered.md +0 -4
  11. package/dist/cases/agent-options/cards.d.ts +1 -0
  12. package/dist/cases/agent-options/cards.jsx +91 -0
  13. package/dist/cases/agent-options.md +164 -0
  14. package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
  15. package/dist/cases/agent-pending-reply/steps.jsx +149 -0
  16. package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
  17. package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
  18. package/dist/cases/agent-pending-reply.md +428 -0
  19. package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
  20. package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
  21. package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
  22. package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
  23. package/dist/cases/agent-plan-proposal.md +652 -0
  24. package/dist/cases/agent-question/choices.d.ts +1 -0
  25. package/dist/cases/agent-question/choices.jsx +132 -0
  26. package/dist/cases/agent-question/free-text.d.ts +1 -0
  27. package/dist/cases/agent-question/free-text.jsx +81 -0
  28. package/dist/cases/agent-question.md +334 -0
  29. package/dist/cases/agent-refuses-clearly.md +0 -4
  30. package/dist/cases/agent-says-what-it-is.md +0 -2
  31. package/dist/cases/agent-settings/form.d.ts +1 -0
  32. package/dist/cases/agent-settings/form.jsx +164 -0
  33. package/dist/cases/agent-settings.md +259 -0
  34. package/dist/cases/agent-shows-progress.md +0 -2
  35. package/dist/cases/agent-shows-sources.md +2 -4
  36. package/dist/cases/api-keys/list.d.ts +1 -0
  37. package/dist/cases/api-keys/list.jsx +162 -0
  38. package/dist/cases/api-keys.md +229 -0
  39. package/dist/cases/artifact-card/card.d.ts +1 -0
  40. package/dist/cases/artifact-card/card.jsx +45 -0
  41. package/dist/cases/artifact-card.md +99 -0
  42. package/dist/cases/auth-gate-loading.md +0 -4
  43. package/dist/cases/check-your-email.md +0 -4
  44. package/dist/cases/collapsible-search/popover.d.ts +1 -0
  45. package/dist/cases/collapsible-search/popover.jsx +74 -0
  46. package/dist/cases/collapsible-search.md +143 -0
  47. package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
  48. package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
  49. package/dist/cases/composer-limit/notice.d.ts +1 -0
  50. package/dist/cases/composer-limit/notice.jsx +84 -0
  51. package/dist/cases/composer-limit.md +282 -0
  52. package/dist/cases/confirm-destructive-action.md +0 -4
  53. package/dist/cases/confirm-dialogs.md +0 -4
  54. package/dist/cases/conversation-starters/chips.d.ts +1 -0
  55. package/dist/cases/conversation-starters/chips.jsx +69 -0
  56. package/dist/cases/conversation-starters/none.d.ts +1 -0
  57. package/dist/cases/conversation-starters/none.jsx +45 -0
  58. package/dist/cases/conversation-starters.md +204 -0
  59. package/dist/cases/create-modal.md +0 -4
  60. package/dist/cases/danger-zone/collapsed.d.ts +1 -0
  61. package/dist/cases/danger-zone/collapsed.jsx +75 -0
  62. package/dist/cases/danger-zone/shown.d.ts +1 -0
  63. package/dist/cases/danger-zone/shown.jsx +95 -0
  64. package/dist/cases/danger-zone.md +263 -0
  65. package/dist/cases/device-login.md +0 -4
  66. package/dist/cases/email-confirmed.md +0 -4
  67. package/dist/cases/empty-list.md +0 -4
  68. package/dist/cases/empty-lists.md +0 -4
  69. package/dist/cases/empty-not-set-up.md +0 -4
  70. package/dist/cases/empty-search.md +0 -4
  71. package/dist/cases/error-page.md +0 -4
  72. package/dist/cases/feedback-form.md +0 -4
  73. package/dist/cases/filter-menu/presets.d.ts +1 -0
  74. package/dist/cases/filter-menu/presets.jsx +53 -0
  75. package/dist/cases/filter-menu/with-clear.d.ts +1 -0
  76. package/dist/cases/filter-menu/with-clear.jsx +56 -0
  77. package/dist/cases/filter-menu.md +204 -0
  78. package/dist/cases/forgot-password.md +0 -4
  79. package/dist/cases/form-errors.md +0 -4
  80. package/dist/cases/import-checklist.md +0 -4
  81. package/dist/cases/inline-form-feedback.md +0 -4
  82. package/dist/cases/integrations-list/nested.d.ts +1 -0
  83. package/dist/cases/integrations-list/nested.jsx +164 -0
  84. package/dist/cases/integrations-list/rows.d.ts +1 -0
  85. package/dist/cases/integrations-list/rows.jsx +134 -0
  86. package/dist/cases/integrations-list.md +379 -0
  87. package/dist/cases/invite-member.md +0 -4
  88. package/dist/cases/load-failure.md +0 -4
  89. package/dist/cases/log-out-confirm.md +0 -4
  90. package/dist/cases/login-page.md +0 -4
  91. package/dist/cases/members-list/rows.d.ts +1 -0
  92. package/dist/cases/members-list/rows.jsx +318 -0
  93. package/dist/cases/members-list/table.d.ts +1 -0
  94. package/dist/cases/members-list/table.jsx +351 -0
  95. package/dist/cases/members-list.md +799 -0
  96. package/dist/cases/mention-list/in-composer.d.ts +1 -0
  97. package/dist/cases/mention-list/in-composer.jsx +169 -0
  98. package/dist/cases/mention-list.md +248 -0
  99. package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
  100. package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
  101. package/dist/cases/message-actions/menu.d.ts +1 -0
  102. package/dist/cases/message-actions/menu.jsx +258 -0
  103. package/dist/cases/message-actions.md +647 -0
  104. package/dist/cases/message-attachments/in-composer.d.ts +1 -0
  105. package/dist/cases/message-attachments/in-composer.jsx +134 -0
  106. package/dist/cases/message-attachments/in-message.d.ts +1 -0
  107. package/dist/cases/message-attachments/in-message.jsx +46 -0
  108. package/dist/cases/message-attachments.md +306 -0
  109. package/dist/cases/message-composer/plain.d.ts +1 -0
  110. package/dist/cases/message-composer/plain.jsx +57 -0
  111. package/dist/cases/message-composer/with-tools.d.ts +1 -0
  112. package/dist/cases/message-composer/with-tools.jsx +182 -0
  113. package/dist/cases/message-composer.md +352 -0
  114. package/dist/cases/message-edit/in-place.d.ts +1 -0
  115. package/dist/cases/message-edit/in-place.jsx +99 -0
  116. package/dist/cases/message-edit.md +175 -0
  117. package/dist/cases/message-reactions/chips.d.ts +1 -0
  118. package/dist/cases/message-reactions/chips.jsx +118 -0
  119. package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
  120. package/dist/cases/message-reactions/quick-pick.jsx +155 -0
  121. package/dist/cases/message-reactions.md +367 -0
  122. package/dist/cases/message-row/grouped.d.ts +1 -0
  123. package/dist/cases/message-row/grouped.jsx +56 -0
  124. package/dist/cases/message-row/person-and-agent.d.ts +1 -0
  125. package/dist/cases/message-row/person-and-agent.jsx +41 -0
  126. package/dist/cases/message-row.md +185 -0
  127. package/dist/cases/not-found-page.md +0 -4
  128. package/dist/cases/notification-menu/menu.d.ts +1 -0
  129. package/dist/cases/notification-menu/menu.jsx +74 -0
  130. package/dist/cases/notification-menu.md +135 -0
  131. package/dist/cases/oauth-consent.md +0 -4
  132. package/dist/cases/on-off-settings/list.d.ts +1 -0
  133. package/dist/cases/on-off-settings/list.jsx +97 -0
  134. package/dist/cases/on-off-settings.md +116 -0
  135. package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
  136. package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
  137. package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
  138. package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
  139. package/dist/cases/overflow-menu.md +410 -0
  140. package/dist/cases/profile-form/form.d.ts +1 -0
  141. package/dist/cases/profile-form/form.jsx +153 -0
  142. package/dist/cases/profile-form.md +236 -0
  143. package/dist/cases/quick-switcher/modal.d.ts +1 -0
  144. package/dist/cases/quick-switcher/modal.jsx +114 -0
  145. package/dist/cases/quick-switcher.md +205 -0
  146. package/dist/cases/range-switch/segmented.d.ts +1 -0
  147. package/dist/cases/range-switch/segmented.jsx +30 -0
  148. package/dist/cases/range-switch.md +67 -0
  149. package/dist/cases/rename.md +0 -4
  150. package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
  151. package/dist/cases/reply-feedback/thumbs.jsx +191 -0
  152. package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
  153. package/dist/cases/reply-feedback/with-reason.jsx +221 -0
  154. package/dist/cases/reply-feedback.md +548 -0
  155. package/dist/cases/reply-sources/cards.d.ts +1 -0
  156. package/dist/cases/reply-sources/cards.jsx +83 -0
  157. package/dist/cases/reply-sources/tag-only.d.ts +1 -0
  158. package/dist/cases/reply-sources/tag-only.jsx +45 -0
  159. package/dist/cases/reply-sources.md +243 -0
  160. package/dist/cases/route-loading.md +0 -2
  161. package/dist/cases/scope-picker/menu.d.ts +1 -0
  162. package/dist/cases/scope-picker/menu.jsx +47 -0
  163. package/dist/cases/scope-picker.md +97 -0
  164. package/dist/cases/set-new-password.md +0 -4
  165. package/dist/cases/settings-page/side-nav.d.ts +1 -0
  166. package/dist/cases/settings-page/side-nav.jsx +171 -0
  167. package/dist/cases/settings-page/top-tabs.d.ts +1 -0
  168. package/dist/cases/settings-page/top-tabs.jsx +129 -0
  169. package/dist/cases/settings-page.md +378 -0
  170. package/dist/cases/settings-save.md +35 -0
  171. package/dist/cases/sign-up-page.md +1 -5
  172. package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
  173. package/dist/cases/slash-command-list/in-composer.jsx +162 -0
  174. package/dist/cases/slash-command-list.md +243 -0
  175. package/dist/cases/success-feedback.md +1 -5
  176. package/dist/cases/tag-filter/tags.d.ts +1 -0
  177. package/dist/cases/tag-filter/tags.jsx +226 -0
  178. package/dist/cases/tag-filter.md +298 -0
  179. package/dist/cases/type-to-confirm.md +0 -4
  180. package/dist/cases/typing-and-status/line.d.ts +1 -0
  181. package/dist/cases/typing-and-status/line.jsx +50 -0
  182. package/dist/cases/typing-and-status.md +92 -0
  183. package/dist/cases/unsaved-changes-guard.md +0 -4
  184. package/dist/cases/upgrade-prompt.md +0 -4
  185. package/dist/cases.json +2331 -294
  186. package/dist/components/alert.d.ts +3 -1
  187. package/dist/components/alert.jsx +2 -2
  188. package/dist/components/button.d.ts +3 -2
  189. package/dist/components/button.jsx +14 -9
  190. package/dist/components/checkBox.d.ts +5 -1
  191. package/dist/components/checkBox.jsx +2 -2
  192. package/dist/components/composer.d.ts +74 -0
  193. package/dist/components/composer.jsx +122 -0
  194. package/dist/components/copyField.d.ts +20 -0
  195. package/dist/components/copyField.jsx +99 -0
  196. package/dist/components/fileChip.d.ts +33 -0
  197. package/dist/components/fileChip.jsx +61 -0
  198. package/dist/components/formField.d.ts +34 -0
  199. package/dist/components/formField.jsx +28 -0
  200. package/dist/components/heading.d.ts +3 -1
  201. package/dist/components/heading.jsx +2 -2
  202. package/dist/components/iconButton.d.ts +3 -3
  203. package/dist/components/iconButton.jsx +9 -7
  204. package/dist/components/layout.d.ts +7 -1
  205. package/dist/components/layout.jsx +5 -2
  206. package/dist/components/menu.d.ts +21 -0
  207. package/dist/components/menu.jsx +27 -3
  208. package/dist/components/menuItem.d.ts +12 -2
  209. package/dist/components/menuItem.jsx +6 -5
  210. package/dist/components/message.d.ts +28 -0
  211. package/dist/components/message.jsx +25 -0
  212. package/dist/components/navigation.d.ts +9 -1
  213. package/dist/components/navigation.jsx +15 -3
  214. package/dist/components/paragraph.d.ts +3 -1
  215. package/dist/components/paragraph.jsx +2 -2
  216. package/dist/components/popover.d.ts +7 -1
  217. package/dist/components/popover.jsx +35 -9
  218. package/dist/components/radioGroup.d.ts +12 -1
  219. package/dist/components/radioGroup.jsx +20 -9
  220. package/dist/components/segmentedControl.d.ts +22 -0
  221. package/dist/components/segmentedControl.jsx +54 -0
  222. package/dist/components/select.d.ts +5 -1
  223. package/dist/components/select.jsx +2 -2
  224. package/dist/components/settingsSection.d.ts +31 -0
  225. package/dist/components/settingsSection.jsx +58 -0
  226. package/dist/components/slidingIndicator.d.ts +50 -0
  227. package/dist/components/slidingIndicator.jsx +102 -0
  228. package/dist/components/sourceCard.d.ts +23 -0
  229. package/dist/components/sourceCard.jsx +56 -0
  230. package/dist/components/stepList.d.ts +17 -0
  231. package/dist/components/stepList.jsx +79 -0
  232. package/dist/components/switch.d.ts +25 -0
  233. package/dist/components/switch.jsx +55 -0
  234. package/dist/components/tab.jsx +5 -11
  235. package/dist/components/tabsContainer.jsx +5 -67
  236. package/dist/components/tag.d.ts +9 -1
  237. package/dist/components/tag.jsx +6 -4
  238. package/dist/components/textField.d.ts +12 -2
  239. package/dist/components/textField.jsx +11 -4
  240. package/dist/components/textarea.d.ts +5 -1
  241. package/dist/components/textarea.jsx +6 -21
  242. package/dist/components/useHotkey.d.ts +7 -0
  243. package/dist/components/useHotkey.js +24 -0
  244. package/dist/components/userImage.d.ts +9 -1
  245. package/dist/components/userImage.jsx +10 -3
  246. package/dist/index.d.ts +6 -0
  247. package/dist/index.js +6 -0
  248. package/dist/internal/autoGrow.d.ts +11 -0
  249. package/dist/internal/autoGrow.js +28 -0
  250. package/dist/internal/composer.d.ts +16 -0
  251. package/dist/internal/composer.js +18 -0
  252. package/dist/internal/copyField.d.ts +5 -0
  253. package/dist/internal/copyField.js +61 -0
  254. package/dist/internal/hotkey.d.ts +16 -0
  255. package/dist/internal/hotkey.js +20 -0
  256. package/dist/internal/menu.d.ts +6 -0
  257. package/dist/internal/menu.js +31 -0
  258. package/dist/internal/switch.d.ts +5 -0
  259. package/dist/internal/switch.js +9 -0
  260. package/dist/native-mapping.json +62 -1
  261. package/dist/stories/Button.stories.d.ts +1 -0
  262. package/dist/stories/Button.stories.jsx +17 -1
  263. package/dist/stories/Cases.generated.stories.d.ts +53 -0
  264. package/dist/stories/Cases.generated.stories.jsx +106 -0
  265. package/dist/stories/Composer.stories.d.ts +23 -0
  266. package/dist/stories/Composer.stories.jsx +121 -0
  267. package/dist/stories/CopyField.stories.d.ts +11 -0
  268. package/dist/stories/CopyField.stories.jsx +65 -0
  269. package/dist/stories/FileChip.stories.d.ts +7 -0
  270. package/dist/stories/FileChip.stories.jsx +35 -0
  271. package/dist/stories/FormField.stories.d.ts +6 -0
  272. package/dist/stories/FormField.stories.jsx +44 -0
  273. package/dist/stories/IconButton.stories.d.ts +1 -0
  274. package/dist/stories/IconButton.stories.jsx +18 -1
  275. package/dist/stories/Menu.stories.d.ts +4 -0
  276. package/dist/stories/Menu.stories.jsx +46 -1
  277. package/dist/stories/MenuItem.stories.d.ts +1 -0
  278. package/dist/stories/MenuItem.stories.jsx +8 -0
  279. package/dist/stories/Message.stories.d.ts +10 -0
  280. package/dist/stories/Message.stories.jsx +77 -0
  281. package/dist/stories/Navigation.stories.d.ts +1 -0
  282. package/dist/stories/Navigation.stories.jsx +17 -1
  283. package/dist/stories/PageComponents.stories.d.ts +1 -0
  284. package/dist/stories/PageComponents.stories.jsx +21 -0
  285. package/dist/stories/RadioGroup.stories.d.ts +2 -0
  286. package/dist/stories/RadioGroup.stories.jsx +40 -1
  287. package/dist/stories/SegmentedControl.stories.d.ts +8 -0
  288. package/dist/stories/SegmentedControl.stories.jsx +33 -0
  289. package/dist/stories/SettingsSection.stories.d.ts +11 -0
  290. package/dist/stories/SettingsSection.stories.jsx +64 -0
  291. package/dist/stories/SourceCard.stories.d.ts +8 -0
  292. package/dist/stories/SourceCard.stories.jsx +33 -0
  293. package/dist/stories/StepList.stories.d.ts +8 -0
  294. package/dist/stories/StepList.stories.jsx +35 -0
  295. package/dist/stories/Switch.stories.d.ts +14 -0
  296. package/dist/stories/Switch.stories.jsx +87 -0
  297. package/dist/stories/TextField.stories.d.ts +1 -0
  298. package/dist/stories/TextField.stories.jsx +13 -0
  299. package/dist/stories/UserImage.stories.d.ts +2 -0
  300. package/dist/stories/UserImage.stories.jsx +19 -0
  301. package/package.json +8 -3
@@ -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
+ }
@@ -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
+ }