oneslash-design-system 2.16.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 +1 -1
- package/dist/DESIGN.md +26 -3
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +2 -2
- 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/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/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/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/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/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 +1 -1
- 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.json +1276 -14
- 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/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- 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/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/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 +8 -1
- package/dist/components/radioGroup.jsx +19 -8
- 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/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- 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/native-mapping.json +32 -1
- 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 +30 -0
- package/dist/stories/Cases.generated.stories.jsx +60 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- 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/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- 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/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
package/dist/cases.json
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"id": "signed-out",
|
|
38
38
|
"title": "Logged out",
|
|
39
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\" />\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",
|
|
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
41
|
"uses": [
|
|
42
42
|
"Button",
|
|
43
43
|
"Center",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"id": "signed-in",
|
|
54
54
|
"title": "Logged in, open link",
|
|
55
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\" />\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",
|
|
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
57
|
"uses": [
|
|
58
58
|
"Button",
|
|
59
59
|
"Center",
|
|
@@ -118,6 +118,321 @@
|
|
|
118
118
|
"Scindo"
|
|
119
119
|
]
|
|
120
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
|
+
},
|
|
121
436
|
{
|
|
122
437
|
"id": "agent-refuses-clearly",
|
|
123
438
|
"title": "An agent refuses clearly",
|
|
@@ -199,13 +514,13 @@
|
|
|
199
514
|
"level": "rule",
|
|
200
515
|
"area": "agent",
|
|
201
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.",
|
|
202
|
-
"answer": "Under the reply, the agent lists what it used. A small tag names the kinds of source, such as 'From Chat · Knowledge base', and one card per source shows its title, its kind and where it lives. Each card opens the source. A reply that used no sources shows no sources section.",
|
|
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.",
|
|
203
518
|
"why": "A person can check an answer only when they can open what it came from.",
|
|
204
519
|
"do": [
|
|
205
520
|
"Put the sources directly under the reply they support.",
|
|
206
521
|
"Show each source as a card with its title and where it lives, such as the space name or the date.",
|
|
207
522
|
"Make each card open the source itself, in the product or on the service it came from.",
|
|
208
|
-
"Show the first six sources and a 'Show N
|
|
523
|
+
"Show the first six sources and a 'Show N More' button for the rest."
|
|
209
524
|
],
|
|
210
525
|
"dont": [
|
|
211
526
|
"Do not show a sources section when the reply used no sources.",
|
|
@@ -216,6 +531,54 @@
|
|
|
216
531
|
"Scindo"
|
|
217
532
|
]
|
|
218
533
|
},
|
|
534
|
+
{
|
|
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
|
+
},
|
|
219
582
|
{
|
|
220
583
|
"id": "auth-gate-loading",
|
|
221
584
|
"title": "Login check loading",
|
|
@@ -326,6 +689,82 @@
|
|
|
326
689
|
}
|
|
327
690
|
]
|
|
328
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
|
+
},
|
|
329
768
|
{
|
|
330
769
|
"id": "confirm-destructive-action",
|
|
331
770
|
"title": "Delete confirm",
|
|
@@ -428,6 +867,72 @@
|
|
|
428
867
|
"Scindo"
|
|
429
868
|
]
|
|
430
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
|
+
},
|
|
431
936
|
{
|
|
432
937
|
"id": "create-modal",
|
|
433
938
|
"title": "Create modal",
|
|
@@ -1432,19 +1937,521 @@
|
|
|
1432
1937
|
]
|
|
1433
1938
|
},
|
|
1434
1939
|
{
|
|
1435
|
-
"id": "
|
|
1436
|
-
"title": "
|
|
1940
|
+
"id": "mention-list",
|
|
1941
|
+
"title": "Mention list",
|
|
1437
1942
|
"kind": "design",
|
|
1438
|
-
"level": "
|
|
1439
|
-
"area": "
|
|
1440
|
-
"situation": "A person
|
|
1943
|
+
"level": "organism",
|
|
1944
|
+
"area": "chat",
|
|
1945
|
+
"situation": "A person types @ in the message box to name someone, or the agent.",
|
|
1441
1946
|
"do": [
|
|
1442
|
-
"
|
|
1443
|
-
"
|
|
1444
|
-
"
|
|
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."
|
|
1445
1960
|
],
|
|
1446
1961
|
"dont": [
|
|
1447
|
-
"Do not
|
|
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.",
|
|
1448
2455
|
"Do not show a line of text with no way home.",
|
|
1449
2456
|
"Do not blame the person for the link."
|
|
1450
2457
|
],
|
|
@@ -1625,6 +2632,162 @@
|
|
|
1625
2632
|
}
|
|
1626
2633
|
]
|
|
1627
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
|
+
},
|
|
1628
2791
|
{
|
|
1629
2792
|
"id": "route-loading",
|
|
1630
2793
|
"title": "Page loading",
|
|
@@ -1846,6 +3009,60 @@
|
|
|
1846
3009
|
}
|
|
1847
3010
|
]
|
|
1848
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
|
+
},
|
|
1849
3066
|
{
|
|
1850
3067
|
"id": "success-feedback",
|
|
1851
3068
|
"title": "Success shows where the person is looking",
|
|
@@ -1853,7 +3070,7 @@
|
|
|
1853
3070
|
"level": "rule",
|
|
1854
3071
|
"area": "state",
|
|
1855
3072
|
"situation": "Something the person did has worked.",
|
|
1856
|
-
"answer": "The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.",
|
|
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'.",
|
|
1857
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.",
|
|
1858
3075
|
"do": [
|
|
1859
3076
|
"Show `loading` on the Button while a form saves, then 'Saved' for 2 seconds.",
|
|
@@ -1943,6 +3160,51 @@
|
|
|
1943
3160
|
}
|
|
1944
3161
|
]
|
|
1945
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
|
+
},
|
|
1946
3208
|
{
|
|
1947
3209
|
"id": "unsaved-changes-guard",
|
|
1948
3210
|
"title": "Unsaved changes",
|