@aircall/ds 0.50.0 → 0.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{data-table-BgeS8KWP.d.ts → data-table-B5VqWPmw.d.ts} +3 -4
- package/dist/data-table.d.ts +1 -1
- package/dist/globals.css +1 -1
- package/dist/index.d.ts +12 -9
- package/dist/index.js +11 -8
- package/package.json +2 -2
- package/skills/aircall-ds/migrate-audio-player/SKILL.md +14 -3
- package/skills/aircall-ds/migrate-icons/SKILL.md +45 -16
- package/skills/aircall-ds/migrate-tractor/SKILL.md +34 -31
- package/skills/aircall-ds/migrate-tractor/accordion/SKILL.md +25 -15
- package/skills/aircall-ds/migrate-tractor/alert/SKILL.md +107 -20
- package/skills/aircall-ds/migrate-tractor/avatar/SKILL.md +57 -26
- package/skills/aircall-ds/migrate-tractor/badge/SKILL.md +71 -25
- package/skills/aircall-ds/migrate-tractor/button/SKILL.md +68 -32
- package/skills/aircall-ds/migrate-tractor/card/SKILL.md +62 -42
- package/skills/aircall-ds/migrate-tractor/combobox/SKILL.md +233 -149
- package/skills/aircall-ds/migrate-tractor/data-table/SKILL.md +102 -108
- package/skills/aircall-ds/migrate-tractor/data-table/references/column-widths-and-pinning.md +50 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/infinite-scroll.md +51 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/row-actions.md +34 -0
- package/skills/aircall-ds/migrate-tractor/date-picker/SKILL.md +100 -47
- package/skills/aircall-ds/migrate-tractor/dialog/SKILL.md +115 -20
- package/skills/aircall-ds/migrate-tractor/dropdown-menu/SKILL.md +135 -57
- package/skills/aircall-ds/migrate-tractor/dropzone/SKILL.md +2 -0
- package/skills/aircall-ds/migrate-tractor/form-and-field/SKILL.md +111 -49
- package/skills/aircall-ds/migrate-tractor/gauge/SKILL.md +6 -4
- package/skills/aircall-ds/migrate-tractor/input/SKILL.md +165 -59
- package/skills/aircall-ds/migrate-tractor/item/SKILL.md +85 -63
- package/skills/aircall-ds/migrate-tractor/link/SKILL.md +85 -68
- package/skills/aircall-ds/migrate-tractor/popover/SKILL.md +115 -74
- package/skills/aircall-ds/migrate-tractor/select/SKILL.md +117 -64
- package/skills/aircall-ds/migrate-tractor/sheet-vs-drawer/SKILL.md +55 -32
- package/skills/aircall-ds/migrate-tractor/skeleton/SKILL.md +40 -11
- package/skills/aircall-ds/migrate-tractor/styling/SKILL.md +11 -7
- package/skills/aircall-ds/migrate-tractor/tabs/SKILL.md +62 -55
- package/skills/aircall-ds/migrate-tractor/toast/SKILL.md +58 -12
- package/skills/aircall-ds/migrate-tractor/tooltip/SKILL.md +65 -40
- package/skills/aircall-ds/migrate-tractor/tree/SKILL.md +23 -6
- package/skills/aircall-ds/setup/SKILL.md +53 -8
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: aircall-ds/migrate-tractor/popover
|
|
3
3
|
description: >
|
|
4
|
-
Migrate Tractor Popover (
|
|
5
|
-
@aircall/ds Popover compound (Popover,
|
|
6
|
-
|
|
4
|
+
Migrate Tractor Popover (Popover.Root / Popover.Trigger / Popover.Content / Popover.Arrow,
|
|
5
|
+
and a Dropdown that holds arbitrary content) to the @aircall/ds Popover compound (Popover,
|
|
6
|
+
PopoverTrigger, PopoverContent, PopoverHeader, PopoverTitle, PopoverDescription,
|
|
7
|
+
PopoverClose). Load when a file imports Popover from @aircall/tractor, or a Dropdown
|
|
8
|
+
whose children are not a menu.
|
|
7
9
|
type: sub-skill
|
|
8
10
|
library: aircall-ds
|
|
9
11
|
requires:
|
|
@@ -11,28 +13,38 @@ requires:
|
|
|
11
13
|
- aircall-ds/migrate-tractor
|
|
12
14
|
sources:
|
|
13
15
|
- "aircall/hydra:docs/migration-guides/tractor-to-ds/recipes/popover.md"
|
|
16
|
+
- "aircall/hydra:packages/ds/src/components/popover.tsx"
|
|
17
|
+
- "aircall/hydra:packages/ds/src/stories/Popover.stories.tsx"
|
|
14
18
|
---
|
|
15
19
|
|
|
16
20
|
This skill builds on aircall-ds/migrate-tractor. Apply all cross-cutting rules from that skill (prop renames, `render` prop, data attributes) before the popover-specific steps below.
|
|
17
21
|
|
|
18
22
|
## 1. Component mapping
|
|
19
23
|
|
|
20
|
-
Tractor `Popover`
|
|
24
|
+
Tractor `Popover` is already a compound of four parts, rendered by hand: `Popover.Root` (state), `Popover.Trigger` (clones its single child and injects a ref and `onClick`), `Popover.Content` (the panel, mounted only while open; you style its surface with Flex/Box props) and `Popover.Arrow`. Positioning is `side` / `align` / `sideOffset` / `alignOffset` on `Popover.Content`, and there is no `content` or `placement` prop. DS keeps the compound but moves the surface into the component and the trigger behaviour into the Base UI `render` prop.
|
|
21
25
|
|
|
22
26
|
| Tractor | @aircall/ds | Role |
|
|
23
27
|
| --- | --- | --- |
|
|
24
|
-
| `<Popover>` | `<Popover>` | State owner
|
|
25
|
-
|
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
| _(no equivalent)_ |
|
|
29
|
-
|
|
|
30
|
-
|
|
|
28
|
+
| `<Popover.Root open defaultOpen onOpenChange>` | `<Popover open defaultOpen onOpenChange>` | State owner |
|
|
29
|
+
| `<Popover.Trigger><Button/></Popover.Trigger>` | `<PopoverTrigger render={<Button />}>label</PopoverTrigger>` | The anchor. The label moves from the trigger's child to `PopoverTrigger`'s children |
|
|
30
|
+
| `{open && <Popover.Content …>}` | `<PopoverContent>` | The floating panel. Always render it; the open state is handled for you (no `{open && …}` guard) |
|
|
31
|
+
| `side`, `align`, `sideOffset`, `alignOffset` on `Popover.Content` | the same four props on `<PopoverContent>` | Same names, same values (`top`/`right`/`bottom`/`left`, `start`/`center`/`end`). **Defaults differ**, see §5 |
|
|
32
|
+
| `Popover.Arrow` | _(no equivalent)_ | DS popovers have no arrow: delete it |
|
|
33
|
+
| `bg`, `boxShadow`, `borderRadius`, `p`, `w`, `maxW` Flex/Box props on the content | built in / `className` | Surface is provided (§6); size and padding via Tailwind `className` |
|
|
34
|
+
| `takeTriggerWidth` | `className="w-(--anchor-width)"` on `PopoverContent` | Positioner CSS variable |
|
|
35
|
+
| `closeOnOutsideClick` (default `true`) | built in | Outside press and Escape always close it |
|
|
36
|
+
| `closeOnInsideClick` | `<PopoverClose>` around the control that should close it, or controlled `open` | Default is the same as Tractor's (clicks inside do not close) |
|
|
37
|
+
| `closeOnScroll` (default `true`) | _(no equivalent)_ | No scroll-close prop; control `open` yourself if a flow needs it |
|
|
38
|
+
| `portalled`, `zIndex`, `portalContainerRef` | _(drop them)_ | `PopoverContent` always portals and uses the `z-popup` layer |
|
|
39
|
+
| `avoidCollisions`, `collisionTolerance` | _(drop them)_ | Collision handling is on by default |
|
|
40
|
+
| `<Dropdown trigger={…}>` holding non-menu content | `Popover` | A `Dropdown` whose children are a `Menu` is a `DropdownMenu` instead (`aircall-ds/migrate-tractor/dropdown-menu`) |
|
|
41
|
+
| _(no equivalent)_ | `<PopoverHeader>` / `<PopoverTitle>` / `<PopoverDescription>` | Optional structured header; the title also names the popup for assistive tech |
|
|
42
|
+
| _(no equivalent)_ | `<PopoverClose>` | A button that closes the popover (required in `modal="trap-focus"`) |
|
|
31
43
|
|
|
32
44
|
## 2. Verified DS exports (`packages/ds/src/index.ts`)
|
|
33
45
|
|
|
34
46
|
```
|
|
35
|
-
Popover, PopoverContent, PopoverDescription,
|
|
47
|
+
Popover, PopoverClose, PopoverContent, PopoverDescription,
|
|
36
48
|
PopoverHeader, PopoverTitle, PopoverTrigger
|
|
37
49
|
```
|
|
38
50
|
|
|
@@ -56,27 +68,29 @@ import {
|
|
|
56
68
|
|
|
57
69
|
```tsx
|
|
58
70
|
// Before
|
|
59
|
-
import { Popover, Button } from '@aircall/tractor';
|
|
60
|
-
|
|
61
|
-
<Popover
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
>
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
import { Popover, Button, Typography } from '@aircall/tractor';
|
|
72
|
+
|
|
73
|
+
<Popover.Root>
|
|
74
|
+
<Popover.Trigger>
|
|
75
|
+
<Button variant="secondary" mode="outline">Open</Button>
|
|
76
|
+
</Popover.Trigger>
|
|
77
|
+
<Popover.Content side="bottom" align="start" sideOffset={8} bg="white" boxShadow={1} borderRadius="sm" p="m">
|
|
78
|
+
<Typography variant="headingBoldS">Title</Typography>
|
|
79
|
+
<Typography>A short description.</Typography>
|
|
80
|
+
<Typography>Body content.</Typography>
|
|
81
|
+
</Popover.Content>
|
|
82
|
+
</Popover.Root>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Note that `Popover.Content` only mounts while the popover is open. Tractor's own pattern of controlling it with `{isOpen && <Popover.Content>…}` is not needed in DS.
|
|
73
86
|
|
|
87
|
+
```tsx
|
|
74
88
|
// After
|
|
75
89
|
import { Popover, PopoverContent, PopoverHeader, PopoverTitle, PopoverDescription, PopoverTrigger, Button } from '@aircall/ds';
|
|
76
90
|
|
|
77
91
|
<Popover>
|
|
78
92
|
<PopoverTrigger render={<Button variant="outline" />}>Open</PopoverTrigger>
|
|
79
|
-
<PopoverContent side="bottom" align="start">
|
|
93
|
+
<PopoverContent side="bottom" align="start" sideOffset={8}>
|
|
80
94
|
<PopoverHeader>
|
|
81
95
|
<PopoverTitle>Title</PopoverTitle>
|
|
82
96
|
<PopoverDescription>A short description.</PopoverDescription>
|
|
@@ -86,20 +100,24 @@ import { Popover, PopoverContent, PopoverHeader, PopoverTitle, PopoverDescriptio
|
|
|
86
100
|
</Popover>
|
|
87
101
|
```
|
|
88
102
|
|
|
89
|
-
### Controlled
|
|
103
|
+
### Controlled
|
|
90
104
|
|
|
91
105
|
```tsx
|
|
92
106
|
// Before
|
|
93
|
-
import { Popover, Button } from '@aircall/tractor';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
>
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
import { Popover, Button, Typography } from '@aircall/tractor';
|
|
108
|
+
|
|
109
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
110
|
+
|
|
111
|
+
<Popover.Root open={isOpen} onOpenChange={setIsOpen}>
|
|
112
|
+
<Popover.Trigger onClick={() => setIsOpen(o => !o)}>
|
|
113
|
+
<Button variant="primary">Settings</Button>
|
|
114
|
+
</Popover.Trigger>
|
|
115
|
+
{isOpen && (
|
|
116
|
+
<Popover.Content side="top" bg="white" boxShadow={1} borderRadius="sm" p="m">
|
|
117
|
+
<Typography>Settings panel</Typography>
|
|
118
|
+
</Popover.Content>
|
|
119
|
+
)}
|
|
120
|
+
</Popover.Root>
|
|
103
121
|
|
|
104
122
|
// After
|
|
105
123
|
import { Popover, PopoverContent, PopoverTrigger, Button } from '@aircall/ds';
|
|
@@ -113,46 +131,48 @@ import { Popover, PopoverContent, PopoverTrigger, Button } from '@aircall/ds';
|
|
|
113
131
|
```
|
|
114
132
|
|
|
115
133
|
Key changes:
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
- Tractor's trigger child becomes `<PopoverTrigger render={<Button />}>` — label goes on `PopoverTrigger`, not inside the `render` element
|
|
119
|
-
- `
|
|
134
|
+
- `open` / `defaultOpen` / `onOpenChange` keep their names; `onOpenChange` receives `(open, eventDetails)` (use `eventDetails.reason` to tell an outside press from Escape).
|
|
135
|
+
- The manual `onClick` toggle on the trigger and the `{isOpen && …}` guard are both gone: `PopoverTrigger` toggles the popover and the root mounts the panel.
|
|
136
|
+
- Tractor's trigger child becomes `<PopoverTrigger render={<Button />}>` — the label goes on `PopoverTrigger`, not inside the `render` element. Any element works as `render` (a `Button`, an `Avatar` wrapper, an `Input`), and it no longer needs to forward a ref (Tractor's contract); Base UI wires it.
|
|
137
|
+
- `Popover.Content` Flex/Box styling props (`bg`, `p`, `boxShadow`, `borderRadius`) are deleted; the panel provides them.
|
|
120
138
|
|
|
121
139
|
## 5. Positioning
|
|
122
140
|
|
|
123
|
-
Tractor's
|
|
141
|
+
`side` and `align` are the same props with the same values as Tractor's `Popover.Content`, so a Tractor call site carries them over. Only the defaults change:
|
|
124
142
|
|
|
125
|
-
|
|
|
143
|
+
| Prop | Tractor `Popover.Content` default | DS `PopoverContent` default |
|
|
126
144
|
| --- | --- | --- |
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
| `"left"` | `"left"` | `"center"` (default) |
|
|
134
|
-
| `"right"` | `"right"` | `"center"` (default) |
|
|
145
|
+
| `side` | `"bottom"` | `"bottom"` |
|
|
146
|
+
| `align` | `"center"` | `"center"` |
|
|
147
|
+
| `sideOffset` | `0` (Dropdown: `8`) | `4` |
|
|
148
|
+
| `alignOffset` | _unset_ | `0` |
|
|
149
|
+
|
|
150
|
+
Pass `sideOffset={8}` where the old content used the Dropdown's `8` gap. Tractor accepted `side` of `top | right | bottom | left` and `align` of `start | center | end`; DS takes the same.
|
|
135
151
|
|
|
136
|
-
|
|
152
|
+
To anchor to an element other than the trigger, pass `anchor` (a ref, element or virtual element) to `PopoverContent`.
|
|
137
153
|
|
|
138
154
|
## 6. Panel surface
|
|
139
155
|
|
|
140
|
-
`PopoverContent` ships its own surface
|
|
156
|
+
`PopoverContent` ships its own surface and layout: `w-72` (288px), `p-4`, `flex flex-col gap-4`, `rounded-md`, `bg-popover`, `ring-1`, `shadow-md`, `text-sm`. Do not re-add a wrapper `<div>` with manual padding, background or border inside it; it will double the spacing and styling. Change the width with `className` (`w-48`, `w-80`, `w-(--anchor-width)`). Because the panel is a column with a `gap-4`, stack sections as direct children and let the gap space them, or group a title and description in `PopoverHeader`.
|
|
157
|
+
|
|
158
|
+
The panel is non-modal by default (the page behind stays interactive). `modal` on `Popover` takes `false | true | 'trap-focus'`; `'trap-focus'` needs a `PopoverClose` inside the content.
|
|
141
159
|
|
|
142
160
|
---
|
|
143
161
|
|
|
144
162
|
## 7. Common mistakes
|
|
145
163
|
|
|
146
|
-
### Mistake 1 — Keeping `
|
|
164
|
+
### Mistake 1 — Keeping the `{isOpen && …}` guard or the `content` prop
|
|
147
165
|
|
|
148
166
|
```tsx
|
|
149
|
-
// Wrong — content prop
|
|
150
|
-
<Popover content={<p>Body content.</p>}>
|
|
167
|
+
// Wrong — there is no `content` prop, and the manual guard defeats the open/close animation
|
|
168
|
+
<Popover open={isOpen} content={<p>Body content.</p>}>
|
|
151
169
|
<PopoverTrigger render={<Button variant="outline" />}>Open</PopoverTrigger>
|
|
152
170
|
</Popover>
|
|
171
|
+
// also wrong
|
|
172
|
+
{isOpen && <PopoverContent>…</PopoverContent>}
|
|
153
173
|
|
|
154
|
-
// Correct — panel content is children of PopoverContent
|
|
155
|
-
<Popover>
|
|
174
|
+
// Correct — panel content is children of PopoverContent, always rendered inside Popover
|
|
175
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
156
176
|
<PopoverTrigger render={<Button variant="outline" />}>Open</PopoverTrigger>
|
|
157
177
|
<PopoverContent>
|
|
158
178
|
<p>Body content.</p>
|
|
@@ -160,7 +180,7 @@ Defaults when omitted: `side="bottom"`, `align="center"`, `sideOffset={4}`. Fine
|
|
|
160
180
|
</Popover>
|
|
161
181
|
```
|
|
162
182
|
|
|
163
|
-
The DS
|
|
183
|
+
The DS `Popover` has no `content` prop; `PopoverContent` is a child of `Popover` and Base UI mounts and unmounts it with the open state (including the exit animation). Move any JSX that Tractor passed as popover content into `PopoverContent`.
|
|
164
184
|
|
|
165
185
|
Source: `packages/ds/src/components/popover.tsx`
|
|
166
186
|
|
|
@@ -169,45 +189,66 @@ Source: `packages/ds/src/components/popover.tsx`
|
|
|
169
189
|
### Mistake 2 — Putting the label inside the `render` Button instead of `PopoverTrigger`
|
|
170
190
|
|
|
171
191
|
```tsx
|
|
172
|
-
// Wrong — label
|
|
192
|
+
// Wrong — the label is in the render element's children, which Base UI replaces
|
|
173
193
|
<PopoverTrigger render={<Button variant="outline">Open</Button>} />
|
|
174
194
|
|
|
175
195
|
// Correct — label is a child of PopoverTrigger; it is merged into the rendered Button
|
|
176
196
|
<PopoverTrigger render={<Button variant="outline" />}>Open</PopoverTrigger>
|
|
177
197
|
```
|
|
178
198
|
|
|
179
|
-
`PopoverTrigger` uses the Base UI `render` prop pattern: it
|
|
199
|
+
`PopoverTrigger` uses the Base UI `render` prop pattern: it builds its own button from its props and children and merges them over the element passed as `render`. The visible label must be the child of `PopoverTrigger`; children of the element inside `render` are dropped, so the button renders empty.
|
|
180
200
|
|
|
181
201
|
Source: `packages/ds/src/components/popover.tsx`
|
|
182
202
|
|
|
183
203
|
---
|
|
184
204
|
|
|
185
|
-
### Mistake 3 —
|
|
205
|
+
### Mistake 3 — Styling the panel with Tractor Flex props, or wrapping the content in a styled div
|
|
186
206
|
|
|
187
207
|
```tsx
|
|
188
|
-
// Wrong —
|
|
189
|
-
<PopoverContent
|
|
208
|
+
// Wrong — Flex/Box props mean nothing to PopoverContent, and the extra wrapper doubles padding
|
|
209
|
+
<PopoverContent bg="white" boxShadow={1} borderRadius="sm" p="m">
|
|
210
|
+
<div className="rounded-md border bg-white p-4 shadow">…</div>
|
|
211
|
+
</PopoverContent>
|
|
190
212
|
|
|
191
|
-
// Correct —
|
|
192
|
-
<PopoverContent
|
|
213
|
+
// Correct — the panel already has the surface; size it with className
|
|
214
|
+
<PopoverContent className="w-80">…</PopoverContent>
|
|
193
215
|
```
|
|
194
216
|
|
|
195
|
-
|
|
217
|
+
`bg`, `boxShadow`, `borderRadius`, `p` and the other Tractor style props are `@xstyled` props, not DOM attributes and not `PopoverContent` props: they type-error and have no styling effect. Delete them, and delete any wrapper that repeats the surface.
|
|
196
218
|
|
|
197
219
|
Source: `packages/ds/src/components/popover.tsx`
|
|
198
220
|
|
|
199
221
|
---
|
|
200
222
|
|
|
201
|
-
### Mistake 4 —
|
|
223
|
+
### Mistake 4 — Carrying over `closeOnScroll`, `portalled`, `takeTriggerWidth` and other Tractor-only props
|
|
202
224
|
|
|
203
225
|
```tsx
|
|
204
|
-
// Wrong —
|
|
205
|
-
<
|
|
226
|
+
// Wrong — none of these exist on PopoverContent
|
|
227
|
+
<PopoverContent closeOnScroll portalled takeTriggerWidth avoidCollisions zIndex={10}>…</PopoverContent>
|
|
228
|
+
|
|
229
|
+
// Correct — width follows the trigger via the positioner variable; the rest is built in
|
|
230
|
+
<PopoverContent className="w-(--anchor-width)">…</PopoverContent>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`PopoverContent` accepts the Base UI popup props plus `side`, `align`, `sideOffset`, `alignOffset` and `anchor`. It always portals and handles collisions itself. If a flow depended on `closeOnInsideClick`, control it with `open`/`onOpenChange` or put a `PopoverClose` on the control that should close it.
|
|
234
|
+
|
|
235
|
+
Source: `packages/ds/src/components/popover.tsx`
|
|
236
|
+
|
|
237
|
+
---
|
|
206
238
|
|
|
207
|
-
|
|
208
|
-
|
|
239
|
+
### Mistake 5 — Using `Popover` for a list of actions
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
// Wrong — a list of actions in a popover has no menu semantics or arrow-key navigation
|
|
243
|
+
<PopoverContent>
|
|
244
|
+
<Button variant="ghost" onClick={edit}>Edit</Button>
|
|
245
|
+
<Button variant="ghost" onClick={remove}>Delete</Button>
|
|
246
|
+
</PopoverContent>
|
|
247
|
+
|
|
248
|
+
// Correct
|
|
249
|
+
<DropdownMenu>…<DropdownMenuItem>Edit</DropdownMenuItem>…</DropdownMenu>
|
|
209
250
|
```
|
|
210
251
|
|
|
211
|
-
|
|
252
|
+
Use `Popover` for arbitrary content (forms, filters, a calendar, a `DataTree`) and `DropdownMenu` for a list of actions. A searchable list of options is a `Combobox`.
|
|
212
253
|
|
|
213
254
|
Source: `packages/ds/src/components/popover.tsx`
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: aircall-ds/migrate-tractor/select
|
|
3
3
|
description: >
|
|
4
|
-
Migrate Tractor Select
|
|
5
|
-
imports Select from @aircall/tractor
|
|
6
|
-
|
|
4
|
+
Migrate Tractor Select (options-array API) and the @dashboard/library Select/SelectField to
|
|
5
|
+
the @aircall/ds Select compound. Load when a file imports Select from @aircall/tractor or
|
|
6
|
+
@dashboard/library. Covers the compound parts, the `items` prop that makes SelectValue show
|
|
7
|
+
labels, the nullable onValueChange, and the Group-wraps-Label rule.
|
|
7
8
|
type: sub-skill
|
|
8
9
|
library: aircall-ds
|
|
9
10
|
requires:
|
|
@@ -11,23 +12,32 @@ requires:
|
|
|
11
12
|
- aircall-ds/migrate-tractor
|
|
12
13
|
sources:
|
|
13
14
|
- "aircall/hydra:docs/migration-guides/tractor-to-ds/recipes/select.md"
|
|
15
|
+
- "aircall/hydra:packages/ds/src/components/select.tsx"
|
|
16
|
+
- "aircall/hydra:packages/ds/src/stories/Select.stories.tsx"
|
|
17
|
+
- "aircall/hydra:packages/blocks/src/components/form-select-field.tsx"
|
|
18
|
+
- "aircall/hydra:packages/tractor/src/components/Select/Select.decl.ts"
|
|
14
19
|
---
|
|
15
20
|
|
|
16
21
|
This skill builds on aircall-ds/migrate-tractor. Apply all cross-cutting rules from that skill (prop renames, `render` prop, data attributes) before the select-specific steps below.
|
|
17
22
|
|
|
23
|
+
For a form that collects and submits data, use `@aircall/blocks` `FormSelectField` and spread its `selectProps` onto `Select` and `selectTriggerProps` (`id`, `onBlur`, `aria-invalid`) onto `SelectTrigger`; it handles the `null` value and the label/`id` pairing. See `@aircall/blocks#aircall-blocks/migrate-dashboard/form-wizard`. The snippets below are the bare primitives.
|
|
24
|
+
|
|
18
25
|
## 1. Component mapping
|
|
19
26
|
|
|
20
|
-
Tractor `Select`
|
|
27
|
+
Tractor `Select` is a **single component driven by an `options` array** (there is no `SelectOption` child component in current Tractor; `@dashboard/library`'s `Select` wraps it and `SelectField` adds a `FormItem` + react-final-form). DS uses a compound structure where each visual slot is a named part and the options are `SelectItem` children:
|
|
21
28
|
|
|
22
29
|
| Tractor | DS compound part | Role |
|
|
23
30
|
| --- | --- | --- |
|
|
24
|
-
| `<Select
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
+
| `<Select options selectedKeys …>` | `<Select items value onValueChange>` | State owner (value, open, disabled). `items` is the label lookup (§4) |
|
|
32
|
+
| built-in trigger / `trigger` prop | `<SelectTrigger>` | Visible field / button (`w-fit` by default; add `className="w-full"` for Tractor's `w="100%"`) |
|
|
33
|
+
| `placeholder` | `<SelectValue placeholder>` | Renders current label or placeholder |
|
|
34
|
+
| built-in dropdown | `<SelectContent>` | Dropdown container |
|
|
35
|
+
| `options[]` entry `{ label, value }` | `<SelectItem value>label</SelectItem>` | Individual option |
|
|
36
|
+
| `OptionGroup` `{ label, options }` | `<SelectGroup>` + `<SelectLabel>` + `SelectItem`s | Labelled section; `SelectLabel` MUST be inside a `SelectGroup` |
|
|
37
|
+
| group `divider` | `<SelectSeparator>` | Rule between groups |
|
|
38
|
+
| `renderOption`, option `prefix`/`suffix` | children of `SelectItem` | Icons / extra nodes inside the item |
|
|
39
|
+
| `searchable`, `searchOptions` | use `Combobox` / `DataCombobox` instead | See §7 |
|
|
40
|
+
| `selectionMode="multiple"` | use `Combobox` with `multiple` instead | See §7 |
|
|
31
41
|
|
|
32
42
|
## 2. Verified DS exports (`packages/ds/src/index.ts`)
|
|
33
43
|
|
|
@@ -49,6 +59,7 @@ import {
|
|
|
49
59
|
SelectGroup,
|
|
50
60
|
SelectItem,
|
|
51
61
|
SelectLabel,
|
|
62
|
+
SelectSeparator,
|
|
52
63
|
SelectTrigger,
|
|
53
64
|
SelectValue,
|
|
54
65
|
} from '@aircall/ds';
|
|
@@ -58,26 +69,35 @@ import {
|
|
|
58
69
|
|
|
59
70
|
| Tractor prop | DS prop | Notes |
|
|
60
71
|
| --- | --- | --- |
|
|
61
|
-
| `
|
|
72
|
+
| `options` | `items` on `<Select>` **and** `<SelectItem>` children | `items` (`{ value, label }[]`, a `Record<value, label>`, or grouped `{ items }[]`) lets `SelectValue` show the **label**. Without it the trigger shows the raw `value` (§9 Mistake 5) |
|
|
73
|
+
| `selectedKeys={[v]}` / `defaultSelectedKeys` | `value={v}` / `defaultValue` | A single value, not an array. Use `null` (not `undefined`) for "nothing selected" on a controlled select |
|
|
74
|
+
| `onSelectionChange(keys[])` / `onItemSelected` | `onValueChange(value, eventDetails)` | Signature change — see Mistake 1 |
|
|
62
75
|
| `placeholder` on `<Select>` | `placeholder` on `<SelectValue>` | Moved to the value part |
|
|
63
|
-
| `
|
|
76
|
+
| `size="small"\|"regular"\|"large"` | `size="default"\|"sm"` on `<SelectTrigger>` | §6 |
|
|
77
|
+
| `validationStatus="error"` | `aria-invalid` on `<SelectTrigger>` | Same ARIA convention as `Input` |
|
|
78
|
+
| `disabled` | `disabled` on `<Select>` | |
|
|
79
|
+
| `getOptionLabel` / `getOptionValue` | _(removed)_ | No accessor props on the DS `Select`; map your array into `SelectItem`s (and into `items`) yourself. Item values are strings (object values need `itemToStringLabel` / `isItemEqualToValue` on the root) |
|
|
80
|
+
| `side`, `align` | `side`, `align` on `<SelectContent>` | Default `side="bottom"`, `align="start"` |
|
|
81
|
+
| `open`, `defaultOpen` | `open`, `defaultOpen`, `onOpenChange` on `<Select>` | |
|
|
82
|
+
| `data-test` | `data-test` on `SelectTrigger` / `SelectContent` | |
|
|
64
83
|
|
|
65
84
|
## 5. Before / After
|
|
66
85
|
|
|
67
86
|
### Before (Tractor)
|
|
68
87
|
|
|
69
88
|
```tsx
|
|
70
|
-
import { Select
|
|
89
|
+
import { Select } from '@aircall/tractor';
|
|
71
90
|
|
|
72
91
|
<Select
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
selectedKeys={channelType ? [channelType] : []}
|
|
93
|
+
onSelectionChange={keys => setChannelType(keys[0] ?? '')}
|
|
75
94
|
placeholder="Pick a channel"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
options={[
|
|
96
|
+
{ value: 'phone', label: 'Phone' },
|
|
97
|
+
{ value: 'email', label: 'Email' },
|
|
98
|
+
{ value: 'sms', label: 'SMS' },
|
|
99
|
+
]}
|
|
100
|
+
/>
|
|
81
101
|
```
|
|
82
102
|
|
|
83
103
|
### After (DS)
|
|
@@ -91,40 +111,56 @@ import {
|
|
|
91
111
|
SelectValue,
|
|
92
112
|
} from '@aircall/ds';
|
|
93
113
|
|
|
114
|
+
const CHANNELS = [
|
|
115
|
+
{ value: 'phone', label: 'Phone' },
|
|
116
|
+
{ value: 'email', label: 'Email' },
|
|
117
|
+
{ value: 'sms', label: 'SMS' },
|
|
118
|
+
];
|
|
119
|
+
|
|
94
120
|
<Select
|
|
121
|
+
items={CHANNELS}
|
|
95
122
|
value={channelType}
|
|
96
123
|
onValueChange={(value: string | null) => {
|
|
97
124
|
if (value !== null) setChannelType(value);
|
|
98
125
|
}}
|
|
99
126
|
>
|
|
100
|
-
<SelectTrigger>
|
|
127
|
+
<SelectTrigger id="channel" className="w-full">
|
|
101
128
|
<SelectValue placeholder="Pick a channel" />
|
|
102
129
|
</SelectTrigger>
|
|
103
130
|
<SelectContent>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
{CHANNELS.map(item => (
|
|
132
|
+
<SelectItem key={item.value} value={item.value}>
|
|
133
|
+
{item.label}
|
|
134
|
+
</SelectItem>
|
|
135
|
+
))}
|
|
107
136
|
</SelectContent>
|
|
108
137
|
</Select>
|
|
109
138
|
```
|
|
110
139
|
|
|
111
|
-
|
|
140
|
+
With a label and an error, wrap it in `Field` (see `aircall-ds/migrate-tractor/form-and-field`): `FieldLabel htmlFor="channel"`, `aria-invalid` on the `SelectTrigger`, `data-invalid` on the `Field`, then `<FieldError>`.
|
|
112
141
|
|
|
113
|
-
|
|
142
|
+
`items` also lets a `{ label: 'Select a timezone', value: null }` entry act as the placeholder label; a `null`-valued item's label wins over `SelectValue`'s `placeholder`.
|
|
114
143
|
|
|
115
|
-
|
|
116
|
-
import {
|
|
117
|
-
Select,
|
|
118
|
-
SelectContent,
|
|
119
|
-
SelectGroup,
|
|
120
|
-
SelectItem,
|
|
121
|
-
SelectLabel,
|
|
122
|
-
SelectTrigger,
|
|
123
|
-
SelectValue,
|
|
124
|
-
} from '@aircall/ds';
|
|
144
|
+
## 6. Size
|
|
125
145
|
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
`SelectTrigger` accepts a `size` prop:
|
|
147
|
+
|
|
148
|
+
| Value | Height | Use for |
|
|
149
|
+
| --- | --- | --- |
|
|
150
|
+
| `"default"` | 40px | Any Tractor size (`small` was 40px, `regular` 48px, `large` 56px) |
|
|
151
|
+
| `"sm"` | 32px | Compact layouts (no Tractor equivalent) |
|
|
152
|
+
|
|
153
|
+
## 7. When to use Combobox instead
|
|
154
|
+
|
|
155
|
+
If users need to **search or filter** the options list, or select **several** options, use `Combobox` / `DataCombobox` (`aircall-ds/migrate-tractor/combobox`) rather than `Select`. Plain `Select` is for short, fixed-enum, single-choice lists. Tractor `Select` with `searchable` or `selectionMode="multiple"` is a Combobox migration.
|
|
156
|
+
|
|
157
|
+
## 8. With sections (Labels)
|
|
158
|
+
|
|
159
|
+
When grouping options under a label, `SelectLabel` **must** be inside a `SelectGroup` along with its items (Base UI throws "SelectGroupContext is missing" otherwise). Use `SelectSeparator` between groups:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
<Select items={groupedItems} value={value} onValueChange={setValue}>
|
|
163
|
+
<SelectTrigger className="w-full">
|
|
128
164
|
<SelectValue placeholder="Pick a channel" />
|
|
129
165
|
</SelectTrigger>
|
|
130
166
|
<SelectContent>
|
|
@@ -133,6 +169,7 @@ import {
|
|
|
133
169
|
<SelectItem value="phone">Phone</SelectItem>
|
|
134
170
|
<SelectItem value="sms">SMS</SelectItem>
|
|
135
171
|
</SelectGroup>
|
|
172
|
+
<SelectSeparator />
|
|
136
173
|
<SelectGroup>
|
|
137
174
|
<SelectLabel>Written</SelectLabel>
|
|
138
175
|
<SelectItem value="email">Email</SelectItem>
|
|
@@ -141,18 +178,7 @@ import {
|
|
|
141
178
|
</Select>
|
|
142
179
|
```
|
|
143
180
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
`SelectTrigger` accepts a `size` prop:
|
|
147
|
-
|
|
148
|
-
| Value | Height | Use for |
|
|
149
|
-
| --- | --- | --- |
|
|
150
|
-
| `"default"` | 40px | Any Tractor `regular` or `small` size |
|
|
151
|
-
| `"sm"` | 32px | Compact layouts |
|
|
152
|
-
|
|
153
|
-
## 8. When to use Combobox instead
|
|
154
|
-
|
|
155
|
-
If users need to **search or filter** the options list, use `Combobox` rather than `Select`. Plain `Select` is for short, fixed-enum lists where no search is needed.
|
|
181
|
+
`groupedItems` can be the flat `{ value, label }[]` of all options (the grouping lives in the JSX).
|
|
156
182
|
|
|
157
183
|
## 9. Common Mistakes
|
|
158
184
|
|
|
@@ -174,8 +200,8 @@ If users need to **search or filter** the options list, use `Combobox` rather th
|
|
|
174
200
|
</Select>
|
|
175
201
|
```
|
|
176
202
|
|
|
177
|
-
The DS `onValueChange` callback receives `string | null`
|
|
178
|
-
Source: `packages/ds/src/components/select.tsx`
|
|
203
|
+
The DS `onValueChange` callback receives `string | null` (plus an event-details argument). Typing the parameter as `string` is a TypeScript error under `strictFunctionTypes`; omitting the null guard lets a runtime `null` propagate into state that expects a string.
|
|
204
|
+
Source: `packages/ds/src/components/select.tsx` (`Select = SelectPrimitive.Root`); Base UI `onValueChange?: (value: Value | null, eventDetails) => void`
|
|
179
205
|
|
|
180
206
|
---
|
|
181
207
|
|
|
@@ -197,8 +223,8 @@ Source: `packages/ds/src/components/select.tsx`
|
|
|
197
223
|
</SelectContent>
|
|
198
224
|
```
|
|
199
225
|
|
|
200
|
-
|
|
201
|
-
Source: `packages/ds/src/components/select.tsx`
|
|
226
|
+
`SelectLabel` wraps Base UI's `Select.GroupLabel`, which reads its parent `Select.Group` context. Outside a `SelectGroup` it throws ("SelectGroupContext is missing") instead of rendering.
|
|
227
|
+
Source: `packages/ds/src/components/select.tsx` (`SelectLabel` → `SelectPrimitive.GroupLabel`)
|
|
202
228
|
|
|
203
229
|
---
|
|
204
230
|
|
|
@@ -222,23 +248,50 @@ Source: `packages/ds/src/components/select.tsx`
|
|
|
222
248
|
</Select>
|
|
223
249
|
```
|
|
224
250
|
|
|
225
|
-
Tractor accepted `placeholder` on the root `<Select>`. In the DS compound, the `placeholder` prop lives on `<SelectValue
|
|
251
|
+
Tractor accepted `placeholder` on the root `<Select>`. In the DS compound, the `placeholder` prop lives on `<SelectValue>`; the root has no such prop (type error), so no placeholder text appears in the trigger.
|
|
226
252
|
Source: `packages/ds/src/components/select.tsx`
|
|
227
253
|
|
|
228
254
|
---
|
|
229
255
|
|
|
230
|
-
### Mistake 4 —
|
|
256
|
+
### Mistake 4 — Passing Tractor's `options` / `selectedKeys` / `onSelectionChange` to the DS `Select`
|
|
231
257
|
|
|
232
258
|
```tsx
|
|
233
|
-
// Wrong
|
|
234
|
-
|
|
235
|
-
// SelectOption does not exist in @aircall/ds
|
|
259
|
+
// Wrong — these props do not exist on the DS Select
|
|
260
|
+
<Select options={options} selectedKeys={[value]} onSelectionChange={keys => setValue(keys[0])} />
|
|
236
261
|
|
|
237
262
|
// Correct
|
|
238
|
-
|
|
263
|
+
<Select items={options} value={value} onValueChange={v => v !== null && setValue(v)}>
|
|
264
|
+
<SelectTrigger><SelectValue /></SelectTrigger>
|
|
265
|
+
<SelectContent>
|
|
266
|
+
{options.map(o => <SelectItem key={o.value} value={o.value}>{o.label}</SelectItem>)}
|
|
267
|
+
</SelectContent>
|
|
268
|
+
</Select>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The DS `Select` renders no options on its own; every option is a `SelectItem` child. There is no `SelectOption` in either library, so do not import one.
|
|
272
|
+
Source: `packages/ds/src/components/select.tsx`; `packages/tractor/src/components/Select/Select.decl.ts` (`options`, `selectedKeys`, `onSelectionChange`)
|
|
239
273
|
|
|
240
|
-
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### Mistake 5 — Omitting `items`, so the trigger shows the raw value
|
|
277
|
+
|
|
278
|
+
```tsx
|
|
279
|
+
// Wrong — after picking "Phone" the trigger reads "phone" (the value), not "Phone"
|
|
280
|
+
<Select value={channel} onValueChange={setChannel}>
|
|
281
|
+
<SelectTrigger><SelectValue placeholder="Pick a channel" /></SelectTrigger>
|
|
282
|
+
<SelectContent>
|
|
283
|
+
<SelectItem value="phone">Phone</SelectItem>
|
|
284
|
+
</SelectContent>
|
|
285
|
+
</Select>
|
|
286
|
+
|
|
287
|
+
// Correct — give the root the value→label lookup
|
|
288
|
+
<Select items={[{ value: 'phone', label: 'Phone' }]} value={channel} onValueChange={setChannel}>
|
|
289
|
+
<SelectTrigger><SelectValue placeholder="Pick a channel" /></SelectTrigger>
|
|
290
|
+
<SelectContent>
|
|
291
|
+
<SelectItem value="phone">Phone</SelectItem>
|
|
292
|
+
</SelectContent>
|
|
293
|
+
</Select>
|
|
241
294
|
```
|
|
242
295
|
|
|
243
|
-
|
|
244
|
-
Source: `packages/ds/src/
|
|
296
|
+
`SelectValue` does not read the text of the matching `SelectItem` (the popup may be unmounted). It resolves the label from the root `items` prop, and falls back to the raw value when `items` is absent. Alternatively give `SelectValue` a function child: `<SelectValue>{(v: string | null) => (v ? labelByValue[v] : null)}</SelectValue>` — note a function child bypasses the `placeholder` prop, so render the placeholder yourself when `v` is empty.
|
|
297
|
+
Source: Base UI `SelectValue` / `resolveSelectedLabel`; every story in `packages/ds/src/stories/Select.stories.tsx` passes `items`
|