@swisper.ai/web-chat-ui 0.1.0 → 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 (83) hide show
  1. package/README.md +2 -5
  2. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  3. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  4. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  5. package/dist/components/rich-text-field/utils.d.ts +36 -36
  6. package/dist/index.css +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.es.js +1566 -1810
  10. package/dist/index.es.js.map +1 -1
  11. package/package.json +4 -4
  12. package/src/components/chat-card/chat-card.json +6 -6
  13. package/src/components/chat-card/chat-card.stories.tsx +6 -14
  14. package/src/components/chat-card/components/chat-card-body.tsx +1 -1
  15. package/src/components/chat-card-container/chat-card-container.json +6 -6
  16. package/src/components/chat-card-container/chat-card-container.stories.tsx +10 -18
  17. package/src/components/chat-container/chat-container.json +1 -1
  18. package/src/components/chat-list/chat-list-items.tsx +3 -3
  19. package/src/components/rich-text-field/rich-text-field.stories.tsx +3 -1
  20. package/src/index.ts +0 -1
  21. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +0 -97
  22. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +0 -1
  23. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +0 -52
  24. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +0 -1
  25. package/dist/layouts/chat-card-list-layout/index.d.ts +0 -3
  26. package/dist/layouts/chat-card-list-layout/index.d.ts.map +0 -1
  27. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +0 -89
  28. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +0 -1
  29. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +0 -44
  30. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +0 -1
  31. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +0 -62
  32. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +0 -1
  33. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +0 -81
  34. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +0 -1
  35. package/dist/layouts/chat-card-three-column-layout/index.d.ts +0 -5
  36. package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +0 -1
  37. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +0 -37
  38. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +0 -1
  39. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +0 -12
  40. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +0 -1
  41. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +0 -40
  42. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +0 -1
  43. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +0 -35
  44. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +0 -1
  45. package/dist/layouts/chat-card-two-column-layout/index.d.ts +0 -4
  46. package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +0 -1
  47. package/dist/layouts/index.d.ts +0 -4
  48. package/dist/layouts/index.d.ts.map +0 -1
  49. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +0 -112
  50. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +0 -36
  51. package/src/layouts/chat-card-list-layout/__stories__/types.ts +0 -31
  52. package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +0 -204
  53. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +0 -129
  54. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +0 -422
  55. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +0 -254
  56. package/src/layouts/chat-card-list-layout/index.ts +0 -11
  57. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +0 -117
  58. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +0 -18
  59. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +0 -85
  60. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +0 -47
  61. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +0 -44
  62. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +0 -61
  63. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +0 -35
  64. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +0 -71
  65. package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +0 -327
  66. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +0 -153
  67. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +0 -76
  68. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +0 -658
  69. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +0 -293
  70. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +0 -146
  71. package/src/layouts/chat-card-three-column-layout/index.ts +0 -24
  72. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +0 -51
  73. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +0 -83
  74. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +0 -24
  75. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +0 -15
  76. package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +0 -109
  77. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +0 -109
  78. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +0 -21
  79. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +0 -439
  80. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +0 -141
  81. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +0 -65
  82. package/src/layouts/chat-card-two-column-layout/index.ts +0 -17
  83. package/src/layouts/index.ts +0 -3
@@ -1,254 +0,0 @@
1
- import { Slot } from '@radix-ui/react-slot';
2
- import type { ComponentProps, MouseEvent, ReactNode } from 'react';
3
- import {
4
- Children,
5
- createContext,
6
- forwardRef,
7
- useCallback,
8
- useContext,
9
- useLayoutEffect,
10
- useMemo,
11
- useState,
12
- } from 'react';
13
-
14
- import { Button } from '@swisper.ai/ui';
15
- import type { ButtonProps } from '@swisper.ai/ui';
16
- import { cn } from '@swisper.ai/web-core';
17
-
18
- /**
19
- * How many items are rendered before the reveal.
20
- *
21
- * Three, because the collapsed list has to read as "there is more here" at a glance.
22
- * One or two look like the whole answer and the button gets ignored; from five up the
23
- * collapsed state is already taller than a phone viewport, which is the thing this
24
- * layout exists to prevent.
25
- */
26
- const DEFAULT_VISIBLE_COUNT = 3;
27
-
28
- interface ChatCardListLayoutContextValue {
29
- visibleCount: number;
30
- isExpanded: boolean;
31
- expand: () => void;
32
- hiddenCount: number;
33
- setHiddenCount: (count: number) => void;
34
- }
35
-
36
- const ChatCardListLayoutContext = createContext<ChatCardListLayoutContextValue>(null!);
37
-
38
- /**
39
- * Reads the layout's state from any descendant.
40
- *
41
- * Exported so a consumer can put the hidden count in their own label ("Show 5 more") or
42
- * build a trigger that isn't a `Button`. `hiddenCount` is `0` on the first render and
43
- * correct from the first layout effect onwards — see `ChatCardListLayoutItems`.
44
- */
45
- export function useChatCardListLayoutContext() {
46
- const context = useContext(ChatCardListLayoutContext);
47
-
48
- if (!context) {
49
- throw new Error(
50
- '[web-chat-ui] "useChatCardListLayoutContext" must be used within a ChatCardListLayout. ' +
51
- 'ChatCardListLayoutItems and ChatCardListLayoutShowMore both read it, so both must be ' +
52
- 'rendered inside the ChatCardListLayout element, not as siblings of it.',
53
- );
54
- }
55
-
56
- return context;
57
- }
58
-
59
- export interface ChatCardListLayoutProps extends ComponentProps<'div'> {
60
- children: ReactNode;
61
- /**
62
- * How many items `ChatCardListLayoutItems` renders while collapsed.
63
- *
64
- * Clamped at zero: a negative value would reach `Array.slice` as a count from the end
65
- * and quietly render the *last* n items, which is the opposite of what the caller
66
- * asked for.
67
- */
68
- visibleCount?: number;
69
- /**
70
- * Expanded state for the uncontrolled case. Set it when the surrounding message is
71
- * restored from history and the reader had already expanded this list.
72
- */
73
- defaultExpanded?: boolean;
74
- /**
75
- * Controlled expanded state. Pass it only if something outside owns the state —
76
- * driving it back to `false` re-collapses the list and brings the button back, which
77
- * the uncontrolled component deliberately cannot do.
78
- */
79
- expanded?: boolean;
80
- onExpandedChange?: (expanded: boolean) => void;
81
- asChild?: boolean;
82
- }
83
-
84
- /**
85
- * Holds a list of chat cards and reveals the overflow behind a one-way "show more".
86
- *
87
- * Structure and state only. By default the root stacks its children in a left-aligned
88
- * column with an 8px gap; `className` is merged last, so the consumer's direction, gap and
89
- * alignment replace those and the same layout serves a stacked card list and a horizontal
90
- * strip without a variant prop. The `group/chat-card-list-layout` marker paints nothing
91
- * and exists so descendants can react to the expanded state with
92
- * `group-data-[expanded=true]/chat-card-list-layout:…`.
93
- *
94
- * The three parts exist because the pieces of information live in different places: only
95
- * `ChatCardListLayoutItems` knows how many children there are, only
96
- * `ChatCardListLayoutShowMore` needs to know whether any are hidden, and this root owns
97
- * the state that joins them. Slicing here instead would mean telling item children apart
98
- * from the button by inspecting `child.type`, which breaks the moment either is wrapped.
99
- */
100
- export const ChatCardListLayout = forwardRef<HTMLDivElement, ChatCardListLayoutProps>(
101
- function ChatCardListLayout(
102
- {
103
- children,
104
- className,
105
- visibleCount = DEFAULT_VISIBLE_COUNT,
106
- defaultExpanded = false,
107
- expanded,
108
- onExpandedChange,
109
- asChild = false,
110
- ...rest
111
- },
112
- ref,
113
- ) {
114
- const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);
115
- const [hiddenCount, setHiddenCount] = useState(0);
116
-
117
- const isExpanded = expanded ?? internalExpanded;
118
-
119
- const expand = useCallback(() => {
120
- if (expanded === undefined) {
121
- setInternalExpanded(true);
122
- }
123
-
124
- onExpandedChange?.(true);
125
- }, [expanded, onExpandedChange]);
126
-
127
- const contextValue = useMemo(
128
- () => ({
129
- visibleCount: Math.max(0, visibleCount),
130
- isExpanded,
131
- expand,
132
- hiddenCount,
133
- setHiddenCount,
134
- }),
135
- [visibleCount, isExpanded, expand, hiddenCount],
136
- );
137
-
138
- const Component = asChild ? Slot : 'div';
139
-
140
- return (
141
- <ChatCardListLayoutContext.Provider value={contextValue}>
142
- <Component
143
- ref={ref}
144
- data-slot="chat-card-list-layout"
145
- data-testid="chat-card-list-layout"
146
- data-expanded={isExpanded}
147
- className={cn(
148
- 'group/chat-card-list-layout',
149
- 'flex flex-col items-start gap-[8px]',
150
- className,
151
- )}
152
- {...rest}
153
- >
154
- {children}
155
- </Component>
156
- </ChatCardListLayoutContext.Provider>
157
- );
158
- },
159
- );
160
-
161
- ChatCardListLayout.displayName = 'ChatCardListLayout';
162
-
163
- export interface ChatCardListLayoutItemsProps {
164
- children: ReactNode;
165
- }
166
-
167
- /**
168
- * Renders the visible slice of the list, and nothing else — no wrapper element.
169
- *
170
- * A `div` here would sit between the root's `className` and the cards, so a consumer's
171
- * `flex`/`grid` on the root would apply to this one wrapper instead of to the items and
172
- * the layout would silently collapse to a single column. There is no `className` prop
173
- * for the same reason: there is no node to hang it on.
174
- *
175
- * Hidden items are sliced away rather than hidden with CSS, so they never mount: no DOM,
176
- * no image or data fetches from cards nobody has asked for, and nothing invisible in the
177
- * tab order.
178
- *
179
- * Only one of these per layout. Two would race on `hiddenCount` and the last effect
180
- * would win; summing across instances is buildable but nothing needs it yet.
181
- */
182
- export function ChatCardListLayoutItems({ children }: ChatCardListLayoutItemsProps) {
183
- const { visibleCount, isExpanded, setHiddenCount } = useChatCardListLayoutContext();
184
-
185
- // `Children.toArray` flattens fragments and drops `null`/`undefined`/booleans, so a
186
- // conditionally rendered card counts only when it actually renders. Reading
187
- // `Children.count` instead would count the holes and the button would offer to reveal
188
- // items that do not exist.
189
- const items = Children.toArray(children);
190
- const hiddenCount = isExpanded ? 0 : Math.max(0, items.length - visibleCount);
191
-
192
- // A layout effect, not `useEffect`: `hiddenCount` starts at 0, so the button renders
193
- // `null` on the first pass and this correction has to land before the browser paints.
194
- // With `useEffect` the button would visibly pop in after the list.
195
- useLayoutEffect(() => {
196
- setHiddenCount(hiddenCount);
197
- }, [hiddenCount, setHiddenCount]);
198
-
199
- return <>{isExpanded ? items : items.slice(0, visibleCount)}</>;
200
- }
201
-
202
- export interface ChatCardListLayoutShowMoreProps extends Omit<ButtonProps, 'children'> {
203
- /**
204
- * The label. Required on purpose: a default `'Show more'` baked into the package would
205
- * be untranslatable by the app that ships it, and this is the one string in the layout
206
- * a reader actually sees.
207
- */
208
- children: ReactNode;
209
- }
210
-
211
- /**
212
- * The reveal trigger. Renders nothing once there is nothing left to reveal — either the
213
- * list is expanded, or it never overflowed — which is what makes the button a one-shot
214
- * affordance rather than a toggle.
215
- *
216
- * By default it is a small tertiary `Button` centred under the cards. Every `Button` prop
217
- * is forwarded after those defaults and `className` is merged last, so a consumer's
218
- * `variant`, `size` or classes win.
219
- */
220
- export const ChatCardListLayoutShowMore = forwardRef<
221
- // The same element union `Button` forwards: it renders a `span` when `isSemantic` is
222
- // false, and narrowing to `HTMLButtonElement` here would make a plain object ref fail
223
- // to type-check against it.
224
- HTMLButtonElement | HTMLSpanElement,
225
- ChatCardListLayoutShowMoreProps
226
- >(function ChatCardListLayoutShowMore({ children, onClick, className, ...rest }, ref) {
227
- const { isExpanded, hiddenCount, expand } = useChatCardListLayoutContext();
228
-
229
- function handleClick(event: MouseEvent<HTMLButtonElement>) {
230
- expand();
231
- onClick?.(event);
232
- }
233
-
234
- if (isExpanded || hiddenCount === 0) {
235
- return null;
236
- }
237
-
238
- return (
239
- <Button
240
- ref={ref}
241
- variant="tertiary"
242
- size="sm"
243
- data-slot="chat-card-list-layout-show-more"
244
- data-testid="chat-card-list-layout-show-more"
245
- onClick={handleClick}
246
- className={cn('mx-auto', className)}
247
- {...rest}
248
- >
249
- {children}
250
- </Button>
251
- );
252
- });
253
-
254
- ChatCardListLayoutShowMore.displayName = 'ChatCardListLayoutShowMore';
@@ -1,11 +0,0 @@
1
- export {
2
- ChatCardListLayout,
3
- ChatCardListLayoutItems,
4
- ChatCardListLayoutShowMore,
5
- useChatCardListLayoutContext,
6
- } from './chat-card-list-layout';
7
- export type {
8
- ChatCardListLayoutProps,
9
- ChatCardListLayoutItemsProps,
10
- ChatCardListLayoutShowMoreProps,
11
- } from './chat-card-list-layout';
@@ -1,117 +0,0 @@
1
- import type { RoomRate, Stay } from './types';
2
-
3
- // The first result of the search: the one a single-property card shows.
4
- export const FEATURED_STAY: Stay = {
5
- id: 'limmatblick',
6
- name: 'Hotel Limmatblick',
7
- area: 'Altstadt · 0.4 km from Zurich HB',
8
- pricePerNight: 'CHF 240',
9
- total: 'CHF 720',
10
- nights: 3,
11
- description:
12
- 'A riverside townhouse with 42 rooms, a breakfast room over the Limmat and the old town at the door.',
13
- amenities: ['Free Wi-Fi', 'Breakfast', 'Air conditioning', 'Lift'],
14
- checkIn: '15:00',
15
- checkOut: '11:00',
16
- room: 'Double room · 1 queen bed · breakfast included',
17
- cancellation: 'Free cancellation until 10 Nov',
18
- pin: { left: 46, top: 38 },
19
- };
20
-
21
- // Results of one search: a name that runs long, a rate that can't be refunded, and a property
22
- // without a map location, which gets a row but no pin.
23
- export const STAYS: Stay[] = [
24
- FEATURED_STAY,
25
- {
26
- id: 'goldener-anker',
27
- name: 'Pension Zum Goldenen Anker am Lindenhof, Altstadt Suites and Apartments',
28
- area: 'Lindenhof · 0.7 km from Zurich HB',
29
- pricePerNight: 'CHF 189',
30
- total: 'CHF 567',
31
- nights: 3,
32
- description: 'Six apartments above a courtyard, each with a kitchenette and a washing machine.',
33
- amenities: ['Kitchenette', 'Free Wi-Fi', 'Washing machine'],
34
- checkIn: '16:00',
35
- checkOut: '10:00',
36
- room: 'Studio apartment · 1 double bed',
37
- cancellation: 'Non-refundable',
38
- pin: { left: 34, top: 52 },
39
- },
40
- {
41
- id: 'seefeld-garden',
42
- name: 'Seefeld Garden Hotel',
43
- area: 'Seefeld · 2.1 km from Zurich HB',
44
- pricePerNight: 'CHF 275',
45
- total: 'CHF 825',
46
- nights: 3,
47
- description: 'A garden hotel two streets from the lake, with a sauna and bicycles to borrow.',
48
- amenities: ['Sauna', 'Breakfast', 'Bicycles', 'Free Wi-Fi', 'Garden'],
49
- checkIn: '15:00',
50
- checkOut: '12:00',
51
- room: 'Superior double · 1 king bed · breakfast included',
52
- cancellation: 'Free cancellation until 11 Nov',
53
- pin: { left: 68, top: 70 },
54
- },
55
- {
56
- id: 'wiedikon-loft',
57
- name: 'Wiedikon Loft House',
58
- area: 'Wiedikon · 2.8 km from Zurich HB',
59
- pricePerNight: 'CHF 162',
60
- total: 'CHF 486',
61
- nights: 3,
62
- description:
63
- 'Self check-in lofts in a converted print shop, ten minutes by tram from the centre.',
64
- amenities: ['Self check-in', 'Free Wi-Fi'],
65
- checkIn: '15:00',
66
- checkOut: '11:00',
67
- room: 'Loft · 2 single beds',
68
- cancellation: 'Free cancellation until 8 Nov',
69
- pin: { left: 18, top: 66 },
70
- },
71
- {
72
- id: 'uetliberg',
73
- name: 'Gasthaus Uetliblick',
74
- area: 'Uetliberg · 6.4 km from Zurich HB',
75
- pricePerNight: 'CHF 205',
76
- total: 'CHF 615',
77
- nights: 3,
78
- description: 'A hilltop guesthouse above the city, reached by the S10 and a ten-minute walk.',
79
- amenities: ['Restaurant', 'Terrace', 'Breakfast'],
80
- checkIn: '14:00',
81
- checkOut: '11:00',
82
- room: 'Twin room · 2 single beds · breakfast included',
83
- cancellation: 'Free cancellation until 9 Nov',
84
- pin: null,
85
- },
86
- ];
87
-
88
- // The rates of the featured stay, cheapest first; the suite does not say how many are left.
89
- export const ROOM_RATES: RoomRate[] = [
90
- {
91
- id: 'rate_01',
92
- room: 'Double room',
93
- bedding: '1 queen bed · breakfast included',
94
- cancellation: 'Free cancellation until 10 Nov',
95
- pricePerNight: 'CHF 240',
96
- total: 'CHF 720',
97
- roomsLeft: 3,
98
- },
99
- {
100
- id: 'rate_02',
101
- room: 'Double room with river view',
102
- bedding: '1 queen bed · breakfast included',
103
- cancellation: 'Non-refundable',
104
- pricePerNight: 'CHF 262',
105
- total: 'CHF 786',
106
- roomsLeft: 1,
107
- },
108
- {
109
- id: 'rate_03',
110
- room: 'Junior suite',
111
- bedding: '1 king bed and 1 sofa bed · breakfast included',
112
- cancellation: 'Free cancellation until 10 Nov',
113
- pricePerNight: 'CHF 318',
114
- total: 'CHF 954',
115
- roomsLeft: null,
116
- },
117
- ];
@@ -1,18 +0,0 @@
1
- import type { ReactNode } from 'react';
2
-
3
- export interface ResizableChatWindowProps {
4
- children: ReactNode;
5
- }
6
-
7
- /** A dashed box that starts 900px wide and resizes from its right edge, standing in for a chat window. */
8
- export function ResizableChatWindow({ children }: ResizableChatWindowProps) {
9
- return (
10
- <div
11
- role="group"
12
- aria-label="Resizable chat window"
13
- className="w-225 max-w-full min-w-90 resize-x overflow-auto border border-dashed border-card-border-base"
14
- >
15
- {children}
16
- </div>
17
- );
18
- }
@@ -1,85 +0,0 @@
1
- import { CloseIcon } from '@swisper.ai/icons';
2
- import { Button, Chip, IconButton, ScrollArea, Typography } from '@swisper.ai/ui';
3
- import { cn } from '@swisper.ai/web-core';
4
-
5
- import type { Stay } from './types';
6
-
7
- export interface StayDetailsProps {
8
- stay: Stay;
9
- /** Whether the Details pane floats over the map; the surface then lifts off it with a shadow. */
10
- isFloating?: boolean;
11
- /** Leave out on a card about one property, where there is no list to go back to. */
12
- onClose?: () => void;
13
- onCheckRooms?: () => void;
14
- }
15
-
16
- /** What the Details pane shows for the open property. The pane is transparent, so this draws the surface. */
17
- export function StayDetails({ stay, isFloating = false, onClose, onCheckRooms }: StayDetailsProps) {
18
- return (
19
- <div
20
- className={cn(
21
- 'flex h-full min-h-0 flex-col gap-12 rounded-10 border border-card-border-base bg-card-background-base p-12',
22
- isFloating && 'shadow-md',
23
- )}
24
- >
25
- <div className="flex items-center gap-8">
26
- <Typography variant="body-medium" fontWeight="semibold" asChild>
27
- <h3 className="line-clamp-1 min-w-0 flex-1" title={stay.name}>
28
- {stay.name}
29
- </h3>
30
- </Typography>
31
- {onClose && (
32
- <IconButton variant="tertiary" size="sm" aria-label="Close details" onClick={onClose}>
33
- <CloseIcon />
34
- </IconButton>
35
- )}
36
- </div>
37
-
38
- <ScrollArea className="min-h-0 flex-1">
39
- <div className="flex flex-col gap-12">
40
- <Typography variant="body-small-low" className="text-text-secondary">
41
- {stay.description}
42
- </Typography>
43
-
44
- <ul aria-label="Amenities" className="flex flex-wrap gap-4">
45
- {stay.amenities.map((amenity) => (
46
- <li key={amenity}>
47
- <Chip variant="outlined" size="2xs">
48
- {amenity}
49
- </Chip>
50
- </li>
51
- ))}
52
- </ul>
53
-
54
- <Typography variant="caption-md" className="text-text-tertiary">
55
- Check-in {stay.checkIn} · Check-out {stay.checkOut}
56
- </Typography>
57
-
58
- <div className="flex flex-col gap-4">
59
- <Typography variant="caption-md" className="text-text-secondary">
60
- From
61
- </Typography>
62
- <Typography variant="body-medium" fontWeight="semibold">
63
- {stay.pricePerNight} avg / night
64
- </Typography>
65
- <Typography variant="caption-md" className="text-text-secondary">
66
- {stay.total} total · {stay.nights} nights
67
- </Typography>
68
- <Typography variant="caption-md" className="text-text-secondary">
69
- {stay.room}
70
- </Typography>
71
- <Typography variant="caption-md" className="text-text-secondary">
72
- {stay.cancellation}
73
- </Typography>
74
- </div>
75
- </div>
76
- </ScrollArea>
77
-
78
- {onCheckRooms && (
79
- <Button variant="secondary" size="md" onClick={onCheckRooms}>
80
- Check other rooms
81
- </Button>
82
- )}
83
- </div>
84
- );
85
- }
@@ -1,47 +0,0 @@
1
- import { ScrollArea, Typography } from '@swisper.ai/ui';
2
-
3
- import type { Stay } from './types';
4
-
5
- export interface StayListProps {
6
- stays: Stay[];
7
- selectedId: string | null;
8
- onOpen: (stayId: string) => void;
9
- }
10
-
11
- /** The search results: a scrolling column of rows. */
12
- export function StayList({ stays, selectedId, onOpen }: StayListProps) {
13
- const list = (
14
- <ul className="flex flex-col gap-8">
15
- {stays.map((stay) => (
16
- <li key={stay.id}>
17
- <button
18
- type="button"
19
- aria-pressed={stay.id === selectedId}
20
- onClick={() => onOpen(stay.id)}
21
- className="flex w-full flex-col gap-2 rounded-10 border border-card-border-base bg-card-background-base p-12 text-left hover:bg-card-background-lvl-2 focus-visible:ring-2 focus-visible:ring-primary-focus-visible focus-visible:outline-none aria-pressed:border-primary-main"
22
- >
23
- <Typography
24
- variant="body-small-high"
25
- fontWeight="medium"
26
- className="line-clamp-1"
27
- asChild
28
- >
29
- <span>{stay.name}</span>
30
- </Typography>
31
- <Typography variant="caption-md" className="line-clamp-1 text-text-secondary" asChild>
32
- <span>{stay.pin ? stay.area : `${stay.area} · Not on the map`}</span>
33
- </Typography>
34
- <Typography variant="caption-md" className="text-text-secondary" asChild>
35
- <span>
36
- {stay.pricePerNight} avg / night · {stay.total} total
37
- </span>
38
- </Typography>
39
- </button>
40
- </li>
41
- ))}
42
- </ul>
43
- );
44
-
45
- // The scroll area keeps a long list inside the column's row.
46
- return <ScrollArea className="h-full">{list}</ScrollArea>;
47
- }
@@ -1,44 +0,0 @@
1
- import { Button, Typography } from '@swisper.ai/ui';
2
-
3
- import type { Stay } from './types';
4
-
5
- export interface StayMapProps {
6
- stays: Stay[];
7
- selectedId: string | null;
8
- onOpen: (stayId: string) => void;
9
- }
10
-
11
- /** Stands in for the map: one price pin per property that has a location, and a note for the rest. */
12
- export function StayMap({ stays, selectedId, onOpen }: StayMapProps) {
13
- const unpinnedCount = stays.filter((stay) => stay.pin === null).length;
14
-
15
- return (
16
- <div className="relative h-full w-full overflow-hidden rounded-10 bg-card-background-lvl-2">
17
- {stays.map(
18
- (stay) =>
19
- stay.pin && (
20
- <Button
21
- key={stay.id}
22
- size="sm"
23
- variant={stay.id === selectedId ? 'primary' : 'secondary'}
24
- aria-label={`${stay.name}, ${stay.pricePerNight} avg / night`}
25
- className="absolute"
26
- style={{ left: `${stay.pin.left}%`, top: `${stay.pin.top}%` }}
27
- onClick={() => onOpen(stay.id)}
28
- >
29
- {stay.pricePerNight}
30
- </Button>
31
- ),
32
- )}
33
-
34
- {unpinnedCount > 0 && (
35
- <Typography
36
- variant="caption-md"
37
- className="absolute top-10 left-10 rounded-10 bg-global-bg/90 px-10 py-4 text-text-secondary"
38
- >
39
- {unpinnedCount} of these {unpinnedCount === 1 ? 'has' : 'have'} no map location
40
- </Typography>
41
- )}
42
- </div>
43
- );
44
- }
@@ -1,61 +0,0 @@
1
- import { Button, ScrollArea, Typography } from '@swisper.ai/ui';
2
-
3
- import type { RoomRate, Stay } from './types';
4
-
5
- export interface StayRoomsProps {
6
- stay: Stay;
7
- rates: RoomRate[];
8
- onBack: () => void;
9
- }
10
-
11
- /** The view the Panel holds: every rate of the open property, and the control that closes the Panel. */
12
- export function StayRooms({ stay, rates, onBack }: StayRoomsProps) {
13
- return (
14
- <div className="flex h-full min-h-0 flex-col gap-12 rounded-10 border border-card-border-base bg-card-background-base p-12 shadow-md">
15
- <div className="flex items-center justify-between gap-12">
16
- <Typography variant="body-medium" fontWeight="semibold" asChild>
17
- <h3 className="line-clamp-1 min-w-0">Rooms at {stay.name}</h3>
18
- </Typography>
19
- <Button variant="tertiary" size="sm" className="shrink-0" onClick={onBack}>
20
- Back to the property
21
- </Button>
22
- </div>
23
-
24
- <ScrollArea className="min-h-0 flex-1">
25
- <ul className="flex flex-col gap-8">
26
- {rates.map((rate) => (
27
- <li
28
- key={rate.id}
29
- className="flex items-start justify-between gap-12 rounded-10 border border-card-border-base p-12"
30
- >
31
- <div className="flex min-w-0 flex-col gap-2">
32
- <Typography variant="body-small-high" fontWeight="medium">
33
- {rate.room}
34
- </Typography>
35
- <Typography variant="caption-md" className="text-text-secondary">
36
- {rate.bedding}
37
- </Typography>
38
- <Typography variant="caption-md" className="text-text-secondary">
39
- {rate.cancellation}
40
- </Typography>
41
- </div>
42
- <div className="flex shrink-0 flex-col items-end gap-2">
43
- <Typography variant="body-small-high" fontWeight="semibold">
44
- {rate.pricePerNight} avg / night
45
- </Typography>
46
- <Typography variant="caption-md" className="text-text-secondary">
47
- {rate.total} total
48
- </Typography>
49
- {rate.roomsLeft !== null && (
50
- <Typography variant="caption-md" className="text-text-tertiary">
51
- {rate.roomsLeft} left
52
- </Typography>
53
- )}
54
- </div>
55
- </li>
56
- ))}
57
- </ul>
58
- </ScrollArea>
59
- </div>
60
- );
61
- }
@@ -1,35 +0,0 @@
1
- /** Where a stay's price pin sits on the map stand-in, in percent of the map's box. */
2
- export interface StayPin {
3
- left: number;
4
- top: number;
5
- }
6
-
7
- /** One property of an accommodation search, trimmed to what the list, the map and Details render. */
8
- export interface Stay {
9
- id: string;
10
- name: string;
11
- area: string;
12
- pricePerNight: string;
13
- total: string;
14
- nights: number;
15
- description: string;
16
- amenities: string[];
17
- checkIn: string;
18
- checkOut: string;
19
- room: string;
20
- cancellation: string;
21
- /** `null` when the property has no map location, so it gets a row but no pin. */
22
- pin: StayPin | null;
23
- }
24
-
25
- /** One bookable rate of a property, as the rooms view lists it. */
26
- export interface RoomRate {
27
- id: string;
28
- room: string;
29
- bedding: string;
30
- cancellation: string;
31
- pricePerNight: string;
32
- total: string;
33
- /** `null` when the supplier does not say how many are left. */
34
- roomsLeft: number | null;
35
- }