oneslash-design-system 2.14.2 → 2.16.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 (232) hide show
  1. package/README.md +15 -0
  2. package/dist/DESIGN.md +138 -1
  3. package/dist/cases/accept-invite/signed-in.d.ts +1 -0
  4. package/dist/cases/accept-invite/signed-in.jsx +57 -0
  5. package/dist/cases/accept-invite/signed-out.d.ts +1 -0
  6. package/dist/cases/accept-invite/signed-out.jsx +33 -0
  7. package/dist/cases/accept-invite.md +161 -0
  8. package/dist/cases/agent-asks-before-risky-action.md +29 -0
  9. package/dist/cases/agent-cancels-when-unanswered.md +27 -0
  10. package/dist/cases/agent-refuses-clearly.md +31 -0
  11. package/dist/cases/agent-says-what-it-is.md +29 -0
  12. package/dist/cases/agent-shows-progress.md +30 -0
  13. package/dist/cases/agent-shows-sources.md +26 -0
  14. package/dist/cases/auth-gate-loading/spinner-with-line.d.ts +1 -0
  15. package/dist/cases/auth-gate-loading/spinner-with-line.jsx +10 -0
  16. package/dist/cases/auth-gate-loading/spinner.d.ts +1 -0
  17. package/dist/cases/auth-gate-loading/spinner.jsx +10 -0
  18. package/dist/cases/auth-gate-loading.md +70 -0
  19. package/dist/cases/check-your-email/alert-on-login.d.ts +1 -0
  20. package/dist/cases/check-your-email/alert-on-login.jsx +78 -0
  21. package/dist/cases/check-your-email/page.d.ts +1 -0
  22. package/dist/cases/check-your-email/page.jsx +49 -0
  23. package/dist/cases/check-your-email.md +184 -0
  24. package/dist/cases/confirm-destructive-action/inline.d.ts +1 -0
  25. package/dist/cases/confirm-destructive-action/inline.jsx +69 -0
  26. package/dist/cases/confirm-destructive-action/modal.d.ts +1 -0
  27. package/dist/cases/confirm-destructive-action/modal.jsx +66 -0
  28. package/dist/cases/confirm-destructive-action.md +211 -0
  29. package/dist/cases/confirm-dialogs.md +36 -0
  30. package/dist/cases/create-modal/quick.d.ts +1 -0
  31. package/dist/cases/create-modal/quick.jsx +80 -0
  32. package/dist/cases/create-modal/with-settings.d.ts +1 -0
  33. package/dist/cases/create-modal/with-settings.jsx +99 -0
  34. package/dist/cases/create-modal.md +244 -0
  35. package/dist/cases/device-login/popup.d.ts +1 -0
  36. package/dist/cases/device-login/popup.jsx +14 -0
  37. package/dist/cases/device-login/provider-first.d.ts +1 -0
  38. package/dist/cases/device-login/provider-first.jsx +98 -0
  39. package/dist/cases/device-login.md +171 -0
  40. package/dist/cases/email-confirmed/alert-on-login.d.ts +1 -0
  41. package/dist/cases/email-confirmed/alert-on-login.jsx +78 -0
  42. package/dist/cases/email-confirmed/page.d.ts +1 -0
  43. package/dist/cases/email-confirmed/page.jsx +21 -0
  44. package/dist/cases/email-confirmed.md +151 -0
  45. package/dist/cases/empty-list/region.d.ts +1 -0
  46. package/dist/cases/empty-list/region.jsx +13 -0
  47. package/dist/cases/empty-list/section.d.ts +1 -0
  48. package/dist/cases/empty-list/section.jsx +17 -0
  49. package/dist/cases/empty-list.md +77 -0
  50. package/dist/cases/empty-lists.md +35 -0
  51. package/dist/cases/empty-not-set-up/action.d.ts +1 -0
  52. package/dist/cases/empty-not-set-up/action.jsx +16 -0
  53. package/dist/cases/empty-not-set-up/pointer.d.ts +1 -0
  54. package/dist/cases/empty-not-set-up/pointer.jsx +13 -0
  55. package/dist/cases/empty-not-set-up.md +88 -0
  56. package/dist/cases/empty-search/clear-search.d.ts +1 -0
  57. package/dist/cases/empty-search/clear-search.jsx +29 -0
  58. package/dist/cases/empty-search.md +77 -0
  59. package/dist/cases/error-page/full-page.d.ts +1 -0
  60. package/dist/cases/error-page/full-page.jsx +19 -0
  61. package/dist/cases/error-page/in-shell.d.ts +1 -0
  62. package/dist/cases/error-page/in-shell.jsx +39 -0
  63. package/dist/cases/error-page.md +107 -0
  64. package/dist/cases/feedback-form/modal.d.ts +1 -0
  65. package/dist/cases/feedback-form/modal.jsx +89 -0
  66. package/dist/cases/feedback-form.md +139 -0
  67. package/dist/cases/forgot-password/in-place.d.ts +1 -0
  68. package/dist/cases/forgot-password/in-place.jsx +155 -0
  69. package/dist/cases/forgot-password/own-page.d.ts +1 -0
  70. package/dist/cases/forgot-password/own-page.jsx +99 -0
  71. package/dist/cases/forgot-password.md +328 -0
  72. package/dist/cases/form-errors.md +32 -0
  73. package/dist/cases/import-checklist/modal.d.ts +1 -0
  74. package/dist/cases/import-checklist/modal.jsx +125 -0
  75. package/dist/cases/import-checklist.md +188 -0
  76. package/dist/cases/inline-form-feedback/button-label.d.ts +1 -0
  77. package/dist/cases/inline-form-feedback/button-label.jsx +54 -0
  78. package/dist/cases/inline-form-feedback/inline-alert.d.ts +1 -0
  79. package/dist/cases/inline-form-feedback/inline-alert.jsx +49 -0
  80. package/dist/cases/inline-form-feedback/toast.d.ts +1 -0
  81. package/dist/cases/inline-form-feedback/toast.jsx +66 -0
  82. package/dist/cases/inline-form-feedback.md +237 -0
  83. package/dist/cases/invite-member/by-email.d.ts +1 -0
  84. package/dist/cases/invite-member/by-email.jsx +98 -0
  85. package/dist/cases/invite-member/by-link.d.ts +1 -0
  86. package/dist/cases/invite-member/by-link.jsx +122 -0
  87. package/dist/cases/invite-member.md +321 -0
  88. package/dist/cases/load-failure/inline.d.ts +1 -0
  89. package/dist/cases/load-failure/inline.jsx +52 -0
  90. package/dist/cases/load-failure/region.d.ts +1 -0
  91. package/dist/cases/load-failure/region.jsx +34 -0
  92. package/dist/cases/load-failure.md +155 -0
  93. package/dist/cases/log-out-confirm/modal.d.ts +1 -0
  94. package/dist/cases/log-out-confirm/modal.jsx +57 -0
  95. package/dist/cases/log-out-confirm.md +106 -0
  96. package/dist/cases/login-page/centered.d.ts +1 -0
  97. package/dist/cases/login-page/centered.jsx +72 -0
  98. package/dist/cases/login-page/email-only.d.ts +1 -0
  99. package/dist/cases/login-page/email-only.jsx +59 -0
  100. package/dist/cases/login-page/provider-first.d.ts +1 -0
  101. package/dist/cases/login-page/provider-first.jsx +66 -0
  102. package/dist/cases/login-page/split.d.ts +1 -0
  103. package/dist/cases/login-page/split.jsx +79 -0
  104. package/dist/cases/login-page.md +373 -0
  105. package/dist/cases/not-found-page/full-page.d.ts +1 -0
  106. package/dist/cases/not-found-page/full-page.jsx +16 -0
  107. package/dist/cases/not-found-page/in-shell.d.ts +1 -0
  108. package/dist/cases/not-found-page/in-shell.jsx +36 -0
  109. package/dist/cases/not-found-page.md +98 -0
  110. package/dist/cases/oauth-consent/simple.d.ts +1 -0
  111. package/dist/cases/oauth-consent/simple.jsx +73 -0
  112. package/dist/cases/oauth-consent/with-scope.d.ts +1 -0
  113. package/dist/cases/oauth-consent/with-scope.jsx +89 -0
  114. package/dist/cases/oauth-consent.md +233 -0
  115. package/dist/cases/rename/inline.d.ts +1 -0
  116. package/dist/cases/rename/inline.jsx +58 -0
  117. package/dist/cases/rename/modal.d.ts +1 -0
  118. package/dist/cases/rename/modal.jsx +70 -0
  119. package/dist/cases/rename.md +205 -0
  120. package/dist/cases/route-loading/full-screen.d.ts +1 -0
  121. package/dist/cases/route-loading/full-screen.jsx +8 -0
  122. package/dist/cases/route-loading/region.d.ts +1 -0
  123. package/dist/cases/route-loading/region.jsx +26 -0
  124. package/dist/cases/route-loading.md +84 -0
  125. package/dist/cases/set-new-password/form.d.ts +1 -0
  126. package/dist/cases/set-new-password/form.jsx +130 -0
  127. package/dist/cases/set-new-password/invalid-link.d.ts +1 -0
  128. package/dist/cases/set-new-password/invalid-link.jsx +50 -0
  129. package/dist/cases/set-new-password.md +247 -0
  130. package/dist/cases/sign-up-page/centered.d.ts +1 -0
  131. package/dist/cases/sign-up-page/centered.jsx +124 -0
  132. package/dist/cases/sign-up-page/provider-first.d.ts +1 -0
  133. package/dist/cases/sign-up-page/provider-first.jsx +124 -0
  134. package/dist/cases/sign-up-page/split.d.ts +1 -0
  135. package/dist/cases/sign-up-page/split.jsx +134 -0
  136. package/dist/cases/sign-up-page.md +478 -0
  137. package/dist/cases/success-feedback.md +35 -0
  138. package/dist/cases/type-to-confirm/inline.d.ts +1 -0
  139. package/dist/cases/type-to-confirm/inline.jsx +69 -0
  140. package/dist/cases/type-to-confirm/modal.d.ts +1 -0
  141. package/dist/cases/type-to-confirm/modal.jsx +73 -0
  142. package/dist/cases/type-to-confirm.md +222 -0
  143. package/dist/cases/unsaved-changes-guard/discard.d.ts +1 -0
  144. package/dist/cases/unsaved-changes-guard/discard.jsx +81 -0
  145. package/dist/cases/unsaved-changes-guard/save-or-discard.d.ts +1 -0
  146. package/dist/cases/unsaved-changes-guard/save-or-discard.jsx +85 -0
  147. package/dist/cases/unsaved-changes-guard.md +239 -0
  148. package/dist/cases/upgrade-prompt/inline.d.ts +1 -0
  149. package/dist/cases/upgrade-prompt/inline.jsx +52 -0
  150. package/dist/cases/upgrade-prompt/modal.d.ts +1 -0
  151. package/dist/cases/upgrade-prompt/modal.jsx +43 -0
  152. package/dist/cases/upgrade-prompt.md +174 -0
  153. package/dist/cases.json +2073 -0
  154. package/dist/components/alert.d.ts +3 -1
  155. package/dist/components/alert.jsx +6 -4
  156. package/dist/components/brandIcon.d.ts +12 -0
  157. package/dist/components/brandIcon.jsx +24 -0
  158. package/dist/components/emptyBox.d.ts +6 -1
  159. package/dist/components/emptyBox.jsx +4 -2
  160. package/dist/components/form.d.ts +11 -0
  161. package/dist/components/form.jsx +22 -0
  162. package/dist/components/heading.d.ts +2 -2
  163. package/dist/components/image.d.ts +14 -0
  164. package/dist/components/image.jsx +6 -0
  165. package/dist/components/layout.d.ts +18 -1
  166. package/dist/components/layout.jsx +16 -0
  167. package/dist/components/line.d.ts +3 -1
  168. package/dist/components/line.jsx +8 -1
  169. package/dist/components/loadingScreen.d.ts +5 -1
  170. package/dist/components/loadingScreen.jsx +4 -2
  171. package/dist/components/modal.d.ts +2 -1
  172. package/dist/components/modal.jsx +20 -8
  173. package/dist/components/radioGroup.d.ts +2 -1
  174. package/dist/components/radioGroup.jsx +2 -2
  175. package/dist/components/select.d.ts +2 -1
  176. package/dist/components/select.jsx +4 -2
  177. package/dist/components/tab.jsx +3 -2
  178. package/dist/components/tabsContainer.d.ts +4 -1
  179. package/dist/components/tabsContainer.jsx +11 -5
  180. package/dist/components/textField.d.ts +5 -1
  181. package/dist/components/textField.jsx +7 -3
  182. package/dist/components/toaster.d.ts +12 -0
  183. package/dist/components/toaster.jsx +103 -0
  184. package/dist/components/tooltip.jsx +3 -1
  185. package/dist/designTokens.d.ts +1 -0
  186. package/dist/designTokens.js +1 -0
  187. package/dist/internal/alert.d.ts +4 -0
  188. package/dist/internal/alert.js +6 -0
  189. package/dist/internal/modal.d.ts +2 -0
  190. package/dist/internal/modal.js +21 -0
  191. package/dist/internal/toaster.d.ts +19 -0
  192. package/dist/internal/toaster.js +50 -0
  193. package/dist/native-mapping.json +23 -1
  194. package/dist/stories/Alert.stories.d.ts +1 -0
  195. package/dist/stories/Alert.stories.jsx +16 -0
  196. package/dist/stories/BrandIcon.stories.d.ts +9 -0
  197. package/dist/stories/BrandIcon.stories.jsx +19 -0
  198. package/dist/stories/Cases.generated.stories.d.ts +60 -0
  199. package/dist/stories/Cases.generated.stories.jsx +116 -0
  200. package/dist/stories/EmptyBox.stories.d.ts +2 -0
  201. package/dist/stories/EmptyBox.stories.jsx +16 -0
  202. package/dist/stories/Form.stories.d.ts +6 -0
  203. package/dist/stories/Form.stories.jsx +26 -0
  204. package/dist/stories/Heading.stories.d.ts +6 -0
  205. package/dist/stories/Heading.stories.jsx +10 -0
  206. package/dist/stories/Image.stories.d.ts +7 -0
  207. package/dist/stories/Image.stories.jsx +18 -0
  208. package/dist/stories/Line.stories.d.ts +1 -0
  209. package/dist/stories/Line.stories.jsx +12 -0
  210. package/dist/stories/LoadingScreen.stories.d.ts +1 -0
  211. package/dist/stories/LoadingScreen.stories.jsx +8 -0
  212. package/dist/stories/Modal.stories.d.ts +2 -0
  213. package/dist/stories/Modal.stories.jsx +36 -0
  214. package/dist/stories/PageComponents.stories.d.ts +2 -0
  215. package/dist/stories/PageComponents.stories.jsx +15 -1
  216. package/dist/stories/RadioGroup.stories.d.ts +1 -0
  217. package/dist/stories/RadioGroup.stories.jsx +14 -0
  218. package/dist/stories/Select.stories.d.ts +1 -0
  219. package/dist/stories/Select.stories.jsx +14 -0
  220. package/dist/stories/TabsContainer.stories.d.ts +1 -0
  221. package/dist/stories/TabsContainer.stories.jsx +12 -0
  222. package/dist/stories/TextField.stories.d.ts +2 -0
  223. package/dist/stories/TextField.stories.jsx +22 -0
  224. package/dist/stories/Toaster.stories.d.ts +6 -0
  225. package/dist/stories/Toaster.stories.jsx +29 -0
  226. package/dist/tailwind-preset-auto.js +2 -1
  227. package/dist/tailwind-preset.js +2 -1
  228. package/dist/theme-auto.css +1 -0
  229. package/dist/theme.css +1 -0
  230. package/dist/tokens.css +1 -0
  231. package/dist/tokens.json +7 -0
  232. package/package.json +4 -2
@@ -0,0 +1,222 @@
1
+ # Type to confirm
2
+
3
+ A person asks to delete something large that cannot be brought back, such as a workspace or an account.
4
+
5
+ **Not built yet:** Commentify matches its phrase with any case and ignores spaces around it, and labels its Button 'Deleting…' while it runs. Scindo labels its Button 'Deleting...' on the web and on Apple. On the web its Delete Workspace Modal shows a failed request as a red caption written by hand.
6
+
7
+ ## Do
8
+
9
+ - Ask for typing only when the loss is permanent and large, such as a workspace with everything in it, or an account.
10
+ - Ask the person to type the thing's name when it has one, and a fixed word such as DELETE when it does not.
11
+ - Put the text to type in the field's label: 'Type Acme Design to confirm'.
12
+ - Keep the action Button `state="disabled"` until the typed text matches exactly.
13
+ - Match with case: 'acme design' does not match 'Acme Design'. Allow pasting the text.
14
+ - Say above the field what is deleted and what is kept.
15
+
16
+ ## Don't
17
+
18
+ - Do not ask for typing for an everyday delete. A plain confirm is enough.
19
+ - Do not block pasting into the field.
20
+ - Do not change the action's label while it is loading, such as to 'Deleting…'.
21
+ - Do not show a failed request as a red caption written by hand. Use an inline error Alert.
22
+
23
+ ## Option: Type the name in a Modal
24
+
25
+ Use when: The action starts from a menu or a row, away from a settings page.
26
+
27
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `List`, `Modal`, `Paragraph`, `Stack`, `Surface`, `TextField`, `Toaster`, `dismissToast`, `toast`
28
+
29
+ ```tsx
30
+ 'use client';
31
+ import { useEffect, useRef, useState } from 'react';
32
+ import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
33
+ import Modal from 'oneslash-design-system/components/modal';
34
+ import Surface from 'oneslash-design-system/components/surface';
35
+ import Heading from 'oneslash-design-system/components/heading';
36
+ import Paragraph from 'oneslash-design-system/components/paragraph';
37
+ import List from 'oneslash-design-system/components/list';
38
+ import TextField from 'oneslash-design-system/components/textField';
39
+ import Button from 'oneslash-design-system/components/button';
40
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
41
+
42
+ const workspace = 'Acme Design';
43
+ const otherWorkspaces = ['Acme Marketing', 'Acme Support'];
44
+
45
+ export default function TypeToConfirmModal() {
46
+ // Opens on the confirm, as if the person just chose Delete Workspace.
47
+ const [open, setOpen] = useState(true);
48
+ const [typed, setTyped] = useState('');
49
+ const [deleting, setDeleting] = useState(false);
50
+ const [deleted, setDeleted] = useState(false);
51
+ const timer = useRef<ReturnType<typeof setTimeout>>();
52
+ const toastIds = useRef<string[]>([]);
53
+
54
+ // On unmount it stops the request and closes every toast it opened.
55
+ useEffect(() => () => {
56
+ clearTimeout(timer.current);
57
+ toastIds.current.forEach((id) => dismissToast(id));
58
+ toastIds.current = [];
59
+ }, []);
60
+
61
+ // An exact match, with case. Pasting the name is fine.
62
+ const matches = typed === workspace;
63
+
64
+ // Escape, a click outside and Cancel all close it, except while the request runs.
65
+ function handleClose() {
66
+ if (deleting) return;
67
+ setOpen(false);
68
+ setTyped('');
69
+ }
70
+
71
+ function handleDelete() {
72
+ if (deleting || !matches) return;
73
+ setDeleting(true);
74
+ // Stands in for the request to the server.
75
+ timer.current = setTimeout(() => {
76
+ setDeleting(false);
77
+ setOpen(false);
78
+ setDeleted(true);
79
+ toastIds.current.push(toast({ type: 'success', message: `Workspace '${workspace}' deleted.` }));
80
+ }, 1200);
81
+ }
82
+
83
+ return (
84
+ <Center width="page">
85
+ {/* A real app mounts one Toaster near its root. */}
86
+ <Toaster />
87
+ {deleted ? (
88
+ <Stack gap="large">
89
+ <Heading level={2} size="h5">Workspaces</Heading>
90
+ <Surface padding="large">
91
+ <List items={otherWorkspaces} size="body1" />
92
+ </Surface>
93
+ </Stack>
94
+ ) : (
95
+ <Stack gap="medium">
96
+ <Heading level={2} size="h5">{workspace}</Heading>
97
+ <Paragraph tone="secondary" size="body2" measure="none">6 members and 14 channels.</Paragraph>
98
+ <Cluster>
99
+ <Button size="small" type="secondary" color="danger" state="enabled" label="Delete Workspace" onClickButton={() => setOpen(true)} />
100
+ </Cluster>
101
+ </Stack>
102
+ )}
103
+ <Modal
104
+ isOpen={open}
105
+ size="small"
106
+ initialFocus="body"
107
+ title="Delete Workspace"
108
+ onClose={handleClose}
109
+ actions={
110
+ <>
111
+ <Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose} />
112
+ <Button size="small" type="primary" color="danger" state={matches ? 'enabled' : 'disabled'} label="Delete" loading={deleting} onClickButton={handleDelete} />
113
+ </>
114
+ }
115
+ >
116
+ <Paragraph measure="none">This deletes the workspace &apos;{workspace}&apos; with its 14 channels, tasks and messages. It cannot be undone.</Paragraph>
117
+ <Paragraph tone="secondary" size="body2" measure="none">Members keep their Acme accounts.</Paragraph>
118
+ <TextField id="type-to-confirm-name" label={`Type ${workspace} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />
119
+ </Modal>
120
+ </Center>
121
+ );
122
+ }
123
+ ```
124
+
125
+ ## Option: Type a word in place
126
+
127
+ Use when: The action lives in a danger zone on a settings page.
128
+
129
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `Paragraph`, `Stack`, `Surface`, `TextField`
130
+
131
+ ```tsx
132
+ 'use client';
133
+ import { useEffect, useRef, useState } from 'react';
134
+ import Surface from 'oneslash-design-system/components/surface';
135
+ import Heading from 'oneslash-design-system/components/heading';
136
+ import Paragraph from 'oneslash-design-system/components/paragraph';
137
+ import TextField from 'oneslash-design-system/components/textField';
138
+ import Button from 'oneslash-design-system/components/button';
139
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
140
+
141
+ // An account has no name to type, so the person types a fixed word.
142
+ const word = 'DELETE';
143
+
144
+ export default function TypeToConfirmInline() {
145
+ // Opens with the field showing, as if the person just chose Delete Account.
146
+ const [confirming, setConfirming] = useState(true);
147
+ const [typed, setTyped] = useState('');
148
+ const [deleting, setDeleting] = useState(false);
149
+ const [deleted, setDeleted] = useState(false);
150
+ const timer = useRef<ReturnType<typeof setTimeout>>();
151
+
152
+ // Stops the request if the example goes away before it ends.
153
+ useEffect(() => () => clearTimeout(timer.current), []);
154
+
155
+ // An exact match, with case. Pasting the word is fine.
156
+ const matches = typed === word;
157
+
158
+ function handleCancel() {
159
+ setConfirming(false);
160
+ setTyped('');
161
+ }
162
+
163
+ function handleDelete() {
164
+ if (deleting || !matches) return;
165
+ setDeleting(true);
166
+ // Stands in for the request to the server.
167
+ timer.current = setTimeout(() => {
168
+ setDeleting(false);
169
+ setDeleted(true);
170
+ }, 1200);
171
+ }
172
+
173
+ // The account is gone, so the page that showed it is gone too.
174
+ if (deleted) {
175
+ return (
176
+ <Center fill>
177
+ <Heading level={1} size="h5">Your account is deleted</Heading>
178
+ <Paragraph tone="secondary" measure="none">We sent a note to ada@example.com to say so.</Paragraph>
179
+ </Center>
180
+ );
181
+ }
182
+
183
+ return (
184
+ <Center width="page">
185
+ <Stack gap="xlarge">
186
+ <Heading level={1} size="h5">Account settings</Heading>
187
+ <Surface padding="large">
188
+ <Stack gap="medium">
189
+ <Heading level={2} size="h6">Profile</Heading>
190
+ <Paragraph size="body2" measure="none">Ada Brooks, ada@example.com</Paragraph>
191
+ </Stack>
192
+ </Surface>
193
+ <Surface padding="large">
194
+ <Stack gap="medium">
195
+ <Heading level={2} size="h6">Delete account</Heading>
196
+ <Paragraph size="body2" measure="none">This deletes your account, your private documents and your settings. It cannot be undone. Projects you shared stay with your team.</Paragraph>
197
+ {confirming ? (
198
+ <>
199
+ <TextField id="type-to-confirm-word" label={`Type ${word} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />
200
+ <Cluster gap="small">
201
+ <Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleCancel} />
202
+ <Button size="small" type="primary" color="danger" state={matches ? 'enabled' : 'disabled'} label="Delete Account" loading={deleting} onClickButton={handleDelete} />
203
+ </Cluster>
204
+ </>
205
+ ) : (
206
+ <Cluster>
207
+ <Button size="small" type="secondary" color="danger" state="enabled" label="Delete Account" onClickButton={() => setConfirming(true)} />
208
+ </Cluster>
209
+ )}
210
+ </Stack>
211
+ </Surface>
212
+ </Stack>
213
+ </Center>
214
+ );
215
+ }
216
+ ```
217
+
218
+ ## Native
219
+
220
+ On Apple use an `.alert` with a `TextField` in it. Put the action in the `.destructive` role and disable it until the text matches.
221
+
222
+ Seen in: Commentify, Scindo.
@@ -0,0 +1 @@
1
+ export default function UnsavedChangesDiscard(): import("react").JSX.Element;
@@ -0,0 +1,81 @@
1
+ 'use client';
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ import { useEffect, useRef, useState } from 'react';
12
+ import Modal from '../../components/modal';
13
+ import Surface from '../../components/surface';
14
+ import Heading from '../../components/heading';
15
+ import Paragraph from '../../components/paragraph';
16
+ import TextField from '../../components/textField';
17
+ import Button from '../../components/button';
18
+ import { Center, Cluster, Stack } from '../../components/layout';
19
+ export default function UnsavedChangesDiscard() {
20
+ var _a = useState([]), replies = _a[0], setReplies = _a[1];
21
+ var _b = useState(true), writing = _b[0], setWriting = _b[1];
22
+ var _c = useState('Friday works for me. I will move the review to Thursday.'), draft = _c[0], setDraft = _c[1];
23
+ // Opens on the question, as if the person just chose Cancel with a reply written.
24
+ var _d = useState(true), asking = _d[0], setAsking = _d[1];
25
+ var _e = useState(false), posting = _e[0], setPosting = _e[1];
26
+ var timer = useRef();
27
+ // Gives each posted reply its own key, even when two read the same.
28
+ var nextId = useRef(1);
29
+ // Stops the request if the example goes away before it ends.
30
+ useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
31
+ // With nothing written, Cancel closes at once.
32
+ function handleCancelReply() {
33
+ if (draft.trim())
34
+ setAsking(true);
35
+ else
36
+ setWriting(false);
37
+ }
38
+ function handleDiscard() {
39
+ setAsking(false);
40
+ setWriting(false);
41
+ setDraft('');
42
+ }
43
+ function handlePost() {
44
+ var text = draft.trim();
45
+ if (posting || !text)
46
+ return;
47
+ setPosting(true);
48
+ // Stands in for the request to the server.
49
+ timer.current = setTimeout(function () {
50
+ setPosting(false);
51
+ var id = nextId.current++;
52
+ setReplies(function (list) { return __spreadArray(__spreadArray([], list, true), [{ id: id, text: text }], false); });
53
+ setDraft('');
54
+ setWriting(false);
55
+ }, 1200);
56
+ }
57
+ return (<Center width="page">
58
+ <Surface padding="large">
59
+ <Stack gap="medium">
60
+ <Heading level={2} size="h6">Dana Lee</Heading>
61
+ <Paragraph size="body2" measure="none">Can we move the launch to Friday?</Paragraph>
62
+ {replies.map(function (reply) { return (<Paragraph key={reply.id} tone="secondary" size="body2" measure="none">You: {reply.text}</Paragraph>); })}
63
+ {writing ? (<>
64
+ <TextField id="unsaved-changes-guard-reply" label="Reply" multiline maxRows={3} value={draft} onChange={function (e) { return setDraft(e.target.value); }}/>
65
+ <Cluster gap="small">
66
+ <Button size="small" type="tertiary" state={posting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleCancelReply}/>
67
+ <Button size="small" type="primary" state={draft.trim() ? 'enabled' : 'disabled'} label="Reply" loading={posting} onClickButton={handlePost}/>
68
+ </Cluster>
69
+ </>) : (<Cluster>
70
+ <Button size="small" type="secondary" state="enabled" label="Reply" onClickButton={function () { return setWriting(true); }}/>
71
+ </Cluster>)}
72
+ </Stack>
73
+ </Surface>
74
+ <Modal isOpen={asking} size="small" title="Discard Reply" onClose={function () { return setAsking(false); }} actions={<>
75
+ <Button size="small" type="tertiary" state="enabled" label="Keep Editing" onClickButton={function () { return setAsking(false); }}/>
76
+ <Button size="small" type="primary" color="danger" state="enabled" label="Discard" onClickButton={handleDiscard}/>
77
+ </>}>
78
+ <Paragraph measure="none">Your reply to Dana is not posted. If you discard it, it is gone.</Paragraph>
79
+ </Modal>
80
+ </Center>);
81
+ }
@@ -0,0 +1 @@
1
+ export default function UnsavedChangesSaveOrDiscard(): import("react").JSX.Element;
@@ -0,0 +1,85 @@
1
+ 'use client';
2
+ import { useEffect, useRef, 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 { Center, Cluster, Stack } from '../../components/layout';
9
+ var savedText = 'Ship the new onboarding in October.';
10
+ export default function UnsavedChangesSaveOrDiscard() {
11
+ var _a = useState(savedText), saved = _a[0], setSaved = _a[1];
12
+ var _b = useState('Ship the new onboarding in October. Hire two designers by November.'), draft = _b[0], setDraft = _b[1];
13
+ var _c = useState(true), editorOpen = _c[0], setEditorOpen = _c[1];
14
+ // Opens on the question, as if the person just chose Close with changes not saved.
15
+ var _d = useState(true), asking = _d[0], setAsking = _d[1];
16
+ var _e = useState(false), saving = _e[0], setSaving = _e[1];
17
+ var timer = useRef();
18
+ // Stops the request if the example goes away before it ends.
19
+ useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
20
+ var changed = draft !== saved;
21
+ function handleOpenEditor() {
22
+ setDraft(saved);
23
+ setEditorOpen(true);
24
+ }
25
+ // With nothing changed, Close closes at once.
26
+ function handleCloseEditor() {
27
+ if (changed)
28
+ setAsking(true);
29
+ else
30
+ setEditorOpen(false);
31
+ }
32
+ // Escape, a click outside and Cancel all keep the person editing, except while the save runs.
33
+ function handleCancel() {
34
+ if (saving)
35
+ return;
36
+ setAsking(false);
37
+ }
38
+ function handleDontSave() {
39
+ if (saving)
40
+ return;
41
+ setAsking(false);
42
+ setEditorOpen(false);
43
+ }
44
+ function handleSave() {
45
+ if (saving)
46
+ return;
47
+ setSaving(true);
48
+ // Stands in for the request to the server.
49
+ timer.current = setTimeout(function () {
50
+ setSaving(false);
51
+ setSaved(draft);
52
+ setAsking(false);
53
+ setEditorOpen(false);
54
+ }, 1200);
55
+ }
56
+ if (!editorOpen) {
57
+ return (<Center width="page">
58
+ <Stack gap="medium">
59
+ <Heading level={1} size="h5">Documents</Heading>
60
+ <Paragraph size="body2" measure="none">Q3 plan: {saved}</Paragraph>
61
+ <Cluster>
62
+ <Button size="small" type="secondary" state="enabled" label="Open Q3 Plan" onClickButton={handleOpenEditor}/>
63
+ </Cluster>
64
+ </Stack>
65
+ </Center>);
66
+ }
67
+ return (<Center width="page">
68
+ <Stack gap="medium">
69
+ <Heading level={1} size="h5">Q3 plan</Heading>
70
+ <TextField id="unsaved-changes-guard-body" label="Plan" multiline maxRows={4} value={draft} onChange={function (e) { return setDraft(e.target.value); }}/>
71
+ <Cluster gap="small">
72
+ <Button size="small" type="tertiary" state="enabled" label="Close Draft" onClickButton={handleCloseEditor}/>
73
+ </Cluster>
74
+ </Stack>
75
+ <Modal isOpen={asking} size="small" title="Save Changes" onClose={handleCancel} actions={<>
76
+ {/* The safe choice first, the main action last, as in every confirm. */}
77
+ <Button size="small" type="tertiary" state={saving ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleCancel}/>
78
+ <Button size="small" type="secondary" state={saving ? 'disabled' : 'enabled'} label="Don't Save" onClickButton={handleDontSave}/>
79
+ <Button size="small" type="primary" state="enabled" label="Save" loading={saving} onClickButton={handleSave}/>
80
+ </>}>
81
+ <Paragraph measure="none">You changed &apos;Q3 plan&apos; and did not save it.</Paragraph>
82
+ <Paragraph tone="secondary" size="body2" measure="none">If you do not save, your changes are lost.</Paragraph>
83
+ </Modal>
84
+ </Center>);
85
+ }
@@ -0,0 +1,239 @@
1
+ # Unsaved changes
2
+
3
+ A person closes or leaves something they changed and did not save.
4
+
5
+ **Not built yet:** Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.
6
+
7
+ ## Do
8
+
9
+ - Ask only when there are changes. With nothing changed, close at once.
10
+ - Title the Modal with the action it offers, such as 'Save Changes' or 'Discard Reply', and name the thing in the body.
11
+ - Put 'Cancel' first, then 'Don't Save', then 'Save'. As in every confirm, the safe choice comes first and the main action last.
12
+ - Make 'Cancel' tertiary, 'Don't Save' secondary and 'Save' primary, all `size="small"`.
13
+ - Offer 'Keep Editing' and a danger 'Discard' when the product cannot save. 'Keep Editing' comes first.
14
+ - Disable 'Cancel' and 'Don't Save' while 'Save' runs, and leave only when the save works.
15
+
16
+ ## Don't
17
+
18
+ - Do not ask when nothing changed.
19
+ - Do not leave when the save fails. Keep the changes on screen.
20
+ - Do not label the choices 'Yes' and 'No'.
21
+ - Do not title the Modal 'Are you sure?'.
22
+
23
+ ## Option: Save or discard
24
+
25
+ Use when: The product can save the changes for the person, such as an edited document.
26
+
27
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `Modal`, `Paragraph`, `Stack`, `TextField`
28
+
29
+ ```tsx
30
+ 'use client';
31
+ import { useEffect, useRef, useState } from 'react';
32
+ import Modal from 'oneslash-design-system/components/modal';
33
+ import Heading from 'oneslash-design-system/components/heading';
34
+ import Paragraph from 'oneslash-design-system/components/paragraph';
35
+ import TextField from 'oneslash-design-system/components/textField';
36
+ import Button from 'oneslash-design-system/components/button';
37
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
38
+
39
+ const savedText = 'Ship the new onboarding in October.';
40
+
41
+ export default function UnsavedChangesSaveOrDiscard() {
42
+ const [saved, setSaved] = useState(savedText);
43
+ const [draft, setDraft] = useState('Ship the new onboarding in October. Hire two designers by November.');
44
+ const [editorOpen, setEditorOpen] = useState(true);
45
+ // Opens on the question, as if the person just chose Close with changes not saved.
46
+ const [asking, setAsking] = useState(true);
47
+ const [saving, setSaving] = useState(false);
48
+ const timer = useRef<ReturnType<typeof setTimeout>>();
49
+
50
+ // Stops the request if the example goes away before it ends.
51
+ useEffect(() => () => clearTimeout(timer.current), []);
52
+
53
+ const changed = draft !== saved;
54
+
55
+ function handleOpenEditor() {
56
+ setDraft(saved);
57
+ setEditorOpen(true);
58
+ }
59
+
60
+ // With nothing changed, Close closes at once.
61
+ function handleCloseEditor() {
62
+ if (changed) setAsking(true);
63
+ else setEditorOpen(false);
64
+ }
65
+
66
+ // Escape, a click outside and Cancel all keep the person editing, except while the save runs.
67
+ function handleCancel() {
68
+ if (saving) return;
69
+ setAsking(false);
70
+ }
71
+
72
+ function handleDontSave() {
73
+ if (saving) return;
74
+ setAsking(false);
75
+ setEditorOpen(false);
76
+ }
77
+
78
+ function handleSave() {
79
+ if (saving) return;
80
+ setSaving(true);
81
+ // Stands in for the request to the server.
82
+ timer.current = setTimeout(() => {
83
+ setSaving(false);
84
+ setSaved(draft);
85
+ setAsking(false);
86
+ setEditorOpen(false);
87
+ }, 1200);
88
+ }
89
+
90
+ if (!editorOpen) {
91
+ return (
92
+ <Center width="page">
93
+ <Stack gap="medium">
94
+ <Heading level={1} size="h5">Documents</Heading>
95
+ <Paragraph size="body2" measure="none">Q3 plan: {saved}</Paragraph>
96
+ <Cluster>
97
+ <Button size="small" type="secondary" state="enabled" label="Open Q3 Plan" onClickButton={handleOpenEditor} />
98
+ </Cluster>
99
+ </Stack>
100
+ </Center>
101
+ );
102
+ }
103
+
104
+ return (
105
+ <Center width="page">
106
+ <Stack gap="medium">
107
+ <Heading level={1} size="h5">Q3 plan</Heading>
108
+ <TextField id="unsaved-changes-guard-body" label="Plan" multiline maxRows={4} value={draft} onChange={(e) => setDraft(e.target.value)} />
109
+ <Cluster gap="small">
110
+ <Button size="small" type="tertiary" state="enabled" label="Close Draft" onClickButton={handleCloseEditor} />
111
+ </Cluster>
112
+ </Stack>
113
+ <Modal
114
+ isOpen={asking}
115
+ size="small"
116
+ title="Save Changes"
117
+ onClose={handleCancel}
118
+ actions={
119
+ <>
120
+ {/* The safe choice first, the main action last, as in every confirm. */}
121
+ <Button size="small" type="tertiary" state={saving ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleCancel} />
122
+ <Button size="small" type="secondary" state={saving ? 'disabled' : 'enabled'} label="Don't Save" onClickButton={handleDontSave} />
123
+ <Button size="small" type="primary" state="enabled" label="Save" loading={saving} onClickButton={handleSave} />
124
+ </>
125
+ }
126
+ >
127
+ <Paragraph measure="none">You changed &apos;Q3 plan&apos; and did not save it.</Paragraph>
128
+ <Paragraph tone="secondary" size="body2" measure="none">If you do not save, your changes are lost.</Paragraph>
129
+ </Modal>
130
+ </Center>
131
+ );
132
+ }
133
+ ```
134
+
135
+ ## Option: Discard or keep editing
136
+
137
+ Use when: The product cannot save for the person, such as a reply that only posts when they say so.
138
+
139
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `Modal`, `Paragraph`, `Stack`, `Surface`, `TextField`
140
+
141
+ ```tsx
142
+ 'use client';
143
+ import { useEffect, useRef, useState } from 'react';
144
+ import Modal from 'oneslash-design-system/components/modal';
145
+ import Surface from 'oneslash-design-system/components/surface';
146
+ import Heading from 'oneslash-design-system/components/heading';
147
+ import Paragraph from 'oneslash-design-system/components/paragraph';
148
+ import TextField from 'oneslash-design-system/components/textField';
149
+ import Button from 'oneslash-design-system/components/button';
150
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
151
+
152
+ export default function UnsavedChangesDiscard() {
153
+ const [replies, setReplies] = useState<{ id: number; text: string }[]>([]);
154
+ const [writing, setWriting] = useState(true);
155
+ const [draft, setDraft] = useState('Friday works for me. I will move the review to Thursday.');
156
+ // Opens on the question, as if the person just chose Cancel with a reply written.
157
+ const [asking, setAsking] = useState(true);
158
+ const [posting, setPosting] = useState(false);
159
+ const timer = useRef<ReturnType<typeof setTimeout>>();
160
+ // Gives each posted reply its own key, even when two read the same.
161
+ const nextId = useRef(1);
162
+
163
+ // Stops the request if the example goes away before it ends.
164
+ useEffect(() => () => clearTimeout(timer.current), []);
165
+
166
+ // With nothing written, Cancel closes at once.
167
+ function handleCancelReply() {
168
+ if (draft.trim()) setAsking(true);
169
+ else setWriting(false);
170
+ }
171
+
172
+ function handleDiscard() {
173
+ setAsking(false);
174
+ setWriting(false);
175
+ setDraft('');
176
+ }
177
+
178
+ function handlePost() {
179
+ const text = draft.trim();
180
+ if (posting || !text) return;
181
+ setPosting(true);
182
+ // Stands in for the request to the server.
183
+ timer.current = setTimeout(() => {
184
+ setPosting(false);
185
+ const id = nextId.current++;
186
+ setReplies((list) => [...list, { id, text }]);
187
+ setDraft('');
188
+ setWriting(false);
189
+ }, 1200);
190
+ }
191
+
192
+ return (
193
+ <Center width="page">
194
+ <Surface padding="large">
195
+ <Stack gap="medium">
196
+ <Heading level={2} size="h6">Dana Lee</Heading>
197
+ <Paragraph size="body2" measure="none">Can we move the launch to Friday?</Paragraph>
198
+ {replies.map((reply) => (
199
+ <Paragraph key={reply.id} tone="secondary" size="body2" measure="none">You: {reply.text}</Paragraph>
200
+ ))}
201
+ {writing ? (
202
+ <>
203
+ <TextField id="unsaved-changes-guard-reply" label="Reply" multiline maxRows={3} value={draft} onChange={(e) => setDraft(e.target.value)} />
204
+ <Cluster gap="small">
205
+ <Button size="small" type="tertiary" state={posting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleCancelReply} />
206
+ <Button size="small" type="primary" state={draft.trim() ? 'enabled' : 'disabled'} label="Reply" loading={posting} onClickButton={handlePost} />
207
+ </Cluster>
208
+ </>
209
+ ) : (
210
+ <Cluster>
211
+ <Button size="small" type="secondary" state="enabled" label="Reply" onClickButton={() => setWriting(true)} />
212
+ </Cluster>
213
+ )}
214
+ </Stack>
215
+ </Surface>
216
+ <Modal
217
+ isOpen={asking}
218
+ size="small"
219
+ title="Discard Reply"
220
+ onClose={() => setAsking(false)}
221
+ actions={
222
+ <>
223
+ <Button size="small" type="tertiary" state="enabled" label="Keep Editing" onClickButton={() => setAsking(false)} />
224
+ <Button size="small" type="primary" color="danger" state="enabled" label="Discard" onClickButton={handleDiscard} />
225
+ </>
226
+ }
227
+ >
228
+ <Paragraph measure="none">Your reply to Dana is not posted. If you discard it, it is gone.</Paragraph>
229
+ </Modal>
230
+ </Center>
231
+ );
232
+ }
233
+ ```
234
+
235
+ ## Native
236
+
237
+ On macOS a document window that closes with changes asks with the system alert: 'Save', 'Don't Save' and 'Cancel'. When the product cannot save, use a `confirmationDialog` with 'Discard' in the `.destructive` role and 'Keep Editing' in the `.cancel` role.
238
+
239
+ Seen in: Scindo.
@@ -0,0 +1 @@
1
+ export default function UpgradePromptInline(): import("react").JSX.Element;