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,2073 @@
1
+ {
2
+ "cases": [
3
+ {
4
+ "id": "accept-invite",
5
+ "title": "Invite link page",
6
+ "kind": "design",
7
+ "level": "page",
8
+ "area": "auth",
9
+ "situation": "A person opens an invite link to join a workspace.",
10
+ "do": [
11
+ "Name the workspace in a `Heading` with `level={1}`: \"You're invited to Acme Design\".",
12
+ "Say the role the person joins as.",
13
+ "Show who invited the person, 'Invited by Dana Lee', on every invite. It builds trust, and it is not secret.",
14
+ "Say which address the invite is for, masked, such as 'a***@example.com', only when the invite is tied to an address.",
15
+ "Offer 'Log In' as the primary Button and 'Sign Up' as the secondary one, and bring the person back to the invite after either.",
16
+ "Join with no screen when the invite is tied to the verified address of the person who is logged in, and land them in the workspace.",
17
+ "Show one screen with a 'Join Acme Design' Button when the invite is an open link and the person is logged in.",
18
+ "Name the account that will join on that screen, 'Joining as ada@example.com', with a text-only 'Not You? Switch Account'.",
19
+ "Show an expired link with a heading, one line and one Button: 'Invite link expired', 'Ask the person who invited you to send a new link.', 'Go Home'.",
20
+ "Show a link for another account with a heading, one line and one Button: 'This invite is for a different account', 'You are logged in as ada@example.com. This invite is for d***@example.com.', 'Switch Account'. Say the logged-in address in full and the invited one masked.",
21
+ "Show a full workspace with a heading, one line and one Button: 'This workspace is full', 'Ask an admin of Acme Design to make room.', 'Go Home'.",
22
+ "Show `LoadingScreen` with `label=\"Checking invite…\"` while the invite is checked, as in 'Login check loading'."
23
+ ],
24
+ "dont": [
25
+ "Do not show the invite to a person whose verified address it is tied to. Join and go on.",
26
+ "Do not show the full invited address to whoever holds the link.",
27
+ "Do not show the login form before the invite is checked.",
28
+ "Do not remember the invite before the person chooses to log in or sign up, so an old link does not take over a later login."
29
+ ],
30
+ "native": "On Apple, Scindo joins from a sheet with the invite link or code in a field. 'Cancel' and 'Join' sit in the toolbar. While it checks the invite, a small `ProgressView` sits beside a line naming the step.",
31
+ "notBuiltYet": "Scindo on the web labels its Buttons 'Log in' and 'Create account' in sentence case, and shows 'Please wait' under its spinner. Its wrong-account Button reads 'Sign out and switch accounts'.",
32
+ "seenIn": [
33
+ "Scindo"
34
+ ],
35
+ "options": [
36
+ {
37
+ "id": "signed-out",
38
+ "title": "Logged out",
39
+ "useWhen": "The person is not logged in.",
40
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so login and sign-up bring the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\nexport default function AcceptInviteSignedOut() {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n {/* 'Invited by' shows on every invite. */}\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* The address sentence shows only when the invite is tied to an address, and the address is masked: anyone who holds the link sees this page.\n An open link shows nothing in its place, only the workspace and the role: 'You will join as a member.' */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member. This invite is for a***@example.com, so log in or sign up with that address.</Paragraph>\n </Stack>\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => router.push(`/login?next=${next}`)} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Sign Up\" onClickButton={() => router.push(`/sign-up?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
41
+ "uses": [
42
+ "Button",
43
+ "Center",
44
+ "Cluster",
45
+ "Heading",
46
+ "Image",
47
+ "Paragraph",
48
+ "Stack",
49
+ "UserImage"
50
+ ]
51
+ },
52
+ {
53
+ "id": "signed-in",
54
+ "title": "Logged in, open link",
55
+ "useWhen": "The person is logged in and the link is open to anyone who has it.",
56
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The invite's own page, so switching accounts brings the person back here to join.\nconst next = encodeURIComponent('/invite/7f3k2q');\n\n// A real app passes the address of the account that is logged in.\nconst address = 'ada@example.com';\n\nexport default function AcceptInviteSignedIn() {\n const [joining, setJoining] = useState(false);\n const [joined, setJoined] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleJoin() {\n if (joining) return;\n setJoining(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setJoining(false);\n setJoined(true);\n }, 1200);\n }\n\n // Joined: a real app opens the workspace as soon as it can.\n if (joined) {\n return (\n <Center fill>\n <LoadingScreen label=\"Opening Acme Design…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re invited to Acme Design</Heading>\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" />\n <Paragraph size=\"body2\" measure=\"none\">Invited by Dana Lee</Paragraph>\n </Cluster>\n {/* An open link names no address, so the page shows only the workspace and the role. */}\n <Paragraph tone=\"secondary\" measure=\"none\">You will join as a member.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Joining as {address}</Paragraph>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Join Acme Design\" loading={joining} onClickButton={handleJoin} />\n <Button size=\"medium\" type=\"textOnly\" state={joining ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push(`/login?next=${next}`)} />\n </Stack>\n </Center>\n );\n}\n",
57
+ "uses": [
58
+ "Button",
59
+ "Center",
60
+ "Cluster",
61
+ "Heading",
62
+ "Image",
63
+ "LoadingScreen",
64
+ "Paragraph",
65
+ "Stack",
66
+ "UserImage"
67
+ ]
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "id": "agent-asks-before-risky-action",
73
+ "title": "An agent asks before a risky action",
74
+ "kind": "rule",
75
+ "level": "rule",
76
+ "area": "agent",
77
+ "situation": "The agent is about to do something that changes shared work or is hard to undo.",
78
+ "answer": "An action is risky when it changes shared work or is hard to undo. In a product that works with code, that includes opening or merging a pull request, deleting files, closing an issue and rolling back a release. Carrying out a plan of several changes is risky too. Before a risky action the agent stops and posts a card with the exact action: every step it will take, or the changes themselves, which the person can open. The agent does nothing until the person presses the approve button.",
79
+ "why": "A person can only approve what they can see, and an agent's mistake in shared work costs other people.",
80
+ "do": [
81
+ "List every step in the card, in the order the agent will do them.",
82
+ "Offer a way to see the full changes, such as a View Changes button, before the approve button is pressed.",
83
+ "Let the person edit the plan or cancel it, not only approve it.",
84
+ "Mark the card Approved or Cancelled once it is decided, and remove its buttons."
85
+ ],
86
+ "dont": [
87
+ "Do not carry out a risky action before the person approves it.",
88
+ "Do not replace the steps or the changes with a one-line summary.",
89
+ "Do not let the agent write the label of an approve or merge button.",
90
+ "Do not let a second click on a decided card approve or cancel it again."
91
+ ],
92
+ "notBuiltYet": "In Scindo the agent asks before carrying out a plan, opening a pull request and merging one. It does not yet ask before deleting files, closing an issue or rolling back a release.",
93
+ "seenIn": [
94
+ "Scindo"
95
+ ]
96
+ },
97
+ {
98
+ "id": "agent-cancels-when-unanswered",
99
+ "title": "An agent cancels and reports when nobody answers",
100
+ "kind": "rule",
101
+ "level": "rule",
102
+ "area": "agent",
103
+ "situation": "The agent has asked a question or proposed an action, and nobody answers.",
104
+ "answer": "The agent never takes silence as a yes: while a question or proposal waits, it does nothing that depends on the answer. Each product sets the waiting time and shows it on the waiting card. When the time is up, the agent cancels the request, marks the card Cancelled, and posts one line saying what it did not do. The agent may write a plan that lists the unanswered questions as open questions. It may not carry out anything that depends on an answer.",
105
+ "why": "An agent that acts on silence does work nobody approved, and one that waits forever leaves work stuck without saying so.",
106
+ "do": [
107
+ "Keep the card and its buttons open until someone answers or the request is cancelled.",
108
+ "Notify the person who asked when the agent needs their answer.",
109
+ "Mark the card Cancelled when a request is cancelled, and post one line on what was not done.",
110
+ "List questions asked before a plan that nobody answered as open questions in that plan."
111
+ ],
112
+ "dont": [
113
+ "Do not treat no answer as approval.",
114
+ "Do not cancel a request without saying so in the thread."
115
+ ],
116
+ "notBuiltYet": "No product cancels a waiting request on its own yet. In Scindo a request waits until a person answers, cancels or skips it, and the waiting time is not decided.",
117
+ "seenIn": [
118
+ "Scindo"
119
+ ]
120
+ },
121
+ {
122
+ "id": "agent-refuses-clearly",
123
+ "title": "An agent refuses clearly",
124
+ "kind": "rule",
125
+ "level": "rule",
126
+ "area": "agent",
127
+ "situation": "The product will not let the agent answer a request, for example because the workspace used all its agent replies for the month, reached its spending cap, or sent too many requests at once.",
128
+ "answer": "The refusal says in one plain sentence which limit was reached, and either who can change it or when to try again. A person who can lift the limit gets the one button that does it, such as Upgrade or Change Budget Cap. When an admin can lift the limit, everyone else is told to ask a workspace admin. A limit that passes with time says when to try again instead.",
129
+ "why": "A person who is refused needs to know why and what to do next, or they will just send the request again.",
130
+ "do": [
131
+ "Say which limit was reached, with the number when there is one: 'You've used all 50 AI agent responses this month.'",
132
+ "Say who can change it, or when to try again: 'Try again in a minute.'",
133
+ "Show the button that lifts the limit only to a person allowed to use it.",
134
+ "Let the person close the refusal without acting, with a button such as 'Not Now'."
135
+ ],
136
+ "dont": [
137
+ "Do not show a general error message for a refusal.",
138
+ "Do not show an Upgrade button to someone who cannot upgrade."
139
+ ],
140
+ "native": "On Apple the refusal is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page.",
141
+ "notBuiltYet": "Scindo on the web does not follow this yet: it shows the Upgrade button to everyone. Scindo's Apple app shows it only to admins.",
142
+ "seenIn": [
143
+ "Scindo"
144
+ ]
145
+ },
146
+ {
147
+ "id": "agent-says-what-it-is",
148
+ "title": "An agent says what it is",
149
+ "kind": "rule",
150
+ "level": "rule",
151
+ "area": "agent",
152
+ "situation": "The agent posts in a thread where people also write, or replies to a person.",
153
+ "answer": "Every agent message has marks no person's message has. It shows an icon avatar instead of a photo, and the agent's own name. When the product knows which model wrote the reply, it shows the model name in small text next to the time. An agent the workspace connects from outside gets a plain bot icon, not the product's logo.",
154
+ "why": "People must see at a glance whether a person or an agent wrote what they are reading, and whose agent it is.",
155
+ "do": [
156
+ "Show the agent with an icon avatar, never a photo or an initial.",
157
+ "Name the agent in the message header: its role or given name, or 'Agent' when it has none.",
158
+ "Show the model name next to the time when the product knows it.",
159
+ "Show the product's logo on the product's own agent and a plain bot icon on an agent from outside, so people see whose agent it is."
160
+ ],
161
+ "dont": [
162
+ "Do not show a photo for an agent, even when one is set.",
163
+ "Do not show the product's logo on an agent the product does not run."
164
+ ],
165
+ "native": "On Apple an 'Agent' label with a sparkles icon sits next to a named agent's name, and the app draws the agent's avatar itself.",
166
+ "seenIn": [
167
+ "Scindo"
168
+ ]
169
+ },
170
+ {
171
+ "id": "agent-shows-progress",
172
+ "title": "An agent shows its progress",
173
+ "kind": "rule",
174
+ "level": "rule",
175
+ "area": "agent",
176
+ "situation": "The agent is working on a request and its reply is not ready yet.",
177
+ "answer": "While it works, the agent shows a live row in the thread, where its reply will appear: its name, the model, the seconds so far, the steps it has finished with a check mark, and the step it is on now in plain words, such as 'Reading file'. A Stop button stays on that row for the whole run. When the run is stopped, the agent posts a short note that it stopped.",
178
+ "why": "A person waiting on an agent needs to know it is still working, what it is doing, and that they can stop it.",
179
+ "do": [
180
+ "Show the progress row in the thread, where the reply will appear.",
181
+ "Name the current step in plain words, such as 'Reading file' or 'Editing code'.",
182
+ "Keep finished steps in view, each with a check mark.",
183
+ "Keep a Stop button on the row for the whole run."
184
+ ],
185
+ "dont": [
186
+ "Do not show a spinner with no words.",
187
+ "Do not hide the Stop button while the agent writes its reply.",
188
+ "Do not say the agent stopped before the run has really ended."
189
+ ],
190
+ "native": "On Apple the Send button turns into Stop while the agent works, and the note reads 'Stopped.' only once the run has really ended.",
191
+ "seenIn": [
192
+ "Scindo"
193
+ ]
194
+ },
195
+ {
196
+ "id": "agent-shows-sources",
197
+ "title": "An agent shows its sources",
198
+ "kind": "rule",
199
+ "level": "rule",
200
+ "area": "agent",
201
+ "situation": "The agent answers from things it read: documents, files, chat, tasks, or a connected service such as a code host or a design tool.",
202
+ "answer": "Under the reply, the agent lists what it used. A small tag names the kinds of source, such as 'From Chat · Knowledge base', and one card per source shows its title, its kind and where it lives. Each card opens the source. A reply that used no sources shows no sources section.",
203
+ "why": "A person can check an answer only when they can open what it came from.",
204
+ "do": [
205
+ "Put the sources directly under the reply they support.",
206
+ "Show each source as a card with its title and where it lives, such as the space name or the date.",
207
+ "Make each card open the source itself, in the product or on the service it came from.",
208
+ "Show the first six sources and a 'Show N more' button for the rest."
209
+ ],
210
+ "dont": [
211
+ "Do not show a sources section when the reply used no sources.",
212
+ "Do not show source cards on a person's message.",
213
+ "Do not link a source card to any site other than the product or the service the source came from."
214
+ ],
215
+ "seenIn": [
216
+ "Scindo"
217
+ ]
218
+ },
219
+ {
220
+ "id": "auth-gate-loading",
221
+ "title": "Login check loading",
222
+ "kind": "design",
223
+ "level": "page",
224
+ "area": "auth",
225
+ "situation": "The app is checking whether the person is logged in, or running a step such as checking an invite, before it knows what to show.",
226
+ "do": [
227
+ "Show the spinner from the first render, before anything else, as `LoadingScreen` in `Center` with `fill`.",
228
+ "Replace the spinner with the page, or go to the login page, as soon as the check ends.",
229
+ "Show no text when the wait is normally under about a second.",
230
+ "Name the step in `LoadingScreen`'s `label` when it can take longer than about a second: `label=\"Checking invite…\"`.",
231
+ "Use the same screen as the full-screen spinner in 'Page loading': `LoadingScreen` alone in `Center` with `fill`."
232
+ ],
233
+ "dont": [
234
+ "Do not show the login form, or the page, before the check ends. It flashes and then goes away.",
235
+ "Do not write a line that names no step, such as 'Loading…' or 'Please wait'.",
236
+ "Do not put a line under a spinner whose wait is normally under about a second.",
237
+ "Do not put more than one line under the spinner, or write it in a separate Paragraph."
238
+ ],
239
+ "native": "On Apple use `ProgressView()` centered in the window, with a label only for a named step that can take longer.",
240
+ "notBuiltYet": "Scindo on the web shows 'Please wait' under the step while it checks an invite, and a small spinner instead of `LoadingScreen` while onboarding checks for a workspace.",
241
+ "seenIn": [
242
+ "Commentify admin",
243
+ "Scindo"
244
+ ],
245
+ "options": [
246
+ {
247
+ "id": "spinner",
248
+ "title": "Spinner",
249
+ "useWhen": "The wait is normally under about a second, such as reading the session.",
250
+ "source": "'use client';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// Shown while the app checks the session, before it knows whether to show the page or the login form.\n// A real app swaps it for the page, or goes to the login page, as soon as the check ends.\nexport default function AuthGateLoadingSpinner() {\n return (\n <Center fill>\n <LoadingScreen />\n </Center>\n );\n}\n",
251
+ "uses": [
252
+ "Center",
253
+ "LoadingScreen"
254
+ ]
255
+ },
256
+ {
257
+ "id": "spinner-with-line",
258
+ "title": "Spinner with a line",
259
+ "useWhen": "A named step can take longer than about a second, such as 'Checking invite…' or 'Joining workspace…'.",
260
+ "source": "'use client';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// Shown while a step that can take longer than a second runs, before the app knows where to send the person.\n// A real app swaps it for the next page as soon as the step ends.\nexport default function AuthGateLoadingSpinnerWithLine() {\n return (\n <Center fill>\n <LoadingScreen label=\"Checking invite…\" />\n </Center>\n );\n}\n",
261
+ "uses": [
262
+ "Center",
263
+ "LoadingScreen"
264
+ ]
265
+ }
266
+ ]
267
+ },
268
+ {
269
+ "id": "check-your-email",
270
+ "title": "Check your email",
271
+ "kind": "design",
272
+ "level": "page",
273
+ "area": "auth",
274
+ "situation": "A person signed up, and the product sent a link to confirm their email.",
275
+ "do": [
276
+ "Name the page 'Check your email' in a `Heading` with `level={1}`, with a `Mail` icon above it.",
277
+ "Say in one line which address the link went to, in words that are true whether or not it already had an account: 'We sent a link to ada@example.com. Open it to continue.'",
278
+ "Offer 'Send Again' and a text-only 'Back to Login'.",
279
+ "Show `loading` on 'Send Again' while it sends, then 'Sent' for 2 seconds.",
280
+ "Ignore 'Send Again' while it sends and while it reads 'Sent', so one click sends one email. Let the server limit how often it sends.",
281
+ "Put the success Alert above the login form with no close button and `autoDismiss={false}`: it says what to do next, so it stays until the person submits the form."
282
+ ],
283
+ "dont": [
284
+ "Do not leave the sign-up form on screen once the link is sent.",
285
+ "Do not say that an account was created, or that one already exists.",
286
+ "Do not make the person close the success Alert, and do not let it close on its own before they have read it.",
287
+ "Do not change 'Send Again' to 'Sending…' while it sends."
288
+ ],
289
+ "notBuiltYet": "Neither Commentify nor Scindo can send the email again from the check-your-email screen. Both show their success Alert above the login form with a close button, and it starts 'Account created.', even for an address that already had an account.",
290
+ "seenIn": [
291
+ "Commentify",
292
+ "Scindo"
293
+ ],
294
+ "options": [
295
+ {
296
+ "id": "page",
297
+ "title": "Page in place of the form",
298
+ "useWhen": "The person must leave for their inbox before they can go on.",
299
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app passes the address the person signed up with.\nconst address = 'ada@example.com';\n\nexport default function CheckYourEmailPage() {\n const [loading, setLoading] = useState(false);\n const [sent, setSent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!sent) return;\n const timer = setTimeout(() => setSent(false), 2000);\n return () => clearTimeout(timer);\n }, [sent]);\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (loading || sent) return;\n setLoading(true);\n // Stands in for the request to the server.\n // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'\n timer.current = setTimeout(() => {\n setLoading(false);\n setSent(true);\n }, 1200);\n }\n\n return (\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a link to {address}. Open it to continue.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={sent ? 'Sent' : 'Send Again'} loading={loading} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n );\n}\n",
300
+ "uses": [
301
+ "Button",
302
+ "Center",
303
+ "Heading",
304
+ "Icon",
305
+ "Paragraph",
306
+ "Stack"
307
+ ]
308
+ },
309
+ {
310
+ "id": "alert-on-login",
311
+ "title": "Alert above the login form",
312
+ "useWhen": "The product lets a person log in before they confirm their email.",
313
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function CheckYourEmailAlertOnLogin() {\n // Opens as the login page does right after sign-up. The words are the same whether or not the address\n // already had an account, so the page never says which.\n const [notice, setNotice] = useState('We sent a link to ada@example.com. Open it to continue, or log in below.');\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setNotice('');\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected={false} href=\"/sign-up\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Log in\" onSubmit={handleSubmit}>\n {/* It says what to do next, so it stays until the person submits the form: no close button, and it does not close on its own. */}\n {notice && <Alert type=\"success\" variant=\"inline\" message={notice} autoDismiss={false} />}\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"check-your-email-login-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"check-your-email-login-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Forgot Password?\" />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n}\n",
314
+ "uses": [
315
+ "Alert",
316
+ "BrandIcon",
317
+ "Button",
318
+ "Center",
319
+ "Form",
320
+ "Image",
321
+ "Line",
322
+ "Tab",
323
+ "TabsContainer",
324
+ "TextField"
325
+ ]
326
+ }
327
+ ]
328
+ },
329
+ {
330
+ "id": "confirm-destructive-action",
331
+ "title": "Delete confirm",
332
+ "kind": "design",
333
+ "level": "organism",
334
+ "area": "confirm",
335
+ "situation": "A person asks to delete or remove something, and it cannot be undone.",
336
+ "do": [
337
+ "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, 'Cancel' first, then the action with `color=\"danger\"`.",
338
+ "Name the thing and what goes with it: \"This deletes 'Q3 plan' and its 12 tasks.\"",
339
+ "Turn the row's Buttons into 'Cancel' and a danger 'Remove' in place for the inline confirm. The rest of the row stays as it is.",
340
+ "Give each row's Buttons an `aria-label` that starts with the visible label and names the thing, such as 'Remove Dana Lee' and 'Cancel removing Dana Lee'.",
341
+ "Name the thing in the label so a screen reader knows which row a Button acts on.",
342
+ "Keep one row confirming at a time. Starting a confirm on another row cancels the first.",
343
+ "Show a toast that names the thing once it is gone."
344
+ ],
345
+ "dont": [
346
+ "Do not ask for a confirm when the action is easy to undo.",
347
+ "Do not remove a row on the first click of its Button.",
348
+ "Do not open a Modal for a row in a long list when the inline confirm keeps the place.",
349
+ "Do not ask a question in place of the action, such as 'Are you sure?'."
350
+ ],
351
+ "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role and 'Cancel' in the `.cancel` role.",
352
+ "notBuiltYet": "Commentify's Delete project confirm is not danger-colored and asks a question in its body. Scindo on the web confirms removing a saved card in place, but asks 'Are you sure?' and labels its Buttons 'Confirm' and 'No'.",
353
+ "seenIn": [
354
+ "Commentify",
355
+ "Scindo"
356
+ ],
357
+ "options": [
358
+ {
359
+ "id": "modal",
360
+ "title": "Confirm in a Modal",
361
+ "useWhen": "The default, for any delete or remove that cannot be undone.",
362
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst otherProjects = ['Website refresh', 'Hiring plan', 'Office move'];\n\nexport default function ConfirmDestructiveActionModal() {\n // Opens on the confirm, as if the person just chose Delete Project.\n const [open, setOpen] = useState(true);\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (deleting) return;\n setOpen(false);\n }\n\n function handleDelete() {\n if (deleting) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setOpen(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: \"Project 'Q3 plan' deleted.\" }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Projects</Heading>\n <Surface padding=\"large\">\n <List items={otherProjects} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">Q3 plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Project\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n )}\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Delete Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={handleDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes &apos;Q3 plan&apos; and its 12 tasks.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Files attached to the tasks stay in Files.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
363
+ "uses": [
364
+ "Button",
365
+ "Center",
366
+ "Cluster",
367
+ "Heading",
368
+ "List",
369
+ "Modal",
370
+ "Paragraph",
371
+ "Stack",
372
+ "Surface",
373
+ "Toaster",
374
+ "dismissToast",
375
+ "toast"
376
+ ]
377
+ },
378
+ {
379
+ "id": "inline",
380
+ "title": "Confirm in the row",
381
+ "useWhen": "The action is on a row inside a dense list, and a Modal would lose the place.",
382
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst people = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@example.com', role: 'Admin' },\n { id: 'omar', name: 'Omar Haddad', email: 'omar@example.com', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@example.com', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@example.com', role: 'Guest' },\n { id: 'ada', name: 'Ada Brooks', email: 'ada@example.com', role: 'Member' },\n];\n\nexport default function ConfirmDestructiveActionInline() {\n const [members, setMembers] = useState(people);\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirming, setConfirming] = useState<string | null>('omar');\n const [removing, setRemoving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n function handleRemove(id: string, name: string) {\n if (removing) return;\n setRemoving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setRemoving(false);\n setConfirming(null);\n setMembers((list) => list.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `${name} removed from Acme Design.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={2} size=\"h5\">Members</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">People who can open Acme Design.</Paragraph>\n </Stack>\n <TableContainer>\n {members.map((m) => (\n <TableRow key={m.id}>\n <TableCell>{m.name}</TableCell>\n <TableCell>{m.email}</TableCell>\n <TableCell width=\"100px\">{m.role}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\">\n {confirming === m.id ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={removing ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirming(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={removing} onClickButton={() => handleRemove(m.id, m.name)} />\n </Cluster>\n ) : (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={removing ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => setConfirming(m.id)} />\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n </Center>\n );\n}\n",
383
+ "uses": [
384
+ "Button",
385
+ "Center",
386
+ "Cluster",
387
+ "Heading",
388
+ "Paragraph",
389
+ "Stack",
390
+ "TableCell",
391
+ "TableContainer",
392
+ "TableRow",
393
+ "Toaster",
394
+ "dismissToast",
395
+ "toast"
396
+ ]
397
+ }
398
+ ]
399
+ },
400
+ {
401
+ "id": "confirm-dialogs",
402
+ "title": "A confirm says exactly what will happen",
403
+ "kind": "rule",
404
+ "level": "rule",
405
+ "area": "confirm",
406
+ "situation": "An action a person takes themselves needs their yes before it happens. An action the agent wants to take follows the rule 'An agent asks before a risky action', a card in the conversation, not this one.",
407
+ "answer": "A confirm is a Modal with `size=\"small\"`. Its title names the action in Title Case, such as 'Delete Project'. The body says in one or two sentences what will happen and what is kept. Two Buttons sit in the Modal's `actions`. 'Cancel' comes first, a `<Button type=\"tertiary\" size=\"small\">`. Then comes the action, a `<Button type=\"primary\" size=\"small\">` labelled in Title Case with the same verb as the title. When the action destroys or removes something, the action Button also has `color=\"danger\"`. One case differs: 'Unsaved changes'. Its guard may have three Buttons, 'Cancel', \"Don't Save\" and 'Save', in that order. When it has two, its safe Button reads 'Keep Editing'. Escape and a click outside the Modal mean Cancel. While the request runs, the action Button is `loading` and keeps its label, and 'Cancel' is `state=\"disabled\"`. The Modal stays open. It still calls `onClose` on Escape or a click outside, and the page ignores that call until the request ends. If the request fails, the Modal stays open and shows an inline error Alert at the top of its body, as the rule 'A form error shows next to the problem' says. When the action works, the Modal closes. If the thing is still on screen, the change shows where it is. If the thing is gone, a toast names it, as the rule 'Success shows where the person is looking' says.",
408
+ "why": "A confirm is the last chance to stop a mistake. It has to say exactly what will happen, and the safe choice has to be easy to find.",
409
+ "do": [
410
+ "Name the thing in the body: \"This deletes 'Q3 plan' and its 12 tasks.\"",
411
+ "Say what is kept: 'Files in the repository are not changed.'",
412
+ "Give the title and the action the same verb, in Title Case: 'Delete Project' has a 'Delete' Button.",
413
+ "Disable 'Cancel' and ignore `onClose` while the request runs.",
414
+ "Close the Modal when the action works. Show the change where the thing is, or a toast that names it if the thing is gone."
415
+ ],
416
+ "dont": [
417
+ "Do not label Cancel 'No' or 'Close'.",
418
+ "Do not label the action 'Yes, Delete', 'Confirm' or 'OK'.",
419
+ "Do not title the Modal 'Confirm Deletion' or 'Sure?'.",
420
+ "Do not change the action's label while it is loading, such as to 'Deleting…'.",
421
+ "Do not replace the Modal body with a spinner, or close the Modal, while the request runs.",
422
+ "Do not ask for a confirm when the action is easy to undo."
423
+ ],
424
+ "native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm.",
425
+ "notBuiltYet": "No Commentify confirm Modal uses `color=\"danger\"`, and two of them label Cancel 'No'. Scindo on the web makes Cancel a secondary Button in some confirms and a tertiary one in others. It leaves its Delete Task and Remove Member confirms uncolored. Scindo on the web revokes an API key, and Commentify revokes an agent client, with no confirm.",
426
+ "seenIn": [
427
+ "Commentify",
428
+ "Scindo"
429
+ ]
430
+ },
431
+ {
432
+ "id": "create-modal",
433
+ "title": "Create modal",
434
+ "kind": "design",
435
+ "level": "organism",
436
+ "area": "confirm",
437
+ "situation": "A person creates something new, such as a project or a task, and it needs a name before it exists.",
438
+ "do": [
439
+ "Title the Modal 'Create' and the thing, such as 'Create Project', and give its action the same verb: 'Create'.",
440
+ "Put 'Cancel' first, a tertiary Button, then 'Create', a primary Button, in the Modal's `actions`.",
441
+ "Create on Enter too: put the fields in a `Form`.",
442
+ "Keep 'Create' `state=\"disabled\"` while the name is empty.",
443
+ "Show `loading` on 'Create' while it runs, and keep the fields on screen with what the person typed.",
444
+ "Disable the fields while it runs, where the part allows it: the `TextField` and the `Checkbox`.",
445
+ "Focus the name field when the Modal opens, with `initialFocus=\"body\"`.",
446
+ "Give a `RadioGroup` a line of text above it and an `aria-label` with the same words.",
447
+ "Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
448
+ "Pick a safe default for every choice, so the person only has to type the name.",
449
+ "Close the Modal when it works and show the new thing where it lives."
450
+ ],
451
+ "dont": [
452
+ "Do not replace the fields with a spinner while it creates.",
453
+ "Do not change the label while it is loading, such as to 'Creating…'.",
454
+ "Do not ask for more than the thing needs to exist. Everything else goes in its settings.",
455
+ "Do not show a toast when the new thing is on screen. It shows where it lives."
456
+ ],
457
+ "native": "On Apple use a sheet with a `Form`. Put 'Cancel' in the `.cancellationAction` placement and 'Create' in `.confirmationAction`, and create on `.onSubmit` from the name field.",
458
+ "notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates a workspace or a task, and makes Cancel a secondary Button. Scindo's Apple app labels the Button 'Creating...' while it runs.",
459
+ "seenIn": [
460
+ "Scindo"
461
+ ],
462
+ "options": [
463
+ {
464
+ "id": "quick",
465
+ "title": "Just a name",
466
+ "useWhen": "One name is enough. Everything else can be set later.",
467
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function CreateModalQuick() {\n const [projects, setProjects] = useState(['Website refresh', 'Hiring plan', 'Office move']);\n // Opens on the Modal, as if the person just chose Create Project.\n const [open, setOpen] = useState(true);\n const [name, setName] = useState('Q4 budget');\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = name.trim();\n\n function handleOpen() {\n setName('');\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (creating) return;\n setOpen(false);\n }\n\n function handleCreate() {\n if (creating || next === '') return;\n setNameError('');\n setCreating(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCreating(false);\n // The server already has these names. Type one to see the request fail.\n if (projects.some((p) => p.toLowerCase() === next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setProjects((list) => [next, ...list]);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster>\n <Heading level={1} size=\"h5\">Projects</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Project\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n {/* The new project shows at the top of the list, so no toast is needed. */}\n <Surface padding=\"large\">\n <List items={projects} size=\"body1\" />\n </Surface>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Create Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={next === '' ? 'disabled' : 'enabled'} label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n }\n >\n {/* The Form lets Enter in the field create too. */}\n <Form aria-label=\"Create project\" onSubmit={handleCreate}>\n <TextField id=\"create-modal-name\" label=\"Project name\" placeholder=\"Q4 budget\" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
468
+ "uses": [
469
+ "Button",
470
+ "Center",
471
+ "Cluster",
472
+ "Form",
473
+ "Heading",
474
+ "List",
475
+ "Modal",
476
+ "Stack",
477
+ "Surface",
478
+ "TextField"
479
+ ]
480
+ },
481
+ {
482
+ "id": "with-settings",
483
+ "title": "A name and a few choices",
484
+ "useWhen": "The thing needs two or three choices up front, such as who can see it.",
485
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst visibilityOptions = [\n { value: 'workspace', label: 'Everyone in Acme Design', secondLabel: 'Anyone in the workspace can find and open it.' },\n { value: 'private', label: 'Only people you invite', secondLabel: 'It stays hidden until you add people.' },\n];\n\nexport default function CreateModalWithSettings() {\n const [projects, setProjects] = useState(['Website refresh', 'Hiring plan', 'Office move']);\n // Opens on the Modal, as if the person just chose Create Project.\n const [open, setOpen] = useState(true);\n const [name, setName] = useState('Q4 budget');\n // Safe defaults, so the name is the only thing the person has to give.\n const [visibility, setVisibility] = useState('workspace');\n const [starterTasks, setStarterTasks] = useState(true);\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = name.trim();\n\n function handleOpen() {\n setName('');\n setVisibility('workspace');\n setStarterTasks(true);\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (creating) return;\n setOpen(false);\n }\n\n function handleCreate() {\n if (creating || next === '') return;\n setNameError('');\n setCreating(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCreating(false);\n // The server already has these names. Type one to see the request fail.\n if (projects.some((p) => p.toLowerCase() === next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setProjects((list) => [next, ...list]);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster>\n <Heading level={1} size=\"h5\">Projects</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Project\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n {/* The new project shows at the top of the list, so no toast is needed. */}\n <Surface padding=\"large\">\n <List items={projects} size=\"body1\" />\n </Surface>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Create Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={next === '' ? 'disabled' : 'enabled'} label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n }\n >\n {/* The Form lets Enter in the name field create too. */}\n <Form aria-label=\"Create project\" onSubmit={handleCreate}>\n <TextField id=\"create-modal-settings-name\" label=\"Project name\" placeholder=\"Q4 budget\" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n <Stack gap=\"small\">\n {/* The line above names the choice on screen, and `aria-label` names it for a screen reader.\n RadioGroup has no disabled state, so it stays live while the request runs. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Who can see it</Paragraph>\n <RadioGroup aria-label=\"Who can see it\" options={visibilityOptions} selectedValue={visibility} onChange={setVisibility} />\n </Stack>\n <Checkbox label=\"Add starter tasks\" secondLabel=\"A short list to plan the first week. You can delete them.\" checked={starterTasks} disabled={creating} onChange={setStarterTasks} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
486
+ "uses": [
487
+ "Button",
488
+ "Center",
489
+ "Checkbox",
490
+ "Cluster",
491
+ "Form",
492
+ "Heading",
493
+ "List",
494
+ "Modal",
495
+ "Paragraph",
496
+ "RadioGroup",
497
+ "Stack",
498
+ "Surface",
499
+ "TextField"
500
+ ]
501
+ }
502
+ ]
503
+ },
504
+ {
505
+ "id": "device-login",
506
+ "title": "Device login",
507
+ "kind": "design",
508
+ "level": "page",
509
+ "area": "auth",
510
+ "situation": "A CLI, an editor or another app opened the browser so the person can log in, and the login must reach that app.",
511
+ "do": [
512
+ "Say in one line what the login connects: 'This connects Acme CLI on your computer to your account.'",
513
+ "Put the providers on top, then a `Line` with `label=\"or\"`, then email and password, as on the 'Login page' with providers first.",
514
+ "Wait for the device to answer before showing success, with `LoadingScreen` and `label=\"Waiting for Acme CLI…\"`.",
515
+ "End on \"You're logged in\" and 'You can close this tab.' once the device has answered.",
516
+ "Go back to the form with an inline error Alert when the device does not answer, and say what to check.",
517
+ "Show `LoadingScreen` with `label=\"Finishing login…\"` while a popup finishes, and close the popup when the page that opened it answers.",
518
+ "Finish the login in this tab after about 2 seconds when no page that opened the popup answers.",
519
+ "Show 'Done. You can close this window.' when the browser keeps the popup open."
520
+ ],
521
+ "dont": [
522
+ "Do not show success before the device answers.",
523
+ "Do not leave a popup blank while it finishes.",
524
+ "Do not label a provider Button with its name alone, such as 'Google'. Write 'Continue with Google'."
525
+ ],
526
+ "notBuiltYet": "Scindo's CLI login shows 'Login successful!' as soon as its request to the CLI gets any reply. It sends that request in a way that leaves the page unable to read the CLI's reply, so it cannot tell whether the CLI took the login. Its provider Buttons read 'GitHub' and 'Google'. Commentify's popup shows nothing while it finishes.",
527
+ "seenIn": [
528
+ "Commentify",
529
+ "Scindo"
530
+ ],
531
+ "options": [
532
+ {
533
+ "id": "provider-first",
534
+ "title": "Login page for a device",
535
+ "useWhen": "A CLI or an editor opened a browser tab; most people log in with a provider and email is the fallback.",
536
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function DeviceLoginProviderFirst() {\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n // 'form', then 'waiting' for the device to answer, then 'done'.\n const [step, setStep] = useState<'form' | 'waiting' | 'done'>('form');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the requests if the example goes away before they end.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n // A refused login calls setError instead: 'That email and password do not match.'\n timer.current = setTimeout(() => {\n setLoading(false);\n setStep('waiting');\n // Stands in for the request to the server.\n // This one hands the login to Acme CLI and waits for it to answer that it has it.\n // If it does not answer, go back to the form with setStep('form') and\n // setError('Acme CLI did not answer. Make sure acme login is still running, then try again.').\n timer.current = setTimeout(() => setStep('done'), 1200);\n }, 1200);\n }\n\n // Success shows only after the device has answered.\n if (step === 'done') {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">You&apos;re logged in</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">You can close this tab.</Paragraph>\n </Stack>\n </Center>\n );\n }\n\n if (step === 'waiting') {\n return (\n <Center fill>\n <LoadingScreen label=\"Waiting for Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Log in to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This connects Acme CLI on your computer to your account.</Paragraph>\n </Stack>\n {/* A real app sends the person to the provider, which brings them back to this page to hand the login to Acme CLI. */}\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={loading ? 'disabled' : 'enabled'} label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n <Button size=\"medium\" type=\"secondary\" state={loading ? 'disabled' : 'enabled'} label=\"Continue with GitHub\" decoIcon={<BrandIcon name=\"github\" />} />\n </Stack>\n <Line label=\"or\" />\n <Form aria-label=\"Log in with email\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"device-login-provider-first-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"device-login-provider-first-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Forgot Password?\" />\n </Form>\n </Center>\n );\n}\n",
537
+ "uses": [
538
+ "Alert",
539
+ "BrandIcon",
540
+ "Button",
541
+ "Center",
542
+ "Form",
543
+ "Heading",
544
+ "Image",
545
+ "Line",
546
+ "LoadingScreen",
547
+ "Paragraph",
548
+ "Stack",
549
+ "TextField"
550
+ ]
551
+ },
552
+ {
553
+ "id": "popup",
554
+ "title": "Popup that closes itself",
555
+ "useWhen": "A page opened a popup for the login, and the popup closes once the page has the login.",
556
+ "source": "'use client';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// The page the provider sends the popup back to. It finishes the login, tells the page\n// that opened it, and closes itself with window.close() once that page answers.\n// It stays on this state: the login does not finish by itself.\n// If the browser keeps the popup open after window.close(), the page shows one line\n// in place of the spinner: 'Done. You can close this window.'\n// If no page answers after about 2 seconds, the login ran in this tab, so the page finishes it here.\nexport default function DeviceLoginPopup() {\n return (\n <Center fill>\n <LoadingScreen label=\"Finishing login…\" />\n </Center>\n );\n}\n",
557
+ "uses": [
558
+ "Center",
559
+ "LoadingScreen"
560
+ ]
561
+ }
562
+ ]
563
+ },
564
+ {
565
+ "id": "email-confirmed",
566
+ "title": "Email confirmed",
567
+ "kind": "design",
568
+ "level": "page",
569
+ "area": "auth",
570
+ "situation": "A person opened the link that confirms their email.",
571
+ "do": [
572
+ "Name the page 'Email confirmed' in a `Heading` with `level={1}`.",
573
+ "Say in one line that the person can close the tab or go on here.",
574
+ "Offer one Button, 'Continue', to where the person was going.",
575
+ "Put the success Alert above the login form with no close button and `autoDismiss={false}`: 'Your email is confirmed. Log in to continue.' It stays until the person submits the form."
576
+ ],
577
+ "dont": [
578
+ "Do not ask the person to log in again in the browser where they are already logged in.",
579
+ "Do not make the person close the success Alert."
580
+ ],
581
+ "notBuiltYet": "Scindo on the web shows its success Alert above the login form with a close button. Commentify has no confirmed page and no Alert for it: the link goes straight to the dashboard.",
582
+ "seenIn": [
583
+ "Commentify",
584
+ "Scindo"
585
+ ],
586
+ "options": [
587
+ {
588
+ "id": "page",
589
+ "title": "Confirmed page",
590
+ "useWhen": "The link opened a new tab in the browser where the person is logged in.",
591
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function EmailConfirmedPage() {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Email confirmed</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">You can close this tab and go back to Acme, or continue here.</Paragraph>\n </Stack>\n {/* A real app sends the person on to where they were going, such as an invite they opened before signing up. */}\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Continue\" onClickButton={() => router.push('/')} />\n </Center>\n );\n}\n",
592
+ "uses": [
593
+ "Button",
594
+ "Center",
595
+ "Heading",
596
+ "Image",
597
+ "Paragraph",
598
+ "Stack"
599
+ ]
600
+ },
601
+ {
602
+ "id": "alert-on-login",
603
+ "title": "Alert above the login form",
604
+ "useWhen": "The link opened in another browser, so the person must log in.",
605
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function EmailConfirmedAlertOnLogin() {\n // Opens as the login page does when the link was opened in another browser.\n const [notice, setNotice] = useState('Your email is confirmed. Log in to continue.');\n // This browser does not know the address yet, so the field starts empty.\n const [email, setEmail] = useState('');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setNotice('');\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected={false} href=\"/sign-up\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Log in\" onSubmit={handleSubmit}>\n {/* It says what to do next, so it stays until the person submits the form: no close button, and it does not close on its own. */}\n {notice && <Alert type=\"success\" variant=\"inline\" message={notice} autoDismiss={false} />}\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"email-confirmed-login-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"email-confirmed-login-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Forgot Password?\" />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n}\n",
606
+ "uses": [
607
+ "Alert",
608
+ "BrandIcon",
609
+ "Button",
610
+ "Center",
611
+ "Form",
612
+ "Image",
613
+ "Line",
614
+ "Tab",
615
+ "TabsContainer",
616
+ "TextField"
617
+ ]
618
+ }
619
+ ]
620
+ },
621
+ {
622
+ "id": "empty-list",
623
+ "title": "Empty list",
624
+ "kind": "design",
625
+ "level": "organism",
626
+ "area": "state",
627
+ "situation": "A list has loaded, and there is nothing in it yet.",
628
+ "do": [
629
+ "Use `size=\"large\"` when the list is the whole pane, and `size=\"small\"` inside a section.",
630
+ "Say what is empty in the person's words: 'No archived projects'.",
631
+ "Say in `secondText` what will appear here: 'Projects you archive appear here.'"
632
+ ],
633
+ "dont": [
634
+ "Do not show a bare line of text, or nothing at all.",
635
+ "Do not use the system's words, such as 'No data' or 'No items found'.",
636
+ "Do not show the empty text while the list is still loading."
637
+ ],
638
+ "native": "On Apple use `ContentUnavailableView`, with the same words.",
639
+ "notBuiltYet": "Commentify writes most of its empty lists in Title Case, such as 'No Comments Available', and gives them no `secondText`.",
640
+ "seenIn": [
641
+ "Commentify",
642
+ "Scindo"
643
+ ],
644
+ "options": [
645
+ {
646
+ "id": "region",
647
+ "title": "Whole pane",
648
+ "useWhen": "The list is the whole pane, such as a page of projects.",
649
+ "source": "'use client';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function EmptyListRegion() {\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Archive</Heading>\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox size=\"large\" text=\"No archived projects\" secondText=\"Projects you archive appear here.\" />\n </Surface>\n </Stack>\n );\n}\n",
650
+ "uses": [
651
+ "EmptyBox",
652
+ "Heading",
653
+ "Stack",
654
+ "Surface"
655
+ ]
656
+ },
657
+ {
658
+ "id": "section",
659
+ "title": "Inside a section",
660
+ "useWhen": "The list sits inside a settings section or a card, next to other things.",
661
+ "source": "'use client';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function EmptyListSection() {\n return (\n <Center width=\"page\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Logged-in devices</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Devices where you are logged in to Acme, other than this one.</Paragraph>\n <EmptyBox size=\"small\" text=\"No other devices\" secondText=\"Devices you log in on appear here.\" />\n </Stack>\n </Surface>\n </Center>\n );\n}\n",
662
+ "uses": [
663
+ "Center",
664
+ "EmptyBox",
665
+ "Heading",
666
+ "Paragraph",
667
+ "Stack",
668
+ "Surface"
669
+ ]
670
+ }
671
+ ]
672
+ },
673
+ {
674
+ "id": "empty-lists",
675
+ "title": "An empty list says what will fill it",
676
+ "kind": "rule",
677
+ "level": "rule",
678
+ "area": "state",
679
+ "situation": "A list, table or pane has nothing to show.",
680
+ "answer": "Use `EmptyBox`, never a bare line of text. Its `size` is `large` when the list fills the whole region and `small` inside a section. The `text` says what is empty, in the person's words and in sentence case: 'No saved comments'. The `secondText` says what will appear here or what to do. When the person can fix it, pass the Button as `action`. The action Button is primary when it fills the list or tries again, and secondary when it is 'Clear Search'. An empty search shows the words searched for and a 'Clear Search' Button. A failed load is not an empty list: say that loading failed and offer a 'Try Again' Button. `EmptyBox` may hold that message, with 'Try Again' as its `action`, but never the empty text.",
681
+ "why": "An empty space looks like something is broken. Saying what is missing and what will fill it tells the person nothing is wrong and what to do next.",
682
+ "do": [
683
+ "Say what is empty in the person's words: 'No saved comments'.",
684
+ "Say in `secondText` what will appear here or what to do: 'Comments you save appear here.'",
685
+ "Pass the Button that fills the list as `action`, such as 'Create Project'.",
686
+ "Make the action Button primary when it fills the list or tries again, and secondary for 'Clear Search'.",
687
+ "Show the words searched for and a 'Clear Search' Button when a search finds nothing.",
688
+ "Say that loading failed and offer a 'Try Again' Button when the list could not load."
689
+ ],
690
+ "dont": [
691
+ "Do not show a bare line of text, or nothing at all, when a list is empty.",
692
+ "Do not show the empty text when the list failed to load.",
693
+ "Do not use the system's words, such as 'No data' or 'No records found'.",
694
+ "Do not pass an `action` the person is not allowed to use."
695
+ ],
696
+ "native": "On Apple use `ContentUnavailableView`, with the same words.",
697
+ "notBuiltYet": "Scindo on the web uses `EmptyBox` in three places and bare text elsewhere, such as 'No API keys yet.' Commentify uses `EmptyBox` in most lists and bare text in a few. Commentify admin and jinhwankim.com show bare text. No product passes an `action` yet.",
698
+ "seenIn": [
699
+ "Commentify",
700
+ "Commentify admin",
701
+ "Scindo",
702
+ "jinhwankim.com"
703
+ ]
704
+ },
705
+ {
706
+ "id": "empty-not-set-up",
707
+ "title": "Empty until set up",
708
+ "kind": "design",
709
+ "level": "organism",
710
+ "area": "state",
711
+ "situation": "A pane is empty because something it needs is not set up yet, such as a connected account.",
712
+ "do": [
713
+ "Say what is missing: 'No calendar connected'.",
714
+ "Pass one Button as `action`, named for what it sets up: 'Connect Calendar'.",
715
+ "Say where the fix lives when it is not here: 'An admin can connect one in Settings, under Integrations.'"
716
+ ],
717
+ "dont": [
718
+ "Do not put the Button outside `EmptyBox`. Pass it as `action`.",
719
+ "Do not offer a Button the person is not allowed to use.",
720
+ "Do not offer more than one Button."
721
+ ],
722
+ "native": "On Apple use `ContentUnavailableView`, with the Button in its `actions`.",
723
+ "notBuiltYet": "Commentify puts its 'Open Settings' Button under `EmptyBox`, not in its `action`, and writes the text in Title Case: 'No App, Team, or User Connected'.",
724
+ "seenIn": [
725
+ "Commentify",
726
+ "Scindo"
727
+ ],
728
+ "options": [
729
+ {
730
+ "id": "action",
731
+ "title": "Fix it here",
732
+ "useWhen": "The person can fix it here, with one Button.",
733
+ "source": "'use client';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function EmptyNotSetUpAction() {\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Calendar</Heading>\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CalendarOff\"\n text=\"No calendar connected\"\n secondText=\"Connect a calendar to see your meetings next to your tasks.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Connect Calendar\" onClickButton={() => router.push('/settings/calendar')} />}\n />\n </Surface>\n </Stack>\n );\n}\n",
734
+ "uses": [
735
+ "Button",
736
+ "EmptyBox",
737
+ "Heading",
738
+ "Stack",
739
+ "Surface"
740
+ ]
741
+ },
742
+ {
743
+ "id": "pointer",
744
+ "title": "Say where to fix it",
745
+ "useWhen": "The fix lives somewhere else, or someone else has to do it. Say where in `secondText`.",
746
+ "source": "'use client';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function EmptyNotSetUpPointer() {\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Calendar</Heading>\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CalendarOff\"\n text=\"No calendar connected\"\n secondText=\"An admin can connect one in Settings, under Integrations.\"\n />\n </Surface>\n </Stack>\n );\n}\n",
747
+ "uses": [
748
+ "EmptyBox",
749
+ "Heading",
750
+ "Stack",
751
+ "Surface"
752
+ ]
753
+ }
754
+ ]
755
+ },
756
+ {
757
+ "id": "empty-search",
758
+ "title": "Empty search",
759
+ "kind": "design",
760
+ "level": "organism",
761
+ "area": "state",
762
+ "situation": "A search or a filter finds nothing.",
763
+ "do": [
764
+ "Use `icon=\"Search\"`, so it reads as a search and not an empty list.",
765
+ "Show the words searched for, as `No <things> match \"<words>\"`: 'No projects match \"q3 plan\"'.",
766
+ "Pass a 'Clear Search' Button as `action`. It empties the field and shows the whole list again.",
767
+ "Put focus back in the search field after 'Clear Search'.",
768
+ "Keep the words in the search field."
769
+ ],
770
+ "dont": [
771
+ "Do not say 'No results found' without the words searched for.",
772
+ "Do not show the list's own empty text, such as 'No projects yet'.",
773
+ "Do not clear the search field unless the person asks."
774
+ ],
775
+ "native": "On Apple use `ContentUnavailableView.search(text:)`.",
776
+ "notBuiltYet": "Scindo on the web shows a bare line, 'No results found', with no words and no way to clear them. Scindo on Apple shows 'No results found' in a `ContentUnavailableView`, without the words. Commentify shows the words in an `EmptyBox`, with no Clear Search Button.",
777
+ "seenIn": [
778
+ "Commentify",
779
+ "Scindo"
780
+ ],
781
+ "options": [
782
+ {
783
+ "id": "clear-search",
784
+ "title": "The words and a way to clear them",
785
+ "useWhen": "Any search or filter.",
786
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport TextField from 'oneslash-design-system/components/textField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst projects = ['Website refresh', 'Hiring plan', 'Q4 budget', 'Office move'];\n\nexport default function EmptySearchClearSearch() {\n const [query, setQuery] = useState('q3 plan');\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes\n // back to the field instead of being lost with the Button that the list replaces.\n const [searchKey, setSearchKey] = useState(0);\n const words = query.trim();\n const found = projects.filter((name) => name.toLowerCase().includes(words.toLowerCase()));\n\n function clearSearch() {\n setQuery('');\n setSearchKey((k) => k + 1);\n }\n\n return (\n <Stack gap=\"large\">\n <TextField key={searchKey} autoFocus={searchKey > 0} id=\"empty-search-query\" label=\"Search projects\" type=\"search\" value={query} onChange={(e) => setQuery(e.target.value)} />\n {found.length > 0 ? (\n <Surface minHeight=\"tall\">\n <List items={found} size=\"body1\" />\n </Surface>\n ) : (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={`No projects match \"${words}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n </Surface>\n )}\n </Stack>\n );\n}\n",
787
+ "uses": [
788
+ "Button",
789
+ "EmptyBox",
790
+ "List",
791
+ "Stack",
792
+ "Surface",
793
+ "TextField"
794
+ ]
795
+ }
796
+ ]
797
+ },
798
+ {
799
+ "id": "error-page",
800
+ "title": "Error page",
801
+ "kind": "design",
802
+ "level": "page",
803
+ "area": "state",
804
+ "situation": "Something broke while showing a page, and the app cannot show it.",
805
+ "do": [
806
+ "Name the page in a `Heading` with `level={1}`: 'Something went wrong'.",
807
+ "Say in one plain sentence what happened and what the person can do.",
808
+ "Offer 'Try Again' first and 'Go Home' second.",
809
+ "Keep the navigation when only one route failed."
810
+ ],
811
+ "dont": [
812
+ "Do not show the error's own message, a stack trace or an error id.",
813
+ "Do not show a line of text with no way out.",
814
+ "Do not hide the navigation when only one route failed."
815
+ ],
816
+ "notBuiltYet": "Scindo on the web shows the error's own message and its id. Commentify shows one line and 'Try again', with no heading and no way home. jinhwankim.com shows an `EmptyBox` with no Button.",
817
+ "seenIn": [
818
+ "Commentify",
819
+ "Scindo",
820
+ "jinhwankim.com"
821
+ ],
822
+ "options": [
823
+ {
824
+ "id": "full-page",
825
+ "title": "Full page",
826
+ "useWhen": "The app shell itself failed, so nothing else can show.",
827
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.\nconst reset = () => console.info('Render the page again');\n\nexport default function ErrorPageFullPage() {\n return (\n <Center fill>\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Something went wrong</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Acme could not load. Try again, or go back to the home page.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" onClickButton={reset} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Center>\n );\n}\n",
828
+ "uses": [
829
+ "Button",
830
+ "Center",
831
+ "Cluster",
832
+ "Heading",
833
+ "Paragraph",
834
+ "Stack"
835
+ ]
836
+ },
837
+ {
838
+ "id": "in-shell",
839
+ "title": "Inside the shell",
840
+ "useWhen": "One route failed and the navigation still works.",
841
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.\nconst reset = () => console.info('Render the page again');\n\nexport default function ErrorPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Something went wrong</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page could not load. Try again, or go back to the home page.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" onClickButton={reset} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
842
+ "uses": [
843
+ "Button",
844
+ "Cluster",
845
+ "Heading",
846
+ "Image",
847
+ "Paragraph",
848
+ "Stack",
849
+ "Surface",
850
+ "Tab",
851
+ "TabsContainer"
852
+ ]
853
+ }
854
+ ]
855
+ },
856
+ {
857
+ "id": "feedback-form",
858
+ "title": "Feedback form",
859
+ "kind": "design",
860
+ "level": "organism",
861
+ "area": "confirm",
862
+ "situation": "A person sends feedback about the product from inside it.",
863
+ "do": [
864
+ "Title the Modal 'Send Feedback' and label its action 'Send', after 'Cancel'.",
865
+ "Ask for a category with a `Select` and the feedback with a `Textarea`. Start the category on a safe default.",
866
+ "Put a line of text above the `Select` that says what it asks, and give the Select the same words as its `aria-label`.",
867
+ "Focus the first field when the Modal opens, with `initialFocus=\"body\"`.",
868
+ "Disable the `Select` and the `Textarea` while it sends, and keep what the person wrote.",
869
+ "Keep 'Send' `state=\"disabled\"` while the feedback is empty.",
870
+ "Send on Cmd+Enter or Ctrl+Enter from the `Textarea`, through its `onSubmit`. Enter adds a new line.",
871
+ "Show an inline error Alert at the top of the Modal when sending fails, and keep what the person wrote.",
872
+ "Close the Modal when it works, and show a toast: 'Feedback sent.'"
873
+ ],
874
+ "dont": [
875
+ "Do not replace the form with a thank-you message that closes on its own.",
876
+ "Do not change the label while it is loading, such as to 'Sending...'.",
877
+ "Do not fail without a word. Say that the feedback was not sent.",
878
+ "Do not clear what the person wrote when sending fails."
879
+ ],
880
+ "notBuiltYet": "Scindo's feedback form labels the Button 'Sending...' while it runs, shows no error when sending fails, and replaces the form with a thank-you that closes after 1.5 seconds. It labels its fields with captions written by hand.",
881
+ "seenIn": [
882
+ "Scindo"
883
+ ],
884
+ "options": [
885
+ {
886
+ "id": "modal",
887
+ "title": "Send from a Modal",
888
+ "useWhen": "Feedback can be sent from anywhere in the product, such as a help menu.",
889
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Select from 'oneslash-design-system/components/select';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst categories = [\n { value: 'idea', label: 'An idea' },\n { value: 'bug', label: 'Something is broken' },\n { value: 'question', label: 'A question' },\n { value: 'other', label: 'Something else' },\n];\n\nexport default function FeedbackFormModal() {\n // Opens on the Modal, as if the person just chose Send Feedback.\n const [open, setOpen] = useState(true);\n const [category, setCategory] = useState('idea');\n const [message, setMessage] = useState('It would help to see who changed a task and when.');\n const [error, setError] = useState('');\n const [sending, setSending] = useState(false);\n const attempts = useRef(0);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n const text = message.trim();\n\n function handleOpen() {\n setError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (sending) return;\n setOpen(false);\n }\n\n function handleSend() {\n if (sending || text === '') return;\n setError('');\n setSending(true);\n attempts.current += 1;\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSending(false);\n // The first try fails, to show the error. Send again and it works.\n if (attempts.current === 1) {\n setError('Your feedback was not sent. Check your connection and try again.');\n return;\n }\n setOpen(false);\n setCategory('idea');\n setMessage('');\n toastIds.current.push(toast({ type: 'success', message: 'Feedback sent.' }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Help</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Guides, shortcuts and what is new in Acme.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Send Feedback\" decoIcon=\"MessageSquare\" onClickButton={handleOpen} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Send Feedback\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={text === '' ? 'disabled' : 'enabled'} label=\"Send\" loading={sending} onClickButton={handleSend} />\n </>\n }\n >\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"small\">\n {/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">What is it about?</Paragraph>\n <Select aria-label=\"What is it about?\" value={category} options={categories} disabled={sending} onChange={(v) => setCategory(typeof v === 'string' ? v : v[0])} />\n </Stack>\n {/* Cmd+Enter or Ctrl+Enter sends. Enter adds a new line. */}\n <Textarea id=\"feedback-form-message\" label=\"Your feedback\" placeholder=\"What happened, or what would help?\" value={message} disabled={sending} onSubmit={handleSend} onChange={(e) => setMessage(e.target.value)} />\n </Modal>\n </Center>\n );\n}\n",
890
+ "uses": [
891
+ "Alert",
892
+ "Button",
893
+ "Center",
894
+ "Cluster",
895
+ "Heading",
896
+ "Modal",
897
+ "Paragraph",
898
+ "Select",
899
+ "Stack",
900
+ "Textarea",
901
+ "Toaster",
902
+ "dismissToast",
903
+ "toast"
904
+ ]
905
+ }
906
+ ]
907
+ },
908
+ {
909
+ "id": "forgot-password",
910
+ "title": "Forgot password",
911
+ "kind": "design",
912
+ "level": "page",
913
+ "area": "auth",
914
+ "situation": "A person cannot remember their password and asks for a link to set a new one.",
915
+ "do": [
916
+ "Name the page 'Reset password' in a `Heading` with `level={1}`, and say in one line what happens next.",
917
+ "Ask only for the email, and send it with 'Send Reset Link'.",
918
+ "Put a text-only 'Back to Login' Button under the form. In place, keep the email typed so far when it goes back.",
919
+ "Keep the email out of the URL when the reset form has its own page.",
920
+ "Offer 'Send Again' on the confirmation, as on 'Check your email': `loading` while it sends, then 'Sent' for 2 seconds.",
921
+ "Answer every address the same way: 'If ada@example.com has an Acme account, we sent it a link to reset the password.'",
922
+ "Show a problem with the email under the field, and a failed request in an inline Alert above it.",
923
+ "Show the loading state on the submit Button while sending, and keep the form in place."
924
+ ],
925
+ "dont": [
926
+ "Do not say whether an address has an account.",
927
+ "Do not clear the email the person typed on the login form.",
928
+ "Do not replace the form with a spinner while sending the link."
929
+ ],
930
+ "native": "On Apple, put 'Forgot Password?' under the 'Log In' Button and open the web reset form from it.",
931
+ "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while sending the link. Both then say 'We sent a password reset link to' the address, even when it has no account.",
932
+ "seenIn": [
933
+ "Commentify",
934
+ "Scindo"
935
+ ],
936
+ "options": [
937
+ {
938
+ "id": "in-place",
939
+ "title": "In place of the login form",
940
+ "useWhen": "The person chose 'Forgot Password?' on the login page. The login form swaps to the reset form and keeps the email typed so far.",
941
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function ForgotPasswordInPlace() {\n // Opens on the reset form, as if the person typed their email on the login form and then chose 'Forgot Password?'.\n const [view, setView] = useState<'login' | 'reset' | 'sent'>('reset');\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const [resending, setResending] = useState(false);\n const [resent, setResent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!resent) return;\n const timer = setTimeout(() => setResent(false), 2000);\n return () => clearTimeout(timer);\n }, [resent]);\n\n // Moves between the login form, the reset form and the confirmation. The email stays as typed.\n function showView(next: 'login' | 'reset' | 'sent') {\n setError('');\n setEmailError('');\n setPasswordError('');\n setView(next);\n }\n\n function handleLogIn() {\n if (loading) return;\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n function handleSendLink() {\n if (loading) return;\n setError('');\n setEmailError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'\n timer.current = setTimeout(() => {\n setLoading(false);\n // Every address gets the same confirmation, so the page never says whether it has an account.\n showView('sent');\n }, 1200);\n }\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (resending || resent) return;\n setResending(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setResending(false);\n setResent(true);\n }, 1200);\n }\n\n if (view === 'sent') {\n return (\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">If {email.trim()} has an Acme account, we sent it a link to reset the password.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => showView('login')} />\n </Stack>\n </Center>\n );\n }\n\n if (view === 'reset') {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Reset password</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Enter your email and we will send you a link to set a new password.</Paragraph>\n </Stack>\n <Form aria-label=\"Reset password\" onSubmit={handleSendLink}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"forgot-password-in-place-reset-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Send Reset Link\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Back to Login\" onClickButton={() => showView('login')} />\n </Form>\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected={false} href=\"/sign-up\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Log in\" onSubmit={handleLogIn}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"forgot-password-in-place-login-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"forgot-password-in-place-login-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Forgot Password?\" onClickButton={() => showView('reset')} />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n}\n",
942
+ "uses": [
943
+ "Alert",
944
+ "BrandIcon",
945
+ "Button",
946
+ "Center",
947
+ "Form",
948
+ "Heading",
949
+ "Icon",
950
+ "Image",
951
+ "Line",
952
+ "Paragraph",
953
+ "Stack",
954
+ "Tab",
955
+ "TabsContainer",
956
+ "TextField"
957
+ ]
958
+ },
959
+ {
960
+ "id": "own-page",
961
+ "title": "Its own page",
962
+ "useWhen": "The person comes from a link in an email or another app.",
963
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function ForgotPasswordOwnPage() {\n const [email, setEmail] = useState('');\n const [sentTo, setSentTo] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [loading, setLoading] = useState(false);\n const [resending, setResending] = useState(false);\n const [resent, setResent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!resent) return;\n const timer = setTimeout(() => setResent(false), 2000);\n return () => clearTimeout(timer);\n }, [resent]);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setEmailError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n setLoading(true);\n const address = email.trim();\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'\n timer.current = setTimeout(() => {\n setLoading(false);\n // Every address gets the same confirmation, so the page never says whether it has an account.\n setSentTo(address);\n }, 1200);\n }\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (resending || resent) return;\n setResending(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setResending(false);\n setResent(true);\n }, 1200);\n }\n\n if (sentTo) {\n return (\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">If {sentTo} has an Acme account, we sent it a link to reset the password.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Reset password</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Enter your email and we will send you a link to set a new password.</Paragraph>\n </Stack>\n <Form aria-label=\"Reset password\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"forgot-password-own-page-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Send Reset Link\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Form>\n </Center>\n );\n}\n",
964
+ "uses": [
965
+ "Alert",
966
+ "Button",
967
+ "Center",
968
+ "Form",
969
+ "Heading",
970
+ "Icon",
971
+ "Image",
972
+ "Paragraph",
973
+ "Stack",
974
+ "TextField"
975
+ ]
976
+ }
977
+ ]
978
+ },
979
+ {
980
+ "id": "form-errors",
981
+ "title": "A form error shows next to the problem",
982
+ "kind": "rule",
983
+ "level": "rule",
984
+ "area": "state",
985
+ "situation": "A form was submitted and something is wrong.",
986
+ "answer": "A problem with one field shows under that field, through the field's `error` and `errorText`. A problem with the whole request shows above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`, so it stays until the person closes it or submits again. Its `onClose` clears the message; if it does not, the Alert comes back. While the request runs, the submit Button is `loading` and keeps its label. The form keeps what the person typed. The next submit clears the old messages. Messages are in sentence case. It is never a colored caption written by hand, and never the browser's `alert()`.",
987
+ "why": "A message next to the problem tells the person what to fix without searching for it. Keeping what they typed means they fix one thing instead of starting again.",
988
+ "do": [
989
+ "Show a problem with one field under that field, with `error` and `errorText`.",
990
+ "Say what to do, not only what is wrong: 'Enter an email address, like name@example.com.'",
991
+ "Show a problem with the whole request above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`.",
992
+ "Clear the message in the Alert's `onClose`.",
993
+ "Keep everything the person typed after a failed submit.",
994
+ "Clear the old messages when the person submits again."
995
+ ],
996
+ "dont": [
997
+ "Do not leave out `variant=\"inline\"`: the default variant is a toast at the top of the screen, away from the form.",
998
+ "Do not write a red caption by hand. Use `errorText` or an Alert.",
999
+ "Do not use the browser's `alert()`.",
1000
+ "Do not clear the form after a failed submit.",
1001
+ "Do not change the submit Button's label while it is loading, such as to 'Saving…'."
1002
+ ],
1003
+ "notBuiltYet": "Commentify writes red captions by hand on its consent screen and in its Figma import dialog. Scindo on the web does the same in its dialogs, such as renaming a workspace or a task. Commentify uses the browser's `alert()` in three files, and Scindo on the web in one.",
1004
+ "seenIn": [
1005
+ "Commentify",
1006
+ "Scindo",
1007
+ "jinhwankim.com"
1008
+ ]
1009
+ },
1010
+ {
1011
+ "id": "import-checklist",
1012
+ "title": "Import checklist",
1013
+ "kind": "design",
1014
+ "level": "organism",
1015
+ "area": "confirm",
1016
+ "situation": "A person picks which items to bring in from another place, such as pages from a wiki.",
1017
+ "do": [
1018
+ "Put a search field at the top, then a count line, then the list of `Checkbox`es.",
1019
+ "Write the count line as plain words: '3 of 8 pages selected.' While a search is on, add how many match: '3 of 8 pages selected. 2 match \"launch\".'",
1020
+ "Offer 'Select All' and 'Clear' as tertiary Buttons. Both act on the items shown, and while a search is on their labels say so: 'Select Shown' and 'Clear Shown'.",
1021
+ "Focus the search field when the Modal opens, with `initialFocus=\"body\"`, and again after 'Clear Search'.",
1022
+ "Count the selection in the action: 'Import 3 Pages'. Keep it `state=\"disabled\"` while nothing is selected.",
1023
+ "Keep the selection when a search hides items. Items that are filtered out stay selected.",
1024
+ "Show `EmptyBox size=\"small\"` with the words searched for and a 'Clear Search' Button when nothing matches.",
1025
+ "Show `EmptyBox size=\"small\"` when there is nothing left to import.",
1026
+ "Show `loading` on the action while it imports, and keep the list on screen with the Checkboxes disabled.",
1027
+ "Close the Modal when it works and show the new items where they live."
1028
+ ],
1029
+ "dont": [
1030
+ "Do not use a master Checkbox for Select All. Checkbox has no state for some selected.",
1031
+ "Do not label the action 'Import' without the count, or change it while it runs, such as to 'Importing… 1/2'.",
1032
+ "Do not clear the selection when the person searches.",
1033
+ "Do not show a bare line of text when the list is empty or nothing matches."
1034
+ ],
1035
+ "notBuiltYet": "Scindo's Notion import labels its Buttons 'Select all' and 'Import', changes the action to 'Importing… 1/2' while it runs, and shows bare text when nothing matches.",
1036
+ "seenIn": [
1037
+ "Scindo"
1038
+ ],
1039
+ "options": [
1040
+ {
1041
+ "id": "modal",
1042
+ "title": "Pick in a Modal",
1043
+ "useWhen": "The person chooses some items out of a list they can search.",
1044
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// Pages in the other place. A real app loads them when the Modal opens.\nconst wikiPages = [\n { id: 'p1', title: 'Launch checklist', edited: 'Edited 2 days ago' },\n { id: 'p2', title: 'Launch email draft', edited: 'Edited 3 days ago' },\n { id: 'p3', title: 'Brand voice', edited: 'Edited last week' },\n { id: 'p4', title: 'Pricing notes', edited: 'Edited last week' },\n { id: 'p5', title: 'Hiring plan', edited: 'Edited 2 weeks ago' },\n { id: 'p6', title: 'Office move', edited: 'Edited last month' },\n { id: 'p7', title: 'Onboarding guide', edited: 'Edited last month' },\n { id: 'p8', title: 'Team rituals', edited: 'Edited 2 months ago' },\n];\n\nconst plural = (n: number) => (n === 1 ? 'Page' : 'Pages');\n\nexport default function ImportChecklistModal() {\n const [docs, setDocs] = useState(['Q3 plan', 'Meeting notes']);\n const [imported, setImported] = useState<string[]>([]);\n // Opens on the Modal with three pages picked, as if the person just chose Import Pages.\n const [open, setOpen] = useState(true);\n const [query, setQuery] = useState('');\n const [selected, setSelected] = useState<string[]>(['p1', 'p2', 'p4']);\n const [importing, setImporting] = useState(false);\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes\n // back to the field instead of being lost with the Button that the list replaces.\n const [searchKey, setSearchKey] = useState(0);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const available = wikiPages.filter((p) => !imported.includes(p.id));\n const words = query.trim();\n const shown = available.filter((p) => p.title.toLowerCase().includes(words.toLowerCase()));\n const shownIds = shown.map((p) => p.id);\n const count = selected.length;\n // While a search is on, the labels say that they act only on the pages shown.\n const searching = words !== '';\n\n function toggle(id: string, checked: boolean) {\n setSelected((list) => (checked ? [...list, id] : list.filter((x) => x !== id)));\n }\n\n // Both act on the pages shown. Pages the search hides keep their selection.\n function selectShown() {\n setSelected((list) => [...list, ...shownIds.filter((id) => !list.includes(id))]);\n }\n function clearShown() {\n setSelected((list) => list.filter((id) => !shownIds.includes(id)));\n }\n\n function clearSearch() {\n setQuery('');\n setSearchKey((k) => k + 1);\n }\n\n function handleOpen() {\n setQuery('');\n setSelected([]);\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (importing) return;\n setOpen(false);\n }\n\n function handleImport() {\n if (importing || count === 0) return;\n setImporting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setImporting(false);\n setDocs((list) => [...wikiPages.filter((p) => selected.includes(p.id)).map((p) => p.title), ...list]);\n setImported((list) => [...list, ...selected]);\n setSelected([]);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster>\n <Heading level={1} size=\"h5\">Docs</Heading>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Import Pages\" decoIcon=\"Download\" onClickButton={handleOpen} />\n </Cluster>\n {/* The imported pages show at the top of the list, so no toast is needed. */}\n <Surface padding=\"large\">\n <List items={docs} size=\"body1\" />\n </Surface>\n </Stack>\n <Modal\n isOpen={open}\n size=\"medium\"\n initialFocus=\"body\"\n title=\"Import Pages\"\n secondTitle=\"From the Acme wiki\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={importing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={count === 0 ? 'disabled' : 'enabled'} label={count === 0 ? 'Import Pages' : `Import ${count} ${plural(count)}`} loading={importing} onClickButton={handleImport} />\n </>\n }\n >\n {available.length === 0 ? (\n <EmptyBox size=\"small\" icon=\"FileCheck\" text=\"No pages left to import\" secondText=\"Every page in the Acme wiki is already in Docs.\" />\n ) : (\n <>\n <TextField key={searchKey} autoFocus={searchKey > 0} id=\"import-checklist-search\" label=\"Search pages\" type=\"search\" value={query} disabled={importing} onChange={(e) => setQuery(e.target.value)} />\n <Stack gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {count} of {available.length} pages selected.{words && ` ${shown.length} match \"${words}\".`}\n </Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={importing || shown.length === 0 ? 'disabled' : 'enabled'} label={searching ? 'Select Shown' : 'Select All'} onClickButton={selectShown} />\n <Button size=\"small\" type=\"tertiary\" state={importing || shown.length === 0 ? 'disabled' : 'enabled'} label={searching ? 'Clear Shown' : 'Clear'} onClickButton={clearShown} />\n </Cluster>\n </Stack>\n {shown.length > 0 ? (\n <Stack gap=\"medium\">\n {shown.map((p) => (\n <Checkbox key={p.id} label={p.title} secondLabel={p.edited} checked={selected.includes(p.id)} disabled={importing} onChange={(checked) => toggle(p.id, checked)} />\n ))}\n </Stack>\n ) : (\n <EmptyBox\n size=\"small\"\n icon=\"Search\"\n text={`No pages match \"${words}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n )}\n </>\n )}\n </Modal>\n </Center>\n );\n}\n",
1045
+ "uses": [
1046
+ "Button",
1047
+ "Center",
1048
+ "Checkbox",
1049
+ "Cluster",
1050
+ "EmptyBox",
1051
+ "Heading",
1052
+ "List",
1053
+ "Modal",
1054
+ "Paragraph",
1055
+ "Stack",
1056
+ "Surface",
1057
+ "TextField"
1058
+ ]
1059
+ }
1060
+ ]
1061
+ },
1062
+ {
1063
+ "id": "inline-form-feedback",
1064
+ "title": "Form feedback",
1065
+ "kind": "design",
1066
+ "level": "organism",
1067
+ "area": "state",
1068
+ "situation": "A person submits a small form, such as a settings field, and the request ends. The three options are the three outcomes of one save: it worked in place, it failed, or the result is elsewhere.",
1069
+ "do": [
1070
+ "Show `loading` on the submit Button while the request runs, and keep its label.",
1071
+ "Show 'Saved' on the Button for 2 seconds when the form saves in place, or until the person edits again.",
1072
+ "Show a failed request above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`, and keep what the person typed.",
1073
+ "Call `toast({ type: 'success', message })` when the result is somewhere else."
1074
+ ],
1075
+ "dont": [
1076
+ "Do not change the Button's label while it is loading, such as to 'Saving…'.",
1077
+ "Do not show a toast for a change the person can already see.",
1078
+ "Do not let a failed save pass with no message.",
1079
+ "Do not say 'successfully'."
1080
+ ],
1081
+ "native": "On Apple there is no toast. Show the result in place.",
1082
+ "notBuiltYet": "Scindo on the web labels its save Buttons 'Saving...' while they save. Its profile settings show nothing when a save fails. Its instructions settings show the error's own message in an inline Alert with no close button.",
1083
+ "seenIn": [
1084
+ "Scindo"
1085
+ ],
1086
+ "options": [
1087
+ {
1088
+ "id": "button-label",
1089
+ "title": "Saved on the Button",
1090
+ "useWhen": "It worked in place: the change shows where it is.",
1091
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function InlineFormFeedbackButtonLabel() {\n const [name, setName] = useState('Dana Reyes');\n const [nameError, setNameError] = useState('');\n const [loading, setLoading] = useState(false);\n // Starts saved, so the example opens on the state it shows.\n const [saved, setSaved] = useState(true);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Saved' shows for 2 seconds, or until the person edits again, then the Button reads 'Save'.\n useEffect(() => {\n if (!saved) return;\n const timer = setTimeout(() => setSaved(false), 2000);\n return () => clearTimeout(timer);\n }, [saved]);\n\n function handleSubmit() {\n if (loading) return;\n setNameError('');\n setSaved(false);\n if (!name.trim()) {\n setNameError('Enter the name people see on your comments.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setSaved(true);\n }, 1200);\n }\n\n return (\n <Center>\n <Surface padding=\"large\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">Profile</Heading>\n <Form aria-label=\"Profile\" onSubmit={handleSubmit}>\n <TextField id=\"inline-form-feedback-name\" label=\"Display name\" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={loading} />\n </Cluster>\n </Form>\n </Stack>\n </Surface>\n </Center>\n );\n}\n",
1092
+ "uses": [
1093
+ "Button",
1094
+ "Center",
1095
+ "Cluster",
1096
+ "Form",
1097
+ "Heading",
1098
+ "Stack",
1099
+ "Surface",
1100
+ "TextField"
1101
+ ]
1102
+ },
1103
+ {
1104
+ "id": "inline-alert",
1105
+ "title": "Inline error Alert",
1106
+ "useWhen": "It failed: the request did not go through.",
1107
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function InlineFormFeedbackInlineAlert() {\n const [name, setName] = useState('Dana Reyes');\n const [nameError, setNameError] = useState('');\n // Starts failed, so the example opens on the state it shows.\n const [error, setError] = useState('Your profile was not saved. Try again.');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setNameError('');\n if (!name.trim()) {\n setNameError('Enter the name people see on your comments.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('Your profile was not saved. Try again.');\n }, 1200);\n }\n\n return (\n <Center>\n <Surface padding=\"large\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">Profile</Heading>\n <Form aria-label=\"Profile\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"inline-form-feedback-alert-name\" label=\"Display name\" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Save\" htmlType=\"submit\" loading={loading} />\n </Cluster>\n </Form>\n </Stack>\n </Surface>\n </Center>\n );\n}\n",
1108
+ "uses": [
1109
+ "Alert",
1110
+ "Button",
1111
+ "Center",
1112
+ "Cluster",
1113
+ "Form",
1114
+ "Heading",
1115
+ "Stack",
1116
+ "Surface",
1117
+ "TextField"
1118
+ ]
1119
+ },
1120
+ {
1121
+ "id": "toast",
1122
+ "title": "Toast",
1123
+ "useWhen": "The result is elsewhere, such as an invite that was sent.",
1124
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function InlineFormFeedbackToast() {\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // Opens on the toast the example shows, as if an invite was just sent.\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => {\n toastIds.current.push(toast({ type: 'success', message: 'Invite sent to dana@example.com.' }));\n return () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n function handleSubmit() {\n if (loading) return;\n setEmailError('');\n const address = email.trim();\n if (!address) {\n setEmailError('Enter an email address.');\n return;\n }\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setEmail('');\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center fill>\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Surface padding=\"large\">\n <Stack gap=\"large\">\n <Heading level={2} size=\"h6\">Invite people</Heading>\n <Form aria-label=\"Invite people\" onSubmit={handleSubmit}>\n <TextField id=\"inline-form-feedback-email\" label=\"Email\" type=\"email\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Invite\" htmlType=\"submit\" loading={loading} />\n </Cluster>\n </Form>\n </Stack>\n </Surface>\n </Center>\n );\n}\n",
1125
+ "uses": [
1126
+ "Button",
1127
+ "Center",
1128
+ "Cluster",
1129
+ "Form",
1130
+ "Heading",
1131
+ "Stack",
1132
+ "Surface",
1133
+ "TextField",
1134
+ "Toaster",
1135
+ "dismissToast",
1136
+ "toast"
1137
+ ]
1138
+ }
1139
+ ]
1140
+ },
1141
+ {
1142
+ "id": "invite-member",
1143
+ "title": "Member invite",
1144
+ "kind": "design",
1145
+ "level": "organism",
1146
+ "area": "confirm",
1147
+ "situation": "A person invites someone to join a workspace.",
1148
+ "do": [
1149
+ "Title the Modal 'Invite Member' and label its action 'Invite', after 'Cancel'.",
1150
+ "Send on Enter too: put the email field in a `Form`.",
1151
+ "Focus the email field when the Modal opens, with `initialFocus=\"body\"`, and disable it while the invite is sent.",
1152
+ "Show a problem with the address under the field, such as a person who is already a member.",
1153
+ "Close the Modal once the invite is sent, and show a toast that names the address: 'Invite sent to ada@example.com.'",
1154
+ "Show a toast that names the link once it is revoked: 'Link made by Dana Lee revoked.'",
1155
+ "Show the link in a `TextField` with `readOnly`, so it can be selected, and a 'Copy' Button next to it.",
1156
+ "Change 'Copy' to 'Copied' for 2 seconds, and only when the link reached the clipboard.",
1157
+ "Say under the field when copying is blocked: 'Copying is blocked here. Select the link and copy it.'",
1158
+ "Say who can use the link and when it stops working.",
1159
+ "List the links that still work, each with a 'Revoke' Button. Revoking removes access, so confirm it in the row, as the case 'Delete confirm' does.",
1160
+ "Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the link: 'Revoke the link made by Dana Lee'.",
1161
+ "Start each `aria-label` with the visible label, so voice control still finds the Button.",
1162
+ "Disable 'Done', and ignore Escape and a click outside, while a revoke runs."
1163
+ ],
1164
+ "dont": [
1165
+ "Do not label the way out 'Close', or the action 'Create Invite' when the product sends it.",
1166
+ "Do not replace the field with a spinner while the invite is sent.",
1167
+ "Do not show 'Copied' when the copy failed, or 'Copied!' with an exclamation mark.",
1168
+ "Do not revoke a link on the first click.",
1169
+ "Do not touch `navigator` while the page renders. Copy only in the click handler."
1170
+ ],
1171
+ "native": "On Apple use a sheet with a `Form`, share the link with `ShareLink`, and revoke a link with a `.destructive` Button that asks first in a `confirmationDialog`.",
1172
+ "notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates an invite, labels the way out 'Close' and reads 'Copied!'. It cancels an invite link on one click with no confirm. Scindo's Apple app cancels a pending invite with no confirm too.",
1173
+ "seenIn": [
1174
+ "Scindo"
1175
+ ],
1176
+ "options": [
1177
+ {
1178
+ "id": "by-email",
1179
+ "title": "Send an invite by email",
1180
+ "useWhen": "The product sends the invite to an address the person types.",
1181
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst members = [\n { name: 'Dana Lee', email: 'dana@example.com', role: 'Admin' },\n { name: 'Omar Haddad', email: 'omar@example.com', role: 'Member' },\n { name: 'Mei Tanaka', email: 'mei@example.com', role: 'Member' },\n];\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function InviteMemberByEmail() {\n // Opens on the Modal, as if the person just chose Invite Member.\n const [open, setOpen] = useState(true);\n const [email, setEmail] = useState('ada@example.com');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n const address = email.trim();\n\n function handleOpen() {\n setEmail('');\n setEmailError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (sending) return;\n setOpen(false);\n }\n\n function handleSend() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n // Type omar@example.com to see a problem with the address.\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme Design.`);\n return;\n }\n setSending(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSending(false);\n setOpen(false);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Cluster>\n <Heading level={1} size=\"h5\">Members</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleOpen} />\n </Cluster>\n <TableContainer>\n {members.map((m) => (\n <TableRow key={m.email}>\n <TableCell>{m.name}</TableCell>\n <TableCell>{m.email}</TableCell>\n <TableCell width=\"100px\">{m.role}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSend} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme Design as a member. The link works for 7 days.</Paragraph>\n {/* The Form lets Enter in the field send too. */}\n <Form aria-label=\"Invite member\" onSubmit={handleSend}>\n <TextField id=\"invite-member-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
1182
+ "uses": [
1183
+ "Button",
1184
+ "Center",
1185
+ "Cluster",
1186
+ "Form",
1187
+ "Heading",
1188
+ "Modal",
1189
+ "Paragraph",
1190
+ "Stack",
1191
+ "TableCell",
1192
+ "TableContainer",
1193
+ "TableRow",
1194
+ "TextField",
1195
+ "Toaster",
1196
+ "dismissToast",
1197
+ "toast"
1198
+ ]
1199
+ },
1200
+ {
1201
+ "id": "by-link",
1202
+ "title": "Share an invite link",
1203
+ "useWhen": "The person shares a link themselves, in their own chat or email.",
1204
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport TextField from 'oneslash-design-system/components/textField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst members = [\n { name: 'Dana Lee', email: 'dana@example.com', role: 'Admin' },\n { name: 'Omar Haddad', email: 'omar@example.com', role: 'Member' },\n { name: 'Mei Tanaka', email: 'mei@example.com', role: 'Member' },\n];\n\n// The link made for this Modal. A real app gets it from the server.\nconst inviteLink = 'https://acme.example/join/k7Qm2xLp';\n\nconst earlierLinks = [\n { id: 'l1', createdBy: 'Dana Lee', expires: '5 days left' },\n { id: 'l2', createdBy: 'Omar Haddad', expires: '2 days left' },\n];\n\nexport default function InviteMemberByLink() {\n // Opens on the Modal, as if the person just chose Invite Member.\n const [open, setOpen] = useState(true);\n const [copied, setCopied] = useState(false);\n const [copyBlocked, setCopyBlocked] = useState(false);\n const [links, setLinks] = useState(earlierLinks);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState(false);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(copyTimer.current);\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the field says so, and the label stays 'Copy'.\n function handleCopy() {\n clearTimeout(copyTimer.current);\n setCopied(false);\n const blocked = () => setCopyBlocked(true);\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(inviteLink).then(() => {\n setCopyBlocked(false);\n setCopied(true);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, blocked);\n }\n\n // Done, Escape and a click outside all close it, except while a revoke runs.\n // Closing drops a row's open confirm, so the Modal never reopens on it.\n function handleClose() {\n if (revoking) return;\n setConfirming(null);\n setOpen(false);\n }\n\n function handleRevoke(id: string, createdBy: string) {\n if (revoking) return;\n setRevoking(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setRevoking(false);\n setConfirming(null);\n setLinks((list) => list.filter((l) => l.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `Link made by ${createdBy} revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Cluster>\n <Heading level={1} size=\"h5\">Members</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={() => setOpen(true)} />\n </Cluster>\n <TableContainer>\n {members.map((m) => (\n <TableRow key={m.email}>\n <TableCell>{m.name}</TableCell>\n <TableCell>{m.email}</TableCell>\n <TableCell width=\"100px\">{m.role}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={open}\n size=\"medium\"\n title=\"Invite Member\"\n onClose={handleClose}\n actions={<Button size=\"small\" type=\"primary\" state={revoking ? 'disabled' : 'enabled'} label=\"Done\" onClickButton={handleClose} />}\n >\n <Paragraph measure=\"none\">Anyone with this link can join Acme Design as a member. It works for 7 days.</Paragraph>\n <Stack gap=\"small\" align=\"start\">\n <TextField id=\"invite-member-link\" label=\"Invite link\" value={inviteLink} readOnly onChange={() => {}} />\n {copyBlocked && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Copying is blocked here. Select the link and copy it.</Paragraph>}\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label={copied ? 'Copied' : 'Copy'} decoIcon={copied ? 'Check' : 'Copy'} onClickButton={handleCopy} />\n </Stack>\n <Stack gap=\"small\">\n <Heading level={3} size=\"subtitle1\">Other links that still work</Heading>\n {links.length > 0 ? (\n <TableContainer>\n {links.map((l) => (\n <TableRow key={l.id}>\n <TableCell>Made by {l.createdBy}</TableCell>\n <TableCell width=\"120px\">{l.expires}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\">\n {confirming === l.id ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel, keep the link made by ${l.createdBy}`} onClickButton={() => setConfirming(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke the link made by ${l.createdBy}`} loading={revoking} onClickButton={() => handleRevoke(l.id, l.createdBy)} />\n </Cluster>\n ) : (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke the link made by ${l.createdBy}`} onClickButton={() => setConfirming(l.id)} />\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"Link\" text=\"No other links\" secondText=\"Links you make here show until they stop working.\" />\n )}\n </Stack>\n </Modal>\n </Center>\n );\n}\n",
1205
+ "uses": [
1206
+ "Button",
1207
+ "Center",
1208
+ "Cluster",
1209
+ "EmptyBox",
1210
+ "Heading",
1211
+ "Modal",
1212
+ "Paragraph",
1213
+ "Stack",
1214
+ "TableCell",
1215
+ "TableContainer",
1216
+ "TableRow",
1217
+ "TextField",
1218
+ "Toaster",
1219
+ "dismissToast",
1220
+ "toast"
1221
+ ]
1222
+ }
1223
+ ]
1224
+ },
1225
+ {
1226
+ "id": "load-failure",
1227
+ "title": "Load failure",
1228
+ "kind": "design",
1229
+ "level": "organism",
1230
+ "area": "state",
1231
+ "situation": "A list or a section could not load.",
1232
+ "do": [
1233
+ "Say what could not load: 'Could not load projects'.",
1234
+ "Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
1235
+ "Show the list as soon as it loads.",
1236
+ "Keep the rest of the page working when only one section failed.",
1237
+ "Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
1238
+ ],
1239
+ "dont": [
1240
+ "Do not show the empty text, such as 'No projects yet', when the list failed to load.",
1241
+ "Do not show the error's own message, such as 'Failed to fetch'.",
1242
+ "Do not replace the whole page when only one section failed."
1243
+ ],
1244
+ "native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
1245
+ "notBuiltYet": "Scindo on the web shows its empty list, with no Try Again, when its API keys or its members fail to load. Commentify puts its 'Try again' Button under `EmptyBox`, not in its `action`.",
1246
+ "seenIn": [
1247
+ "Commentify",
1248
+ "Scindo"
1249
+ ],
1250
+ "options": [
1251
+ {
1252
+ "id": "region",
1253
+ "title": "Whole list failed",
1254
+ "useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
1255
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst projects = ['Website refresh', 'Hiring plan', 'Q4 budget', 'Office move'];\n\nexport default function LoadFailureRegion() {\n const [loaded, setLoaded] = useState(false);\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setLoaded(true);\n }, 1200);\n }\n\n return (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Projects</Heading>\n {loaded ? (\n <Surface minHeight=\"tall\">\n <List items={projects} size=\"body1\" />\n </Surface>\n ) : (\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n icon=\"CloudOff\"\n text=\"Could not load projects\"\n secondText=\"Check your connection and try again.\"\n action={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />}\n />\n </Surface>\n )}\n </Stack>\n );\n}\n",
1256
+ "uses": [
1257
+ "Button",
1258
+ "EmptyBox",
1259
+ "Heading",
1260
+ "List",
1261
+ "Stack",
1262
+ "Surface"
1263
+ ]
1264
+ },
1265
+ {
1266
+ "id": "inline",
1267
+ "title": "One section failed",
1268
+ "useWhen": "One section failed to load and the rest of the page works.",
1269
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst invoices = ['November 2026: $240', 'October 2026: $240', 'September 2026: $180'];\n\nexport default function LoadFailureInline() {\n const [error, setError] = useState('Could not load your invoices.');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleTryAgain() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Plan</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Team plan, 12 seats, renews on December 1.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Change Plan\" />\n </Cluster>\n </Stack>\n </Surface>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Invoices</Heading>\n {error ? (\n <>\n {/* The section stays failed until it loads, so the Alert has no close button and does not close on its own. */}\n <Alert type=\"error\" variant=\"inline\" message={error} autoDismiss={false} />\n <Cluster>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Try Again\" loading={loading} onClickButton={handleTryAgain} />\n </Cluster>\n </>\n ) : (\n <List items={invoices} size=\"body2\" />\n )}\n </Stack>\n </Surface>\n </Stack>\n </Center>\n );\n}\n",
1270
+ "uses": [
1271
+ "Alert",
1272
+ "Button",
1273
+ "Center",
1274
+ "Cluster",
1275
+ "Heading",
1276
+ "List",
1277
+ "Paragraph",
1278
+ "Stack",
1279
+ "Surface"
1280
+ ]
1281
+ }
1282
+ ]
1283
+ },
1284
+ {
1285
+ "id": "log-out-confirm",
1286
+ "title": "Log-out confirm",
1287
+ "kind": "design",
1288
+ "level": "organism",
1289
+ "area": "confirm",
1290
+ "situation": "A person chooses Log Out.",
1291
+ "do": [
1292
+ "Call it 'Log Out' everywhere: the menu item, the Modal title and the action Button. The way back in is 'Log In'.",
1293
+ "Say in one sentence what logging out means on this device.",
1294
+ "Ask before logging out, although logging out is easy to undo. A person can press it by mistake on a shared device, or with unsent work.",
1295
+ "Leave the action Button in the plain primary color. Logging out destroys nothing.",
1296
+ "Show `loading` on 'Log Out' while it runs, then show the logged-out page."
1297
+ ],
1298
+ "dont": [
1299
+ "Do not mix 'Sign Out' with 'Log In'. Use one word family: 'Log Out' and 'Log In'.",
1300
+ "Do not give the action Button `color=\"danger\"`.",
1301
+ "Do not ask 'Are you sure you want to log out?'.",
1302
+ "Do not show a toast after logging out. The logged-out page says it."
1303
+ ],
1304
+ "native": "On Apple use a system `confirmationDialog` titled 'Log Out', with a 'Log Out' Button and 'Cancel' in the `.cancel` role. Leave out the `.destructive` role: nothing is destroyed.",
1305
+ "notBuiltYet": "Scindo on the web says 'Log Out' but colors it as danger. Scindo on Apple says 'Sign Out' and puts it in the destructive role. Commentify and Commentify admin say 'Sign Out', title the Modal 'Confirm Sign Out', label the action 'Yes, Sign Out' and ask 'Are you sure you want to sign out?'.",
1306
+ "seenIn": [
1307
+ "Commentify",
1308
+ "Commentify admin",
1309
+ "Scindo"
1310
+ ],
1311
+ "options": [
1312
+ {
1313
+ "id": "modal",
1314
+ "title": "Confirm in a Modal",
1315
+ "useWhen": "The product keeps unsent work or runs on shared devices.",
1316
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function LogOutConfirmModal() {\n // Opens on the confirm, as if the person just chose Log Out.\n const [open, setOpen] = useState(true);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (loggingOut) return;\n setOpen(false);\n }\n\n function handleLogOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setOpen(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => setLoggedOut(false)} />\n </Cluster>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Account</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Logged in as ada@example.com.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Log Out\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n title=\"Log Out\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={handleLogOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1317
+ "uses": [
1318
+ "Button",
1319
+ "Center",
1320
+ "Cluster",
1321
+ "Heading",
1322
+ "Modal",
1323
+ "Paragraph",
1324
+ "Stack"
1325
+ ]
1326
+ }
1327
+ ]
1328
+ },
1329
+ {
1330
+ "id": "login-page",
1331
+ "title": "Login page",
1332
+ "kind": "design",
1333
+ "level": "page",
1334
+ "area": "auth",
1335
+ "situation": "A person who already has an account opens the product and is not logged in.",
1336
+ "do": [
1337
+ "Show a problem with one field under that field.",
1338
+ "Show a refused login or a failed request in an inline Alert above the fields.",
1339
+ "Put a text-only 'Forgot Password?' Button right under the submit Button when there is a password.",
1340
+ "Name the provider on its button: 'Continue with Google'.",
1341
+ "Show the loading state on the submit Button while logging in, and keep the form in place.",
1342
+ "Disable the fields while the request runs."
1343
+ ],
1344
+ "dont": [
1345
+ "Do not clear the email field after a failed attempt.",
1346
+ "Do not show sign-up fields on the login page; link or tab to sign-up.",
1347
+ "Do not replace the form with a spinner while logging in.",
1348
+ "Do not say which of the email or the password was wrong."
1349
+ ],
1350
+ "native": "On Apple use `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
1351
+ "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while logging in. They do not use the Button's loading state yet.",
1352
+ "seenIn": [
1353
+ "Commentify",
1354
+ "Commentify admin",
1355
+ "Scindo"
1356
+ ],
1357
+ "options": [
1358
+ {
1359
+ "id": "centered",
1360
+ "title": "Centered column",
1361
+ "useWhen": "The product has one way in, and most people log in with email and a password.",
1362
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function LoginCentered() {\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected={false} href=\"/sign-up\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Log in\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"login-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"login-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Forgot Password?\" />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n}\n",
1363
+ "uses": [
1364
+ "Alert",
1365
+ "BrandIcon",
1366
+ "Button",
1367
+ "Center",
1368
+ "Form",
1369
+ "Image",
1370
+ "Line",
1371
+ "Tab",
1372
+ "TabsContainer",
1373
+ "TextField"
1374
+ ]
1375
+ },
1376
+ {
1377
+ "id": "split",
1378
+ "title": "Brand beside the form",
1379
+ "useWhen": "First-time visitors land here and need one line on what the product is.",
1380
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport Link from 'oneslash-design-system/components/link';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Cluster, Split, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function LoginSplit() {\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n return (\n <Split\n fill\n aside={\n <Stack gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Heading level={2} size=\"h4\">Plan the week with your whole team.</Heading>\n <Paragraph tone=\"secondary\" measure=\"lede\">\n Acme keeps tasks, notes and decisions in one place.\n </Paragraph>\n </Stack>\n }\n >\n <Center fill>\n <Heading level={1} size=\"h5\">Log in to Acme</Heading>\n <Form aria-label=\"Log in\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"split-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"split-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Forgot Password?\" />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">New here?</Paragraph>\n <Link href=\"/sign-up\" size=\"body2\">Sign Up</Link>\n </Cluster>\n </Center>\n </Split>\n );\n}\n",
1381
+ "uses": [
1382
+ "Alert",
1383
+ "BrandIcon",
1384
+ "Button",
1385
+ "Center",
1386
+ "Cluster",
1387
+ "Form",
1388
+ "Heading",
1389
+ "Image",
1390
+ "Line",
1391
+ "Link",
1392
+ "Paragraph",
1393
+ "Split",
1394
+ "Stack",
1395
+ "TextField"
1396
+ ]
1397
+ },
1398
+ {
1399
+ "id": "provider-first",
1400
+ "title": "Provider first",
1401
+ "useWhen": "Most people log in with Google, GitHub or Apple; email is the fallback.",
1402
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function LoginProviderFirst() {\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">Log in to Acme</Heading>\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with GitHub\" decoIcon={<BrandIcon name=\"github\" />} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Apple\" decoIcon={<BrandIcon name=\"apple\" />} />\n </Stack>\n <Line label=\"or\" />\n <Form aria-label=\"Log in with email\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"provider-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"provider-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In with Email\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Forgot Password?\" />\n </Form>\n </Center>\n );\n}\n",
1403
+ "uses": [
1404
+ "Alert",
1405
+ "BrandIcon",
1406
+ "Button",
1407
+ "Center",
1408
+ "Form",
1409
+ "Heading",
1410
+ "Line",
1411
+ "Stack",
1412
+ "TextField"
1413
+ ]
1414
+ },
1415
+ {
1416
+ "id": "email-only",
1417
+ "title": "Email only",
1418
+ "useWhen": "An internal tool with no passwords: the person gets a login link by email.",
1419
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function LoginEmailOnly() {\n const [email, setEmail] = useState('ada@example.com');\n const [sentTo, setSentTo] = useState('');\n const [emailError, setEmailError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSubmit() {\n if (loading) return;\n setEmailError('');\n setSentTo('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n setLoading(true);\n const address = email.trim();\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setSentTo(address);\n }, 1200);\n }\n\n return (\n <Center fill>\n <Surface padding=\"large\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Log in</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">We will email you a link to log in.</Paragraph>\n </Stack>\n <Form aria-label=\"Log in\" onSubmit={handleSubmit}>\n {sentTo && <Alert type=\"success\" variant=\"inline\" message={`We sent a login link to ${sentTo}.`} autoDismiss={false} />}\n <TextField id=\"email-only-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Send Login Link\" htmlType=\"submit\" loading={loading} />\n </Form>\n </Stack>\n </Surface>\n </Center>\n );\n}\n",
1420
+ "uses": [
1421
+ "Alert",
1422
+ "Button",
1423
+ "Center",
1424
+ "Form",
1425
+ "Heading",
1426
+ "Paragraph",
1427
+ "Stack",
1428
+ "Surface",
1429
+ "TextField"
1430
+ ]
1431
+ }
1432
+ ]
1433
+ },
1434
+ {
1435
+ "id": "not-found-page",
1436
+ "title": "Page not found",
1437
+ "kind": "design",
1438
+ "level": "page",
1439
+ "area": "state",
1440
+ "situation": "A person opens a link to a page that does not exist.",
1441
+ "do": [
1442
+ "Say 'Page not found' in a `Heading` with `level={1}`.",
1443
+ "Add one line on what may have happened: 'The link may be wrong, or the page was moved or removed.'",
1444
+ "Offer one Button home: 'Go Home'."
1445
+ ],
1446
+ "dont": [
1447
+ "Do not make '404' the heading.",
1448
+ "Do not show a line of text with no way home.",
1449
+ "Do not blame the person for the link."
1450
+ ],
1451
+ "notBuiltYet": "Commentify's page not found is one line of bare text, 'Page not found.', with no way home. Scindo on the web shows '404' as its heading, then bare text and a text link home. jinhwankim.com has no heading: it puts '404:' at the start of its `EmptyBox` text and labels its Button 'Go to Home'.",
1452
+ "seenIn": [
1453
+ "Commentify",
1454
+ "Scindo",
1455
+ "jinhwankim.com"
1456
+ ],
1457
+ "options": [
1458
+ {
1459
+ "id": "full-page",
1460
+ "title": "Full page",
1461
+ "useWhen": "The address is outside the app shell, so nothing else can show.",
1462
+ "source": "'use client';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function NotFoundPageFullPage() {\n return (\n <Center fill>\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Center>\n );\n}\n",
1463
+ "uses": [
1464
+ "Button",
1465
+ "Center",
1466
+ "Cluster",
1467
+ "Heading",
1468
+ "Paragraph",
1469
+ "Stack"
1470
+ ]
1471
+ },
1472
+ {
1473
+ "id": "in-shell",
1474
+ "title": "Inside the shell",
1475
+ "useWhen": "The address is inside the app and the navigation still works.",
1476
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function NotFoundPageInShell() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </Stack>\n );\n}\n",
1477
+ "uses": [
1478
+ "Button",
1479
+ "Cluster",
1480
+ "Heading",
1481
+ "Image",
1482
+ "Paragraph",
1483
+ "Stack",
1484
+ "Surface",
1485
+ "Tab",
1486
+ "TabsContainer"
1487
+ ]
1488
+ }
1489
+ ]
1490
+ },
1491
+ {
1492
+ "id": "oauth-consent",
1493
+ "title": "OAuth consent",
1494
+ "kind": "design",
1495
+ "level": "page",
1496
+ "area": "auth",
1497
+ "situation": "Another app, such as a CLI or an MCP client, asks to act for a person who is logged in, and the person must allow it.",
1498
+ "do": [
1499
+ "Name the app in a `Heading` with `level={1}`: 'Acme CLI wants to connect to Acme'.",
1500
+ "Say in one or two plain sentences what the app will be able to do, in the person's words: 'read your projects and tasks, and create tasks as you'.",
1501
+ "Say how to remove the access later: 'You can remove its access at any time in Settings, under Connected apps.'",
1502
+ "Show the account that gives the access, with a text-only 'Not You? Switch Account' Button under it.",
1503
+ "Take the app's name and the place the person goes back to from the server's record of the registered app, never from the link.",
1504
+ "Say where the person goes next: 'You will go back to cli.acme.dev.'",
1505
+ "Put 'Cancel' first and 'Allow' second, side by side and the same width, in a `Grid` with `columns={2}`.",
1506
+ "Show `loading` on 'Allow' and disable 'Cancel' and every field while the request runs.",
1507
+ "Show `LoadingScreen` with `label=\"Going back to Acme CLI…\"` while the browser goes back, after 'Allow' and after 'Cancel'.",
1508
+ "Send 'Cancel' back to the app with `error=access_denied`, and return the `state` value the app sent on both paths.",
1509
+ "Leave wider access off until the person turns it on, and say under it what it adds."
1510
+ ],
1511
+ "dont": [
1512
+ "Do not color 'Allow' or 'Cancel' as danger. Allowing is the person's choice, not a destructive action.",
1513
+ "Do not turn on wider access for the person.",
1514
+ "Do not name the access by its scope id, such as 'tasks:write'.",
1515
+ "Do not label Cancel 'Deny' or 'No'."
1516
+ ],
1517
+ "notBuiltYet": "Scindo on the web turns on access to every workspace for the person, and shows its spinner on neither Button while the request runs. Commentify puts 'Allow' before 'Deny', writes its error in a red caption by hand, and says nothing about how to remove the access.",
1518
+ "seenIn": [
1519
+ "Commentify",
1520
+ "Scindo"
1521
+ ],
1522
+ "options": [
1523
+ {
1524
+ "id": "simple",
1525
+ "title": "One account, one access",
1526
+ "useWhen": "The app gets one set of access to one account, so the only choice is to allow it or not.",
1527
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function OAuthConsentSimple() {\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read your projects and tasks, and create tasks as you. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
1528
+ "uses": [
1529
+ "Alert",
1530
+ "Button",
1531
+ "Center",
1532
+ "Cluster",
1533
+ "Grid",
1534
+ "Heading",
1535
+ "Image",
1536
+ "LoadingScreen",
1537
+ "Paragraph",
1538
+ "Stack",
1539
+ "UserImage"
1540
+ ]
1541
+ },
1542
+ {
1543
+ "id": "with-scope",
1544
+ "title": "Workspace and wider access",
1545
+ "useWhen": "The person picks the workspace the app can use, or turns on wider access.",
1546
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Select from 'oneslash-design-system/components/select';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\n// The app's name and cli.acme.dev come from the server's record of the registered app, never from the link.\n// Going back to another site is a full page load, such as window.location.assign() in a real app.\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// The workspaces the person belongs to.\nconst workspaces = [\n { value: 'design', label: 'Acme Design' },\n { value: 'marketing', label: 'Acme Marketing' },\n];\n\nexport default function OAuthConsentWithScope() {\n const [workspace, setWorkspace] = useState('design');\n // The wider access is off until the person turns it on.\n const [allWorkspaces, setAllWorkspaces] = useState(false);\n const [allowing, setAllowing] = useState(false);\n const [handingBack, setHandingBack] = useState(false);\n const [error, setError] = useState('');\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleAllow() {\n if (allowing) return;\n setError('');\n setAllowing(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Acme CLI was not connected. Try again.'\n timer.current = setTimeout(() => {\n setAllowing(false);\n setHandingBack(true);\n // A real app also returns the `state` value the app sent, so the app can match the answer to its request.\n router.push('https://cli.acme.dev/callback');\n }, 1200);\n }\n\n // The app hears that the person said no, and nothing is shared.\n // A real app also returns the `state` value the app sent.\n function handleCancel() {\n setHandingBack(true);\n router.push('https://cli.acme.dev/callback?error=access_denied');\n }\n\n // Shown while the browser goes back to the app, the same as a named step in 'Login check loading'.\n if (handingBack) {\n return (\n <Center fill>\n <LoadingScreen label=\"Going back to Acme CLI…\" />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Acme CLI wants to connect to Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">It will be able to read the projects and tasks you can see, and create tasks as you, in the workspaces you allow below. You can remove its access at any time in Settings, under Connected apps.</Paragraph>\n </Stack>\n {/* The account that gives the access, so the person can tell it is the right one. */}\n <Stack gap=\"small\" align=\"start\">\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Ada Lovelace\" />\n <Paragraph size=\"body2\" measure=\"none\">ada@example.com</Paragraph>\n </Cluster>\n <Button size=\"small\" type=\"textOnly\" state={allowing ? 'disabled' : 'enabled'} label=\"Not You? Switch Account\" onClickButton={() => router.push('/login?next=%2Foauth%2Fauthorize')} />\n </Stack>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <Stack gap=\"small\">\n {/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Workspace</Paragraph>\n <Select aria-label=\"Workspace\" value={workspace} options={workspaces} disabled={allowing} onChange={(v) => setWorkspace(typeof v === 'string' ? v : v[0])} />\n </Stack>\n <Checkbox label=\"Also allow my other workspaces\" secondLabel=\"It can then do the same in every workspace you belong to. It still sees only what you can see.\" checked={allWorkspaces} disabled={allowing} onChange={setAllWorkspaces} />\n <Stack gap=\"medium\">\n <Grid columns={2} gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state={allowing ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Allow\" loading={allowing} onClickButton={handleAllow} />\n </Grid>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">You will go back to cli.acme.dev.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
1547
+ "uses": [
1548
+ "Alert",
1549
+ "Button",
1550
+ "Center",
1551
+ "Checkbox",
1552
+ "Cluster",
1553
+ "Grid",
1554
+ "Heading",
1555
+ "Image",
1556
+ "LoadingScreen",
1557
+ "Paragraph",
1558
+ "Select",
1559
+ "Stack",
1560
+ "UserImage"
1561
+ ]
1562
+ }
1563
+ ]
1564
+ },
1565
+ {
1566
+ "id": "rename",
1567
+ "title": "Rename",
1568
+ "kind": "design",
1569
+ "level": "organism",
1570
+ "area": "confirm",
1571
+ "situation": "A person renames something, such as a project or a channel.",
1572
+ "do": [
1573
+ "Title the Modal 'Rename' and the thing, such as 'Rename Project', and give its action the same verb: 'Rename'.",
1574
+ "Keep 'Rename' `state=\"disabled\"` while the name is empty or unchanged.",
1575
+ "Save on Enter too: put the field in a `Form`.",
1576
+ "Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
1577
+ "Focus the field with `autoFocus` when the name becomes a field in place.",
1578
+ "Save on Enter and when the person leaves the field. Cancel on Escape, and when the name is empty."
1579
+ ],
1580
+ "dont": [
1581
+ "Do not label the Modal's action 'Save' or 'OK'.",
1582
+ "Do not show a toast after a rename. The new name shows where the old one was.",
1583
+ "Do not save an empty name.",
1584
+ "Do not drop what the person typed when they leave the field."
1585
+ ],
1586
+ "native": "On Apple rename in place in a list with a `TextField` and `.onSubmit`. Use an `.alert` with a `TextField` when the name is not on screen.",
1587
+ "notBuiltYet": "Commentify's two renames disagree on what leaving the field does: a project name cancels, a tag name saves. Scindo on the web labels its rename Modals' action 'Save', shows 'Saving...' while it runs, and writes a taken name as a red caption by hand.",
1588
+ "seenIn": [
1589
+ "Commentify",
1590
+ "Scindo"
1591
+ ],
1592
+ "options": [
1593
+ {
1594
+ "id": "modal",
1595
+ "title": "Rename in a Modal",
1596
+ "useWhen": "Rename is opened from a menu or from far away from the name.",
1597
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// Names the server already has. Type one to see the request fail.\nconst takenNames = ['website refresh', 'hiring plan', 'office move'];\n\nexport default function RenameModal() {\n const [name, setName] = useState('Q3 plan');\n // Opens on the Modal, as if the person just chose Rename Project.\n const [open, setOpen] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = draft.trim();\n const canRename = next !== '' && next !== name;\n\n function handleOpen() {\n setDraft(name);\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (saving) return;\n setOpen(false);\n }\n\n function handleRename() {\n if (saving || !canRename) return;\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (takenNames.includes(next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setName(next);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* A real app often opens Rename from a menu on the project. */}\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Rename Project\" onClickButton={handleOpen} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Rename Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={canRename ? 'enabled' : 'disabled'} label=\"Rename\" loading={saving} onClickButton={handleRename} />\n </>\n }\n >\n {/* The Form lets Enter in the field rename too. */}\n <Form aria-label=\"Rename project\" onSubmit={handleRename}>\n <TextField id=\"rename-name\" label=\"Project name\" value={draft} disabled={saving} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setDraft(e.target.value); setNameError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
1598
+ "uses": [
1599
+ "Button",
1600
+ "Center",
1601
+ "Cluster",
1602
+ "Form",
1603
+ "Heading",
1604
+ "Modal",
1605
+ "Paragraph",
1606
+ "Stack",
1607
+ "TextField"
1608
+ ]
1609
+ },
1610
+ {
1611
+ "id": "inline",
1612
+ "title": "Rename in place",
1613
+ "useWhen": "The name is on screen, and it becomes a field.",
1614
+ "source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function RenameInline() {\n const [name, setName] = useState('Q3 plan');\n // Opens with the name as a field, as if the person just chose Rename.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n\n function startEditing() {\n ended.current = false;\n setDraft(name);\n setEditing(true);\n }\n\n function save() {\n if (ended.current) return;\n ended.current = true;\n const next = draft.trim();\n // An empty or unchanged name cancels: there is nothing to send.\n // Otherwise a real app sends the new name to the server here and shows it at once.\n if (next && next !== name) setName(next);\n setEditing(false);\n }\n\n function cancel() {\n if (ended.current) return;\n ended.current = true;\n setEditing(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n {editing ? (\n <TextField\n id=\"rename-inline-name\"\n label=\"Project name\"\n value={draft}\n autoFocus\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n save();\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel();\n }\n }}\n onBlur={save}\n />\n ) : (\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Tooltip title=\"Rename\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Rename project\" onClick={startEditing} />\n </Tooltip>\n </Cluster>\n )}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
1615
+ "uses": [
1616
+ "Center",
1617
+ "Cluster",
1618
+ "Heading",
1619
+ "IconButton",
1620
+ "Paragraph",
1621
+ "Stack",
1622
+ "TextField",
1623
+ "Tooltip"
1624
+ ]
1625
+ }
1626
+ ]
1627
+ },
1628
+ {
1629
+ "id": "route-loading",
1630
+ "title": "Page loading",
1631
+ "kind": "design",
1632
+ "level": "page",
1633
+ "area": "state",
1634
+ "situation": "A page or a pane is loading, and there is nothing to show yet.",
1635
+ "do": [
1636
+ "Show the shell as soon as it can, and the spinner only where content is loading.",
1637
+ "Center the spinner in the space that is loading.",
1638
+ "Replace the spinner with the content as soon as it loads.",
1639
+ "Name the step in `LoadingScreen`'s `label` when a named step can take longer than about a second, as in 'Login check loading'.",
1640
+ "Use the same screen as the spinner in 'Login check loading' when nothing can show yet: `LoadingScreen` alone in `Center` with `fill`."
1641
+ ],
1642
+ "dont": [
1643
+ "Do not write a line that names no step, such as 'Loading…'.",
1644
+ "Do not cover the navigation with a spinner when only one pane is loading.",
1645
+ "Do not show the empty text while the list is still loading."
1646
+ ],
1647
+ "native": "On Apple use `ProgressView()` with no label, centered in the pane.",
1648
+ "seenIn": [
1649
+ "Commentify",
1650
+ "Scindo"
1651
+ ],
1652
+ "options": [
1653
+ {
1654
+ "id": "full-screen",
1655
+ "title": "Full screen",
1656
+ "useWhen": "Nothing can show yet, not even the navigation.",
1657
+ "source": "'use client';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Center } from 'oneslash-design-system/components/layout';\n\nexport default function RouteLoadingFullScreen() {\n return (\n <Center fill>\n <LoadingScreen />\n </Center>\n );\n}\n",
1658
+ "uses": [
1659
+ "Center",
1660
+ "LoadingScreen"
1661
+ ]
1662
+ },
1663
+ {
1664
+ "id": "region",
1665
+ "title": "In one pane",
1666
+ "useWhen": "The shell shows and one pane loads.",
1667
+ "source": "'use client';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Surface from 'oneslash-design-system/components/surface';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\nexport default function RouteLoadingRegion() {\n return (\n <Stack gap=\"large\">\n <Cluster gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={32} height={32} />\n <TabsContainer>\n <Tab label=\"Home\" isSelected={false} href=\"/\" router={router} onClickTab={() => {}} />\n <Tab label=\"Projects\" isSelected href=\"/projects\" router={router} onClickTab={() => {}} />\n <Tab label=\"Settings\" isSelected={false} href=\"/settings\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n </Cluster>\n <Surface minHeight=\"tall\" align=\"center\">\n <LoadingScreen />\n </Surface>\n </Stack>\n );\n}\n",
1668
+ "uses": [
1669
+ "Cluster",
1670
+ "Image",
1671
+ "LoadingScreen",
1672
+ "Stack",
1673
+ "Surface",
1674
+ "Tab",
1675
+ "TabsContainer"
1676
+ ]
1677
+ }
1678
+ ]
1679
+ },
1680
+ {
1681
+ "id": "set-new-password",
1682
+ "title": "Set new password",
1683
+ "kind": "design",
1684
+ "level": "page",
1685
+ "area": "auth",
1686
+ "situation": "A person opened the link to reset their password and now chooses a new one.",
1687
+ "do": [
1688
+ "Name the page 'Set new password' in a `Heading` with `level={1}`, and name the account it is for.",
1689
+ "Ask for 'New password' and 'Confirm password', and send them with 'Update Password'. Ask twice here: the old password is gone after this, and there is no other way to catch a typo.",
1690
+ "Say the product's password rule before the person breaks it, such as 'Use at least 8 characters.'",
1691
+ "Put the rule in the password field's `helperText`, so it is tied to the field.",
1692
+ "Check the rule on the server too, and show its refusal under the field.",
1693
+ "Show a problem with one field under that field: a password that does not match shows under Confirm password, and clears when either field changes.",
1694
+ "Show the loading state on the submit Button while updating, and keep the form in place.",
1695
+ "Log the person out of the reset link's session before showing the login form, so they really log in with the new password.",
1696
+ "Go to the login form on success, with a success Alert above it: 'Password updated. Log in with your new password.'"
1697
+ ],
1698
+ "dont": [
1699
+ "Do not show the rule only after the person breaks it.",
1700
+ "Do not show a mismatch above the fields; it belongs under Confirm password.",
1701
+ "Do not replace the form with a spinner while updating.",
1702
+ "Do not show the form when the link is invalid or expired."
1703
+ ],
1704
+ "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while updating, and show field problems in an Alert above the fields. Both accept 6 characters, and say 'Password must be at least 6 characters.' only after it is broken. Scindo's reset page has no invalid-link state.",
1705
+ "seenIn": [
1706
+ "Commentify",
1707
+ "Scindo"
1708
+ ],
1709
+ "options": [
1710
+ {
1711
+ "id": "form",
1712
+ "title": "New password form",
1713
+ "useWhen": "The link is valid.",
1714
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app passes the address of the account the reset link was sent for.\nconst address = 'ada@example.com';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function SetNewPasswordForm() {\n const [updated, setUpdated] = useState(false);\n const [newPassword, setNewPassword] = useState('');\n const [confirmPassword, setConfirmPassword] = useState('');\n const [newPasswordError, setNewPasswordError] = useState('');\n const [confirmPasswordError, setConfirmPasswordError] = useState('');\n const [notice, setNotice] = useState('');\n const [email, setEmail] = useState(address);\n const [password, setPassword] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [error, setError] = useState('');\n const [loading, setLoading] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleUpdate() {\n if (loading) return;\n setError('');\n setNewPasswordError('');\n setConfirmPasswordError('');\n if (newPassword.length < 8) {\n setNewPasswordError('Use at least 8 characters.');\n return;\n }\n if (!confirmPassword) {\n setConfirmPasswordError('Enter the new password again.');\n return;\n }\n if (confirmPassword !== newPassword) {\n setConfirmPasswordError('This does not match. Enter the same password as above.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Your password was not updated. Try again.'\n timer.current = setTimeout(() => {\n setLoading(false);\n // A real app signs the reset session out and goes to its login page here, which shows the notice.\n // The example shows it in place.\n setNotice('Password updated. Log in with your new password.');\n setUpdated(true);\n }, 1200);\n }\n\n function handleLogIn() {\n if (loading) return;\n setNotice('');\n setError('');\n setEmailError('');\n setPasswordError('');\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (!password) {\n setPasswordError('Enter your password.');\n return;\n }\n setLoading(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoading(false);\n setError('That email and password do not match.');\n }, 1200);\n }\n\n if (updated) {\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected={false} href=\"/sign-up\" router={router} onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Log in\" onSubmit={handleLogIn}>\n {/* It says what to do next, so it stays until the person submits the form: no close button, and it does not close on its own. */}\n {notice && <Alert type=\"success\" variant=\"inline\" message={notice} autoDismiss={false} />}\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"set-new-password-login-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"set-new-password-login-password\" label=\"Password\" type=\"password\" autoComplete=\"current-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" htmlType=\"submit\" loading={loading} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Forgot Password?\" />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Set new password</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Choose a new password for {address}.</Paragraph>\n </Stack>\n <Form aria-label=\"Set new password\" onSubmit={handleUpdate}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n {/* Editing the new password also clears the message under Confirm password, which may no longer be true. */}\n <TextField id=\"set-new-password-new\" label=\"New password\" type=\"password\" autoComplete=\"new-password\" value={newPassword} disabled={loading} error={Boolean(newPasswordError)} errorText={newPasswordError} helperText=\"Use at least 8 characters.\" onChange={(e) => { setNewPassword(e.target.value); setNewPasswordError(''); setConfirmPasswordError(''); }} />\n <TextField id=\"set-new-password-confirm\" label=\"Confirm password\" type=\"password\" autoComplete=\"new-password\" value={confirmPassword} disabled={loading} error={Boolean(confirmPasswordError)} errorText={confirmPasswordError} onChange={(e) => { setConfirmPassword(e.target.value); setConfirmPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Update Password\" htmlType=\"submit\" loading={loading} />\n </Form>\n </Center>\n );\n}\n",
1715
+ "uses": [
1716
+ "Alert",
1717
+ "BrandIcon",
1718
+ "Button",
1719
+ "Center",
1720
+ "Form",
1721
+ "Heading",
1722
+ "Image",
1723
+ "Line",
1724
+ "Paragraph",
1725
+ "Stack",
1726
+ "Tab",
1727
+ "TabsContainer",
1728
+ "TextField"
1729
+ ]
1730
+ },
1731
+ {
1732
+ "id": "invalid-link",
1733
+ "title": "Link no longer works",
1734
+ "useWhen": "The link is invalid, expired or already used.",
1735
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app passes the address of the account the old link was sent for.\nconst address = 'ada@example.com';\n\nexport default function SetNewPasswordInvalidLink() {\n const [loading, setLoading] = useState(false);\n const [sent, setSent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleSendNewLink() {\n if (loading) return;\n setLoading(true);\n // Stands in for the request to the server.\n // A failed request shows an inline error Alert above the Buttons, such as 'The link was not sent. Try again.'\n timer.current = setTimeout(() => {\n setLoading(false);\n setSent(true);\n }, 1200);\n }\n\n if (sent) {\n return (\n <Center width=\"form\" fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a new link to {address}. Open it to set a new password.</Paragraph>\n </Stack>\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Center>\n );\n }\n\n return (\n <Center width=\"form\" fill>\n <Heading level={1} size=\"h5\">Set new password</Heading>\n {/* The link cannot be used, so the form does not show. The Alert reports a standing condition: it has no close button and stays. */}\n <Alert type=\"error\" variant=\"inline\" message=\"This link has expired or was already used.\" autoDismiss={false} />\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Send a New Link\" loading={loading} onClickButton={handleSendNewLink} />\n <Button size=\"medium\" type=\"textOnly\" state={loading ? 'disabled' : 'enabled'} label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n );\n}\n",
1736
+ "uses": [
1737
+ "Alert",
1738
+ "Button",
1739
+ "Center",
1740
+ "Heading",
1741
+ "Icon",
1742
+ "Paragraph",
1743
+ "Stack"
1744
+ ]
1745
+ }
1746
+ ]
1747
+ },
1748
+ {
1749
+ "id": "sign-up-page",
1750
+ "title": "Sign-up page",
1751
+ "kind": "design",
1752
+ "level": "page",
1753
+ "area": "auth",
1754
+ "situation": "A person who has no account yet opens the product and wants one.",
1755
+ "do": [
1756
+ "Ask only for what the account needs: name, email and password.",
1757
+ "Say the product's password rule before the person breaks it, such as 'Use at least 8 characters.'",
1758
+ "Put the rule in the password field's `helperText`, so it is tied to the field.",
1759
+ "Check the rule on the server too, and show its refusal under the field.",
1760
+ "Show a problem with one field under that field.",
1761
+ "Show a failed request in an inline Alert above the fields.",
1762
+ "Show the loading state on the submit Button while creating the account, and keep the form in place.",
1763
+ "Show the check-your-email view in place of the form when the email must be confirmed, for every address, even one that already has an account. Tell that person by email that they can log in.",
1764
+ "Keep the submit Button loading until the check-your-email view shows.",
1765
+ "Name the provider on its button: 'Continue with Google'.",
1766
+ "Link or tab to login for people who already have an account."
1767
+ ],
1768
+ "dont": [
1769
+ "Do not ask for anything the account can do without, such as a username or the password twice.",
1770
+ "Do not clear the email field after a failed attempt.",
1771
+ "Do not replace the form with a spinner while creating the account.",
1772
+ "Do not say on the page whether an address already has an account."
1773
+ ],
1774
+ "native": "On Apple, Scindo opens the web sign-up page with a `Link`. A sign-up built in the app uses `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
1775
+ "notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while creating the account. Neither says a password rule on its sign-up page. Their reset pages accept 6 characters and say 'Password must be at least 6 characters.' only after it is broken. Commentify asks for the first and last name in two fields.",
1776
+ "seenIn": [
1777
+ "Commentify",
1778
+ "Scindo"
1779
+ ],
1780
+ "options": [
1781
+ {
1782
+ "id": "centered",
1783
+ "title": "Centered column",
1784
+ "useWhen": "The product has one way in, and most people sign up with email and a password.",
1785
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Image from 'oneslash-design-system/components/image';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function SignUpCentered() {\n const [name, setName] = useState('Ada Lovelace');\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [nameError, setNameError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n // The address the link went to. Set once the account request ends, which shows the check-your-email view.\n const [sentTo, setSentTo] = useState('');\n const [resending, setResending] = useState(false);\n const [resent, setResent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!resent) return;\n const timer = setTimeout(() => setResent(false), 2000);\n return () => clearTimeout(timer);\n }, [resent]);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setNameError('');\n setEmailError('');\n setPasswordError('');\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (password.length < 8) {\n setPasswordError('Use at least 8 characters.');\n return;\n }\n setLoading(true);\n const address = email.trim();\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'\n timer.current = setTimeout(() => {\n // Every address goes on to the same view, so the page never says whether it has an account.\n // The Button stays loading until the view changes.\n setLoading(false);\n setSentTo(address);\n }, 1200);\n }\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (resending || resent) return;\n setResending(true);\n // Stands in for the request to the server.\n // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'\n timer.current = setTimeout(() => {\n setResending(false);\n setResent(true);\n }, 1200);\n }\n\n // The same view as the 'Check your email' case, in place of the form.\n if (sentTo) {\n return (\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a link to {sentTo}. Open it to continue.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <TabsContainer fill>\n <Tab label=\"Log In\" isSelected={false} href=\"/login\" router={router} onClickTab={() => {}} />\n <Tab label=\"Sign Up\" isSelected onClickTab={() => {}} />\n </TabsContainer>\n <Form aria-label=\"Sign up\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"sign-up-page-centered-name\" label=\"Name\" autoComplete=\"name\" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n <TextField id=\"sign-up-page-centered-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"sign-up-page-centered-password\" label=\"Password\" type=\"password\" autoComplete=\"new-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText=\"Use at least 8 characters.\" onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" htmlType=\"submit\" loading={loading} />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n </Center>\n );\n}\n",
1786
+ "uses": [
1787
+ "Alert",
1788
+ "BrandIcon",
1789
+ "Button",
1790
+ "Center",
1791
+ "Form",
1792
+ "Heading",
1793
+ "Icon",
1794
+ "Image",
1795
+ "Line",
1796
+ "Paragraph",
1797
+ "Stack",
1798
+ "Tab",
1799
+ "TabsContainer",
1800
+ "TextField"
1801
+ ]
1802
+ },
1803
+ {
1804
+ "id": "split",
1805
+ "title": "Brand beside the form",
1806
+ "useWhen": "People arrive from an ad or an invite and need one line on what the product is.",
1807
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Image from 'oneslash-design-system/components/image';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport Link from 'oneslash-design-system/components/link';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Cluster, Split, Stack } from 'oneslash-design-system/components/layout';\n\n// The product's mark. A real app passes its own file.\nconst productMark =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E\";\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function SignUpSplit() {\n const [name, setName] = useState('Ada Lovelace');\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [nameError, setNameError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n // The address the link went to. Set once the account request ends, which shows the check-your-email view.\n const [sentTo, setSentTo] = useState('');\n const [resending, setResending] = useState(false);\n const [resent, setResent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!resent) return;\n const timer = setTimeout(() => setResent(false), 2000);\n return () => clearTimeout(timer);\n }, [resent]);\n\n const aside = (\n <Stack gap=\"large\">\n <Image src={productMark} alt=\"Acme\" width={40} height={40} />\n <Heading level={2} size=\"h4\">Plan the week with your whole team.</Heading>\n <Paragraph tone=\"secondary\" measure=\"lede\">\n Acme keeps tasks, notes and decisions in one place.\n </Paragraph>\n </Stack>\n );\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setNameError('');\n setEmailError('');\n setPasswordError('');\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (password.length < 8) {\n setPasswordError('Use at least 8 characters.');\n return;\n }\n setLoading(true);\n const address = email.trim();\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'\n timer.current = setTimeout(() => {\n // Every address goes on to the same view, so the page never says whether it has an account.\n // The Button stays loading until the view changes.\n setLoading(false);\n setSentTo(address);\n }, 1200);\n }\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (resending || resent) return;\n setResending(true);\n // Stands in for the request to the server.\n // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'\n timer.current = setTimeout(() => {\n setResending(false);\n setResent(true);\n }, 1200);\n }\n\n // The same view as the 'Check your email' case, in place of the form.\n if (sentTo) {\n return (\n <Split fill aside={aside}>\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a link to {sentTo}. Open it to continue.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n </Split>\n );\n }\n\n return (\n <Split fill aside={aside}>\n <Center fill>\n <Heading level={1} size=\"h5\">Create your Acme account</Heading>\n <Form aria-label=\"Sign up\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"sign-up-page-split-name\" label=\"Name\" autoComplete=\"name\" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n <TextField id=\"sign-up-page-split-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"sign-up-page-split-password\" label=\"Password\" type=\"password\" autoComplete=\"new-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText=\"Use at least 8 characters.\" onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" htmlType=\"submit\" loading={loading} />\n </Form>\n <Line label=\"or\" />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Already have an account?</Paragraph>\n <Link href=\"/login\" size=\"body2\">Log in</Link>\n </Cluster>\n </Center>\n </Split>\n );\n}\n",
1808
+ "uses": [
1809
+ "Alert",
1810
+ "BrandIcon",
1811
+ "Button",
1812
+ "Center",
1813
+ "Cluster",
1814
+ "Form",
1815
+ "Heading",
1816
+ "Icon",
1817
+ "Image",
1818
+ "Line",
1819
+ "Link",
1820
+ "Paragraph",
1821
+ "Split",
1822
+ "Stack",
1823
+ "TextField"
1824
+ ]
1825
+ },
1826
+ {
1827
+ "id": "provider-first",
1828
+ "title": "Provider first",
1829
+ "useWhen": "Most people sign up with Google, GitHub or Apple; email is the fallback.",
1830
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Mail } from 'lucide-react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport Alert from 'oneslash-design-system/components/alert';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Button from 'oneslash-design-system/components/button';\nimport Line from 'oneslash-design-system/components/line';\nimport Link from 'oneslash-design-system/components/link';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function SignUpProviderFirst() {\n const [name, setName] = useState('Ada Lovelace');\n const [email, setEmail] = useState('ada@example.com');\n const [password, setPassword] = useState('');\n const [error, setError] = useState('');\n const [nameError, setNameError] = useState('');\n const [emailError, setEmailError] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [loading, setLoading] = useState(false);\n // The address the link went to. Set once the account request ends, which shows the check-your-email view.\n const [sentTo, setSentTo] = useState('');\n const [resending, setResending] = useState(false);\n const [resent, setResent] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.\n useEffect(() => {\n if (!resent) return;\n const timer = setTimeout(() => setResent(false), 2000);\n return () => clearTimeout(timer);\n }, [resent]);\n\n function handleSubmit() {\n if (loading) return;\n setError('');\n setNameError('');\n setEmailError('');\n setPasswordError('');\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n if (!email.trim()) {\n setEmailError('Enter your email.');\n return;\n }\n if (!looksLikeEmail(email.trim())) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n if (password.length < 8) {\n setPasswordError('Use at least 8 characters.');\n return;\n }\n setLoading(true);\n const address = email.trim();\n // Stands in for the request to the server.\n // A failed request calls setError with one sentence instead, such as 'Your account was not created. Try again.'\n timer.current = setTimeout(() => {\n // Every address goes on to the same view, so the page never says whether it has an account.\n // The Button stays loading until the view changes.\n setLoading(false);\n setSentTo(address);\n }, 1200);\n }\n\n function handleSendAgain() {\n // One click sends one email: clicks while it sends or reads 'Sent' do nothing.\n if (resending || resent) return;\n setResending(true);\n // Stands in for the request to the server.\n // A failed request shows an inline error Alert above the Buttons, such as 'The email was not sent. Try again.'\n timer.current = setTimeout(() => {\n setResending(false);\n setResent(true);\n }, 1200);\n }\n\n // The same view as the 'Check your email' case, in place of the form.\n if (sentTo) {\n return (\n <Center fill>\n <Icon icon={Mail} size=\"large\" color=\"secondary\" />\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Check your email</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a link to {sentTo}. Open it to continue.</Paragraph>\n </Stack>\n <Stack gap=\"large\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />\n <Button size=\"medium\" type=\"textOnly\" state=\"enabled\" label=\"Back to Login\" onClickButton={() => router.push('/login')} />\n </Stack>\n </Center>\n );\n }\n\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">Sign up for Acme</Heading>\n <Stack gap=\"medium\">\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Google\" decoIcon={<BrandIcon name=\"google\" />} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with GitHub\" decoIcon={<BrandIcon name=\"github\" />} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Continue with Apple\" decoIcon={<BrandIcon name=\"apple\" />} />\n </Stack>\n <Line label=\"or\" />\n <Form aria-label=\"Sign up with email\" onSubmit={handleSubmit}>\n {error && <Alert type=\"error\" variant=\"inline\" message={error} showCloseButton onClose={() => setError('')} />}\n <TextField id=\"sign-up-page-provider-name\" label=\"Name\" autoComplete=\"name\" value={name} disabled={loading} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n <TextField id=\"sign-up-page-provider-email\" label=\"Email\" type=\"email\" autoComplete=\"username\" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n <TextField id=\"sign-up-page-provider-password\" label=\"Password\" type=\"password\" autoComplete=\"new-password\" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} helperText=\"Use at least 8 characters.\" onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up with Email\" htmlType=\"submit\" loading={loading} />\n </Form>\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Already have an account?</Paragraph>\n <Link href=\"/login\" size=\"body2\">Log in</Link>\n </Cluster>\n </Center>\n );\n}\n",
1831
+ "uses": [
1832
+ "Alert",
1833
+ "BrandIcon",
1834
+ "Button",
1835
+ "Center",
1836
+ "Cluster",
1837
+ "Form",
1838
+ "Heading",
1839
+ "Icon",
1840
+ "Line",
1841
+ "Link",
1842
+ "Paragraph",
1843
+ "Stack",
1844
+ "TextField"
1845
+ ]
1846
+ }
1847
+ ]
1848
+ },
1849
+ {
1850
+ "id": "success-feedback",
1851
+ "title": "Success shows where the person is looking",
1852
+ "kind": "rule",
1853
+ "level": "rule",
1854
+ "area": "state",
1855
+ "situation": "Something the person did has worked.",
1856
+ "answer": "The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.",
1857
+ "why": "Feedback belongs where the person is looking. A change they can see needs only a word on the Button, and a result they cannot see needs a short message that names it.",
1858
+ "do": [
1859
+ "Show `loading` on the Button while a form saves, then 'Saved' for 2 seconds.",
1860
+ "Write a toast as one short sentence in the past tense that names the thing: 'Invite sent to Dana.'",
1861
+ "Show 'Copied' on a copy Button, or the `Check` icon on a copy IconButton, for 2 seconds.",
1862
+ "Show 'Sent' for 2 seconds on a Button that sends an email again, such as 'Send Again'.",
1863
+ "Mount one `Toaster` near the app root, and show every toast with `toast()`."
1864
+ ],
1865
+ "dont": [
1866
+ "Do not say 'successfully'.",
1867
+ "Do not change a Button's label while it is loading, such as to 'Saving…' or 'Deleting…'.",
1868
+ "Do not show a toast for a change the person can already see.",
1869
+ "Do not build a toast from `Alert`. Use `toast()`.",
1870
+ "Do not make the person close a success message."
1871
+ ],
1872
+ "native": "On Apple there is no toast. Show the result in place.",
1873
+ "notBuiltYet": "Scindo on the web has no toast. It shows success in five ways: a 'Saved' Button label, a green caption, an inline Alert, a thank-you that replaces a dialog and a 'Copied' label. The timed ones clear after 1.5, 2, 3 or 4 seconds. Commentify shows toasts through `Alert`, one at a time, and many of them say 'successfully'.",
1874
+ "seenIn": [
1875
+ "Commentify",
1876
+ "Scindo"
1877
+ ]
1878
+ },
1879
+ {
1880
+ "id": "type-to-confirm",
1881
+ "title": "Type to confirm",
1882
+ "kind": "design",
1883
+ "level": "organism",
1884
+ "area": "confirm",
1885
+ "situation": "A person asks to delete something large that cannot be brought back, such as a workspace or an account.",
1886
+ "do": [
1887
+ "Ask for typing only when the loss is permanent and large, such as a workspace with everything in it, or an account.",
1888
+ "Ask the person to type the thing's name when it has one, and a fixed word such as DELETE when it does not.",
1889
+ "Put the text to type in the field's label: 'Type Acme Design to confirm'.",
1890
+ "Keep the action Button `state=\"disabled\"` until the typed text matches exactly.",
1891
+ "Match with case: 'acme design' does not match 'Acme Design'. Allow pasting the text.",
1892
+ "Say above the field what is deleted and what is kept."
1893
+ ],
1894
+ "dont": [
1895
+ "Do not ask for typing for an everyday delete. A plain confirm is enough.",
1896
+ "Do not block pasting into the field.",
1897
+ "Do not change the action's label while it is loading, such as to 'Deleting…'.",
1898
+ "Do not show a failed request as a red caption written by hand. Use an inline error Alert."
1899
+ ],
1900
+ "native": "On Apple use an `.alert` with a `TextField` in it. Put the action in the `.destructive` role and disable it until the text matches.",
1901
+ "notBuiltYet": "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.",
1902
+ "seenIn": [
1903
+ "Commentify",
1904
+ "Scindo"
1905
+ ],
1906
+ "options": [
1907
+ {
1908
+ "id": "modal",
1909
+ "title": "Type the name in a Modal",
1910
+ "useWhen": "The action starts from a menu or a row, away from a settings page.",
1911
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst workspace = 'Acme Design';\nconst otherWorkspaces = ['Acme Marketing', 'Acme Support'];\n\nexport default function TypeToConfirmModal() {\n // Opens on the confirm, as if the person just chose Delete Workspace.\n const [open, setOpen] = useState(true);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // An exact match, with case. Pasting the name is fine.\n const matches = typed === workspace;\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (deleting) return;\n setOpen(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setOpen(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: `Workspace '${workspace}' deleted.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n <Stack gap=\"large\">\n <Heading level={2} size=\"h5\">Workspaces</Heading>\n <Surface padding=\"large\">\n <List items={otherWorkspaces} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h5\">{workspace}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">6 members and 14 channels.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Workspace\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n )}\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Delete Workspace\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete\" loading={deleting} onClickButton={handleDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes the workspace &apos;{workspace}&apos; with its 14 channels, tasks and messages. It cannot be undone.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Members keep their Acme accounts.</Paragraph>\n <TextField id=\"type-to-confirm-name\" label={`Type ${workspace} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n </Modal>\n </Center>\n );\n}\n",
1912
+ "uses": [
1913
+ "Button",
1914
+ "Center",
1915
+ "Cluster",
1916
+ "Heading",
1917
+ "List",
1918
+ "Modal",
1919
+ "Paragraph",
1920
+ "Stack",
1921
+ "Surface",
1922
+ "TextField",
1923
+ "Toaster",
1924
+ "dismissToast",
1925
+ "toast"
1926
+ ]
1927
+ },
1928
+ {
1929
+ "id": "inline",
1930
+ "title": "Type a word in place",
1931
+ "useWhen": "The action lives in a danger zone on a settings page.",
1932
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// An account has no name to type, so the person types a fixed word.\nconst word = 'DELETE';\n\nexport default function TypeToConfirmInline() {\n // Opens with the field showing, as if the person just chose Delete Account.\n const [confirming, setConfirming] = useState(true);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // An exact match, with case. Pasting the word is fine.\n const matches = typed === word;\n\n function handleCancel() {\n setConfirming(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setDeleted(true);\n }, 1200);\n }\n\n // The account is gone, so the page that showed it is gone too.\n if (deleted) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">Your account is deleted</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a note to ada@example.com to say so.</Paragraph>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Account settings</Heading>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Profile</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Ada Brooks, ada@example.com</Paragraph>\n </Stack>\n </Surface>\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Delete account</Heading>\n <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>\n {confirming ? (\n <>\n <TextField id=\"type-to-confirm-word\" label={`Type ${word} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete Account\" loading={deleting} onClickButton={handleDelete} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Account\" onClickButton={() => setConfirming(true)} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n </Stack>\n </Center>\n );\n}\n",
1933
+ "uses": [
1934
+ "Button",
1935
+ "Center",
1936
+ "Cluster",
1937
+ "Heading",
1938
+ "Paragraph",
1939
+ "Stack",
1940
+ "Surface",
1941
+ "TextField"
1942
+ ]
1943
+ }
1944
+ ]
1945
+ },
1946
+ {
1947
+ "id": "unsaved-changes-guard",
1948
+ "title": "Unsaved changes",
1949
+ "kind": "design",
1950
+ "level": "organism",
1951
+ "area": "confirm",
1952
+ "situation": "A person closes or leaves something they changed and did not save.",
1953
+ "do": [
1954
+ "Ask only when there are changes. With nothing changed, close at once.",
1955
+ "Title the Modal with the action it offers, such as 'Save Changes' or 'Discard Reply', and name the thing in the body.",
1956
+ "Put 'Cancel' first, then 'Don't Save', then 'Save'. As in every confirm, the safe choice comes first and the main action last.",
1957
+ "Make 'Cancel' tertiary, 'Don't Save' secondary and 'Save' primary, all `size=\"small\"`.",
1958
+ "Offer 'Keep Editing' and a danger 'Discard' when the product cannot save. 'Keep Editing' comes first.",
1959
+ "Disable 'Cancel' and 'Don't Save' while 'Save' runs, and leave only when the save works."
1960
+ ],
1961
+ "dont": [
1962
+ "Do not ask when nothing changed.",
1963
+ "Do not leave when the save fails. Keep the changes on screen.",
1964
+ "Do not label the choices 'Yes' and 'No'.",
1965
+ "Do not title the Modal 'Are you sure?'."
1966
+ ],
1967
+ "native": "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.",
1968
+ "notBuiltYet": "Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.",
1969
+ "seenIn": [
1970
+ "Scindo"
1971
+ ],
1972
+ "options": [
1973
+ {
1974
+ "id": "save-or-discard",
1975
+ "title": "Save or discard",
1976
+ "useWhen": "The product can save the changes for the person, such as an edited document.",
1977
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst savedText = 'Ship the new onboarding in October.';\n\nexport default function UnsavedChangesSaveOrDiscard() {\n const [saved, setSaved] = useState(savedText);\n const [draft, setDraft] = useState('Ship the new onboarding in October. Hire two designers by November.');\n const [editorOpen, setEditorOpen] = useState(true);\n // Opens on the question, as if the person just chose Close with changes not saved.\n const [asking, setAsking] = useState(true);\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const changed = draft !== saved;\n\n function handleOpenEditor() {\n setDraft(saved);\n setEditorOpen(true);\n }\n\n // With nothing changed, Close closes at once.\n function handleCloseEditor() {\n if (changed) setAsking(true);\n else setEditorOpen(false);\n }\n\n // Escape, a click outside and Cancel all keep the person editing, except while the save runs.\n function handleCancel() {\n if (saving) return;\n setAsking(false);\n }\n\n function handleDontSave() {\n if (saving) return;\n setAsking(false);\n setEditorOpen(false);\n }\n\n function handleSave() {\n if (saving) return;\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n setSaved(draft);\n setAsking(false);\n setEditorOpen(false);\n }, 1200);\n }\n\n if (!editorOpen) {\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Documents</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Q3 plan: {saved}</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Open Q3 Plan\" onClickButton={handleOpenEditor} />\n </Cluster>\n </Stack>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Q3 plan</Heading>\n <TextField id=\"unsaved-changes-guard-body\" label=\"Plan\" multiline maxRows={4} value={draft} onChange={(e) => setDraft(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Close Draft\" onClickButton={handleCloseEditor} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={asking}\n size=\"small\"\n title=\"Save Changes\"\n onClose={handleCancel}\n actions={\n <>\n {/* The safe choice first, the main action last, as in every confirm. */}\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"small\" type=\"secondary\" state={saving ? 'disabled' : 'enabled'} label=\"Don't Save\" onClickButton={handleDontSave} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Save\" loading={saving} onClickButton={handleSave} />\n </>\n }\n >\n <Paragraph measure=\"none\">You changed &apos;Q3 plan&apos; and did not save it.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">If you do not save, your changes are lost.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1978
+ "uses": [
1979
+ "Button",
1980
+ "Center",
1981
+ "Cluster",
1982
+ "Heading",
1983
+ "Modal",
1984
+ "Paragraph",
1985
+ "Stack",
1986
+ "TextField"
1987
+ ]
1988
+ },
1989
+ {
1990
+ "id": "discard",
1991
+ "title": "Discard or keep editing",
1992
+ "useWhen": "The product cannot save for the person, such as a reply that only posts when they say so.",
1993
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function UnsavedChangesDiscard() {\n const [replies, setReplies] = useState<{ id: number; text: string }[]>([]);\n const [writing, setWriting] = useState(true);\n const [draft, setDraft] = useState('Friday works for me. I will move the review to Thursday.');\n // Opens on the question, as if the person just chose Cancel with a reply written.\n const [asking, setAsking] = useState(true);\n const [posting, setPosting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n // Gives each posted reply its own key, even when two read the same.\n const nextId = useRef(1);\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // With nothing written, Cancel closes at once.\n function handleCancelReply() {\n if (draft.trim()) setAsking(true);\n else setWriting(false);\n }\n\n function handleDiscard() {\n setAsking(false);\n setWriting(false);\n setDraft('');\n }\n\n function handlePost() {\n const text = draft.trim();\n if (posting || !text) return;\n setPosting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPosting(false);\n const id = nextId.current++;\n setReplies((list) => [...list, { id, text }]);\n setDraft('');\n setWriting(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Surface padding=\"large\">\n <Stack gap=\"medium\">\n <Heading level={2} size=\"h6\">Dana Lee</Heading>\n <Paragraph size=\"body2\" measure=\"none\">Can we move the launch to Friday?</Paragraph>\n {replies.map((reply) => (\n <Paragraph key={reply.id} tone=\"secondary\" size=\"body2\" measure=\"none\">You: {reply.text}</Paragraph>\n ))}\n {writing ? (\n <>\n <TextField id=\"unsaved-changes-guard-reply\" label=\"Reply\" multiline maxRows={3} value={draft} onChange={(e) => setDraft(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={posting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancelReply} />\n <Button size=\"small\" type=\"primary\" state={draft.trim() ? 'enabled' : 'disabled'} label=\"Reply\" loading={posting} onClickButton={handlePost} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Reply\" onClickButton={() => setWriting(true)} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n <Modal\n isOpen={asking}\n size=\"small\"\n title=\"Discard Reply\"\n onClose={() => setAsking(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Keep Editing\" onClickButton={() => setAsking(false)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Discard\" onClickButton={handleDiscard} />\n </>\n }\n >\n <Paragraph measure=\"none\">Your reply to Dana is not posted. If you discard it, it is gone.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1994
+ "uses": [
1995
+ "Button",
1996
+ "Center",
1997
+ "Cluster",
1998
+ "Heading",
1999
+ "Modal",
2000
+ "Paragraph",
2001
+ "Stack",
2002
+ "Surface",
2003
+ "TextField"
2004
+ ]
2005
+ }
2006
+ ]
2007
+ },
2008
+ {
2009
+ "id": "upgrade-prompt",
2010
+ "title": "Upgrade prompt",
2011
+ "kind": "design",
2012
+ "level": "organism",
2013
+ "area": "confirm",
2014
+ "situation": "A person reaches something their plan does not include, or a limit of their plan.",
2015
+ "do": [
2016
+ "Say what is locked and which plan unlocks it: 'Exporting to PDF is part of the Pro plan.'",
2017
+ "Say which limit was reached, with the number, and when it resets: \"You've used all 50 AI agent responses this month. They start again on December 1.\"",
2018
+ "Offer 'Not Now' as a tertiary Button, then 'Upgrade to Pro' as a primary Button.",
2019
+ "Show 'Upgrade to Pro' only to a person who can change the plan. Tell everyone else to ask a workspace admin, and give them only 'Not Now'.",
2020
+ "Title the Modal 'Upgrade to Pro' only for a person who can upgrade. For everyone else, title it 'Pro Feature'.",
2021
+ "Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, and Escape or a click outside means 'Not Now'.",
2022
+ "Put the notice where the control was, with the same two Buttons, when a limit is reached inside a flow.",
2023
+ "Follow the rule 'An agent refuses clearly' too when the agent is the one refused."
2024
+ ],
2025
+ "dont": [
2026
+ "Do not title the Modal 'Upgrade Required' or 'This is available on Pro plan only'. Name the action: 'Upgrade to Pro'.",
2027
+ "Do not label the way out 'Maybe Later' or 'Close'.",
2028
+ "Do not show an Upgrade Button to someone who cannot upgrade.",
2029
+ "Do not hide the locked control. Let the person press it and learn what unlocks it.",
2030
+ "Do not build the overlay by hand. Use `Modal`, which closes on Escape."
2031
+ ],
2032
+ "native": "On Apple show the notice in place, with an Upgrade Button only for admins. It opens the plan sheet in the app, never a link to a web page.",
2033
+ "notBuiltYet": "Scindo's upgrade prompt on the web is an overlay built by hand that does not close on Escape, is titled 'Upgrade Required' and shows Upgrade to everyone. Commentify's upgrade Modal labels its Buttons 'Maybe Later' and 'Upgrade'.",
2034
+ "seenIn": [
2035
+ "Commentify",
2036
+ "Scindo"
2037
+ ],
2038
+ "options": [
2039
+ {
2040
+ "id": "modal",
2041
+ "title": "Explain in a Modal",
2042
+ "useWhen": "The person pressed something their plan does not include.",
2043
+ "source": "'use client';\nimport { useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nexport default function UpgradePromptModal() {\n // Opens on the Modal, as if the person just chose Export PDF.\n const [open, setOpen] = useState(true);\n\n function handleUpgrade() {\n setOpen(false);\n router.push('/settings/billing?plan=pro');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Q3 plan</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* The locked control stays on the page, so the person can find out what unlocks it. */}\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Share\" />\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export PDF\" decoIcon=\"Lock\" onClickButton={() => setOpen(true)} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n // The title names the action only for a person who can take it.\n title={canChangePlan ? 'Upgrade to Pro' : 'Pro Feature'}\n onClose={() => setOpen(false)}\n actions={\n canChangePlan ? (\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={handleUpgrade} />\n </>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setOpen(false)} />\n )\n }\n >\n <Paragraph measure=\"none\">Exporting to PDF is part of the Pro plan. Acme Design is on the Free plan.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'Pro also adds version history and unlimited guests, for $8 per member each month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro.'}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
2044
+ "uses": [
2045
+ "Button",
2046
+ "Center",
2047
+ "Cluster",
2048
+ "Heading",
2049
+ "Modal",
2050
+ "Paragraph",
2051
+ "Stack"
2052
+ ]
2053
+ },
2054
+ {
2055
+ "id": "inline",
2056
+ "title": "Replace the control",
2057
+ "useWhen": "A limit was reached inside a flow. The notice takes the place of the control that hit it.",
2058
+ "source": "'use client';\nimport { useState } from 'react';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the router from its framework, such as Next's useRouter().\nconst router = { push: (url: string) => console.info(`Go to ${url}`) };\n\n// A real app reads this from the person's role. Only an admin can change the plan.\nconst canChangePlan = true;\n\nconst thread = [\n { id: 'm1', from: 'Dana Lee', text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme agent', text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Dana Lee', text: 'Draft the launch email, please.' },\n];\n\nexport default function UpgradePromptInline() {\n // Opens on the notice, as if the workspace just used its last AI agent response of the month.\n const [showNotice, setShowNotice] = useState(true);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n <Stack gap=\"medium\">\n {thread.map((m) => (\n <Stack key={m.id} gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.from}</Paragraph>\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Stack>\n ))}\n </Stack>\n {showNotice ? (\n // The notice takes the place of the message box, where the person was about to type.\n <Surface padding=\"medium\">\n <Stack gap=\"medium\">\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">You&apos;ve used all 50 AI agent responses this month. They start again on December 1.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {canChangePlan\n ? 'The Pro plan gives Acme Design 1,000 AI agent responses a month.'\n : 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'}\n </Paragraph>\n </Stack>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setShowNotice(false)} />\n {canChangePlan && (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n )}\n </Cluster>\n </Stack>\n </Surface>\n ) : (\n // After 'Not Now' the message box comes back, closed until the replies start again.\n <TextField id=\"upgrade-prompt-message\" label=\"Message the agent\" value=\"\" placeholder=\"Agent replies start again on December 1.\" disabled onChange={() => {}} />\n )}\n </Stack>\n </Center>\n );\n}\n",
2059
+ "uses": [
2060
+ "Button",
2061
+ "Center",
2062
+ "Cluster",
2063
+ "Heading",
2064
+ "Paragraph",
2065
+ "Stack",
2066
+ "Surface",
2067
+ "TextField"
2068
+ ]
2069
+ }
2070
+ ]
2071
+ }
2072
+ ]
2073
+ }