@swisper.ai/web-chat-ui 0.0.9 → 0.2.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 +2 -5
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
- package/dist/components/rich-text-field/utils.d.ts +38 -38
- package/dist/index.css +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +1571 -1813
- package/dist/index.es.js.map +1 -1
- package/package.json +5 -5
- package/src/components/chat-card/chat-card.json +6 -6
- package/src/components/chat-card/chat-card.stories.tsx +6 -14
- package/src/components/chat-card/components/chat-card-body.tsx +1 -1
- package/src/components/chat-card/components/chat-card-header.tsx +3 -7
- package/src/components/chat-card-container/chat-card-container.json +6 -6
- package/src/components/chat-card-container/chat-card-container.stories.tsx +10 -18
- package/src/components/chat-container/chat-container.json +1 -1
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +4 -12
- package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +12 -2
- package/src/components/rich-text-field/rich-text-field.stories.tsx +3 -1
- package/src/index.ts +0 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +0 -97
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +0 -52
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-list-layout/index.d.ts +0 -3
- package/dist/layouts/chat-card-list-layout/index.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +0 -84
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -45
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +0 -62
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +0 -81
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/index.d.ts +0 -5
- package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +0 -37
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +0 -12
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +0 -40
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +0 -35
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/index.d.ts +0 -4
- package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +0 -1
- package/dist/layouts/index.d.ts +0 -4
- package/dist/layouts/index.d.ts.map +0 -1
- package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +0 -112
- package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +0 -36
- package/src/layouts/chat-card-list-layout/__stories__/types.ts +0 -31
- package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +0 -204
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +0 -129
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +0 -422
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +0 -254
- package/src/layouts/chat-card-list-layout/index.ts +0 -11
- package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +0 -117
- package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +0 -18
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +0 -85
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +0 -50
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +0 -44
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +0 -61
- package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +0 -35
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +0 -73
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +0 -282
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +0 -147
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -78
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +0 -694
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +0 -291
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +0 -135
- package/src/layouts/chat-card-three-column-layout/index.ts +0 -24
- package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +0 -51
- package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +0 -83
- package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +0 -24
- package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +0 -15
- package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +0 -109
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +0 -109
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +0 -21
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +0 -439
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +0 -141
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +0 -65
- package/src/layouts/chat-card-two-column-layout/index.ts +0 -17
- package/src/layouts/index.ts +0 -3
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
-
import { createContext, forwardRef, useCallback, useContext, useMemo } from 'react';
|
|
3
|
-
import type { ComponentProps, ForwardedRef, ReactNode } from 'react';
|
|
4
|
-
|
|
5
|
-
import { cn, useElementMeasure } from '@swisper.ai/web-core';
|
|
6
|
-
|
|
7
|
-
import { resolveLayout } from './chat-card-three-column-layout.sizing';
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_DETAILS_PLACEMENT,
|
|
10
|
-
chatCardThreeColumnLayoutDetailsVariants,
|
|
11
|
-
chatCardThreeColumnLayoutListVariants,
|
|
12
|
-
chatCardThreeColumnLayoutMainVariants,
|
|
13
|
-
chatCardThreeColumnLayoutPanelVariants,
|
|
14
|
-
chatCardThreeColumnLayoutVariants,
|
|
15
|
-
} from './chat-card-three-column-layout.variants';
|
|
16
|
-
import type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
|
|
17
|
-
|
|
18
|
-
interface ChatCardThreeColumnLayoutContextValue {
|
|
19
|
-
isListFloating: boolean;
|
|
20
|
-
isDetailsFloating: boolean;
|
|
21
|
-
isDetailsSheet: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const ChatCardThreeColumnLayoutContext = createContext<ChatCardThreeColumnLayoutContextValue>(
|
|
25
|
-
null!,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
function useChatCardThreeColumnLayoutContext(part: string) {
|
|
29
|
-
const context = useContext(ChatCardThreeColumnLayoutContext);
|
|
30
|
-
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
`[web-chat-ui] "${part}" must be used within a ChatCardThreeColumnLayout. ` +
|
|
34
|
-
'It reads its floating state from the layout, so render ' +
|
|
35
|
-
'it as a child of the ChatCardThreeColumnLayout element, not as a sibling of it.',
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return context;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A pane's content, or a function of whether the pane is currently floating.
|
|
44
|
-
*
|
|
45
|
-
* The function form exists because a floating pane usually needs different content, not
|
|
46
|
-
* just different styling: the places card shows a vertical list in the column and a
|
|
47
|
-
* horizontal swipe strip when floating. CSS alone cannot swap the component tree.
|
|
48
|
-
*/
|
|
49
|
-
export type ChatCardThreeColumnLayoutPaneChildren =
|
|
50
|
-
ReactNode | ((isFloating: boolean) => ReactNode);
|
|
51
|
-
|
|
52
|
-
function renderPane(children: ChatCardThreeColumnLayoutPaneChildren, isFloating: boolean) {
|
|
53
|
-
return typeof children === 'function' ? children(isFloating) : children;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface ChatCardThreeColumnLayoutProps extends ComponentProps<'div'> {
|
|
57
|
-
children: ReactNode;
|
|
58
|
-
/**
|
|
59
|
-
* Whether Details may take its own column. See `ChatCardThreeColumnLayoutDetailsPlacement`.
|
|
60
|
-
* It is on the root, not on Details, because the root's grid template has to change
|
|
61
|
-
* with it.
|
|
62
|
-
*/
|
|
63
|
-
detailsPlacement?: ChatCardThreeColumnLayoutDetailsPlacement;
|
|
64
|
-
asChild?: boolean;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Hands one element to the measuring ref and the consumer's forwarded ref alike. */
|
|
68
|
-
function useMergedRef<T>(first: (node: T | null) => void, second: ForwardedRef<T>) {
|
|
69
|
-
return useCallback(
|
|
70
|
-
(node: T | null) => {
|
|
71
|
-
first(node);
|
|
72
|
-
|
|
73
|
-
if (typeof second === 'function') {
|
|
74
|
-
second(node);
|
|
75
|
-
} else if (second) {
|
|
76
|
-
second.current = node;
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
[first, second],
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A three-pane card body: List (fixed column), Main (flexible), Details (floating or a
|
|
85
|
-
* right column).
|
|
86
|
-
*
|
|
87
|
-
* Which panes fit is decided by the layout's **own measured width**, not by viewport
|
|
88
|
-
* breakpoints. The card is sized by the chat window, and a sidebar, a split view or the
|
|
89
|
-
* Storybook panel all make the viewport claim room the card doesn't have (or the
|
|
90
|
-
* reverse). The root measures itself, resolves the panes once (`resolveLayout`), and
|
|
91
|
-
* publishes the result twice: as data attributes for the CSS, and through context for the render props. Both read the same numbers, so the content a
|
|
92
|
-
* render prop picks always matches where its pane is drawn.
|
|
93
|
-
*
|
|
94
|
-
* Height is not set here, because it belongs to the content (a map needs a fixed height, a
|
|
95
|
-
* table might not), so pass it in `className`.
|
|
96
|
-
*/
|
|
97
|
-
export const ChatCardThreeColumnLayout = forwardRef<HTMLDivElement, ChatCardThreeColumnLayoutProps>(
|
|
98
|
-
function ChatCardThreeColumnLayout(
|
|
99
|
-
{ children, className, detailsPlacement = DEFAULT_DETAILS_PLACEMENT, asChild = false, ...rest },
|
|
100
|
-
ref,
|
|
101
|
-
) {
|
|
102
|
-
const { ref: measureRef, width } = useElementMeasure<HTMLDivElement>();
|
|
103
|
-
const mergedRef = useMergedRef(measureRef, ref);
|
|
104
|
-
|
|
105
|
-
const { size, isListFloating, isDetailsFloating, isDetailsSheet } = resolveLayout(
|
|
106
|
-
width,
|
|
107
|
-
detailsPlacement,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const contextValue = useMemo(
|
|
111
|
-
() => ({ isListFloating, isDetailsFloating, isDetailsSheet }),
|
|
112
|
-
[isListFloating, isDetailsFloating, isDetailsSheet],
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const Component = asChild ? Slot : 'div';
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<ChatCardThreeColumnLayoutContext.Provider value={contextValue}>
|
|
119
|
-
<Component
|
|
120
|
-
ref={mergedRef}
|
|
121
|
-
data-testid="chat-card-three-column-layout"
|
|
122
|
-
data-slot="chat-card-three-column-layout"
|
|
123
|
-
data-details-placement={detailsPlacement}
|
|
124
|
-
data-size={size}
|
|
125
|
-
data-list-floating={isListFloating}
|
|
126
|
-
data-details-floating={isDetailsFloating}
|
|
127
|
-
className={cn(chatCardThreeColumnLayoutVariants(), className)}
|
|
128
|
-
{...rest}
|
|
129
|
-
>
|
|
130
|
-
{children}
|
|
131
|
-
</Component>
|
|
132
|
-
</ChatCardThreeColumnLayoutContext.Provider>
|
|
133
|
-
);
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
ChatCardThreeColumnLayout.displayName = 'ChatCardThreeColumnLayout';
|
|
138
|
-
|
|
139
|
-
export interface ChatCardThreeColumnLayoutListProps extends Omit<
|
|
140
|
-
ComponentProps<'aside'>,
|
|
141
|
-
'children'
|
|
142
|
-
> {
|
|
143
|
-
children: ChatCardThreeColumnLayoutPaneChildren;
|
|
144
|
-
asChild?: boolean;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Column 1 when the layout has room for it beside a usable Main; otherwise a strip pinned
|
|
149
|
-
* to the bottom, over Main. It is the same element either way, so only the render prop's
|
|
150
|
-
* output changes when it switches.
|
|
151
|
-
*
|
|
152
|
-
* `data-floating` is set too, for styling the pane itself without a render prop.
|
|
153
|
-
*/
|
|
154
|
-
export const ChatCardThreeColumnLayoutList = forwardRef<
|
|
155
|
-
HTMLDivElement,
|
|
156
|
-
ChatCardThreeColumnLayoutListProps
|
|
157
|
-
>(function ChatCardThreeColumnLayoutList({ children, className, asChild = false, ...rest }, ref) {
|
|
158
|
-
const { isListFloating } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutList');
|
|
159
|
-
|
|
160
|
-
const Component = asChild ? Slot : 'aside';
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<Component
|
|
164
|
-
ref={ref}
|
|
165
|
-
data-testid="chat-card-three-column-layout-list"
|
|
166
|
-
data-slot="chat-card-three-column-layout-list"
|
|
167
|
-
data-floating={isListFloating}
|
|
168
|
-
className={cn(chatCardThreeColumnLayoutListVariants(), className)}
|
|
169
|
-
{...rest}
|
|
170
|
-
>
|
|
171
|
-
{renderPane(children, isListFloating)}
|
|
172
|
-
</Component>
|
|
173
|
-
);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
ChatCardThreeColumnLayoutList.displayName = 'ChatCardThreeColumnLayoutList';
|
|
177
|
-
|
|
178
|
-
export interface ChatCardThreeColumnLayoutMainProps extends ComponentProps<'main'> {
|
|
179
|
-
children: ReactNode;
|
|
180
|
-
asChild?: boolean;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Column 2, the flexible track. It never floats, so it takes plain children. It still
|
|
185
|
-
* requires the layout, because outside the grid its `[grid-area:main]` means nothing and
|
|
186
|
-
* the pane collapses without any error.
|
|
187
|
-
*/
|
|
188
|
-
export const ChatCardThreeColumnLayoutMain = forwardRef<
|
|
189
|
-
HTMLDivElement,
|
|
190
|
-
ChatCardThreeColumnLayoutMainProps
|
|
191
|
-
>(function ChatCardThreeColumnLayoutMain({ children, className, asChild = false, ...rest }, ref) {
|
|
192
|
-
useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutMain');
|
|
193
|
-
|
|
194
|
-
const Component = asChild ? Slot : 'main';
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
<Component
|
|
198
|
-
ref={ref}
|
|
199
|
-
data-testid="chat-card-three-column-layout-main"
|
|
200
|
-
data-slot="chat-card-three-column-layout-main"
|
|
201
|
-
className={cn(chatCardThreeColumnLayoutMainVariants(), className)}
|
|
202
|
-
{...rest}
|
|
203
|
-
>
|
|
204
|
-
{children}
|
|
205
|
-
</Component>
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
ChatCardThreeColumnLayoutMain.displayName = 'ChatCardThreeColumnLayoutMain';
|
|
210
|
-
|
|
211
|
-
export interface ChatCardThreeColumnLayoutDetailsProps extends Omit<
|
|
212
|
-
ComponentProps<'aside'>,
|
|
213
|
-
'children'
|
|
214
|
-
> {
|
|
215
|
-
children: ChatCardThreeColumnLayoutPaneChildren;
|
|
216
|
-
asChild?: boolean;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Column 3. Mount it only while there is something to show: its presence is what adds the
|
|
221
|
-
* third grid track, so rendering it empty would reserve a blank column.
|
|
222
|
-
*
|
|
223
|
-
* It takes a column when the layout is wide enough and `detailsPlacement` allows it, and
|
|
224
|
-
* floats over Main otherwise: pinned to Main's right edge, or a bottom sheet on a narrow
|
|
225
|
-
* layout (`data-sheet`). `isFloating` in the render prop reflects all of that.
|
|
226
|
-
*/
|
|
227
|
-
export const ChatCardThreeColumnLayoutDetails = forwardRef<
|
|
228
|
-
HTMLDivElement,
|
|
229
|
-
ChatCardThreeColumnLayoutDetailsProps
|
|
230
|
-
>(function ChatCardThreeColumnLayoutDetails(
|
|
231
|
-
{ children, className, asChild = false, ...rest },
|
|
232
|
-
ref,
|
|
233
|
-
) {
|
|
234
|
-
const { isDetailsFloating, isDetailsSheet } = useChatCardThreeColumnLayoutContext(
|
|
235
|
-
'ChatCardThreeColumnLayoutDetails',
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
const Component = asChild ? Slot : 'aside';
|
|
239
|
-
|
|
240
|
-
return (
|
|
241
|
-
<Component
|
|
242
|
-
ref={ref}
|
|
243
|
-
data-testid="chat-card-three-column-layout-details"
|
|
244
|
-
data-slot="chat-card-three-column-layout-details"
|
|
245
|
-
data-floating={isDetailsFloating}
|
|
246
|
-
data-sheet={isDetailsSheet}
|
|
247
|
-
className={cn(chatCardThreeColumnLayoutDetailsVariants(), className)}
|
|
248
|
-
{...rest}
|
|
249
|
-
>
|
|
250
|
-
{renderPane(children, isDetailsFloating)}
|
|
251
|
-
</Component>
|
|
252
|
-
);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
ChatCardThreeColumnLayoutDetails.displayName = 'ChatCardThreeColumnLayoutDetails';
|
|
256
|
-
|
|
257
|
-
export interface ChatCardThreeColumnLayoutPanelProps extends ComponentProps<'section'> {
|
|
258
|
-
children: ReactNode;
|
|
259
|
-
asChild?: boolean;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* An overlay covering everything but the List column (the whole layout when List floats),
|
|
264
|
-
* inset 12px. Mount it only while it is open. Main and Details stay mounted under it, so
|
|
265
|
-
* a map keeps its viewport and the open Details item survives closing the Panel.
|
|
266
|
-
*
|
|
267
|
-
* The pane is transparent: draw the surface (background, radius, shadow) in its content,
|
|
268
|
-
* as for Details.
|
|
269
|
-
*/
|
|
270
|
-
export const ChatCardThreeColumnLayoutPanel = forwardRef<
|
|
271
|
-
HTMLElement,
|
|
272
|
-
ChatCardThreeColumnLayoutPanelProps
|
|
273
|
-
>(function ChatCardThreeColumnLayoutPanel({ children, className, asChild = false, ...rest }, ref) {
|
|
274
|
-
const { isListFloating } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutPanel');
|
|
275
|
-
const Component = asChild ? Slot : 'section';
|
|
276
|
-
|
|
277
|
-
return (
|
|
278
|
-
<Component
|
|
279
|
-
ref={ref}
|
|
280
|
-
data-testid="chat-card-three-column-layout-panel"
|
|
281
|
-
data-slot="chat-card-three-column-layout-panel"
|
|
282
|
-
data-list-floating={isListFloating}
|
|
283
|
-
className={cn(chatCardThreeColumnLayoutPanelVariants(), className)}
|
|
284
|
-
{...rest}
|
|
285
|
-
>
|
|
286
|
-
{children}
|
|
287
|
-
</Component>
|
|
288
|
-
);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
ChatCardThreeColumnLayoutPanel.displayName = 'ChatCardThreeColumnLayoutPanel';
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { cva } from 'class-variance-authority';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Whether Details may take its own right column.
|
|
5
|
-
*
|
|
6
|
-
* - `responsive` — a column whenever the layout is wide enough for List, Details and a
|
|
7
|
-
* usable Main side by side; floating over Main otherwise.
|
|
8
|
-
* - `floating` — always over Main, for a pane that is secondary at every size.
|
|
9
|
-
*
|
|
10
|
-
* There is no "always a column": at widths where it would not fit, Main would be squeezed
|
|
11
|
-
* below usefulness, which is exactly what the width check exists to prevent.
|
|
12
|
-
*/
|
|
13
|
-
export type ChatCardThreeColumnLayoutDetailsPlacement = 'responsive' | 'floating';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `responsive` because it uses the room when it is there: `floating` would cover Main on
|
|
17
|
-
* a card with space to spare.
|
|
18
|
-
*/
|
|
19
|
-
export const DEFAULT_DETAILS_PLACEMENT: ChatCardThreeColumnLayoutDetailsPlacement = 'responsive';
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Every recipe below keys on data attributes the components set from the layout's measured
|
|
23
|
-
* width (`data-size`, `data-list-floating`, `data-details-floating` on the root;
|
|
24
|
-
* `data-floating`, `data-sheet` on each pane). `290px` and `358px` are `LIST_WIDTH_LG` and
|
|
25
|
-
* `PANE_WIDTH_XL` from `chat-card-three-column-layout.sizing.ts`, written out because
|
|
26
|
-
* Tailwind cannot read a constant. Change both together.
|
|
27
|
-
*
|
|
28
|
-
* The tiers are the original card's `md` / `lg` / `xl`, but none of the recipes uses viewport
|
|
29
|
-
* breakpoints: the card is sized by the chat window, not the viewport, so `lg:` / `xl:`
|
|
30
|
-
* would switch panes at the wrong widths.
|
|
31
|
-
*
|
|
32
|
-
* Using a recipe without its component means setting those attributes yourself.
|
|
33
|
-
*
|
|
34
|
-
* Class strings are written out in full because Tailwind finds classes by scanning source;
|
|
35
|
-
* a class assembled from a constant is never generated.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Root grid.
|
|
40
|
-
*
|
|
41
|
-
* The third track needs both "Details fits" (`data-details-floating=false`, from the
|
|
42
|
-
* width) and "Details is mounted" (`:has(> [data-slot=…-details])`). The second is CSS, not
|
|
43
|
-
* a prop, because consumers mount Details conditionally and a `hasDetails` prop could
|
|
44
|
-
* disagree with what is rendered.
|
|
45
|
-
*/
|
|
46
|
-
export const chatCardThreeColumnLayoutVariants = cva([
|
|
47
|
-
'relative grid gap-[8px]',
|
|
48
|
-
// sm + md — Main only; List floats as a strip and Details floats over Main
|
|
49
|
-
"grid-cols-[1fr] [grid-template-areas:'main']",
|
|
50
|
-
"data-[size=lg]:grid-cols-[290px_1fr] data-[size=lg]:[grid-template-areas:'list_main']",
|
|
51
|
-
"data-[size=xl]:grid-cols-[358px_1fr] data-[size=xl]:[grid-template-areas:'list_main']",
|
|
52
|
-
// xl with a mounted Details that is allowed a column
|
|
53
|
-
'data-[details-floating=false]:has-[>[data-slot=chat-card-three-column-layout-details]]:grid-cols-[358px_1fr_358px]',
|
|
54
|
-
"data-[details-floating=false]:has-[>[data-slot=chat-card-three-column-layout-details]]:[grid-template-areas:'list_main_details']",
|
|
55
|
-
]);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Column 1, or, when there is no room for it, a strip pinned to the bottom of the layout
|
|
59
|
-
* over Main. One element for both, so the pane never remounts when it switches; only what
|
|
60
|
-
* the consumer's render prop returns changes.
|
|
61
|
-
*
|
|
62
|
-
* Floating is `absolute` rather than a grid row so Main keeps the full height. In the
|
|
63
|
-
* column, `min-h-0` + `overflow-hidden` keep a long list inside the row. Without them the
|
|
64
|
-
* grid item grows to its content and the card gets taller instead of scrolling.
|
|
65
|
-
*/
|
|
66
|
-
export const chatCardThreeColumnLayoutListVariants = cva([
|
|
67
|
-
'min-w-0',
|
|
68
|
-
'data-[floating=true]:absolute data-[floating=true]:bottom-0 data-[floating=true]:inset-x-0 data-[floating=true]:z-10',
|
|
69
|
-
'data-[floating=false]:[grid-area:list] data-[floating=false]:min-h-0 data-[floating=false]:h-full data-[floating=false]:overflow-hidden',
|
|
70
|
-
]);
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Column 2, the flexible `1fr` track. `min-w-0` because a grid item's minimum width is its
|
|
74
|
-
* content by default: a map or a wide table would push the track past the card. `relative`
|
|
75
|
-
* so the consumer can anchor their own overlays to Main.
|
|
76
|
-
*/
|
|
77
|
-
export const chatCardThreeColumnLayoutMainVariants = cva([
|
|
78
|
-
'[grid-area:main] relative min-w-0 min-h-0 h-full',
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Column 3, or floating over Main. Floating shares Main's grid area instead of being
|
|
83
|
-
* `absolute`, so it is sized by the same track Main is.
|
|
84
|
-
*
|
|
85
|
-
* - pinned: the right edge of Main, at the same width the column would have, inset 12px
|
|
86
|
-
* - sheet: on a narrow layout, a bottom sheet at a fixed 85% height, so the pane does not
|
|
87
|
-
* change height as its content changes (the content scrolls instead)
|
|
88
|
-
*
|
|
89
|
-
* `z-20` keeps a floating Details above the floating List (`z-10`): an open Details is
|
|
90
|
-
* what the reader asked for last. `min-w-0` + `max-w-full` stop the fixed width from
|
|
91
|
-
* widening the `1fr` track past the card.
|
|
92
|
-
*/
|
|
93
|
-
export const chatCardThreeColumnLayoutDetailsVariants = cva([
|
|
94
|
-
'min-h-0 min-w-0 max-w-full',
|
|
95
|
-
'data-[floating=false]:[grid-area:details] data-[floating=false]:h-full',
|
|
96
|
-
'data-[floating=true]:z-20 data-[floating=true]:[grid-area:main]',
|
|
97
|
-
'data-[floating=true]:data-[sheet=false]:w-[358px] data-[floating=true]:data-[sheet=false]:h-full data-[floating=true]:data-[sheet=false]:justify-self-end data-[floating=true]:data-[sheet=false]:self-stretch data-[floating=true]:data-[sheet=false]:p-[12px]',
|
|
98
|
-
'data-[sheet=true]:w-full data-[sheet=true]:h-[85%] data-[sheet=true]:justify-self-start data-[sheet=true]:self-end',
|
|
99
|
-
]);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* An overlay over everything but the List column, inset 12px, for a view that takes over the
|
|
103
|
-
* card (all reviews, a filter form) while Main and Details stay mounted underneath.
|
|
104
|
-
*
|
|
105
|
-
* It spans columns in row 1 instead of being `absolute`, so it follows the grid template:
|
|
106
|
-
* from column 2 to the last one when List is a column, all of them when List floats. It
|
|
107
|
-
* never adds a track, so mounting it doesn't move Main. `z-30` keeps it above floating
|
|
108
|
-
* Details (`z-20`) and the List strip (`z-10`).
|
|
109
|
-
*/
|
|
110
|
-
export const chatCardThreeColumnLayoutPanelVariants = cva([
|
|
111
|
-
'relative z-30 min-w-0 min-h-0 h-full p-[12px] row-1',
|
|
112
|
-
'data-[list-floating=false]:col-[2/-1]',
|
|
113
|
-
'data-[list-floating=true]:col-span-full',
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Width recipe for the `ChatCard` that wraps the layout.
|
|
118
|
-
*
|
|
119
|
-
* A grid of `1fr` tracks has no intrinsic width, so inside a shrink-to-fit message the card
|
|
120
|
-
* would collapse to nothing. It takes the whole chat window instead, minus the message
|
|
121
|
-
* gutter on both sides, up to 1432px (four 358px columns). The layout then decides which
|
|
122
|
-
* panes fit in whatever width that gives it. `ChatContainer` sets both variables.
|
|
123
|
-
*
|
|
124
|
-
* One cap, not a ladder of viewport steps: a step like `lg:min-w-[1074px]` held the card
|
|
125
|
-
* narrower than the chat window between breakpoints, and Details floated for no reason.
|
|
126
|
-
*
|
|
127
|
-
* Gated on `data-state=open`, which `ChatCard`'s `Collapsible` puts on the card element
|
|
128
|
-
* itself: a collapsed card is only a header, and holding it at full width would leave a
|
|
129
|
-
* wide empty bar in the thread. A non-collapsible card is always `open`.
|
|
130
|
-
*/
|
|
131
|
-
export const chatCardThreeColumnLayoutCardVariants = cva([
|
|
132
|
-
'data-[state=open]:w-(--message-list-content-width) data-[state=open]:mx-0',
|
|
133
|
-
// `100%` fallback, like every other read of the variable, for a card outside `ChatContainer`
|
|
134
|
-
'data-[state=open]:min-w-[min(1432px,calc(var(--chat-window-width,100%)-var(--spacing-message)*2))]',
|
|
135
|
-
]);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
ChatCardThreeColumnLayout,
|
|
3
|
-
ChatCardThreeColumnLayoutList,
|
|
4
|
-
ChatCardThreeColumnLayoutMain,
|
|
5
|
-
ChatCardThreeColumnLayoutDetails,
|
|
6
|
-
ChatCardThreeColumnLayoutPanel,
|
|
7
|
-
} from './chat-card-three-column-layout';
|
|
8
|
-
export type {
|
|
9
|
-
ChatCardThreeColumnLayoutProps,
|
|
10
|
-
ChatCardThreeColumnLayoutListProps,
|
|
11
|
-
ChatCardThreeColumnLayoutMainProps,
|
|
12
|
-
ChatCardThreeColumnLayoutDetailsProps,
|
|
13
|
-
ChatCardThreeColumnLayoutPanelProps,
|
|
14
|
-
ChatCardThreeColumnLayoutPaneChildren,
|
|
15
|
-
} from './chat-card-three-column-layout';
|
|
16
|
-
export {
|
|
17
|
-
chatCardThreeColumnLayoutVariants,
|
|
18
|
-
chatCardThreeColumnLayoutListVariants,
|
|
19
|
-
chatCardThreeColumnLayoutMainVariants,
|
|
20
|
-
chatCardThreeColumnLayoutDetailsVariants,
|
|
21
|
-
chatCardThreeColumnLayoutPanelVariants,
|
|
22
|
-
chatCardThreeColumnLayoutCardVariants,
|
|
23
|
-
} from './chat-card-three-column-layout.variants';
|
|
24
|
-
export type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { LocationIcon, TrainIcon, TramIcon, WalkIcon } from '@swisper.ai/icons';
|
|
2
|
-
import {
|
|
3
|
-
Timeline,
|
|
4
|
-
TimelineItem,
|
|
5
|
-
TimelineItemContent,
|
|
6
|
-
TimelineItemIcon,
|
|
7
|
-
TimelineItemTimestamp,
|
|
8
|
-
Typography,
|
|
9
|
-
} from '@swisper.ai/ui';
|
|
10
|
-
|
|
11
|
-
import { LEG_LABELS } from './fixtures';
|
|
12
|
-
import type { ItineraryStep } from './types';
|
|
13
|
-
|
|
14
|
-
function StepIcon({ step }: { step: ItineraryStep }) {
|
|
15
|
-
if (step.legType === 'arrival') return <LocationIcon fontSize="inherit" aria-hidden />;
|
|
16
|
-
if (step.legType === 'tram') return <TramIcon fontSize="inherit" aria-hidden />;
|
|
17
|
-
if (step.legType === 'train') return <TrainIcon fontSize="inherit" aria-hidden />;
|
|
18
|
-
return <WalkIcon fontSize="inherit" aria-hidden />;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ConnectionItineraryProps {
|
|
22
|
-
steps: ItineraryStep[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** The steps of a connection as a timeline: what the travel card puts in the Aside column. */
|
|
26
|
-
export function ConnectionItinerary({ steps }: ConnectionItineraryProps) {
|
|
27
|
-
return (
|
|
28
|
-
<Timeline className="w-full">
|
|
29
|
-
{steps.map((step) => (
|
|
30
|
-
<TimelineItem key={`${step.time}-${step.legType}`}>
|
|
31
|
-
<TimelineItemTimestamp className="tabular-nums">
|
|
32
|
-
<time dateTime={step.time}>{step.displayTime}</time>
|
|
33
|
-
</TimelineItemTimestamp>
|
|
34
|
-
<TimelineItemIcon wrapperClassName="text-base">
|
|
35
|
-
<StepIcon step={step} />
|
|
36
|
-
</TimelineItemIcon>
|
|
37
|
-
<TimelineItemContent className="flex min-w-0 flex-col gap-4">
|
|
38
|
-
<Typography variant="body-medium" fontWeight="bold">
|
|
39
|
-
{step.name ?? LEG_LABELS[step.legType]}
|
|
40
|
-
</Typography>
|
|
41
|
-
{step.detail && (
|
|
42
|
-
<Typography variant="caption-md" className="text-text-secondary">
|
|
43
|
-
{step.detail}
|
|
44
|
-
</Typography>
|
|
45
|
-
)}
|
|
46
|
-
</TimelineItemContent>
|
|
47
|
-
</TimelineItem>
|
|
48
|
-
))}
|
|
49
|
-
</Timeline>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { ItineraryLegType, ItineraryStep } from './types';
|
|
2
|
-
|
|
3
|
-
export const LEG_LABELS: Record<ItineraryLegType, string> = {
|
|
4
|
-
walk: 'Walk',
|
|
5
|
-
tram: 'Departure',
|
|
6
|
-
train: 'Departure',
|
|
7
|
-
transfer: 'Transfer',
|
|
8
|
-
arrival: 'Arrival',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// Station to station with one change of mode: a tram into town, a transfer, then the train.
|
|
12
|
-
// Short enough to fit beside the map without scrolling. The transfer has no name.
|
|
13
|
-
export const ZURICH_TO_LUGANO: ItineraryStep[] = [
|
|
14
|
-
{
|
|
15
|
-
time: '2026-04-14T12:10:00+02:00',
|
|
16
|
-
displayTime: '12:10',
|
|
17
|
-
name: 'Zürich, Höschgasse',
|
|
18
|
-
legType: 'tram',
|
|
19
|
-
detail: 'T 11 to Zürich, Bahnhofstrasse/HB · 14 min',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
time: '2026-04-14T12:25:00+02:00',
|
|
23
|
-
displayTime: '12:25',
|
|
24
|
-
name: null,
|
|
25
|
-
legType: 'transfer',
|
|
26
|
-
detail: '7 min',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
time: '2026-04-14T12:33:00+02:00',
|
|
30
|
-
displayTime: '12:33',
|
|
31
|
-
name: 'Zürich HB',
|
|
32
|
-
legType: 'train',
|
|
33
|
-
detail: 'EC 151 to Milano Centrale · 1 h 55 min · Platform 9',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
time: '2026-04-14T14:28:00+02:00',
|
|
37
|
-
displayTime: '14:28',
|
|
38
|
-
name: 'Lugano',
|
|
39
|
-
legType: 'arrival',
|
|
40
|
-
detail: 'Platform 2',
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
// The same trip door to door: nine steps, longer than the card is tall, so the column has to
|
|
45
|
-
// scroll. The first and last names are full addresses, the longest text the column gets.
|
|
46
|
-
export const ZURICH_TO_PARADISO_DOOR_TO_DOOR: ItineraryStep[] = [
|
|
47
|
-
{
|
|
48
|
-
time: '2026-04-14T12:02:00+02:00',
|
|
49
|
-
displayTime: '12:02',
|
|
50
|
-
name: '8008 Zürich, Feldeggstrasse 58',
|
|
51
|
-
legType: 'walk',
|
|
52
|
-
detail: '8 min',
|
|
53
|
-
},
|
|
54
|
-
...ZURICH_TO_LUGANO.slice(0, 3),
|
|
55
|
-
{
|
|
56
|
-
time: '2026-04-14T14:28:00+02:00',
|
|
57
|
-
displayTime: '14:28',
|
|
58
|
-
name: null,
|
|
59
|
-
legType: 'transfer',
|
|
60
|
-
detail: '9 min',
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
time: '2026-04-14T14:37:00+02:00',
|
|
64
|
-
displayTime: '14:37',
|
|
65
|
-
name: 'Lugano',
|
|
66
|
-
legType: 'train',
|
|
67
|
-
detail: 'S 10 to Chiasso · 3 min · Platform 3',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
time: '2026-04-14T14:40:00+02:00',
|
|
71
|
-
displayTime: '14:40',
|
|
72
|
-
name: 'Lugano-Paradiso',
|
|
73
|
-
legType: 'walk',
|
|
74
|
-
detail: '6 min',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
time: '2026-04-14T14:46:00+02:00',
|
|
78
|
-
displayTime: '14:46',
|
|
79
|
-
name: '6900 Paradiso, Riva Paradiso 14, lakeside entrance',
|
|
80
|
-
legType: 'arrival',
|
|
81
|
-
detail: null,
|
|
82
|
-
},
|
|
83
|
-
];
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Typography } from '@swisper.ai/ui';
|
|
2
|
-
|
|
3
|
-
export interface RouteMapProps {
|
|
4
|
-
/** What the map shows, read out in place of the canvas. */
|
|
5
|
-
label: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Stands in for `MapView` from `@swisper.ai/web-map`, which this package does not depend on.
|
|
10
|
-
* Like a map it has no height of its own and fills whatever Main gives it.
|
|
11
|
-
*/
|
|
12
|
-
export function RouteMap({ label }: RouteMapProps) {
|
|
13
|
-
return (
|
|
14
|
-
<div
|
|
15
|
-
role="img"
|
|
16
|
-
aria-label={label}
|
|
17
|
-
className="flex size-full items-center justify-center rounded-10 border border-card-border-base bg-card-background-lvl-2"
|
|
18
|
-
>
|
|
19
|
-
<Typography variant="caption-md" className="text-text-tertiary">
|
|
20
|
-
Map
|
|
21
|
-
</Typography>
|
|
22
|
-
</div>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** How one step of a connection is travelled: a walk, a tram or train leg, a transfer, or the arrival. */
|
|
2
|
-
export type ItineraryLegType = 'walk' | 'tram' | 'train' | 'transfer' | 'arrival';
|
|
3
|
-
|
|
4
|
-
/** One row of a connection's itinerary, trimmed to what the card shows. */
|
|
5
|
-
export interface ItineraryStep {
|
|
6
|
-
/** ISO departure (arrival, for the last step), for `<time dateTime>`. */
|
|
7
|
-
time: string;
|
|
8
|
-
/** The same time as the card shows it. */
|
|
9
|
-
displayTime: string;
|
|
10
|
-
/** Where the step starts. `null` for a transfer, which falls back to its leg label. */
|
|
11
|
-
name: string | null;
|
|
12
|
-
legType: ItineraryLegType;
|
|
13
|
-
/** Line, direction, duration and platform on one line. `null` when the step has none. */
|
|
14
|
-
detail: string | null;
|
|
15
|
-
}
|