@swisper.ai/web-chat-ui 0.0.7 → 0.1.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/dist/components/chat-card/components/chat-card-header.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/utils.d.ts +2 -2
- package/dist/index.css +1 -1
- package/dist/index.es.js +932 -930
- package/dist/index.es.js.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +20 -15
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +4 -4
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +13 -13
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/components/chat-card/components/chat-card-header.tsx +3 -7
- 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/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +6 -9
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +10 -12
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +71 -26
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +18 -12
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -2
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +20 -56
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +36 -34
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +33 -22
- package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +1 -1
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
3
|
"component": "chat-card-three-column-layout",
|
|
4
|
-
"purpose": "Responsive three-pane body for a chat card: List (a fixed column
|
|
4
|
+
"purpose": "Responsive three-pane body for a chat card: List (a fixed column on a wide layout, optionally hidden on a narrow one), Main (flexible), Details (its own right column, or floating over Main), plus an optional Panel that covers everything but the List column while Main and Details stay mounted. Panes switch on the layout's own measured width. Parts: ChatCardThreeColumnLayout, ChatCardThreeColumnLayoutList, ChatCardThreeColumnLayoutMain, ChatCardThreeColumnLayoutDetails, ChatCardThreeColumnLayoutPanel, plus chatCardThreeColumnLayoutCardVariants for the wrapping ChatCard.",
|
|
5
5
|
"anatomy": [
|
|
6
6
|
"import {",
|
|
7
7
|
" ChatCardThreeColumnLayout,",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"useWhen": [
|
|
22
22
|
"A chat card shaped like \"a collection + a canvas + a selected item\", e.g. places on a map, or rows next to a chart with a detail pane",
|
|
23
|
-
"The list
|
|
23
|
+
"The list can give way to the canvas on a narrow card, and the selected item must float over the canvas or become a bottom sheet",
|
|
24
24
|
"A secondary view (all reviews, a filter form) has to take over the card temporarily without unmounting the map or the open item"
|
|
25
25
|
],
|
|
26
26
|
"avoidWhen": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"uxPrinciples": [
|
|
33
33
|
"The card is sized by the chat window, not the viewport, so the panes switch on the layout's own width",
|
|
34
34
|
"Main (usually a map or chart) never drops below 400px beside a column; when a pane would squeeze it further, the pane floats instead",
|
|
35
|
-
"An open Details is what the reader asked for last, so it
|
|
35
|
+
"An open Details is what the reader asked for last, so it floats above Main; the Panel stacks above both",
|
|
36
36
|
"Opening the Panel must not cost the reader their place: the map keeps its viewport and the open item survives closing it"
|
|
37
37
|
],
|
|
38
38
|
"accessibility": {
|
|
@@ -64,18 +64,19 @@
|
|
|
64
64
|
"Panel mounted / not mounted"
|
|
65
65
|
],
|
|
66
66
|
"rules": [
|
|
67
|
-
"The root measures its own width and resolves the panes once, then publishes the result both as data attributes for the CSS (data-size, data-
|
|
68
|
-
"sm:
|
|
67
|
+
"The root measures its own width and resolves the panes once, then publishes the result both as data attributes for the CSS (data-size, data-details-floating on the root; data-size on List and Panel; data-floating and data-sheet on Details) and as isFloating for Details' render prop, so the content the render prop picks always matches where the pane is drawn",
|
|
68
|
+
"sm: there is no List column, so a List with hideOnMobile is hidden and Main fills the layout; a floating Details is a full-width bottom sheet at 85% of the height; the Panel covers the whole layout",
|
|
69
69
|
"md: as sm, but a floating Details is pinned to Main's right edge at 358px wide, inset 12px",
|
|
70
70
|
"lg: List is a 290px column beside Main; Details floats pinned to Main's right edge at 358px; the Panel covers Main's column",
|
|
71
71
|
"xl: List is a 358px column; with detailsPlacement=responsive a mounted Details gets its own 358px right column; the Panel covers Main's and Details' columns",
|
|
72
72
|
"detailsPlacement=responsive (default) gives Details its column at xl and floats it below that; detailsPlacement=floating always floats Details over Main while List still follows the tiers",
|
|
73
73
|
"Details adds the third grid track only while it is mounted (CSS :has on a direct child), so an always-mounted empty Details reserves a blank column — mount it conditionally",
|
|
74
|
-
"List
|
|
75
|
-
"
|
|
74
|
+
"List takes plain children. hideOnMobile hides it at sm and md, where there is no List column; it stays mounted, so its scroll position and state return with the column. Without hideOnMobile the layout does not place List at sm and md: it becomes an ordinary grid item in a row under Main",
|
|
75
|
+
"Details accepts plain children or a render prop (isFloating) => content; use the render prop to swap content, e.g. a surface with a shadow when floating — the CSS already positions the pane",
|
|
76
|
+
"Details is the same element before and after a switch: only the render prop's output changes, so scroll position and state above the render prop survive",
|
|
76
77
|
"The Panel is an overlay inset 12px that never adds a grid track, so mounting it does not move Main; it takes plain children because it overlays at every width; mount it only while it is open",
|
|
77
78
|
"Floating Details and the Panel are transparent: draw the surface (background, radius, shadow) in their content",
|
|
78
|
-
"Stacking order: Panel above floating Details above
|
|
79
|
+
"Stacking order: Panel above floating Details above Main",
|
|
79
80
|
"Before the first measurement (server render) the layout assumes xl; on the client the measurement lands before paint",
|
|
80
81
|
"The layout sets no height and the panes fill the row: give the root a height in className (e.g. h-[480px] md:h-[600px]), or a map or scroll area collapses to 0",
|
|
81
82
|
"In the List column, content needs h-full and its own scroll (e.g. ui/scroll-area) or a long list grows the card instead of scrolling",
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
"web-chat-ui/ChatCardThreeColumnLayoutDetails",
|
|
94
95
|
"web-chat-ui/ChatCardThreeColumnLayoutPanel",
|
|
95
96
|
"ui/scroll-area",
|
|
96
|
-
"web-map/map
|
|
97
|
+
"web-map/map",
|
|
97
98
|
"isFloating render prop"
|
|
98
99
|
],
|
|
99
100
|
"avoidCombinations": [
|
|
@@ -121,10 +122,15 @@
|
|
|
121
122
|
"reason": "The panes switch on the layout's own width, so a card that isn't given the width stays in a narrow tier"
|
|
122
123
|
},
|
|
123
124
|
{
|
|
124
|
-
"condition": "
|
|
125
|
-
"decision": "Pass a render prop (isFloating) => content to
|
|
125
|
+
"condition": "Details needs different content when it floats (a shadowed surface over the map, a flat one in the column)",
|
|
126
|
+
"decision": "Pass a render prop (isFloating) => content to Details; use plain children when the content is the same either way",
|
|
126
127
|
"reason": "CSS positions the pane but cannot swap the component tree, and the render prop reads the same decision the CSS uses"
|
|
127
128
|
},
|
|
129
|
+
{
|
|
130
|
+
"condition": "The card is narrow and the list would crowd the canvas",
|
|
131
|
+
"decision": "Set hideOnMobile on ChatCardThreeColumnLayoutList",
|
|
132
|
+
"reason": "Below 698px there is no List column; hideOnMobile hides the list there and leaves Main the whole layout, while keeping it mounted for when the column returns"
|
|
133
|
+
},
|
|
128
134
|
{
|
|
129
135
|
"condition": "A secondary view must take over the card (all reviews, a filter form) and closing it should return to the same map and item",
|
|
130
136
|
"decision": "Mount ChatCardThreeColumnLayoutPanel conditionally while it is open, with its own surface and a close control",
|
|
@@ -141,7 +147,7 @@
|
|
|
141
147
|
"web-chat-ui/chat-card",
|
|
142
148
|
"web-chat-ui/chat-card-container",
|
|
143
149
|
"ui/scroll-area",
|
|
144
|
-
"web-map/map
|
|
150
|
+
"web-map/map",
|
|
145
151
|
"ui/dialog"
|
|
146
152
|
]
|
|
147
153
|
}
|
|
@@ -40,7 +40,6 @@ export type ChatCardThreeColumnLayoutSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
|
40
40
|
|
|
41
41
|
export interface ChatCardThreeColumnLayoutResolved {
|
|
42
42
|
size: ChatCardThreeColumnLayoutSize;
|
|
43
|
-
isListFloating: boolean;
|
|
44
43
|
isDetailsFloating: boolean;
|
|
45
44
|
isDetailsSheet: boolean;
|
|
46
45
|
}
|
|
@@ -71,7 +70,6 @@ export function resolveLayout(
|
|
|
71
70
|
|
|
72
71
|
return {
|
|
73
72
|
size,
|
|
74
|
-
isListFloating: size === 'sm' || size === 'md',
|
|
75
73
|
isDetailsFloating: detailsPlacement === 'floating' || size !== 'xl',
|
|
76
74
|
isDetailsSheet: size === 'sm',
|
|
77
75
|
};
|
|
@@ -161,15 +161,8 @@ function StaySearchCard({
|
|
|
161
161
|
<ChatCardBody>
|
|
162
162
|
<ChatCardContent>
|
|
163
163
|
<ChatCardThreeColumnLayout {...layoutProps}>
|
|
164
|
-
<ChatCardThreeColumnLayoutList aria-label="Places to stay">
|
|
165
|
-
{
|
|
166
|
-
<StayList
|
|
167
|
-
stays={STAYS}
|
|
168
|
-
isFloating={isFloating}
|
|
169
|
-
selectedId={stayId}
|
|
170
|
-
onOpen={setStayId}
|
|
171
|
-
/>
|
|
172
|
-
)}
|
|
164
|
+
<ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
|
|
165
|
+
<StayList stays={STAYS} selectedId={stayId} onOpen={setStayId} />
|
|
173
166
|
</ChatCardThreeColumnLayoutList>
|
|
174
167
|
|
|
175
168
|
{/* `asChild`: the chat page already has a `<main>` landmark. */}
|
|
@@ -206,8 +199,8 @@ function StaySearchCard({
|
|
|
206
199
|
}
|
|
207
200
|
|
|
208
201
|
/**
|
|
209
|
-
* An accommodation search. Below 698px of layout width the list is
|
|
210
|
-
*
|
|
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
|
|
211
204
|
* 358px one. Open a place for its Details: they float over the map until 1132px, then take a
|
|
212
205
|
* 358px third column. Every threshold is the layout's own width, not the viewport's.
|
|
213
206
|
*/
|
|
@@ -269,7 +262,7 @@ export const CollapsedCard: Story = {
|
|
|
269
262
|
/**
|
|
270
263
|
* Drag the dashed window's right edge. The panes switch on the layout's own width: List becomes
|
|
271
264
|
* a 290px column at 698px, and at 1132px List widens to 358px and Details takes its 358px
|
|
272
|
-
* column, with
|
|
265
|
+
* column, with its render-prop content changing at the same moment. No browser resize needed,
|
|
273
266
|
* which is the point: the viewport never changes here.
|
|
274
267
|
*/
|
|
275
268
|
export const ResizableContainer: Story = {
|
|
@@ -361,7 +354,7 @@ export const PanelBackKeepsDetails: Story = {
|
|
|
361
354
|
},
|
|
362
355
|
};
|
|
363
356
|
|
|
364
|
-
/** Resizes the chat window through the tiers and checks where each pane is drawn
|
|
357
|
+
/** Resizes the chat window through the tiers and checks where each pane is drawn. */
|
|
365
358
|
export const ResizableContainerSwitchesPanes: Story = {
|
|
366
359
|
...ResizableContainer,
|
|
367
360
|
tags: ['e2e', '!autodocs'],
|
|
@@ -382,27 +375,19 @@ export const ResizableContainerSwitchesPanes: Story = {
|
|
|
382
375
|
height: Math.round(rect.height),
|
|
383
376
|
};
|
|
384
377
|
};
|
|
385
|
-
const rowTops = () =>
|
|
386
|
-
within(list)
|
|
387
|
-
.getAllByRole('button')
|
|
388
|
-
.slice(0, 2)
|
|
389
|
-
.map((row) => box(row).top);
|
|
390
378
|
|
|
391
379
|
// The window is capped at 100% of the page, which in a test run is narrower than the tiers.
|
|
392
380
|
chatWindow.style.maxWidth = 'none';
|
|
393
381
|
|
|
394
382
|
await step('lg: List is a 290px column and Details floats at Main’s right edge', async () => {
|
|
395
383
|
chatWindow.style.width = '1000px';
|
|
396
|
-
await waitFor(() => expect(list).toHaveAttribute('data-
|
|
384
|
+
await waitFor(() => expect(list).toHaveAttribute('data-size', 'lg'));
|
|
397
385
|
await waitFor(() => expect(box(list).width).toBe(290));
|
|
398
386
|
await expect(box(list).right).toBeLessThanOrEqual(box(map).left);
|
|
399
387
|
await expect(details).toHaveAttribute('data-floating', 'true');
|
|
400
388
|
await expect(details).toHaveAttribute('data-sheet', 'false');
|
|
401
389
|
await expect(box(details).width).toBe(358);
|
|
402
390
|
await expect(box(details).right).toBe(box(map).right);
|
|
403
|
-
// The column's render prop draws the rows one under the other.
|
|
404
|
-
const [first, second] = rowTops();
|
|
405
|
-
await expect(second).toBeGreaterThan(first ?? 0);
|
|
406
391
|
});
|
|
407
392
|
|
|
408
393
|
await step('xl: List widens to 358px and Details takes its own column', async () => {
|
|
@@ -413,18 +398,14 @@ export const ResizableContainerSwitchesPanes: Story = {
|
|
|
413
398
|
await expect(box(details).left).toBeGreaterThanOrEqual(box(map).right);
|
|
414
399
|
});
|
|
415
400
|
|
|
416
|
-
await step('sm: List is
|
|
401
|
+
await step('sm: List is hidden and Details a bottom sheet', async () => {
|
|
417
402
|
chatWindow.style.width = '600px';
|
|
418
|
-
await waitFor(() => expect(list).toHaveAttribute('data-
|
|
403
|
+
await waitFor(() => expect(list).toHaveAttribute('data-size', 'sm'));
|
|
404
|
+
await expect(list).not.toBeVisible();
|
|
419
405
|
await expect(details).toHaveAttribute('data-sheet', 'true');
|
|
420
|
-
await waitFor(() => expect(box(list).bottom).toBe(box(map).bottom));
|
|
421
|
-
await expect(box(list).width).toBe(box(map).width);
|
|
422
406
|
await expect(box(details).width).toBe(box(map).width);
|
|
423
407
|
await expect(box(details).bottom).toBe(box(map).bottom);
|
|
424
408
|
await expect(box(details).height).toBe(Math.round(box(map).height * 0.85));
|
|
425
|
-
// The strip's render prop draws the rows side by side.
|
|
426
|
-
const [first, second] = rowTops();
|
|
427
|
-
await expect(second).toBe(first);
|
|
428
409
|
});
|
|
429
410
|
},
|
|
430
411
|
};
|
|
@@ -470,15 +451,8 @@ export const Examples: Story = {
|
|
|
470
451
|
<ChatCardBody>
|
|
471
452
|
<ChatCardContent>
|
|
472
453
|
<ChatCardThreeColumnLayout className="h-100">
|
|
473
|
-
<ChatCardThreeColumnLayoutList aria-label="Places to stay">
|
|
474
|
-
{(
|
|
475
|
-
<StayList
|
|
476
|
-
stays={[FEATURED_STAY]}
|
|
477
|
-
isFloating={isFloating}
|
|
478
|
-
selectedId={FEATURED_STAY.id}
|
|
479
|
-
onOpen={fn()}
|
|
480
|
-
/>
|
|
481
|
-
)}
|
|
454
|
+
<ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
|
|
455
|
+
<StayList stays={[FEATURED_STAY]} selectedId={FEATURED_STAY.id} onOpen={fn()} />
|
|
482
456
|
</ChatCardThreeColumnLayoutList>
|
|
483
457
|
<ChatCardThreeColumnLayoutMain asChild>
|
|
484
458
|
<section aria-label="Map of the property">
|
|
@@ -511,15 +485,8 @@ export const Examples: Story = {
|
|
|
511
485
|
Prices as they were on this search. Restore it to check them again.
|
|
512
486
|
</Typography>
|
|
513
487
|
<ChatCardThreeColumnLayout className="h-100">
|
|
514
|
-
<ChatCardThreeColumnLayoutList aria-label="Places to stay">
|
|
515
|
-
{(
|
|
516
|
-
<StayList
|
|
517
|
-
stays={STAYS}
|
|
518
|
-
isFloating={isFloating}
|
|
519
|
-
selectedId={FEATURED_STAY.id}
|
|
520
|
-
onOpen={fn()}
|
|
521
|
-
/>
|
|
522
|
-
)}
|
|
488
|
+
<ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
|
|
489
|
+
<StayList stays={STAYS} selectedId={FEATURED_STAY.id} onOpen={fn()} />
|
|
523
490
|
</ChatCardThreeColumnLayoutList>
|
|
524
491
|
<ChatCardThreeColumnLayoutMain asChild>
|
|
525
492
|
<section aria-label="Map of available properties">
|
|
@@ -600,15 +567,12 @@ function ChatCardThreeColumnLayoutPlayground({
|
|
|
600
567
|
<ChatCardBody>
|
|
601
568
|
<ChatCardContent>
|
|
602
569
|
<ChatCardThreeColumnLayout detailsPlacement={detailsPlacement} className={className}>
|
|
603
|
-
<ChatCardThreeColumnLayoutList aria-label="Places to stay">
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
onOpen={onOpenStay}
|
|
610
|
-
/>
|
|
611
|
-
)}
|
|
570
|
+
<ChatCardThreeColumnLayoutList aria-label="Places to stay" hideOnMobile>
|
|
571
|
+
<StayList
|
|
572
|
+
stays={stays}
|
|
573
|
+
selectedId={hasDetails ? FEATURED_STAY.id : null}
|
|
574
|
+
onOpen={onOpenStay}
|
|
575
|
+
/>
|
|
612
576
|
</ChatCardThreeColumnLayoutList>
|
|
613
577
|
|
|
614
578
|
<ChatCardThreeColumnLayoutMain asChild>
|
|
@@ -5,6 +5,7 @@ import type { ComponentProps, ForwardedRef, ReactNode } from 'react';
|
|
|
5
5
|
import { cn, useElementMeasure } from '@swisper.ai/web-core';
|
|
6
6
|
|
|
7
7
|
import { resolveLayout } from './chat-card-three-column-layout.sizing';
|
|
8
|
+
import type { ChatCardThreeColumnLayoutSize } from './chat-card-three-column-layout.sizing';
|
|
8
9
|
import {
|
|
9
10
|
DEFAULT_DETAILS_PLACEMENT,
|
|
10
11
|
chatCardThreeColumnLayoutDetailsVariants,
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
import type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
|
|
17
18
|
|
|
18
19
|
interface ChatCardThreeColumnLayoutContextValue {
|
|
19
|
-
|
|
20
|
+
size: ChatCardThreeColumnLayoutSize;
|
|
20
21
|
isDetailsFloating: boolean;
|
|
21
22
|
isDetailsSheet: boolean;
|
|
22
23
|
}
|
|
@@ -31,7 +32,7 @@ function useChatCardThreeColumnLayoutContext(part: string) {
|
|
|
31
32
|
if (!context) {
|
|
32
33
|
throw new Error(
|
|
33
34
|
`[web-chat-ui] "${part}" must be used within a ChatCardThreeColumnLayout. ` +
|
|
34
|
-
'It reads its
|
|
35
|
+
'It reads its placement from the layout, so render ' +
|
|
35
36
|
'it as a child of the ChatCardThreeColumnLayout element, not as a sibling of it.',
|
|
36
37
|
);
|
|
37
38
|
}
|
|
@@ -40,11 +41,11 @@ function useChatCardThreeColumnLayoutContext(part: string) {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* The Details pane's content, or a function of whether the pane is currently floating.
|
|
44
45
|
*
|
|
45
|
-
* The function form exists because a floating pane
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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.
|
|
48
49
|
*/
|
|
49
50
|
export type ChatCardThreeColumnLayoutPaneChildren =
|
|
50
51
|
ReactNode | ((isFloating: boolean) => ReactNode);
|
|
@@ -88,8 +89,9 @@ function useMergedRef<T>(first: (node: T | null) => void, second: ForwardedRef<T
|
|
|
88
89
|
* breakpoints. The card is sized by the chat window, and a sidebar, a split view or the
|
|
89
90
|
* Storybook panel all make the viewport claim room the card doesn't have (or the
|
|
90
91
|
* 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
|
|
92
|
-
* render prop
|
|
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.
|
|
93
95
|
*
|
|
94
96
|
* Height is not set here, because it belongs to the content (a map needs a fixed height, a
|
|
95
97
|
* table might not), so pass it in `className`.
|
|
@@ -102,14 +104,11 @@ export const ChatCardThreeColumnLayout = forwardRef<HTMLDivElement, ChatCardThre
|
|
|
102
104
|
const { ref: measureRef, width } = useElementMeasure<HTMLDivElement>();
|
|
103
105
|
const mergedRef = useMergedRef(measureRef, ref);
|
|
104
106
|
|
|
105
|
-
const { size,
|
|
106
|
-
width,
|
|
107
|
-
detailsPlacement,
|
|
108
|
-
);
|
|
107
|
+
const { size, isDetailsFloating, isDetailsSheet } = resolveLayout(width, detailsPlacement);
|
|
109
108
|
|
|
110
109
|
const contextValue = useMemo(
|
|
111
|
-
() => ({
|
|
112
|
-
[
|
|
110
|
+
() => ({ size, isDetailsFloating, isDetailsSheet }),
|
|
111
|
+
[size, isDetailsFloating, isDetailsSheet],
|
|
113
112
|
);
|
|
114
113
|
|
|
115
114
|
const Component = asChild ? Slot : 'div';
|
|
@@ -122,7 +121,6 @@ export const ChatCardThreeColumnLayout = forwardRef<HTMLDivElement, ChatCardThre
|
|
|
122
121
|
data-slot="chat-card-three-column-layout"
|
|
123
122
|
data-details-placement={detailsPlacement}
|
|
124
123
|
data-size={size}
|
|
125
|
-
data-list-floating={isListFloating}
|
|
126
124
|
data-details-floating={isDetailsFloating}
|
|
127
125
|
className={cn(chatCardThreeColumnLayoutVariants(), className)}
|
|
128
126
|
{...rest}
|
|
@@ -136,26 +134,30 @@ export const ChatCardThreeColumnLayout = forwardRef<HTMLDivElement, ChatCardThre
|
|
|
136
134
|
|
|
137
135
|
ChatCardThreeColumnLayout.displayName = 'ChatCardThreeColumnLayout';
|
|
138
136
|
|
|
139
|
-
export interface ChatCardThreeColumnLayoutListProps extends
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
144
|
asChild?: boolean;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Column 1 when the layout has room for it beside a usable Main
|
|
149
|
-
*
|
|
150
|
-
* output changes when it switches.
|
|
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.
|
|
151
150
|
*
|
|
152
|
-
* `data-
|
|
151
|
+
* `data-size` is set too, for styling the pane by the layout's tier.
|
|
153
152
|
*/
|
|
154
153
|
export const ChatCardThreeColumnLayoutList = forwardRef<
|
|
155
154
|
HTMLDivElement,
|
|
156
155
|
ChatCardThreeColumnLayoutListProps
|
|
157
|
-
>(function ChatCardThreeColumnLayoutList(
|
|
158
|
-
|
|
156
|
+
>(function ChatCardThreeColumnLayoutList(
|
|
157
|
+
{ children, className, hideOnMobile = false, asChild = false, ...rest },
|
|
158
|
+
ref,
|
|
159
|
+
) {
|
|
160
|
+
const { size } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutList');
|
|
159
161
|
|
|
160
162
|
const Component = asChild ? Slot : 'aside';
|
|
161
163
|
|
|
@@ -164,11 +166,11 @@ export const ChatCardThreeColumnLayoutList = forwardRef<
|
|
|
164
166
|
ref={ref}
|
|
165
167
|
data-testid="chat-card-three-column-layout-list"
|
|
166
168
|
data-slot="chat-card-three-column-layout-list"
|
|
167
|
-
data-
|
|
168
|
-
className={cn(chatCardThreeColumnLayoutListVariants(), className)}
|
|
169
|
+
data-size={size}
|
|
170
|
+
className={cn(chatCardThreeColumnLayoutListVariants({ hideOnMobile }), className)}
|
|
169
171
|
{...rest}
|
|
170
172
|
>
|
|
171
|
-
{
|
|
173
|
+
{children}
|
|
172
174
|
</Component>
|
|
173
175
|
);
|
|
174
176
|
});
|
|
@@ -260,9 +262,9 @@ export interface ChatCardThreeColumnLayoutPanelProps extends ComponentProps<'sec
|
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
/**
|
|
263
|
-
* An overlay covering everything but the List column (the whole layout when
|
|
264
|
-
* inset 12px. Mount it only while it is open. Main and Details stay mounted
|
|
265
|
-
* a map keeps its viewport and the open Details item survives closing the Panel.
|
|
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.
|
|
266
268
|
*
|
|
267
269
|
* The pane is transparent: draw the surface (background, radius, shadow) in its content,
|
|
268
270
|
* as for Details.
|
|
@@ -271,7 +273,7 @@ export const ChatCardThreeColumnLayoutPanel = forwardRef<
|
|
|
271
273
|
HTMLElement,
|
|
272
274
|
ChatCardThreeColumnLayoutPanelProps
|
|
273
275
|
>(function ChatCardThreeColumnLayoutPanel({ children, className, asChild = false, ...rest }, ref) {
|
|
274
|
-
const {
|
|
276
|
+
const { size } = useChatCardThreeColumnLayoutContext('ChatCardThreeColumnLayoutPanel');
|
|
275
277
|
const Component = asChild ? Slot : 'section';
|
|
276
278
|
|
|
277
279
|
return (
|
|
@@ -279,7 +281,7 @@ export const ChatCardThreeColumnLayoutPanel = forwardRef<
|
|
|
279
281
|
ref={ref}
|
|
280
282
|
data-testid="chat-card-three-column-layout-panel"
|
|
281
283
|
data-slot="chat-card-three-column-layout-panel"
|
|
282
|
-
data-
|
|
284
|
+
data-size={size}
|
|
283
285
|
className={cn(chatCardThreeColumnLayoutPanelVariants(), className)}
|
|
284
286
|
{...rest}
|
|
285
287
|
>
|
|
@@ -20,8 +20,8 @@ export const DEFAULT_DETAILS_PLACEMENT: ChatCardThreeColumnLayoutDetailsPlacemen
|
|
|
20
20
|
|
|
21
21
|
/*
|
|
22
22
|
* Every recipe below keys on data attributes the components set from the layout's measured
|
|
23
|
-
* width (`data-size`, `data-
|
|
24
|
-
* `data-floating`, `data-sheet` on
|
|
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
25
|
* `PANE_WIDTH_XL` from `chat-card-three-column-layout.sizing.ts`, written out because
|
|
26
26
|
* Tailwind cannot read a constant. Change both together.
|
|
27
27
|
*
|
|
@@ -45,7 +45,7 @@ export const DEFAULT_DETAILS_PLACEMENT: ChatCardThreeColumnLayoutDetailsPlacemen
|
|
|
45
45
|
*/
|
|
46
46
|
export const chatCardThreeColumnLayoutVariants = cva([
|
|
47
47
|
'relative grid gap-[8px]',
|
|
48
|
-
// sm + md — Main only;
|
|
48
|
+
// sm + md — Main only; there is no List column and Details floats over Main
|
|
49
49
|
"grid-cols-[1fr] [grid-template-areas:'main']",
|
|
50
50
|
"data-[size=lg]:grid-cols-[290px_1fr] data-[size=lg]:[grid-template-areas:'list_main']",
|
|
51
51
|
"data-[size=xl]:grid-cols-[358px_1fr] data-[size=xl]:[grid-template-areas:'list_main']",
|
|
@@ -55,19 +55,31 @@ export const chatCardThreeColumnLayoutVariants = cva([
|
|
|
55
55
|
]);
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Column 1
|
|
59
|
-
*
|
|
60
|
-
* the
|
|
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
61
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* grid item grows to its content and the card gets taller instead of scrolling.
|
|
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.
|
|
65
64
|
*/
|
|
66
|
-
export const chatCardThreeColumnLayoutListVariants = cva(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
]
|
|
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
|
+
);
|
|
71
83
|
|
|
72
84
|
/**
|
|
73
85
|
* Column 2, the flexible `1fr` track. `min-w-0` because a grid item's minimum width is its
|
|
@@ -86,9 +98,8 @@ export const chatCardThreeColumnLayoutMainVariants = cva([
|
|
|
86
98
|
* - sheet: on a narrow layout, a bottom sheet at a fixed 85% height, so the pane does not
|
|
87
99
|
* change height as its content changes (the content scrolls instead)
|
|
88
100
|
*
|
|
89
|
-
* `z-20` keeps a floating Details above
|
|
90
|
-
*
|
|
91
|
-
* widening the `1fr` track past the card.
|
|
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.
|
|
92
103
|
*/
|
|
93
104
|
export const chatCardThreeColumnLayoutDetailsVariants = cva([
|
|
94
105
|
'min-h-0 min-w-0 max-w-full',
|
|
@@ -103,14 +114,14 @@ export const chatCardThreeColumnLayoutDetailsVariants = cva([
|
|
|
103
114
|
* card (all reviews, a filter form) while Main and Details stay mounted underneath.
|
|
104
115
|
*
|
|
105
116
|
* 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
|
|
107
|
-
* never adds a track, so mounting it doesn't move Main. `z-30` keeps it above floating
|
|
108
|
-
* Details (`z-20`)
|
|
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`).
|
|
109
120
|
*/
|
|
110
121
|
export const chatCardThreeColumnLayoutPanelVariants = cva([
|
|
111
122
|
'relative z-30 min-w-0 min-h-0 h-full p-[12px] row-1',
|
|
112
|
-
'
|
|
113
|
-
'data-[
|
|
123
|
+
'col-span-full',
|
|
124
|
+
'data-[size=lg]:col-[2/-1] data-[size=xl]:col-[2/-1]',
|
|
114
125
|
]);
|
|
115
126
|
|
|
116
127
|
/**
|
|
@@ -6,7 +6,7 @@ export interface RouteMapProps {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Stands in for `
|
|
9
|
+
* Stands in for `Map` from `@swisper.ai/web-map`, which this package does not depend on.
|
|
10
10
|
* Like a map it has no height of its own and fills whatever Main gives it.
|
|
11
11
|
*/
|
|
12
12
|
export function RouteMap({ label }: RouteMapProps) {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"web-chat-ui/ChatCardTwoColumnLayoutAside",
|
|
64
64
|
"web-chat-ui/ChatCardTwoColumnLayoutMain",
|
|
65
65
|
"ui/scroll-area",
|
|
66
|
-
"web-map/map
|
|
66
|
+
"web-map/map"
|
|
67
67
|
],
|
|
68
68
|
"avoidCombinations": [
|
|
69
69
|
"Wrapping Aside or Main in another element — they must be direct children of the root to sit in the grid; use asChild for a different element instead",
|
|
@@ -104,6 +104,6 @@
|
|
|
104
104
|
"web-chat-ui/chat-card",
|
|
105
105
|
"web-chat-ui/chat-card-container",
|
|
106
106
|
"ui/scroll-area",
|
|
107
|
-
"web-map/map
|
|
107
|
+
"web-map/map"
|
|
108
108
|
]
|
|
109
109
|
}
|