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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Bot, Plug } from 'lucide-react';
|
|
3
|
+
import Message from '../../components/message';
|
|
4
|
+
import UserImage from '../../components/userImage';
|
|
5
|
+
import Tag from '../../components/tag';
|
|
6
|
+
import TimeStamp from '../../components/timeStamp';
|
|
7
|
+
import Heading from '../../components/heading';
|
|
8
|
+
import Paragraph from '../../components/paragraph';
|
|
9
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
10
|
+
var agentName = 'Acme Agent';
|
|
11
|
+
var thread = [
|
|
12
|
+
{ from: 'Ben Carter', at: new Date('2025-01-15T11:36:00Z'), text: 'Testing needs two more weeks. It now ends on January 31.' },
|
|
13
|
+
{ from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Acme Agent, what does that do to the launch date?' },
|
|
14
|
+
];
|
|
15
|
+
var repliedAt = new Date('2025-01-15T11:41:00Z');
|
|
16
|
+
// The agent read only the messages above, which the person can already see.
|
|
17
|
+
var reply = 'If testing ends on January 31, the launch moves to March 3. That keeps the two weeks Ben asked for.';
|
|
18
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
19
|
+
function agentMeta(at) {
|
|
20
|
+
return (<>
|
|
21
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
22
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
23
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
24
|
+
</>);
|
|
25
|
+
}
|
|
26
|
+
export default function ReplySourcesTagOnly() {
|
|
27
|
+
return (<Center width="page">
|
|
28
|
+
<Stack gap="large">
|
|
29
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
30
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
31
|
+
<Stack gap="small">
|
|
32
|
+
{thread.map(function (m) { return (<Message key={m.from} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
|
|
33
|
+
<Paragraph measure="none">{m.text}</Paragraph>
|
|
34
|
+
</Message>); })}
|
|
35
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(repliedAt)}
|
|
36
|
+
// One kind of source, already on screen: the tag says where the answer came from, and no cards follow.
|
|
37
|
+
footer={<Cluster>
|
|
38
|
+
<Tag variant="contained" size="small" color="success" icon={Plug} label="From Chat"/>
|
|
39
|
+
</Cluster>}>
|
|
40
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
41
|
+
</Message>
|
|
42
|
+
</Stack>
|
|
43
|
+
</Stack>
|
|
44
|
+
</Center>);
|
|
45
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Reply sources
|
|
2
|
+
|
|
3
|
+
The agent answered from things it read, and the person may want to check them.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** 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.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Follow the rule 'An agent shows its sources': put the sources in the reply's `footer`, directly under the reply.
|
|
10
|
+
- Name the kinds of source in one `Tag`, in the order they first appear: 'From Chat · Knowledge base'.
|
|
11
|
+
- 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'.
|
|
12
|
+
- Lay the cards out in `<Grid columns={2}>` and show the first six.
|
|
13
|
+
- 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.
|
|
14
|
+
- Make a card the person can open a link with `href`. A source on another site opens in a new tab.
|
|
15
|
+
- 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'.
|
|
16
|
+
- Keep a static card's look at rest the same as the others'. It has no hover look.
|
|
17
|
+
- Link each card to its own source, such as the message it read. Two cards never share a link.
|
|
18
|
+
- Show only the `Tag` when the reply read only the messages already on screen above it, as the rule allows.
|
|
19
|
+
- Show no sources section when the reply used no sources.
|
|
20
|
+
- Mark the agent's row as the rule 'An agent says what it is' says.
|
|
21
|
+
- Give the list that holds the rows `role="log"`.
|
|
22
|
+
|
|
23
|
+
## Don't
|
|
24
|
+
|
|
25
|
+
- Do not show sources on a person's message.
|
|
26
|
+
- Do not link a card to any site other than the product or the service the source came from.
|
|
27
|
+
- Do not make a card look clickable when the person cannot open it.
|
|
28
|
+
- Do not show more than six cards before the person asks for the rest.
|
|
29
|
+
|
|
30
|
+
## Option: Source cards
|
|
31
|
+
|
|
32
|
+
Use when: The reply read things a person can open.
|
|
33
|
+
|
|
34
|
+
Uses: `Button`, `Center`, `Cluster`, `Grid`, `Heading`, `Message`, `Paragraph`, `SourceCard`, `Stack`, `Tag`, `TimeStamp`, `UserImage`
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
'use client';
|
|
38
|
+
import { useState } from 'react';
|
|
39
|
+
import { BookOpen, Bot, MessageSquare, Plug } from 'lucide-react';
|
|
40
|
+
import Message from 'oneslash-design-system/components/message';
|
|
41
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
42
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
43
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
44
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
45
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
46
|
+
import Button from 'oneslash-design-system/components/button';
|
|
47
|
+
import SourceCard from 'oneslash-design-system/components/sourceCard';
|
|
48
|
+
import { Center, Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';
|
|
49
|
+
|
|
50
|
+
const agentName = 'Acme Agent';
|
|
51
|
+
|
|
52
|
+
const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What did we decide about the launch date?' };
|
|
53
|
+
const repliedAt = new Date('2025-01-15T11:41:00Z');
|
|
54
|
+
const reply = 'The launch moved to March 3. Ben asked for two more weeks of testing, and the team agreed in #launch on Jan 12.';
|
|
55
|
+
|
|
56
|
+
type Kind = 'chat' | 'kb';
|
|
57
|
+
// A source with no href is one the person cannot open: its meta says why. Each chat card links to the message it read.
|
|
58
|
+
type Source = { kind: Kind; title: string; where: string; href?: string };
|
|
59
|
+
|
|
60
|
+
const kinds = {
|
|
61
|
+
chat: { label: 'Chat', icon: MessageSquare },
|
|
62
|
+
kb: { label: 'Knowledge base', icon: BookOpen },
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const sources: Source[] = [
|
|
66
|
+
{ kind: 'chat', title: 'Launch date', where: '#launch · Jan 12', href: '/chat/launch/m-1042' },
|
|
67
|
+
{ kind: 'kb', title: 'Launch plan 2025', where: 'Acme Design', href: '/docs/launch-plan-2025' },
|
|
68
|
+
{ kind: 'chat', title: 'Testing schedule', where: '#qa · Jan 10', href: '/chat/qa/m-0981' },
|
|
69
|
+
{ kind: 'kb', title: 'Release checklist', where: 'Acme Design', href: '/docs/release-checklist' },
|
|
70
|
+
{ kind: 'chat', title: 'Budget for the launch', where: 'Private channel you are not in' },
|
|
71
|
+
{ kind: 'kb', title: 'Press kit guide', where: 'Acme Marketing', href: '/docs/press-kit-guide' },
|
|
72
|
+
{ kind: 'chat', title: 'Beta feedback', where: '#beta · Jan 8', href: '/chat/beta/m-0917' },
|
|
73
|
+
{ kind: 'kb', title: 'Pricing for the new plans', where: 'Acme Design', href: '/docs/pricing' },
|
|
74
|
+
{ kind: 'chat', title: 'Launch day roles', where: '#launch · Jan 14', href: '/chat/launch/m-1107' },
|
|
75
|
+
{ kind: 'kb', title: 'Support playbook', where: 'Acme Support', href: '/docs/support-playbook' },
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const visible = 6;
|
|
79
|
+
|
|
80
|
+
// 'From Chat · Knowledge base': each kind once, in the order it first appears.
|
|
81
|
+
function kindsTag(list: Source[]) {
|
|
82
|
+
const labels: string[] = [];
|
|
83
|
+
list.forEach((s) => {
|
|
84
|
+
if (!labels.includes(kinds[s.kind].label)) labels.push(kinds[s.kind].label);
|
|
85
|
+
});
|
|
86
|
+
return `From ${labels.join(' · ')}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
90
|
+
function agentMeta(at: Date) {
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
94
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
95
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
96
|
+
</>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default function ReplySourcesCards() {
|
|
101
|
+
const [expanded, setExpanded] = useState(false);
|
|
102
|
+
const shown = expanded ? sources : sources.slice(0, visible);
|
|
103
|
+
const more = sources.length - visible;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Center width="page">
|
|
107
|
+
<Stack gap="large">
|
|
108
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
109
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
110
|
+
<Stack gap="small">
|
|
111
|
+
<Message
|
|
112
|
+
aria-label={request.from}
|
|
113
|
+
avatar={<UserImage userHandle={request.from} decorative />}
|
|
114
|
+
name={request.from}
|
|
115
|
+
meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
|
|
116
|
+
>
|
|
117
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
118
|
+
</Message>
|
|
119
|
+
<Message
|
|
120
|
+
aria-label={`${agentName}, agent`}
|
|
121
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
122
|
+
name={agentName}
|
|
123
|
+
meta={agentMeta(repliedAt)}
|
|
124
|
+
// A reply that used no sources has no footer at all.
|
|
125
|
+
footer={
|
|
126
|
+
<Stack gap="medium">
|
|
127
|
+
<Cluster>
|
|
128
|
+
<Tag variant="contained" size="small" color="success" icon={Plug} label={kindsTag(sources)} />
|
|
129
|
+
</Cluster>
|
|
130
|
+
<Grid columns={2} gap="medium">
|
|
131
|
+
{shown.map((s) => (
|
|
132
|
+
// A source in the product is a path; one on another site is an https:// URL and opens in a new tab.
|
|
133
|
+
<SourceCard
|
|
134
|
+
key={`${s.kind}:${s.title}`}
|
|
135
|
+
icon={kinds[s.kind].icon}
|
|
136
|
+
title={s.title}
|
|
137
|
+
meta={`${kinds[s.kind].label} · ${s.where}`}
|
|
138
|
+
href={s.href}
|
|
139
|
+
/>
|
|
140
|
+
))}
|
|
141
|
+
</Grid>
|
|
142
|
+
{more > 0 && (
|
|
143
|
+
<Cluster>
|
|
144
|
+
<Button
|
|
145
|
+
size="small"
|
|
146
|
+
type="textOnly"
|
|
147
|
+
state="enabled"
|
|
148
|
+
label={expanded ? 'Show Fewer' : `Show ${more} More`}
|
|
149
|
+
aria-expanded={expanded}
|
|
150
|
+
onClickButton={() => setExpanded((e) => !e)}
|
|
151
|
+
/>
|
|
152
|
+
</Cluster>
|
|
153
|
+
)}
|
|
154
|
+
</Stack>
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
158
|
+
</Message>
|
|
159
|
+
</Stack>
|
|
160
|
+
</Stack>
|
|
161
|
+
</Center>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Option: Tag only
|
|
167
|
+
|
|
168
|
+
Use when: The reply read only the messages already on screen above it.
|
|
169
|
+
|
|
170
|
+
Uses: `Center`, `Cluster`, `Heading`, `Message`, `Paragraph`, `Stack`, `Tag`, `TimeStamp`, `UserImage`
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
'use client';
|
|
174
|
+
import { Bot, Plug } from 'lucide-react';
|
|
175
|
+
import Message from 'oneslash-design-system/components/message';
|
|
176
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
177
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
178
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
179
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
180
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
181
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
182
|
+
|
|
183
|
+
const agentName = 'Acme Agent';
|
|
184
|
+
|
|
185
|
+
const thread = [
|
|
186
|
+
{ from: 'Ben Carter', at: new Date('2025-01-15T11:36:00Z'), text: 'Testing needs two more weeks. It now ends on January 31.' },
|
|
187
|
+
{ from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Acme Agent, what does that do to the launch date?' },
|
|
188
|
+
];
|
|
189
|
+
const repliedAt = new Date('2025-01-15T11:41:00Z');
|
|
190
|
+
// The agent read only the messages above, which the person can already see.
|
|
191
|
+
const reply = 'If testing ends on January 31, the launch moves to March 3. That keeps the two weeks Ben asked for.';
|
|
192
|
+
|
|
193
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
194
|
+
function agentMeta(at: Date) {
|
|
195
|
+
return (
|
|
196
|
+
<>
|
|
197
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
198
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
199
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
200
|
+
</>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default function ReplySourcesTagOnly() {
|
|
205
|
+
return (
|
|
206
|
+
<Center width="page">
|
|
207
|
+
<Stack gap="large">
|
|
208
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
209
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
210
|
+
<Stack gap="small">
|
|
211
|
+
{thread.map((m) => (
|
|
212
|
+
<Message
|
|
213
|
+
key={m.from}
|
|
214
|
+
aria-label={m.from}
|
|
215
|
+
avatar={<UserImage userHandle={m.from} decorative />}
|
|
216
|
+
name={m.from}
|
|
217
|
+
meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
|
|
218
|
+
>
|
|
219
|
+
<Paragraph measure="none">{m.text}</Paragraph>
|
|
220
|
+
</Message>
|
|
221
|
+
))}
|
|
222
|
+
<Message
|
|
223
|
+
aria-label={`${agentName}, agent`}
|
|
224
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
225
|
+
name={agentName}
|
|
226
|
+
meta={agentMeta(repliedAt)}
|
|
227
|
+
// One kind of source, already on screen: the tag says where the answer came from, and no cards follow.
|
|
228
|
+
footer={
|
|
229
|
+
<Cluster>
|
|
230
|
+
<Tag variant="contained" size="small" color="success" icon={Plug} label="From Chat" />
|
|
231
|
+
</Cluster>
|
|
232
|
+
}
|
|
233
|
+
>
|
|
234
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
235
|
+
</Message>
|
|
236
|
+
</Stack>
|
|
237
|
+
</Stack>
|
|
238
|
+
</Center>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Native
|
|
244
|
+
|
|
245
|
+
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.
|
|
246
|
+
|
|
247
|
+
Seen in: Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function SlashCommandListInComposer(): import("react").JSX.Element;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import { useEffect, useRef, useState } from 'react';
|
|
12
|
+
import Message from '../../components/message';
|
|
13
|
+
import UserImage from '../../components/userImage';
|
|
14
|
+
import TimeStamp from '../../components/timeStamp';
|
|
15
|
+
import Heading from '../../components/heading';
|
|
16
|
+
import Paragraph from '../../components/paragraph';
|
|
17
|
+
import Composer from '../../components/composer';
|
|
18
|
+
import Menu from '../../components/menu';
|
|
19
|
+
import MenuItem from '../../components/menuItem';
|
|
20
|
+
import { Center, Stack } from '../../components/layout';
|
|
21
|
+
// A real app reads this from the session.
|
|
22
|
+
var me = 'Dana Lee';
|
|
23
|
+
var commands = [
|
|
24
|
+
{ name: 'plan', does: 'Ask the agent for a plan before it acts' },
|
|
25
|
+
{ name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },
|
|
26
|
+
{ name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },
|
|
27
|
+
{ name: 'status', does: 'Show what the agent is working on' },
|
|
28
|
+
];
|
|
29
|
+
var listId = 'slash-command-list-commands';
|
|
30
|
+
// The list shows at most this many commands; typing more letters narrows it.
|
|
31
|
+
var MAX_MATCHES = 8;
|
|
32
|
+
var optionId = function (c) { return "slash-command-list-option-".concat(c.name); };
|
|
33
|
+
var firstThread = [
|
|
34
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
|
|
35
|
+
{ id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },
|
|
36
|
+
];
|
|
37
|
+
// Opens with a / typed, so the list shows every command.
|
|
38
|
+
var firstText = '/';
|
|
39
|
+
// The word after a / at the start of the text before the caret, or null once there is a space or no /.
|
|
40
|
+
function commandQuery(before) {
|
|
41
|
+
var match = before.match(/^\/(\S*)$/);
|
|
42
|
+
return match ? match[1] : null;
|
|
43
|
+
}
|
|
44
|
+
// The query for where the caret is now.
|
|
45
|
+
function queryAtCaret(field) {
|
|
46
|
+
var _a;
|
|
47
|
+
return commandQuery(field.value.slice(0, (_a = field.selectionStart) !== null && _a !== void 0 ? _a : field.value.length));
|
|
48
|
+
}
|
|
49
|
+
var matches = function (query) { return commands.filter(function (c) { return c.name.startsWith(query.toLowerCase()); }).slice(0, MAX_MATCHES); };
|
|
50
|
+
export default function SlashCommandListInComposer() {
|
|
51
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
52
|
+
var _b = useState(firstText), text = _b[0], setText = _b[1];
|
|
53
|
+
var _c = useState(commandQuery(firstText)), query = _c[0], setQuery = _c[1];
|
|
54
|
+
var _d = useState(0), active = _d[0], setActive = _d[1];
|
|
55
|
+
// Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
|
|
56
|
+
var _e = useState(null), caret = _e[0], setCaret = _e[1];
|
|
57
|
+
var field = useRef(null);
|
|
58
|
+
var results = query === null ? [] : matches(query);
|
|
59
|
+
// No match: the list closes.
|
|
60
|
+
var open = results.length > 0;
|
|
61
|
+
// The field opens with the caret at the end, after the /.
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
|
|
65
|
+
(_c = field.current) === null || _c === void 0 ? void 0 : _c.setSelectionRange(end, end);
|
|
66
|
+
}, []);
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
if (caret === null || !field.current)
|
|
69
|
+
return;
|
|
70
|
+
field.current.focus();
|
|
71
|
+
field.current.setSelectionRange(caret, caret);
|
|
72
|
+
setCaret(null);
|
|
73
|
+
}, [caret]);
|
|
74
|
+
function change(value) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
setText(value);
|
|
77
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length;
|
|
78
|
+
setQuery(commandQuery(value.slice(0, at)));
|
|
79
|
+
setActive(0);
|
|
80
|
+
}
|
|
81
|
+
// The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
|
|
82
|
+
// closes when the caret leaves it.
|
|
83
|
+
function caretMoved(e) {
|
|
84
|
+
var next = queryAtCaret(e.currentTarget);
|
|
85
|
+
if (next === query)
|
|
86
|
+
return;
|
|
87
|
+
setQuery(next);
|
|
88
|
+
setActive(0);
|
|
89
|
+
}
|
|
90
|
+
// Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes
|
|
91
|
+
// after the space, so the person can type the argument. Nothing runs yet.
|
|
92
|
+
function pick(c) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : text.length;
|
|
95
|
+
var insert = "/".concat(c.name, " ");
|
|
96
|
+
// One space between the command and what follows, not two.
|
|
97
|
+
var after = text.slice(at).replace(/^ /, '');
|
|
98
|
+
setText(insert + after);
|
|
99
|
+
setQuery(null);
|
|
100
|
+
setCaret(insert.length);
|
|
101
|
+
}
|
|
102
|
+
// While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
|
|
103
|
+
function keyDown(e) {
|
|
104
|
+
// An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
|
|
105
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229)
|
|
106
|
+
return;
|
|
107
|
+
if (!open)
|
|
108
|
+
return;
|
|
109
|
+
if (e.key === 'ArrowDown') {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
setActive(function (i) { return Math.min(i + 1, results.length - 1); });
|
|
112
|
+
}
|
|
113
|
+
else if (e.key === 'ArrowUp') {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
setActive(function (i) { return Math.max(i - 1, 0); });
|
|
116
|
+
}
|
|
117
|
+
else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
|
|
118
|
+
// Check the word at the caret again before taking the key. If nothing matches now, the list
|
|
119
|
+
// closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
|
|
120
|
+
var now = queryAtCaret(e.currentTarget);
|
|
121
|
+
var found = now === null ? [] : matches(now);
|
|
122
|
+
if (found.length === 0) {
|
|
123
|
+
setQuery(null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
|
|
128
|
+
}
|
|
129
|
+
else if (e.key === 'Escape') {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
e.stopPropagation();
|
|
132
|
+
setQuery(null);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A real app runs the command here. This one shows it in the thread.
|
|
136
|
+
function send() {
|
|
137
|
+
var value = text.trim();
|
|
138
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: value, command: value.startsWith('/') }], false); });
|
|
139
|
+
setText('');
|
|
140
|
+
setQuery(null);
|
|
141
|
+
}
|
|
142
|
+
return (<Center width="page">
|
|
143
|
+
<Stack gap="large">
|
|
144
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
145
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
146
|
+
<Stack gap="small">
|
|
147
|
+
{thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
|
|
148
|
+
<Paragraph measure="none" mono={m.command}>{m.text}</Paragraph>
|
|
149
|
+
</Message>); })}
|
|
150
|
+
</Stack>
|
|
151
|
+
<Composer ref={field} id="slash-command-list-message" aria-label="Message" placeholder="Message the team, or type / for commands" value={text} onChange={change} onSubmit={send} onKeyDown={keyDown} onSelect={caretMoved}
|
|
152
|
+
// A press on a row keeps focus in the field, so this runs only when focus leaves for good.
|
|
153
|
+
onBlur={function () { return setQuery(null); }}
|
|
154
|
+
// Focus stays in the field; the field points at the list and at the highlighted row.
|
|
155
|
+
role="combobox" aria-autocomplete="list" aria-expanded={open} aria-controls={open ? listId : undefined} aria-activedescendant={open ? optionId(results[active]) : undefined} above={open ? (<Menu role="listbox" id={listId} aria-label="Commands" width={400}>
|
|
156
|
+
{results.map(function (c, i) { return (<MenuItem key={c.name} id={optionId(c)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small" iconName="SquareSlash"
|
|
157
|
+
// MenuItem has no mono label, so the command is plain text.
|
|
158
|
+
label={"/".concat(c.name)} secondLabel={c.does} tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined} onClick={function () { return pick(c); }}/>); })}
|
|
159
|
+
</Menu>) : undefined}/>
|
|
160
|
+
</Stack>
|
|
161
|
+
</Center>);
|
|
162
|
+
}
|