@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.
- package/README.md +2 -5
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
- package/dist/components/rich-text-field/utils.d.ts +36 -36
- package/dist/index.css +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +1566 -1810
- package/dist/index.es.js.map +1 -1
- package/package.json +4 -4
- package/src/components/chat-card/chat-card.json +6 -6
- package/src/components/chat-card/chat-card.stories.tsx +6 -14
- package/src/components/chat-card/components/chat-card-body.tsx +1 -1
- package/src/components/chat-card-container/chat-card-container.json +6 -6
- package/src/components/chat-card-container/chat-card-container.stories.tsx +10 -18
- package/src/components/chat-container/chat-container.json +1 -1
- package/src/components/chat-list/chat-list-items.tsx +3 -3
- package/src/components/rich-text-field/rich-text-field.stories.tsx +3 -1
- package/src/index.ts +0 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +0 -97
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +0 -52
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-list-layout/index.d.ts +0 -3
- package/dist/layouts/chat-card-list-layout/index.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +0 -89
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -44
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +0 -62
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +0 -81
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +0 -1
- package/dist/layouts/chat-card-three-column-layout/index.d.ts +0 -5
- package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +0 -37
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +0 -12
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +0 -40
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +0 -35
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +0 -1
- package/dist/layouts/chat-card-two-column-layout/index.d.ts +0 -4
- package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +0 -1
- package/dist/layouts/index.d.ts +0 -4
- package/dist/layouts/index.d.ts.map +0 -1
- package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +0 -112
- package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +0 -36
- package/src/layouts/chat-card-list-layout/__stories__/types.ts +0 -31
- package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +0 -204
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +0 -129
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +0 -422
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +0 -254
- package/src/layouts/chat-card-list-layout/index.ts +0 -11
- package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +0 -117
- package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +0 -18
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +0 -85
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +0 -47
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +0 -44
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +0 -61
- package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +0 -35
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +0 -71
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +0 -327
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +0 -153
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -76
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +0 -658
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +0 -293
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +0 -146
- package/src/layouts/chat-card-three-column-layout/index.ts +0 -24
- package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +0 -51
- package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +0 -83
- package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +0 -24
- package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +0 -15
- package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +0 -109
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +0 -109
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +0 -21
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +0 -439
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +0 -141
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +0 -65
- package/src/layouts/chat-card-two-column-layout/index.ts +0 -17
- package/src/layouts/index.ts +0 -3
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { resolveLayout } from '../chat-card-three-column-layout.sizing';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The thresholds are the whole feature: every pane decision, in CSS and in Details' render
|
|
7
|
-
* prop, comes from this function. Each boundary is tested at its exact pixel and one
|
|
8
|
-
* below, so an off-by-one (a `>` for a `>=`, a forgotten gap) shows up here instead of as
|
|
9
|
-
* a pane that floats with room to spare.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
describe('size tiers', () => {
|
|
13
|
-
// md from 640; lg = 290 list + 8 gap + 400 min Main; xl = 2 × 358 + 2 × 8 + 400
|
|
14
|
-
test.each([
|
|
15
|
-
[639, 'sm'],
|
|
16
|
-
[640, 'md'],
|
|
17
|
-
[697, 'md'],
|
|
18
|
-
[698, 'lg'],
|
|
19
|
-
[1131, 'lg'],
|
|
20
|
-
[1132, 'xl'],
|
|
21
|
-
])('at %ipx the layout is %s', (width, expected) => {
|
|
22
|
-
expect(resolveLayout(width, 'responsive').size).toBe(expected);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('with responsive placement', () => {
|
|
27
|
-
test.each([
|
|
28
|
-
[500, { isDetailsFloating: true, isDetailsSheet: true }],
|
|
29
|
-
[660, { isDetailsFloating: true, isDetailsSheet: false }],
|
|
30
|
-
[800, { isDetailsFloating: true, isDetailsSheet: false }],
|
|
31
|
-
[1200, { isDetailsFloating: false, isDetailsSheet: false }],
|
|
32
|
-
])('at %ipx resolves %o', (width, expected) => {
|
|
33
|
-
expect(resolveLayout(width, 'responsive')).toMatchObject(expected);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// The bug that motivated measuring the layout: Details only got its column at a 1366px
|
|
37
|
-
// viewport, so a card with 1200px of room still floated it.
|
|
38
|
-
test('gives details its column once the layout has room, whatever the viewport', () => {
|
|
39
|
-
expect(resolveLayout(1200, 'responsive').isDetailsFloating).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('with floating placement', () => {
|
|
44
|
-
// The tiers still apply to List; only Details is kept off its column.
|
|
45
|
-
test.each([
|
|
46
|
-
[500, 'sm'],
|
|
47
|
-
[800, 'lg'],
|
|
48
|
-
[1920, 'xl'],
|
|
49
|
-
])('at %ipx is %s, and details floats', (width, size) => {
|
|
50
|
-
expect(resolveLayout(width, 'floating')).toMatchObject({
|
|
51
|
-
size,
|
|
52
|
-
isDetailsFloating: true,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('before the layout is measured', () => {
|
|
58
|
-
// SSR and the first client render have no width; the wide form is the safer guess
|
|
59
|
-
// because SSR HTML is mostly seen on desktops.
|
|
60
|
-
test('resolves to xl', () => {
|
|
61
|
-
expect(resolveLayout('unset', 'responsive')).toEqual({
|
|
62
|
-
size: 'xl',
|
|
63
|
-
isDetailsFloating: false,
|
|
64
|
-
isDetailsSheet: false,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('still floats details with floating placement', () => {
|
|
69
|
-
expect(resolveLayout('unset', 'floating').isDetailsFloating).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
});
|
package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { act, cleanup, render, screen } from '@testing-library/react';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
ChatCardThreeColumnLayout,
|
|
6
|
-
ChatCardThreeColumnLayoutDetails,
|
|
7
|
-
ChatCardThreeColumnLayoutList,
|
|
8
|
-
ChatCardThreeColumnLayoutMain,
|
|
9
|
-
ChatCardThreeColumnLayoutPanel,
|
|
10
|
-
} from '../chat-card-three-column-layout';
|
|
11
|
-
import type { ChatCardThreeColumnLayoutProps } from '../chat-card-three-column-layout';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The thresholds have their own table in `chat-card-three-column-layout.sizing.test.ts`.
|
|
15
|
-
* What this file locks is the wiring: the root measures itself, and the width it measures
|
|
16
|
-
* reaches both halves of the contract. That means the data attributes the CSS keys on and
|
|
17
|
-
* the `isFloating` Details' render prop receives. If they disagree, floating content gets
|
|
18
|
-
* drawn in a column, and no single-width visual check would notice.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
type ResizeCallback = (
|
|
22
|
-
entries: { borderBoxSize: { inlineSize: number; blockSize: number }[] }[],
|
|
23
|
-
) => void;
|
|
24
|
-
|
|
25
|
-
let layoutWidth = 1440;
|
|
26
|
-
const observers = new Set<ResizeCallback>();
|
|
27
|
-
|
|
28
|
-
/** A `ResizeObserver` whose callbacks `resizeTo` fires by hand; jsdom has none and lays nothing out. */
|
|
29
|
-
class ResizeObserverStub {
|
|
30
|
-
constructor(private readonly callback: ResizeCallback) {}
|
|
31
|
-
observe() {
|
|
32
|
-
observers.add(this.callback);
|
|
33
|
-
}
|
|
34
|
-
disconnect() {
|
|
35
|
-
observers.delete(this.callback);
|
|
36
|
-
}
|
|
37
|
-
unobserve() {}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function resizeTo(width: number) {
|
|
41
|
-
layoutWidth = width;
|
|
42
|
-
act(() =>
|
|
43
|
-
observers.forEach((callback) =>
|
|
44
|
-
callback([{ borderBoxSize: [{ inlineSize: width, blockSize: 480 }] }]),
|
|
45
|
-
),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
layoutWidth = 1440;
|
|
51
|
-
vi.stubGlobal('ResizeObserver', ResizeObserverStub);
|
|
52
|
-
// `useElementMeasure` reads `offsetWidth` for the first measurement, before any observer fires
|
|
53
|
-
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(() => layoutWidth);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
afterEach(() => {
|
|
57
|
-
cleanup();
|
|
58
|
-
observers.clear();
|
|
59
|
-
vi.unstubAllGlobals();
|
|
60
|
-
vi.restoreAllMocks();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
function renderLayout(props: Partial<ChatCardThreeColumnLayoutProps> = {}) {
|
|
64
|
-
return render(
|
|
65
|
-
<ChatCardThreeColumnLayout {...props}>
|
|
66
|
-
<ChatCardThreeColumnLayoutList>list</ChatCardThreeColumnLayoutList>
|
|
67
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
68
|
-
<ChatCardThreeColumnLayoutDetails>
|
|
69
|
-
{(isFloating) => <span>{isFloating ? 'details: floating' : 'details: column'}</span>}
|
|
70
|
-
</ChatCardThreeColumnLayoutDetails>
|
|
71
|
-
</ChatCardThreeColumnLayout>,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function text(container: HTMLElement) {
|
|
76
|
-
return container.textContent ?? '';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function root() {
|
|
80
|
-
return screen.getByTestId('chat-card-three-column-layout');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function list() {
|
|
84
|
-
return screen.getByTestId('chat-card-three-column-layout-list');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function details() {
|
|
88
|
-
return screen.getByTestId('chat-card-three-column-layout-details');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
describe('the measured width', () => {
|
|
92
|
-
test.each([
|
|
93
|
-
[500, 'details: floating'],
|
|
94
|
-
[800, 'details: floating'],
|
|
95
|
-
[1200, 'details: column'],
|
|
96
|
-
])('at %ipx renders "%s"', (width, detailsText) => {
|
|
97
|
-
layoutWidth = width;
|
|
98
|
-
const { container } = renderLayout();
|
|
99
|
-
|
|
100
|
-
expect(text(container)).toContain(detailsText);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// The CSS switches on these attributes, so they must carry the same decision the render
|
|
104
|
-
// prop received. That agreement is why the layout is resolved once, at the root.
|
|
105
|
-
test('reaches the attributes the CSS keys on', () => {
|
|
106
|
-
layoutWidth = 800;
|
|
107
|
-
renderLayout();
|
|
108
|
-
|
|
109
|
-
expect(root().getAttribute('data-details-floating')).toBe('true');
|
|
110
|
-
expect(details().getAttribute('data-floating')).toBe('true');
|
|
111
|
-
expect(details().getAttribute('data-sheet')).toBe('false');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// `data-size` picks the grid template (290px list at lg, 358px at xl)
|
|
115
|
-
test.each([
|
|
116
|
-
[500, 'sm'],
|
|
117
|
-
[800, 'lg'],
|
|
118
|
-
[1200, 'xl'],
|
|
119
|
-
])('at %ipx publishes size %s', (width, size) => {
|
|
120
|
-
layoutWidth = width;
|
|
121
|
-
renderLayout();
|
|
122
|
-
|
|
123
|
-
expect(root().getAttribute('data-size')).toBe(size);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// List and Panel are placed by the tier too, and their recipes key on their own attribute.
|
|
127
|
-
test.each([
|
|
128
|
-
[500, 'sm'],
|
|
129
|
-
[800, 'lg'],
|
|
130
|
-
[1200, 'xl'],
|
|
131
|
-
])('at %ipx gives List size %s', (width, size) => {
|
|
132
|
-
layoutWidth = width;
|
|
133
|
-
renderLayout();
|
|
134
|
-
|
|
135
|
-
expect(list().getAttribute('data-size')).toBe(size);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('marks a floating details pane as a sheet on a narrow layout', () => {
|
|
139
|
-
layoutWidth = 500;
|
|
140
|
-
renderLayout();
|
|
141
|
-
|
|
142
|
-
expect(details().getAttribute('data-sheet')).toBe('true');
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('keeps details floating with floating placement, however wide', () => {
|
|
146
|
-
layoutWidth = 1920;
|
|
147
|
-
const { container } = renderLayout({ detailsPlacement: 'floating' });
|
|
148
|
-
|
|
149
|
-
expect(text(container)).toContain('details: floating');
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('resizing', () => {
|
|
154
|
-
test('swaps the render-prop content when a threshold is crossed', () => {
|
|
155
|
-
const { container } = renderLayout();
|
|
156
|
-
|
|
157
|
-
resizeTo(500);
|
|
158
|
-
|
|
159
|
-
expect(text(container)).toContain('details: floating');
|
|
160
|
-
|
|
161
|
-
resizeTo(1440);
|
|
162
|
-
|
|
163
|
-
expect(text(container)).toContain('details: column');
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// The pane element must survive the switch, and only its content changes. Remounting the
|
|
167
|
-
// pane would drop the consumer's scroll position and any state above the render prop.
|
|
168
|
-
test('keeps the same pane element across a threshold', () => {
|
|
169
|
-
renderLayout();
|
|
170
|
-
const before = details();
|
|
171
|
-
|
|
172
|
-
resizeTo(500);
|
|
173
|
-
|
|
174
|
-
expect(details()).toBe(before);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('the root element', () => {
|
|
179
|
-
// The root needs its own ref for measuring as well as the consumer's; losing either is silent.
|
|
180
|
-
test('still forwards the consumer ref', () => {
|
|
181
|
-
const ref = { current: null as HTMLDivElement | null };
|
|
182
|
-
render(
|
|
183
|
-
<ChatCardThreeColumnLayout ref={ref}>
|
|
184
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
185
|
-
</ChatCardThreeColumnLayout>,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(ref.current).toBe(root());
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
describe('the parts', () => {
|
|
193
|
-
test('Details accepts plain children as well as a render prop', () => {
|
|
194
|
-
render(
|
|
195
|
-
<ChatCardThreeColumnLayout>
|
|
196
|
-
<ChatCardThreeColumnLayoutList>plain list</ChatCardThreeColumnLayoutList>
|
|
197
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
198
|
-
<ChatCardThreeColumnLayoutDetails>plain details</ChatCardThreeColumnLayoutDetails>
|
|
199
|
-
</ChatCardThreeColumnLayout>,
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
expect(screen.getByText('plain list')).not.toBeNull();
|
|
203
|
-
expect(screen.getByText('plain details')).not.toBeNull();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// The root grid only grows a third track via `:has(> [data-slot=…-details])`, so the
|
|
207
|
-
// slot must land on the element the consumer asked for, including through `asChild`.
|
|
208
|
-
test('render into the consumer element with asChild', () => {
|
|
209
|
-
render(
|
|
210
|
-
<ChatCardThreeColumnLayout>
|
|
211
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
212
|
-
<ChatCardThreeColumnLayoutDetails asChild>
|
|
213
|
-
<section aria-label="details">details</section>
|
|
214
|
-
</ChatCardThreeColumnLayoutDetails>
|
|
215
|
-
</ChatCardThreeColumnLayout>,
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
const section = screen.getByRole('region', { name: 'details' });
|
|
219
|
-
|
|
220
|
-
expect(section.getAttribute('data-slot')).toBe('chat-card-three-column-layout-details');
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test.each([
|
|
224
|
-
[
|
|
225
|
-
'ChatCardThreeColumnLayoutList',
|
|
226
|
-
<ChatCardThreeColumnLayoutList key="list">x</ChatCardThreeColumnLayoutList>,
|
|
227
|
-
],
|
|
228
|
-
[
|
|
229
|
-
'ChatCardThreeColumnLayoutMain',
|
|
230
|
-
<ChatCardThreeColumnLayoutMain key="main">x</ChatCardThreeColumnLayoutMain>,
|
|
231
|
-
],
|
|
232
|
-
[
|
|
233
|
-
'ChatCardThreeColumnLayoutDetails',
|
|
234
|
-
<ChatCardThreeColumnLayoutDetails key="details">x</ChatCardThreeColumnLayoutDetails>,
|
|
235
|
-
],
|
|
236
|
-
[
|
|
237
|
-
'ChatCardThreeColumnLayoutPanel',
|
|
238
|
-
<ChatCardThreeColumnLayoutPanel key="panel">x</ChatCardThreeColumnLayoutPanel>,
|
|
239
|
-
],
|
|
240
|
-
])('%s throws outside the layout', (name, element) => {
|
|
241
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
242
|
-
|
|
243
|
-
expect(() => render(element)).toThrow(new RegExp(`\\[web-chat-ui\\] "${name}"`));
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe('hideOnMobile on List', () => {
|
|
248
|
-
function renderList(hideOnMobile?: boolean) {
|
|
249
|
-
return render(
|
|
250
|
-
<ChatCardThreeColumnLayout>
|
|
251
|
-
<ChatCardThreeColumnLayoutList hideOnMobile={hideOnMobile}>
|
|
252
|
-
list
|
|
253
|
-
</ChatCardThreeColumnLayoutList>
|
|
254
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
255
|
-
</ChatCardThreeColumnLayout>,
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// jsdom applies no Tailwind, so the classes are what can be checked: hidden at sm and md only.
|
|
260
|
-
test('hides the pane on a layout with no List column', () => {
|
|
261
|
-
renderList(true);
|
|
262
|
-
|
|
263
|
-
expect(list().className).toContain('data-[size=sm]:hidden');
|
|
264
|
-
expect(list().className).toContain('data-[size=md]:hidden');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test('leaves the pane alone by default', () => {
|
|
268
|
-
renderList();
|
|
269
|
-
|
|
270
|
-
expect(list().className).not.toContain(':hidden');
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
// Hidden, not unmounted: the list's scroll position and state come back with the column.
|
|
274
|
-
test('keeps the pane mounted when it is hidden', () => {
|
|
275
|
-
layoutWidth = 500;
|
|
276
|
-
renderList(true);
|
|
277
|
-
|
|
278
|
-
expect(screen.getByText('list')).not.toBeNull();
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
describe('the panel', () => {
|
|
283
|
-
function renderWithPanel() {
|
|
284
|
-
return render(
|
|
285
|
-
<ChatCardThreeColumnLayout>
|
|
286
|
-
<ChatCardThreeColumnLayoutList>list</ChatCardThreeColumnLayoutList>
|
|
287
|
-
<ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
|
|
288
|
-
<ChatCardThreeColumnLayoutDetails>details</ChatCardThreeColumnLayoutDetails>
|
|
289
|
-
<ChatCardThreeColumnLayoutPanel>reviews</ChatCardThreeColumnLayoutPanel>
|
|
290
|
-
</ChatCardThreeColumnLayout>,
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function panel() {
|
|
295
|
-
return screen.getByTestId('chat-card-three-column-layout-panel');
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// The CSS spans the panel from column 2 while List is a column (lg, xl), and over all of
|
|
299
|
-
// it otherwise; this attribute is the switch.
|
|
300
|
-
test.each([
|
|
301
|
-
[500, 'sm'],
|
|
302
|
-
[800, 'lg'],
|
|
303
|
-
[1200, 'xl'],
|
|
304
|
-
])('at %ipx publishes size %s', (width, size) => {
|
|
305
|
-
layoutWidth = width;
|
|
306
|
-
renderWithPanel();
|
|
307
|
-
|
|
308
|
-
expect(panel().getAttribute('data-size')).toBe(size);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
test('follows the layout when it is resized', () => {
|
|
312
|
-
renderWithPanel();
|
|
313
|
-
|
|
314
|
-
resizeTo(500);
|
|
315
|
-
|
|
316
|
-
expect(panel().getAttribute('data-size')).toBe('sm');
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
// The point of the panel over a replacement view: the map and the open item keep their state.
|
|
320
|
-
test('leaves Main and Details mounted underneath', () => {
|
|
321
|
-
const { container } = renderWithPanel();
|
|
322
|
-
|
|
323
|
-
expect(text(container)).toContain('map');
|
|
324
|
-
expect(text(container)).toContain('details');
|
|
325
|
-
expect(text(container)).toContain('reviews');
|
|
326
|
-
});
|
|
327
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
|
-
"component": "chat-card-three-column-layout",
|
|
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
|
-
"anatomy": [
|
|
6
|
-
"import {",
|
|
7
|
-
" ChatCardThreeColumnLayout,",
|
|
8
|
-
" ChatCardThreeColumnLayoutList,",
|
|
9
|
-
" ChatCardThreeColumnLayoutMain,",
|
|
10
|
-
" ChatCardThreeColumnLayoutDetails,",
|
|
11
|
-
" ChatCardThreeColumnLayoutPanel,",
|
|
12
|
-
"} from '@swisper.ai/web-chat-ui';",
|
|
13
|
-
"",
|
|
14
|
-
"<ChatCardThreeColumnLayout>",
|
|
15
|
-
" <ChatCardThreeColumnLayoutList />",
|
|
16
|
-
" <ChatCardThreeColumnLayoutMain />",
|
|
17
|
-
" <ChatCardThreeColumnLayoutDetails />",
|
|
18
|
-
" <ChatCardThreeColumnLayoutPanel />",
|
|
19
|
-
"</ChatCardThreeColumnLayout>"
|
|
20
|
-
],
|
|
21
|
-
"useWhen": [
|
|
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 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
|
-
"A secondary view (all reviews, a filter form) has to take over the card temporarily without unmounting the map or the open item"
|
|
25
|
-
],
|
|
26
|
-
"avoidWhen": [
|
|
27
|
-
"Only a list or summary beside a canvas, with no selected-item pane and nothing floating — use web-chat-ui/chat-card-two-column-layout instead",
|
|
28
|
-
"The card has a single content area — put the content in web-chat-ui/ChatCardContent directly",
|
|
29
|
-
"A blocking task that must interrupt the whole conversation — use ui/dialog instead of the Panel",
|
|
30
|
-
"Page-level layout outside a chat card — the tiers, pane widths and card recipe are tuned for a card in a chat message"
|
|
31
|
-
],
|
|
32
|
-
"uxPrinciples": [
|
|
33
|
-
"The card is sized by the chat window, not the viewport, so the panes switch on the layout's own width",
|
|
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 floats above Main; the Panel stacks above both",
|
|
36
|
-
"Opening the Panel must not cost the reader their place: the map keeps its viewport and the open item survives closing it"
|
|
37
|
-
],
|
|
38
|
-
"accessibility": {
|
|
39
|
-
"required": [
|
|
40
|
-
"List and Details render <aside>, Main a <main> and Panel a <section>; a chat page usually already has a <main>, so use asChild to render a <section> or <div> for Main when that would create a second main landmark",
|
|
41
|
-
"Give the Panel's content a heading or aria-label naming the view, and a visible close control",
|
|
42
|
-
"Give Details a visible close control; the layout provides none"
|
|
43
|
-
],
|
|
44
|
-
"keyboard": [
|
|
45
|
-
"No keyboard handling of its own; DOM and tab order is the order the parts are rendered (List, Main, Details, Panel), whatever their visual position",
|
|
46
|
-
"Escape does not close Details or the Panel; the consumer owns closing"
|
|
47
|
-
],
|
|
48
|
-
"aria": [
|
|
49
|
-
"Sets no ARIA attributes; landmarks come from the pane elements (or the asChild element)",
|
|
50
|
-
"The Panel is not a dialog: it sets no role=dialog or aria-modal"
|
|
51
|
-
],
|
|
52
|
-
"focus": [
|
|
53
|
-
"Nothing is focus-managed: opening Details or the Panel does not move focus into it, and closing does not restore it",
|
|
54
|
-
"Main and Details stay mounted and focusable under an open Panel; the layout does not make them inert"
|
|
55
|
-
]
|
|
56
|
-
},
|
|
57
|
-
"behaviour": {
|
|
58
|
-
"states": [
|
|
59
|
-
"sm (layout narrower than 640px)",
|
|
60
|
-
"md (640–697px)",
|
|
61
|
-
"lg (698–1131px)",
|
|
62
|
-
"xl (1132px and wider)",
|
|
63
|
-
"Details mounted / not mounted",
|
|
64
|
-
"Panel mounted / not mounted"
|
|
65
|
-
],
|
|
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-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
|
-
"md: as sm, but a floating Details is pinned to Main's right edge at 358px wide, inset 12px",
|
|
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
|
-
"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
|
-
"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
|
-
"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 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",
|
|
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",
|
|
78
|
-
"Floating Details and the Panel are transparent: draw the surface (background, radius, shadow) in their content",
|
|
79
|
-
"Stacking order: Panel above floating Details above Main",
|
|
80
|
-
"Before the first measurement (server render) the layout assumes xl; on the client the measurement lands before paint",
|
|
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",
|
|
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",
|
|
83
|
-
"Main is position: relative, so consumers can anchor their own overlays to it",
|
|
84
|
-
"The exported cva recipes key on the data attributes above; using a recipe without its component means setting those attributes yourself. A className on any part is merged over its recipe and wins",
|
|
85
|
-
"Every part throws \"[web-chat-ui] … must be used within a ChatCardThreeColumnLayout\" when rendered outside the root",
|
|
86
|
-
"asChild on the root and on each part renders the consumer's element instead of div / aside / main / section, keeping the data-slot the grid relies on"
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
"composition": {
|
|
90
|
-
"allowedParents": ["web-chat-ui/ChatCardContent"],
|
|
91
|
-
"allowedChildren": [
|
|
92
|
-
"web-chat-ui/ChatCardThreeColumnLayoutList",
|
|
93
|
-
"web-chat-ui/ChatCardThreeColumnLayoutMain",
|
|
94
|
-
"web-chat-ui/ChatCardThreeColumnLayoutDetails",
|
|
95
|
-
"web-chat-ui/ChatCardThreeColumnLayoutPanel",
|
|
96
|
-
"ui/scroll-area",
|
|
97
|
-
"web-map/map",
|
|
98
|
-
"isFloating render prop"
|
|
99
|
-
],
|
|
100
|
-
"avoidCombinations": [
|
|
101
|
-
"Wrapping List, Main, Details or Panel in another element — the grid areas and the :has check need direct children of the root (a wrapped Details never becomes a column, a wrapped Panel adds a row and pushes Main down); use asChild instead",
|
|
102
|
-
"Hiding Details with CSS instead of unmounting it — it still reserves the third column",
|
|
103
|
-
"The wrapping web-chat-ui/chat-card without chatCardThreeColumnLayoutCardVariants() — a grid of 1fr tracks has no intrinsic width, so the card shrinks to nothing inside a message",
|
|
104
|
-
"web-chat-ui/chat-card-container on its default fixed variant — it caps the card at the reading column, so the card overflows the chat and Details floats although the window is wide; use variant=\"full\""
|
|
105
|
-
],
|
|
106
|
-
"contexts": ["chat card body", "chat thread"]
|
|
107
|
-
},
|
|
108
|
-
"content": {
|
|
109
|
-
"labelRules": [],
|
|
110
|
-
"helperTextRules": [],
|
|
111
|
-
"errorRules": []
|
|
112
|
-
},
|
|
113
|
-
"aiDecisionRules": [
|
|
114
|
-
{
|
|
115
|
-
"condition": "Building a collection + canvas + selected-item card (places on a map, rows next to a chart)",
|
|
116
|
-
"decision": "Render web-chat-ui/chat-card-container variant=\"full\" > web-chat-ui/chat-card with className={chatCardThreeColumnLayoutCardVariants()} > ChatCardBody > ChatCardContent > ChatCardThreeColumnLayout with a height in className, List and Main always, Details only while an item is selected",
|
|
117
|
-
"reason": "Without the card recipe the card collapses to zero width, without variant=\"full\" it overflows the chat and never reaches xl, and without a height the map is blank"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"condition": "Details floats although the window is wide, or the card overflows the chat to the right",
|
|
121
|
-
"decision": "Check that the ChatCard has chatCardThreeColumnLayoutCardVariants() and that its web-chat-ui/chat-card-container uses variant=\"full\"",
|
|
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"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
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",
|
|
127
|
-
"reason": "CSS positions the pane but cannot swap the component tree, and the render prop reads the same decision the CSS uses"
|
|
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
|
-
},
|
|
134
|
-
{
|
|
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",
|
|
136
|
-
"decision": "Mount ChatCardThreeColumnLayoutPanel conditionally while it is open, with its own surface and a close control",
|
|
137
|
-
"reason": "Main and Details stay mounted underneath, so the map keeps its viewport and the open item survives; replacing Main would lose both"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
"condition": "The selected-item pane is secondary at every size and should never take a column",
|
|
141
|
-
"decision": "Set detailsPlacement=\"floating\" on the root",
|
|
142
|
-
"reason": "Details then always floats over Main while List still follows the width tiers"
|
|
143
|
-
}
|
|
144
|
-
],
|
|
145
|
-
"relatedComponents": [
|
|
146
|
-
"web-chat-ui/chat-card-two-column-layout",
|
|
147
|
-
"web-chat-ui/chat-card",
|
|
148
|
-
"web-chat-ui/chat-card-container",
|
|
149
|
-
"ui/scroll-area",
|
|
150
|
-
"web-map/map",
|
|
151
|
-
"ui/dialog"
|
|
152
|
-
]
|
|
153
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { ChatCardThreeColumnLayoutDetailsPlacement } from './chat-card-three-column-layout.variants';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Pane widths are fixed pixels per size tier, as in the places card this layout came from:
|
|
5
|
-
* List is 290px at `lg` and 358px at `xl`, and Details is always 358px. The recipes in
|
|
6
|
-
* `chat-card-three-column-layout.variants.ts` write them out as literal `290px` / `358px`,
|
|
7
|
-
* because Tailwind cannot read a constant, so change both together.
|
|
8
|
-
*/
|
|
9
|
-
export const LIST_WIDTH_LG = 290;
|
|
10
|
-
/** List at `xl`, and Details at every tier (as a column and as a pinned floating pane). */
|
|
11
|
-
export const PANE_WIDTH_XL = 358;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Narrowest Main may get before a pane has to float over it instead of sitting beside it.
|
|
15
|
-
* Main is usually a map or a chart, and below ~400px a map shows too little context to
|
|
16
|
-
* pick a place from. This is the one number to tune when a card feels cramped.
|
|
17
|
-
*/
|
|
18
|
-
export const MIN_MAIN_WIDTH = 400;
|
|
19
|
-
|
|
20
|
-
/** Must equal the `gap-[8px]` on the root grid, or the thresholds are off by that much. */
|
|
21
|
-
export const GAP = 8;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Below this, a floating Details is a bottom sheet (`sm`). Pinned to Main's right edge at
|
|
25
|
-
* 358px, it would leave a sliver of Main too thin to read or tap.
|
|
26
|
-
*/
|
|
27
|
-
export const MD_MIN_WIDTH = 640;
|
|
28
|
-
|
|
29
|
-
/** `lg`: a 290px List column fits beside a usable Main. */
|
|
30
|
-
export const LG_MIN_WIDTH = LIST_WIDTH_LG + GAP + MIN_MAIN_WIDTH;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* `xl`: a Details column fits beside a 358px List and a usable Main. List widens to 358px at
|
|
34
|
-
* the same point, as in the original, where both changed at the `xl` breakpoint.
|
|
35
|
-
*/
|
|
36
|
-
export const XL_MIN_WIDTH = PANE_WIDTH_XL * 2 + GAP * 2 + MIN_MAIN_WIDTH;
|
|
37
|
-
|
|
38
|
-
/** Size tier, named after the viewport breakpoints the original card used. */
|
|
39
|
-
export type ChatCardThreeColumnLayoutSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
40
|
-
|
|
41
|
-
export interface ChatCardThreeColumnLayoutResolved {
|
|
42
|
-
size: ChatCardThreeColumnLayoutSize;
|
|
43
|
-
isDetailsFloating: boolean;
|
|
44
|
-
isDetailsSheet: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getSize(width: number): ChatCardThreeColumnLayoutSize {
|
|
48
|
-
if (width >= XL_MIN_WIDTH) return 'xl';
|
|
49
|
-
if (width >= LG_MIN_WIDTH) return 'lg';
|
|
50
|
-
if (width >= MD_MIN_WIDTH) return 'md';
|
|
51
|
-
return 'sm';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Where each pane goes, given the width the layout actually has.
|
|
56
|
-
*
|
|
57
|
-
* The tiers are the original card's `md` / `lg` / `xl`, but measured on the layout, not
|
|
58
|
-
* the viewport. The card is sized by the chat window, and a sidebar, a split view or the
|
|
59
|
-
* Storybook panel all make the viewport claim room the card doesn't have (or the reverse).
|
|
60
|
-
*
|
|
61
|
-
* `'unset'` means the layout has not been measured yet (on the server, or before the first
|
|
62
|
-
* layout effect). It resolves to `xl`: SSR HTML is mostly seen on desktops, and on the
|
|
63
|
-
* client the measurement lands before paint.
|
|
64
|
-
*/
|
|
65
|
-
export function resolveLayout(
|
|
66
|
-
width: number | 'unset',
|
|
67
|
-
detailsPlacement: ChatCardThreeColumnLayoutDetailsPlacement,
|
|
68
|
-
): ChatCardThreeColumnLayoutResolved {
|
|
69
|
-
const size = width === 'unset' ? 'xl' : getSize(width);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
size,
|
|
73
|
-
isDetailsFloating: detailsPlacement === 'floating' || size !== 'xl',
|
|
74
|
-
isDetailsSheet: size === 'sm',
|
|
75
|
-
};
|
|
76
|
-
}
|