@swisper.ai/web-chat-ui 0.2.5 → 0.2.6
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/dist/components/chat-artifact/chat-artifact.d.ts +52 -0
- package/dist/components/chat-artifact/chat-artifact.d.ts.map +1 -0
- package/dist/components/chat-artifact/chat-artifact.stories.d.ts +18 -0
- package/dist/components/chat-artifact/chat-artifact.stories.d.ts.map +1 -0
- package/dist/components/chat-artifact/index.d.ts +2 -0
- package/dist/components/chat-artifact/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +2 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +316 -261
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/components/chat-artifact/chat-artifact.json +118 -0
- package/src/components/chat-artifact/chat-artifact.stories.tsx +212 -0
- package/src/components/chat-artifact/chat-artifact.tsx +151 -0
- package/src/components/chat-artifact/index.ts +14 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +14 -0
- package/src/components/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
|
+
"component": "chat-artifact",
|
|
4
|
+
"purpose": "A message-row control for a generated artifact: an icon slot (ChatArtifactIcon), stacked title and caption (ChatArtifactContent with ChatArtifactTitle and ChatArtifactCaption), and trailing consumer actions (ChatArtifactActions). Root supports asChild so the row can render as a link or button.",
|
|
5
|
+
"anatomy": [
|
|
6
|
+
"import {",
|
|
7
|
+
" ChatArtifact,",
|
|
8
|
+
" ChatArtifactIcon,",
|
|
9
|
+
" ChatArtifactContent,",
|
|
10
|
+
" ChatArtifactTitle,",
|
|
11
|
+
" ChatArtifactCaption,",
|
|
12
|
+
" ChatArtifactActions,",
|
|
13
|
+
"} from '@swisper.ai/web-chat-ui';",
|
|
14
|
+
"",
|
|
15
|
+
"<ChatArtifact>",
|
|
16
|
+
" <ChatArtifactIcon />",
|
|
17
|
+
" <ChatArtifactContent>",
|
|
18
|
+
" <ChatArtifactTitle />",
|
|
19
|
+
" <ChatArtifactCaption />",
|
|
20
|
+
" </ChatArtifactContent>",
|
|
21
|
+
" <ChatArtifactActions />",
|
|
22
|
+
"</ChatArtifact>"
|
|
23
|
+
],
|
|
24
|
+
"useWhen": [
|
|
25
|
+
"Showing a generated artifact (slides, doc, sheet) in an assistant message so the user can open or share it",
|
|
26
|
+
"Composing a row with a title, a secondary caption, and trailing action buttons",
|
|
27
|
+
"Wrapping the whole row as a link with asChild"
|
|
28
|
+
],
|
|
29
|
+
"avoidWhen": [
|
|
30
|
+
"A file the user attached to the prompt or sent with a question — use web-chat-ui/chat-message-attachment-card",
|
|
31
|
+
"Opening or reading a file's contents in a panel — use web-file-preview/file-preview or web-chat-ui/canvas-shell",
|
|
32
|
+
"A rich result card with form fields or collapsible sections — use cards-ui/card"
|
|
33
|
+
],
|
|
34
|
+
"uxPrinciples": [
|
|
35
|
+
"Name the artifact first; the caption carries source or visibility, not a second headline",
|
|
36
|
+
"Actions stay consumer-owned: the package does not ship Share or Open buttons"
|
|
37
|
+
],
|
|
38
|
+
"accessibility": {
|
|
39
|
+
"required": [
|
|
40
|
+
"Give each control in ChatArtifactActions an accessible name (aria-label on icon-only buttons, visible text on labelled buttons)",
|
|
41
|
+
"When asChild renders the root as a link or button, ensure the accessible name reflects the artifact (title text inside the root is enough if it is not nested in another labelled control)"
|
|
42
|
+
],
|
|
43
|
+
"keyboard": [
|
|
44
|
+
"The root is not focusable when it is a div; focus lands on the controls inside ChatArtifactActions, or on the root when asChild makes it a link or button"
|
|
45
|
+
],
|
|
46
|
+
"aria": [
|
|
47
|
+
"The root and the actions wrapper set role=group without an accessible name",
|
|
48
|
+
"ChatArtifactIcon sets no role or label; ChatArtifactTitle and ChatArtifactCaption supply the text"
|
|
49
|
+
],
|
|
50
|
+
"focus": ["No focus management; action controls use their own focus rings"]
|
|
51
|
+
},
|
|
52
|
+
"behaviour": {
|
|
53
|
+
"states": ["default"],
|
|
54
|
+
"rules": [
|
|
55
|
+
"asChild=true merges the root props onto the single child via Radix Slot; false (default) renders a div with role=group",
|
|
56
|
+
"ChatArtifactContent stacks ChatArtifactTitle above ChatArtifactCaption and truncates overflow",
|
|
57
|
+
"ChatArtifactTitle uses body-sm and truncates to one line; ChatArtifactCaption uses caption-md, tertiary text, and truncates to one line",
|
|
58
|
+
"ChatArtifactActions is a trailing flex slot for consumer controls; it does not provide Share, Open or remove",
|
|
59
|
+
"ChatArtifactIcon is a shrink-0 wrapper; nest any icon or thumbnail, including web-chat-ui/ChatMessageAttachmentCardIcon",
|
|
60
|
+
"Every part takes className, merged last. The root reuses promptbox-attachment background and radius tokens"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"composition": {
|
|
64
|
+
"allowedParents": ["web-chat-ui/ChatThreadAnswer"],
|
|
65
|
+
"allowedChildren": [
|
|
66
|
+
"web-chat-ui/ChatArtifactIcon",
|
|
67
|
+
"web-chat-ui/ChatArtifactContent",
|
|
68
|
+
"web-chat-ui/ChatArtifactTitle",
|
|
69
|
+
"web-chat-ui/ChatArtifactCaption",
|
|
70
|
+
"web-chat-ui/ChatArtifactActions",
|
|
71
|
+
"web-chat-ui/ChatMessageAttachmentCardIcon",
|
|
72
|
+
"icon (in ChatArtifactIcon)",
|
|
73
|
+
"ui/Button",
|
|
74
|
+
"ui/IconButton"
|
|
75
|
+
],
|
|
76
|
+
"avoidCombinations": [
|
|
77
|
+
"ChatArtifactCaption without ChatArtifactTitle — the caption is secondary to the name",
|
|
78
|
+
"Using it for prompt attachments that can be removed — use web-chat-ui/chat-message-attachment-card with ChatMessageAttachmentCardActions"
|
|
79
|
+
],
|
|
80
|
+
"contexts": ["assistant message in a chat thread", "artifact list in a message"]
|
|
81
|
+
},
|
|
82
|
+
"content": {
|
|
83
|
+
"labelRules": ["ChatArtifactTitle is the artifact name as shown to the user (e.g. 'Weather')"],
|
|
84
|
+
"helperTextRules": [
|
|
85
|
+
"ChatArtifactCaption holds a short secondary fact (source, visibility, type), not a second title"
|
|
86
|
+
],
|
|
87
|
+
"errorRules": []
|
|
88
|
+
},
|
|
89
|
+
"aiDecisionRules": [
|
|
90
|
+
{
|
|
91
|
+
"condition": "The assistant produced an artifact the user can open",
|
|
92
|
+
"decision": "Render ChatArtifact with title, optional caption, and ChatArtifactActions holding the open (and any share) control",
|
|
93
|
+
"reason": "The row is for opening the artifact, not for listing an uploaded file"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"condition": "The whole row should navigate to the artifact",
|
|
97
|
+
"decision": "Set asChild and wrap an a or button that contains the icon, content and actions",
|
|
98
|
+
"reason": "asChild merges the row chrome onto that interactive element"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"condition": "The file is a user attachment on the prompt or a sent question",
|
|
102
|
+
"decision": "Use web-chat-ui/chat-message-attachment-card instead",
|
|
103
|
+
"reason": "Attachment chips own remove and preview; ChatArtifact does not"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"relatedComponents": [
|
|
107
|
+
"web-chat-ui/chat-message-attachment-card",
|
|
108
|
+
"web-chat-ui/chat-thread",
|
|
109
|
+
"web-chat-ui/canvas-shell",
|
|
110
|
+
"web-file-preview/file-preview",
|
|
111
|
+
"cards-ui/card"
|
|
112
|
+
],
|
|
113
|
+
"tokenReferences": {
|
|
114
|
+
"source": "packages/design-system/src/tailwind.css",
|
|
115
|
+
"categories": ["promptbox-attachment-* (background, radius)"],
|
|
116
|
+
"rule": "Reuse the attachment chip chrome; do not invent a separate artifact palette until tokens exist."
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
|
|
4
|
+
import { ShareIcon } from '@swisper.ai/icons';
|
|
5
|
+
import { Button, IconButton } from '@swisper.ai/ui';
|
|
6
|
+
|
|
7
|
+
import { ParentBlock } from '../../__storybook__/parent-block';
|
|
8
|
+
import { ChatMessageAttachmentCardIcon } from '../chat-message-attachment-card';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ChatArtifact,
|
|
12
|
+
ChatArtifactActions,
|
|
13
|
+
ChatArtifactCaption,
|
|
14
|
+
ChatArtifactContent,
|
|
15
|
+
ChatArtifactIcon,
|
|
16
|
+
ChatArtifactTitle,
|
|
17
|
+
} from './chat-artifact';
|
|
18
|
+
|
|
19
|
+
const meta: Meta<typeof ChatArtifact> = {
|
|
20
|
+
title: 'Chat/ChatArtifact',
|
|
21
|
+
component: ChatArtifact,
|
|
22
|
+
subcomponents: {
|
|
23
|
+
ChatArtifactIcon,
|
|
24
|
+
ChatArtifactContent,
|
|
25
|
+
ChatArtifactTitle,
|
|
26
|
+
ChatArtifactCaption,
|
|
27
|
+
ChatArtifactActions,
|
|
28
|
+
},
|
|
29
|
+
tags: ['autodocs'],
|
|
30
|
+
argTypes: {
|
|
31
|
+
asChild: {
|
|
32
|
+
control: 'boolean',
|
|
33
|
+
description:
|
|
34
|
+
'Merges the root props onto the single child (e.g. an `a` or `button`) instead of rendering a `div`.',
|
|
35
|
+
table: { defaultValue: { summary: 'false' } },
|
|
36
|
+
},
|
|
37
|
+
children: {
|
|
38
|
+
control: false,
|
|
39
|
+
description:
|
|
40
|
+
'The parts: `ChatArtifactIcon`, `ChatArtifactContent` (title and caption), and `ChatArtifactActions`.',
|
|
41
|
+
},
|
|
42
|
+
className: {
|
|
43
|
+
control: 'text',
|
|
44
|
+
description:
|
|
45
|
+
'Extra classes merged onto the root, e.g. `w-fit max-w-80` to cap the row width.',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
args: {
|
|
49
|
+
asChild: false,
|
|
50
|
+
className: 'w-fit max-w-80',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default meta;
|
|
55
|
+
type Story = StoryObj<typeof ChatArtifact>;
|
|
56
|
+
|
|
57
|
+
/** An artifact in a message: presentation icon, name, caption, and share plus open actions. */
|
|
58
|
+
export const Default: Story = {
|
|
59
|
+
render: (args) => (
|
|
60
|
+
<ChatArtifact {...args}>
|
|
61
|
+
<ChatArtifactIcon>
|
|
62
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
63
|
+
</ChatArtifactIcon>
|
|
64
|
+
<ChatArtifactContent>
|
|
65
|
+
<ChatArtifactTitle>Weather</ChatArtifactTitle>
|
|
66
|
+
<ChatArtifactCaption>Claude Slides · Only you</ChatArtifactCaption>
|
|
67
|
+
</ChatArtifactContent>
|
|
68
|
+
<ChatArtifactActions>
|
|
69
|
+
<IconButton variant="tertiary" size="sm" aria-label="Share" onClick={fn()}>
|
|
70
|
+
<ShareIcon />
|
|
71
|
+
</IconButton>
|
|
72
|
+
<Button size="sm" onClick={fn()}>
|
|
73
|
+
Open
|
|
74
|
+
</Button>
|
|
75
|
+
</ChatArtifactActions>
|
|
76
|
+
</ChatArtifact>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** The whole row is a link via `asChild` (no nested buttons — those belong on a `div` root). */
|
|
81
|
+
export const AsChildLink: Story = {
|
|
82
|
+
args: { asChild: true, className: 'w-fit max-w-80' },
|
|
83
|
+
render: (args) => (
|
|
84
|
+
<ChatArtifact {...args}>
|
|
85
|
+
<a href="#artifact-weather" className="no-underline text-inherit">
|
|
86
|
+
<ChatArtifactIcon>
|
|
87
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
88
|
+
</ChatArtifactIcon>
|
|
89
|
+
<ChatArtifactContent>
|
|
90
|
+
<ChatArtifactTitle>Weather</ChatArtifactTitle>
|
|
91
|
+
<ChatArtifactCaption>Claude Slides · Only you</ChatArtifactCaption>
|
|
92
|
+
</ChatArtifactContent>
|
|
93
|
+
</a>
|
|
94
|
+
</ChatArtifact>
|
|
95
|
+
),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Title only — caption and actions are optional. */
|
|
99
|
+
export const TitleOnly: Story = {
|
|
100
|
+
render: (args) => (
|
|
101
|
+
<ChatArtifact {...args}>
|
|
102
|
+
<ChatArtifactIcon>
|
|
103
|
+
<ChatMessageAttachmentCardIcon icon="document" />
|
|
104
|
+
</ChatArtifactIcon>
|
|
105
|
+
<ChatArtifactContent>
|
|
106
|
+
<ChatArtifactTitle>Q3 itinerary draft</ChatArtifactTitle>
|
|
107
|
+
</ChatArtifactContent>
|
|
108
|
+
</ChatArtifact>
|
|
109
|
+
),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** A name and caption longer than the row: both ellipsize to one line, and the actions stay fully visible. */
|
|
113
|
+
export const LongTitle: Story = {
|
|
114
|
+
render: (args) => (
|
|
115
|
+
<ChatArtifact {...args}>
|
|
116
|
+
<ChatArtifactIcon>
|
|
117
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
118
|
+
</ChatArtifactIcon>
|
|
119
|
+
<ChatArtifactContent>
|
|
120
|
+
<ChatArtifactTitle>
|
|
121
|
+
Alpine weather briefing for the summer season across the resorts
|
|
122
|
+
</ChatArtifactTitle>
|
|
123
|
+
<ChatArtifactCaption>
|
|
124
|
+
Claude Slides · Shared with the travel team · Only you can view this deck
|
|
125
|
+
</ChatArtifactCaption>
|
|
126
|
+
</ChatArtifactContent>
|
|
127
|
+
<ChatArtifactActions>
|
|
128
|
+
<IconButton variant="tertiary" size="sm" aria-label="Share" onClick={fn()}>
|
|
129
|
+
<ShareIcon />
|
|
130
|
+
</IconButton>
|
|
131
|
+
<Button size="sm" onClick={fn()}>
|
|
132
|
+
Open
|
|
133
|
+
</Button>
|
|
134
|
+
</ChatArtifactActions>
|
|
135
|
+
</ChatArtifact>
|
|
136
|
+
),
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** Inside an assistant message, as it appears in a thread. */
|
|
140
|
+
export const Examples: Story = {
|
|
141
|
+
parameters: { controls: { disable: true } },
|
|
142
|
+
render: () => (
|
|
143
|
+
<ul aria-label="ChatArtifact examples" className="flex flex-col gap-24">
|
|
144
|
+
<li>
|
|
145
|
+
<ParentBlock parent="assistant message">
|
|
146
|
+
<ChatArtifact className="w-fit max-w-80">
|
|
147
|
+
<ChatArtifactIcon>
|
|
148
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
149
|
+
</ChatArtifactIcon>
|
|
150
|
+
<ChatArtifactContent>
|
|
151
|
+
<ChatArtifactTitle>Weather</ChatArtifactTitle>
|
|
152
|
+
<ChatArtifactCaption>Claude Slides · Only you</ChatArtifactCaption>
|
|
153
|
+
</ChatArtifactContent>
|
|
154
|
+
<ChatArtifactActions>
|
|
155
|
+
<IconButton variant="tertiary" size="sm" aria-label="Share" onClick={fn()}>
|
|
156
|
+
<ShareIcon />
|
|
157
|
+
</IconButton>
|
|
158
|
+
<Button size="sm" onClick={fn()}>
|
|
159
|
+
Open
|
|
160
|
+
</Button>
|
|
161
|
+
</ChatArtifactActions>
|
|
162
|
+
</ChatArtifact>
|
|
163
|
+
</ParentBlock>
|
|
164
|
+
</li>
|
|
165
|
+
</ul>
|
|
166
|
+
),
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/** Toggle className and asChild from the controls. */
|
|
170
|
+
export const Playground: Story = {
|
|
171
|
+
args: {
|
|
172
|
+
asChild: false,
|
|
173
|
+
className: 'w-fit max-w-80',
|
|
174
|
+
},
|
|
175
|
+
render: (args) => {
|
|
176
|
+
if (args.asChild) {
|
|
177
|
+
return (
|
|
178
|
+
<ChatArtifact {...args}>
|
|
179
|
+
<a href="#artifact-playground" className="no-underline text-inherit">
|
|
180
|
+
<ChatArtifactIcon>
|
|
181
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
182
|
+
</ChatArtifactIcon>
|
|
183
|
+
<ChatArtifactContent>
|
|
184
|
+
<ChatArtifactTitle>Weather</ChatArtifactTitle>
|
|
185
|
+
<ChatArtifactCaption>Claude Slides · Only you</ChatArtifactCaption>
|
|
186
|
+
</ChatArtifactContent>
|
|
187
|
+
</a>
|
|
188
|
+
</ChatArtifact>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<ChatArtifact {...args}>
|
|
194
|
+
<ChatArtifactIcon>
|
|
195
|
+
<ChatMessageAttachmentCardIcon icon="presentation" />
|
|
196
|
+
</ChatArtifactIcon>
|
|
197
|
+
<ChatArtifactContent>
|
|
198
|
+
<ChatArtifactTitle>Weather</ChatArtifactTitle>
|
|
199
|
+
<ChatArtifactCaption>Claude Slides · Only you</ChatArtifactCaption>
|
|
200
|
+
</ChatArtifactContent>
|
|
201
|
+
<ChatArtifactActions>
|
|
202
|
+
<IconButton variant="tertiary" size="sm" aria-label="Share" onClick={fn()}>
|
|
203
|
+
<ShareIcon />
|
|
204
|
+
</IconButton>
|
|
205
|
+
<Button size="sm" onClick={fn()}>
|
|
206
|
+
Open
|
|
207
|
+
</Button>
|
|
208
|
+
</ChatArtifactActions>
|
|
209
|
+
</ChatArtifact>
|
|
210
|
+
);
|
|
211
|
+
},
|
|
212
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
+
import type { HtmlHTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { Typography } from '@swisper.ai/ui';
|
|
5
|
+
import { cn } from '@swisper.ai/web-core';
|
|
6
|
+
|
|
7
|
+
export interface ChatArtifactProps extends HtmlHTMLAttributes<HTMLButtonElement> {
|
|
8
|
+
/** When true, merges props onto the single child instead of rendering a `div`. */
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
/** Classes merged last onto the root. */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** The artifact parts: an icon, the content with title and caption, and the actions. */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A message-row control for a generated artifact: icon, title, caption and trailing actions. */
|
|
17
|
+
export function ChatArtifact({ asChild = false, className, children, ...rest }: ChatArtifactProps) {
|
|
18
|
+
const Comp = asChild ? Slot : 'button';
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Comp
|
|
22
|
+
role="group"
|
|
23
|
+
data-slot="chat-artifact"
|
|
24
|
+
data-testid="chat-artifact"
|
|
25
|
+
className={cn(
|
|
26
|
+
'cursor-pointer',
|
|
27
|
+
'max-w-80',
|
|
28
|
+
'flex flex-row items-center gap-8',
|
|
29
|
+
'p-8 rounded-promptbox-attachment',
|
|
30
|
+
'bg-promptbox-attachment-background',
|
|
31
|
+
'hover:bg-promptbox-attachment-background-hover',
|
|
32
|
+
'active:bg-promptbox-attachment-background-pressed',
|
|
33
|
+
'outline-none',
|
|
34
|
+
'focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-primary-focus-visible',
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...rest}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</Comp>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ChatArtifactIconProps {
|
|
45
|
+
/** Classes merged last onto the icon wrapper. */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** The icon or thumbnail to show. */
|
|
48
|
+
children?: ReactNode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Shrink-wrapped slot for a consumer-supplied icon or thumbnail. */
|
|
52
|
+
export function ChatArtifactIcon({ className, children }: ChatArtifactIconProps) {
|
|
53
|
+
return (
|
|
54
|
+
<span
|
|
55
|
+
data-slot="chat-artifact-icon"
|
|
56
|
+
data-testid="chat-artifact-icon"
|
|
57
|
+
className={cn(
|
|
58
|
+
'inline-flex shrink-0 items-center justify-center',
|
|
59
|
+
'text-icon-fill-inverse inline-flex size-promptbox-attachment-size-icon-container items-center justify-center',
|
|
60
|
+
'bg-secondary-hover',
|
|
61
|
+
'rounded-[8px] p-8 [&_svg]:size-[24px]',
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</span>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ChatArtifactContentProps {
|
|
71
|
+
/** Classes merged last onto the content element. */
|
|
72
|
+
className?: string;
|
|
73
|
+
/** Usually a `ChatArtifactTitle` and optional `ChatArtifactCaption`. */
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The text column: takes the width left beside the icon and stacks title above caption. */
|
|
78
|
+
export function ChatArtifactContent({ className, children }: ChatArtifactContentProps) {
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
data-slot="chat-artifact-content"
|
|
82
|
+
data-testid="chat-artifact-content"
|
|
83
|
+
className={cn('flex-1 min-w-0', 'flex flex-col', 'text-left', 'overflow-hidden', className)}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ChatArtifactTitleProps {
|
|
91
|
+
/** Classes merged last onto the title element. */
|
|
92
|
+
className?: string;
|
|
93
|
+
/** The artifact name. */
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The artifact name, truncated to one line. */
|
|
98
|
+
export function ChatArtifactTitle({ className, children }: ChatArtifactTitleProps) {
|
|
99
|
+
return (
|
|
100
|
+
<Typography
|
|
101
|
+
variant="body-sm"
|
|
102
|
+
data-slot="chat-artifact-title"
|
|
103
|
+
data-testid="chat-artifact-title"
|
|
104
|
+
className={cn('min-w-0 w-full truncate', className)}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</Typography>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ChatArtifactCaptionProps {
|
|
112
|
+
/** Classes merged last onto the caption element. */
|
|
113
|
+
className?: string;
|
|
114
|
+
/** Secondary fact under the title, e.g. source or visibility. */
|
|
115
|
+
children?: ReactNode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A quieter secondary line under the title, truncated to one line. */
|
|
119
|
+
export function ChatArtifactCaption({ className, children }: ChatArtifactCaptionProps) {
|
|
120
|
+
return (
|
|
121
|
+
<Typography
|
|
122
|
+
variant="caption-md"
|
|
123
|
+
data-slot="chat-artifact-caption"
|
|
124
|
+
data-testid="chat-artifact-caption"
|
|
125
|
+
className={cn('min-w-0 w-full truncate', 'text-text-tertiary', className)}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</Typography>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface ChatArtifactActionsProps {
|
|
133
|
+
/** Classes merged last onto the actions wrapper. */
|
|
134
|
+
className?: string;
|
|
135
|
+
/** Consumer-supplied controls, e.g. share and open buttons. */
|
|
136
|
+
children?: ReactNode;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Trailing action slot on the right of the row. */
|
|
140
|
+
export function ChatArtifactActions({ className, children }: ChatArtifactActionsProps) {
|
|
141
|
+
return (
|
|
142
|
+
<div
|
|
143
|
+
role="group"
|
|
144
|
+
data-slot="chat-artifact-actions"
|
|
145
|
+
data-testid="chat-artifact-actions"
|
|
146
|
+
className={cn('ml-auto shrink-0', 'flex items-center gap-8', className)}
|
|
147
|
+
>
|
|
148
|
+
{children}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ChatArtifact,
|
|
3
|
+
ChatArtifactIcon,
|
|
4
|
+
ChatArtifactContent,
|
|
5
|
+
ChatArtifactTitle,
|
|
6
|
+
ChatArtifactCaption,
|
|
7
|
+
ChatArtifactActions,
|
|
8
|
+
type ChatArtifactProps,
|
|
9
|
+
type ChatArtifactIconProps,
|
|
10
|
+
type ChatArtifactContentProps,
|
|
11
|
+
type ChatArtifactTitleProps,
|
|
12
|
+
type ChatArtifactCaptionProps,
|
|
13
|
+
type ChatArtifactActionsProps,
|
|
14
|
+
} from './chat-artifact';
|
package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx
CHANGED
|
@@ -87,6 +87,20 @@ export const Default: Story = {
|
|
|
87
87
|
),
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
/** A file name longer than the chip: it truncates to one line instead of widening the card. */
|
|
91
|
+
export const LongTitle: Story = {
|
|
92
|
+
args: { className: 'w-fit max-w-60' },
|
|
93
|
+
render: (args) => (
|
|
94
|
+
<ChatMessageAttachmentCard {...args}>
|
|
95
|
+
<ChatMessageAttachmentCardIcon icon="pdf" />
|
|
96
|
+
<ChatMessageAttachmentCardContent>
|
|
97
|
+
<ChatMessageAttachmentCardTitle>{LONG_FILE_NAME}</ChatMessageAttachmentCardTitle>
|
|
98
|
+
</ChatMessageAttachmentCardContent>
|
|
99
|
+
<ChatMessageAttachmentCardActions onDelete={fn()} />
|
|
100
|
+
</ChatMessageAttachmentCard>
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
|
|
90
104
|
/** A file that was sent with a question: static, with no hover background and no remove action. */
|
|
91
105
|
export const NonInteractive: Story = {
|
|
92
106
|
args: { isInteractive: false, className: 'w-fit max-w-60' },
|
package/src/components/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './chat-notification-popup';
|
|
|
14
14
|
export * from './chat-reply';
|
|
15
15
|
export * from './chat-suggestion';
|
|
16
16
|
export * from './chat-thread';
|
|
17
|
+
export * from './chat-artifact';
|
|
17
18
|
export * from './canvas-shell';
|
|
18
19
|
export * from './new-chat-trigger';
|
|
19
20
|
export * from './chat-thinking-process';
|