@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,658 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { useId, useState } from 'react';
3
- import type { ReactNode } from 'react';
4
- import { expect, fn, waitFor, within } from 'storybook/test';
5
-
6
- import { HomeIcon } from '@swisper.ai/icons';
7
- import { Typography } from '@swisper.ai/ui';
8
-
9
- import { ParentBlock } from '../../__storybook__/parent-block';
10
- import {
11
- ChatCard,
12
- ChatCardActions,
13
- ChatCardBody,
14
- ChatCardCollapsibleButton,
15
- ChatCardContent,
16
- ChatCardFooter,
17
- ChatCardFooterNotes,
18
- ChatCardHeader,
19
- ChatCardHeaderContent,
20
- ChatCardIcon,
21
- ChatCardSubTitle,
22
- ChatCardTitle,
23
- } from '../../components/chat-card';
24
- import { ChatCardContainer } from '../../components/chat-card-container';
25
- import { ChatContainer } from '../../components/chat-container';
26
- import { ChatMessage, ChatMessageContent } from '../../components/chat-message';
27
-
28
- import { FEATURED_STAY, ROOM_RATES, STAYS } from './__stories__/fixtures';
29
- import { ResizableChatWindow } from './__stories__/resizable-chat-window';
30
- import { StayDetails } from './__stories__/stay-details';
31
- import { StayList } from './__stories__/stay-list';
32
- import { StayMap } from './__stories__/stay-map';
33
- import { StayRooms } from './__stories__/stay-rooms';
34
- import type { Stay } from './__stories__/types';
35
- import {
36
- ChatCardThreeColumnLayout,
37
- ChatCardThreeColumnLayoutDetails,
38
- ChatCardThreeColumnLayoutList,
39
- ChatCardThreeColumnLayoutMain,
40
- ChatCardThreeColumnLayoutPanel,
41
- } from './chat-card-three-column-layout';
42
- import type { ChatCardThreeColumnLayoutProps } from './chat-card-three-column-layout';
43
- import { chatCardThreeColumnLayoutCardVariants } from './chat-card-three-column-layout.variants';
44
- import type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
45
-
46
- const meta: Meta<typeof ChatCardThreeColumnLayout> = {
47
- title: 'Chat/ChatCardThreeColumnLayout',
48
- component: ChatCardThreeColumnLayout,
49
- tags: ['autodocs'],
50
- parameters: { layout: 'fullscreen' },
51
- decorators: [
52
- (Story) => (
53
- <div className="py-16">
54
- <Story />
55
- </div>
56
- ),
57
- ],
58
- argTypes: {
59
- detailsPlacement: {
60
- control: 'inline-radio',
61
- options: ['responsive', 'floating'],
62
- description:
63
- '`responsive` gives Details its own column when there is room beside a usable Main; `floating` always floats it over Main.',
64
- table: { defaultValue: { summary: 'responsive' } },
65
- },
66
- children: {
67
- control: false,
68
- description:
69
- 'The panes: `ChatCardThreeColumnLayoutList`, `…Main`, and optionally `…Details` and `…Panel`.',
70
- },
71
- className: {
72
- control: 'text',
73
- description:
74
- 'Classes for the root. Set the height here (e.g. `h-120 md:h-150`); the layout sets none.',
75
- },
76
- asChild: {
77
- control: false,
78
- description: 'Renders the single child element as the layout root instead of a `<div>`.',
79
- table: { defaultValue: { summary: 'false' } },
80
- },
81
- },
82
- args: {
83
- detailsPlacement: 'responsive',
84
- className: 'h-120 md:h-150',
85
- asChild: false,
86
- },
87
- };
88
-
89
- export default meta;
90
- type Story = StoryObj<typeof ChatCardThreeColumnLayout>;
91
-
92
- interface StayCardProps {
93
- title: string;
94
- subTitle: string;
95
- isDefaultOpen?: boolean;
96
- /** The card's `ChatCardBody`. */
97
- children: ReactNode;
98
- }
99
-
100
- /**
101
- * The card around the layout. Both settings matter: `variant="full"` lets the card grow past the
102
- * reading column, and the card recipe gives a grid of `1fr` tracks a width to fill.
103
- */
104
- function StayCard({ title, subTitle, isDefaultOpen = true, children }: StayCardProps) {
105
- const titleId = useId();
106
-
107
- return (
108
- <ChatCardContainer variant="full">
109
- <ChatCard
110
- aria-labelledby={titleId}
111
- defaultOpen={isDefaultOpen}
112
- className={chatCardThreeColumnLayoutCardVariants()}
113
- >
114
- <ChatCardHeader>
115
- <ChatCardIcon>
116
- <HomeIcon />
117
- </ChatCardIcon>
118
- <ChatCardHeaderContent>
119
- <ChatCardTitle id={titleId}>{title}</ChatCardTitle>
120
- <ChatCardSubTitle>{subTitle}</ChatCardSubTitle>
121
- </ChatCardHeaderContent>
122
- <ChatCardActions>
123
- <ChatCardCollapsibleButton aria-label="Collapse or expand the places to stay" />
124
- </ChatCardActions>
125
- </ChatCardHeader>
126
- {children}
127
- </ChatCard>
128
- </ChatCardContainer>
129
- );
130
- }
131
-
132
- interface StaySearchCardProps extends Omit<ChatCardThreeColumnLayoutProps, 'children'> {
133
- /** The property whose Details are open on mount; `null` opens at the list. */
134
- initialStayId?: string | null;
135
- /** Whether the rooms Panel is open on mount. It needs an open property. */
136
- isRoomsInitiallyOpen?: boolean;
137
- /** Whether the card starts expanded. */
138
- isDefaultOpen?: boolean;
139
- }
140
-
141
- /**
142
- * An accommodation search: the places as a list, their prices on a map, and the open place in
143
- * Details. "Check other rooms" opens the rooms in the Panel, over the map and Details.
144
- */
145
- function StaySearchCard({
146
- initialStayId = null,
147
- isRoomsInitiallyOpen = false,
148
- isDefaultOpen,
149
- ...layoutProps
150
- }: StaySearchCardProps) {
151
- const [stayId, setStayId] = useState<string | null>(initialStayId);
152
- const [isRoomsOpen, setIsRoomsOpen] = useState(isRoomsInitiallyOpen);
153
- const stay = STAYS.find((candidate) => candidate.id === stayId) ?? null;
154
-
155
- return (
156
- <StayCard
157
- title="Places to stay in Zurich"
158
- subTitle="12–15 Nov · 2 adults"
159
- isDefaultOpen={isDefaultOpen}
160
- >
161
- <ChatCardBody>
162
- <ChatCardContent>
163
- <ChatCardThreeColumnLayout {...layoutProps}>
164
- <ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
165
- <StayList stays={STAYS} selectedId={stayId} onOpen={setStayId} />
166
- </ChatCardThreeColumnLayoutList>
167
-
168
- {/* `asChild`: the chat page already has a `<main>` landmark. */}
169
- <ChatCardThreeColumnLayoutMain asChild>
170
- <section aria-label="Map of available properties">
171
- <StayMap stays={STAYS} selectedId={stayId} onOpen={setStayId} />
172
- </section>
173
- </ChatCardThreeColumnLayoutMain>
174
-
175
- {/* Mounted only with a place open: an empty Details would reserve a blank column. */}
176
- {stay && (
177
- <ChatCardThreeColumnLayoutDetails aria-label={`Details for ${stay.name}`}>
178
- {(isFloating) => (
179
- <StayDetails
180
- stay={stay}
181
- isFloating={isFloating}
182
- onClose={() => setStayId(null)}
183
- onCheckRooms={() => setIsRoomsOpen(true)}
184
- />
185
- )}
186
- </ChatCardThreeColumnLayoutDetails>
187
- )}
188
-
189
- {stay && isRoomsOpen && (
190
- <ChatCardThreeColumnLayoutPanel aria-label={`Rooms at ${stay.name}`}>
191
- <StayRooms stay={stay} rates={ROOM_RATES} onBack={() => setIsRoomsOpen(false)} />
192
- </ChatCardThreeColumnLayoutPanel>
193
- )}
194
- </ChatCardThreeColumnLayout>
195
- </ChatCardContent>
196
- </ChatCardBody>
197
- </StayCard>
198
- );
199
- }
200
-
201
- /**
202
- * An accommodation search. Below 698px of layout width the list is hidden (`hideOnMobile`) and
203
- * the map has the card to itself; from 698px it is a 290px column, and from 1132px a
204
- * 358px one. Open a place for its Details: they float over the map until 1132px, then take a
205
- * 358px third column. Every threshold is the layout's own width, not the viewport's.
206
- */
207
- export const Default: Story = {
208
- render: (args) => (
209
- <ChatContainer className="h-auto">
210
- <StaySearchCard {...args} />
211
- </ChatContainer>
212
- ),
213
- };
214
-
215
- /** Details always floats over Main, even in a wide chat window. */
216
- export const DetailsFloating: Story = {
217
- args: { detailsPlacement: 'floating' },
218
- render: (args) => (
219
- <ChatContainer className="h-auto">
220
- <StaySearchCard {...args} initialStayId={FEATURED_STAY.id} />
221
- </ChatContainer>
222
- ),
223
- };
224
-
225
- /**
226
- * Panel covers everything but the List column, and the whole layout when List floats (below
227
- * 698px). Main and Details stay mounted under it: go back and the open place is still there.
228
- * Open it again from Details with "Check other rooms".
229
- */
230
- export const Panel: Story = {
231
- render: (args) => (
232
- <ChatContainer className="h-auto">
233
- <StaySearchCard {...args} initialStayId={FEATURED_STAY.id} isRoomsInitiallyOpen />
234
- </ChatContainer>
235
- ),
236
- };
237
-
238
- /** Drag the right edge across 698px: the Panel grows over the List once it floats. */
239
- export const PanelResizable: Story = {
240
- render: (args) => (
241
- <ResizableChatWindow>
242
- <ChatContainer className="h-auto">
243
- <StaySearchCard {...args} initialStayId="seefeld-garden" isRoomsInitiallyOpen />
244
- </ChatContainer>
245
- </ResizableChatWindow>
246
- ),
247
- };
248
-
249
- /**
250
- * A card that starts collapsed. The card's minimum width is gated on `data-state=open`, so the
251
- * collapsed card is only as wide as the reading column; expand it from the header and it takes
252
- * the chat window's width.
253
- */
254
- export const CollapsedCard: Story = {
255
- render: (args) => (
256
- <ChatContainer className="h-auto">
257
- <StaySearchCard {...args} initialStayId="seefeld-garden" isDefaultOpen={false} />
258
- </ChatContainer>
259
- ),
260
- };
261
-
262
- /**
263
- * Drag the dashed window's right edge. The panes switch on the layout's own width: List becomes
264
- * a 290px column at 698px, and at 1132px List widens to 358px and Details takes its 358px
265
- * column, with its render-prop content changing at the same moment. No browser resize needed,
266
- * which is the point: the viewport never changes here.
267
- */
268
- export const ResizableContainer: Story = {
269
- render: (args) => (
270
- <ResizableChatWindow>
271
- <ChatContainer className="h-auto">
272
- <StaySearchCard {...args} initialStayId={FEATURED_STAY.id} />
273
- </ChatContainer>
274
- </ResizableChatWindow>
275
- ),
276
- };
277
-
278
- /** Opens a place from the list and from the map, then closes Details, which unmounts the pane. */
279
- export const DefaultOpenAndCloseDetails: Story = {
280
- ...Default,
281
- tags: ['e2e', '!autodocs'],
282
- play: async ({ canvas, userEvent, step }) => {
283
- const list = within(canvas.getByRole('complementary', { name: 'Places to stay' }));
284
- const map = within(canvas.getByRole('region', { name: 'Map of available properties' }));
285
-
286
- await step('Starts at the list, with no Details pane', async () => {
287
- await expect(canvas.queryByRole('complementary', { name: /details for/i })).toBeNull();
288
- await expect(map.getByText('1 of these has no map location')).toBeVisible();
289
- });
290
-
291
- await step('A row opens its place in Details', async () => {
292
- await userEvent.click(list.getByRole('button', { name: /seefeld garden hotel/i }));
293
- const details = within(
294
- await canvas.findByRole('complementary', { name: 'Details for Seefeld Garden Hotel' }),
295
- );
296
- await expect(details.getByText('CHF 825 total · 3 nights')).toBeVisible();
297
- await expect(list.getByRole('button', { name: /seefeld garden hotel/i })).toHaveAttribute(
298
- 'aria-pressed',
299
- 'true',
300
- );
301
- });
302
-
303
- await step('A pin swaps the place in the same pane', async () => {
304
- await userEvent.click(map.getByRole('button', { name: /wiedikon loft house/i }));
305
- await expect(
306
- canvas.getByRole('complementary', { name: 'Details for Wiedikon Loft House' }),
307
- ).toBeVisible();
308
- await expect(canvas.getAllByRole('complementary', { name: /details for/i })).toHaveLength(1);
309
- });
310
-
311
- await step('Closing unmounts Details', async () => {
312
- await userEvent.click(canvas.getByRole('button', { name: 'Close details' }));
313
- await expect(canvas.queryByRole('complementary', { name: /details for/i })).toBeNull();
314
- });
315
- },
316
- };
317
-
318
- /** Closes the rooms Panel and checks that the map and the open place were mounted under it all along. */
319
- export const PanelBackKeepsDetails: Story = {
320
- ...Panel,
321
- tags: ['e2e', '!autodocs'],
322
- play: async ({ canvas, userEvent, step }) => {
323
- const map = canvas.getByRole('region', { name: 'Map of available properties' });
324
-
325
- await step('The Panel covers the map while Details stays mounted', async () => {
326
- const panel = canvas.getByRole('region', { name: 'Rooms at Hotel Limmatblick' });
327
- await expect(within(panel).getByText('Junior suite')).toBeVisible();
328
- await expect(
329
- canvas.getByRole('complementary', { name: 'Details for Hotel Limmatblick' }),
330
- ).toBeInTheDocument();
331
-
332
- const panelBox = panel.getBoundingClientRect();
333
- const mapBox = map.getBoundingClientRect();
334
- await expect(Math.round(panelBox.left)).toBeLessThanOrEqual(Math.round(mapBox.left));
335
- await expect(Math.round(panelBox.right)).toBeGreaterThanOrEqual(Math.round(mapBox.right));
336
- await expect(Math.round(panelBox.height)).toBe(Math.round(mapBox.height));
337
- });
338
-
339
- await step('Going back leaves the same map and the same open place', async () => {
340
- await userEvent.click(canvas.getByRole('button', { name: 'Back to the property' }));
341
- await expect(canvas.queryByRole('region', { name: /rooms at/i })).toBeNull();
342
- await expect(canvas.getByRole('region', { name: 'Map of available properties' })).toBe(map);
343
- await expect(
344
- canvas.getByRole('complementary', { name: 'Details for Hotel Limmatblick' }),
345
- ).toBeVisible();
346
- });
347
-
348
- await step('Details opens the Panel again', async () => {
349
- await userEvent.click(canvas.getByRole('button', { name: 'Check other rooms' }));
350
- await expect(
351
- canvas.getByRole('region', { name: 'Rooms at Hotel Limmatblick' }),
352
- ).toBeVisible();
353
- });
354
- },
355
- };
356
-
357
- /** Resizes the chat window through the tiers and checks where each pane is drawn. */
358
- export const ResizableContainerSwitchesPanes: Story = {
359
- ...ResizableContainer,
360
- tags: ['e2e', '!autodocs'],
361
- play: async ({ canvas, step }) => {
362
- const chatWindow = canvas.getByRole('group', { name: 'Resizable chat window' });
363
- const list = canvas.getByRole('complementary', { name: 'Places to stay' });
364
- const map = canvas.getByRole('region', { name: 'Map of available properties' });
365
- const details = canvas.getByRole('complementary', { name: 'Details for Hotel Limmatblick' });
366
-
367
- const box = (element: HTMLElement) => {
368
- const rect = element.getBoundingClientRect();
369
- return {
370
- left: Math.round(rect.left),
371
- right: Math.round(rect.right),
372
- top: Math.round(rect.top),
373
- bottom: Math.round(rect.bottom),
374
- width: Math.round(rect.width),
375
- height: Math.round(rect.height),
376
- };
377
- };
378
-
379
- // The window is capped at 100% of the page, which in a test run is narrower than the tiers.
380
- chatWindow.style.maxWidth = 'none';
381
-
382
- await step('lg: List is a 290px column and Details floats at Main’s right edge', async () => {
383
- chatWindow.style.width = '1000px';
384
- await waitFor(() => expect(list).toHaveAttribute('data-size', 'lg'));
385
- await waitFor(() => expect(box(list).width).toBe(290));
386
- await expect(box(list).right).toBeLessThanOrEqual(box(map).left);
387
- await expect(details).toHaveAttribute('data-floating', 'true');
388
- await expect(details).toHaveAttribute('data-sheet', 'false');
389
- await expect(box(details).width).toBe(358);
390
- await expect(box(details).right).toBe(box(map).right);
391
- });
392
-
393
- await step('xl: List widens to 358px and Details takes its own column', async () => {
394
- chatWindow.style.width = '1400px';
395
- await waitFor(() => expect(details).toHaveAttribute('data-floating', 'false'));
396
- await waitFor(() => expect(box(list).width).toBe(358));
397
- await expect(box(details).width).toBe(358);
398
- await expect(box(details).left).toBeGreaterThanOrEqual(box(map).right);
399
- });
400
-
401
- await step('sm: List is hidden and Details a bottom sheet', async () => {
402
- chatWindow.style.width = '600px';
403
- await waitFor(() => expect(list).toHaveAttribute('data-size', 'sm'));
404
- await expect(list).not.toBeVisible();
405
- await expect(details).toHaveAttribute('data-sheet', 'true');
406
- await expect(box(details).width).toBe(box(map).width);
407
- await expect(box(details).bottom).toBe(box(map).bottom);
408
- await expect(box(details).height).toBe(Math.round(box(map).height * 0.85));
409
- });
410
- },
411
- };
412
-
413
- /** Expands the collapsed card from its header and checks it only then claims the chat window's width. */
414
- export const CollapsedCardExpands: Story = {
415
- ...CollapsedCard,
416
- tags: ['e2e', '!autodocs'],
417
- play: async ({ canvas, userEvent, step }) => {
418
- const card = canvas.getByRole('region', { name: 'Places to stay in Zurich' });
419
- const collapsedMinWidth = getComputedStyle(card).minWidth;
420
-
421
- await step('Starts as a header, with no layout and no minimum width', async () => {
422
- await expect(card).toHaveAttribute('data-state', 'closed');
423
- await expect(
424
- canvas.queryByRole('region', { name: 'Map of available properties' }),
425
- ).toBeNull();
426
- await expect(Number.parseFloat(collapsedMinWidth) || 0).toBe(0);
427
- });
428
-
429
- await step('Expanding mounts the layout and holds the card at the window’s width', async () => {
430
- await userEvent.click(canvas.getByText('Places to stay in Zurich'));
431
- await expect(card).toHaveAttribute('data-state', 'open');
432
- await expect(
433
- await canvas.findByRole('region', { name: 'Map of available properties' }),
434
- ).toBeVisible();
435
- await expect(
436
- canvas.getByRole('complementary', { name: 'Details for Seefeld Garden Hotel' }),
437
- ).toBeVisible();
438
- await expect(Number.parseFloat(getComputedStyle(card).minWidth)).toBeGreaterThan(0);
439
- });
440
- },
441
- };
442
-
443
- /** The layout in each place it's allowed: a card's content, a card body with a note and a footer around it, and a chat thread. */
444
- export const Examples: Story = {
445
- parameters: { controls: { disable: true } },
446
- render: () => (
447
- <div className="flex flex-col gap-24">
448
- <ParentBlock parent="web-chat-ui/ChatCardContent">
449
- <ChatContainer className="h-auto">
450
- <StayCard title={FEATURED_STAY.name} subTitle="Hotel · Zurich">
451
- <ChatCardBody>
452
- <ChatCardContent>
453
- <ChatCardThreeColumnLayout className="h-100">
454
- <ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
455
- <StayList stays={[FEATURED_STAY]} selectedId={FEATURED_STAY.id} onOpen={fn()} />
456
- </ChatCardThreeColumnLayoutList>
457
- <ChatCardThreeColumnLayoutMain asChild>
458
- <section aria-label="Map of the property">
459
- <StayMap
460
- stays={[FEATURED_STAY]}
461
- selectedId={FEATURED_STAY.id}
462
- onOpen={fn()}
463
- />
464
- </section>
465
- </ChatCardThreeColumnLayoutMain>
466
- {/* A card about one property: Details is its content, so it is always mounted. */}
467
- <ChatCardThreeColumnLayoutDetails
468
- aria-label={`Details for ${FEATURED_STAY.name}`}
469
- >
470
- {(isFloating) => <StayDetails stay={FEATURED_STAY} isFloating={isFloating} />}
471
- </ChatCardThreeColumnLayoutDetails>
472
- </ChatCardThreeColumnLayout>
473
- </ChatCardContent>
474
- </ChatCardBody>
475
- </StayCard>
476
- </ChatContainer>
477
- </ParentBlock>
478
-
479
- <ParentBlock parent="chat card body">
480
- <ChatContainer className="h-auto">
481
- <StayCard title="Places to stay in Zurich" subTitle="12–15 Nov · 2 adults">
482
- <ChatCardBody>
483
- <ChatCardContent className="flex flex-col gap-8">
484
- <Typography variant="caption-md" className="text-text-tertiary">
485
- Prices as they were on this search. Restore it to check them again.
486
- </Typography>
487
- <ChatCardThreeColumnLayout className="h-100">
488
- <ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
489
- <StayList stays={STAYS} selectedId={FEATURED_STAY.id} onOpen={fn()} />
490
- </ChatCardThreeColumnLayoutList>
491
- <ChatCardThreeColumnLayoutMain asChild>
492
- <section aria-label="Map of available properties">
493
- <StayMap stays={STAYS} selectedId={FEATURED_STAY.id} onOpen={fn()} />
494
- </section>
495
- </ChatCardThreeColumnLayoutMain>
496
- </ChatCardThreeColumnLayout>
497
- </ChatCardContent>
498
- <ChatCardFooter>
499
- <ChatCardFooterNotes>
500
- <Typography variant="body-small-high" fontWeight="semibold">
501
- {FEATURED_STAY.name}
502
- </Typography>
503
- <Typography variant="caption-md" className="text-text-secondary">
504
- 1 × Double room · {FEATURED_STAY.total} total
505
- </Typography>
506
- </ChatCardFooterNotes>
507
- </ChatCardFooter>
508
- </ChatCardBody>
509
- </StayCard>
510
- </ChatContainer>
511
- </ParentBlock>
512
-
513
- <ParentBlock parent="chat thread">
514
- <ChatContainer className="h-auto gap-16">
515
- <ChatMessage isQuestion className="px-message">
516
- <ChatMessageContent>
517
- Find me a place to stay in Zurich from 12 to 15 November, for two adults.
518
- </ChatMessageContent>
519
- </ChatMessage>
520
- <ChatMessage className="px-message">
521
- <ChatMessageContent>
522
- Here are five places with a room free on those dates. Open one for its rates.
523
- </ChatMessageContent>
524
- </ChatMessage>
525
- <StaySearchCard className="h-100" />
526
- </ChatContainer>
527
- </ParentBlock>
528
- </div>
529
- ),
530
- };
531
-
532
- interface ChatCardThreeColumnLayoutPlaygroundProps {
533
- detailsPlacement: ChatCardThreeColumnLayoutDetailsPlacement;
534
- className: string;
535
- chatWindowWidth: number;
536
- stayCount: number;
537
- hasDetails: boolean;
538
- hasPanel: boolean;
539
- onOpenStay: (stayId: string) => void;
540
- onCloseDetails: () => void;
541
- onCheckRooms: () => void;
542
- onCloseRooms: () => void;
543
- }
544
-
545
- function ChatCardThreeColumnLayoutPlayground({
546
- detailsPlacement,
547
- className,
548
- chatWindowWidth,
549
- stayCount,
550
- hasDetails,
551
- hasPanel,
552
- onOpenStay,
553
- onCloseDetails,
554
- onCheckRooms,
555
- onCloseRooms,
556
- }: ChatCardThreeColumnLayoutPlaygroundProps) {
557
- const stays: Stay[] = STAYS.slice(0, stayCount);
558
-
559
- return (
560
- // The layout switches on its own width, so the window's width is the control that drives it.
561
- <div style={{ width: chatWindowWidth }}>
562
- <ChatContainer className="h-auto">
563
- <StayCard
564
- title="Places to stay in Zurich"
565
- subTitle={`12–15 Nov · 2 adults · ${stays.length} places`}
566
- >
567
- <ChatCardBody>
568
- <ChatCardContent>
569
- <ChatCardThreeColumnLayout detailsPlacement={detailsPlacement} className={className}>
570
- <ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
571
- <StayList
572
- stays={stays}
573
- selectedId={hasDetails ? FEATURED_STAY.id : null}
574
- onOpen={onOpenStay}
575
- />
576
- </ChatCardThreeColumnLayoutList>
577
-
578
- <ChatCardThreeColumnLayoutMain asChild>
579
- <section aria-label="Map of available properties">
580
- <StayMap
581
- stays={stays}
582
- selectedId={hasDetails ? FEATURED_STAY.id : null}
583
- onOpen={onOpenStay}
584
- />
585
- </section>
586
- </ChatCardThreeColumnLayoutMain>
587
-
588
- {hasDetails && (
589
- <ChatCardThreeColumnLayoutDetails
590
- aria-label={`Details for ${FEATURED_STAY.name}`}
591
- >
592
- {(isFloating) => (
593
- <StayDetails
594
- stay={FEATURED_STAY}
595
- isFloating={isFloating}
596
- onClose={onCloseDetails}
597
- onCheckRooms={onCheckRooms}
598
- />
599
- )}
600
- </ChatCardThreeColumnLayoutDetails>
601
- )}
602
-
603
- {hasPanel && (
604
- <ChatCardThreeColumnLayoutPanel aria-label={`Rooms at ${FEATURED_STAY.name}`}>
605
- <StayRooms stay={FEATURED_STAY} rates={ROOM_RATES} onBack={onCloseRooms} />
606
- </ChatCardThreeColumnLayoutPanel>
607
- )}
608
- </ChatCardThreeColumnLayout>
609
- </ChatCardContent>
610
- </ChatCardBody>
611
- </StayCard>
612
- </ChatContainer>
613
- </div>
614
- );
615
- }
616
-
617
- /** All four panes at once, with the root's props, the chat window's width and each optional pane on the Controls panel. */
618
- export const Playground: StoryObj<typeof ChatCardThreeColumnLayoutPlayground> = {
619
- tags: ['!autodocs'],
620
- args: {
621
- detailsPlacement: 'responsive',
622
- className: 'h-150',
623
- chatWindowWidth: 1280,
624
- stayCount: STAYS.length,
625
- hasDetails: true,
626
- hasPanel: true,
627
- onOpenStay: fn(),
628
- onCloseDetails: fn(),
629
- onCheckRooms: fn(),
630
- onCloseRooms: fn(),
631
- },
632
- argTypes: {
633
- chatWindowWidth: {
634
- control: { type: 'range', min: 360, max: 1600, step: 20 },
635
- description:
636
- 'Width of the chat window around the card, in px. The layout is this minus the message gutters and the card padding, and switches at 640px, 698px and 1132px of its own width.',
637
- },
638
- stayCount: {
639
- control: { type: 'number', min: 1, max: STAYS.length },
640
- description: 'Number of places in the List and on the map.',
641
- },
642
- hasDetails: {
643
- control: 'boolean',
644
- description:
645
- 'Mounts `ChatCardThreeColumnLayoutDetails`. Only a mounted Details adds the third column.',
646
- },
647
- hasPanel: {
648
- control: 'boolean',
649
- description:
650
- 'Mounts `ChatCardThreeColumnLayoutPanel` over Main and Details, which stay mounted under it.',
651
- },
652
- onOpenStay: { description: 'Called with the place’s id when a row or a pin is clicked.' },
653
- onCloseDetails: { description: 'Called by the close control in Details.' },
654
- onCheckRooms: { description: 'Called by "Check other rooms" in Details.' },
655
- onCloseRooms: { description: 'Called by "Back to the property" in the Panel.' },
656
- },
657
- render: (args) => <ChatCardThreeColumnLayoutPlayground {...args} />,
658
- };