@swisper.ai/web-chat-ui 0.0.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) 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/components/chat-card-header.d.ts.map +1 -1
  4. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  5. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  6. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  7. package/dist/components/rich-text-field/utils.d.ts +38 -38
  8. package/dist/index.css +1 -1
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.es.js +1571 -1813
  12. package/dist/index.es.js.map +1 -1
  13. package/package.json +5 -5
  14. package/src/components/chat-card/chat-card.json +6 -6
  15. package/src/components/chat-card/chat-card.stories.tsx +6 -14
  16. package/src/components/chat-card/components/chat-card-body.tsx +1 -1
  17. package/src/components/chat-card/components/chat-card-header.tsx +3 -7
  18. package/src/components/chat-card-container/chat-card-container.json +6 -6
  19. package/src/components/chat-card-container/chat-card-container.stories.tsx +10 -18
  20. package/src/components/chat-container/chat-container.json +1 -1
  21. package/src/components/chat-thinking-process/chat-thinking-process.tsx +4 -12
  22. package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +12 -2
  23. package/src/components/rich-text-field/rich-text-field.stories.tsx +3 -1
  24. package/src/index.ts +0 -1
  25. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +0 -97
  26. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +0 -1
  27. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +0 -52
  28. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +0 -1
  29. package/dist/layouts/chat-card-list-layout/index.d.ts +0 -3
  30. package/dist/layouts/chat-card-list-layout/index.d.ts.map +0 -1
  31. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +0 -84
  32. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +0 -1
  33. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -45
  34. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +0 -1
  35. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +0 -62
  36. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +0 -1
  37. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +0 -81
  38. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +0 -1
  39. package/dist/layouts/chat-card-three-column-layout/index.d.ts +0 -5
  40. package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +0 -1
  41. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +0 -37
  42. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +0 -1
  43. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +0 -12
  44. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +0 -1
  45. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +0 -40
  46. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +0 -1
  47. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +0 -35
  48. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +0 -1
  49. package/dist/layouts/chat-card-two-column-layout/index.d.ts +0 -4
  50. package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +0 -1
  51. package/dist/layouts/index.d.ts +0 -4
  52. package/dist/layouts/index.d.ts.map +0 -1
  53. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +0 -112
  54. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +0 -36
  55. package/src/layouts/chat-card-list-layout/__stories__/types.ts +0 -31
  56. package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +0 -204
  57. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +0 -129
  58. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +0 -422
  59. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +0 -254
  60. package/src/layouts/chat-card-list-layout/index.ts +0 -11
  61. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +0 -117
  62. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +0 -18
  63. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +0 -85
  64. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +0 -50
  65. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +0 -44
  66. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +0 -61
  67. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +0 -35
  68. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +0 -73
  69. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +0 -282
  70. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +0 -147
  71. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -78
  72. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +0 -694
  73. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +0 -291
  74. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +0 -135
  75. package/src/layouts/chat-card-three-column-layout/index.ts +0 -24
  76. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +0 -51
  77. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +0 -83
  78. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +0 -24
  79. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +0 -15
  80. package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +0 -109
  81. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +0 -109
  82. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +0 -21
  83. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +0 -439
  84. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +0 -141
  85. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +0 -65
  86. package/src/layouts/chat-card-two-column-layout/index.ts +0 -17
  87. package/src/layouts/index.ts +0 -3
@@ -1,282 +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` each render prop receives. If they disagree, mobile content gets drawn
18
- * in a desktop 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>
67
- {(isFloating) => <span>{isFloating ? 'list: strip' : 'list: column'}</span>}
68
- </ChatCardThreeColumnLayoutList>
69
- <ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
70
- <ChatCardThreeColumnLayoutDetails>
71
- {(isFloating) => <span>{isFloating ? 'details: floating' : 'details: column'}</span>}
72
- </ChatCardThreeColumnLayoutDetails>
73
- </ChatCardThreeColumnLayout>,
74
- );
75
- }
76
-
77
- function text(container: HTMLElement) {
78
- return container.textContent ?? '';
79
- }
80
-
81
- function root() {
82
- return screen.getByTestId('chat-card-three-column-layout');
83
- }
84
-
85
- function details() {
86
- return screen.getByTestId('chat-card-three-column-layout-details');
87
- }
88
-
89
- describe('the measured width', () => {
90
- test.each([
91
- [500, 'list: strip', 'details: floating'],
92
- [800, 'list: column', 'details: floating'],
93
- [1200, 'list: column', 'details: column'],
94
- ])('at %ipx renders "%s" and "%s"', (width, list, detailsText) => {
95
- layoutWidth = width;
96
- const { container } = renderLayout();
97
-
98
- expect(text(container)).toContain(list);
99
- expect(text(container)).toContain(detailsText);
100
- });
101
-
102
- // The CSS switches on these attributes, so they must carry the same decision the render
103
- // props received. That agreement is why the layout is resolved once, at the root.
104
- test('reaches the attributes the CSS keys on', () => {
105
- layoutWidth = 800;
106
- renderLayout();
107
-
108
- expect(root().getAttribute('data-list-floating')).toBe('false');
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
- test('marks a floating details pane as a sheet on a narrow layout', () => {
127
- layoutWidth = 500;
128
- renderLayout();
129
-
130
- expect(details().getAttribute('data-sheet')).toBe('true');
131
- });
132
-
133
- test('keeps details floating with floating placement, however wide', () => {
134
- layoutWidth = 1920;
135
- const { container } = renderLayout({ detailsPlacement: 'floating' });
136
-
137
- expect(text(container)).toContain('details: floating');
138
- });
139
- });
140
-
141
- describe('resizing', () => {
142
- test('swaps the render-prop content when a threshold is crossed', () => {
143
- const { container } = renderLayout();
144
-
145
- resizeTo(500);
146
-
147
- expect(text(container)).toContain('list: strip');
148
- expect(text(container)).toContain('details: floating');
149
-
150
- resizeTo(1440);
151
-
152
- expect(text(container)).toContain('list: column');
153
- expect(text(container)).toContain('details: column');
154
- });
155
-
156
- // The pane element must survive the switch, and only its content changes. Remounting the
157
- // pane would drop the consumer's scroll position and any state above the render prop.
158
- test('keeps the same pane element across a threshold', () => {
159
- renderLayout();
160
- const before = screen.getByTestId('chat-card-three-column-layout-list');
161
-
162
- resizeTo(500);
163
-
164
- expect(screen.getByTestId('chat-card-three-column-layout-list')).toBe(before);
165
- });
166
- });
167
-
168
- describe('the root element', () => {
169
- // The root needs its own ref for measuring as well as the consumer's; losing either is silent.
170
- test('still forwards the consumer ref', () => {
171
- const ref = { current: null as HTMLDivElement | null };
172
- render(
173
- <ChatCardThreeColumnLayout ref={ref}>
174
- <ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
175
- </ChatCardThreeColumnLayout>,
176
- );
177
-
178
- expect(ref.current).toBe(root());
179
- });
180
- });
181
-
182
- describe('the parts', () => {
183
- test('accept plain children as well as a render prop', () => {
184
- render(
185
- <ChatCardThreeColumnLayout>
186
- <ChatCardThreeColumnLayoutList>plain list</ChatCardThreeColumnLayoutList>
187
- <ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
188
- <ChatCardThreeColumnLayoutDetails>plain details</ChatCardThreeColumnLayoutDetails>
189
- </ChatCardThreeColumnLayout>,
190
- );
191
-
192
- expect(screen.getByText('plain list')).not.toBeNull();
193
- expect(screen.getByText('plain details')).not.toBeNull();
194
- });
195
-
196
- // The root grid only grows a third track via `:has(> [data-slot=…-details])`, so the
197
- // slot must land on the element the consumer asked for, including through `asChild`.
198
- test('render into the consumer element with asChild', () => {
199
- render(
200
- <ChatCardThreeColumnLayout>
201
- <ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
202
- <ChatCardThreeColumnLayoutDetails asChild>
203
- <section aria-label="details">details</section>
204
- </ChatCardThreeColumnLayoutDetails>
205
- </ChatCardThreeColumnLayout>,
206
- );
207
-
208
- const section = screen.getByRole('region', { name: 'details' });
209
-
210
- expect(section.getAttribute('data-slot')).toBe('chat-card-three-column-layout-details');
211
- });
212
-
213
- test.each([
214
- [
215
- 'ChatCardThreeColumnLayoutList',
216
- <ChatCardThreeColumnLayoutList key="list">x</ChatCardThreeColumnLayoutList>,
217
- ],
218
- [
219
- 'ChatCardThreeColumnLayoutMain',
220
- <ChatCardThreeColumnLayoutMain key="main">x</ChatCardThreeColumnLayoutMain>,
221
- ],
222
- [
223
- 'ChatCardThreeColumnLayoutDetails',
224
- <ChatCardThreeColumnLayoutDetails key="details">x</ChatCardThreeColumnLayoutDetails>,
225
- ],
226
- [
227
- 'ChatCardThreeColumnLayoutPanel',
228
- <ChatCardThreeColumnLayoutPanel key="panel">x</ChatCardThreeColumnLayoutPanel>,
229
- ],
230
- ])('%s throws outside the layout', (name, element) => {
231
- vi.spyOn(console, 'error').mockImplementation(() => {});
232
-
233
- expect(() => render(element)).toThrow(new RegExp(`\\[web-chat-ui\\] "${name}"`));
234
- });
235
- });
236
-
237
- describe('the panel', () => {
238
- function renderWithPanel() {
239
- return render(
240
- <ChatCardThreeColumnLayout>
241
- <ChatCardThreeColumnLayoutList>list</ChatCardThreeColumnLayoutList>
242
- <ChatCardThreeColumnLayoutMain>map</ChatCardThreeColumnLayoutMain>
243
- <ChatCardThreeColumnLayoutDetails>details</ChatCardThreeColumnLayoutDetails>
244
- <ChatCardThreeColumnLayoutPanel>reviews</ChatCardThreeColumnLayoutPanel>
245
- </ChatCardThreeColumnLayout>,
246
- );
247
- }
248
-
249
- function panel() {
250
- return screen.getByTestId('chat-card-three-column-layout-panel');
251
- }
252
-
253
- // The CSS spans the panel from column 2 while List is a column, and over all of it once
254
- // List floats; this attribute is the switch.
255
- test.each([
256
- [500, 'true'],
257
- [800, 'false'],
258
- [1200, 'false'],
259
- ])('at %ipx publishes list-floating %s', (width, listFloating) => {
260
- layoutWidth = width;
261
- renderWithPanel();
262
-
263
- expect(panel().getAttribute('data-list-floating')).toBe(listFloating);
264
- });
265
-
266
- test('follows List when the layout is resized', () => {
267
- renderWithPanel();
268
-
269
- resizeTo(500);
270
-
271
- expect(panel().getAttribute('data-list-floating')).toBe('true');
272
- });
273
-
274
- // The point of the panel over a replacement view: the map and the open item keep their state.
275
- test('leaves Main and Details mounted underneath', () => {
276
- const { container } = renderWithPanel();
277
-
278
- expect(text(container)).toContain('map');
279
- expect(text(container)).toContain('details');
280
- expect(text(container)).toContain('reviews');
281
- });
282
- });
@@ -1,147 +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, or a strip floating over Main), 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 must stay usable on a narrow card as a strip over the canvas, and the selected item must float over it 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 stacks above the floating List; 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-list-floating, data-details-floating on the root; data-floating on List and Details; data-sheet on Details; data-list-floating on Panel) and as isFloating for the render props, so the content a render prop picks always matches where its pane is drawn",
68
- "sm: Main fills the layout; List is a strip pinned to the bottom over Main; a floating Details is a full-width bottom sheet at 85% of the height; the Panel covers the whole layout including the strip",
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 and Details accept plain children or a render prop (isFloating) => content; use the render prop to swap content, e.g. a vertical list in the column and a horizontal swipe strip when floating — the CSS already positions the pane",
75
- "A pane 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
- "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
- "Floating Details and the Panel are transparent: draw the surface (background, radius, shadow) in their content",
78
- "Stacking order: Panel above floating Details above the floating List strip",
79
- "Before the first measurement (server render) the layout assumes xl; on the client the measurement lands before paint",
80
- "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
- "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",
82
- "Main is position: relative, so consumers can anchor their own overlays to it",
83
- "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",
84
- "Every part throws \"[web-chat-ui] … must be used within a ChatCardThreeColumnLayout\" when rendered outside the root",
85
- "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"
86
- ]
87
- },
88
- "composition": {
89
- "allowedParents": ["web-chat-ui/ChatCardContent"],
90
- "allowedChildren": [
91
- "web-chat-ui/ChatCardThreeColumnLayoutList",
92
- "web-chat-ui/ChatCardThreeColumnLayoutMain",
93
- "web-chat-ui/ChatCardThreeColumnLayoutDetails",
94
- "web-chat-ui/ChatCardThreeColumnLayoutPanel",
95
- "ui/scroll-area",
96
- "web-map/map-view",
97
- "isFloating render prop"
98
- ],
99
- "avoidCombinations": [
100
- "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",
101
- "Hiding Details with CSS instead of unmounting it — it still reserves the third column",
102
- "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",
103
- "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\""
104
- ],
105
- "contexts": ["chat card body", "chat thread"]
106
- },
107
- "content": {
108
- "labelRules": [],
109
- "helperTextRules": [],
110
- "errorRules": []
111
- },
112
- "aiDecisionRules": [
113
- {
114
- "condition": "Building a collection + canvas + selected-item card (places on a map, rows next to a chart)",
115
- "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",
116
- "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"
117
- },
118
- {
119
- "condition": "Details floats although the window is wide, or the card overflows the chat to the right",
120
- "decision": "Check that the ChatCard has chatCardThreeColumnLayoutCardVariants() and that its web-chat-ui/chat-card-container uses variant=\"full\"",
121
- "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
- {
124
- "condition": "A pane needs different content when it floats (a vertical list in the column, a swipe strip over the map)",
125
- "decision": "Pass a render prop (isFloating) => content to List or Details; use plain children when the content is the same either way",
126
- "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
- "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
- "decision": "Mount ChatCardThreeColumnLayoutPanel conditionally while it is open, with its own surface and a close control",
131
- "reason": "Main and Details stay mounted underneath, so the map keeps its viewport and the open item survives; replacing Main would lose both"
132
- },
133
- {
134
- "condition": "The selected-item pane is secondary at every size and should never take a column",
135
- "decision": "Set detailsPlacement=\"floating\" on the root",
136
- "reason": "Details then always floats over Main while List still follows the width tiers"
137
- }
138
- ],
139
- "relatedComponents": [
140
- "web-chat-ui/chat-card-two-column-layout",
141
- "web-chat-ui/chat-card",
142
- "web-chat-ui/chat-card-container",
143
- "ui/scroll-area",
144
- "web-map/map-view",
145
- "ui/dialog"
146
- ]
147
- }
@@ -1,78 +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
- isListFloating: boolean;
44
- isDetailsFloating: boolean;
45
- isDetailsSheet: boolean;
46
- }
47
-
48
- function getSize(width: number): ChatCardThreeColumnLayoutSize {
49
- if (width >= XL_MIN_WIDTH) return 'xl';
50
- if (width >= LG_MIN_WIDTH) return 'lg';
51
- if (width >= MD_MIN_WIDTH) return 'md';
52
- return 'sm';
53
- }
54
-
55
- /**
56
- * Where each pane goes, given the width the layout actually has.
57
- *
58
- * The tiers are the original card's `md` / `lg` / `xl`, but measured on the layout, not
59
- * the viewport. The card is sized by the chat window, and a sidebar, a split view or the
60
- * Storybook panel all make the viewport claim room the card doesn't have (or the reverse).
61
- *
62
- * `'unset'` means the layout has not been measured yet (on the server, or before the first
63
- * layout effect). It resolves to `xl`: SSR HTML is mostly seen on desktops, and on the
64
- * client the measurement lands before paint.
65
- */
66
- export function resolveLayout(
67
- width: number | 'unset',
68
- detailsPlacement: ChatCardThreeColumnLayoutDetailsPlacement,
69
- ): ChatCardThreeColumnLayoutResolved {
70
- const size = width === 'unset' ? 'xl' : getSize(width);
71
-
72
- return {
73
- size,
74
- isListFloating: size === 'sm' || size === 'md',
75
- isDetailsFloating: detailsPlacement === 'floating' || size !== 'xl',
76
- isDetailsSheet: size === 'sm',
77
- };
78
- }