oneslash-design-system 2.15.0 → 2.17.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.
- package/README.md +6 -1
- package/dist/DESIGN.md +100 -73
- package/dist/cases/accept-invite/signed-in.d.ts +1 -0
- package/dist/cases/accept-invite/signed-in.jsx +57 -0
- package/dist/cases/accept-invite/signed-out.d.ts +1 -0
- package/dist/cases/accept-invite/signed-out.jsx +33 -0
- package/dist/cases/accept-invite.md +161 -0
- package/dist/cases/agent-asks-before-risky-action.md +1 -1
- package/dist/cases/agent-cancels-when-unanswered.md +1 -1
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +168 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +432 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +656 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +103 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.jsx +10 -0
- package/dist/cases/auth-gate-loading/spinner.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner.jsx +10 -0
- package/dist/cases/auth-gate-loading.md +70 -0
- package/dist/cases/check-your-email/alert-on-login.d.ts +1 -0
- package/dist/cases/check-your-email/alert-on-login.jsx +78 -0
- package/dist/cases/check-your-email/page.d.ts +1 -0
- package/dist/cases/check-your-email/page.jsx +49 -0
- package/dist/cases/check-your-email.md +184 -0
- package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +286 -0
- package/dist/cases/confirm-destructive-action/inline.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/inline.jsx +69 -0
- package/dist/cases/confirm-destructive-action/modal.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/modal.jsx +66 -0
- package/dist/cases/confirm-destructive-action.md +211 -0
- package/dist/cases/confirm-dialogs.md +36 -0
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +208 -0
- package/dist/cases/create-modal/quick.d.ts +1 -0
- package/dist/cases/create-modal/quick.jsx +80 -0
- package/dist/cases/create-modal/with-settings.d.ts +1 -0
- package/dist/cases/create-modal/with-settings.jsx +99 -0
- package/dist/cases/create-modal.md +244 -0
- package/dist/cases/device-login/popup.d.ts +1 -0
- package/dist/cases/device-login/popup.jsx +14 -0
- package/dist/cases/device-login/provider-first.d.ts +1 -0
- package/dist/cases/device-login/provider-first.jsx +98 -0
- package/dist/cases/device-login.md +171 -0
- package/dist/cases/email-confirmed/alert-on-login.d.ts +1 -0
- package/dist/cases/email-confirmed/alert-on-login.jsx +78 -0
- package/dist/cases/email-confirmed/page.d.ts +1 -0
- package/dist/cases/email-confirmed/page.jsx +21 -0
- package/dist/cases/email-confirmed.md +151 -0
- package/dist/cases/empty-list/region.d.ts +1 -0
- package/dist/cases/empty-list/region.jsx +13 -0
- package/dist/cases/empty-list/section.d.ts +1 -0
- package/dist/cases/empty-list/section.jsx +17 -0
- package/dist/cases/empty-list.md +77 -0
- package/dist/cases/empty-lists.md +35 -0
- package/dist/cases/empty-not-set-up/action.d.ts +1 -0
- package/dist/cases/empty-not-set-up/action.jsx +16 -0
- package/dist/cases/empty-not-set-up/pointer.d.ts +1 -0
- package/dist/cases/empty-not-set-up/pointer.jsx +13 -0
- package/dist/cases/empty-not-set-up.md +88 -0
- package/dist/cases/empty-search/clear-search.d.ts +1 -0
- package/dist/cases/empty-search/clear-search.jsx +29 -0
- package/dist/cases/empty-search.md +77 -0
- package/dist/cases/error-page/full-page.d.ts +1 -0
- package/dist/cases/error-page/full-page.jsx +19 -0
- package/dist/cases/error-page/in-shell.d.ts +1 -0
- package/dist/cases/error-page/in-shell.jsx +39 -0
- package/dist/cases/error-page.md +107 -0
- package/dist/cases/feedback-form/modal.d.ts +1 -0
- package/dist/cases/feedback-form/modal.jsx +89 -0
- package/dist/cases/feedback-form.md +139 -0
- package/dist/cases/forgot-password/in-place.d.ts +1 -0
- package/dist/cases/forgot-password/in-place.jsx +155 -0
- package/dist/cases/forgot-password/own-page.d.ts +1 -0
- package/dist/cases/forgot-password/own-page.jsx +99 -0
- package/dist/cases/forgot-password.md +328 -0
- package/dist/cases/form-errors.md +32 -0
- package/dist/cases/import-checklist/modal.d.ts +1 -0
- package/dist/cases/import-checklist/modal.jsx +125 -0
- package/dist/cases/import-checklist.md +188 -0
- package/dist/cases/inline-form-feedback/button-label.d.ts +1 -0
- package/dist/cases/inline-form-feedback/button-label.jsx +54 -0
- package/dist/cases/inline-form-feedback/inline-alert.d.ts +1 -0
- package/dist/cases/inline-form-feedback/inline-alert.jsx +49 -0
- package/dist/cases/inline-form-feedback/toast.d.ts +1 -0
- package/dist/cases/inline-form-feedback/toast.jsx +66 -0
- package/dist/cases/inline-form-feedback.md +237 -0
- package/dist/cases/invite-member/by-email.d.ts +1 -0
- package/dist/cases/invite-member/by-email.jsx +98 -0
- package/dist/cases/invite-member/by-link.d.ts +1 -0
- package/dist/cases/invite-member/by-link.jsx +122 -0
- package/dist/cases/invite-member.md +321 -0
- package/dist/cases/load-failure/inline.d.ts +1 -0
- package/dist/cases/load-failure/inline.jsx +52 -0
- package/dist/cases/load-failure/region.d.ts +1 -0
- package/dist/cases/load-failure/region.jsx +34 -0
- package/dist/cases/load-failure.md +155 -0
- package/dist/cases/log-out-confirm/modal.d.ts +1 -0
- package/dist/cases/log-out-confirm/modal.jsx +57 -0
- package/dist/cases/log-out-confirm.md +106 -0
- package/dist/cases/login-page/centered.jsx +10 -7
- package/dist/cases/login-page/email-only.jsx +11 -8
- package/dist/cases/login-page/provider-first.jsx +12 -9
- package/dist/cases/login-page/split.jsx +11 -8
- package/dist/cases/login-page.md +58 -41
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +252 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +651 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +310 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +356 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +179 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +371 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +189 -0
- package/dist/cases/not-found-page/full-page.d.ts +1 -0
- package/dist/cases/not-found-page/full-page.jsx +16 -0
- package/dist/cases/not-found-page/in-shell.d.ts +1 -0
- package/dist/cases/not-found-page/in-shell.jsx +36 -0
- package/dist/cases/not-found-page.md +98 -0
- package/dist/cases/oauth-consent/simple.d.ts +1 -0
- package/dist/cases/oauth-consent/simple.jsx +73 -0
- package/dist/cases/oauth-consent/with-scope.d.ts +1 -0
- package/dist/cases/oauth-consent/with-scope.jsx +89 -0
- package/dist/cases/oauth-consent.md +233 -0
- package/dist/cases/rename/inline.d.ts +1 -0
- package/dist/cases/rename/inline.jsx +58 -0
- package/dist/cases/rename/modal.d.ts +1 -0
- package/dist/cases/rename/modal.jsx +70 -0
- package/dist/cases/rename.md +205 -0
- package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +552 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +247 -0
- package/dist/cases/route-loading/full-screen.d.ts +1 -0
- package/dist/cases/route-loading/full-screen.jsx +8 -0
- package/dist/cases/route-loading/region.d.ts +1 -0
- package/dist/cases/route-loading/region.jsx +26 -0
- package/dist/cases/route-loading.md +84 -0
- package/dist/cases/set-new-password/form.d.ts +1 -0
- package/dist/cases/set-new-password/form.jsx +130 -0
- package/dist/cases/set-new-password/invalid-link.d.ts +1 -0
- package/dist/cases/set-new-password/invalid-link.jsx +50 -0
- package/dist/cases/set-new-password.md +247 -0
- package/dist/cases/sign-up-page/centered.d.ts +1 -0
- package/dist/cases/sign-up-page/centered.jsx +124 -0
- package/dist/cases/sign-up-page/provider-first.d.ts +1 -0
- package/dist/cases/sign-up-page/provider-first.jsx +124 -0
- package/dist/cases/sign-up-page/split.d.ts +1 -0
- package/dist/cases/sign-up-page/split.jsx +134 -0
- package/dist/cases/sign-up-page.md +478 -0
- package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +247 -0
- package/dist/cases/success-feedback.md +35 -0
- package/dist/cases/type-to-confirm/inline.d.ts +1 -0
- package/dist/cases/type-to-confirm/inline.jsx +69 -0
- package/dist/cases/type-to-confirm/modal.d.ts +1 -0
- package/dist/cases/type-to-confirm/modal.jsx +73 -0
- package/dist/cases/type-to-confirm.md +222 -0
- package/dist/cases/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +96 -0
- package/dist/cases/unsaved-changes-guard/discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/discard.jsx +81 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.jsx +85 -0
- package/dist/cases/unsaved-changes-guard.md +239 -0
- package/dist/cases/upgrade-prompt/inline.d.ts +1 -0
- package/dist/cases/upgrade-prompt/inline.jsx +52 -0
- package/dist/cases/upgrade-prompt/modal.d.ts +1 -0
- package/dist/cases/upgrade-prompt/modal.jsx +43 -0
- package/dist/cases/upgrade-prompt.md +174 -0
- package/dist/cases.json +3138 -59
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +6 -4
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/emptyBox.d.ts +6 -1
- package/dist/components/emptyBox.jsx +4 -2
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/loadingScreen.d.ts +5 -1
- package/dist/components/loadingScreen.jsx +4 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/modal.d.ts +2 -1
- package/dist/components/modal.jsx +20 -8
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +9 -1
- package/dist/components/radioGroup.jsx +20 -9
- package/dist/components/select.d.ts +2 -1
- package/dist/components/select.jsx +4 -2
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/tab.jsx +3 -2
- package/dist/components/tabsContainer.d.ts +4 -1
- package/dist/components/tabsContainer.jsx +7 -3
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textField.d.ts +5 -1
- package/dist/components/textField.jsx +7 -3
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/toaster.d.ts +12 -0
- package/dist/components/toaster.jsx +103 -0
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/internal/alert.d.ts +4 -0
- package/dist/internal/alert.js +6 -0
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/internal/modal.d.ts +2 -0
- package/dist/internal/modal.js +21 -0
- package/dist/internal/toaster.d.ts +19 -0
- package/dist/internal/toaster.js +50 -0
- package/dist/native-mapping.json +38 -1
- package/dist/stories/Alert.stories.d.ts +1 -0
- package/dist/stories/Alert.stories.jsx +16 -0
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +82 -0
- package/dist/stories/Cases.generated.stories.jsx +164 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/EmptyBox.stories.d.ts +2 -0
- package/dist/stories/EmptyBox.stories.jsx +16 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/Heading.stories.d.ts +6 -0
- package/dist/stories/Heading.stories.jsx +10 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/LoadingScreen.stories.d.ts +1 -0
- package/dist/stories/LoadingScreen.stories.jsx +8 -0
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/Modal.stories.d.ts +2 -0
- package/dist/stories/Modal.stories.jsx +36 -0
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +3 -0
- package/dist/stories/RadioGroup.stories.jsx +54 -1
- package/dist/stories/Select.stories.d.ts +1 -0
- package/dist/stories/Select.stories.jsx +14 -0
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/TabsContainer.stories.d.ts +1 -0
- package/dist/stories/TabsContainer.stories.jsx +12 -0
- package/dist/stories/TextField.stories.d.ts +2 -0
- package/dist/stories/TextField.stories.jsx +22 -0
- package/dist/stories/Toaster.stories.d.ts +6 -0
- package/dist/stories/Toaster.stories.jsx +29 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
package/dist/cases.json
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
{
|
|
2
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're invited to Acme Design</Heading>\n {/* 'Invited by' shows on every invite. */}\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" decorative />\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're invited to Acme Design</Heading>\n <Cluster gap=\"small\">\n <UserImage userHandle=\"Dana Lee\" decorative />\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
|
+
},
|
|
3
71
|
{
|
|
4
72
|
"id": "agent-asks-before-risky-action",
|
|
5
73
|
"title": "An agent asks before a risky action",
|
|
@@ -13,7 +81,7 @@
|
|
|
13
81
|
"List every step in the card, in the order the agent will do them.",
|
|
14
82
|
"Offer a way to see the full changes, such as a View Changes button, before the approve button is pressed.",
|
|
15
83
|
"Let the person edit the plan or cancel it, not only approve it.",
|
|
16
|
-
"
|
|
84
|
+
"Mark the card Approved or Cancelled once it is decided, and remove its buttons."
|
|
17
85
|
],
|
|
18
86
|
"dont": [
|
|
19
87
|
"Do not carry out a risky action before the person approves it.",
|
|
@@ -38,7 +106,7 @@
|
|
|
38
106
|
"do": [
|
|
39
107
|
"Keep the card and its buttons open until someone answers or the request is cancelled.",
|
|
40
108
|
"Notify the person who asked when the agent needs their answer.",
|
|
41
|
-
"
|
|
109
|
+
"Mark the card Cancelled when a request is cancelled, and post one line on what was not done.",
|
|
42
110
|
"List questions asked before a plan that nobody answered as open questions in that plan."
|
|
43
111
|
],
|
|
44
112
|
"dont": [
|
|
@@ -50,6 +118,321 @@
|
|
|
50
118
|
"Scindo"
|
|
51
119
|
]
|
|
52
120
|
},
|
|
121
|
+
{
|
|
122
|
+
"id": "agent-options",
|
|
123
|
+
"title": "Agent options",
|
|
124
|
+
"kind": "design",
|
|
125
|
+
"level": "organism",
|
|
126
|
+
"area": "agent",
|
|
127
|
+
"situation": "The agent sees two to four ways forward and needs the person to pick one. These are ways forward for the agent's own work. For a fact or a decision only the person has, see the case 'Agent question'.",
|
|
128
|
+
"do": [
|
|
129
|
+
"Put the card in the agent's `Message`, in a `Surface` with the question as its heading.",
|
|
130
|
+
"Show each way forward as an option of `<RadioGroup variant=\"card\">`, with a `secondLabel` that says what it means.",
|
|
131
|
+
"Give the agent's pick the `badge` 'Recommended', on one option only.",
|
|
132
|
+
"Preselect the recommended option: the agent has a view, and the person can pick another. With no recommended option, preselect nothing.",
|
|
133
|
+
"Disable 'Choose' until an option is picked when nothing is preselected.",
|
|
134
|
+
"Give the RadioGroup an `aria-label` that starts with the question.",
|
|
135
|
+
"Order the buttons 'Cancel', then 'Choose' as the primary Button, at the start of the row.",
|
|
136
|
+
"Make the pressed Button `loading` and keep its label. Disable the options and the other Button while the request runs.",
|
|
137
|
+
"Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
|
|
138
|
+
"Show the waiting time on the card while it waits: 'Waits 10 more minutes, then cancels.'",
|
|
139
|
+
"Notify the person who asked when the agent needs their answer.",
|
|
140
|
+
"Keep only the chosen option once it is decided, as text, with a 'Chosen' `Tag`. Remove the buttons.",
|
|
141
|
+
"Mark the card with a 'Cancelled' `Tag` when it is cancelled, and add one compact agent row under it that says what was not done: 'Cancelled. Nothing was changed.'",
|
|
142
|
+
"Mark the card Cancelled when the waiting time is up, with the same row on what was not done.",
|
|
143
|
+
"Announce the decided `Tag` politely: the app wraps it in a polite live region.",
|
|
144
|
+
"Move focus to the message box once the card is decided, since its buttons are gone."
|
|
145
|
+
],
|
|
146
|
+
"dont": [
|
|
147
|
+
"Do not offer one option, or more than four.",
|
|
148
|
+
"Do not give more than one option the 'Recommended' badge.",
|
|
149
|
+
"Do not preselect an option the agent does not recommend.",
|
|
150
|
+
"Do not recommend or preselect an option that does more than the others, such as one that deletes, publishes or widens access.",
|
|
151
|
+
"Do not act on an option before the person presses Choose.",
|
|
152
|
+
"Do not change a Button's label while it is loading, such as to 'Confirming...'."
|
|
153
|
+
],
|
|
154
|
+
"notBuiltYet": "Scindo's options card labels its button 'Confirm Selection', which reads 'Confirming...' while it loads, and marks a decided card 'Selected'. With no recommended option it preselects the first one. Scindo's Apple app shows no options card.",
|
|
155
|
+
"seenIn": [
|
|
156
|
+
"Scindo"
|
|
157
|
+
],
|
|
158
|
+
"options": [
|
|
159
|
+
{
|
|
160
|
+
"id": "cards",
|
|
161
|
+
"title": "Option cards",
|
|
162
|
+
"useWhen": "The default: each way forward is a card with a line on what it means.",
|
|
163
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Surface from 'oneslash-design-system/components/surface';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\nconst question = 'Which layout should the pricing page use?';\n\nconst options = [\n { value: 'columns', label: 'Three columns', secondLabel: 'One card per plan, side by side. Easy to compare.', badge: 'Recommended' },\n { value: 'table', label: 'Table', secondLabel: 'Plans as columns and features as rows.' },\n { value: 'switch', label: 'One plan at a time', secondLabel: 'A switch moves between the plans.' },\n];\n\ntype Status = 'open' | 'chosen' | 'cancelled';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentOptionsCards() {\n // The recommended option starts selected: the agent has a view, and the person can pick another.\n const [selected, setSelected] = useState('columns');\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'choose' | 'cancel' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Decided once: the buttons go away, so a second click cannot change it.\n // Nothing takes their place, so a real app moves focus to the message box.\n function decide(action: 'choose' | 'cancel') {\n if (pending || status !== 'open' || (action === 'choose' && selected === '')) return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus(action === 'choose' ? 'chosen' : 'cancelled');\n }, 1200);\n }\n\n const chosen = options.find((o) => o.value === selected);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n {status === 'chosen' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Chosen\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n {status === 'open' && (\n <>\n <RadioGroup\n variant=\"card\"\n aria-label={question}\n options={options}\n selectedValue={selected}\n onChange={setSelected}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'choose' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button size=\"small\" type=\"primary\" state={selected === '' || pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Choose\" loading={pending === 'choose'} onClickButton={() => decide('choose')} />\n </Cluster>\n </>\n )}\n {/* Once decided, only the chosen option is left on the card. */}\n {status === 'chosen' && chosen && <Paragraph measure=\"none\">{chosen.label}</Paragraph>}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
164
|
+
"uses": [
|
|
165
|
+
"Button",
|
|
166
|
+
"Center",
|
|
167
|
+
"Cluster",
|
|
168
|
+
"Heading",
|
|
169
|
+
"Message",
|
|
170
|
+
"Paragraph",
|
|
171
|
+
"RadioGroup",
|
|
172
|
+
"Stack",
|
|
173
|
+
"Surface",
|
|
174
|
+
"Tag",
|
|
175
|
+
"TimeStamp",
|
|
176
|
+
"UserImage"
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"id": "agent-pending-reply",
|
|
183
|
+
"title": "Agent at work",
|
|
184
|
+
"kind": "design",
|
|
185
|
+
"level": "organism",
|
|
186
|
+
"area": "agent",
|
|
187
|
+
"situation": "The agent is working on a request in the thread, and its reply is not ready yet.",
|
|
188
|
+
"do": [
|
|
189
|
+
"Follow the rule 'An agent shows its progress': one row in the thread, where the reply will appear.",
|
|
190
|
+
"Mark the row as the rule 'An agent says what it is' says: an icon avatar, the agent's name, an 'Agent' `Tag`, the time and the model line.",
|
|
191
|
+
"Show the seconds so far in a caption, 'Working for 12 seconds', and update it once a second.",
|
|
192
|
+
"Show the steps in a `StepList`: the finished ones with a check, and the current one running, in plain words.",
|
|
193
|
+
"Leave out steps the agent has not started, unless it knows them.",
|
|
194
|
+
"Put the only 'Stop' in the row's `footer`, for the whole run, and under the reply while it is written.",
|
|
195
|
+
"Make 'Stop' `loading` while the run stops. Once the run has ended, replace the row in place with a note on what was and was not done.",
|
|
196
|
+
"Say 'Stopped. Nothing was changed.' when nothing was. When part was done, say what: 'Stopped after 2 of 4 steps. The rest of the plan was not done.'",
|
|
197
|
+
"Say 'Stopped. Nothing was written.' when a streaming reply is stopped before any text.",
|
|
198
|
+
"Keep the text and say 'Stopped before the reply was finished.' when a streaming reply is stopped after some text.",
|
|
199
|
+
"Show a failed run in the row: an inline error `Alert` with no close button and `autoDismiss={false}`, the failed step marked, and 'Try Again'.",
|
|
200
|
+
"Turn the row into the agent's reply when the run is done, and remove 'Stop'.",
|
|
201
|
+
"Move focus to the message box when 'Stop' goes away and no other control takes its place.",
|
|
202
|
+
"Announce the changing part politely, such as the running step: the app wraps it in a polite live region, since `StepList` has none.",
|
|
203
|
+
"Give the list that holds the rows `role=\"log\"`."
|
|
204
|
+
],
|
|
205
|
+
"dont": [
|
|
206
|
+
"Do not show a spinner with no words.",
|
|
207
|
+
"Do not hide 'Stop' while the agent writes its reply.",
|
|
208
|
+
"Do not put 'Stop' in the Composer of a thread that people also write in.",
|
|
209
|
+
"Do not say the agent stopped before the run has really ended.",
|
|
210
|
+
"Do not report a failed run only in a toast away from the row."
|
|
211
|
+
],
|
|
212
|
+
"notBuiltYet": "Scindo on the web shows no 'Agent' tag on the progress row, its Stop is an icon button with a cross, and its current step is a blinking dot. Scindo's Apple app shows no progress row: while the agent works, Send turns into Stop.",
|
|
213
|
+
"seenIn": [
|
|
214
|
+
"Scindo"
|
|
215
|
+
],
|
|
216
|
+
"options": [
|
|
217
|
+
{
|
|
218
|
+
"id": "steps",
|
|
219
|
+
"title": "Steps",
|
|
220
|
+
"useWhen": "The run has steps to show.",
|
|
221
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Alert from 'oneslash-design-system/components/alert';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };\nconst runStartedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Finding the new plans', done: 'Found the new plans' },\n { doing: 'Reading the pricing page', done: 'Read the pricing page' },\n { doing: 'Comparing the prices', done: 'Compared the prices' },\n];\n\nconst reply = \"The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15.\";\n\ntype Phase = 'running' | 'stopping' | 'stopped' | 'failed' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(current: number, failed: boolean): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) =>\n i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: failed ? 'failed' : 'running' },\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPendingReplySteps() {\n // Opens on a still of a run in progress, 12 seconds in, so the picture in the docs does not move.\n // 'Run Again' runs it live: the seconds tick and the steps go on.\n const [phase, setPhase] = useState<Phase>('running');\n const [current, setCurrent] = useState(2);\n const [seconds, setSeconds] = useState(12);\n const [startedAt, setStartedAt] = useState(runStartedAt);\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The first live run fails at the pricing page, so the example shows the failed row; 'Try Again' then works.\n const triedAgain = useRef(false);\n\n // On unmount it stops the run, its clock and the cancel request.\n useEffect(() => () => {\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function stopTimers() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === 2 && !triedAgain.current) {\n stopTimers();\n setPhase('failed');\n return;\n }\n if (at === plan.length - 1) {\n stopTimers();\n setPhase('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n function runLive() {\n stopTimers();\n setPhase('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n }\n\n function tryAgain() {\n triedAgain.current = true;\n runLive();\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setPhase('stopped');\n // 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.\n focusNext.current = () => runAgainButton.current?.focus();\n }, 1200);\n }\n\n const working = phase === 'running' || phase === 'stopping';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : phase === 'failed' ? (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Try Again\" onClickButton={tryAgain} />\n </Cluster>\n ) : phase === 'stopped' ? (\n <Cluster>\n <Button ref={runAgainButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Run Again\" onClickButton={runLive} />\n </Cluster>\n ) : undefined\n }\n >\n {phase === 'done' ? (\n // The run is over: the row is the reply, and Stop is gone. A real app moves focus to the message box.\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : phase === 'stopped' ? (\n <Paragraph measure=\"none\">Stopped. Nothing was changed.</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n {working && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>}\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current, phase === 'failed')} />\n {phase === 'failed' && (\n // It reports where the run stands, so it has no close button and stays.\n <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message=\"Acme Agent could not open the pricing page. Nothing was changed.\" />\n )}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
222
|
+
"uses": [
|
|
223
|
+
"Alert",
|
|
224
|
+
"Button",
|
|
225
|
+
"Center",
|
|
226
|
+
"Cluster",
|
|
227
|
+
"Heading",
|
|
228
|
+
"Message",
|
|
229
|
+
"Paragraph",
|
|
230
|
+
"Stack",
|
|
231
|
+
"StepList",
|
|
232
|
+
"Tag",
|
|
233
|
+
"TimeStamp",
|
|
234
|
+
"UserImage"
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"id": "streaming",
|
|
239
|
+
"title": "Streaming reply",
|
|
240
|
+
"useWhen": "The reply text arrives as it is written.",
|
|
241
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };\nconst runStartedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Reading the pricing page', done: 'Read the pricing page' },\n { doing: 'Writing the reply', done: 'Wrote the reply' },\n];\nconst writing = plan.length - 1;\n\nconst words = \"The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15. The Team plan is missing too.\".split(' ');\n\ntype Phase = 'running' | 'stopping' | 'stopped' | 'done';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) =>\n i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' },\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPendingReplyStreaming() {\n // Opens on a still of a run that is writing its reply, 18 seconds in, so the picture in the docs does not move.\n // 'Run Again' runs it live: the seconds tick and the reply grows word by word.\n const [phase, setPhase] = useState<Phase>('running');\n const [current, setCurrent] = useState(writing);\n const [shown, setShown] = useState(10);\n const [seconds, setSeconds] = useState(18);\n const [startedAt, setStartedAt] = useState(runStartedAt);\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the run, its clock and the cancel request.\n useEffect(() => () => {\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function stopTimers() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n }\n\n // Stands in for the agent's run: a step every 1.5 seconds, then a word of the reply every 0.2 seconds.\n function advance(at: number, count: number) {\n if (at < writing) {\n step.current = setTimeout(() => {\n setCurrent(at + 1);\n advance(at + 1, 0);\n }, 1500);\n return;\n }\n step.current = setTimeout(() => {\n if (count === words.length) {\n stopTimers();\n setPhase('done');\n return;\n }\n setShown(count + 1);\n advance(at, count + 1);\n }, 200);\n }\n\n function runLive() {\n stopTimers();\n setPhase('running');\n setCurrent(0);\n setShown(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0, 0);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setPhase('stopped');\n // 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.\n focusNext.current = () => runAgainButton.current?.focus();\n }, 1200);\n }\n\n const working = phase === 'running' || phase === 'stopping';\n const text = words.slice(0, shown).join(' ');\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n working ? (\n // The only Stop, under the reply while it is written. It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : phase === 'stopped' ? (\n <Cluster>\n <Button ref={runAgainButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Run Again\" onClickButton={runLive} />\n </Cluster>\n ) : undefined\n }\n >\n {phase === 'done' ? (\n // The run is over: the row is a plain reply, and Stop is gone. A real app moves focus to the message box.\n <Paragraph measure=\"none\">{text}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n {working && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>}\n {working && <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />}\n {text !== '' && <Paragraph measure=\"none\">{text}</Paragraph>}\n {/* A stop before any text says nothing was written; a stop after some text keeps it. */}\n {phase === 'stopped' && (\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">\n {text === '' ? 'Stopped. Nothing was written.' : 'Stopped before the reply was finished.'}\n </Paragraph>\n )}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
242
|
+
"uses": [
|
|
243
|
+
"Button",
|
|
244
|
+
"Center",
|
|
245
|
+
"Cluster",
|
|
246
|
+
"Heading",
|
|
247
|
+
"Message",
|
|
248
|
+
"Paragraph",
|
|
249
|
+
"Stack",
|
|
250
|
+
"StepList",
|
|
251
|
+
"Tag",
|
|
252
|
+
"TimeStamp",
|
|
253
|
+
"UserImage"
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"id": "agent-plan-proposal",
|
|
260
|
+
"title": "Plan proposal",
|
|
261
|
+
"kind": "design",
|
|
262
|
+
"level": "organism",
|
|
263
|
+
"area": "agent",
|
|
264
|
+
"situation": "The agent is about to change shared work and needs the person to approve it first.",
|
|
265
|
+
"do": [
|
|
266
|
+
"Follow the rule 'An agent asks before a risky action': the agent does nothing until the person presses 'Approve'.",
|
|
267
|
+
"Put the card in the agent's `Message`, in a `Surface` with a heading, the plan, then the buttons.",
|
|
268
|
+
"List every step in a `<StepList numbered>`, in the order the agent will do them, each one waiting.",
|
|
269
|
+
"Offer 'View Changes' when the changes are ready, so the person sees them before they approve. It opens a `Modal` that lists them.",
|
|
270
|
+
"List each changed file in that Modal with one line on what changes in it. ODS has no diff part yet.",
|
|
271
|
+
"Order the steps card's buttons 'Cancel', 'Edit', then 'Approve' as the primary Button, at the start of the row under the plan.",
|
|
272
|
+
"Order the changes card's buttons 'Cancel', 'Request Changes', then 'Approve' as the primary Button.",
|
|
273
|
+
"Let the product write the label 'Approve'. The agent never writes the label of an approve or merge button.",
|
|
274
|
+
"Show the waiting time on the card while it waits, and while the person edits: 'Waits 10 more minutes, then cancels.'",
|
|
275
|
+
"Notify the person who asked when the agent needs their answer.",
|
|
276
|
+
"Make the pressed Button `loading` and keep its label. Disable the others while the request runs.",
|
|
277
|
+
"Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
|
|
278
|
+
"Mark the card with an 'Approved' or 'Cancelled' `Tag` once it is decided, and remove its buttons.",
|
|
279
|
+
"Announce the decided `Tag` politely: the app wraps it in a polite live region.",
|
|
280
|
+
"Keep an approved card as the record: the steps as they were approved, none running, and no buttons.",
|
|
281
|
+
"Move the run to its own progress row under the card, as the case 'Agent at work' shows, with its 'Stop'.",
|
|
282
|
+
"Say how far a stopped run got: 'Stopped after 2 of 4 steps. The rest of the plan was not done.' Take the count from the server's answer, not from the list on screen.",
|
|
283
|
+
"Add one compact agent row under a cancelled card that says what was not done: 'Cancelled. Nothing was changed.'",
|
|
284
|
+
"Mark the card Cancelled when the waiting time is up, with the same row on what was not done.",
|
|
285
|
+
"Turn the steps into a `Textarea` on 'Edit', one step per line, with 'Discard' and 'Save'.",
|
|
286
|
+
"Use 'Discard' to leave an edit on an agent card, since 'Cancel' there cancels the proposal. Editing your own message keeps 'Cancel'.",
|
|
287
|
+
"Send the edited steps to the agent on 'Save'. The plan comes back with the new steps, still waiting for a yes.",
|
|
288
|
+
"Open a `Textarea` labelled 'What should change?' on 'Request Changes', with 'Discard' and 'Send'.",
|
|
289
|
+
"Say on the card that the agent is redoing the changes once the request is sent, and remove its buttons.",
|
|
290
|
+
"Move focus to the field when 'Edit' or 'Request Changes' opens it, and back to that button after 'Discard', or after 'Save' in an edit.",
|
|
291
|
+
"Move focus to 'Stop' when the run's progress row appears.",
|
|
292
|
+
"Move focus to the message box when the card's buttons or 'Stop' go away and nothing takes their place."
|
|
293
|
+
],
|
|
294
|
+
"dont": [
|
|
295
|
+
"Do not carry out any step before the person approves.",
|
|
296
|
+
"Do not replace the steps or the changes with a one-line summary.",
|
|
297
|
+
"Do not label the approve button 'Proceed', 'Confirm' or 'OK', or let the agent choose its label.",
|
|
298
|
+
"Do not change a Button's label while it is loading, such as to 'Proceeding...'.",
|
|
299
|
+
"Do not let a second click on a decided card approve or cancel it again.",
|
|
300
|
+
"Do not treat no answer as approval.",
|
|
301
|
+
"Do not show the run's steps as running on the card. The run has its own row."
|
|
302
|
+
],
|
|
303
|
+
"notBuiltYet": "Scindo's plan button reads 'Proceed' and comes first, and its buttons change label while loading, such as 'Proceeding...' and 'Cancelling...'. Its plan card has no View Changes button and shows no waiting time. Scindo's Apple app shows no plan card.",
|
|
304
|
+
"seenIn": [
|
|
305
|
+
"Scindo"
|
|
306
|
+
],
|
|
307
|
+
"options": [
|
|
308
|
+
{
|
|
309
|
+
"id": "steps",
|
|
310
|
+
"title": "Steps",
|
|
311
|
+
"useWhen": "The agent will carry out a list of steps.",
|
|
312
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Surface from 'oneslash-design-system/components/surface';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };\nconst proposedAt = new Date('2025-01-15T11:41:00Z');\n\nconst firstSteps = [\n 'Change the Pro price from $12 to $15',\n 'Add the Team plan at $25 per seat',\n 'Update the plan table on the pricing page',\n 'Open a pull request for review',\n];\n\nconst reply = 'The pricing page is updated, and the pull request is open for review.';\n\ntype Status = 'open' | 'editing' | 'approved' | 'cancelled';\ntype Run = 'running' | 'stopping' | 'stopped' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(steps: string[], current: number): StepListStep[] {\n return steps.slice(0, current + 1).map((label, i) => ({ label, status: i < current ? 'done' : 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPlanProposalSteps() {\n const [steps, setSteps] = useState(firstSteps);\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'approve' | 'cancel' | 'save' | null>(null);\n const [draft, setDraft] = useState('');\n // The run after 'Approve', in its own progress row under the card.\n const [run, setRun] = useState<Run | null>(null);\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [startedAt, setStartedAt] = useState(proposedAt);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const editButton = useRef<Focusable>(null);\n const stopButton = useRef<Focusable>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the requests, the run and its clock.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === steps.length - 1) {\n clearInterval(tick.current);\n setRun('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The card stays as the record, and the run shows in its own progress row below it.\n // 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.\n function startRun() {\n setRun('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Decided once: the buttons go away, so a second click cannot approve or cancel it again.\n // After 'Cancel' nothing takes their place: a real app moves focus to the message box.\n function decide(action: 'approve' | 'cancel') {\n if (pending || status !== 'open') return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n if (action === 'cancel') {\n setStatus('cancelled');\n return;\n }\n setStatus('approved');\n startRun();\n }, 1200);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (run !== 'running') return;\n clearTimeout(step.current);\n setRun('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setRun('stopped');\n }, 1200);\n }\n\n function startEditing() {\n if (pending) return;\n setDraft(steps.join('\\n'));\n setStatus('editing');\n }\n\n // 'Discard' leaves the edit and keeps the plan as it was. 'Cancel' would cancel the whole proposal.\n function discard() {\n setStatus('open');\n focusNext.current = () => editButton.current?.focus();\n }\n\n const draftSteps = draft.split('\\n').map((s) => s.trim()).filter((s) => s !== '');\n\n // 'Save' sends the edited steps to the agent. The plan comes back with them, still waiting for a yes.\n function save() {\n if (pending || draftSteps.length === 0) return;\n setPending('save');\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setSteps(draftSteps);\n setStatus('open');\n focusNext.current = () => editButton.current?.focus();\n }, 1200);\n }\n\n // A stop says how far the run got, so it never says nothing changed when something did.\n // A real app takes the count from the server's answer, not from the list on screen.\n const stoppedNote = current === 0\n ? 'Stopped. Nothing was changed.'\n : `Stopped after ${current} of ${steps.length} steps. The rest of the plan was not done.`;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(proposedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Proposed plan</Heading>\n {status === 'approved' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Approved\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n {status === 'editing' ? (\n <Textarea\n id=\"agent-plan-proposal-steps\"\n label=\"Steps, one per line\"\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n onSubmit={save}\n autoFocus\n maxRows={10}\n disabled={pending === 'save'}\n />\n ) : (\n // Every step, in the order the agent will do them. Once decided, the card is the record:\n // an approved plan keeps its steps as they were, and a cancelled one marks each step cancelled.\n <StepList\n numbered\n aria-label=\"Proposed plan\"\n steps={steps.map((label) => ({ label, status: status === 'cancelled' ? 'cancelled' : 'waiting' }))}\n />\n )}\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n {(status === 'open' || status === 'editing') && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n )}\n {status === 'open' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'approve' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button ref={editButton} size=\"small\" type=\"secondary\" state={pending ? 'disabled' : 'enabled'} label=\"Edit\" onClickButton={startEditing} />\n {/* The product writes this label, never the agent. */}\n <Button size=\"small\" type=\"primary\" state={pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Approve\" loading={pending === 'approve'} onClickButton={() => decide('approve')} />\n </Cluster>\n )}\n {status === 'editing' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'save' ? 'disabled' : 'enabled'} label=\"Discard\" onClickButton={discard} />\n <Button size=\"small\" type=\"primary\" state={draftSteps.length === 0 ? 'disabled' : 'enabled'} label=\"Save\" loading={pending === 'save'} onClickButton={save} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n {run && (\n // The run's own progress row, as the case 'Agent at work' shows.\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n run === 'running' || run === 'stopping' ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n // When it goes, a real app moves focus to the message box.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : undefined\n }\n >\n {run === 'done' ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : run === 'stopped' ? (\n <Paragraph measure=\"none\">{stoppedNote}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(steps, current)} />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
313
|
+
"uses": [
|
|
314
|
+
"Button",
|
|
315
|
+
"Center",
|
|
316
|
+
"Cluster",
|
|
317
|
+
"Heading",
|
|
318
|
+
"Message",
|
|
319
|
+
"Paragraph",
|
|
320
|
+
"Stack",
|
|
321
|
+
"StepList",
|
|
322
|
+
"Surface",
|
|
323
|
+
"Tag",
|
|
324
|
+
"Textarea",
|
|
325
|
+
"TimeStamp",
|
|
326
|
+
"UserImage"
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"id": "changes",
|
|
331
|
+
"title": "Changes",
|
|
332
|
+
"useWhen": "The agent has changes ready to apply.",
|
|
333
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Surface from 'oneslash-design-system/components/surface';\nimport Modal from 'oneslash-design-system/components/modal';\nimport List from 'oneslash-design-system/components/list';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };\nconst proposedAt = new Date('2025-01-15T11:44:00Z');\n\n// ODS has no diff part yet, so the changes are a list of the files they touch, each with what changes in it.\nconst changedFiles = [\n { path: 'pages/pricing.tsx', change: 'Adds the Team plan to the page.' },\n { path: 'data/plans.json', change: 'Sets the Pro price to $15 and adds the Team plan at $25 per seat.' },\n { path: 'components/planTable.tsx', change: 'Adds a column for the Team plan.' },\n];\n\n// The run after 'Approve': one step per file.\nconst runSteps = changedFiles.map((f) => `Change ${f.path}`);\n\nconst reply = 'The three files are changed. The pricing page shows the new plans.';\n\ntype Status = 'open' | 'requesting' | 'redoing' | 'approved' | 'cancelled';\ntype Run = 'running' | 'stopping' | 'stopped' | 'done';\n\n// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.\nfunction stepsUpTo(current: number): StepListStep[] {\n return runSteps.slice(0, current + 1).map((label, i) => ({ label, status: i < current ? 'done' : 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentPlanProposalChanges() {\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'approve' | 'cancel' | 'send' | null>(null);\n const [viewing, setViewing] = useState(false);\n const [draft, setDraft] = useState('');\n // The run after 'Approve', in its own progress row under the card.\n const [run, setRun] = useState<Run | null>(null);\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [startedAt, setStartedAt] = useState(proposedAt);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const requestButton = useRef<Focusable>(null);\n const stopButton = useRef<Focusable>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the requests, the run and its clock.\n useEffect(() => () => {\n clearTimeout(timer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === runSteps.length - 1) {\n clearInterval(tick.current);\n setRun('done');\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The card stays as the record, and the run shows in its own progress row below it.\n // 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.\n function startRun() {\n setRun('running');\n setCurrent(0);\n setSeconds(0);\n setStartedAt(new Date());\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Decided once: the buttons go away, so a second click cannot approve or cancel it again.\n // After 'Cancel' nothing takes their place: a real app moves focus to the message box.\n function decide(action: 'approve' | 'cancel') {\n if (pending || status !== 'open') return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n if (action === 'cancel') {\n setStatus('cancelled');\n return;\n }\n setStatus('approved');\n startRun();\n }, 1200);\n }\n\n // Stop asks the server to end the run. The row says it stopped only once the run has ended.\n function stop() {\n if (run !== 'running') return;\n clearTimeout(step.current);\n setRun('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n clearInterval(tick.current);\n setRun('stopped');\n }, 1200);\n }\n\n function startRequest() {\n if (pending) return;\n setDraft('');\n setStatus('requesting');\n }\n\n // 'Discard' leaves the sub-form and keeps the proposal open. 'Cancel' would cancel the whole proposal.\n function discard() {\n setStatus('open');\n focusNext.current = () => requestButton.current?.focus();\n }\n\n const empty = draft.trim() === '';\n\n // 'Send' gives the agent what should change. The card's buttons go, and the agent redoes the changes.\n // Nothing takes their place: a real app moves focus to the message box.\n function send() {\n if (pending || empty) return;\n setPending('send');\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus('redoing');\n }, 1200);\n }\n\n // A real app takes the count from the server's answer. Here the file that was being changed when the run\n // stopped may be partly changed, so the note says so and does not claim it is untouched.\n const partFile = changedFiles[current].path;\n const stoppedNote = current === 0\n ? `Stopped before any file was done. ${partFile} may be partly changed. Check it.`\n : `Stopped after ${current} of ${runSteps.length} files. ${partFile} may be partly changed. Check it.`;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(proposedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Changes ready</Heading>\n {status === 'approved' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Approved\" />}\n {status === 'cancelled' && <Tag variant=\"contained\" size=\"small\" label=\"Cancelled\" />}\n </Cluster>\n <Paragraph measure=\"none\">These changes set the Pro price to $15 and add the Team plan to the pricing page. Three files change.</Paragraph>\n {(status === 'open' || status === 'requesting') && (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"View Changes\" onClickButton={() => setViewing(true)} />\n </Cluster>\n )}\n {status === 'requesting' && (\n <Textarea\n id=\"agent-plan-proposal-change-request\"\n label=\"What should change?\"\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n onSubmit={send}\n autoFocus\n disabled={pending === 'send'}\n />\n )}\n {status === 'redoing' && (\n <Paragraph measure=\"none\">Acme Agent is redoing the changes. It posts a new card when they are ready.</Paragraph>\n )}\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n {(status === 'open' || status === 'requesting') && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n )}\n {status === 'open' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'approve' ? 'disabled' : 'enabled'} label=\"Cancel\" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />\n <Button ref={requestButton} size=\"small\" type=\"secondary\" state={pending ? 'disabled' : 'enabled'} label=\"Request Changes\" onClickButton={startRequest} />\n {/* The product writes this label, never the agent. */}\n <Button size=\"small\" type=\"primary\" state={pending === 'cancel' ? 'disabled' : 'enabled'} label=\"Approve\" loading={pending === 'approve'} onClickButton={() => decide('approve')} />\n </Cluster>\n )}\n {status === 'requesting' && (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'send' ? 'disabled' : 'enabled'} label=\"Discard\" onClickButton={discard} />\n <Button size=\"small\" type=\"primary\" state={empty ? 'disabled' : 'enabled'} label=\"Send\" loading={pending === 'send'} onClickButton={send} />\n </Cluster>\n )}\n </Stack>\n </Surface>\n </Message>\n {status === 'cancelled' && (\n // One line in the thread on what was not done, under the card.\n <Message compact aria-label={`${agentName}, agent`}>\n <Paragraph measure=\"none\">Cancelled. Nothing was changed.</Paragraph>\n </Message>\n )}\n {run && (\n // The run's own progress row, as the case 'Agent at work' shows.\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(startedAt)}\n footer={\n run === 'running' || run === 'stopping' ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n // When it goes, a real app moves focus to the message box.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : undefined\n }\n >\n {run === 'done' ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : run === 'stopped' ? (\n <Paragraph measure=\"none\">{stoppedNote}</Paragraph>\n ) : (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n <Modal\n isOpen={viewing}\n title=\"Changed Files\"\n onClose={() => setViewing(false)}\n actions={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Close\" onClickButton={() => setViewing(false)} />}\n >\n <Paragraph measure=\"none\">Approve changes these files.</Paragraph>\n <List\n marker=\"dot\"\n size=\"body1\"\n items={changedFiles.map((f) => (\n <Stack key={f.path} gap=\"small\">\n <Paragraph mono measure=\"none\">{f.path}</Paragraph>\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{f.change}</Paragraph>\n </Stack>\n ))}\n />\n </Modal>\n </Center>\n );\n}\n",
|
|
334
|
+
"uses": [
|
|
335
|
+
"Button",
|
|
336
|
+
"Center",
|
|
337
|
+
"Cluster",
|
|
338
|
+
"Heading",
|
|
339
|
+
"List",
|
|
340
|
+
"Message",
|
|
341
|
+
"Modal",
|
|
342
|
+
"Paragraph",
|
|
343
|
+
"Stack",
|
|
344
|
+
"StepList",
|
|
345
|
+
"Surface",
|
|
346
|
+
"Tag",
|
|
347
|
+
"Textarea",
|
|
348
|
+
"TimeStamp",
|
|
349
|
+
"UserImage"
|
|
350
|
+
]
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
"id": "agent-question",
|
|
356
|
+
"title": "Agent question",
|
|
357
|
+
"kind": "design",
|
|
358
|
+
"level": "organism",
|
|
359
|
+
"area": "agent",
|
|
360
|
+
"situation": "The agent needs an answer from the person before it can go on. It needs a fact or a decision only the person has. For ways forward in its own work, see the case 'Agent options'.",
|
|
361
|
+
"do": [
|
|
362
|
+
"Put the card in the agent's `Message`, in a `Surface` with the question as its heading.",
|
|
363
|
+
"Say which question it is in a caption when there are several: 'Question 1 of 3'.",
|
|
364
|
+
"Replace the question with the next one in the same card once it is answered or skipped, and move focus to its first answer.",
|
|
365
|
+
"Show a few answers as `<RadioGroup variant=\"card\">`, with an `aria-label` that starts with the question.",
|
|
366
|
+
"Preselect nothing unless the agent recommends an answer. Then give it the `badge` 'Recommended' and preselect it.",
|
|
367
|
+
"Take a free answer in a `Textarea` with a visible label.",
|
|
368
|
+
"Let Cmd+Enter or Ctrl+Enter in the field answer. Enter adds a line.",
|
|
369
|
+
"Order the buttons 'Skip', a tertiary Button that is always there, then 'Answer' as the primary Button.",
|
|
370
|
+
"Disable 'Answer' until an answer is picked or typed.",
|
|
371
|
+
"Make the pressed Button `loading` and keep its label. Disable the field and the other Button while the request runs.",
|
|
372
|
+
"Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
|
|
373
|
+
"Follow the rule 'An agent cancels and reports when nobody answers': show the waiting time on the card, 'Waits 10 more minutes, then cancels.'",
|
|
374
|
+
"Notify the person who asked when the agent needs their answer.",
|
|
375
|
+
"Show the answer as text with an 'Answered' `Tag` once it is sent, and remove the buttons.",
|
|
376
|
+
"Mark a skipped question with a 'Skipped' `Tag`, and say that the agent will list it as an open question in the plan.",
|
|
377
|
+
"Mark the card with a 'Cancelled' `Tag` when the waiting time is up. Add one compact agent row under it that says what was not done: 'Cancelled. Nothing was changed.'",
|
|
378
|
+
"Announce the decided `Tag` politely: the app wraps it in a polite live region.",
|
|
379
|
+
"Move focus to the message box once the last question is answered or skipped, since its buttons are gone."
|
|
380
|
+
],
|
|
381
|
+
"dont": [
|
|
382
|
+
"Do not treat no answer as a yes.",
|
|
383
|
+
"Do not send an answer the person did not choose.",
|
|
384
|
+
"Do not recommend or preselect an option that does more than the others, such as one that deletes, publishes or widens access.",
|
|
385
|
+
"Do not leave a question waiting with no end, and do not cancel it without saying so in the thread.",
|
|
386
|
+
"Do not hide 'Skip'.",
|
|
387
|
+
"Do not change a Button's label while it is loading, such as to 'Submitting...'."
|
|
388
|
+
],
|
|
389
|
+
"notBuiltYet": "A waiting question in Scindo never times out: it stays open until someone answers or skips it. Its answer button reads 'Submit', and its buttons read 'Submitting...' and 'Skipping...' while they load. With no recommended answer it preselects the first one. Scindo's Apple app shows no question card.",
|
|
390
|
+
"seenIn": [
|
|
391
|
+
"Scindo"
|
|
392
|
+
],
|
|
393
|
+
"options": [
|
|
394
|
+
{
|
|
395
|
+
"id": "choices",
|
|
396
|
+
"title": "Choices",
|
|
397
|
+
"useWhen": "The answer is one of a few.",
|
|
398
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Surface from 'oneslash-design-system/components/surface';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you plan the new pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\n// The agent has three questions. Each one replaces the one before it in the same card.\nconst questions = [\n {\n question: 'Which plans should the pricing page show?',\n options: [\n { value: 'three', label: 'Free, Pro and Team' },\n { value: 'two', label: 'Pro and Team only' },\n { value: 'four', label: 'Free, Pro, Team and Enterprise' },\n ],\n },\n {\n question: 'Should prices show per month or per year?',\n options: [\n { value: 'month', label: 'Per month' },\n { value: 'year', label: 'Per year' },\n { value: 'both', label: 'Both, with a switch' },\n ],\n },\n {\n question: 'Where should the plan table go?',\n options: [\n { value: 'top', label: 'At the top of the page' },\n { value: 'below', label: 'Below the feature list' },\n ],\n },\n];\n\n// What the person did with each question: the label of the answer, or null when it was skipped.\ntype Outcome = string | null;\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentQuestionChoices() {\n const [index, setIndex] = useState(0);\n const [outcomes, setOutcomes] = useState<Outcome[]>([]);\n // No option is recommended, so nothing starts selected.\n const [selected, setSelected] = useState('');\n const [pending, setPending] = useState<'answer' | 'skip' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const done = outcomes.length === questions.length;\n const { question, options } = questions[index];\n\n // After an answer or a skip, the next question replaces this one in the same card, with nothing selected.\n // A real app moves focus to its first answer. After the last one the buttons are gone, and a real app\n // moves focus to the message box.\n function send(action: 'answer' | 'skip') {\n if (pending || done || (action === 'answer' && selected === '')) return;\n setPending(action);\n const outcome = action === 'answer' ? options.find((o) => o.value === selected)?.label ?? null : null;\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setOutcomes((list) => [...list, outcome]);\n setSelected('');\n if (index < questions.length - 1) setIndex(index + 1);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n {done ? (\n // Every question is decided: the card is the record, with each answer or skip.\n // A real app announces the decided Tag in a polite live region.\n <Stack gap=\"medium\">\n {questions.map((q, i) => (\n <Stack key={q.question} gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{q.question}</Heading>\n {outcomes[i] === null\n ? <Tag variant=\"contained\" size=\"small\" label=\"Skipped\" />\n : <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Answered\" />}\n </Cluster>\n <Paragraph measure=\"none\">{outcomes[i] ?? 'Acme Agent will list this as an open question in the plan.'}</Paragraph>\n </Stack>\n ))}\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n {/* The agent has more than one question, so the card says which one this is. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`Question ${index + 1} of ${questions.length}`}</Paragraph>\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n <RadioGroup\n variant=\"card\"\n aria-label={question}\n options={options}\n selectedValue={selected}\n onChange={setSelected}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'answer' ? 'disabled' : 'enabled'} label=\"Skip\" loading={pending === 'skip'} onClickButton={() => send('skip')} />\n <Button\n size=\"small\"\n type=\"primary\"\n state={selected === '' || pending === 'skip' ? 'disabled' : 'enabled'}\n label=\"Answer\"\n loading={pending === 'answer'}\n onClickButton={() => send('answer')}\n />\n </Cluster>\n </Stack>\n )}\n </Surface>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
399
|
+
"uses": [
|
|
400
|
+
"Button",
|
|
401
|
+
"Center",
|
|
402
|
+
"Cluster",
|
|
403
|
+
"Heading",
|
|
404
|
+
"Message",
|
|
405
|
+
"Paragraph",
|
|
406
|
+
"RadioGroup",
|
|
407
|
+
"Stack",
|
|
408
|
+
"Surface",
|
|
409
|
+
"Tag",
|
|
410
|
+
"TimeStamp",
|
|
411
|
+
"UserImage"
|
|
412
|
+
]
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"id": "free-text",
|
|
416
|
+
"title": "Free text",
|
|
417
|
+
"useWhen": "The answer is the person's own words.",
|
|
418
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 Surface from 'oneslash-design-system/components/surface';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };\nconst askedAt = new Date('2025-01-15T11:41:00Z');\n\nconst question = 'What should the Team plan say under its price?';\n\ntype Status = 'open' | 'answered' | 'skipped';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function AgentQuestionFreeText() {\n const [text, setText] = useState('');\n const [status, setStatus] = useState<Status>('open');\n const [pending, setPending] = useState<'answer' | 'skip' | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const empty = text.trim() === '';\n\n // Ctrl+Enter or Cmd+Enter in the field answers too, and Enter adds a line.\n // Once it is answered or skipped the buttons are gone, and a real app moves focus to the message box.\n function send(action: 'answer' | 'skip') {\n if (pending || status !== 'open' || (action === 'answer' && empty)) return;\n setPending(action);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setPending(null);\n setStatus(action === 'answer' ? 'answered' : 'skipped');\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(askedAt)}\n >\n <Surface padding=\"small\">\n <Stack gap=\"medium\">\n {/* One question only, so there is no 'Question 1 of 3' line. */}\n {/* A real app announces the decided Tag in a polite live region. */}\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{question}</Heading>\n {status === 'answered' && <Tag variant=\"contained\" size=\"small\" color=\"success\" label=\"Answered\" />}\n {status === 'skipped' && <Tag variant=\"contained\" size=\"small\" label=\"Skipped\" />}\n </Cluster>\n {status === 'open' && (\n <>\n <Textarea\n id=\"agent-question-answer\"\n label=\"Your answer\"\n value={text}\n onChange={(e) => setText(e.target.value)}\n onSubmit={() => send('answer')}\n disabled={pending !== null}\n />\n {/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Waits 10 more minutes, then cancels.</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={pending === 'answer' ? 'disabled' : 'enabled'} label=\"Skip\" loading={pending === 'skip'} onClickButton={() => send('skip')} />\n <Button\n size=\"small\"\n type=\"primary\"\n state={empty || pending === 'skip' ? 'disabled' : 'enabled'}\n label=\"Answer\"\n loading={pending === 'answer'}\n onClickButton={() => send('answer')}\n />\n </Cluster>\n </>\n )}\n {status === 'answered' && <Paragraph measure=\"none\">{text.trim()}</Paragraph>}\n {status === 'skipped' && <Paragraph measure=\"none\">Acme Agent will list this as an open question in the plan.</Paragraph>}\n </Stack>\n </Surface>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
419
|
+
"uses": [
|
|
420
|
+
"Button",
|
|
421
|
+
"Center",
|
|
422
|
+
"Cluster",
|
|
423
|
+
"Heading",
|
|
424
|
+
"Message",
|
|
425
|
+
"Paragraph",
|
|
426
|
+
"Stack",
|
|
427
|
+
"Surface",
|
|
428
|
+
"Tag",
|
|
429
|
+
"Textarea",
|
|
430
|
+
"TimeStamp",
|
|
431
|
+
"UserImage"
|
|
432
|
+
]
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
},
|
|
53
436
|
{
|
|
54
437
|
"id": "agent-refuses-clearly",
|
|
55
438
|
"title": "An agent refuses clearly",
|
|
@@ -131,13 +514,13 @@
|
|
|
131
514
|
"level": "rule",
|
|
132
515
|
"area": "agent",
|
|
133
516
|
"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.",
|
|
134
|
-
"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.",
|
|
517
|
+
"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. When the reply read only the messages already on screen above it, the Tag alone is enough.",
|
|
135
518
|
"why": "A person can check an answer only when they can open what it came from.",
|
|
136
519
|
"do": [
|
|
137
520
|
"Put the sources directly under the reply they support.",
|
|
138
521
|
"Show each source as a card with its title and where it lives, such as the space name or the date.",
|
|
139
522
|
"Make each card open the source itself, in the product or on the service it came from.",
|
|
140
|
-
"Show the first six sources and a 'Show N
|
|
523
|
+
"Show the first six sources and a 'Show N More' button for the rest."
|
|
141
524
|
],
|
|
142
525
|
"dont": [
|
|
143
526
|
"Do not show a sources section when the reply used no sources.",
|
|
@@ -149,101 +532,2797 @@
|
|
|
149
532
|
]
|
|
150
533
|
},
|
|
151
534
|
{
|
|
152
|
-
"id": "
|
|
153
|
-
"title": "
|
|
535
|
+
"id": "artifact-card",
|
|
536
|
+
"title": "Document card",
|
|
537
|
+
"kind": "design",
|
|
538
|
+
"level": "organism",
|
|
539
|
+
"area": "agent",
|
|
540
|
+
"situation": "The agent made a document for the person, such as a plan or a report.",
|
|
541
|
+
"do": [
|
|
542
|
+
"Keep the reply to one sentence on what the agent made. Then put the card in the reply's `footer`.",
|
|
543
|
+
"Show the document as a `SourceCard`: an icon for its kind, its title, its kind and length in `meta` ('Document · 4 pages'), and `action=\"Open\"`.",
|
|
544
|
+
"Open the document from the card with `onClick`, in a pane beside the thread.",
|
|
545
|
+
"Move focus into the pane when it opens.",
|
|
546
|
+
"Give the pane a Close control, and move focus back to the card when the pane closes.",
|
|
547
|
+
"Bring the open pane forward when the person presses the card again, instead of opening a second one.",
|
|
548
|
+
"Mark the agent's row as the rule 'An agent says what it is' says.",
|
|
549
|
+
"Give the list that holds the rows `role=\"log\"`."
|
|
550
|
+
],
|
|
551
|
+
"dont": [
|
|
552
|
+
"Do not paste the document into the thread.",
|
|
553
|
+
"Do not repeat or list what the document says in the reply.",
|
|
554
|
+
"Do not show the document's card on a person's message."
|
|
555
|
+
],
|
|
556
|
+
"native": "On Mac the card opens the document in the canvas beside the thread. On iPhone it opens the document in a read-only sheet.",
|
|
557
|
+
"notBuiltYet": "Scindo's card shows the kind, the title and 'Open' on one line, with no icon and no length. Its reply is not short: it is cut to its first lines.",
|
|
558
|
+
"seenIn": [
|
|
559
|
+
"Scindo"
|
|
560
|
+
],
|
|
561
|
+
"options": [
|
|
562
|
+
{
|
|
563
|
+
"id": "card",
|
|
564
|
+
"title": "In the thread",
|
|
565
|
+
"useWhen": "A reply made a document.",
|
|
566
|
+
"source": "'use client';\nimport { Bot, FileText } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Center, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// One sentence on what the agent made. The document itself stays out of the thread.\nconst reply = 'I wrote the launch plan for March 3 as a document.';\n\nconst doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\n// A real app opens the document in a pane beside the thread and moves focus into it.\n// ODS has no side pane part yet, so this example shows the card only.\nfunction openDocument() {}\n\nexport default function ArtifactCardCard() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={FileText} title={doc.title} meta={doc.meta} action=\"Open\" onClick={openDocument} />\n </Grid>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
567
|
+
"uses": [
|
|
568
|
+
"Center",
|
|
569
|
+
"Grid",
|
|
570
|
+
"Heading",
|
|
571
|
+
"Message",
|
|
572
|
+
"Paragraph",
|
|
573
|
+
"SourceCard",
|
|
574
|
+
"Stack",
|
|
575
|
+
"Tag",
|
|
576
|
+
"TimeStamp",
|
|
577
|
+
"UserImage"
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
]
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
"id": "auth-gate-loading",
|
|
584
|
+
"title": "Login check loading",
|
|
154
585
|
"kind": "design",
|
|
155
586
|
"level": "page",
|
|
156
587
|
"area": "auth",
|
|
157
|
-
"situation": "
|
|
588
|
+
"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.",
|
|
158
589
|
"do": [
|
|
159
|
-
"Show
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"Name the
|
|
163
|
-
"
|
|
590
|
+
"Show the spinner from the first render, before anything else, as `LoadingScreen` in `Center` with `fill`.",
|
|
591
|
+
"Replace the spinner with the page, or go to the login page, as soon as the check ends.",
|
|
592
|
+
"Show no text when the wait is normally under about a second.",
|
|
593
|
+
"Name the step in `LoadingScreen`'s `label` when it can take longer than about a second: `label=\"Checking invite…\"`.",
|
|
594
|
+
"Use the same screen as the full-screen spinner in 'Page loading': `LoadingScreen` alone in `Center` with `fill`."
|
|
164
595
|
],
|
|
165
596
|
"dont": [
|
|
166
|
-
"Do not
|
|
167
|
-
"Do not
|
|
168
|
-
"Do not
|
|
169
|
-
"Do not
|
|
597
|
+
"Do not show the login form, or the page, before the check ends. It flashes and then goes away.",
|
|
598
|
+
"Do not write a line that names no step, such as 'Loading…' or 'Please wait'.",
|
|
599
|
+
"Do not put a line under a spinner whose wait is normally under about a second.",
|
|
600
|
+
"Do not put more than one line under the spinner, or write it in a separate Paragraph."
|
|
170
601
|
],
|
|
171
|
-
"native": "On Apple use `
|
|
172
|
-
"notBuiltYet": "
|
|
602
|
+
"native": "On Apple use `ProgressView()` centered in the window, with a label only for a named step that can take longer.",
|
|
603
|
+
"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.",
|
|
173
604
|
"seenIn": [
|
|
174
|
-
"Commentify",
|
|
175
605
|
"Commentify admin",
|
|
176
606
|
"Scindo"
|
|
177
607
|
],
|
|
178
608
|
"options": [
|
|
179
609
|
{
|
|
180
|
-
"id": "
|
|
181
|
-
"title": "
|
|
182
|
-
"useWhen": "The
|
|
183
|
-
"source": "'use client';\nimport
|
|
610
|
+
"id": "spinner",
|
|
611
|
+
"title": "Spinner",
|
|
612
|
+
"useWhen": "The wait is normally under about a second, such as reading the session.",
|
|
613
|
+
"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",
|
|
184
614
|
"uses": [
|
|
185
|
-
"Alert",
|
|
186
|
-
"BrandIcon",
|
|
187
|
-
"Button",
|
|
188
615
|
"Center",
|
|
189
|
-
"
|
|
190
|
-
"Image",
|
|
191
|
-
"Line",
|
|
192
|
-
"Tab",
|
|
193
|
-
"TabsContainer",
|
|
194
|
-
"TextField"
|
|
616
|
+
"LoadingScreen"
|
|
195
617
|
]
|
|
196
618
|
},
|
|
197
619
|
{
|
|
198
|
-
"id": "
|
|
199
|
-
"title": "
|
|
200
|
-
"useWhen": "
|
|
201
|
-
"source": "'use client';\nimport
|
|
620
|
+
"id": "spinner-with-line",
|
|
621
|
+
"title": "Spinner with a line",
|
|
622
|
+
"useWhen": "A named step can take longer than about a second, such as 'Checking invite…' or 'Joining workspace…'.",
|
|
623
|
+
"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",
|
|
624
|
+
"uses": [
|
|
625
|
+
"Center",
|
|
626
|
+
"LoadingScreen"
|
|
627
|
+
]
|
|
628
|
+
}
|
|
629
|
+
]
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
"id": "check-your-email",
|
|
633
|
+
"title": "Check your email",
|
|
634
|
+
"kind": "design",
|
|
635
|
+
"level": "page",
|
|
636
|
+
"area": "auth",
|
|
637
|
+
"situation": "A person signed up, and the product sent a link to confirm their email.",
|
|
638
|
+
"do": [
|
|
639
|
+
"Name the page 'Check your email' in a `Heading` with `level={1}`, with a `Mail` icon above it.",
|
|
640
|
+
"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.'",
|
|
641
|
+
"Offer 'Send Again' and a text-only 'Back to Login'.",
|
|
642
|
+
"Show `loading` on 'Send Again' while it sends, then 'Sent' for 2 seconds.",
|
|
643
|
+
"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.",
|
|
644
|
+
"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."
|
|
645
|
+
],
|
|
646
|
+
"dont": [
|
|
647
|
+
"Do not leave the sign-up form on screen once the link is sent.",
|
|
648
|
+
"Do not say that an account was created, or that one already exists.",
|
|
649
|
+
"Do not make the person close the success Alert, and do not let it close on its own before they have read it.",
|
|
650
|
+
"Do not change 'Send Again' to 'Sending…' while it sends."
|
|
651
|
+
],
|
|
652
|
+
"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.",
|
|
653
|
+
"seenIn": [
|
|
654
|
+
"Commentify",
|
|
655
|
+
"Scindo"
|
|
656
|
+
],
|
|
657
|
+
"options": [
|
|
658
|
+
{
|
|
659
|
+
"id": "page",
|
|
660
|
+
"title": "Page in place of the form",
|
|
661
|
+
"useWhen": "The person must leave for their inbox before they can go on.",
|
|
662
|
+
"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",
|
|
202
663
|
"uses": [
|
|
203
|
-
"Alert",
|
|
204
|
-
"BrandIcon",
|
|
205
664
|
"Button",
|
|
206
665
|
"Center",
|
|
207
|
-
"Cluster",
|
|
208
|
-
"Form",
|
|
209
666
|
"Heading",
|
|
210
|
-
"
|
|
211
|
-
"Line",
|
|
212
|
-
"Link",
|
|
667
|
+
"Icon",
|
|
213
668
|
"Paragraph",
|
|
214
|
-
"
|
|
215
|
-
"Stack",
|
|
216
|
-
"TextField"
|
|
669
|
+
"Stack"
|
|
217
670
|
]
|
|
218
671
|
},
|
|
219
672
|
{
|
|
220
|
-
"id": "
|
|
221
|
-
"title": "
|
|
222
|
-
"useWhen": "
|
|
223
|
-
"source": "'use client';\nimport { useState } from 'react';\nimport
|
|
673
|
+
"id": "alert-on-login",
|
|
674
|
+
"title": "Alert above the login form",
|
|
675
|
+
"useWhen": "The product lets a person log in before they confirm their email.",
|
|
676
|
+
"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",
|
|
224
677
|
"uses": [
|
|
225
678
|
"Alert",
|
|
226
679
|
"BrandIcon",
|
|
227
680
|
"Button",
|
|
228
681
|
"Center",
|
|
229
682
|
"Form",
|
|
230
|
-
"
|
|
683
|
+
"Image",
|
|
231
684
|
"Line",
|
|
232
|
-
"
|
|
685
|
+
"Tab",
|
|
686
|
+
"TabsContainer",
|
|
233
687
|
"TextField"
|
|
234
688
|
]
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
689
|
+
}
|
|
690
|
+
]
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
"id": "composer-limit",
|
|
694
|
+
"title": "Composer at a limit",
|
|
695
|
+
"kind": "design",
|
|
696
|
+
"level": "organism",
|
|
697
|
+
"area": "chat",
|
|
698
|
+
"situation": "The agent cannot be called from the composer because the workspace reached a limit, such as its agent replies for the month.",
|
|
699
|
+
"do": [
|
|
700
|
+
"Follow the rule 'An agent refuses clearly' word for word: \"You've used all 50 AI agent responses this month.\"",
|
|
701
|
+
"Put the notice in the Composer's `above` slot: `<Alert variant=\"inline\" autoDismiss={false}>`, with no close button on the Alert itself.",
|
|
702
|
+
"Say when it resets and who can change it: 'Ask a workspace admin to upgrade Acme Design to Pro for more replies.'",
|
|
703
|
+
"Give everyone 'Not Now', a tertiary Button, so the refusal can be closed. Put the Buttons in a `Cluster` under the Alert.",
|
|
704
|
+
"Give a person who can lift the limit the action after 'Not Now', as a primary Button, such as 'Upgrade to Pro'.",
|
|
705
|
+
"Keep the agent toggle pressable while the limit stands, as the case 'Upgrade prompt' says. Pressing it shows the notice again, and it does not turn on.",
|
|
706
|
+
"Say in the placeholder when agent replies start again, once the person chose 'Not Now'.",
|
|
707
|
+
"Move focus to the message box after 'Not Now', since the Button that had it is gone.",
|
|
708
|
+
"Keep the field and send working, so messages to people still go.",
|
|
709
|
+
"Follow the case 'Upgrade prompt' for a limit reached anywhere outside the message box."
|
|
710
|
+
],
|
|
711
|
+
"dont": [
|
|
712
|
+
"Do not disable the whole Composer. Only the agent is refused.",
|
|
713
|
+
"Do not hide or disable the agent toggle. The person presses it and learns why it does not work.",
|
|
714
|
+
"Do not show the upgrade Button to someone who cannot upgrade.",
|
|
715
|
+
"Do not show a general error, or a toast that goes away, for a limit.",
|
|
716
|
+
"Do not cover the thread with a Modal when the agent is refused."
|
|
717
|
+
],
|
|
718
|
+
"native": "On Apple the notice is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page.",
|
|
719
|
+
"notBuiltYet": "Scindo on the web shows the monthly limit in an overlay over the thread, and shows its Upgrade button to everyone. Its other limits show as an error Alert that the person closes.",
|
|
720
|
+
"seenIn": [
|
|
721
|
+
"Scindo"
|
|
722
|
+
],
|
|
723
|
+
"options": [
|
|
724
|
+
{
|
|
725
|
+
"id": "notice",
|
|
726
|
+
"title": "Notice",
|
|
727
|
+
"useWhen": "The person cannot lift the limit.",
|
|
728
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\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\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNotice() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\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 const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-notice-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person cannot change the plan, so it says who can. Everyone can close a refusal. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. Ask a workspace admin to upgrade Acme Design to Pro for more replies.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
729
|
+
"uses": [
|
|
730
|
+
"Alert",
|
|
731
|
+
"Button",
|
|
732
|
+
"Center",
|
|
733
|
+
"Cluster",
|
|
734
|
+
"Composer",
|
|
735
|
+
"Heading",
|
|
736
|
+
"IconButton",
|
|
737
|
+
"Message",
|
|
738
|
+
"Paragraph",
|
|
739
|
+
"Stack",
|
|
740
|
+
"TimeStamp",
|
|
741
|
+
"Tooltip",
|
|
742
|
+
"UserImage"
|
|
743
|
+
]
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
"id": "notice-with-action",
|
|
747
|
+
"title": "Notice with an action",
|
|
748
|
+
"useWhen": "The person can lift the limit.",
|
|
749
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Button from 'oneslash-design-system/components/button';\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\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 session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who writes the launch email?' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function ComposerLimitNoticeWithAction() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\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 const field = useRef<HTMLTextAreaElement>(null);\n\n // 'Not Now' goes away with the notice, so focus goes to the message box.\n function notNow() {\n setShowNotice(false);\n field.current?.focus();\n }\n\n // The agent cannot be called, but messages to people still send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"composer-limit-action-message\"\n aria-label=\"Message\"\n // After 'Not Now' the placeholder says when agent replies start again.\n placeholder={showNotice ? 'Message the team' : 'Message the team. Agent replies start again on December 1.'}\n value={text}\n onChange={setText}\n onSubmit={send}\n // A standing condition: no close button on the Alert, and no auto-dismiss. 'Not Now' closes it.\n // This person can change the plan, so they get the button that lifts the limit. Alert has no action slot.\n above={\n showNotice ? (\n <Stack gap=\"small\">\n <Alert\n type=\"warning\"\n variant=\"inline\"\n autoDismiss={false}\n message=\"You've used all 50 AI agent responses this month.\"\n secondMessage=\"They start again on December 1. The Pro plan gives Acme Design 1,000 AI agent responses a month.\"\n />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={notNow} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => router.push('/settings/billing?plan=pro')} />\n </Cluster>\n </Stack>\n ) : undefined\n }\n tools={\n // It stays pressable while the limit stands, as the case 'Upgrade prompt' says: pressing it shows the notice\n // again. It does not turn on until the limit is lifted.\n <Tooltip title=\"Mention the agent\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" icon={Bot} ariaLabel=\"Mention the agent\" aria-pressed={false} onClick={() => setShowNotice(true)} />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
750
|
+
"uses": [
|
|
751
|
+
"Alert",
|
|
752
|
+
"Button",
|
|
753
|
+
"Center",
|
|
754
|
+
"Cluster",
|
|
755
|
+
"Composer",
|
|
756
|
+
"Heading",
|
|
757
|
+
"IconButton",
|
|
758
|
+
"Message",
|
|
759
|
+
"Paragraph",
|
|
760
|
+
"Stack",
|
|
761
|
+
"TimeStamp",
|
|
762
|
+
"Tooltip",
|
|
763
|
+
"UserImage"
|
|
764
|
+
]
|
|
765
|
+
}
|
|
766
|
+
]
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
"id": "confirm-destructive-action",
|
|
770
|
+
"title": "Delete confirm",
|
|
771
|
+
"kind": "design",
|
|
772
|
+
"level": "organism",
|
|
773
|
+
"area": "confirm",
|
|
774
|
+
"situation": "A person asks to delete or remove something, and it cannot be undone.",
|
|
775
|
+
"do": [
|
|
776
|
+
"Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, 'Cancel' first, then the action with `color=\"danger\"`.",
|
|
777
|
+
"Name the thing and what goes with it: \"This deletes 'Q3 plan' and its 12 tasks.\"",
|
|
778
|
+
"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.",
|
|
779
|
+
"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'.",
|
|
780
|
+
"Name the thing in the label so a screen reader knows which row a Button acts on.",
|
|
781
|
+
"Keep one row confirming at a time. Starting a confirm on another row cancels the first.",
|
|
782
|
+
"Show a toast that names the thing once it is gone."
|
|
783
|
+
],
|
|
784
|
+
"dont": [
|
|
785
|
+
"Do not ask for a confirm when the action is easy to undo.",
|
|
786
|
+
"Do not remove a row on the first click of its Button.",
|
|
787
|
+
"Do not open a Modal for a row in a long list when the inline confirm keeps the place.",
|
|
788
|
+
"Do not ask a question in place of the action, such as 'Are you sure?'."
|
|
789
|
+
],
|
|
790
|
+
"native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role and 'Cancel' in the `.cancel` role.",
|
|
791
|
+
"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'.",
|
|
792
|
+
"seenIn": [
|
|
793
|
+
"Commentify",
|
|
794
|
+
"Scindo"
|
|
795
|
+
],
|
|
796
|
+
"options": [
|
|
797
|
+
{
|
|
798
|
+
"id": "modal",
|
|
799
|
+
"title": "Confirm in a Modal",
|
|
800
|
+
"useWhen": "The default, for any delete or remove that cannot be undone.",
|
|
801
|
+
"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 'Q3 plan' 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",
|
|
802
|
+
"uses": [
|
|
803
|
+
"Button",
|
|
804
|
+
"Center",
|
|
805
|
+
"Cluster",
|
|
806
|
+
"Heading",
|
|
807
|
+
"List",
|
|
808
|
+
"Modal",
|
|
809
|
+
"Paragraph",
|
|
810
|
+
"Stack",
|
|
811
|
+
"Surface",
|
|
812
|
+
"Toaster",
|
|
813
|
+
"dismissToast",
|
|
814
|
+
"toast"
|
|
815
|
+
]
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
"id": "inline",
|
|
819
|
+
"title": "Confirm in the row",
|
|
820
|
+
"useWhen": "The action is on a row inside a dense list, and a Modal would lose the place.",
|
|
821
|
+
"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",
|
|
822
|
+
"uses": [
|
|
823
|
+
"Button",
|
|
824
|
+
"Center",
|
|
825
|
+
"Cluster",
|
|
826
|
+
"Heading",
|
|
827
|
+
"Paragraph",
|
|
828
|
+
"Stack",
|
|
829
|
+
"TableCell",
|
|
830
|
+
"TableContainer",
|
|
831
|
+
"TableRow",
|
|
832
|
+
"Toaster",
|
|
833
|
+
"dismissToast",
|
|
834
|
+
"toast"
|
|
835
|
+
]
|
|
836
|
+
}
|
|
837
|
+
]
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
"id": "confirm-dialogs",
|
|
841
|
+
"title": "A confirm says exactly what will happen",
|
|
842
|
+
"kind": "rule",
|
|
843
|
+
"level": "rule",
|
|
844
|
+
"area": "confirm",
|
|
845
|
+
"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.",
|
|
846
|
+
"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.",
|
|
847
|
+
"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.",
|
|
848
|
+
"do": [
|
|
849
|
+
"Name the thing in the body: \"This deletes 'Q3 plan' and its 12 tasks.\"",
|
|
850
|
+
"Say what is kept: 'Files in the repository are not changed.'",
|
|
851
|
+
"Give the title and the action the same verb, in Title Case: 'Delete Project' has a 'Delete' Button.",
|
|
852
|
+
"Disable 'Cancel' and ignore `onClose` while the request runs.",
|
|
853
|
+
"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."
|
|
854
|
+
],
|
|
855
|
+
"dont": [
|
|
856
|
+
"Do not label Cancel 'No' or 'Close'.",
|
|
857
|
+
"Do not label the action 'Yes, Delete', 'Confirm' or 'OK'.",
|
|
858
|
+
"Do not title the Modal 'Confirm Deletion' or 'Sure?'.",
|
|
859
|
+
"Do not change the action's label while it is loading, such as to 'Deleting…'.",
|
|
860
|
+
"Do not replace the Modal body with a spinner, or close the Modal, while the request runs.",
|
|
861
|
+
"Do not ask for a confirm when the action is easy to undo."
|
|
862
|
+
],
|
|
863
|
+
"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.",
|
|
864
|
+
"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.",
|
|
865
|
+
"seenIn": [
|
|
866
|
+
"Commentify",
|
|
867
|
+
"Scindo"
|
|
868
|
+
]
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
"id": "conversation-starters",
|
|
872
|
+
"title": "Conversation starters",
|
|
873
|
+
"kind": "design",
|
|
874
|
+
"level": "organism",
|
|
875
|
+
"area": "chat",
|
|
876
|
+
"situation": "A thread has no messages yet, and the person may not know what to write first.",
|
|
877
|
+
"do": [
|
|
878
|
+
"Show the empty thread as the rule 'An empty list says what will fill it' says. Use `EmptyBox` with `size=\"large\"`, the `text` 'No messages yet', and a `secondText` that says what to do.",
|
|
879
|
+
"Pass the starters as the `action`: a `Cluster` of three or four clickable `Tag`s, each a short thing to ask in the person's words.",
|
|
880
|
+
"Pass `toggle={false}` to each starter `Tag`, so it is a plain button and not a toggle.",
|
|
881
|
+
"Use `Tag`, not Button: a starter is a phrase the person might say, and a Button label is in Title Case.",
|
|
882
|
+
"Fill the Composer with the starter and focus it, with the caret at the end. Do not send it: the person reads it and can change it first.",
|
|
883
|
+
"Say who reads the message in the placeholder: 'Message Acme Agent'.",
|
|
884
|
+
"Hide the starters once the thread has a message.",
|
|
885
|
+
"Write the starters for the place: in a task, ask about the plan; in a channel, ask about what the team discussed."
|
|
886
|
+
],
|
|
887
|
+
"dont": [
|
|
888
|
+
"Do not send a starter on a click.",
|
|
889
|
+
"Do not show starters in a thread between people. Say what to do in `secondText` instead.",
|
|
890
|
+
"Do not offer more than four starters.",
|
|
891
|
+
"Do not write starters in the system's words, such as 'Run summary'."
|
|
892
|
+
],
|
|
893
|
+
"notBuiltYet": "Scindo on the web shows its starters as `Tag`s under the `EmptyBox`, not as its `action`. It shows them in threads between people too, and puts '@Agent' before the text.",
|
|
894
|
+
"seenIn": [
|
|
895
|
+
"Scindo"
|
|
896
|
+
],
|
|
897
|
+
"options": [
|
|
898
|
+
{
|
|
899
|
+
"id": "chips",
|
|
900
|
+
"title": "Things to ask",
|
|
901
|
+
"useWhen": "A conversation with the agent: three or four things to ask it.",
|
|
902
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Tag from 'oneslash-design-system/components/tag';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst agentName = 'Acme Agent';\n\n// Things to ask, in the person's words.\nconst starters = [\n 'Summarize the launch plan',\n 'Draft the launch email',\n 'List what is still open',\n 'Check the pricing page for mistakes',\n];\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nexport default function ConversationStartersChips() {\n const [thread, setThread] = useState<Row[]>([]);\n const [text, setText] = useState('');\n // Set when a starter fills the field; the effect below focuses it with the caret at the end.\n const [filled, setFilled] = useState(0);\n const field = useRef<HTMLTextAreaElement>(null);\n\n useEffect(() => {\n if (!filled || !field.current) return;\n const end = field.current.value.length;\n field.current.focus();\n field.current.setSelectionRange(end, end);\n }, [filled]);\n\n // Fills the field and does not send: the person can change it first.\n function fillWith(starter: string) {\n setText(starter);\n setFilled((n) => n + 1);\n }\n\n function send() {\n // A real app sends the message to the agent here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">{`Ask ${agentName}`}</Heading>\n {thread.length === 0 ? (\n <EmptyBox\n size=\"large\"\n icon=\"MessageCircle\"\n text=\"No messages yet\"\n secondText={`Ask ${agentName} about the launch, or start with one of these.`}\n action={\n <Cluster gap=\"small\">\n {starters.map((s) => (\n <Tag key={s} variant=\"contained\" size=\"small\" label={s} toggle={false} onClick={() => fillWith(s)} />\n ))}\n </Cluster>\n }\n />\n ) : (\n // A real app gives the list that holds the rows role=\"log\".\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n )}\n <Composer\n ref={field}\n id=\"conversation-starters-chips-message\"\n aria-label=\"Message\"\n placeholder={`Message ${agentName}`}\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
903
|
+
"uses": [
|
|
904
|
+
"Center",
|
|
905
|
+
"Cluster",
|
|
906
|
+
"Composer",
|
|
907
|
+
"EmptyBox",
|
|
908
|
+
"Heading",
|
|
909
|
+
"Message",
|
|
910
|
+
"Paragraph",
|
|
911
|
+
"Stack",
|
|
912
|
+
"Tag",
|
|
913
|
+
"TimeStamp",
|
|
914
|
+
"UserImage"
|
|
915
|
+
]
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
"id": "none",
|
|
919
|
+
"title": "No starters",
|
|
920
|
+
"useWhen": "A thread between people, where the agent is not the one asked.",
|
|
921
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nexport default function ConversationStartersNone() {\n const [thread, setThread] = useState<Row[]>([]);\n const [text, setText] = useState('');\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {thread.length === 0 ? (\n // A thread between people: no starters, and secondText says what to do.\n <EmptyBox\n size=\"large\"\n icon=\"MessageCircle\"\n text=\"No messages yet\"\n secondText=\"Send the first message to the team in Launch plan.\"\n />\n ) : (\n // A real app gives the list that holds the rows role=\"log\".\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n )}\n <Composer\n id=\"conversation-starters-none-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
922
|
+
"uses": [
|
|
923
|
+
"Center",
|
|
924
|
+
"Composer",
|
|
925
|
+
"EmptyBox",
|
|
926
|
+
"Heading",
|
|
927
|
+
"Message",
|
|
928
|
+
"Paragraph",
|
|
929
|
+
"Stack",
|
|
930
|
+
"TimeStamp",
|
|
931
|
+
"UserImage"
|
|
932
|
+
]
|
|
933
|
+
}
|
|
934
|
+
]
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
"id": "create-modal",
|
|
938
|
+
"title": "Create modal",
|
|
939
|
+
"kind": "design",
|
|
940
|
+
"level": "organism",
|
|
941
|
+
"area": "confirm",
|
|
942
|
+
"situation": "A person creates something new, such as a project or a task, and it needs a name before it exists.",
|
|
943
|
+
"do": [
|
|
944
|
+
"Title the Modal 'Create' and the thing, such as 'Create Project', and give its action the same verb: 'Create'.",
|
|
945
|
+
"Put 'Cancel' first, a tertiary Button, then 'Create', a primary Button, in the Modal's `actions`.",
|
|
946
|
+
"Create on Enter too: put the fields in a `Form`.",
|
|
947
|
+
"Keep 'Create' `state=\"disabled\"` while the name is empty.",
|
|
948
|
+
"Show `loading` on 'Create' while it runs, and keep the fields on screen with what the person typed.",
|
|
949
|
+
"Disable the fields while it runs, where the part allows it: the `TextField` and the `Checkbox`.",
|
|
950
|
+
"Focus the name field when the Modal opens, with `initialFocus=\"body\"`.",
|
|
951
|
+
"Give a `RadioGroup` a line of text above it and an `aria-label` with the same words.",
|
|
952
|
+
"Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
|
|
953
|
+
"Pick a safe default for every choice, so the person only has to type the name.",
|
|
954
|
+
"Close the Modal when it works and show the new thing where it lives."
|
|
955
|
+
],
|
|
956
|
+
"dont": [
|
|
957
|
+
"Do not replace the fields with a spinner while it creates.",
|
|
958
|
+
"Do not change the label while it is loading, such as to 'Creating…'.",
|
|
959
|
+
"Do not ask for more than the thing needs to exist. Everything else goes in its settings.",
|
|
960
|
+
"Do not show a toast when the new thing is on screen. It shows where it lives."
|
|
961
|
+
],
|
|
962
|
+
"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.",
|
|
963
|
+
"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.",
|
|
964
|
+
"seenIn": [
|
|
965
|
+
"Scindo"
|
|
966
|
+
],
|
|
967
|
+
"options": [
|
|
968
|
+
{
|
|
969
|
+
"id": "quick",
|
|
970
|
+
"title": "Just a name",
|
|
971
|
+
"useWhen": "One name is enough. Everything else can be set later.",
|
|
972
|
+
"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",
|
|
973
|
+
"uses": [
|
|
974
|
+
"Button",
|
|
975
|
+
"Center",
|
|
976
|
+
"Cluster",
|
|
977
|
+
"Form",
|
|
978
|
+
"Heading",
|
|
979
|
+
"List",
|
|
980
|
+
"Modal",
|
|
981
|
+
"Stack",
|
|
982
|
+
"Surface",
|
|
983
|
+
"TextField"
|
|
984
|
+
]
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
"id": "with-settings",
|
|
988
|
+
"title": "A name and a few choices",
|
|
989
|
+
"useWhen": "The thing needs two or three choices up front, such as who can see it.",
|
|
990
|
+
"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",
|
|
991
|
+
"uses": [
|
|
992
|
+
"Button",
|
|
993
|
+
"Center",
|
|
994
|
+
"Checkbox",
|
|
995
|
+
"Cluster",
|
|
996
|
+
"Form",
|
|
997
|
+
"Heading",
|
|
998
|
+
"List",
|
|
999
|
+
"Modal",
|
|
1000
|
+
"Paragraph",
|
|
1001
|
+
"RadioGroup",
|
|
1002
|
+
"Stack",
|
|
1003
|
+
"Surface",
|
|
1004
|
+
"TextField"
|
|
1005
|
+
]
|
|
1006
|
+
}
|
|
1007
|
+
]
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
"id": "device-login",
|
|
1011
|
+
"title": "Device login",
|
|
1012
|
+
"kind": "design",
|
|
1013
|
+
"level": "page",
|
|
1014
|
+
"area": "auth",
|
|
1015
|
+
"situation": "A CLI, an editor or another app opened the browser so the person can log in, and the login must reach that app.",
|
|
1016
|
+
"do": [
|
|
1017
|
+
"Say in one line what the login connects: 'This connects Acme CLI on your computer to your account.'",
|
|
1018
|
+
"Put the providers on top, then a `Line` with `label=\"or\"`, then email and password, as on the 'Login page' with providers first.",
|
|
1019
|
+
"Wait for the device to answer before showing success, with `LoadingScreen` and `label=\"Waiting for Acme CLI…\"`.",
|
|
1020
|
+
"End on \"You're logged in\" and 'You can close this tab.' once the device has answered.",
|
|
1021
|
+
"Go back to the form with an inline error Alert when the device does not answer, and say what to check.",
|
|
1022
|
+
"Show `LoadingScreen` with `label=\"Finishing login…\"` while a popup finishes, and close the popup when the page that opened it answers.",
|
|
1023
|
+
"Finish the login in this tab after about 2 seconds when no page that opened the popup answers.",
|
|
1024
|
+
"Show 'Done. You can close this window.' when the browser keeps the popup open."
|
|
1025
|
+
],
|
|
1026
|
+
"dont": [
|
|
1027
|
+
"Do not show success before the device answers.",
|
|
1028
|
+
"Do not leave a popup blank while it finishes.",
|
|
1029
|
+
"Do not label a provider Button with its name alone, such as 'Google'. Write 'Continue with Google'."
|
|
1030
|
+
],
|
|
1031
|
+
"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.",
|
|
1032
|
+
"seenIn": [
|
|
1033
|
+
"Commentify",
|
|
1034
|
+
"Scindo"
|
|
1035
|
+
],
|
|
1036
|
+
"options": [
|
|
1037
|
+
{
|
|
1038
|
+
"id": "provider-first",
|
|
1039
|
+
"title": "Login page for a device",
|
|
1040
|
+
"useWhen": "A CLI or an editor opened a browser tab; most people log in with a provider and email is the fallback.",
|
|
1041
|
+
"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'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",
|
|
1042
|
+
"uses": [
|
|
1043
|
+
"Alert",
|
|
1044
|
+
"BrandIcon",
|
|
1045
|
+
"Button",
|
|
1046
|
+
"Center",
|
|
1047
|
+
"Form",
|
|
1048
|
+
"Heading",
|
|
1049
|
+
"Image",
|
|
1050
|
+
"Line",
|
|
1051
|
+
"LoadingScreen",
|
|
1052
|
+
"Paragraph",
|
|
1053
|
+
"Stack",
|
|
1054
|
+
"TextField"
|
|
1055
|
+
]
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
"id": "popup",
|
|
1059
|
+
"title": "Popup that closes itself",
|
|
1060
|
+
"useWhen": "A page opened a popup for the login, and the popup closes once the page has the login.",
|
|
1061
|
+
"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",
|
|
1062
|
+
"uses": [
|
|
1063
|
+
"Center",
|
|
1064
|
+
"LoadingScreen"
|
|
1065
|
+
]
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
"id": "email-confirmed",
|
|
1071
|
+
"title": "Email confirmed",
|
|
1072
|
+
"kind": "design",
|
|
1073
|
+
"level": "page",
|
|
1074
|
+
"area": "auth",
|
|
1075
|
+
"situation": "A person opened the link that confirms their email.",
|
|
1076
|
+
"do": [
|
|
1077
|
+
"Name the page 'Email confirmed' in a `Heading` with `level={1}`.",
|
|
1078
|
+
"Say in one line that the person can close the tab or go on here.",
|
|
1079
|
+
"Offer one Button, 'Continue', to where the person was going.",
|
|
1080
|
+
"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."
|
|
1081
|
+
],
|
|
1082
|
+
"dont": [
|
|
1083
|
+
"Do not ask the person to log in again in the browser where they are already logged in.",
|
|
1084
|
+
"Do not make the person close the success Alert."
|
|
1085
|
+
],
|
|
1086
|
+
"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.",
|
|
1087
|
+
"seenIn": [
|
|
1088
|
+
"Commentify",
|
|
1089
|
+
"Scindo"
|
|
1090
|
+
],
|
|
1091
|
+
"options": [
|
|
1092
|
+
{
|
|
1093
|
+
"id": "page",
|
|
1094
|
+
"title": "Confirmed page",
|
|
1095
|
+
"useWhen": "The link opened a new tab in the browser where the person is logged in.",
|
|
1096
|
+
"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",
|
|
1097
|
+
"uses": [
|
|
1098
|
+
"Button",
|
|
1099
|
+
"Center",
|
|
1100
|
+
"Heading",
|
|
1101
|
+
"Image",
|
|
1102
|
+
"Paragraph",
|
|
1103
|
+
"Stack"
|
|
1104
|
+
]
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
"id": "alert-on-login",
|
|
1108
|
+
"title": "Alert above the login form",
|
|
1109
|
+
"useWhen": "The link opened in another browser, so the person must log in.",
|
|
1110
|
+
"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",
|
|
1111
|
+
"uses": [
|
|
1112
|
+
"Alert",
|
|
1113
|
+
"BrandIcon",
|
|
1114
|
+
"Button",
|
|
1115
|
+
"Center",
|
|
1116
|
+
"Form",
|
|
1117
|
+
"Image",
|
|
1118
|
+
"Line",
|
|
1119
|
+
"Tab",
|
|
1120
|
+
"TabsContainer",
|
|
1121
|
+
"TextField"
|
|
1122
|
+
]
|
|
1123
|
+
}
|
|
1124
|
+
]
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
"id": "empty-list",
|
|
1128
|
+
"title": "Empty list",
|
|
1129
|
+
"kind": "design",
|
|
1130
|
+
"level": "organism",
|
|
1131
|
+
"area": "state",
|
|
1132
|
+
"situation": "A list has loaded, and there is nothing in it yet.",
|
|
1133
|
+
"do": [
|
|
1134
|
+
"Use `size=\"large\"` when the list is the whole pane, and `size=\"small\"` inside a section.",
|
|
1135
|
+
"Say what is empty in the person's words: 'No archived projects'.",
|
|
1136
|
+
"Say in `secondText` what will appear here: 'Projects you archive appear here.'"
|
|
1137
|
+
],
|
|
1138
|
+
"dont": [
|
|
1139
|
+
"Do not show a bare line of text, or nothing at all.",
|
|
1140
|
+
"Do not use the system's words, such as 'No data' or 'No items found'.",
|
|
1141
|
+
"Do not show the empty text while the list is still loading."
|
|
1142
|
+
],
|
|
1143
|
+
"native": "On Apple use `ContentUnavailableView`, with the same words.",
|
|
1144
|
+
"notBuiltYet": "Commentify writes most of its empty lists in Title Case, such as 'No Comments Available', and gives them no `secondText`.",
|
|
1145
|
+
"seenIn": [
|
|
1146
|
+
"Commentify",
|
|
1147
|
+
"Scindo"
|
|
1148
|
+
],
|
|
1149
|
+
"options": [
|
|
1150
|
+
{
|
|
1151
|
+
"id": "region",
|
|
1152
|
+
"title": "Whole pane",
|
|
1153
|
+
"useWhen": "The list is the whole pane, such as a page of projects.",
|
|
1154
|
+
"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",
|
|
1155
|
+
"uses": [
|
|
1156
|
+
"EmptyBox",
|
|
1157
|
+
"Heading",
|
|
1158
|
+
"Stack",
|
|
1159
|
+
"Surface"
|
|
1160
|
+
]
|
|
1161
|
+
},
|
|
1162
|
+
{
|
|
1163
|
+
"id": "section",
|
|
1164
|
+
"title": "Inside a section",
|
|
1165
|
+
"useWhen": "The list sits inside a settings section or a card, next to other things.",
|
|
1166
|
+
"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",
|
|
1167
|
+
"uses": [
|
|
1168
|
+
"Center",
|
|
1169
|
+
"EmptyBox",
|
|
1170
|
+
"Heading",
|
|
1171
|
+
"Paragraph",
|
|
1172
|
+
"Stack",
|
|
1173
|
+
"Surface"
|
|
1174
|
+
]
|
|
1175
|
+
}
|
|
1176
|
+
]
|
|
1177
|
+
},
|
|
1178
|
+
{
|
|
1179
|
+
"id": "empty-lists",
|
|
1180
|
+
"title": "An empty list says what will fill it",
|
|
1181
|
+
"kind": "rule",
|
|
1182
|
+
"level": "rule",
|
|
1183
|
+
"area": "state",
|
|
1184
|
+
"situation": "A list, table or pane has nothing to show.",
|
|
1185
|
+
"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.",
|
|
1186
|
+
"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.",
|
|
1187
|
+
"do": [
|
|
1188
|
+
"Say what is empty in the person's words: 'No saved comments'.",
|
|
1189
|
+
"Say in `secondText` what will appear here or what to do: 'Comments you save appear here.'",
|
|
1190
|
+
"Pass the Button that fills the list as `action`, such as 'Create Project'.",
|
|
1191
|
+
"Make the action Button primary when it fills the list or tries again, and secondary for 'Clear Search'.",
|
|
1192
|
+
"Show the words searched for and a 'Clear Search' Button when a search finds nothing.",
|
|
1193
|
+
"Say that loading failed and offer a 'Try Again' Button when the list could not load."
|
|
1194
|
+
],
|
|
1195
|
+
"dont": [
|
|
1196
|
+
"Do not show a bare line of text, or nothing at all, when a list is empty.",
|
|
1197
|
+
"Do not show the empty text when the list failed to load.",
|
|
1198
|
+
"Do not use the system's words, such as 'No data' or 'No records found'.",
|
|
1199
|
+
"Do not pass an `action` the person is not allowed to use."
|
|
1200
|
+
],
|
|
1201
|
+
"native": "On Apple use `ContentUnavailableView`, with the same words.",
|
|
1202
|
+
"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.",
|
|
1203
|
+
"seenIn": [
|
|
1204
|
+
"Commentify",
|
|
1205
|
+
"Commentify admin",
|
|
1206
|
+
"Scindo",
|
|
1207
|
+
"jinhwankim.com"
|
|
1208
|
+
]
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
"id": "empty-not-set-up",
|
|
1212
|
+
"title": "Empty until set up",
|
|
1213
|
+
"kind": "design",
|
|
1214
|
+
"level": "organism",
|
|
1215
|
+
"area": "state",
|
|
1216
|
+
"situation": "A pane is empty because something it needs is not set up yet, such as a connected account.",
|
|
1217
|
+
"do": [
|
|
1218
|
+
"Say what is missing: 'No calendar connected'.",
|
|
1219
|
+
"Pass one Button as `action`, named for what it sets up: 'Connect Calendar'.",
|
|
1220
|
+
"Say where the fix lives when it is not here: 'An admin can connect one in Settings, under Integrations.'"
|
|
1221
|
+
],
|
|
1222
|
+
"dont": [
|
|
1223
|
+
"Do not put the Button outside `EmptyBox`. Pass it as `action`.",
|
|
1224
|
+
"Do not offer a Button the person is not allowed to use.",
|
|
1225
|
+
"Do not offer more than one Button."
|
|
1226
|
+
],
|
|
1227
|
+
"native": "On Apple use `ContentUnavailableView`, with the Button in its `actions`.",
|
|
1228
|
+
"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'.",
|
|
1229
|
+
"seenIn": [
|
|
1230
|
+
"Commentify",
|
|
1231
|
+
"Scindo"
|
|
1232
|
+
],
|
|
1233
|
+
"options": [
|
|
1234
|
+
{
|
|
1235
|
+
"id": "action",
|
|
1236
|
+
"title": "Fix it here",
|
|
1237
|
+
"useWhen": "The person can fix it here, with one Button.",
|
|
1238
|
+
"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",
|
|
1239
|
+
"uses": [
|
|
1240
|
+
"Button",
|
|
1241
|
+
"EmptyBox",
|
|
1242
|
+
"Heading",
|
|
1243
|
+
"Stack",
|
|
1244
|
+
"Surface"
|
|
1245
|
+
]
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
"id": "pointer",
|
|
1249
|
+
"title": "Say where to fix it",
|
|
1250
|
+
"useWhen": "The fix lives somewhere else, or someone else has to do it. Say where in `secondText`.",
|
|
1251
|
+
"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",
|
|
1252
|
+
"uses": [
|
|
1253
|
+
"EmptyBox",
|
|
1254
|
+
"Heading",
|
|
1255
|
+
"Stack",
|
|
1256
|
+
"Surface"
|
|
1257
|
+
]
|
|
1258
|
+
}
|
|
1259
|
+
]
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
"id": "empty-search",
|
|
1263
|
+
"title": "Empty search",
|
|
1264
|
+
"kind": "design",
|
|
1265
|
+
"level": "organism",
|
|
1266
|
+
"area": "state",
|
|
1267
|
+
"situation": "A search or a filter finds nothing.",
|
|
1268
|
+
"do": [
|
|
1269
|
+
"Use `icon=\"Search\"`, so it reads as a search and not an empty list.",
|
|
1270
|
+
"Show the words searched for, as `No <things> match \"<words>\"`: 'No projects match \"q3 plan\"'.",
|
|
1271
|
+
"Pass a 'Clear Search' Button as `action`. It empties the field and shows the whole list again.",
|
|
1272
|
+
"Put focus back in the search field after 'Clear Search'.",
|
|
1273
|
+
"Keep the words in the search field."
|
|
1274
|
+
],
|
|
1275
|
+
"dont": [
|
|
1276
|
+
"Do not say 'No results found' without the words searched for.",
|
|
1277
|
+
"Do not show the list's own empty text, such as 'No projects yet'.",
|
|
1278
|
+
"Do not clear the search field unless the person asks."
|
|
1279
|
+
],
|
|
1280
|
+
"native": "On Apple use `ContentUnavailableView.search(text:)`.",
|
|
1281
|
+
"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.",
|
|
1282
|
+
"seenIn": [
|
|
1283
|
+
"Commentify",
|
|
1284
|
+
"Scindo"
|
|
1285
|
+
],
|
|
1286
|
+
"options": [
|
|
1287
|
+
{
|
|
1288
|
+
"id": "clear-search",
|
|
1289
|
+
"title": "The words and a way to clear them",
|
|
1290
|
+
"useWhen": "Any search or filter.",
|
|
1291
|
+
"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",
|
|
1292
|
+
"uses": [
|
|
1293
|
+
"Button",
|
|
1294
|
+
"EmptyBox",
|
|
1295
|
+
"List",
|
|
1296
|
+
"Stack",
|
|
1297
|
+
"Surface",
|
|
1298
|
+
"TextField"
|
|
1299
|
+
]
|
|
1300
|
+
}
|
|
1301
|
+
]
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
"id": "error-page",
|
|
1305
|
+
"title": "Error page",
|
|
1306
|
+
"kind": "design",
|
|
1307
|
+
"level": "page",
|
|
1308
|
+
"area": "state",
|
|
1309
|
+
"situation": "Something broke while showing a page, and the app cannot show it.",
|
|
1310
|
+
"do": [
|
|
1311
|
+
"Name the page in a `Heading` with `level={1}`: 'Something went wrong'.",
|
|
1312
|
+
"Say in one plain sentence what happened and what the person can do.",
|
|
1313
|
+
"Offer 'Try Again' first and 'Go Home' second.",
|
|
1314
|
+
"Keep the navigation when only one route failed."
|
|
1315
|
+
],
|
|
1316
|
+
"dont": [
|
|
1317
|
+
"Do not show the error's own message, a stack trace or an error id.",
|
|
1318
|
+
"Do not show a line of text with no way out.",
|
|
1319
|
+
"Do not hide the navigation when only one route failed."
|
|
1320
|
+
],
|
|
1321
|
+
"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.",
|
|
1322
|
+
"seenIn": [
|
|
1323
|
+
"Commentify",
|
|
1324
|
+
"Scindo",
|
|
1325
|
+
"jinhwankim.com"
|
|
1326
|
+
],
|
|
1327
|
+
"options": [
|
|
1328
|
+
{
|
|
1329
|
+
"id": "full-page",
|
|
1330
|
+
"title": "Full page",
|
|
1331
|
+
"useWhen": "The app shell itself failed, so nothing else can show.",
|
|
1332
|
+
"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",
|
|
1333
|
+
"uses": [
|
|
1334
|
+
"Button",
|
|
1335
|
+
"Center",
|
|
1336
|
+
"Cluster",
|
|
1337
|
+
"Heading",
|
|
1338
|
+
"Paragraph",
|
|
1339
|
+
"Stack"
|
|
1340
|
+
]
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
"id": "in-shell",
|
|
1344
|
+
"title": "Inside the shell",
|
|
1345
|
+
"useWhen": "One route failed and the navigation still works.",
|
|
1346
|
+
"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",
|
|
1347
|
+
"uses": [
|
|
1348
|
+
"Button",
|
|
1349
|
+
"Cluster",
|
|
1350
|
+
"Heading",
|
|
1351
|
+
"Image",
|
|
1352
|
+
"Paragraph",
|
|
1353
|
+
"Stack",
|
|
1354
|
+
"Surface",
|
|
1355
|
+
"Tab",
|
|
1356
|
+
"TabsContainer"
|
|
1357
|
+
]
|
|
1358
|
+
}
|
|
1359
|
+
]
|
|
1360
|
+
},
|
|
1361
|
+
{
|
|
1362
|
+
"id": "feedback-form",
|
|
1363
|
+
"title": "Feedback form",
|
|
1364
|
+
"kind": "design",
|
|
1365
|
+
"level": "organism",
|
|
1366
|
+
"area": "confirm",
|
|
1367
|
+
"situation": "A person sends feedback about the product from inside it.",
|
|
1368
|
+
"do": [
|
|
1369
|
+
"Title the Modal 'Send Feedback' and label its action 'Send', after 'Cancel'.",
|
|
1370
|
+
"Ask for a category with a `Select` and the feedback with a `Textarea`. Start the category on a safe default.",
|
|
1371
|
+
"Put a line of text above the `Select` that says what it asks, and give the Select the same words as its `aria-label`.",
|
|
1372
|
+
"Focus the first field when the Modal opens, with `initialFocus=\"body\"`.",
|
|
1373
|
+
"Disable the `Select` and the `Textarea` while it sends, and keep what the person wrote.",
|
|
1374
|
+
"Keep 'Send' `state=\"disabled\"` while the feedback is empty.",
|
|
1375
|
+
"Send on Cmd+Enter or Ctrl+Enter from the `Textarea`, through its `onSubmit`. Enter adds a new line.",
|
|
1376
|
+
"Show an inline error Alert at the top of the Modal when sending fails, and keep what the person wrote.",
|
|
1377
|
+
"Close the Modal when it works, and show a toast: 'Feedback sent.'"
|
|
1378
|
+
],
|
|
1379
|
+
"dont": [
|
|
1380
|
+
"Do not replace the form with a thank-you message that closes on its own.",
|
|
1381
|
+
"Do not change the label while it is loading, such as to 'Sending...'.",
|
|
1382
|
+
"Do not fail without a word. Say that the feedback was not sent.",
|
|
1383
|
+
"Do not clear what the person wrote when sending fails."
|
|
1384
|
+
],
|
|
1385
|
+
"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.",
|
|
1386
|
+
"seenIn": [
|
|
1387
|
+
"Scindo"
|
|
1388
|
+
],
|
|
1389
|
+
"options": [
|
|
1390
|
+
{
|
|
1391
|
+
"id": "modal",
|
|
1392
|
+
"title": "Send from a Modal",
|
|
1393
|
+
"useWhen": "Feedback can be sent from anywhere in the product, such as a help menu.",
|
|
1394
|
+
"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",
|
|
1395
|
+
"uses": [
|
|
1396
|
+
"Alert",
|
|
1397
|
+
"Button",
|
|
1398
|
+
"Center",
|
|
1399
|
+
"Cluster",
|
|
1400
|
+
"Heading",
|
|
1401
|
+
"Modal",
|
|
1402
|
+
"Paragraph",
|
|
1403
|
+
"Select",
|
|
1404
|
+
"Stack",
|
|
1405
|
+
"Textarea",
|
|
1406
|
+
"Toaster",
|
|
1407
|
+
"dismissToast",
|
|
1408
|
+
"toast"
|
|
1409
|
+
]
|
|
1410
|
+
}
|
|
1411
|
+
]
|
|
1412
|
+
},
|
|
1413
|
+
{
|
|
1414
|
+
"id": "forgot-password",
|
|
1415
|
+
"title": "Forgot password",
|
|
1416
|
+
"kind": "design",
|
|
1417
|
+
"level": "page",
|
|
1418
|
+
"area": "auth",
|
|
1419
|
+
"situation": "A person cannot remember their password and asks for a link to set a new one.",
|
|
1420
|
+
"do": [
|
|
1421
|
+
"Name the page 'Reset password' in a `Heading` with `level={1}`, and say in one line what happens next.",
|
|
1422
|
+
"Ask only for the email, and send it with 'Send Reset Link'.",
|
|
1423
|
+
"Put a text-only 'Back to Login' Button under the form. In place, keep the email typed so far when it goes back.",
|
|
1424
|
+
"Keep the email out of the URL when the reset form has its own page.",
|
|
1425
|
+
"Offer 'Send Again' on the confirmation, as on 'Check your email': `loading` while it sends, then 'Sent' for 2 seconds.",
|
|
1426
|
+
"Answer every address the same way: 'If ada@example.com has an Acme account, we sent it a link to reset the password.'",
|
|
1427
|
+
"Show a problem with the email under the field, and a failed request in an inline Alert above it.",
|
|
1428
|
+
"Show the loading state on the submit Button while sending, and keep the form in place."
|
|
1429
|
+
],
|
|
1430
|
+
"dont": [
|
|
1431
|
+
"Do not say whether an address has an account.",
|
|
1432
|
+
"Do not clear the email the person typed on the login form.",
|
|
1433
|
+
"Do not replace the form with a spinner while sending the link."
|
|
1434
|
+
],
|
|
1435
|
+
"native": "On Apple, put 'Forgot Password?' under the 'Log In' Button and open the web reset form from it.",
|
|
1436
|
+
"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.",
|
|
1437
|
+
"seenIn": [
|
|
1438
|
+
"Commentify",
|
|
1439
|
+
"Scindo"
|
|
1440
|
+
],
|
|
1441
|
+
"options": [
|
|
1442
|
+
{
|
|
1443
|
+
"id": "in-place",
|
|
1444
|
+
"title": "In place of the login form",
|
|
1445
|
+
"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.",
|
|
1446
|
+
"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",
|
|
1447
|
+
"uses": [
|
|
1448
|
+
"Alert",
|
|
1449
|
+
"BrandIcon",
|
|
1450
|
+
"Button",
|
|
1451
|
+
"Center",
|
|
1452
|
+
"Form",
|
|
1453
|
+
"Heading",
|
|
1454
|
+
"Icon",
|
|
1455
|
+
"Image",
|
|
1456
|
+
"Line",
|
|
1457
|
+
"Paragraph",
|
|
1458
|
+
"Stack",
|
|
1459
|
+
"Tab",
|
|
1460
|
+
"TabsContainer",
|
|
1461
|
+
"TextField"
|
|
1462
|
+
]
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
"id": "own-page",
|
|
1466
|
+
"title": "Its own page",
|
|
1467
|
+
"useWhen": "The person comes from a link in an email or another app.",
|
|
1468
|
+
"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",
|
|
1469
|
+
"uses": [
|
|
1470
|
+
"Alert",
|
|
1471
|
+
"Button",
|
|
1472
|
+
"Center",
|
|
1473
|
+
"Form",
|
|
1474
|
+
"Heading",
|
|
1475
|
+
"Icon",
|
|
1476
|
+
"Image",
|
|
1477
|
+
"Paragraph",
|
|
1478
|
+
"Stack",
|
|
1479
|
+
"TextField"
|
|
1480
|
+
]
|
|
1481
|
+
}
|
|
1482
|
+
]
|
|
1483
|
+
},
|
|
1484
|
+
{
|
|
1485
|
+
"id": "form-errors",
|
|
1486
|
+
"title": "A form error shows next to the problem",
|
|
1487
|
+
"kind": "rule",
|
|
1488
|
+
"level": "rule",
|
|
1489
|
+
"area": "state",
|
|
1490
|
+
"situation": "A form was submitted and something is wrong.",
|
|
1491
|
+
"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()`.",
|
|
1492
|
+
"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.",
|
|
1493
|
+
"do": [
|
|
1494
|
+
"Show a problem with one field under that field, with `error` and `errorText`.",
|
|
1495
|
+
"Say what to do, not only what is wrong: 'Enter an email address, like name@example.com.'",
|
|
1496
|
+
"Show a problem with the whole request above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`.",
|
|
1497
|
+
"Clear the message in the Alert's `onClose`.",
|
|
1498
|
+
"Keep everything the person typed after a failed submit.",
|
|
1499
|
+
"Clear the old messages when the person submits again."
|
|
1500
|
+
],
|
|
1501
|
+
"dont": [
|
|
1502
|
+
"Do not leave out `variant=\"inline\"`: the default variant is a toast at the top of the screen, away from the form.",
|
|
1503
|
+
"Do not write a red caption by hand. Use `errorText` or an Alert.",
|
|
1504
|
+
"Do not use the browser's `alert()`.",
|
|
1505
|
+
"Do not clear the form after a failed submit.",
|
|
1506
|
+
"Do not change the submit Button's label while it is loading, such as to 'Saving…'."
|
|
1507
|
+
],
|
|
1508
|
+
"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.",
|
|
1509
|
+
"seenIn": [
|
|
1510
|
+
"Commentify",
|
|
1511
|
+
"Scindo",
|
|
1512
|
+
"jinhwankim.com"
|
|
1513
|
+
]
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
"id": "import-checklist",
|
|
1517
|
+
"title": "Import checklist",
|
|
1518
|
+
"kind": "design",
|
|
1519
|
+
"level": "organism",
|
|
1520
|
+
"area": "confirm",
|
|
1521
|
+
"situation": "A person picks which items to bring in from another place, such as pages from a wiki.",
|
|
1522
|
+
"do": [
|
|
1523
|
+
"Put a search field at the top, then a count line, then the list of `Checkbox`es.",
|
|
1524
|
+
"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\".'",
|
|
1525
|
+
"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'.",
|
|
1526
|
+
"Focus the search field when the Modal opens, with `initialFocus=\"body\"`, and again after 'Clear Search'.",
|
|
1527
|
+
"Count the selection in the action: 'Import 3 Pages'. Keep it `state=\"disabled\"` while nothing is selected.",
|
|
1528
|
+
"Keep the selection when a search hides items. Items that are filtered out stay selected.",
|
|
1529
|
+
"Show `EmptyBox size=\"small\"` with the words searched for and a 'Clear Search' Button when nothing matches.",
|
|
1530
|
+
"Show `EmptyBox size=\"small\"` when there is nothing left to import.",
|
|
1531
|
+
"Show `loading` on the action while it imports, and keep the list on screen with the Checkboxes disabled.",
|
|
1532
|
+
"Close the Modal when it works and show the new items where they live."
|
|
1533
|
+
],
|
|
1534
|
+
"dont": [
|
|
1535
|
+
"Do not use a master Checkbox for Select All. Checkbox has no state for some selected.",
|
|
1536
|
+
"Do not label the action 'Import' without the count, or change it while it runs, such as to 'Importing… 1/2'.",
|
|
1537
|
+
"Do not clear the selection when the person searches.",
|
|
1538
|
+
"Do not show a bare line of text when the list is empty or nothing matches."
|
|
1539
|
+
],
|
|
1540
|
+
"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.",
|
|
1541
|
+
"seenIn": [
|
|
1542
|
+
"Scindo"
|
|
1543
|
+
],
|
|
1544
|
+
"options": [
|
|
1545
|
+
{
|
|
1546
|
+
"id": "modal",
|
|
1547
|
+
"title": "Pick in a Modal",
|
|
1548
|
+
"useWhen": "The person chooses some items out of a list they can search.",
|
|
1549
|
+
"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",
|
|
1550
|
+
"uses": [
|
|
1551
|
+
"Button",
|
|
1552
|
+
"Center",
|
|
1553
|
+
"Checkbox",
|
|
1554
|
+
"Cluster",
|
|
1555
|
+
"EmptyBox",
|
|
1556
|
+
"Heading",
|
|
1557
|
+
"List",
|
|
1558
|
+
"Modal",
|
|
1559
|
+
"Paragraph",
|
|
1560
|
+
"Stack",
|
|
1561
|
+
"Surface",
|
|
1562
|
+
"TextField"
|
|
1563
|
+
]
|
|
1564
|
+
}
|
|
1565
|
+
]
|
|
1566
|
+
},
|
|
1567
|
+
{
|
|
1568
|
+
"id": "inline-form-feedback",
|
|
1569
|
+
"title": "Form feedback",
|
|
1570
|
+
"kind": "design",
|
|
1571
|
+
"level": "organism",
|
|
1572
|
+
"area": "state",
|
|
1573
|
+
"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.",
|
|
1574
|
+
"do": [
|
|
1575
|
+
"Show `loading` on the submit Button while the request runs, and keep its label.",
|
|
1576
|
+
"Show 'Saved' on the Button for 2 seconds when the form saves in place, or until the person edits again.",
|
|
1577
|
+
"Show a failed request above the fields in `<Alert type=\"error\" variant=\"inline\" showCloseButton>`, and keep what the person typed.",
|
|
1578
|
+
"Call `toast({ type: 'success', message })` when the result is somewhere else."
|
|
1579
|
+
],
|
|
1580
|
+
"dont": [
|
|
1581
|
+
"Do not change the Button's label while it is loading, such as to 'Saving…'.",
|
|
1582
|
+
"Do not show a toast for a change the person can already see.",
|
|
1583
|
+
"Do not let a failed save pass with no message.",
|
|
1584
|
+
"Do not say 'successfully'."
|
|
1585
|
+
],
|
|
1586
|
+
"native": "On Apple there is no toast. Show the result in place.",
|
|
1587
|
+
"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.",
|
|
1588
|
+
"seenIn": [
|
|
1589
|
+
"Scindo"
|
|
1590
|
+
],
|
|
1591
|
+
"options": [
|
|
1592
|
+
{
|
|
1593
|
+
"id": "button-label",
|
|
1594
|
+
"title": "Saved on the Button",
|
|
1595
|
+
"useWhen": "It worked in place: the change shows where it is.",
|
|
1596
|
+
"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",
|
|
1597
|
+
"uses": [
|
|
1598
|
+
"Button",
|
|
1599
|
+
"Center",
|
|
1600
|
+
"Cluster",
|
|
1601
|
+
"Form",
|
|
1602
|
+
"Heading",
|
|
1603
|
+
"Stack",
|
|
1604
|
+
"Surface",
|
|
1605
|
+
"TextField"
|
|
1606
|
+
]
|
|
1607
|
+
},
|
|
1608
|
+
{
|
|
1609
|
+
"id": "inline-alert",
|
|
1610
|
+
"title": "Inline error Alert",
|
|
1611
|
+
"useWhen": "It failed: the request did not go through.",
|
|
1612
|
+
"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",
|
|
1613
|
+
"uses": [
|
|
1614
|
+
"Alert",
|
|
1615
|
+
"Button",
|
|
1616
|
+
"Center",
|
|
1617
|
+
"Cluster",
|
|
1618
|
+
"Form",
|
|
1619
|
+
"Heading",
|
|
1620
|
+
"Stack",
|
|
1621
|
+
"Surface",
|
|
1622
|
+
"TextField"
|
|
1623
|
+
]
|
|
1624
|
+
},
|
|
1625
|
+
{
|
|
1626
|
+
"id": "toast",
|
|
1627
|
+
"title": "Toast",
|
|
1628
|
+
"useWhen": "The result is elsewhere, such as an invite that was sent.",
|
|
1629
|
+
"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",
|
|
1630
|
+
"uses": [
|
|
1631
|
+
"Button",
|
|
1632
|
+
"Center",
|
|
1633
|
+
"Cluster",
|
|
1634
|
+
"Form",
|
|
1635
|
+
"Heading",
|
|
1636
|
+
"Stack",
|
|
1637
|
+
"Surface",
|
|
1638
|
+
"TextField",
|
|
1639
|
+
"Toaster",
|
|
1640
|
+
"dismissToast",
|
|
1641
|
+
"toast"
|
|
1642
|
+
]
|
|
1643
|
+
}
|
|
1644
|
+
]
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
"id": "invite-member",
|
|
1648
|
+
"title": "Member invite",
|
|
1649
|
+
"kind": "design",
|
|
1650
|
+
"level": "organism",
|
|
1651
|
+
"area": "confirm",
|
|
1652
|
+
"situation": "A person invites someone to join a workspace.",
|
|
1653
|
+
"do": [
|
|
1654
|
+
"Title the Modal 'Invite Member' and label its action 'Invite', after 'Cancel'.",
|
|
1655
|
+
"Send on Enter too: put the email field in a `Form`.",
|
|
1656
|
+
"Focus the email field when the Modal opens, with `initialFocus=\"body\"`, and disable it while the invite is sent.",
|
|
1657
|
+
"Show a problem with the address under the field, such as a person who is already a member.",
|
|
1658
|
+
"Close the Modal once the invite is sent, and show a toast that names the address: 'Invite sent to ada@example.com.'",
|
|
1659
|
+
"Show a toast that names the link once it is revoked: 'Link made by Dana Lee revoked.'",
|
|
1660
|
+
"Show the link in a `TextField` with `readOnly`, so it can be selected, and a 'Copy' Button next to it.",
|
|
1661
|
+
"Change 'Copy' to 'Copied' for 2 seconds, and only when the link reached the clipboard.",
|
|
1662
|
+
"Say under the field when copying is blocked: 'Copying is blocked here. Select the link and copy it.'",
|
|
1663
|
+
"Say who can use the link and when it stops working.",
|
|
1664
|
+
"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.",
|
|
1665
|
+
"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'.",
|
|
1666
|
+
"Start each `aria-label` with the visible label, so voice control still finds the Button.",
|
|
1667
|
+
"Disable 'Done', and ignore Escape and a click outside, while a revoke runs."
|
|
1668
|
+
],
|
|
1669
|
+
"dont": [
|
|
1670
|
+
"Do not label the way out 'Close', or the action 'Create Invite' when the product sends it.",
|
|
1671
|
+
"Do not replace the field with a spinner while the invite is sent.",
|
|
1672
|
+
"Do not show 'Copied' when the copy failed, or 'Copied!' with an exclamation mark.",
|
|
1673
|
+
"Do not revoke a link on the first click.",
|
|
1674
|
+
"Do not touch `navigator` while the page renders. Copy only in the click handler."
|
|
1675
|
+
],
|
|
1676
|
+
"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`.",
|
|
1677
|
+
"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.",
|
|
1678
|
+
"seenIn": [
|
|
1679
|
+
"Scindo"
|
|
1680
|
+
],
|
|
1681
|
+
"options": [
|
|
1682
|
+
{
|
|
1683
|
+
"id": "by-email",
|
|
1684
|
+
"title": "Send an invite by email",
|
|
1685
|
+
"useWhen": "The product sends the invite to an address the person types.",
|
|
1686
|
+
"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",
|
|
1687
|
+
"uses": [
|
|
1688
|
+
"Button",
|
|
1689
|
+
"Center",
|
|
1690
|
+
"Cluster",
|
|
1691
|
+
"Form",
|
|
1692
|
+
"Heading",
|
|
1693
|
+
"Modal",
|
|
1694
|
+
"Paragraph",
|
|
1695
|
+
"Stack",
|
|
1696
|
+
"TableCell",
|
|
1697
|
+
"TableContainer",
|
|
1698
|
+
"TableRow",
|
|
1699
|
+
"TextField",
|
|
1700
|
+
"Toaster",
|
|
1701
|
+
"dismissToast",
|
|
1702
|
+
"toast"
|
|
1703
|
+
]
|
|
1704
|
+
},
|
|
1705
|
+
{
|
|
1706
|
+
"id": "by-link",
|
|
1707
|
+
"title": "Share an invite link",
|
|
1708
|
+
"useWhen": "The person shares a link themselves, in their own chat or email.",
|
|
1709
|
+
"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",
|
|
1710
|
+
"uses": [
|
|
1711
|
+
"Button",
|
|
1712
|
+
"Center",
|
|
1713
|
+
"Cluster",
|
|
1714
|
+
"EmptyBox",
|
|
1715
|
+
"Heading",
|
|
1716
|
+
"Modal",
|
|
1717
|
+
"Paragraph",
|
|
1718
|
+
"Stack",
|
|
1719
|
+
"TableCell",
|
|
1720
|
+
"TableContainer",
|
|
1721
|
+
"TableRow",
|
|
1722
|
+
"TextField",
|
|
1723
|
+
"Toaster",
|
|
1724
|
+
"dismissToast",
|
|
1725
|
+
"toast"
|
|
1726
|
+
]
|
|
1727
|
+
}
|
|
1728
|
+
]
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
"id": "load-failure",
|
|
1732
|
+
"title": "Load failure",
|
|
1733
|
+
"kind": "design",
|
|
1734
|
+
"level": "organism",
|
|
1735
|
+
"area": "state",
|
|
1736
|
+
"situation": "A list or a section could not load.",
|
|
1737
|
+
"do": [
|
|
1738
|
+
"Say what could not load: 'Could not load projects'.",
|
|
1739
|
+
"Offer a 'Try Again' Button. It is `loading` while it loads, and keeps its label.",
|
|
1740
|
+
"Show the list as soon as it loads.",
|
|
1741
|
+
"Keep the rest of the page working when only one section failed.",
|
|
1742
|
+
"Give the inline error Alert for a failed section no close button and `autoDismiss={false}`, so it stays until the section loads."
|
|
1743
|
+
],
|
|
1744
|
+
"dont": [
|
|
1745
|
+
"Do not show the empty text, such as 'No projects yet', when the list failed to load.",
|
|
1746
|
+
"Do not show the error's own message, such as 'Failed to fetch'.",
|
|
1747
|
+
"Do not replace the whole page when only one section failed."
|
|
1748
|
+
],
|
|
1749
|
+
"native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
|
|
1750
|
+
"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`.",
|
|
1751
|
+
"seenIn": [
|
|
1752
|
+
"Commentify",
|
|
1753
|
+
"Scindo"
|
|
1754
|
+
],
|
|
1755
|
+
"options": [
|
|
1756
|
+
{
|
|
1757
|
+
"id": "region",
|
|
1758
|
+
"title": "Whole list failed",
|
|
1759
|
+
"useWhen": "The whole list failed to load, so there is nothing else to show in its place.",
|
|
1760
|
+
"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",
|
|
1761
|
+
"uses": [
|
|
1762
|
+
"Button",
|
|
1763
|
+
"EmptyBox",
|
|
1764
|
+
"Heading",
|
|
1765
|
+
"List",
|
|
1766
|
+
"Stack",
|
|
1767
|
+
"Surface"
|
|
1768
|
+
]
|
|
1769
|
+
},
|
|
1770
|
+
{
|
|
1771
|
+
"id": "inline",
|
|
1772
|
+
"title": "One section failed",
|
|
1773
|
+
"useWhen": "One section failed to load and the rest of the page works.",
|
|
1774
|
+
"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",
|
|
1775
|
+
"uses": [
|
|
1776
|
+
"Alert",
|
|
1777
|
+
"Button",
|
|
1778
|
+
"Center",
|
|
1779
|
+
"Cluster",
|
|
1780
|
+
"Heading",
|
|
1781
|
+
"List",
|
|
1782
|
+
"Paragraph",
|
|
1783
|
+
"Stack",
|
|
1784
|
+
"Surface"
|
|
1785
|
+
]
|
|
1786
|
+
}
|
|
1787
|
+
]
|
|
1788
|
+
},
|
|
1789
|
+
{
|
|
1790
|
+
"id": "log-out-confirm",
|
|
1791
|
+
"title": "Log-out confirm",
|
|
1792
|
+
"kind": "design",
|
|
1793
|
+
"level": "organism",
|
|
1794
|
+
"area": "confirm",
|
|
1795
|
+
"situation": "A person chooses Log Out.",
|
|
1796
|
+
"do": [
|
|
1797
|
+
"Call it 'Log Out' everywhere: the menu item, the Modal title and the action Button. The way back in is 'Log In'.",
|
|
1798
|
+
"Say in one sentence what logging out means on this device.",
|
|
1799
|
+
"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.",
|
|
1800
|
+
"Leave the action Button in the plain primary color. Logging out destroys nothing.",
|
|
1801
|
+
"Show `loading` on 'Log Out' while it runs, then show the logged-out page."
|
|
1802
|
+
],
|
|
1803
|
+
"dont": [
|
|
1804
|
+
"Do not mix 'Sign Out' with 'Log In'. Use one word family: 'Log Out' and 'Log In'.",
|
|
1805
|
+
"Do not give the action Button `color=\"danger\"`.",
|
|
1806
|
+
"Do not ask 'Are you sure you want to log out?'.",
|
|
1807
|
+
"Do not show a toast after logging out. The logged-out page says it."
|
|
1808
|
+
],
|
|
1809
|
+
"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.",
|
|
1810
|
+
"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?'.",
|
|
1811
|
+
"seenIn": [
|
|
1812
|
+
"Commentify",
|
|
1813
|
+
"Commentify admin",
|
|
1814
|
+
"Scindo"
|
|
1815
|
+
],
|
|
1816
|
+
"options": [
|
|
1817
|
+
{
|
|
1818
|
+
"id": "modal",
|
|
1819
|
+
"title": "Confirm in a Modal",
|
|
1820
|
+
"useWhen": "The product keeps unsent work or runs on shared devices.",
|
|
1821
|
+
"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",
|
|
1822
|
+
"uses": [
|
|
1823
|
+
"Button",
|
|
1824
|
+
"Center",
|
|
1825
|
+
"Cluster",
|
|
1826
|
+
"Heading",
|
|
1827
|
+
"Modal",
|
|
1828
|
+
"Paragraph",
|
|
1829
|
+
"Stack"
|
|
1830
|
+
]
|
|
1831
|
+
}
|
|
1832
|
+
]
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
"id": "login-page",
|
|
1836
|
+
"title": "Login page",
|
|
1837
|
+
"kind": "design",
|
|
1838
|
+
"level": "page",
|
|
1839
|
+
"area": "auth",
|
|
1840
|
+
"situation": "A person who already has an account opens the product and is not logged in.",
|
|
1841
|
+
"do": [
|
|
1842
|
+
"Show a problem with one field under that field.",
|
|
1843
|
+
"Show a refused login or a failed request in an inline Alert above the fields.",
|
|
1844
|
+
"Put a text-only 'Forgot Password?' Button right under the submit Button when there is a password.",
|
|
1845
|
+
"Name the provider on its button: 'Continue with Google'.",
|
|
1846
|
+
"Show the loading state on the submit Button while logging in, and keep the form in place.",
|
|
1847
|
+
"Disable the fields while the request runs."
|
|
1848
|
+
],
|
|
1849
|
+
"dont": [
|
|
1850
|
+
"Do not clear the email field after a failed attempt.",
|
|
1851
|
+
"Do not show sign-up fields on the login page; link or tab to sign-up.",
|
|
1852
|
+
"Do not replace the form with a spinner while logging in.",
|
|
1853
|
+
"Do not say which of the email or the password was wrong."
|
|
1854
|
+
],
|
|
1855
|
+
"native": "On Apple use `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
|
|
1856
|
+
"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.",
|
|
1857
|
+
"seenIn": [
|
|
1858
|
+
"Commentify",
|
|
1859
|
+
"Commentify admin",
|
|
1860
|
+
"Scindo"
|
|
1861
|
+
],
|
|
1862
|
+
"options": [
|
|
1863
|
+
{
|
|
1864
|
+
"id": "centered",
|
|
1865
|
+
"title": "Centered column",
|
|
1866
|
+
"useWhen": "The product has one way in, and most people log in with email and a password.",
|
|
1867
|
+
"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",
|
|
1868
|
+
"uses": [
|
|
1869
|
+
"Alert",
|
|
1870
|
+
"BrandIcon",
|
|
1871
|
+
"Button",
|
|
1872
|
+
"Center",
|
|
1873
|
+
"Form",
|
|
1874
|
+
"Image",
|
|
1875
|
+
"Line",
|
|
1876
|
+
"Tab",
|
|
1877
|
+
"TabsContainer",
|
|
1878
|
+
"TextField"
|
|
1879
|
+
]
|
|
1880
|
+
},
|
|
1881
|
+
{
|
|
1882
|
+
"id": "split",
|
|
1883
|
+
"title": "Brand beside the form",
|
|
1884
|
+
"useWhen": "First-time visitors land here and need one line on what the product is.",
|
|
1885
|
+
"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",
|
|
1886
|
+
"uses": [
|
|
1887
|
+
"Alert",
|
|
1888
|
+
"BrandIcon",
|
|
1889
|
+
"Button",
|
|
1890
|
+
"Center",
|
|
1891
|
+
"Cluster",
|
|
1892
|
+
"Form",
|
|
1893
|
+
"Heading",
|
|
1894
|
+
"Image",
|
|
1895
|
+
"Line",
|
|
1896
|
+
"Link",
|
|
1897
|
+
"Paragraph",
|
|
1898
|
+
"Split",
|
|
1899
|
+
"Stack",
|
|
1900
|
+
"TextField"
|
|
1901
|
+
]
|
|
1902
|
+
},
|
|
1903
|
+
{
|
|
1904
|
+
"id": "provider-first",
|
|
1905
|
+
"title": "Provider first",
|
|
1906
|
+
"useWhen": "Most people log in with Google, GitHub or Apple; email is the fallback.",
|
|
1907
|
+
"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",
|
|
1908
|
+
"uses": [
|
|
1909
|
+
"Alert",
|
|
1910
|
+
"BrandIcon",
|
|
1911
|
+
"Button",
|
|
1912
|
+
"Center",
|
|
1913
|
+
"Form",
|
|
1914
|
+
"Heading",
|
|
1915
|
+
"Line",
|
|
1916
|
+
"Stack",
|
|
1917
|
+
"TextField"
|
|
1918
|
+
]
|
|
1919
|
+
},
|
|
1920
|
+
{
|
|
1921
|
+
"id": "email-only",
|
|
1922
|
+
"title": "Email only",
|
|
1923
|
+
"useWhen": "An internal tool with no passwords: the person gets a login link by email.",
|
|
1924
|
+
"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",
|
|
1925
|
+
"uses": [
|
|
1926
|
+
"Alert",
|
|
1927
|
+
"Button",
|
|
1928
|
+
"Center",
|
|
1929
|
+
"Form",
|
|
1930
|
+
"Heading",
|
|
1931
|
+
"Paragraph",
|
|
1932
|
+
"Stack",
|
|
1933
|
+
"Surface",
|
|
1934
|
+
"TextField"
|
|
1935
|
+
]
|
|
1936
|
+
}
|
|
1937
|
+
]
|
|
1938
|
+
},
|
|
1939
|
+
{
|
|
1940
|
+
"id": "mention-list",
|
|
1941
|
+
"title": "Mention list",
|
|
1942
|
+
"kind": "design",
|
|
1943
|
+
"level": "organism",
|
|
1944
|
+
"area": "chat",
|
|
1945
|
+
"situation": "A person types @ in the message box to name someone, or the agent.",
|
|
1946
|
+
"do": [
|
|
1947
|
+
"Open the list when the person types @ at the start of the text or after a space. A bare @ opens it, and each letter after it narrows it.",
|
|
1948
|
+
"Show at most 8 names. Typing more letters finds the rest.",
|
|
1949
|
+
"Build it as a combobox. The text area gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows with `isActive` and `aria-selected`.",
|
|
1950
|
+
"Show each person's avatar and name. A person with no picture shows their initial, and the avatar is not read aloud, since the name is.",
|
|
1951
|
+
"Put the agent first, with its icon avatar and an 'Agent' tag, as the rule 'An agent says what it is' says.",
|
|
1952
|
+
"Keep focus in the message box while the list is open, so the person keeps typing.",
|
|
1953
|
+
"Move the highlight with the arrow keys. Enter or Tab picks the highlighted name, and Escape closes the list.",
|
|
1954
|
+
"Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.",
|
|
1955
|
+
"Close the list when the caret moves out of the name being typed, and when focus leaves the message box.",
|
|
1956
|
+
"Check the word at the caret again on Enter or Tab, and pick only if a name still matches. Shift+Tab picks nothing.",
|
|
1957
|
+
"Put the name in at the caret with a space after it, and put the caret after the space.",
|
|
1958
|
+
"Close the list when no name matches.",
|
|
1959
|
+
"Leave out the person who is typing."
|
|
1960
|
+
],
|
|
1961
|
+
"dont": [
|
|
1962
|
+
"Do not move focus into the list. The person keeps typing in the field.",
|
|
1963
|
+
"Do not send the message on the Enter that picks a name.",
|
|
1964
|
+
"Do not show an empty list.",
|
|
1965
|
+
"Do not open the list for an @ inside a word, such as in an email address.",
|
|
1966
|
+
"Do not show the agent with a photo or an initial."
|
|
1967
|
+
],
|
|
1968
|
+
"native": "On Apple the list shows above the field, the agent with a sparkles icon and people with a person icon. A name is picked with a click or a tap.",
|
|
1969
|
+
"notBuiltYet": "Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which name is highlighted. It shows no 'Agent' tag on the agent's row.",
|
|
1970
|
+
"seenIn": [
|
|
1971
|
+
"Scindo"
|
|
1972
|
+
],
|
|
1973
|
+
"options": [
|
|
1974
|
+
{
|
|
1975
|
+
"id": "in-composer",
|
|
1976
|
+
"title": "List in the composer",
|
|
1977
|
+
"useWhen": "The default: the list opens over the text while the person types a name.",
|
|
1978
|
+
"source": "'use client';\nimport { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the session and the workspace.\nconst me = 'Dana Lee';\ntype Member = { id: string; name: string; agent?: boolean };\n// The agent comes first.\nconst members: Member[] = [\n { id: 'acme-agent', name: 'Acme Agent', agent: true },\n { id: 'ben-carter', name: 'Ben Carter' },\n { id: 'dana-lee', name: 'Dana Lee' },\n { id: 'omar-reyes', name: 'Omar Reyes' },\n];\n\nconst listId = 'mention-list-suggestions';\n// The list shows at most this many names; typing more letters narrows it.\nconst MAX_MATCHES = 8;\nconst optionId = (m: Member) => `mention-list-option-${m.id}`;\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who checks the links before we announce it?' },\n];\n\n// Opens with the person part-way through a mention, so the list shows.\nconst firstText = 'Can you check the links, @';\n\n// The word after the @ that ends the text before the caret, or null when there is none. The @ starts\n// the text or follows a space, so an email address such as dana@example.com opens nothing.\nfunction mentionQuery(before: string) {\n const match = before.match(/(?:^|\\s)@(\\w*)$/);\n return match ? match[1] : null;\n}\n\n// The query for where the caret is now.\nfunction queryAtCaret(field: HTMLTextAreaElement) {\n return mentionQuery(field.value.slice(0, field.selectionStart ?? field.value.length));\n}\n\n// Names with a word that starts with what was typed, at most 8. The person typing is left out.\nfunction matches(query: string) {\n const q = query.toLowerCase();\n return members.filter((m) => m.name !== me && m.name.toLowerCase().split(' ').some((w) => w.startsWith(q))).slice(0, MAX_MATCHES);\n}\n\nexport default function MentionListInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState(firstText);\n const [query, setQuery] = useState<string | null>(mentionQuery(firstText));\n const [active, setActive] = useState(0);\n // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.\n const [caret, setCaret] = useState<number | null>(null);\n const field = useRef<HTMLTextAreaElement>(null);\n\n const results = query === null ? [] : matches(query);\n // No match: the list closes.\n const open = results.length > 0;\n\n // The field opens with the caret at the end, after the @.\n useEffect(() => {\n const end = field.current?.value.length ?? 0;\n field.current?.setSelectionRange(end, end);\n }, []);\n\n useEffect(() => {\n if (caret === null || !field.current) return;\n field.current.focus();\n field.current.setSelectionRange(caret, caret);\n setCaret(null);\n }, [caret]);\n\n function change(value: string) {\n setText(value);\n const at = field.current?.selectionStart ?? value.length;\n setQuery(mentionQuery(value.slice(0, at)));\n setActive(0);\n }\n\n // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and\n // closes when the caret leaves it.\n function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {\n const next = queryAtCaret(e.currentTarget);\n if (next === query) return;\n setQuery(next);\n setActive(0);\n }\n\n // Puts '@Name ' in place of the @ and the word typed so far, and the caret after the space.\n function pick(m: Member) {\n const at = field.current?.selectionStart ?? text.length;\n const before = text.slice(0, at);\n const start = before.lastIndexOf('@');\n if (start < 0) return;\n const inserted = `@${m.name} `;\n setText(before.slice(0, start) + inserted + text.slice(at));\n setQuery(null);\n setCaret(start + inserted.length);\n }\n\n // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.\n function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!open) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {\n // Check the word at the caret again before taking the key. If nothing matches now, the list\n // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.\n const now = queryAtCaret(e.currentTarget);\n const found = now === null ? [] : matches(now);\n if (found.length === 0) {\n setQuery(null);\n return;\n }\n e.preventDefault();\n pick(found[now === query ? Math.min(active, found.length - 1) : 0]);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n setQuery(null);\n }\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n setQuery(null);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"mention-list-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={change}\n onSubmit={send}\n onKeyDown={keyDown}\n onSelect={caretMoved}\n // A press on a row keeps focus in the field, so this runs only when focus leaves for good.\n onBlur={() => setQuery(null)}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-activedescendant={open ? optionId(results[active]) : undefined}\n above={\n open ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"People and agents\" width={280}>\n {results.map((m, i) => (\n <MenuItem\n key={m.id}\n id={optionId(m)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n // A person may have no picture, so the avatar goes in icon: UserImage shows the initial.\n icon={m.agent ? <UserImage userHandle={m.name} icon={Bot} size={20} decorative /> : <UserImage userHandle={m.name} size={20} decorative />}\n label={m.name}\n tag={m.agent ? { label: 'Agent' } : undefined}\n onClick={() => pick(m)}\n />\n ))}\n </Menu>\n ) : undefined\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
1979
|
+
"uses": [
|
|
1980
|
+
"Center",
|
|
1981
|
+
"Composer",
|
|
1982
|
+
"Heading",
|
|
1983
|
+
"Menu",
|
|
1984
|
+
"MenuItem",
|
|
1985
|
+
"Message",
|
|
1986
|
+
"Paragraph",
|
|
1987
|
+
"Stack",
|
|
1988
|
+
"TimeStamp",
|
|
1989
|
+
"UserImage"
|
|
1990
|
+
]
|
|
1991
|
+
}
|
|
1992
|
+
]
|
|
1993
|
+
},
|
|
1994
|
+
{
|
|
1995
|
+
"id": "message-actions",
|
|
1996
|
+
"title": "Message actions",
|
|
1997
|
+
"kind": "design",
|
|
1998
|
+
"level": "organism",
|
|
1999
|
+
"area": "chat",
|
|
2000
|
+
"situation": "A person acts on one message: reacts to it, copies it, edits or deletes it.",
|
|
2001
|
+
"do": [
|
|
2002
|
+
"Put the actions in the Message's `actions`. They show while the pointer is on the row or focus is in it.",
|
|
2003
|
+
"Use the More menu on a touch screen, where `actions` always show: one button per row instead of four.",
|
|
2004
|
+
"Order them Add reaction, Copy, then Edit and Delete. Edit and Delete show only on the person's own messages.",
|
|
2005
|
+
"Give each `IconButton` a short `Tooltip`, such as 'Add reaction' or 'Copy'. Give it an `ariaLabel` in sentence case that names the row's message: 'Add reaction to message from Dana Lee'.",
|
|
2006
|
+
"Call the reaction action 'Add Reaction' in the menu, the same action as the 'Add reaction' button.",
|
|
2007
|
+
"Swap Copy's icon to `Check` for 2 seconds after it copies, as the rule 'Success shows where the person is looking' says.",
|
|
2008
|
+
"Show the toast 'Message copied.' when Copy is chosen from a menu, because the menu item is gone.",
|
|
2009
|
+
"Check that the example is still mounted before the clipboard promise sets state, starts a timer or shows a toast.",
|
|
2010
|
+
"Confirm Delete in the row, as the case 'Delete confirm' says for a row in a dense list. The row's `footer` shows 'Delete this message?', 'Cancel', then a danger 'Delete'.",
|
|
2011
|
+
"Make 'Cancel' a small tertiary Button and 'Delete' a small primary Button with `color=\"danger\"`. Hide the row's actions while it asks.",
|
|
2012
|
+
"Show 'Delete' as `loading` while the request runs, and disable 'Cancel'.",
|
|
2013
|
+
"Move focus to 'Cancel' when the confirm opens, and back to the row's Delete or More button after 'Cancel'.",
|
|
2014
|
+
"Remove the row once the message is deleted, and show a toast that names it: 'Message deleted.'",
|
|
2015
|
+
"Move focus to the next row's first action after a delete, or to the message box when no row follows.",
|
|
2016
|
+
"Edit the message in place, as the case 'Message edit' says. After Save or Cancel, focus goes to the row's Edit or More button.",
|
|
2017
|
+
"Put every action in a More menu when there are more than four: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Message actions\">`.",
|
|
2018
|
+
"Open the menu from the More button the person pressed: pass `event.currentTarget` to the Popover as `anchorEl`.",
|
|
2019
|
+
"Keep the More button on screen with `actionsVisible` while its menu is open.",
|
|
2020
|
+
"Make Delete the last item, a `MenuItem` with `color=\"danger\"`."
|
|
2021
|
+
],
|
|
2022
|
+
"dont": [
|
|
2023
|
+
"Do not delete a message on the first click.",
|
|
2024
|
+
"Do not open a Modal to confirm a delete. The confirm stays in the row, so the person keeps their place in the thread.",
|
|
2025
|
+
"Do not show the actions only on pointer hover. A keyboard and a touch screen must reach them too.",
|
|
2026
|
+
"Do not show Edit or Delete on someone else's message.",
|
|
2027
|
+
"Do not open the menu when the page loads."
|
|
2028
|
+
],
|
|
2029
|
+
"native": "On Apple put the actions in the row's `contextMenu`: Copy, Edit, Add Reaction, Create Task and Report, with Delete last in the `.destructive` role. Delete asks in a system `confirmationDialog`, not in the row.",
|
|
2030
|
+
"notBuiltYet": "Scindo on the web deletes a message with no confirm and has no Copy. Its row actions show only while the pointer is on the row, so a keyboard or a phone cannot reach them.",
|
|
2031
|
+
"seenIn": [
|
|
2032
|
+
"Scindo"
|
|
2033
|
+
],
|
|
2034
|
+
"options": [
|
|
2035
|
+
{
|
|
2036
|
+
"id": "hover-toolbar",
|
|
2037
|
+
"title": "Toolbar on the row",
|
|
2038
|
+
"useWhen": "A product used with a pointer, with three or four frequent actions.",
|
|
2039
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\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\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsHoverToolbar() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [copiedId, setCopiedId] = useState<string | null>(null);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's buttons by row id, so focus can move to one when the thing that had it is gone.\n const reactButtons = useRef<Record<string, Focusable>>({});\n const editButtons = useRef<Record<string, Focusable>>({});\n const deleteButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(copyTimer.current);\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(id: string) {\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, reacted: !m.reacted } : m)));\n }\n\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n setCopiedId(m.id);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopiedId(null), 2000);\n }, () => {});\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's Edit button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => editButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(id: string) {\n setConfirmingId(id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Delete button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => deleteButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's first action, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? reactButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\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 <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => {\n const own = m.from === me;\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n actions={\n editing || confirming ? undefined : (\n <>\n <Tooltip title=\"Add reaction\">\n <IconButton\n ref={(el) => { reactButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => react(m.id)}\n />\n </Tooltip>\n <Tooltip title={copiedId === m.id ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copiedId === m.id ? 'Check' : 'Copy'} ariaLabel={copiedId === m.id ? 'Copied' : `Copy message from ${m.from}`} onClick={() => copy(m)} />\n </Tooltip>\n {own && (\n <Tooltip title=\"Edit\">\n <IconButton ref={(el) => { editButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={() => startEditing(m)} />\n </Tooltip>\n )}\n {own && (\n <Tooltip title=\"Delete\">\n <IconButton ref={(el) => { deleteButtons.current[m.id] = el; }} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Trash2\" ariaLabel=\"Delete your message\" onClick={() => askToDelete(m.id)} />\n </Tooltip>\n )}\n </>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-hover-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-hover-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
2040
|
+
"uses": [
|
|
2041
|
+
"Button",
|
|
2042
|
+
"Center",
|
|
2043
|
+
"Cluster",
|
|
2044
|
+
"Composer",
|
|
2045
|
+
"Heading",
|
|
2046
|
+
"IconButton",
|
|
2047
|
+
"Message",
|
|
2048
|
+
"Paragraph",
|
|
2049
|
+
"Stack",
|
|
2050
|
+
"Tag",
|
|
2051
|
+
"TimeStamp",
|
|
2052
|
+
"Toaster",
|
|
2053
|
+
"Tooltip",
|
|
2054
|
+
"UserImage",
|
|
2055
|
+
"dismissToast",
|
|
2056
|
+
"toast"
|
|
2057
|
+
]
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
"id": "menu",
|
|
2061
|
+
"title": "More menu",
|
|
2062
|
+
"useWhen": "There are more than four actions, or the product is used on a touch screen.",
|
|
2063
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; edited?: boolean; reacted?: boolean };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },\n { id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },\n];\n\nexport default function MessageActionsMenu() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Row | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [editingId, setEditingId] = useState<string | null>(null);\n const [draft, setDraft] = useState('');\n const [saving, setSaving] = useState(false);\n // The row whose footer asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n // One timer per request, so a save and a delete never clear each other's.\n const saveTimer = useRef<ReturnType<typeof setTimeout>>();\n const deleteTimer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n const box = useRef<HTMLTextAreaElement>(null);\n const cancelDelete = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the timers and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(saveTimer.current);\n clearTimeout(deleteTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const editingRow = thread.find((m) => m.id === editingId);\n const canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;\n\n // A real app opens its reaction picker here; this one adds or removes a thumbs-up.\n function react(m: Row) {\n setThread((rows) => rows.map((r) => (r.id === m.id ? { ...r, reacted: !r.reacted } : r)));\n }\n\n // The menu closes when an item is chosen, so a copy shows a toast rather than a check.\n function copy(m: Row) {\n navigator.clipboard?.writeText(m.text).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Message copied.' }));\n }, () => {});\n }\n\n // A real app sends the task to the server here.\n function createTask(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `Task created from ${m.from}'s message.` }));\n }\n\n // A real app asks for a reason in a Modal, then sends the report.\n function report(m: Row) {\n toastIds.current.push(toast({ type: 'success', message: `${m.from}'s message reported to the workspace admins.` }));\n }\n\n function openMenu(m: Row, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === m.id) {\n closeMenu();\n return;\n }\n setMenuRow(m);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Escape, a click outside and every item close the menu. Popover's returnFocus gives focus back to More.\n function closeMenu() {\n setMenuOpen(false);\n }\n\n function choose(action: (m: Row) => void) {\n if (!menuRow) return;\n const m = menuRow;\n closeMenu();\n action(m);\n }\n\n // The field takes focus, with the caret after the text.\n function startEditing(m: Row) {\n setDraft(m.text);\n setEditingId(m.id);\n focusNext.current = () => {\n const end = field.current?.value.length ?? 0;\n field.current?.focus();\n field.current?.setSelectionRange(end, end);\n };\n }\n\n // The field that had focus is gone, so focus goes to the row's More button.\n function stopEditing(id: string) {\n setEditingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function cancelEditing() {\n if (saving || !editingId) return;\n stopEditing(editingId);\n }\n\n function save() {\n if (saving || !canSave || !editingId) return;\n const id = editingId;\n const value = draft.trim();\n setSaving(true);\n // Stands in for the request to the server.\n saveTimer.current = setTimeout(() => {\n setSaving(false);\n setThread((rows) => rows.map((m) => (m.id === id ? { ...m, text: value, edited: true } : m)));\n stopEditing(id);\n }, 1200);\n }\n\n // The confirm opens in the row's footer, with focus on 'Cancel'.\n function askToDelete(m: Row) {\n setConfirmingId(m.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepMessage() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const next = thread[thread.findIndex((m) => m.id === id) + 1];\n setDeleting(true);\n // Stands in for the request to the server.\n deleteTimer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setThread((rows) => rows.filter((m) => m.id !== id));\n toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));\n // The row is gone: focus goes to the next row's More button, or to the message box when none follows.\n // If the next row's button is not on screen, focus goes to the message box.\n focusNext.current = () => ((next ? moreButtons.current[next.id] : null) ?? box.current)?.focus();\n }, 1200);\n }\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\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 <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => {\n const editing = m.id === editingId;\n const confirming = m.id === confirmingId;\n return (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={\n <>\n {m.agent && <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />}\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n {m.agent && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>}\n {m.edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n footer={\n m.reacted || confirming ? (\n <Stack gap=\"small\">\n {m.reacted && <Tag variant=\"contained\" size=\"small\" state=\"selected\" label=\"👍 1\" aria-label=\"Thumbs up, 1 reaction\" />}\n {confirming && (\n // The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Delete this message?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label=\"Cancel deleting your message\" onClickButton={keepMessage} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label=\"Delete this message\" loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n </Stack>\n )}\n </Stack>\n ) : undefined\n }\n // One More button. Shown while the pointer is on the row or focus is in it, and always on a touch screen.\n // It stays on screen while its menu is open, though the pointer and focus are in the menu.\n actionsVisible={menuOpen && menuRow?.id === m.id}\n actions={\n editing || confirming ? undefined : (\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[m.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(m, e.currentTarget)}\n />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // Edit works as the case 'Message edit' says.\n <Composer\n ref={field}\n id=\"message-actions-menu-edit\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancelEditing();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelEditing} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n )}\n </Message>\n );\n })}\n </Stack>\n <Composer\n ref={box}\n id=\"message-actions-menu-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={closeMenu} returnFocus>\n <Menu navigable aria-label=\"Message actions\" width={200}>\n <MenuItem size=\"small\" iconName=\"SmilePlus\" label=\"Add Reaction\" onClick={() => choose(react)} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Copy\" onClick={() => choose(copy)} />\n {menuRow?.from === me && <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Edit\" onClick={() => choose(startEditing)} />}\n <MenuItem size=\"small\" iconName=\"ClipboardPlus\" label=\"Create Task\" onClick={() => choose(createTask)} />\n {menuRow?.from !== me && <MenuItem size=\"small\" iconName=\"Flag\" label=\"Report\" onClick={() => choose(report)} />}\n {menuRow?.from === me && <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
2064
|
+
"uses": [
|
|
2065
|
+
"Button",
|
|
2066
|
+
"Center",
|
|
2067
|
+
"Cluster",
|
|
2068
|
+
"Composer",
|
|
2069
|
+
"Heading",
|
|
2070
|
+
"IconButton",
|
|
2071
|
+
"Menu",
|
|
2072
|
+
"MenuItem",
|
|
2073
|
+
"Message",
|
|
2074
|
+
"Paragraph",
|
|
2075
|
+
"Popover",
|
|
2076
|
+
"Stack",
|
|
2077
|
+
"Tag",
|
|
2078
|
+
"TimeStamp",
|
|
2079
|
+
"Toaster",
|
|
2080
|
+
"Tooltip",
|
|
2081
|
+
"UserImage",
|
|
2082
|
+
"dismissToast",
|
|
2083
|
+
"toast"
|
|
2084
|
+
]
|
|
2085
|
+
}
|
|
2086
|
+
]
|
|
2087
|
+
},
|
|
2088
|
+
{
|
|
2089
|
+
"id": "message-attachments",
|
|
2090
|
+
"title": "Attachments",
|
|
2091
|
+
"kind": "design",
|
|
2092
|
+
"level": "organism",
|
|
2093
|
+
"area": "chat",
|
|
2094
|
+
"situation": "A person adds files to a message, and people open the files in a message that was sent.",
|
|
2095
|
+
"do": [
|
|
2096
|
+
"Show each waiting file as a `FileChip` in the Composer's `above` slot, with `onRemove`.",
|
|
2097
|
+
"Show a file that is still uploading with `state=\"uploading\"` and the `meta` 'Uploading'.",
|
|
2098
|
+
"Show a file that cannot be sent with `state=\"failed\"` and the reason in `meta`: 'Too large. The limit is 25 MB.'",
|
|
2099
|
+
"Pass `onClick` and the `meta` 'Failed. Try again' when the upload can be tried again. A file that is too large can only be removed.",
|
|
2100
|
+
"Announce when an upload finishes or fails: the app puts the words in a polite live region, since the chip announces nothing.",
|
|
2101
|
+
"Block sending while a file uploads or has failed, and say why under the chips: 'Wait for the upload to finish, then send.'",
|
|
2102
|
+
"Give that line an `id`, and point the message box at it with `aria-describedby`, so a screen reader hears why it cannot send.",
|
|
2103
|
+
"Say the limit in one line under the chips when it is reached: 'You can attach up to 5 files.' Disable the attach button too.",
|
|
2104
|
+
"Pass `canSubmit` so a message with files and no text can be sent.",
|
|
2105
|
+
"Keep the files and the text when a send fails. Show an inline error Alert above the message box, as the rule 'A form error shows next to the problem' says.",
|
|
2106
|
+
"Move focus to the next chip after a chip is removed, or to the message box when none is left, since the chip that had it is gone.",
|
|
2107
|
+
"Show images in a sent message as thumbnails: a `Grid` of `<Figure crop>` with an `Image` each. Write `alt` text that says what the image shows.",
|
|
2108
|
+
"Show other files as `FileChip`s that open the file, with the kind ('PDF'), the name and the size.",
|
|
2109
|
+
"Show a `FileChip` with the file's name in place of an image that fails to load, so the file can still be opened.",
|
|
2110
|
+
"Let the person open an image at full size. The example shows the thumbnails only."
|
|
2111
|
+
],
|
|
2112
|
+
"dont": [
|
|
2113
|
+
"Do not show a failed upload only in an Alert away from the file.",
|
|
2114
|
+
"Do not use the file name as the `alt` text of an image. Say what it shows.",
|
|
2115
|
+
"Do not send a message while one of its files is still uploading.",
|
|
2116
|
+
"Do not clear the waiting files when a send is blocked."
|
|
2117
|
+
],
|
|
2118
|
+
"native": "On Apple the attach button opens a menu with Photo Library and Files on iPhone, and opens Files on a Mac. Waiting files show as chips with a remove button. Sent images open full screen.",
|
|
2119
|
+
"notBuiltYet": "No product shows upload progress or a failed upload on the file itself. Scindo on the web shows a rejected file in an error Alert above the field, and its images use the file name as `alt` text.",
|
|
2120
|
+
"seenIn": [
|
|
2121
|
+
"Scindo"
|
|
2122
|
+
],
|
|
2123
|
+
"options": [
|
|
2124
|
+
{
|
|
2125
|
+
"id": "in-composer",
|
|
2126
|
+
"title": "In the composer",
|
|
2127
|
+
"useWhen": "Files are waiting to be sent with the next message.",
|
|
2128
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport FileChip from 'oneslash-design-system/components/fileChip';\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\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst MAX_FILES = 5;\n\ntype Upload = { id: string; name: string; kind: string; size: string; state: 'ready' | 'uploading' | 'failed'; error?: string };\ntype Row = { id: string; from: string; at: Date; text: string; files?: Upload[] };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Dana has the final versions.' },\n];\n\n// Opens with one file ready, one still uploading and one the server refused.\nconst firstFiles: Upload[] = [\n { id: 'f1', name: 'Launch brief.pdf', kind: 'PDF', size: '1.2 MB', state: 'ready' },\n { id: 'f2', name: 'Hero image.png', kind: 'PNG', size: '3.4 MB', state: 'uploading' },\n { id: 'f3', name: 'Product video.mov', kind: 'MOV', size: '48 MB', state: 'failed', error: 'Too large. The limit is 25 MB.' },\n];\n\n// What the attach button adds, in turn. A real app opens the file picker.\nconst sampleFiles = [\n { name: 'Press list.xlsx', kind: 'XLSX', size: '48 KB' },\n { name: 'Pricing sheet.pdf', kind: 'PDF', size: '320 KB' },\n { name: 'Logo.svg', kind: 'SVG', size: '12 KB' },\n];\n\n// Where a sent file opens. A real app links to the stored file.\nconst fileHref = (name: string) => `/files/${name.toLowerCase().replace(/\\s+/g, '-')}`;\n\n// The line that says why sending is blocked. The message box points at it with aria-describedby.\nconst blockedId = 'message-attachments-send-blocked';\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageAttachmentsInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n const [files, setFiles] = useState(firstFiles);\n const added = useRef(0);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops every upload still running.\n useEffect(() => () => {\n timers.current.forEach((t) => clearTimeout(t));\n timers.current = [];\n }, []);\n\n const atLimit = files.length >= MAX_FILES;\n const uploading = files.some((f) => f.state === 'uploading');\n const failed = files.find((f) => f.state === 'failed');\n const blockedReason = failed ? `Remove ${failed.name} to send.` : uploading ? 'Wait for the upload to finish, then send.' : null;\n\n function attach() {\n if (atLimit) return;\n const sample = sampleFiles[added.current % sampleFiles.length];\n const id = `a${added.current + 1}`;\n added.current += 1;\n setFiles((list) => [...list, { ...sample, id, state: 'uploading' }]);\n // Stands in for the request to the server.\n timers.current.push(\n setTimeout(() => {\n setFiles((list) => list.map((f) => (f.id === id ? { ...f, state: 'ready' } : f)));\n }, 1200),\n );\n }\n\n // The chip that had focus is gone. A real app moves focus to the next chip, or to the message box when\n // none is left. FileChip does not pass a ref to its remove button, so this example always uses the message box.\n function remove(id: string) {\n setFiles((list) => list.filter((f) => f.id !== id));\n field.current?.focus();\n }\n\n // The Composer calls this only when canSubmit is true: no upload running, none failed.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim(), files }]);\n setText('');\n setFiles([]);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n m.files && m.files.length > 0 ? (\n <Cluster gap=\"small\">\n {m.files.map((f) => (\n // A sent file opens when its chip is pressed.\n <FileChip key={f.id} name={f.name} kind={f.kind} meta={f.size} href={fileHref(f.name)} openInNewTab />\n ))}\n </Cluster>\n ) : undefined\n }\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"message-attachments-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n aria-describedby={blockedReason ? blockedId : undefined}\n // Files alone can be sent, but not while one uploads or has failed.\n canSubmit={(text.trim() !== '' || files.length > 0) && !uploading && !failed}\n above={\n files.length > 0 ? (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {files.map((f) => (\n <FileChip\n key={f.id}\n name={f.name}\n kind={f.kind}\n state={f.state}\n meta={f.state === 'uploading' ? 'Uploading' : f.state === 'failed' ? f.error : f.size}\n onRemove={() => remove(f.id)}\n />\n ))}\n </Cluster>\n {/* A real app also says these in a polite live region when they change. */}\n {blockedReason && (\n <Paragraph id={blockedId} size=\"caption\" tone=\"secondary\" measure=\"none\">{blockedReason}</Paragraph>\n )}\n {atLimit && (\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{`You can attach up to ${MAX_FILES} files.`}</Paragraph>\n )}\n </Stack>\n ) : undefined\n }\n tools={\n <Tooltip title=\"Attach files\">\n <IconButton\n color=\"iconOnly\"\n state={atLimit ? 'disabled' : 'enabled'}\n size=\"small\"\n iconName=\"Paperclip\"\n ariaLabel=\"Attach files\"\n onClick={attach}\n />\n </Tooltip>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
2129
|
+
"uses": [
|
|
2130
|
+
"Center",
|
|
2131
|
+
"Cluster",
|
|
2132
|
+
"Composer",
|
|
2133
|
+
"FileChip",
|
|
2134
|
+
"Heading",
|
|
2135
|
+
"IconButton",
|
|
2136
|
+
"Message",
|
|
2137
|
+
"Paragraph",
|
|
2138
|
+
"Stack",
|
|
2139
|
+
"TimeStamp",
|
|
2140
|
+
"Tooltip",
|
|
2141
|
+
"UserImage"
|
|
2142
|
+
]
|
|
2143
|
+
},
|
|
2144
|
+
{
|
|
2145
|
+
"id": "in-message",
|
|
2146
|
+
"title": "In a sent message",
|
|
2147
|
+
"useWhen": "Files are part of a message in the thread.",
|
|
2148
|
+
"source": "'use client';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport FileChip from 'oneslash-design-system/components/fileChip';\nimport Figure from 'oneslash-design-system/components/figure';\nimport Image from 'oneslash-design-system/components/image';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\n// Two small drawings stand in for the uploaded photos.\nconst hillside =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E\";\nconst desk =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E\";\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst before: Row = { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'Can someone send the launch assets?' };\nconst withFiles: Row = { id: 'm2', from: 'Dana Lee', at: new Date('2025-01-15T11:44:00Z'), text: 'Here are the two hero options and the brief.' };\n\nexport default function MessageAttachmentsInMessage() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={before.from}\n avatar={<UserImage userHandle={before.from} decorative />}\n name={before.from}\n meta={<TimeStamp createdAt={before.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{before.text}</Paragraph>\n </Message>\n <Message\n aria-label={withFiles.from}\n avatar={<UserImage userHandle={withFiles.from} decorative />}\n name={withFiles.from}\n meta={<TimeStamp createdAt={withFiles.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Stack gap=\"small\">\n {/* Small thumbnails: four columns, two of them used. A real app opens the full image on click. */}\n <Grid columns={4} compact gap=\"small\">\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={hillside} alt=\"Hero option A: a green hillside under a pale sky with the sun on the right\" width={160} height={120} />\n </Figure>\n <Figure crop={4 / 3} radius=\"control\">\n <Image src={desk} alt=\"Hero option B: a laptop on a wooden desk, its screen blue\" width={160} height={120} />\n </Figure>\n </Grid>\n <Cluster gap=\"small\">\n {/* Each chip opens the file. */}\n <FileChip name=\"Launch brief.pdf\" kind=\"PDF\" meta=\"1.2 MB\" href=\"/files/launch-brief.pdf\" openInNewTab />\n <FileChip name=\"Press list.xlsx\" kind=\"XLSX\" meta=\"48 KB\" href=\"/files/press-list.xlsx\" openInNewTab />\n </Cluster>\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{withFiles.text}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2149
|
+
"uses": [
|
|
2150
|
+
"Center",
|
|
2151
|
+
"Cluster",
|
|
2152
|
+
"Figure",
|
|
2153
|
+
"FileChip",
|
|
2154
|
+
"Grid",
|
|
2155
|
+
"Heading",
|
|
2156
|
+
"Image",
|
|
2157
|
+
"Message",
|
|
2158
|
+
"Paragraph",
|
|
2159
|
+
"Stack",
|
|
2160
|
+
"TimeStamp",
|
|
2161
|
+
"UserImage"
|
|
2162
|
+
]
|
|
2163
|
+
}
|
|
2164
|
+
]
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
"id": "message-composer",
|
|
2168
|
+
"title": "Message composer",
|
|
2169
|
+
"kind": "design",
|
|
2170
|
+
"level": "organism",
|
|
2171
|
+
"area": "chat",
|
|
2172
|
+
"situation": "A person writes a message at the bottom of a thread.",
|
|
2173
|
+
"do": [
|
|
2174
|
+
"Use `Composer` under the thread, with an `aria-label`, since it has no visible label.",
|
|
2175
|
+
"Send on Enter and add a line on Shift+Enter, on a keyboard. On a touch screen, set `submitOnEnter={false}` so Return adds a line.",
|
|
2176
|
+
"Say who will read the message in the placeholder: 'Message the team', or 'Message Acme Agent' while the agent is called.",
|
|
2177
|
+
"Add the sent message to the thread at once, and set the Composer's `value` to an empty string.",
|
|
2178
|
+
"Put the tools in `tools`: an attach `IconButton`, and a toggle that calls the agent, `state=\"selected\"` and `aria-pressed` while it is on.",
|
|
2179
|
+
"Pass `canSubmit` when a file alone can be sent.",
|
|
2180
|
+
"Put Stop on the agent's progress row, as the rule 'An agent shows its progress' says. The Composer keeps Send, so a message to people still goes.",
|
|
2181
|
+
"Pass `onStop` in a conversation with the agent only, so Send becomes Stop.",
|
|
2182
|
+
"Show the agent's name, its 'Agent' `Tag`, the model line, the seconds so far and a `StepList` on the progress row. The case 'Agent at work' has the full pattern.",
|
|
2183
|
+
"Show 'Working for 12 seconds' in the progress row's body, above the steps.",
|
|
2184
|
+
"Show 'Stop' as `loading` until the run has ended. Then 'Stopped. Nothing was changed.' replaces the progress row in the same place.",
|
|
2185
|
+
"Move focus to the message box when Stop goes away.",
|
|
2186
|
+
"Announce the progress row politely to screen readers: the app wraps the changing part in a polite live region, since the row has none.",
|
|
2187
|
+
"Show an inline error Alert above the message box when a message fails to send, as the rule 'A form error shows next to the problem' says. Keep the text so it can be sent again.",
|
|
2188
|
+
"Keep the draft when the person leaves the thread, and show it again when they come back."
|
|
2189
|
+
],
|
|
2190
|
+
"dont": [
|
|
2191
|
+
"Do not clear the field before the message is in the thread.",
|
|
2192
|
+
"Do not write a placeholder that does not say who reads the message, such as 'Type here'.",
|
|
2193
|
+
"Do not send on Return on a touch screen.",
|
|
2194
|
+
"Do not hide the Stop on the agent's row while the agent works.",
|
|
2195
|
+
"Do not turn Send into Stop in a thread that people also write in."
|
|
2196
|
+
],
|
|
2197
|
+
"native": "On Apple use a `TextField` with `axis: .vertical`. On a Mac, Return sends and Shift-Return adds a line. On an iPhone, Return adds a line. While the agent works, Send becomes Stop.",
|
|
2198
|
+
"notBuiltYet": "Scindo's Apple app shows only 'Message' as its placeholder when the agent is not called, so it does not say who will read the message.",
|
|
2199
|
+
"seenIn": [
|
|
2200
|
+
"Commentify",
|
|
2201
|
+
"Scindo"
|
|
2202
|
+
],
|
|
2203
|
+
"options": [
|
|
2204
|
+
{
|
|
2205
|
+
"id": "plain",
|
|
2206
|
+
"title": "Plain composer",
|
|
2207
|
+
"useWhen": "Only people read the thread.",
|
|
2208
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageComposerPlain() {\n const [thread, setThread] = useState(firstThread);\n // A real app keeps the draft per thread, so it is still there when the person comes back.\n const [text, setText] = useState('');\n\n // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is text.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) => (\n <Message\n key={m.id}\n aria-label={m.from}\n compact={followsOn(thread, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}\n <Composer\n id=\"message-composer-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
2209
|
+
"uses": [
|
|
2210
|
+
"Center",
|
|
2211
|
+
"Composer",
|
|
2212
|
+
"Heading",
|
|
2213
|
+
"Message",
|
|
2214
|
+
"Paragraph",
|
|
2215
|
+
"Stack",
|
|
2216
|
+
"TimeStamp",
|
|
2217
|
+
"UserImage"
|
|
2218
|
+
]
|
|
2219
|
+
},
|
|
2220
|
+
{
|
|
2221
|
+
"id": "with-tools",
|
|
2222
|
+
"title": "Composer with tools",
|
|
2223
|
+
"useWhen": "The person can attach files and call the agent.",
|
|
2224
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport FileChip from 'oneslash-design-system/components/fileChip';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\nconst agentName = 'Acme Agent';\n\ntype Attachment = { name: string; kind: string; size: string };\n// `progress` marks the agent's row while its run is live. The same row later holds the note or the reply.\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string; file?: Attachment; progress?: boolean };\n\nconst sampleFile: Attachment = { name: 'Launch email.pdf', kind: 'PDF', size: '240 KB' };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The launch email is ready for review.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I will read it after lunch.' },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function MessageComposerWithTools() {\n const [thread, setThread] = useState(firstThread);\n // A real app keeps the draft per thread, so it is still there when the person comes back.\n const [text, setText] = useState('');\n const [file, setFile] = useState<Attachment | null>(null);\n const [mentionAgent, setMentionAgent] = useState(false);\n // The agent's run while it works: the id of its row in the thread, and whether a stop has been asked for.\n const [run, setRun] = useState<{ rowId: string; stopping: boolean } | null>(null);\n const [seconds, setSeconds] = useState(0);\n const runTimer = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const field = useRef<HTMLTextAreaElement>(null);\n\n // On unmount it stops the agent's run, its clock and the cancel request.\n useEffect(() => () => {\n clearTimeout(runTimer.current);\n clearTimeout(cancel.current);\n clearInterval(tick.current);\n }, []);\n\n // The run is over: its own row, in the same place and with the same time, now holds the reply or the note.\n function endRun(rowId: string, text: string) {\n clearTimeout(runTimer.current);\n clearInterval(tick.current);\n setRun(null);\n setThread((rows) => rows.map((m) => (m.id === rowId ? { ...m, text, progress: false } : m)));\n }\n\n function addRow(row: Omit<Row, 'id'>) {\n setThread((rows) => [...rows, { ...row, id: `m${rows.length + 1}` }]);\n }\n\n // A real app opens the file picker here; this one attaches a sample file.\n function attach() {\n setFile(sampleFile);\n }\n\n function removeFile() {\n setFile(null);\n field.current?.focus();\n }\n\n // Enter sends and Shift+Enter adds a line. The Composer calls this only when there is something to send.\n function send() {\n // A real app sends the message to the server here and shows it at once.\n addRow({ from: me, at: new Date(), text: text.trim(), file: file ?? undefined });\n setText('');\n setFile(null);\n // One run at a time: a real app queues a second call to the agent.\n if (!mentionAgent || run) return;\n // The run gets one row, added now where the reply will appear. Messages sent during the run go below it.\n const startedAt = new Date();\n const rowId = `run-${startedAt.getTime()}`;\n setThread((rows) => [...rows, { id: rowId, from: agentName, agent: true, at: startedAt, text: '', progress: true }]);\n setRun({ rowId, stopping: false });\n setSeconds(0);\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n // Stands in for the agent's run.\n runTimer.current = setTimeout(() => {\n endRun(rowId, 'The email reads well. The pricing link in the second paragraph points to last year\\'s page.');\n }, 3000);\n }\n\n // Stop asks the server to end the run, and shows loading until it has. Only then does the note that it\n // stopped replace the progress row, in the same row. Stop is gone, so focus goes to the message box.\n function stop() {\n if (!run || run.stopping) return;\n clearTimeout(runTimer.current);\n setRun({ ...run, stopping: true });\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n endRun(run.rowId, 'Stopped. Nothing was changed.');\n field.current?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m, i) =>\n m.progress && run?.rowId === m.id ? (\n // While the agent works, its row shows where the reply will appear: the seconds so far,\n // the steps, and the only Stop. The case 'Agent at work' has the full pattern.\n <Message\n key={m.id}\n aria-label={`${m.from}, agent`}\n avatar={<UserImage userHandle={m.from} icon={Bot} decorative />}\n name={m.from}\n meta={agentMeta(m.at)}\n footer={\n // It shows loading while the run is stopping.\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={run.stopping} onClickButton={stop} />\n </Cluster>\n }\n >\n {/* A real app wraps this part in a polite live region, since StepList has none. */}\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList\n aria-label=\"Acme Agent's steps\"\n steps={[\n { label: 'Read the thread', status: 'done' },\n { label: 'Checking the links in the email', status: 'running' },\n ]}\n />\n </Stack>\n </Message>\n ) : (\n <Message\n key={m.id}\n aria-label={m.agent ? `${m.from}, agent` : m.from}\n compact={followsOn(thread, i)}\n avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative /> : <UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={m.agent ? agentMeta(m.at) : <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n // A sent file opens when its chip is pressed. A real app links to the stored file.\n footer={m.file ? <FileChip name={m.file.name} kind={m.file.kind} meta={m.file.size} href=\"/files/launch-email.pdf\" openInNewTab /> : undefined}\n >\n {m.text && <Paragraph measure=\"none\">{m.text}</Paragraph>}\n </Message>\n ),\n )}\n </Stack>\n {/* On a touch screen, pass submitOnEnter={false} so Return adds a line. */}\n <Composer\n ref={field}\n id=\"message-composer-tools-message\"\n aria-label=\"Message\"\n // The placeholder says who will read the message.\n placeholder={mentionAgent ? `Message ${agentName}` : 'Message the team'}\n value={text}\n onChange={setText}\n onSubmit={send}\n canSubmit={text.trim() !== '' || file !== null}\n // The Composer keeps Send while the agent works, so a message to people still goes. Stop is on the agent's row.\n above={file ? <FileChip name={file.name} kind={file.kind} meta={file.size} onRemove={removeFile} /> : undefined}\n tools={\n <>\n <Tooltip title=\"Attach files\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Paperclip\" ariaLabel=\"Attach files\" onClick={attach} />\n </Tooltip>\n <Tooltip title=\"Mention the agent\">\n <IconButton\n color=\"iconOnly\"\n state={mentionAgent ? 'selected' : 'enabled'}\n size=\"small\"\n icon={Bot}\n ariaLabel=\"Mention the agent\"\n aria-pressed={mentionAgent}\n onClick={() => setMentionAgent((on) => !on)}\n />\n </Tooltip>\n </>\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
2225
|
+
"uses": [
|
|
2226
|
+
"Button",
|
|
2227
|
+
"Center",
|
|
2228
|
+
"Cluster",
|
|
2229
|
+
"Composer",
|
|
2230
|
+
"FileChip",
|
|
2231
|
+
"Heading",
|
|
2232
|
+
"IconButton",
|
|
2233
|
+
"Message",
|
|
2234
|
+
"Paragraph",
|
|
2235
|
+
"Stack",
|
|
2236
|
+
"StepList",
|
|
2237
|
+
"Tag",
|
|
2238
|
+
"TimeStamp",
|
|
2239
|
+
"Tooltip",
|
|
2240
|
+
"UserImage"
|
|
2241
|
+
]
|
|
2242
|
+
}
|
|
2243
|
+
]
|
|
2244
|
+
},
|
|
2245
|
+
{
|
|
2246
|
+
"id": "message-edit",
|
|
2247
|
+
"title": "Message edit",
|
|
2248
|
+
"kind": "design",
|
|
2249
|
+
"level": "organism",
|
|
2250
|
+
"area": "chat",
|
|
2251
|
+
"situation": "A person changes the text of a message they sent.",
|
|
2252
|
+
"do": [
|
|
2253
|
+
"Replace the row's body with a `Composer` that holds the text, and focus it with the caret after the text.",
|
|
2254
|
+
"Put 'Cancel' and 'Save' in the Composer's `actions`: `<Button type=\"tertiary\" size=\"small\">`, then `<Button type=\"primary\" size=\"small\">`.",
|
|
2255
|
+
"Save on Enter, and cancel on Escape. Take Escape in `onKeyDown` with `preventDefault()` and `stopPropagation()`.",
|
|
2256
|
+
"Pass `canSubmit` so an empty or unchanged text cannot be saved, and keep 'Save' `state=\"disabled\"` until then.",
|
|
2257
|
+
"Show 'Save' as `loading` while the request runs, keep its label, and disable the field and 'Cancel'.",
|
|
2258
|
+
"Show the new text in the row once it is saved, with '(edited)' after the time.",
|
|
2259
|
+
"Show '(edited)' on a compact row, which has no time line, as a caption in the row's `footer`.",
|
|
2260
|
+
"Move focus to the row's Edit or More button after Save or Cancel, since the field that had it is gone.",
|
|
2261
|
+
"Keep the field, its text, 'Cancel' and 'Save' when the save fails. Show an inline error Alert above the field, as the rule 'A form error shows next to the problem' says.",
|
|
2262
|
+
"Offer Edit only on the person's own messages."
|
|
2263
|
+
],
|
|
2264
|
+
"dont": [
|
|
2265
|
+
"Do not open a Modal to edit a message. The text is on screen, so it becomes the field.",
|
|
2266
|
+
"Do not show a toast after an edit. The new text shows where the old one was.",
|
|
2267
|
+
"Do not change 'Save' to 'Saving…' while it runs.",
|
|
2268
|
+
"Do not let Escape in the field close a Modal or a panel around the thread."
|
|
2269
|
+
],
|
|
2270
|
+
"native": "On Apple the text becomes a field in the row, with 'Cancel' and 'Save', and the row shows '(edited)' after.",
|
|
2271
|
+
"notBuiltYet": "Scindo on the web saves and cancels with two icon buttons, a check and a cross, under the field. Scindo's Apple app shows 'Saving...' on its Save button while it saves.",
|
|
2272
|
+
"seenIn": [
|
|
2273
|
+
"Scindo"
|
|
2274
|
+
],
|
|
2275
|
+
"options": [
|
|
2276
|
+
{
|
|
2277
|
+
"id": "in-place",
|
|
2278
|
+
"title": "Edit in place",
|
|
2279
|
+
"useWhen": "The default: the message body becomes the field, where the text was.",
|
|
2280
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Button from 'oneslash-design-system/components/button';\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\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nconst question = { from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'When does the launch email go out?' };\nconst mine = { from: me, at: new Date('2025-01-15T11:42:00Z') };\n\nexport default function MessageEditInPlace() {\n const [text, setText] = useState('Thursday at 9:00.');\n const [edited, setEdited] = useState(false);\n // Opens with the message in edit mode, as if the person just chose Edit.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Thursday at 9:00.');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const field = useRef<HTMLTextAreaElement>(null);\n const editButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n\n // On unmount it stops the request.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Set when the person presses Edit. The example opens in edit mode without it, so nothing takes focus on load.\n const pressedEdit = useRef(false);\n\n // When the person opens the field, focus it with the caret after the text. When it closes, the field\n // that had focus is gone, so focus goes to the row's Edit button.\n useEffect(() => {\n if (!editing) {\n editButton.current?.focus();\n return;\n }\n if (!pressedEdit.current || !field.current) return;\n const end = field.current.value.length;\n field.current.focus();\n field.current.setSelectionRange(end, end);\n }, [editing]);\n\n // An empty or unchanged text has nothing to save.\n const canSave = draft.trim() !== '' && draft.trim() !== text;\n\n function startEditing() {\n pressedEdit.current = true;\n setDraft(text);\n setEditing(true);\n }\n\n function cancel() {\n if (saving) return;\n setEditing(false);\n }\n\n function save() {\n if (saving || !canSave) return;\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n setText(draft.trim());\n setEdited(true);\n setEditing(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={question.from}\n avatar={<UserImage userHandle={question.from} decorative />}\n name={question.from}\n meta={<TimeStamp createdAt={question.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{question.text}</Paragraph>\n </Message>\n <Message\n aria-label={mine.from}\n avatar={<UserImage userHandle={mine.from} decorative />}\n name={mine.from}\n meta={\n <>\n <TimeStamp createdAt={mine.at} dateFormat=\"absolute\" data=\"time\" />\n {edited && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">(edited)</Paragraph>}\n </>\n }\n actions={\n editing ? undefined : (\n <Tooltip title=\"Edit\">\n <IconButton ref={editButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Edit your message\" onClick={startEditing} />\n </Tooltip>\n )\n }\n >\n {editing ? (\n // The body becomes a Composer in place. Enter saves and Escape cancels.\n <Composer\n ref={field}\n id=\"message-edit-text\"\n aria-label=\"Edit message\"\n value={draft}\n onChange={setDraft}\n onSubmit={save}\n canSubmit={canSave}\n disabled={saving}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n cancel();\n }\n }}\n actions={\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancel} />\n <Button size=\"small\" type=\"primary\" state={canSave ? 'enabled' : 'disabled'} label=\"Save\" loading={saving} onClickButton={save} />\n </Cluster>\n }\n />\n ) : (\n <Paragraph measure=\"none\">{text}</Paragraph>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2281
|
+
"uses": [
|
|
2282
|
+
"Button",
|
|
2283
|
+
"Center",
|
|
2284
|
+
"Cluster",
|
|
2285
|
+
"Composer",
|
|
2286
|
+
"Heading",
|
|
2287
|
+
"IconButton",
|
|
2288
|
+
"Message",
|
|
2289
|
+
"Paragraph",
|
|
2290
|
+
"Stack",
|
|
2291
|
+
"TimeStamp",
|
|
2292
|
+
"Tooltip",
|
|
2293
|
+
"UserImage"
|
|
2294
|
+
]
|
|
2295
|
+
}
|
|
2296
|
+
]
|
|
2297
|
+
},
|
|
2298
|
+
{
|
|
2299
|
+
"id": "message-reactions",
|
|
2300
|
+
"title": "Reactions",
|
|
2301
|
+
"kind": "design",
|
|
2302
|
+
"level": "organism",
|
|
2303
|
+
"area": "chat",
|
|
2304
|
+
"situation": "People answer a message with an emoji instead of a reply.",
|
|
2305
|
+
"do": [
|
|
2306
|
+
"Put the reactions in the Message's `footer`: a `Cluster` of `Tag`s, then a small 'Add reaction' `IconButton`.",
|
|
2307
|
+
"Label each chip with the emoji and the count, such as '👍 3', and give it `state=\"selected\"` when the person reacted with it.",
|
|
2308
|
+
"Name the emoji in words in the chip's `aria-label`: 'Thumbs up, 3 reactions'. The chip's `aria-pressed` says whether the person reacted.",
|
|
2309
|
+
"Wrap each chip in a `Tooltip` that names who reacted, with the person last: 'Omar and you'.",
|
|
2310
|
+
"Add or remove the reaction when the chip is pressed, and change the count at once.",
|
|
2311
|
+
"Name the 'Add reaction' button after the row: 'Add reaction to message from Dana Lee'.",
|
|
2312
|
+
"Open the quick pick from 'Add reaction': `<Popover returnFocus>` around `<Menu navigable aria-label=\"Add reaction\">`, one `MenuItem` per emoji, named in words.",
|
|
2313
|
+
"Mark the emoji the person already used with an 'Added' tag. Picking it again removes it.",
|
|
2314
|
+
"Close the quick pick when an emoji is picked. Focus goes back to the button that opened it.",
|
|
2315
|
+
"Move focus to the 'Add reaction' button when the chip that had it disappears, because its count reached 0.",
|
|
2316
|
+
"Offer the six emoji for now: ODS has no full emoji picker yet."
|
|
2317
|
+
],
|
|
2318
|
+
"dont": [
|
|
2319
|
+
"Do not show a chip with a count of 0.",
|
|
2320
|
+
"Do not name a chip by its emoji alone. A screen reader may read it differently, or not at all.",
|
|
2321
|
+
"Do not wait for the server before the count changes.",
|
|
2322
|
+
"Do not open the quick pick on hover. Open it on a press."
|
|
2323
|
+
],
|
|
2324
|
+
"native": "On Apple a reaction is added from the row's `contextMenu`, with Add Reaction.",
|
|
2325
|
+
"notBuiltYet": "Commentify's reaction chips do not show which are the person's, and cannot be pressed. Commentify adds a reaction from a full emoji picker.",
|
|
2326
|
+
"seenIn": [
|
|
2327
|
+
"Commentify",
|
|
2328
|
+
"Scindo"
|
|
2329
|
+
],
|
|
2330
|
+
"options": [
|
|
2331
|
+
{
|
|
2332
|
+
"id": "chips",
|
|
2333
|
+
"title": "Reaction chips",
|
|
2334
|
+
"useWhen": "A message has reactions: each emoji shows under it with its count.",
|
|
2335
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\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\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// Each emoji's name in words, for its aria-label.\nconst emojiNames: Record<string, string> = { '👍': 'Thumbs up', '❤️': 'Heart', '🎉': 'Party popper' };\n\ntype Reaction = { emoji: string; by: string[] };\ntype Row = { id: string; from: string; at: Date; text: string; reactions: Reaction[] };\n\nconst firstThread: Row[] = [\n {\n id: 'm1',\n from: 'Ben Carter',\n at: new Date('2025-01-15T11:40:00Z'),\n text: 'The pricing page is live.',\n reactions: [\n { emoji: '👍', by: ['Omar Reyes', me] },\n { emoji: '🎉', by: ['Omar Reyes'] },\n ],\n },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Nice work. I will share it with the sales team.', reactions: [] },\n];\n\nconst firstName = (name: string) => name.split(' ')[0];\n\n// 'Omar and you': other people by first name, the person last.\nfunction whoReacted(by: string[]) {\n const names = [...by.filter((n) => n !== me).map(firstName), ...(by.includes(me) ? ['you'] : [])];\n if (names.length === 1) return names[0] === 'you' ? 'You' : names[0];\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\n// 'Thumbs up, 3 reactions'. The chip's aria-pressed says whether the person reacted.\nfunction chipName(r: Reaction) {\n const count = `${r.by.length} ${r.by.length === 1 ? 'reaction' : 'reactions'}`;\n return `${emojiNames[r.emoji]}, ${count}`;\n}\n\nexport default function MessageReactionsChips() {\n const [thread, setThread] = useState(firstThread);\n // Each row's 'Add reaction' button by row id. When the chip that had focus goes away, focus goes there.\n const addButtons = useRef<Record<string, HTMLButtonElement | HTMLAnchorElement | null>>({});\n const focusAdd = useRef<string | null>(null);\n\n useEffect(() => {\n if (!focusAdd.current) return;\n addButtons.current[focusAdd.current]?.focus();\n focusAdd.current = null;\n });\n\n // The count changes at once. A real app sends the change to the server and puts it back if that fails.\n function toggle(rowId: string, emoji: string) {\n const row = thread.find((m) => m.id === rowId);\n const chip = row?.reactions.find((r) => r.emoji === emoji);\n // The person's reaction was the last one, so the chip goes away.\n if (chip && chip.by.length === 1 && chip.by[0] === me) focusAdd.current = rowId;\n setThread((rows) =>\n rows.map((m) => {\n if (m.id !== rowId) return m;\n const has = m.reactions.find((r) => r.emoji === emoji);\n const reactions = has\n ? m.reactions.map((r) =>\n r.emoji !== emoji ? r : { ...r, by: r.by.includes(me) ? r.by.filter((n) => n !== me) : [...r.by, me] },\n )\n : [...m.reactions, { emoji, by: [me] }];\n // A chip with no reactions left goes away.\n return { ...m, reactions: reactions.filter((r) => r.by.length > 0) };\n }),\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Cluster gap=\"small\">\n {m.reactions.map((r) => (\n <Tooltip key={r.emoji} title={whoReacted(r.by)}>\n <Tag\n variant=\"contained\"\n size=\"small\"\n state={r.by.includes(me) ? 'selected' : 'enabled'}\n label={`${r.emoji} ${r.by.length}`}\n aria-label={chipName(r)}\n onClick={() => toggle(m.id, r.emoji)}\n />\n </Tooltip>\n ))}\n {/* A real app opens the quick pick here, as the option 'Quick pick' shows; this one adds a heart. */}\n <Tooltip title=\"Add reaction\">\n <IconButton\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"small\"\n ref={(el) => { addButtons.current[m.id] = el; }}\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n onClick={() => {\n if (!m.reactions.some((r) => r.emoji === '❤️' && r.by.includes(me))) toggle(m.id, '❤️');\n }}\n />\n </Tooltip>\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2336
|
+
"uses": [
|
|
2337
|
+
"Center",
|
|
2338
|
+
"Cluster",
|
|
2339
|
+
"Heading",
|
|
2340
|
+
"IconButton",
|
|
2341
|
+
"Message",
|
|
2342
|
+
"Paragraph",
|
|
2343
|
+
"Stack",
|
|
2344
|
+
"Tag",
|
|
2345
|
+
"TimeStamp",
|
|
2346
|
+
"Tooltip",
|
|
2347
|
+
"UserImage"
|
|
2348
|
+
]
|
|
2349
|
+
},
|
|
2350
|
+
{
|
|
2351
|
+
"id": "quick-pick",
|
|
2352
|
+
"title": "Quick pick",
|
|
2353
|
+
"useWhen": "A person adds a reaction from the six emoji people use most.",
|
|
2354
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Tag from 'oneslash-design-system/components/tag';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// The six emoji people use most, each named in words. ODS has no full emoji picker yet.\nconst quickEmoji = [\n { emoji: '👍', name: 'Thumbs up' },\n { emoji: '❤️', name: 'Heart' },\n { emoji: '😂', name: 'Tears of joy' },\n { emoji: '🎉', name: 'Party popper' },\n { emoji: '👀', name: 'Eyes' },\n { emoji: '🚀', name: 'Rocket' },\n];\nconst emojiName = (emoji: string) => quickEmoji.find((q) => q.emoji === emoji)?.name ?? emoji;\n\ntype Reaction = { emoji: string; by: string[] };\ntype Row = { id: string; from: string; at: Date; text: string; reactions: Reaction[] };\n\nconst firstThread: Row[] = [\n {\n id: 'm1',\n from: 'Ben Carter',\n at: new Date('2025-01-15T11:40:00Z'),\n text: 'The pricing page is live.',\n reactions: [{ emoji: '👍', by: ['Omar Reyes', me] }],\n },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Nice work. I will share it with the sales team.', reactions: [] },\n];\n\nconst firstName = (name: string) => name.split(' ')[0];\n\n// 'Omar and you': other people by first name, the person last.\nfunction whoReacted(by: string[]) {\n const names = [...by.filter((n) => n !== me).map(firstName), ...(by.includes(me) ? ['you'] : [])];\n if (names.length === 1) return names[0] === 'you' ? 'You' : names[0];\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\n// 'Thumbs up, 3 reactions'. The chip's aria-pressed says whether the person reacted.\nfunction chipName(r: Reaction) {\n const count = `${r.by.length} ${r.by.length === 1 ? 'reaction' : 'reactions'}`;\n return `${emojiName(r.emoji)}, ${count}`;\n}\n\nexport default function MessageReactionsQuickPick() {\n const [thread, setThread] = useState(firstThread);\n // Each row's 'Add reaction' button by row id. When the chip that had focus goes away, focus goes there.\n const addButtons = useRef<Record<string, HTMLButtonElement | HTMLAnchorElement | null>>({});\n const focusAdd = useRef<string | null>(null);\n\n useEffect(() => {\n if (!focusAdd.current) return;\n addButtons.current[focusAdd.current]?.focus();\n focusAdd.current = null;\n });\n // The row whose quick pick is open, and the button it opens from. Both stay set while it fades out.\n const [pickRow, setPickRow] = useState<Row | null>(null);\n const [pickAnchor, setPickAnchor] = useState<HTMLElement | null>(null);\n const [pickOpen, setPickOpen] = useState(false);\n\n // The count changes at once. A real app sends the change to the server and puts it back if that fails.\n function toggle(rowId: string, emoji: string) {\n const row = thread.find((m) => m.id === rowId);\n const chip = row?.reactions.find((r) => r.emoji === emoji);\n // The person's reaction was the last one, so the chip goes away.\n if (chip && chip.by.length === 1 && chip.by[0] === me) focusAdd.current = rowId;\n setThread((rows) =>\n rows.map((m) => {\n if (m.id !== rowId) return m;\n const has = m.reactions.find((r) => r.emoji === emoji);\n const reactions = has\n ? m.reactions.map((r) =>\n r.emoji !== emoji ? r : { ...r, by: r.by.includes(me) ? r.by.filter((n) => n !== me) : [...r.by, me] },\n )\n : [...m.reactions, { emoji, by: [me] }];\n // A chip with no reactions left goes away.\n return { ...m, reactions: reactions.filter((r) => r.by.length > 0) };\n }),\n );\n }\n\n function openPick(m: Row, anchor: HTMLElement) {\n if (pickOpen && pickRow?.id === m.id) {\n setPickOpen(false);\n return;\n }\n setPickRow(m);\n setPickAnchor(anchor);\n setPickOpen(true);\n }\n\n // Escape, a click outside and a pick close it. Popover's returnFocus gives focus back to 'Add reaction'.\n function closePick() {\n setPickOpen(false);\n }\n\n function pick(emoji: string) {\n if (!pickRow) return;\n closePick();\n toggle(pickRow.id, emoji);\n }\n\n // The open row, read from the thread so the quick pick shows its reactions as they are now.\n const openRow = thread.find((m) => m.id === pickRow?.id);\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n footer={\n <Cluster gap=\"small\">\n {m.reactions.map((r) => (\n <Tooltip key={r.emoji} title={whoReacted(r.by)}>\n <Tag\n variant=\"contained\"\n size=\"small\"\n state={r.by.includes(me) ? 'selected' : 'enabled'}\n label={`${r.emoji} ${r.by.length}`}\n aria-label={chipName(r)}\n onClick={() => toggle(m.id, r.emoji)}\n />\n </Tooltip>\n ))}\n <Tooltip title=\"Add reaction\">\n <IconButton\n color=\"iconOnly\"\n state={pickOpen && pickRow?.id === m.id ? 'selected' : 'enabled'}\n size=\"small\"\n ref={(el) => { addButtons.current[m.id] = el; }}\n iconName=\"SmilePlus\"\n ariaLabel={`Add reaction to message from ${m.from}`}\n aria-haspopup=\"menu\"\n aria-expanded={pickOpen && pickRow?.id === m.id}\n onClick={(e: { currentTarget: HTMLElement }) => openPick(m, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n </Stack>\n {/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}\n <Popover open={pickOpen} anchorEl={pickAnchor} onClose={closePick} returnFocus>\n <Menu navigable aria-label=\"Add reaction\" width={200}>\n {quickEmoji.map((q) => (\n <MenuItem\n key={q.emoji}\n size=\"small\"\n icon={q.emoji}\n label={q.name}\n // Picking an emoji the person already used removes it.\n tag={openRow?.reactions.some((r) => r.emoji === q.emoji && r.by.includes(me)) ? { label: 'Added', variant: 'textOnly' } : undefined}\n onClick={() => pick(q.emoji)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
2355
|
+
"uses": [
|
|
2356
|
+
"Center",
|
|
2357
|
+
"Cluster",
|
|
2358
|
+
"Heading",
|
|
2359
|
+
"IconButton",
|
|
2360
|
+
"Menu",
|
|
2361
|
+
"MenuItem",
|
|
2362
|
+
"Message",
|
|
2363
|
+
"Paragraph",
|
|
2364
|
+
"Popover",
|
|
2365
|
+
"Stack",
|
|
2366
|
+
"Tag",
|
|
2367
|
+
"TimeStamp",
|
|
2368
|
+
"Tooltip",
|
|
2369
|
+
"UserImage"
|
|
2370
|
+
]
|
|
2371
|
+
}
|
|
2372
|
+
]
|
|
2373
|
+
},
|
|
2374
|
+
{
|
|
2375
|
+
"id": "message-row",
|
|
2376
|
+
"title": "Message row",
|
|
2377
|
+
"kind": "design",
|
|
2378
|
+
"level": "organism",
|
|
2379
|
+
"area": "chat",
|
|
2380
|
+
"situation": "A thread shows messages from people, and sometimes from an agent.",
|
|
2381
|
+
"do": [
|
|
2382
|
+
"Show each row with `Message`: the sender's `UserImage`, their name and the time. A person's avatar is their picture or their initial.",
|
|
2383
|
+
"Pass `decorative` to the avatar, since the name beside it is already read.",
|
|
2384
|
+
"Mark an agent's row as the rule 'An agent says what it is' says: an icon avatar, its name, an 'Agent' `Tag` and the model line beside the time.",
|
|
2385
|
+
"Give an agent's avatar `UserImage` with `icon`: the product's own agent shows the product's mark, and an agent from outside shows a plain `Bot` icon.",
|
|
2386
|
+
"Write the model line in small secondary text, such as `<Paragraph size=\"caption\" tone=\"secondary\">`, when the product knows the model.",
|
|
2387
|
+
"Show the time with `<TimeStamp dateFormat=\"absolute\" data=\"time\">`. The date line says the day.",
|
|
2388
|
+
"Make a row `compact` when the row above is from the same sender, less than 5 minutes older and on the same day.",
|
|
2389
|
+
"Put a date line between days, a `Line` with a `label` that reads 'Today', 'Yesterday', or the full date with the year: 'Monday, January 13, 2025'.",
|
|
2390
|
+
"Pass an `aria-label` that names the sender on every row, compact ones too: 'Dana Lee', or 'Acme Agent, agent'. The time is in the row.",
|
|
2391
|
+
"Give the list that holds the rows `role=\"log\"`, so a screen reader reads new messages as they arrive.",
|
|
2392
|
+
"Write an agent's text as plain sentences in `Paragraph`."
|
|
2393
|
+
],
|
|
2394
|
+
"dont": [
|
|
2395
|
+
"Do not show a photo or an initial for an agent.",
|
|
2396
|
+
"Do not group rows from two senders, or rows from two days. The first row after a date line shows its header.",
|
|
2397
|
+
"Do not leave the `aria-label` off a compact row. It shows no name.",
|
|
2398
|
+
"Do not put the agent's model in its name. It goes on the model line."
|
|
2399
|
+
],
|
|
2400
|
+
"native": "On Apple a row shows the avatar, the name and the time, with an 'Agent' label next to an agent's name.",
|
|
2401
|
+
"notBuiltYet": "Scindo on the web shows no 'Agent' tag on an agent's row, and its message list is not a log for screen readers. Scindo's Apple app shows no model name and does not group messages.",
|
|
2402
|
+
"seenIn": [
|
|
2403
|
+
"Commentify",
|
|
2404
|
+
"Scindo"
|
|
2405
|
+
],
|
|
2406
|
+
"options": [
|
|
2407
|
+
{
|
|
2408
|
+
"id": "person-and-agent",
|
|
2409
|
+
"title": "People and an agent",
|
|
2410
|
+
"useWhen": "A thread with gaps between messages: every row shows who and when.",
|
|
2411
|
+
"source": "'use client';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Row = { id: string; from: string; agent?: boolean; at: Date; text: string };\n\nconst thread: Row[] = [\n { id: 'm1', from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you list what is still open for the launch?' },\n { id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'Three tasks are open: the press kit, the pricing page and the launch email.' },\n { id: 'm3', from: 'Ben Carter', at: new Date('2025-01-15T11:44:00Z'), text: 'I can take the press kit.' },\n];\n\nexport default function MessageRowPersonAndAgent() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) =>\n m.agent ? (\n // An agent's row: an icon avatar, its name, an 'Agent' tag, the time and the model line.\n // The product's own agent shows the product's mark; an agent from outside shows a plain bot icon.\n // Acme has no mark here, so Acme Agent uses Bot.\n <Message\n key={m.id}\n aria-label={`${m.from}, agent`}\n avatar={<UserImage userHandle={m.from} icon={Bot} decorative />}\n name={m.from}\n meta={\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n }\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ) : (\n // A person's row: their picture or initial, their name and the time.\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ),\n )}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2412
|
+
"uses": [
|
|
2413
|
+
"Center",
|
|
2414
|
+
"Heading",
|
|
2415
|
+
"Message",
|
|
2416
|
+
"Paragraph",
|
|
2417
|
+
"Stack",
|
|
2418
|
+
"Tag",
|
|
2419
|
+
"TimeStamp",
|
|
2420
|
+
"UserImage"
|
|
2421
|
+
]
|
|
2422
|
+
},
|
|
2423
|
+
{
|
|
2424
|
+
"id": "grouped",
|
|
2425
|
+
"title": "Grouped rows",
|
|
2426
|
+
"useWhen": "A busy thread: follow-on rows from one sender drop the avatar and the name.",
|
|
2427
|
+
"source": "'use client';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\n// A real app builds each date line from the message times, in the reader's time zone, and labels the\n// days 'Today', 'Yesterday', or the full date with the year. These lines are fixed, so the times sit\n// near midday UTC, where the date is the same in most time zones.\nconst days: { label: string; rows: Row[] }[] = [\n {\n label: 'Monday, January 13, 2025',\n rows: [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-13T12:10:00Z'), text: 'I sent the pricing page draft to legal.' },\n { id: 'm2', from: 'Ben Carter', at: new Date('2025-01-13T12:12:00Z'), text: 'They usually answer within a day.' },\n ],\n },\n {\n label: 'Today',\n rows: [\n { id: 'm3', from: 'Ben Carter', at: new Date('2025-01-15T11:30:00Z'), text: 'Legal approved the pricing page.' },\n { id: 'm4', from: 'Ben Carter', at: new Date('2025-01-15T11:31:00Z'), text: 'They asked for two small wording changes, both in the footer.' },\n { id: 'm5', from: 'Ben Carter', at: new Date('2025-01-15T11:33:00Z'), text: 'I made them already.' },\n { id: 'm6', from: 'Dana Lee', at: new Date('2025-01-15T11:45:00Z'), text: 'Thanks. I will publish it this afternoon.' },\n ],\n },\n];\n\nconst FIVE_MINUTES = 5 * 60 * 1000;\n\n// A follow-on row: the same sender as the row above, less than 5 minutes later and on the same day.\nfunction followsOn(rows: Row[], i: number) {\n const prev = rows[i - 1];\n return (\n !!prev &&\n prev.from === rows[i].from &&\n rows[i].at.getTime() - prev.at.getTime() < FIVE_MINUTES &&\n rows[i].at.toDateString() === prev.at.toDateString()\n );\n}\n\nexport default function MessageRowGrouped() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"medium\">\n {days.map((day) => (\n <Stack key={day.label} gap=\"small\">\n <Line label={day.label} />\n {day.rows.map((m, i) => (\n <Message\n key={m.id}\n // A compact row shows no name, so its aria-label carries it.\n aria-label={m.from}\n compact={followsOn(day.rows, i)}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n ))}\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2428
|
+
"uses": [
|
|
2429
|
+
"Center",
|
|
2430
|
+
"Heading",
|
|
2431
|
+
"Line",
|
|
2432
|
+
"Message",
|
|
2433
|
+
"Paragraph",
|
|
2434
|
+
"Stack",
|
|
2435
|
+
"TimeStamp",
|
|
2436
|
+
"UserImage"
|
|
2437
|
+
]
|
|
2438
|
+
}
|
|
2439
|
+
]
|
|
2440
|
+
},
|
|
2441
|
+
{
|
|
2442
|
+
"id": "not-found-page",
|
|
2443
|
+
"title": "Page not found",
|
|
2444
|
+
"kind": "design",
|
|
2445
|
+
"level": "page",
|
|
2446
|
+
"area": "state",
|
|
2447
|
+
"situation": "A person opens a link to a page that does not exist.",
|
|
2448
|
+
"do": [
|
|
2449
|
+
"Say 'Page not found' in a `Heading` with `level={1}`.",
|
|
2450
|
+
"Add one line on what may have happened: 'The link may be wrong, or the page was moved or removed.'",
|
|
2451
|
+
"Offer one Button home: 'Go Home'."
|
|
2452
|
+
],
|
|
2453
|
+
"dont": [
|
|
2454
|
+
"Do not make '404' the heading.",
|
|
2455
|
+
"Do not show a line of text with no way home.",
|
|
2456
|
+
"Do not blame the person for the link."
|
|
2457
|
+
],
|
|
2458
|
+
"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'.",
|
|
2459
|
+
"seenIn": [
|
|
2460
|
+
"Commentify",
|
|
2461
|
+
"Scindo",
|
|
2462
|
+
"jinhwankim.com"
|
|
2463
|
+
],
|
|
2464
|
+
"options": [
|
|
2465
|
+
{
|
|
2466
|
+
"id": "full-page",
|
|
2467
|
+
"title": "Full page",
|
|
2468
|
+
"useWhen": "The address is outside the app shell, so nothing else can show.",
|
|
2469
|
+
"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",
|
|
2470
|
+
"uses": [
|
|
2471
|
+
"Button",
|
|
2472
|
+
"Center",
|
|
2473
|
+
"Cluster",
|
|
2474
|
+
"Heading",
|
|
2475
|
+
"Paragraph",
|
|
2476
|
+
"Stack"
|
|
2477
|
+
]
|
|
2478
|
+
},
|
|
2479
|
+
{
|
|
2480
|
+
"id": "in-shell",
|
|
2481
|
+
"title": "Inside the shell",
|
|
2482
|
+
"useWhen": "The address is inside the app and the navigation still works.",
|
|
2483
|
+
"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",
|
|
2484
|
+
"uses": [
|
|
2485
|
+
"Button",
|
|
2486
|
+
"Cluster",
|
|
2487
|
+
"Heading",
|
|
2488
|
+
"Image",
|
|
2489
|
+
"Paragraph",
|
|
2490
|
+
"Stack",
|
|
2491
|
+
"Surface",
|
|
2492
|
+
"Tab",
|
|
2493
|
+
"TabsContainer"
|
|
2494
|
+
]
|
|
2495
|
+
}
|
|
2496
|
+
]
|
|
2497
|
+
},
|
|
2498
|
+
{
|
|
2499
|
+
"id": "oauth-consent",
|
|
2500
|
+
"title": "OAuth consent",
|
|
2501
|
+
"kind": "design",
|
|
2502
|
+
"level": "page",
|
|
2503
|
+
"area": "auth",
|
|
2504
|
+
"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.",
|
|
2505
|
+
"do": [
|
|
2506
|
+
"Name the app in a `Heading` with `level={1}`: 'Acme CLI wants to connect to Acme'.",
|
|
2507
|
+
"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'.",
|
|
2508
|
+
"Say how to remove the access later: 'You can remove its access at any time in Settings, under Connected apps.'",
|
|
2509
|
+
"Show the account that gives the access, with a text-only 'Not You? Switch Account' Button under it.",
|
|
2510
|
+
"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.",
|
|
2511
|
+
"Say where the person goes next: 'You will go back to cli.acme.dev.'",
|
|
2512
|
+
"Put 'Cancel' first and 'Allow' second, side by side and the same width, in a `Grid` with `columns={2}`.",
|
|
2513
|
+
"Show `loading` on 'Allow' and disable 'Cancel' and every field while the request runs.",
|
|
2514
|
+
"Show `LoadingScreen` with `label=\"Going back to Acme CLI…\"` while the browser goes back, after 'Allow' and after 'Cancel'.",
|
|
2515
|
+
"Send 'Cancel' back to the app with `error=access_denied`, and return the `state` value the app sent on both paths.",
|
|
2516
|
+
"Leave wider access off until the person turns it on, and say under it what it adds."
|
|
2517
|
+
],
|
|
2518
|
+
"dont": [
|
|
2519
|
+
"Do not color 'Allow' or 'Cancel' as danger. Allowing is the person's choice, not a destructive action.",
|
|
2520
|
+
"Do not turn on wider access for the person.",
|
|
2521
|
+
"Do not name the access by its scope id, such as 'tasks:write'.",
|
|
2522
|
+
"Do not label Cancel 'Deny' or 'No'."
|
|
2523
|
+
],
|
|
2524
|
+
"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.",
|
|
2525
|
+
"seenIn": [
|
|
2526
|
+
"Commentify",
|
|
2527
|
+
"Scindo"
|
|
2528
|
+
],
|
|
2529
|
+
"options": [
|
|
2530
|
+
{
|
|
2531
|
+
"id": "simple",
|
|
2532
|
+
"title": "One account, one access",
|
|
2533
|
+
"useWhen": "The app gets one set of access to one account, so the only choice is to allow it or not.",
|
|
2534
|
+
"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",
|
|
2535
|
+
"uses": [
|
|
2536
|
+
"Alert",
|
|
2537
|
+
"Button",
|
|
2538
|
+
"Center",
|
|
2539
|
+
"Cluster",
|
|
2540
|
+
"Grid",
|
|
2541
|
+
"Heading",
|
|
2542
|
+
"Image",
|
|
2543
|
+
"LoadingScreen",
|
|
2544
|
+
"Paragraph",
|
|
2545
|
+
"Stack",
|
|
2546
|
+
"UserImage"
|
|
2547
|
+
]
|
|
2548
|
+
},
|
|
2549
|
+
{
|
|
2550
|
+
"id": "with-scope",
|
|
2551
|
+
"title": "Workspace and wider access",
|
|
2552
|
+
"useWhen": "The person picks the workspace the app can use, or turns on wider access.",
|
|
2553
|
+
"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",
|
|
2554
|
+
"uses": [
|
|
2555
|
+
"Alert",
|
|
2556
|
+
"Button",
|
|
2557
|
+
"Center",
|
|
2558
|
+
"Checkbox",
|
|
2559
|
+
"Cluster",
|
|
2560
|
+
"Grid",
|
|
2561
|
+
"Heading",
|
|
2562
|
+
"Image",
|
|
2563
|
+
"LoadingScreen",
|
|
2564
|
+
"Paragraph",
|
|
2565
|
+
"Select",
|
|
2566
|
+
"Stack",
|
|
2567
|
+
"UserImage"
|
|
2568
|
+
]
|
|
2569
|
+
}
|
|
2570
|
+
]
|
|
2571
|
+
},
|
|
2572
|
+
{
|
|
2573
|
+
"id": "rename",
|
|
2574
|
+
"title": "Rename",
|
|
2575
|
+
"kind": "design",
|
|
2576
|
+
"level": "organism",
|
|
2577
|
+
"area": "confirm",
|
|
2578
|
+
"situation": "A person renames something, such as a project or a channel.",
|
|
2579
|
+
"do": [
|
|
2580
|
+
"Title the Modal 'Rename' and the thing, such as 'Rename Project', and give its action the same verb: 'Rename'.",
|
|
2581
|
+
"Keep 'Rename' `state=\"disabled\"` while the name is empty or unchanged.",
|
|
2582
|
+
"Save on Enter too: put the field in a `Form`.",
|
|
2583
|
+
"Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
|
|
2584
|
+
"Focus the field with `autoFocus` when the name becomes a field in place.",
|
|
2585
|
+
"Save on Enter and when the person leaves the field. Cancel on Escape, and when the name is empty."
|
|
2586
|
+
],
|
|
2587
|
+
"dont": [
|
|
2588
|
+
"Do not label the Modal's action 'Save' or 'OK'.",
|
|
2589
|
+
"Do not show a toast after a rename. The new name shows where the old one was.",
|
|
2590
|
+
"Do not save an empty name.",
|
|
2591
|
+
"Do not drop what the person typed when they leave the field."
|
|
2592
|
+
],
|
|
2593
|
+
"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.",
|
|
2594
|
+
"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.",
|
|
2595
|
+
"seenIn": [
|
|
2596
|
+
"Commentify",
|
|
2597
|
+
"Scindo"
|
|
2598
|
+
],
|
|
2599
|
+
"options": [
|
|
2600
|
+
{
|
|
2601
|
+
"id": "modal",
|
|
2602
|
+
"title": "Rename in a Modal",
|
|
2603
|
+
"useWhen": "Rename is opened from a menu or from far away from the name.",
|
|
2604
|
+
"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",
|
|
2605
|
+
"uses": [
|
|
2606
|
+
"Button",
|
|
2607
|
+
"Center",
|
|
2608
|
+
"Cluster",
|
|
2609
|
+
"Form",
|
|
2610
|
+
"Heading",
|
|
2611
|
+
"Modal",
|
|
2612
|
+
"Paragraph",
|
|
2613
|
+
"Stack",
|
|
2614
|
+
"TextField"
|
|
2615
|
+
]
|
|
2616
|
+
},
|
|
2617
|
+
{
|
|
2618
|
+
"id": "inline",
|
|
2619
|
+
"title": "Rename in place",
|
|
2620
|
+
"useWhen": "The name is on screen, and it becomes a field.",
|
|
2621
|
+
"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",
|
|
2622
|
+
"uses": [
|
|
2623
|
+
"Center",
|
|
2624
|
+
"Cluster",
|
|
2625
|
+
"Heading",
|
|
2626
|
+
"IconButton",
|
|
2627
|
+
"Paragraph",
|
|
2628
|
+
"Stack",
|
|
2629
|
+
"TextField",
|
|
2630
|
+
"Tooltip"
|
|
2631
|
+
]
|
|
2632
|
+
}
|
|
2633
|
+
]
|
|
2634
|
+
},
|
|
2635
|
+
{
|
|
2636
|
+
"id": "reply-feedback",
|
|
2637
|
+
"title": "Reply feedback",
|
|
2638
|
+
"kind": "design",
|
|
2639
|
+
"level": "organism",
|
|
2640
|
+
"area": "agent",
|
|
2641
|
+
"situation": "The agent has replied, and the person can say whether the reply helped.",
|
|
2642
|
+
"do": [
|
|
2643
|
+
"Put a row of small `IconButton`s with Tooltips in the agent reply's `footer`: thumbs up, thumbs down, Copy, then Regenerate.",
|
|
2644
|
+
"Name them for the reply: 'Mark reply as helpful', 'Mark reply as not helpful', 'Copy reply' and 'Regenerate reply'.",
|
|
2645
|
+
"Add what tells the replies apart to the names when several replies are on screen, such as the question each one answers.",
|
|
2646
|
+
"Mark the pressed thumb with `state=\"selected\"` and `aria-pressed`. Pressing it again clears it, and pressing the other thumb moves the mark.",
|
|
2647
|
+
"Show 'Thanks. This helps the agent improve.' after the buttons for 2 seconds. It is the only confirmation, since the result shows in place.",
|
|
2648
|
+
"Confirm in place, unlike the case 'Feedback form', which sends from a Modal and confirms with a toast.",
|
|
2649
|
+
"Announce the thanks politely: the app wraps it in a polite live region.",
|
|
2650
|
+
"Swap Copy's icon to `Check` for 2 seconds once the reply is copied.",
|
|
2651
|
+
"Show Regenerate on the latest reply only. It turns the row into the agent's progress row with 'Stop', as the case 'Agent at work' shows.",
|
|
2652
|
+
"Leave the old reply's time off the progress row while the new reply is written.",
|
|
2653
|
+
"Move focus to 'Stop' when Regenerate turns the row into a progress row.",
|
|
2654
|
+
"Keep the reply and its buttons when Regenerate fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.",
|
|
2655
|
+
"Keep the reply as it was when the person presses 'Stop', and say 'Stopped. Nothing was changed.' under it.",
|
|
2656
|
+
"Move focus back to Regenerate when the new reply is ready or the run has stopped.",
|
|
2657
|
+
"Show 'What was wrong?' after thumbs down, with four reason `Tag`s with `toggle={false}` and a tertiary small 'Skip' Button.",
|
|
2658
|
+
"Group the reasons under the question and name the group 'What was wrong?', so a screen reader hears them together.",
|
|
2659
|
+
"Close the reasons when the person picks one or presses 'Skip', show the thanks, and move focus back to thumbs down.",
|
|
2660
|
+
"Give the list that holds the rows `role=\"log\"`."
|
|
2661
|
+
],
|
|
2662
|
+
"dont": [
|
|
2663
|
+
"Do not show a toast for feedback. The thanks shows where the person pressed.",
|
|
2664
|
+
"Do not ask for a reason after thumbs up.",
|
|
2665
|
+
"Do not make the person pick a reason. 'Skip' closes the row.",
|
|
2666
|
+
"Do not show feedback buttons on a person's message.",
|
|
2667
|
+
"Do not show Regenerate on an older reply."
|
|
2668
|
+
],
|
|
2669
|
+
"notBuiltYet": "Scindo on the web shows thumbs down only, with no thumbs up and no Copy, and the button goes away once pressed. Its thanks reads 'Noted, we'll improve.' Its reasons are Buttons, Skip is a cross, and Regenerate sits in the hover toolbar. Scindo's Apple app has no feedback buttons and no Regenerate.",
|
|
2670
|
+
"seenIn": [
|
|
2671
|
+
"Scindo"
|
|
2672
|
+
],
|
|
2673
|
+
"options": [
|
|
2674
|
+
{
|
|
2675
|
+
"id": "thumbs",
|
|
2676
|
+
"title": "Thumbs",
|
|
2677
|
+
"useWhen": "The team wants a signal and will not read reasons.",
|
|
2678
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackThumbs() {\n const [thumb, setThumb] = useState<Thumb>(null);\n const [thanks, setThanks] = useState(false);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n clearTimeout(thanksTimer.current);\n setThanks(value !== null);\n if (value !== null) thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2679
|
+
"uses": [
|
|
2680
|
+
"Button",
|
|
2681
|
+
"Center",
|
|
2682
|
+
"Cluster",
|
|
2683
|
+
"Heading",
|
|
2684
|
+
"IconButton",
|
|
2685
|
+
"Message",
|
|
2686
|
+
"Paragraph",
|
|
2687
|
+
"Stack",
|
|
2688
|
+
"StepList",
|
|
2689
|
+
"Tag",
|
|
2690
|
+
"TimeStamp",
|
|
2691
|
+
"Tooltip",
|
|
2692
|
+
"UserImage"
|
|
2693
|
+
]
|
|
2694
|
+
},
|
|
2695
|
+
{
|
|
2696
|
+
"id": "with-reason",
|
|
2697
|
+
"title": "With reason",
|
|
2698
|
+
"useWhen": "Someone reads the reasons and acts on them.",
|
|
2699
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Bot } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };\nconst firstRepliedAt = new Date('2025-01-15T11:41:00Z');\n\n// Each Regenerate writes the next version of the reply.\nconst replies = [\n 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',\n 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',\n];\n\n// Each step in plain words: what the agent is doing now, and what it did once the step is done.\nconst plan = [\n { doing: 'Reading the thread', done: 'Read the thread' },\n { doing: 'Writing a new reply', done: 'Wrote a new reply' },\n];\n\ntype Thumb = 'up' | 'down' | null;\n\n// A real app sends the reason with the mark, for the team to read.\nconst reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];\ntype Phase = 'reply' | 'running' | 'stopping';\n\nfunction stepsUpTo(current: number): StepListStep[] {\n return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));\n}\n\nfunction secondsLine(seconds: number) {\n return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is\n// no time to show: the old reply's time would be wrong for it.\nfunction agentMeta(at?: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n {at && <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplyFeedbackWithReason() {\n // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.\n const [thumb, setThumb] = useState<Thumb>('down');\n const [thanks, setThanks] = useState(false);\n // The reason row, open after thumbs down until a reason or Skip is picked.\n const [asking, setAsking] = useState(true);\n const [copied, setCopied] = useState(false);\n const [version, setVersion] = useState(0);\n // Each version of the reply has its own time: a regenerated reply shows when it was written.\n const [repliedAt, setRepliedAt] = useState(firstRepliedAt);\n const [phase, setPhase] = useState<Phase>('reply');\n const [current, setCurrent] = useState(0);\n const [seconds, setSeconds] = useState(0);\n const [stopped, setStopped] = useState(false);\n const thanksTimer = useRef<ReturnType<typeof setTimeout>>();\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const tick = useRef<ReturnType<typeof setInterval>>();\n const step = useRef<ReturnType<typeof setTimeout>>();\n const cancel = useRef<ReturnType<typeof setTimeout>>();\n const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const thumbsDownButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops every timer and the run.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(thanksTimer.current);\n clearTimeout(copyTimer.current);\n clearInterval(tick.current);\n clearTimeout(step.current);\n clearTimeout(cancel.current);\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const reply = replies[version];\n\n function showThanks() {\n clearTimeout(thanksTimer.current);\n setThanks(true);\n thanksTimer.current = setTimeout(() => setThanks(false), 2000);\n }\n\n // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.\n // Thumbs down asks what was wrong; the thanks waits for the answer.\n // A real app sends the mark to the server; the thanks is the only confirmation.\n function mark(next: 'up' | 'down') {\n const value = thumb === next ? null : next;\n setThumb(value);\n setAsking(value === 'down');\n clearTimeout(thanksTimer.current);\n setThanks(false);\n if (value === 'up') showThanks();\n }\n\n // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.\n function finish() {\n setAsking(false);\n showThanks();\n thumbsDownButton.current?.focus();\n }\n\n function copy() {\n navigator.clipboard?.writeText(reply).then(() => {\n if (!mounted.current) return;\n setCopied(true);\n clearTimeout(copyTimer.current);\n copyTimer.current = setTimeout(() => setCopied(false), 2000);\n }, () => {});\n }\n\n function endRun() {\n clearInterval(tick.current);\n clearTimeout(step.current);\n setPhase('reply');\n // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.\n focusNext.current = () => regenerateButton.current?.focus();\n }\n\n // Stands in for the agent's run: one step every 1.5 seconds.\n function advance(at: number) {\n step.current = setTimeout(() => {\n if (at === plan.length - 1) {\n setVersion((v) => (v + 1) % replies.length);\n setRepliedAt(new Date());\n setThumb(null);\n endRun();\n return;\n }\n setCurrent(at + 1);\n advance(at + 1);\n }, 1500);\n }\n\n // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.\n function regenerate() {\n clearTimeout(thanksTimer.current);\n setThanks(false);\n setAsking(false);\n setStopped(false);\n setCurrent(0);\n setSeconds(0);\n setPhase('running');\n tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);\n advance(0);\n // Regenerate had focus and is gone; 'Stop' takes its place.\n focusNext.current = () => stopButton.current?.focus();\n }\n\n // Stop asks the server to end the run. The reply stays as it was.\n function stop() {\n if (phase !== 'running') return;\n clearTimeout(step.current);\n setPhase('stopping');\n // Stands in for the request to the server.\n cancel.current = setTimeout(() => {\n setStopped(true);\n endRun();\n }, 1200);\n }\n\n const working = phase !== 'reply';\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(working ? undefined : repliedAt)}\n footer={\n working ? (\n // The only Stop, on the row for the whole run. It shows loading while the run is stopping.\n <Cluster>\n <Button ref={stopButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Stop\" loading={phase === 'stopping'} onClickButton={stop} />\n </Cluster>\n ) : (\n // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Tooltip title=\"Mark as helpful\">\n <IconButton color=\"iconOnly\" state={thumb === 'up' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsUp\" ariaLabel=\"Mark reply as helpful\" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />\n </Tooltip>\n <Tooltip title=\"Mark as not helpful\">\n <IconButton ref={thumbsDownButton} color=\"iconOnly\" state={thumb === 'down' ? 'selected' : 'enabled'} size=\"small\" iconName=\"ThumbsDown\" ariaLabel=\"Mark reply as not helpful\" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />\n </Tooltip>\n <Tooltip title={copied ? 'Copied' : 'Copy'}>\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />\n </Tooltip>\n {/* Only on the latest reply. */}\n <Tooltip title=\"Regenerate\">\n <IconButton ref={regenerateButton} color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"RefreshCw\" ariaLabel=\"Regenerate reply\" onClick={regenerate} />\n </Tooltip>\n {/* A real app wraps the thanks in a polite live region. */}\n {thanks && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Thanks. This helps the agent improve.</Paragraph>}\n </Cluster>\n {asking && (\n <Cluster gap=\"small\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">What was wrong?</Paragraph>\n {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:\n a real app groups the reasons under the question, named 'What was wrong?'. */}\n {reasons.map((r) => (\n <Tag key={r} variant=\"contained\" size=\"small\" toggle={false} label={r} onClick={finish} />\n ))}\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Skip\" onClickButton={finish} />\n </Cluster>\n )}\n </Stack>\n )\n }\n >\n {working ? (\n // A real app wraps this part in a polite live region, since StepList has none.\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">{secondsLine(seconds)}</Paragraph>\n <StepList aria-label=\"Acme Agent's steps\" steps={stepsUpTo(current)} />\n </Stack>\n ) : (\n <Stack gap=\"small\">\n <Paragraph measure=\"none\">{reply}</Paragraph>\n {stopped && <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Stopped. Nothing was changed.</Paragraph>}\n </Stack>\n )}\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2700
|
+
"uses": [
|
|
2701
|
+
"Button",
|
|
2702
|
+
"Center",
|
|
2703
|
+
"Cluster",
|
|
2704
|
+
"Heading",
|
|
2705
|
+
"IconButton",
|
|
2706
|
+
"Message",
|
|
2707
|
+
"Paragraph",
|
|
2708
|
+
"Stack",
|
|
2709
|
+
"StepList",
|
|
2710
|
+
"Tag",
|
|
2711
|
+
"TimeStamp",
|
|
2712
|
+
"Tooltip",
|
|
2713
|
+
"UserImage"
|
|
2714
|
+
]
|
|
2715
|
+
}
|
|
2716
|
+
]
|
|
2717
|
+
},
|
|
2718
|
+
{
|
|
2719
|
+
"id": "reply-sources",
|
|
2720
|
+
"title": "Reply sources",
|
|
2721
|
+
"kind": "design",
|
|
2722
|
+
"level": "organism",
|
|
2723
|
+
"area": "agent",
|
|
2724
|
+
"situation": "The agent answered from things it read, and the person may want to check them.",
|
|
2725
|
+
"do": [
|
|
2726
|
+
"Follow the rule 'An agent shows its sources': put the sources in the reply's `footer`, directly under the reply.",
|
|
2727
|
+
"Name the kinds of source in one `Tag`, in the order they first appear: 'From Chat · Knowledge base'.",
|
|
2728
|
+
"Show each source as a `SourceCard` with an icon for its kind, its title, and in `meta` its kind and where it lives: 'Chat · #launch · Jan 12'.",
|
|
2729
|
+
"Lay the cards out in `<Grid columns={2}>` and show the first six.",
|
|
2730
|
+
"Show the rest with a text-only 'Show N More' Button, with the number of hidden cards. It then reads 'Show Fewer', which hides them again.",
|
|
2731
|
+
"Make a card the person can open a link with `href`. A source on another site opens in a new tab.",
|
|
2732
|
+
"Make a card the person cannot open static, with no `href` and no `onClick`, and say why in `meta`: 'Chat · Private channel you are not in'.",
|
|
2733
|
+
"Keep a static card's look at rest the same as the others'. It has no hover look.",
|
|
2734
|
+
"Link each card to its own source, such as the message it read. Two cards never share a link.",
|
|
2735
|
+
"Show only the `Tag` when the reply read only the messages already on screen above it, as the rule allows.",
|
|
2736
|
+
"Show no sources section when the reply used no sources.",
|
|
2737
|
+
"Mark the agent's row as the rule 'An agent says what it is' says.",
|
|
2738
|
+
"Give the list that holds the rows `role=\"log\"`."
|
|
2739
|
+
],
|
|
2740
|
+
"dont": [
|
|
2741
|
+
"Do not show sources on a person's message.",
|
|
2742
|
+
"Do not link a card to any site other than the product or the service the source came from.",
|
|
2743
|
+
"Do not make a card look clickable when the person cannot open it.",
|
|
2744
|
+
"Do not show more than six cards before the person asks for the rest."
|
|
2745
|
+
],
|
|
2746
|
+
"native": "On Apple the cards fill as many columns as fit. A card with a link opens it in the browser, and a card with nothing to open cannot be tapped.",
|
|
2747
|
+
"notBuiltYet": "Scindo cannot hide the sources again once they are all shown, and its button reads 'Show N more', in sentence case. The meta of a card that cannot be opened does not say why.",
|
|
2748
|
+
"seenIn": [
|
|
2749
|
+
"Scindo"
|
|
2750
|
+
],
|
|
2751
|
+
"options": [
|
|
2752
|
+
{
|
|
2753
|
+
"id": "cards",
|
|
2754
|
+
"title": "Source cards",
|
|
2755
|
+
"useWhen": "The reply read things a person can open.",
|
|
2756
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport { BookOpen, Bot, MessageSquare, Plug } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\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 SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What did we decide about the launch date?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\nconst reply = 'The launch moved to March 3. Ben asked for two more weeks of testing, and the team agreed in #launch on Jan 12.';\n\ntype Kind = 'chat' | 'kb';\n// A source with no href is one the person cannot open: its meta says why. Each chat card links to the message it read.\ntype Source = { kind: Kind; title: string; where: string; href?: string };\n\nconst kinds = {\n chat: { label: 'Chat', icon: MessageSquare },\n kb: { label: 'Knowledge base', icon: BookOpen },\n};\n\nconst sources: Source[] = [\n { kind: 'chat', title: 'Launch date', where: '#launch · Jan 12', href: '/chat/launch/m-1042' },\n { kind: 'kb', title: 'Launch plan 2025', where: 'Acme Design', href: '/docs/launch-plan-2025' },\n { kind: 'chat', title: 'Testing schedule', where: '#qa · Jan 10', href: '/chat/qa/m-0981' },\n { kind: 'kb', title: 'Release checklist', where: 'Acme Design', href: '/docs/release-checklist' },\n { kind: 'chat', title: 'Budget for the launch', where: 'Private channel you are not in' },\n { kind: 'kb', title: 'Press kit guide', where: 'Acme Marketing', href: '/docs/press-kit-guide' },\n { kind: 'chat', title: 'Beta feedback', where: '#beta · Jan 8', href: '/chat/beta/m-0917' },\n { kind: 'kb', title: 'Pricing for the new plans', where: 'Acme Design', href: '/docs/pricing' },\n { kind: 'chat', title: 'Launch day roles', where: '#launch · Jan 14', href: '/chat/launch/m-1107' },\n { kind: 'kb', title: 'Support playbook', where: 'Acme Support', href: '/docs/support-playbook' },\n];\n\nconst visible = 6;\n\n// 'From Chat · Knowledge base': each kind once, in the order it first appears.\nfunction kindsTag(list: Source[]) {\n const labels: string[] = [];\n list.forEach((s) => {\n if (!labels.includes(kinds[s.kind].label)) labels.push(kinds[s.kind].label);\n });\n return `From ${labels.join(' · ')}`;\n}\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplySourcesCards() {\n const [expanded, setExpanded] = useState(false);\n const shown = expanded ? sources : sources.slice(0, visible);\n const more = sources.length - visible;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n // A reply that used no sources has no footer at all.\n footer={\n <Stack gap=\"medium\">\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color=\"success\" icon={Plug} label={kindsTag(sources)} />\n </Cluster>\n <Grid columns={2} gap=\"medium\">\n {shown.map((s) => (\n // A source in the product is a path; one on another site is an https:// URL and opens in a new tab.\n <SourceCard\n key={`${s.kind}:${s.title}`}\n icon={kinds[s.kind].icon}\n title={s.title}\n meta={`${kinds[s.kind].label} · ${s.where}`}\n href={s.href}\n />\n ))}\n </Grid>\n {more > 0 && (\n <Cluster>\n <Button\n size=\"small\"\n type=\"textOnly\"\n state=\"enabled\"\n label={expanded ? 'Show Fewer' : `Show ${more} More`}\n aria-expanded={expanded}\n onClickButton={() => setExpanded((e) => !e)}\n />\n </Cluster>\n )}\n </Stack>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2757
|
+
"uses": [
|
|
2758
|
+
"Button",
|
|
2759
|
+
"Center",
|
|
2760
|
+
"Cluster",
|
|
2761
|
+
"Grid",
|
|
2762
|
+
"Heading",
|
|
2763
|
+
"Message",
|
|
2764
|
+
"Paragraph",
|
|
2765
|
+
"SourceCard",
|
|
2766
|
+
"Stack",
|
|
2767
|
+
"Tag",
|
|
2768
|
+
"TimeStamp",
|
|
2769
|
+
"UserImage"
|
|
2770
|
+
]
|
|
2771
|
+
},
|
|
2772
|
+
{
|
|
2773
|
+
"id": "tag-only",
|
|
2774
|
+
"title": "Tag only",
|
|
2775
|
+
"useWhen": "The reply read only the messages already on screen above it.",
|
|
2776
|
+
"source": "'use client';\nimport { Bot, Plug } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst thread = [\n { from: 'Ben Carter', at: new Date('2025-01-15T11:36:00Z'), text: 'Testing needs two more weeks. It now ends on January 31.' },\n { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Acme Agent, what does that do to the launch date?' },\n];\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// The agent read only the messages above, which the person can already see.\nconst reply = 'If testing ends on January 31, the launch moves to March 3. That keeps the two weeks Ben asked for.';\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ReplySourcesTagOnly() {\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.from}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n // One kind of source, already on screen: the tag says where the answer came from, and no cards follow.\n footer={\n <Cluster>\n <Tag variant=\"contained\" size=\"small\" color=\"success\" icon={Plug} label=\"From Chat\" />\n </Cluster>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
2777
|
+
"uses": [
|
|
2778
|
+
"Center",
|
|
2779
|
+
"Cluster",
|
|
2780
|
+
"Heading",
|
|
2781
|
+
"Message",
|
|
2782
|
+
"Paragraph",
|
|
2783
|
+
"Stack",
|
|
2784
|
+
"Tag",
|
|
2785
|
+
"TimeStamp",
|
|
2786
|
+
"UserImage"
|
|
2787
|
+
]
|
|
2788
|
+
}
|
|
2789
|
+
]
|
|
2790
|
+
},
|
|
2791
|
+
{
|
|
2792
|
+
"id": "route-loading",
|
|
2793
|
+
"title": "Page loading",
|
|
2794
|
+
"kind": "design",
|
|
2795
|
+
"level": "page",
|
|
2796
|
+
"area": "state",
|
|
2797
|
+
"situation": "A page or a pane is loading, and there is nothing to show yet.",
|
|
2798
|
+
"do": [
|
|
2799
|
+
"Show the shell as soon as it can, and the spinner only where content is loading.",
|
|
2800
|
+
"Center the spinner in the space that is loading.",
|
|
2801
|
+
"Replace the spinner with the content as soon as it loads.",
|
|
2802
|
+
"Name the step in `LoadingScreen`'s `label` when a named step can take longer than about a second, as in 'Login check loading'.",
|
|
2803
|
+
"Use the same screen as the spinner in 'Login check loading' when nothing can show yet: `LoadingScreen` alone in `Center` with `fill`."
|
|
2804
|
+
],
|
|
2805
|
+
"dont": [
|
|
2806
|
+
"Do not write a line that names no step, such as 'Loading…'.",
|
|
2807
|
+
"Do not cover the navigation with a spinner when only one pane is loading.",
|
|
2808
|
+
"Do not show the empty text while the list is still loading."
|
|
2809
|
+
],
|
|
2810
|
+
"native": "On Apple use `ProgressView()` with no label, centered in the pane.",
|
|
2811
|
+
"seenIn": [
|
|
2812
|
+
"Commentify",
|
|
2813
|
+
"Scindo"
|
|
2814
|
+
],
|
|
2815
|
+
"options": [
|
|
2816
|
+
{
|
|
2817
|
+
"id": "full-screen",
|
|
2818
|
+
"title": "Full screen",
|
|
2819
|
+
"useWhen": "Nothing can show yet, not even the navigation.",
|
|
2820
|
+
"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",
|
|
2821
|
+
"uses": [
|
|
2822
|
+
"Center",
|
|
2823
|
+
"LoadingScreen"
|
|
2824
|
+
]
|
|
2825
|
+
},
|
|
2826
|
+
{
|
|
2827
|
+
"id": "region",
|
|
2828
|
+
"title": "In one pane",
|
|
2829
|
+
"useWhen": "The shell shows and one pane loads.",
|
|
2830
|
+
"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",
|
|
2831
|
+
"uses": [
|
|
2832
|
+
"Cluster",
|
|
2833
|
+
"Image",
|
|
2834
|
+
"LoadingScreen",
|
|
2835
|
+
"Stack",
|
|
2836
|
+
"Surface",
|
|
2837
|
+
"Tab",
|
|
2838
|
+
"TabsContainer"
|
|
2839
|
+
]
|
|
2840
|
+
}
|
|
2841
|
+
]
|
|
2842
|
+
},
|
|
2843
|
+
{
|
|
2844
|
+
"id": "set-new-password",
|
|
2845
|
+
"title": "Set new password",
|
|
2846
|
+
"kind": "design",
|
|
2847
|
+
"level": "page",
|
|
2848
|
+
"area": "auth",
|
|
2849
|
+
"situation": "A person opened the link to reset their password and now chooses a new one.",
|
|
2850
|
+
"do": [
|
|
2851
|
+
"Name the page 'Set new password' in a `Heading` with `level={1}`, and name the account it is for.",
|
|
2852
|
+
"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.",
|
|
2853
|
+
"Say the product's password rule before the person breaks it, such as 'Use at least 8 characters.'",
|
|
2854
|
+
"Put the rule in the password field's `helperText`, so it is tied to the field.",
|
|
2855
|
+
"Check the rule on the server too, and show its refusal under the field.",
|
|
2856
|
+
"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.",
|
|
2857
|
+
"Show the loading state on the submit Button while updating, and keep the form in place.",
|
|
2858
|
+
"Log the person out of the reset link's session before showing the login form, so they really log in with the new password.",
|
|
2859
|
+
"Go to the login form on success, with a success Alert above it: 'Password updated. Log in with your new password.'"
|
|
2860
|
+
],
|
|
2861
|
+
"dont": [
|
|
2862
|
+
"Do not show the rule only after the person breaks it.",
|
|
2863
|
+
"Do not show a mismatch above the fields; it belongs under Confirm password.",
|
|
2864
|
+
"Do not replace the form with a spinner while updating.",
|
|
2865
|
+
"Do not show the form when the link is invalid or expired."
|
|
2866
|
+
],
|
|
2867
|
+
"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.",
|
|
2868
|
+
"seenIn": [
|
|
2869
|
+
"Commentify",
|
|
2870
|
+
"Scindo"
|
|
2871
|
+
],
|
|
2872
|
+
"options": [
|
|
2873
|
+
{
|
|
2874
|
+
"id": "form",
|
|
2875
|
+
"title": "New password form",
|
|
2876
|
+
"useWhen": "The link is valid.",
|
|
2877
|
+
"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",
|
|
2878
|
+
"uses": [
|
|
2879
|
+
"Alert",
|
|
2880
|
+
"BrandIcon",
|
|
2881
|
+
"Button",
|
|
2882
|
+
"Center",
|
|
2883
|
+
"Form",
|
|
2884
|
+
"Heading",
|
|
2885
|
+
"Image",
|
|
2886
|
+
"Line",
|
|
2887
|
+
"Paragraph",
|
|
2888
|
+
"Stack",
|
|
2889
|
+
"Tab",
|
|
2890
|
+
"TabsContainer",
|
|
2891
|
+
"TextField"
|
|
2892
|
+
]
|
|
2893
|
+
},
|
|
2894
|
+
{
|
|
2895
|
+
"id": "invalid-link",
|
|
2896
|
+
"title": "Link no longer works",
|
|
2897
|
+
"useWhen": "The link is invalid, expired or already used.",
|
|
2898
|
+
"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",
|
|
2899
|
+
"uses": [
|
|
2900
|
+
"Alert",
|
|
2901
|
+
"Button",
|
|
2902
|
+
"Center",
|
|
2903
|
+
"Heading",
|
|
2904
|
+
"Icon",
|
|
2905
|
+
"Paragraph",
|
|
2906
|
+
"Stack"
|
|
2907
|
+
]
|
|
2908
|
+
}
|
|
2909
|
+
]
|
|
2910
|
+
},
|
|
2911
|
+
{
|
|
2912
|
+
"id": "sign-up-page",
|
|
2913
|
+
"title": "Sign-up page",
|
|
2914
|
+
"kind": "design",
|
|
2915
|
+
"level": "page",
|
|
2916
|
+
"area": "auth",
|
|
2917
|
+
"situation": "A person who has no account yet opens the product and wants one.",
|
|
2918
|
+
"do": [
|
|
2919
|
+
"Ask only for what the account needs: name, email and password.",
|
|
2920
|
+
"Say the product's password rule before the person breaks it, such as 'Use at least 8 characters.'",
|
|
2921
|
+
"Put the rule in the password field's `helperText`, so it is tied to the field.",
|
|
2922
|
+
"Check the rule on the server too, and show its refusal under the field.",
|
|
2923
|
+
"Show a problem with one field under that field.",
|
|
2924
|
+
"Show a failed request in an inline Alert above the fields.",
|
|
2925
|
+
"Show the loading state on the submit Button while creating the account, and keep the form in place.",
|
|
2926
|
+
"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.",
|
|
2927
|
+
"Keep the submit Button loading until the check-your-email view shows.",
|
|
2928
|
+
"Name the provider on its button: 'Continue with Google'.",
|
|
2929
|
+
"Link or tab to login for people who already have an account."
|
|
2930
|
+
],
|
|
2931
|
+
"dont": [
|
|
2932
|
+
"Do not ask for anything the account can do without, such as a username or the password twice.",
|
|
2933
|
+
"Do not clear the email field after a failed attempt.",
|
|
2934
|
+
"Do not replace the form with a spinner while creating the account.",
|
|
2935
|
+
"Do not say on the page whether an address already has an account."
|
|
2936
|
+
],
|
|
2937
|
+
"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.",
|
|
2938
|
+
"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.",
|
|
2939
|
+
"seenIn": [
|
|
2940
|
+
"Commentify",
|
|
2941
|
+
"Scindo"
|
|
2942
|
+
],
|
|
2943
|
+
"options": [
|
|
2944
|
+
{
|
|
2945
|
+
"id": "centered",
|
|
2946
|
+
"title": "Centered column",
|
|
2947
|
+
"useWhen": "The product has one way in, and most people sign up with email and a password.",
|
|
2948
|
+
"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",
|
|
2949
|
+
"uses": [
|
|
2950
|
+
"Alert",
|
|
2951
|
+
"BrandIcon",
|
|
2952
|
+
"Button",
|
|
2953
|
+
"Center",
|
|
2954
|
+
"Form",
|
|
2955
|
+
"Heading",
|
|
2956
|
+
"Icon",
|
|
2957
|
+
"Image",
|
|
2958
|
+
"Line",
|
|
2959
|
+
"Paragraph",
|
|
2960
|
+
"Stack",
|
|
2961
|
+
"Tab",
|
|
2962
|
+
"TabsContainer",
|
|
2963
|
+
"TextField"
|
|
2964
|
+
]
|
|
2965
|
+
},
|
|
2966
|
+
{
|
|
2967
|
+
"id": "split",
|
|
2968
|
+
"title": "Brand beside the form",
|
|
2969
|
+
"useWhen": "People arrive from an ad or an invite and need one line on what the product is.",
|
|
2970
|
+
"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",
|
|
2971
|
+
"uses": [
|
|
2972
|
+
"Alert",
|
|
2973
|
+
"BrandIcon",
|
|
2974
|
+
"Button",
|
|
2975
|
+
"Center",
|
|
2976
|
+
"Cluster",
|
|
2977
|
+
"Form",
|
|
2978
|
+
"Heading",
|
|
2979
|
+
"Icon",
|
|
2980
|
+
"Image",
|
|
2981
|
+
"Line",
|
|
2982
|
+
"Link",
|
|
2983
|
+
"Paragraph",
|
|
2984
|
+
"Split",
|
|
2985
|
+
"Stack",
|
|
2986
|
+
"TextField"
|
|
2987
|
+
]
|
|
2988
|
+
},
|
|
2989
|
+
{
|
|
2990
|
+
"id": "provider-first",
|
|
2991
|
+
"title": "Provider first",
|
|
2992
|
+
"useWhen": "Most people sign up with Google, GitHub or Apple; email is the fallback.",
|
|
2993
|
+
"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",
|
|
2994
|
+
"uses": [
|
|
242
2995
|
"Alert",
|
|
2996
|
+
"BrandIcon",
|
|
243
2997
|
"Button",
|
|
244
2998
|
"Center",
|
|
2999
|
+
"Cluster",
|
|
245
3000
|
"Form",
|
|
246
3001
|
"Heading",
|
|
3002
|
+
"Icon",
|
|
3003
|
+
"Line",
|
|
3004
|
+
"Link",
|
|
3005
|
+
"Paragraph",
|
|
3006
|
+
"Stack",
|
|
3007
|
+
"TextField"
|
|
3008
|
+
]
|
|
3009
|
+
}
|
|
3010
|
+
]
|
|
3011
|
+
},
|
|
3012
|
+
{
|
|
3013
|
+
"id": "slash-command-list",
|
|
3014
|
+
"title": "Command list",
|
|
3015
|
+
"kind": "design",
|
|
3016
|
+
"level": "organism",
|
|
3017
|
+
"area": "chat",
|
|
3018
|
+
"situation": "A person types / at the start of the message box to run a command.",
|
|
3019
|
+
"do": [
|
|
3020
|
+
"Open the list when the text starts with /. A bare / opens it, each letter after it narrows it, and a space closes it.",
|
|
3021
|
+
"Show at most 8 commands. Typing more letters finds the rest.",
|
|
3022
|
+
"Build it as a combobox. The text area gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows with `isActive` and `aria-selected`.",
|
|
3023
|
+
"Show each command with one line on what it does, and the argument it takes, such as '[topic]'. A menu row has no code font yet, so the command is plain text.",
|
|
3024
|
+
"Keep focus in the message box while the list is open, so the person keeps typing.",
|
|
3025
|
+
"Use the same keys as the case 'Mention list': the arrows move, Enter or Tab picks, Escape closes.",
|
|
3026
|
+
"Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.",
|
|
3027
|
+
"Close the list when the caret moves out of the command being typed, and when focus leaves the message box.",
|
|
3028
|
+
"Check the word at the caret again on Enter or Tab, and pick only if a command still matches. Shift+Tab picks nothing.",
|
|
3029
|
+
"Put the command and a space in place of the '/word' before the caret, and keep the text after it.",
|
|
3030
|
+
"Put the caret after that space, so the person can type the argument.",
|
|
3031
|
+
"Run the command when the person sends it. Every command works this way, even one that takes no argument.",
|
|
3032
|
+
"Close the list when no command matches."
|
|
3033
|
+
],
|
|
3034
|
+
"dont": [
|
|
3035
|
+
"Do not move focus into the list. The person keeps typing in the field.",
|
|
3036
|
+
"Do not run a command on the Enter that picks it.",
|
|
3037
|
+
"Do not show an empty list.",
|
|
3038
|
+
"Do not open the list for a / in the middle of the text."
|
|
3039
|
+
],
|
|
3040
|
+
"native": "On Apple the list shows above the field with the command, what it does and, when it takes an argument, its usage. Escape closes the list on a Mac.",
|
|
3041
|
+
"notBuiltYet": "Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which command is highlighted. Both Scindo apps run a command with no argument as soon as it is picked.",
|
|
3042
|
+
"seenIn": [
|
|
3043
|
+
"Scindo"
|
|
3044
|
+
],
|
|
3045
|
+
"options": [
|
|
3046
|
+
{
|
|
3047
|
+
"id": "in-composer",
|
|
3048
|
+
"title": "List in the composer",
|
|
3049
|
+
"useWhen": "The default: the list opens over the text while the person types a command.",
|
|
3050
|
+
"source": "'use client';\nimport { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Command = { name: string; does: string; argument?: string };\nconst commands: Command[] = [\n { name: 'plan', does: 'Ask the agent for a plan before it acts' },\n { name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },\n { name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },\n { name: 'status', does: 'Show what the agent is working on' },\n];\n\nconst listId = 'slash-command-list-commands';\n// The list shows at most this many commands; typing more letters narrows it.\nconst MAX_MATCHES = 8;\nconst optionId = (c: Command) => `slash-command-list-option-${c.name}`;\n\ntype Row = { id: string; from: string; at: Date; text: string; command?: boolean };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },\n { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },\n];\n\n// Opens with a / typed, so the list shows every command.\nconst firstText = '/';\n\n// The word after a / at the start of the text before the caret, or null once there is a space or no /.\nfunction commandQuery(before: string) {\n const match = before.match(/^\\/(\\S*)$/);\n return match ? match[1] : null;\n}\n\n// The query for where the caret is now.\nfunction queryAtCaret(field: HTMLTextAreaElement) {\n return commandQuery(field.value.slice(0, field.selectionStart ?? field.value.length));\n}\n\nconst matches = (query: string) => commands.filter((c) => c.name.startsWith(query.toLowerCase())).slice(0, MAX_MATCHES);\n\nexport default function SlashCommandListInComposer() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState(firstText);\n const [query, setQuery] = useState<string | null>(commandQuery(firstText));\n const [active, setActive] = useState(0);\n // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.\n const [caret, setCaret] = useState<number | null>(null);\n const field = useRef<HTMLTextAreaElement>(null);\n\n const results = query === null ? [] : matches(query);\n // No match: the list closes.\n const open = results.length > 0;\n\n // The field opens with the caret at the end, after the /.\n useEffect(() => {\n const end = field.current?.value.length ?? 0;\n field.current?.setSelectionRange(end, end);\n }, []);\n\n useEffect(() => {\n if (caret === null || !field.current) return;\n field.current.focus();\n field.current.setSelectionRange(caret, caret);\n setCaret(null);\n }, [caret]);\n\n function change(value: string) {\n setText(value);\n const at = field.current?.selectionStart ?? value.length;\n setQuery(commandQuery(value.slice(0, at)));\n setActive(0);\n }\n\n // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and\n // closes when the caret leaves it.\n function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {\n const next = queryAtCaret(e.currentTarget);\n if (next === query) return;\n setQuery(next);\n setActive(0);\n }\n\n // Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes\n // after the space, so the person can type the argument. Nothing runs yet.\n function pick(c: Command) {\n const at = field.current?.selectionStart ?? text.length;\n const insert = `/${c.name} `;\n // One space between the command and what follows, not two.\n const after = text.slice(at).replace(/^ /, '');\n setText(insert + after);\n setQuery(null);\n setCaret(insert.length);\n }\n\n // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.\n function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!open) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {\n // Check the word at the caret again before taking the key. If nothing matches now, the list\n // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.\n const now = queryAtCaret(e.currentTarget);\n const found = now === null ? [] : matches(now);\n if (found.length === 0) {\n setQuery(null);\n return;\n }\n e.preventDefault();\n pick(found[now === query ? Math.min(active, found.length - 1) : 0]);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n e.stopPropagation();\n setQuery(null);\n }\n }\n\n // A real app runs the command here. This one shows it in the thread.\n function send() {\n const value = text.trim();\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: value, command: value.startsWith('/') }]);\n setText('');\n setQuery(null);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\" mono={m.command}>{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Composer\n ref={field}\n id=\"slash-command-list-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team, or type / for commands\"\n value={text}\n onChange={change}\n onSubmit={send}\n onKeyDown={keyDown}\n onSelect={caretMoved}\n // A press on a row keeps focus in the field, so this runs only when focus leaves for good.\n onBlur={() => setQuery(null)}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listId : undefined}\n aria-activedescendant={open ? optionId(results[active]) : undefined}\n above={\n open ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Commands\" width={400}>\n {results.map((c, i) => (\n <MenuItem\n key={c.name}\n id={optionId(c)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName=\"SquareSlash\"\n // MenuItem has no mono label, so the command is plain text.\n label={`/${c.name}`}\n secondLabel={c.does}\n tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined}\n onClick={() => pick(c)}\n />\n ))}\n </Menu>\n ) : undefined\n }\n />\n </Stack>\n </Center>\n );\n}\n",
|
|
3051
|
+
"uses": [
|
|
3052
|
+
"Center",
|
|
3053
|
+
"Composer",
|
|
3054
|
+
"Heading",
|
|
3055
|
+
"Menu",
|
|
3056
|
+
"MenuItem",
|
|
3057
|
+
"Message",
|
|
3058
|
+
"Paragraph",
|
|
3059
|
+
"Stack",
|
|
3060
|
+
"TimeStamp",
|
|
3061
|
+
"UserImage"
|
|
3062
|
+
]
|
|
3063
|
+
}
|
|
3064
|
+
]
|
|
3065
|
+
},
|
|
3066
|
+
{
|
|
3067
|
+
"id": "success-feedback",
|
|
3068
|
+
"title": "Success shows where the person is looking",
|
|
3069
|
+
"kind": "rule",
|
|
3070
|
+
"level": "rule",
|
|
3071
|
+
"area": "state",
|
|
3072
|
+
"situation": "Something the person did has worked.",
|
|
3073
|
+
"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 Copy is a menu item, the menu closes, so a toast says 'Message copied.' instead. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.",
|
|
3074
|
+
"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.",
|
|
3075
|
+
"do": [
|
|
3076
|
+
"Show `loading` on the Button while a form saves, then 'Saved' for 2 seconds.",
|
|
3077
|
+
"Write a toast as one short sentence in the past tense that names the thing: 'Invite sent to Dana.'",
|
|
3078
|
+
"Show 'Copied' on a copy Button, or the `Check` icon on a copy IconButton, for 2 seconds.",
|
|
3079
|
+
"Show 'Sent' for 2 seconds on a Button that sends an email again, such as 'Send Again'.",
|
|
3080
|
+
"Mount one `Toaster` near the app root, and show every toast with `toast()`."
|
|
3081
|
+
],
|
|
3082
|
+
"dont": [
|
|
3083
|
+
"Do not say 'successfully'.",
|
|
3084
|
+
"Do not change a Button's label while it is loading, such as to 'Saving…' or 'Deleting…'.",
|
|
3085
|
+
"Do not show a toast for a change the person can already see.",
|
|
3086
|
+
"Do not build a toast from `Alert`. Use `toast()`.",
|
|
3087
|
+
"Do not make the person close a success message."
|
|
3088
|
+
],
|
|
3089
|
+
"native": "On Apple there is no toast. Show the result in place.",
|
|
3090
|
+
"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'.",
|
|
3091
|
+
"seenIn": [
|
|
3092
|
+
"Commentify",
|
|
3093
|
+
"Scindo"
|
|
3094
|
+
]
|
|
3095
|
+
},
|
|
3096
|
+
{
|
|
3097
|
+
"id": "type-to-confirm",
|
|
3098
|
+
"title": "Type to confirm",
|
|
3099
|
+
"kind": "design",
|
|
3100
|
+
"level": "organism",
|
|
3101
|
+
"area": "confirm",
|
|
3102
|
+
"situation": "A person asks to delete something large that cannot be brought back, such as a workspace or an account.",
|
|
3103
|
+
"do": [
|
|
3104
|
+
"Ask for typing only when the loss is permanent and large, such as a workspace with everything in it, or an account.",
|
|
3105
|
+
"Ask the person to type the thing's name when it has one, and a fixed word such as DELETE when it does not.",
|
|
3106
|
+
"Put the text to type in the field's label: 'Type Acme Design to confirm'.",
|
|
3107
|
+
"Keep the action Button `state=\"disabled\"` until the typed text matches exactly.",
|
|
3108
|
+
"Match with case: 'acme design' does not match 'Acme Design'. Allow pasting the text.",
|
|
3109
|
+
"Say above the field what is deleted and what is kept."
|
|
3110
|
+
],
|
|
3111
|
+
"dont": [
|
|
3112
|
+
"Do not ask for typing for an everyday delete. A plain confirm is enough.",
|
|
3113
|
+
"Do not block pasting into the field.",
|
|
3114
|
+
"Do not change the action's label while it is loading, such as to 'Deleting…'.",
|
|
3115
|
+
"Do not show a failed request as a red caption written by hand. Use an inline error Alert."
|
|
3116
|
+
],
|
|
3117
|
+
"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.",
|
|
3118
|
+
"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.",
|
|
3119
|
+
"seenIn": [
|
|
3120
|
+
"Commentify",
|
|
3121
|
+
"Scindo"
|
|
3122
|
+
],
|
|
3123
|
+
"options": [
|
|
3124
|
+
{
|
|
3125
|
+
"id": "modal",
|
|
3126
|
+
"title": "Type the name in a Modal",
|
|
3127
|
+
"useWhen": "The action starts from a menu or a row, away from a settings page.",
|
|
3128
|
+
"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 '{workspace}' 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",
|
|
3129
|
+
"uses": [
|
|
3130
|
+
"Button",
|
|
3131
|
+
"Center",
|
|
3132
|
+
"Cluster",
|
|
3133
|
+
"Heading",
|
|
3134
|
+
"List",
|
|
3135
|
+
"Modal",
|
|
3136
|
+
"Paragraph",
|
|
3137
|
+
"Stack",
|
|
3138
|
+
"Surface",
|
|
3139
|
+
"TextField",
|
|
3140
|
+
"Toaster",
|
|
3141
|
+
"dismissToast",
|
|
3142
|
+
"toast"
|
|
3143
|
+
]
|
|
3144
|
+
},
|
|
3145
|
+
{
|
|
3146
|
+
"id": "inline",
|
|
3147
|
+
"title": "Type a word in place",
|
|
3148
|
+
"useWhen": "The action lives in a danger zone on a settings page.",
|
|
3149
|
+
"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",
|
|
3150
|
+
"uses": [
|
|
3151
|
+
"Button",
|
|
3152
|
+
"Center",
|
|
3153
|
+
"Cluster",
|
|
3154
|
+
"Heading",
|
|
3155
|
+
"Paragraph",
|
|
3156
|
+
"Stack",
|
|
3157
|
+
"Surface",
|
|
3158
|
+
"TextField"
|
|
3159
|
+
]
|
|
3160
|
+
}
|
|
3161
|
+
]
|
|
3162
|
+
},
|
|
3163
|
+
{
|
|
3164
|
+
"id": "typing-and-status",
|
|
3165
|
+
"title": "Typing line",
|
|
3166
|
+
"kind": "design",
|
|
3167
|
+
"level": "organism",
|
|
3168
|
+
"area": "chat",
|
|
3169
|
+
"situation": "Other people in the thread are writing a message that has not arrived yet.",
|
|
3170
|
+
"do": [
|
|
3171
|
+
"Show one line just above the Composer, in small secondary text: `<Paragraph size=\"caption\" tone=\"secondary\">`.",
|
|
3172
|
+
"Name one person by first name: 'Ben is typing…'.",
|
|
3173
|
+
"Name two people: 'Ben and Omar are typing…'.",
|
|
3174
|
+
"Name the first person and count the rest when three or more type: 'Ben and 2 others are typing…'.",
|
|
3175
|
+
"End the line with an ellipsis, one character.",
|
|
3176
|
+
"Remove the line a few seconds after the last keystroke, or when the message arrives.",
|
|
3177
|
+
"Leave out the person who is reading.",
|
|
3178
|
+
"Show an agent at work with its progress row, not as typing. The case 'Agent at work' has the pattern.",
|
|
3179
|
+
"Keep the line out of a live region. It changes too often to read aloud."
|
|
3180
|
+
],
|
|
3181
|
+
"dont": [
|
|
3182
|
+
"Do not say an agent is typing.",
|
|
3183
|
+
"Do not list every name when three or more people type."
|
|
3184
|
+
],
|
|
3185
|
+
"notBuiltYet": "Scindo on the web names people by their full name and ends the line with three dots.",
|
|
3186
|
+
"seenIn": [
|
|
3187
|
+
"Scindo"
|
|
3188
|
+
],
|
|
3189
|
+
"options": [
|
|
3190
|
+
{
|
|
3191
|
+
"id": "line",
|
|
3192
|
+
"title": "Line above the composer",
|
|
3193
|
+
"useWhen": "The default: one line just above the Composer while someone types.",
|
|
3194
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Composer from 'oneslash-design-system/components/composer';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\ntype Row = { id: string; from: string; at: Date; text: string };\n\nconst firstThread: Row[] = [\n { id: 'm1', from: 'Omar Reyes', at: new Date('2025-01-15T11:38:00Z'), text: 'Is the launch email going out today?' },\n { id: 'm2', from: me, at: new Date('2025-01-15T11:40:00Z'), text: 'Ben has the final copy. Ben, can you confirm?' },\n];\n\nexport default function TypingAndStatusLine() {\n const [thread, setThread] = useState(firstThread);\n const [text, setText] = useState('');\n\n function send() {\n // A real app sends the message to the server here and shows it at once.\n setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);\n setText('');\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n {thread.map((m) => (\n <Message\n key={m.id}\n aria-label={m.from}\n avatar={<UserImage userHandle={m.from} decorative />}\n name={m.from}\n meta={<TimeStamp createdAt={m.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{m.text}</Paragraph>\n </Message>\n ))}\n </Stack>\n <Stack gap=\"small\">\n {/* One person typing. Two: 'Ben and Omar are typing…'. Three or more: 'Ben and 2 others are typing…'.\n A real app removes the line a few seconds after the last keystroke. It is not a live region. */}\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Ben is typing…</Paragraph>\n <Composer\n id=\"typing-and-status-message\"\n aria-label=\"Message\"\n placeholder=\"Message the team\"\n value={text}\n onChange={setText}\n onSubmit={send}\n />\n </Stack>\n </Stack>\n </Center>\n );\n}\n",
|
|
3195
|
+
"uses": [
|
|
3196
|
+
"Center",
|
|
3197
|
+
"Composer",
|
|
3198
|
+
"Heading",
|
|
3199
|
+
"Message",
|
|
3200
|
+
"Paragraph",
|
|
3201
|
+
"Stack",
|
|
3202
|
+
"TimeStamp",
|
|
3203
|
+
"UserImage"
|
|
3204
|
+
]
|
|
3205
|
+
}
|
|
3206
|
+
]
|
|
3207
|
+
},
|
|
3208
|
+
{
|
|
3209
|
+
"id": "unsaved-changes-guard",
|
|
3210
|
+
"title": "Unsaved changes",
|
|
3211
|
+
"kind": "design",
|
|
3212
|
+
"level": "organism",
|
|
3213
|
+
"area": "confirm",
|
|
3214
|
+
"situation": "A person closes or leaves something they changed and did not save.",
|
|
3215
|
+
"do": [
|
|
3216
|
+
"Ask only when there are changes. With nothing changed, close at once.",
|
|
3217
|
+
"Title the Modal with the action it offers, such as 'Save Changes' or 'Discard Reply', and name the thing in the body.",
|
|
3218
|
+
"Put 'Cancel' first, then 'Don't Save', then 'Save'. As in every confirm, the safe choice comes first and the main action last.",
|
|
3219
|
+
"Make 'Cancel' tertiary, 'Don't Save' secondary and 'Save' primary, all `size=\"small\"`.",
|
|
3220
|
+
"Offer 'Keep Editing' and a danger 'Discard' when the product cannot save. 'Keep Editing' comes first.",
|
|
3221
|
+
"Disable 'Cancel' and 'Don't Save' while 'Save' runs, and leave only when the save works."
|
|
3222
|
+
],
|
|
3223
|
+
"dont": [
|
|
3224
|
+
"Do not ask when nothing changed.",
|
|
3225
|
+
"Do not leave when the save fails. Keep the changes on screen.",
|
|
3226
|
+
"Do not label the choices 'Yes' and 'No'.",
|
|
3227
|
+
"Do not title the Modal 'Are you sure?'."
|
|
3228
|
+
],
|
|
3229
|
+
"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.",
|
|
3230
|
+
"notBuiltYet": "Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.",
|
|
3231
|
+
"seenIn": [
|
|
3232
|
+
"Scindo"
|
|
3233
|
+
],
|
|
3234
|
+
"options": [
|
|
3235
|
+
{
|
|
3236
|
+
"id": "save-or-discard",
|
|
3237
|
+
"title": "Save or discard",
|
|
3238
|
+
"useWhen": "The product can save the changes for the person, such as an edited document.",
|
|
3239
|
+
"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 'Q3 plan' 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",
|
|
3240
|
+
"uses": [
|
|
3241
|
+
"Button",
|
|
3242
|
+
"Center",
|
|
3243
|
+
"Cluster",
|
|
3244
|
+
"Heading",
|
|
3245
|
+
"Modal",
|
|
3246
|
+
"Paragraph",
|
|
3247
|
+
"Stack",
|
|
3248
|
+
"TextField"
|
|
3249
|
+
]
|
|
3250
|
+
},
|
|
3251
|
+
{
|
|
3252
|
+
"id": "discard",
|
|
3253
|
+
"title": "Discard or keep editing",
|
|
3254
|
+
"useWhen": "The product cannot save for the person, such as a reply that only posts when they say so.",
|
|
3255
|
+
"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",
|
|
3256
|
+
"uses": [
|
|
3257
|
+
"Button",
|
|
3258
|
+
"Center",
|
|
3259
|
+
"Cluster",
|
|
3260
|
+
"Heading",
|
|
3261
|
+
"Modal",
|
|
3262
|
+
"Paragraph",
|
|
3263
|
+
"Stack",
|
|
3264
|
+
"Surface",
|
|
3265
|
+
"TextField"
|
|
3266
|
+
]
|
|
3267
|
+
}
|
|
3268
|
+
]
|
|
3269
|
+
},
|
|
3270
|
+
{
|
|
3271
|
+
"id": "upgrade-prompt",
|
|
3272
|
+
"title": "Upgrade prompt",
|
|
3273
|
+
"kind": "design",
|
|
3274
|
+
"level": "organism",
|
|
3275
|
+
"area": "confirm",
|
|
3276
|
+
"situation": "A person reaches something their plan does not include, or a limit of their plan.",
|
|
3277
|
+
"do": [
|
|
3278
|
+
"Say what is locked and which plan unlocks it: 'Exporting to PDF is part of the Pro plan.'",
|
|
3279
|
+
"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.\"",
|
|
3280
|
+
"Offer 'Not Now' as a tertiary Button, then 'Upgrade to Pro' as a primary Button.",
|
|
3281
|
+
"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'.",
|
|
3282
|
+
"Title the Modal 'Upgrade to Pro' only for a person who can upgrade. For everyone else, title it 'Pro Feature'.",
|
|
3283
|
+
"Follow the rule 'A confirm says exactly what will happen' for the Modal: `size=\"small\"`, and Escape or a click outside means 'Not Now'.",
|
|
3284
|
+
"Put the notice where the control was, with the same two Buttons, when a limit is reached inside a flow.",
|
|
3285
|
+
"Follow the rule 'An agent refuses clearly' too when the agent is the one refused."
|
|
3286
|
+
],
|
|
3287
|
+
"dont": [
|
|
3288
|
+
"Do not title the Modal 'Upgrade Required' or 'This is available on Pro plan only'. Name the action: 'Upgrade to Pro'.",
|
|
3289
|
+
"Do not label the way out 'Maybe Later' or 'Close'.",
|
|
3290
|
+
"Do not show an Upgrade Button to someone who cannot upgrade.",
|
|
3291
|
+
"Do not hide the locked control. Let the person press it and learn what unlocks it.",
|
|
3292
|
+
"Do not build the overlay by hand. Use `Modal`, which closes on Escape."
|
|
3293
|
+
],
|
|
3294
|
+
"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.",
|
|
3295
|
+
"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'.",
|
|
3296
|
+
"seenIn": [
|
|
3297
|
+
"Commentify",
|
|
3298
|
+
"Scindo"
|
|
3299
|
+
],
|
|
3300
|
+
"options": [
|
|
3301
|
+
{
|
|
3302
|
+
"id": "modal",
|
|
3303
|
+
"title": "Explain in a Modal",
|
|
3304
|
+
"useWhen": "The person pressed something their plan does not include.",
|
|
3305
|
+
"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",
|
|
3306
|
+
"uses": [
|
|
3307
|
+
"Button",
|
|
3308
|
+
"Center",
|
|
3309
|
+
"Cluster",
|
|
3310
|
+
"Heading",
|
|
3311
|
+
"Modal",
|
|
3312
|
+
"Paragraph",
|
|
3313
|
+
"Stack"
|
|
3314
|
+
]
|
|
3315
|
+
},
|
|
3316
|
+
{
|
|
3317
|
+
"id": "inline",
|
|
3318
|
+
"title": "Replace the control",
|
|
3319
|
+
"useWhen": "A limit was reached inside a flow. The notice takes the place of the control that hit it.",
|
|
3320
|
+
"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'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",
|
|
3321
|
+
"uses": [
|
|
3322
|
+
"Button",
|
|
3323
|
+
"Center",
|
|
3324
|
+
"Cluster",
|
|
3325
|
+
"Heading",
|
|
247
3326
|
"Paragraph",
|
|
248
3327
|
"Stack",
|
|
249
3328
|
"Surface",
|