@swisper.ai/web-chat-ui 0.1.0 → 0.2.1

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.
Files changed (83) hide show
  1. package/README.md +2 -5
  2. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  3. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  4. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  5. package/dist/components/rich-text-field/utils.d.ts +36 -36
  6. package/dist/index.css +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.es.js +1566 -1810
  10. package/dist/index.es.js.map +1 -1
  11. package/package.json +4 -4
  12. package/src/components/chat-card/chat-card.json +6 -6
  13. package/src/components/chat-card/chat-card.stories.tsx +6 -14
  14. package/src/components/chat-card/components/chat-card-body.tsx +1 -1
  15. package/src/components/chat-card-container/chat-card-container.json +6 -6
  16. package/src/components/chat-card-container/chat-card-container.stories.tsx +10 -18
  17. package/src/components/chat-container/chat-container.json +1 -1
  18. package/src/components/chat-list/chat-list-items.tsx +3 -3
  19. package/src/components/rich-text-field/rich-text-field.stories.tsx +3 -1
  20. package/src/index.ts +0 -1
  21. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +0 -97
  22. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +0 -1
  23. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +0 -52
  24. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +0 -1
  25. package/dist/layouts/chat-card-list-layout/index.d.ts +0 -3
  26. package/dist/layouts/chat-card-list-layout/index.d.ts.map +0 -1
  27. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +0 -89
  28. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +0 -1
  29. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -44
  30. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +0 -1
  31. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +0 -62
  32. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +0 -1
  33. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +0 -81
  34. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +0 -1
  35. package/dist/layouts/chat-card-three-column-layout/index.d.ts +0 -5
  36. package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +0 -1
  37. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +0 -37
  38. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +0 -1
  39. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +0 -12
  40. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +0 -1
  41. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +0 -40
  42. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +0 -1
  43. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +0 -35
  44. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +0 -1
  45. package/dist/layouts/chat-card-two-column-layout/index.d.ts +0 -4
  46. package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +0 -1
  47. package/dist/layouts/index.d.ts +0 -4
  48. package/dist/layouts/index.d.ts.map +0 -1
  49. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +0 -112
  50. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +0 -36
  51. package/src/layouts/chat-card-list-layout/__stories__/types.ts +0 -31
  52. package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +0 -204
  53. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +0 -129
  54. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +0 -422
  55. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +0 -254
  56. package/src/layouts/chat-card-list-layout/index.ts +0 -11
  57. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +0 -117
  58. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +0 -18
  59. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +0 -85
  60. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +0 -47
  61. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +0 -44
  62. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +0 -61
  63. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +0 -35
  64. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +0 -71
  65. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +0 -327
  66. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +0 -153
  67. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -76
  68. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +0 -658
  69. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +0 -293
  70. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +0 -146
  71. package/src/layouts/chat-card-three-column-layout/index.ts +0 -24
  72. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +0 -51
  73. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +0 -83
  74. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +0 -24
  75. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +0 -15
  76. package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +0 -109
  77. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +0 -109
  78. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +0 -21
  79. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +0 -439
  80. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +0 -141
  81. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +0 -65
  82. package/src/layouts/chat-card-two-column-layout/index.ts +0 -17
  83. package/src/layouts/index.ts +0 -3
@@ -1,293 +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 type { ChatCardThreeColumnLayoutSize } from './chat-card-three-column-layout.sizing';
9
- import {
10
- DEFAULT_DETAILS_PLACEMENT,
11
- chatCardThreeColumnLayoutDetailsVariants,
12
- chatCardThreeColumnLayoutListVariants,
13
- chatCardThreeColumnLayoutMainVariants,
14
- chatCardThreeColumnLayoutPanelVariants,
15
- chatCardThreeColumnLayoutVariants,
16
- } from './chat-card-three-column-layout.variants';
17
- import type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
18
-
19
- interface ChatCardThreeColumnLayoutContextValue {
20
- size: ChatCardThreeColumnLayoutSize;
21
- isDetailsFloating: boolean;
22
- isDetailsSheet: boolean;
23
- }
24
-
25
- const ChatCardThreeColumnLayoutContext = createContext<ChatCardThreeColumnLayoutContextValue>(
26
- null!,
27
- );
28
-
29
- function useChatCardThreeColumnLayoutContext(part: string) {
30
- const context = useContext(ChatCardThreeColumnLayoutContext);
31
-
32
- if (!context) {
33
- throw new Error(
34
- `[web-chat-ui] "${part}" must be used within a ChatCardThreeColumnLayout. ` +
35
- 'It reads its placement from the layout, so render ' +
36
- 'it as a child of the ChatCardThreeColumnLayout element, not as a sibling of it.',
37
- );
38
- }
39
-
40
- return context;
41
- }
42
-
43
- /**
44
- * The Details pane's content, or a function of whether the pane is currently floating.
45
- *
46
- * The function form exists because a floating pane can need different content, not just
47
- * different styling: a surface with a shadow over Main, a flat one in the column. CSS alone
48
- * cannot swap the component tree.
49
- */
50
- export type ChatCardThreeColumnLayoutPaneChildren =
51
- ReactNode | ((isFloating: boolean) => ReactNode);
52
-
53
- function renderPane(children: ChatCardThreeColumnLayoutPaneChildren, isFloating: boolean) {
54
- return typeof children === 'function' ? children(isFloating) : children;
55
- }
56
-
57
- export interface ChatCardThreeColumnLayoutProps extends ComponentProps<'div'> {
58
- children: ReactNode;
59
- /**
60
- * Whether Details may take its own column. See `ChatCardThreeColumnLayoutDetailsPlacement`.
61
- * It is on the root, not on Details, because the root's grid template has to change
62
- * with it.
63
- */
64
- detailsPlacement?: ChatCardThreeColumnLayoutDetailsPlacement;
65
- asChild?: boolean;
66
- }
67
-
68
- /** Hands one element to the measuring ref and the consumer's forwarded ref alike. */
69
- function useMergedRef<T>(first: (node: T | null) => void, second: ForwardedRef<T>) {
70
- return useCallback(
71
- (node: T | null) => {
72
- first(node);
73
-
74
- if (typeof second === 'function') {
75
- second(node);
76
- } else if (second) {
77
- second.current = node;
78
- }
79
- },
80
- [first, second],
81
- );
82
- }
83
-
84
- /**
85
- * A three-pane card body: List (fixed column), Main (flexible), Details (floating or a
86
- * right column).
87
- *
88
- * Which panes fit is decided by the layout's **own measured width**, not by viewport
89
- * breakpoints. The card is sized by the chat window, and a sidebar, a split view or the
90
- * Storybook panel all make the viewport claim room the card doesn't have (or the
91
- * reverse). The root measures itself, resolves the panes once (`resolveLayout`), and
92
- * publishes the result twice: as data attributes for the CSS, and through context for
93
- * Details' render prop. Both read the same numbers, so the content the render prop picks
94
- * always matches where the pane is drawn.
95
- *
96
- * Height is not set here, because it belongs to the content (a map needs a fixed height, a
97
- * table might not), so pass it in `className`.
98
- */
99
- export const ChatCardThreeColumnLayout = forwardRef<HTMLDivElement, ChatCardThreeColumnLayoutProps>(
100
- function ChatCardThreeColumnLayout(
101
- { children, className, detailsPlacement = DEFAULT_DETAILS_PLACEMENT, asChild = false, ...rest },
102
- ref,
103
- ) {
104
- const { ref: measureRef, width } = useElementMeasure<HTMLDivElement>();
105
- const mergedRef = useMergedRef(measureRef, ref);
106
-
107
- const { size, isDetailsFloating, isDetailsSheet } = resolveLayout(width, detailsPlacement);
108
-
109
- const contextValue = useMemo(
110
- () => ({ size, isDetailsFloating, isDetailsSheet }),
111
- [size, isDetailsFloating, isDetailsSheet],
112
- );
113
-
114
- const Component = asChild ? Slot : 'div';
115
-
116
- return (
117
- <ChatCardThreeColumnLayoutContext.Provider value={contextValue}>
118
- <Component
119
- ref={mergedRef}
120
- data-testid="chat-card-three-column-layout"
121
- data-slot="chat-card-three-column-layout"
122
- data-details-placement={detailsPlacement}
123
- data-size={size}
124
- data-details-floating={isDetailsFloating}
125
- className={cn(chatCardThreeColumnLayoutVariants(), className)}
126
- {...rest}
127
- >
128
- {children}
129
- </Component>
130
- </ChatCardThreeColumnLayoutContext.Provider>
131
- );
132
- },
133
- );
134
-
135
- ChatCardThreeColumnLayout.displayName = 'ChatCardThreeColumnLayout';
136
-
137
- export interface ChatCardThreeColumnLayoutListProps extends ComponentProps<'aside'> {
138
- children: ReactNode;
139
- /**
140
- * Hides the pane while the layout is too narrow for the List column (`sm` and `md`). It
141
- * stays mounted, so its state is still there when the column comes back.
142
- */
143
- hideOnMobile?: boolean;
144
- asChild?: boolean;
145
- }
146
-
147
- /**
148
- * Column 1 when the layout has room for it beside a usable Main (`lg` and `xl`). Below that
149
- * the layout does not place it: pass `hideOnMobile` to hide it there.
150
- *
151
- * `data-size` is set too, for styling the pane by the layout's tier.
152
- */
153
- export const ChatCardThreeColumnLayoutList = forwardRef<
154
- HTMLDivElement,
155
- ChatCardThreeColumnLayoutListProps
156
- >(function ChatCardThreeColumnLayoutList(
157
- { children, className, hideOnMobile = false, asChild = false, ...rest },
158
- ref,
159
- ) {
160
- const { size } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutList');
161
-
162
- const Component = asChild ? Slot : 'aside';
163
-
164
- return (
165
- <Component
166
- ref={ref}
167
- data-testid="chat-card-three-column-layout-list"
168
- data-slot="chat-card-three-column-layout-list"
169
- data-size={size}
170
- className={cn(chatCardThreeColumnLayoutListVariants({ hideOnMobile }), className)}
171
- {...rest}
172
- >
173
- {children}
174
- </Component>
175
- );
176
- });
177
-
178
- ChatCardThreeColumnLayoutList.displayName = 'ChatCardThreeColumnLayoutList';
179
-
180
- export interface ChatCardThreeColumnLayoutMainProps extends ComponentProps<'main'> {
181
- children: ReactNode;
182
- asChild?: boolean;
183
- }
184
-
185
- /**
186
- * Column 2, the flexible track. It never floats, so it takes plain children. It still
187
- * requires the layout, because outside the grid its `[grid-area:main]` means nothing and
188
- * the pane collapses without any error.
189
- */
190
- export const ChatCardThreeColumnLayoutMain = forwardRef<
191
- HTMLDivElement,
192
- ChatCardThreeColumnLayoutMainProps
193
- >(function ChatCardThreeColumnLayoutMain({ children, className, asChild = false, ...rest }, ref) {
194
- useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutMain');
195
-
196
- const Component = asChild ? Slot : 'main';
197
-
198
- return (
199
- <Component
200
- ref={ref}
201
- data-testid="chat-card-three-column-layout-main"
202
- data-slot="chat-card-three-column-layout-main"
203
- className={cn(chatCardThreeColumnLayoutMainVariants(), className)}
204
- {...rest}
205
- >
206
- {children}
207
- </Component>
208
- );
209
- });
210
-
211
- ChatCardThreeColumnLayoutMain.displayName = 'ChatCardThreeColumnLayoutMain';
212
-
213
- export interface ChatCardThreeColumnLayoutDetailsProps extends Omit<
214
- ComponentProps<'aside'>,
215
- 'children'
216
- > {
217
- children: ChatCardThreeColumnLayoutPaneChildren;
218
- asChild?: boolean;
219
- }
220
-
221
- /**
222
- * Column 3. Mount it only while there is something to show: its presence is what adds the
223
- * third grid track, so rendering it empty would reserve a blank column.
224
- *
225
- * It takes a column when the layout is wide enough and `detailsPlacement` allows it, and
226
- * floats over Main otherwise: pinned to Main's right edge, or a bottom sheet on a narrow
227
- * layout (`data-sheet`). `isFloating` in the render prop reflects all of that.
228
- */
229
- export const ChatCardThreeColumnLayoutDetails = forwardRef<
230
- HTMLDivElement,
231
- ChatCardThreeColumnLayoutDetailsProps
232
- >(function ChatCardThreeColumnLayoutDetails(
233
- { children, className, asChild = false, ...rest },
234
- ref,
235
- ) {
236
- const { isDetailsFloating, isDetailsSheet } = useChatCardThreeColumnLayoutContext(
237
- 'ChatCardThreeColumnLayoutDetails',
238
- );
239
-
240
- const Component = asChild ? Slot : 'aside';
241
-
242
- return (
243
- <Component
244
- ref={ref}
245
- data-testid="chat-card-three-column-layout-details"
246
- data-slot="chat-card-three-column-layout-details"
247
- data-floating={isDetailsFloating}
248
- data-sheet={isDetailsSheet}
249
- className={cn(chatCardThreeColumnLayoutDetailsVariants(), className)}
250
- {...rest}
251
- >
252
- {renderPane(children, isDetailsFloating)}
253
- </Component>
254
- );
255
- });
256
-
257
- ChatCardThreeColumnLayoutDetails.displayName = 'ChatCardThreeColumnLayoutDetails';
258
-
259
- export interface ChatCardThreeColumnLayoutPanelProps extends ComponentProps<'section'> {
260
- children: ReactNode;
261
- asChild?: boolean;
262
- }
263
-
264
- /**
265
- * An overlay covering everything but the List column (the whole layout when there is no
266
- * List column), inset 12px. Mount it only while it is open. Main and Details stay mounted
267
- * under it, so a map keeps its viewport and the open Details item survives closing the Panel.
268
- *
269
- * The pane is transparent: draw the surface (background, radius, shadow) in its content,
270
- * as for Details.
271
- */
272
- export const ChatCardThreeColumnLayoutPanel = forwardRef<
273
- HTMLElement,
274
- ChatCardThreeColumnLayoutPanelProps
275
- >(function ChatCardThreeColumnLayoutPanel({ children, className, asChild = false, ...rest }, ref) {
276
- const { size } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutPanel');
277
- const Component = asChild ? Slot : 'section';
278
-
279
- return (
280
- <Component
281
- ref={ref}
282
- data-testid="chat-card-three-column-layout-panel"
283
- data-slot="chat-card-three-column-layout-panel"
284
- data-size={size}
285
- className={cn(chatCardThreeColumnLayoutPanelVariants(), className)}
286
- {...rest}
287
- >
288
- {children}
289
- </Component>
290
- );
291
- });
292
-
293
- ChatCardThreeColumnLayoutPanel.displayName = 'ChatCardThreeColumnLayoutPanel';
@@ -1,146 +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-details-floating` on the root; `data-size` on List and Panel;
24
- * `data-floating`, `data-sheet` on Details). `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; there is no List column 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 at `lg` and `xl`. Below that the grid has no `list` area, so the column classes
59
- * are keyed on the size: naming a missing area would add a stray track. `hideOnMobile`
60
- * hides the pane at those sizes, without unmounting it.
61
- *
62
- * In the column, `min-h-0` + `overflow-hidden` keep a long list inside the row. Without them
63
- * the grid item grows to its content and the card gets taller instead of scrolling.
64
- */
65
- export const chatCardThreeColumnLayoutListVariants = cva(
66
- [
67
- 'min-w-0',
68
- 'data-[size=lg]:[grid-area:list] data-[size=lg]:min-h-0 data-[size=lg]:h-full data-[size=lg]:overflow-hidden',
69
- 'data-[size=xl]:[grid-area:list] data-[size=xl]:min-h-0 data-[size=xl]:h-full data-[size=xl]:overflow-hidden',
70
- ],
71
- {
72
- variants: {
73
- hideOnMobile: {
74
- true: 'data-[size=sm]:hidden data-[size=md]:hidden',
75
- false: '',
76
- },
77
- },
78
- defaultVariants: {
79
- hideOnMobile: false,
80
- },
81
- },
82
- );
83
-
84
- /**
85
- * Column 2, the flexible `1fr` track. `min-w-0` because a grid item's minimum width is its
86
- * content by default: a map or a wide table would push the track past the card. `relative`
87
- * so the consumer can anchor their own overlays to Main.
88
- */
89
- export const chatCardThreeColumnLayoutMainVariants = cva([
90
- '[grid-area:main] relative min-w-0 min-h-0 h-full',
91
- ]);
92
-
93
- /**
94
- * Column 3, or floating over Main. Floating shares Main's grid area instead of being
95
- * `absolute`, so it is sized by the same track Main is.
96
- *
97
- * - pinned: the right edge of Main, at the same width the column would have, inset 12px
98
- * - sheet: on a narrow layout, a bottom sheet at a fixed 85% height, so the pane does not
99
- * change height as its content changes (the content scrolls instead)
100
- *
101
- * `z-20` keeps a floating Details above Main's own overlays. `min-w-0` + `max-w-full` stop
102
- * the fixed width from widening the `1fr` track past the card.
103
- */
104
- export const chatCardThreeColumnLayoutDetailsVariants = cva([
105
- 'min-h-0 min-w-0 max-w-full',
106
- 'data-[floating=false]:[grid-area:details] data-[floating=false]:h-full',
107
- 'data-[floating=true]:z-20 data-[floating=true]:[grid-area:main]',
108
- '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]',
109
- 'data-[sheet=true]:w-full data-[sheet=true]:h-[85%] data-[sheet=true]:justify-self-start data-[sheet=true]:self-end',
110
- ]);
111
-
112
- /**
113
- * An overlay over everything but the List column, inset 12px, for a view that takes over the
114
- * card (all reviews, a filter form) while Main and Details stay mounted underneath.
115
- *
116
- * It spans columns in row 1 instead of being `absolute`, so it follows the grid template:
117
- * from column 2 to the last one when List is a column (`lg`, `xl`), all of them otherwise.
118
- * It never adds a track, so mounting it doesn't move Main. `z-30` keeps it above floating
119
- * Details (`z-20`).
120
- */
121
- export const chatCardThreeColumnLayoutPanelVariants = cva([
122
- 'relative z-30 min-w-0 min-h-0 h-full p-[12px] row-1',
123
- 'col-span-full',
124
- 'data-[size=lg]:col-[2/-1] data-[size=xl]:col-[2/-1]',
125
- ]);
126
-
127
- /**
128
- * Width recipe for the `ChatCard` that wraps the layout.
129
- *
130
- * A grid of `1fr` tracks has no intrinsic width, so inside a shrink-to-fit message the card
131
- * would collapse to nothing. It takes the whole chat window instead, minus the message
132
- * gutter on both sides, up to 1432px (four 358px columns). The layout then decides which
133
- * panes fit in whatever width that gives it. `ChatContainer` sets both variables.
134
- *
135
- * One cap, not a ladder of viewport steps: a step like `lg:min-w-[1074px]` held the card
136
- * narrower than the chat window between breakpoints, and Details floated for no reason.
137
- *
138
- * Gated on `data-state=open`, which `ChatCard`'s `Collapsible` puts on the card element
139
- * itself: a collapsed card is only a header, and holding it at full width would leave a
140
- * wide empty bar in the thread. A non-collapsible card is always `open`.
141
- */
142
- export const chatCardThreeColumnLayoutCardVariants = cva([
143
- 'data-[state=open]:w-(--message-list-content-width) data-[state=open]:mx-0',
144
- // `100%` fallback, like every other read of the variable, for a card outside `ChatContainer`
145
- 'data-[state=open]:min-w-[min(1432px,calc(var(--chat-window-width,100%)-var(--spacing-message)*2))]',
146
- ]);
@@ -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 `Map` 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
- }