@codecademy/gamut 72.2.3-alpha.e393cd.0 → 72.2.3-alpha.e8c7ae.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-tools/skills/gamut-forms/SKILL.md +0 -16
- package/dist/Alert/elements.d.ts +2 -2
- package/dist/Anchor/index.d.ts +19 -9
- package/dist/Anchor/index.js +9 -6
- package/dist/BarChart/BarRow/elements.d.ts +47 -45
- package/dist/BarChart/utils/hooks.d.ts +2 -2
- package/dist/BarChart/utils/hooks.js +3 -1
- package/dist/Box/GridBox.d.ts +1 -0
- package/dist/Box/GridBox.js +1 -1
- package/dist/Box/props.d.ts +1 -1
- package/dist/Breadcrumbs/index.d.ts +5 -5
- package/dist/Breadcrumbs/index.js +2 -2
- package/dist/Button/CTAButton.d.ts +2 -2
- package/dist/Button/FillButton.d.ts +4 -4
- package/dist/Button/IconButton.d.ts +4 -4
- package/dist/Button/StrokeButton.d.ts +4 -4
- package/dist/Button/TextButton.d.ts +4 -4
- package/dist/Button/shared/InlineIconButton.d.ts +2 -2
- package/dist/Button/shared/styles.d.ts +3 -3
- package/dist/Button/shared/types.d.ts +1 -1
- package/dist/ButtonBase/ButtonBase.d.ts +9 -4
- package/dist/ButtonBase/ButtonBase.js +11 -4
- package/dist/Card/elements.d.ts +109 -103
- package/dist/Card/styles.d.ts +8 -8
- package/dist/Coachmark/index.d.ts +1 -1
- package/dist/ConnectedForm/ConnectedForm.d.ts +1 -1
- package/dist/ConnectedForm/ConnectedFormGroup.js +3 -2
- package/dist/ConnectedForm/utils.d.ts +1 -1
- package/dist/ConnectedForm/utils.js +1 -1
- package/dist/DatePicker/DatePickerInput/index.d.ts +1 -1
- package/dist/Disclosure/elements.d.ts +18 -12
- package/dist/FeatureShimmer/index.js +1 -1
- package/dist/Form/SelectDropdown/SelectDropdown.js +19 -36
- package/dist/Form/SelectDropdown/elements/constants.d.ts +8 -0
- package/dist/Form/SelectDropdown/elements/constants.js +9 -1
- package/dist/Form/SelectDropdown/elements/containers.d.ts +2 -6
- package/dist/Form/SelectDropdown/elements/containers.js +2 -18
- package/dist/Form/SelectDropdown/elements/controls.d.ts +5 -0
- package/dist/Form/SelectDropdown/elements/controls.js +70 -2
- package/dist/Form/SelectDropdown/elements/multi-value.js +2 -2
- package/dist/Form/SelectDropdown/elements/options.d.ts +0 -1
- package/dist/Form/SelectDropdown/elements/options.js +2 -5
- package/dist/Form/SelectDropdown/styles.js +10 -28
- package/dist/Form/SelectDropdown/types/component-props.d.ts +6 -54
- package/dist/Form/SelectDropdown/types/internal.d.ts +2 -2
- package/dist/Form/SelectDropdown/types/styles.d.ts +0 -4
- package/dist/Form/SelectDropdown/utils.d.ts +1 -7
- package/dist/Form/SelectDropdown/utils.js +2 -17
- package/dist/Form/elements/Form.d.ts +15 -15
- package/dist/Form/elements/FormGroup.d.ts +1 -1
- package/dist/Form/styles/Checkbox-styles.d.ts +1 -1
- package/dist/GridForm/GridFormButtons/index.d.ts +4 -4
- package/dist/List/ListProvider.d.ts +1 -1
- package/dist/List/elements.d.ts +44 -42
- package/dist/Menu/MenuItem.js +10 -6
- package/dist/Menu/elements.d.ts +2 -2
- package/dist/Modals/Dialog.js +6 -2
- package/dist/Modals/Modal.js +5 -2
- package/dist/Modals/elements.d.ts +1 -1
- package/dist/Pagination/AnimatedPaginationButtons.d.ts +31 -29
- package/dist/Pagination/EllipsisButton.d.ts +2 -2
- package/dist/Pagination/PaginationButton.d.ts +6 -6
- package/dist/Pagination/utils.d.ts +31 -29
- package/dist/Pagination/utils.js +14 -11
- package/dist/Popover/Popover.js +6 -6
- package/dist/Popover/types.d.ts +4 -3
- package/dist/PopoverContainer/PopoverContainer.js +9 -9
- package/dist/PopoverContainer/hooks.d.ts +16 -4
- package/dist/PopoverContainer/hooks.js +50 -27
- package/dist/PopoverContainer/types.d.ts +2 -1
- package/dist/Tabs/TabButton.d.ts +2 -2
- package/dist/Tabs/TabNavLink.d.ts +2 -2
- package/dist/Tag/elements.d.ts +14 -8
- package/dist/Tip/InfoTip/InfoTipButton.d.ts +4 -4
- package/dist/Tip/PreviewTip/elements.d.ts +12 -6
- package/dist/Tip/__tests__/helpers.d.ts +1 -1
- package/dist/Tip/shared/FloatingTip.js +2 -2
- package/dist/Tip/shared/types.d.ts +2 -2
- package/dist/Tip/shared/utils.js +1 -1
- package/dist/utils/nullish.d.ts +10 -0
- package/dist/utils/nullish.js +11 -0
- package/dist/utils/react.js +4 -2
- package/package.json +10 -10
- package/agent-tools/skills/gamut-select-dropdown/SKILL.md +0 -236
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/gamut",
|
|
3
3
|
"description": "Styleguide & Component library for Codecademy",
|
|
4
|
-
"version": "72.2.3-alpha.
|
|
4
|
+
"version": "72.2.3-alpha.e8c7ae.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"bin": "./bin/gamut.mjs",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@codecademy/gamut-icons": "9.57.10-alpha.
|
|
9
|
-
"@codecademy/gamut-illustrations": "0.58.16-alpha.
|
|
10
|
-
"@codecademy/gamut-patterns": "0.10.35-alpha.
|
|
11
|
-
"@codecademy/gamut-styles": "20.0.3-alpha.
|
|
12
|
-
"@codecademy/variance": "0.26.2-alpha.
|
|
8
|
+
"@codecademy/gamut-icons": "9.57.10-alpha.e8c7ae.0",
|
|
9
|
+
"@codecademy/gamut-illustrations": "0.58.16-alpha.e8c7ae.0",
|
|
10
|
+
"@codecademy/gamut-patterns": "0.10.35-alpha.e8c7ae.0",
|
|
11
|
+
"@codecademy/gamut-styles": "20.0.3-alpha.e8c7ae.0",
|
|
12
|
+
"@codecademy/variance": "0.26.2-alpha.e8c7ae.0",
|
|
13
13
|
"@formatjs/intl-locale": "5.3.1",
|
|
14
14
|
"@react-aria/interactions": "3.25.0",
|
|
15
15
|
"@types/marked": "^4.0.8",
|
|
16
16
|
"@vidstack/react": "^1.12.12",
|
|
17
17
|
"classnames": "^2.2.5",
|
|
18
|
-
"framer-motion": "^
|
|
18
|
+
"framer-motion": "^12.0.0",
|
|
19
19
|
"html-to-react": "^1.6.0",
|
|
20
20
|
"invariant": "^2.2.4",
|
|
21
21
|
"lodash": "^4.17.23",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"polished": "^4.1.2",
|
|
24
24
|
"react-aria-components": "1.7.1",
|
|
25
25
|
"react-focus-on": "3.10.0",
|
|
26
|
-
"react-hook-form": "^7.
|
|
26
|
+
"react-hook-form": "^7.71.2",
|
|
27
27
|
"react-player": "^2.16.0",
|
|
28
28
|
"react-select": "^5.2.2",
|
|
29
29
|
"react-truncate-markup": "^5.1.2",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@emotion/react": "^11.4.0",
|
|
46
46
|
"@emotion/styled": "^11.3.0",
|
|
47
|
-
"react": "^17.0.2 || ^18.3.0",
|
|
48
|
-
"react-dom": "^17.0.2 || ^18.3.0"
|
|
47
|
+
"react": "^17.0.2 || ^18.3.0 || ^19.0.0",
|
|
48
|
+
"react-dom": "^17.0.2 || ^18.3.0 || ^19.0.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: gamut-select-dropdown
|
|
3
|
-
description: Use when implementing or auditing SelectDropdown — single/multi modes, controlled vs uncontrolled value, creatable options, FormGroup wiring, and onChange contract. Pair with gamut-forms for error live regions, ConnectedForm, and field-level validation.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Gamut SelectDropdown
|
|
7
|
-
|
|
8
|
-
Styled dropdown built on react-select.
|
|
9
|
-
|
|
10
|
-
Source: `@codecademy/gamut` — [SelectDropdown.tsx](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/Form/SelectDropdown/SelectDropdown.tsx)
|
|
11
|
-
|
|
12
|
-
See also: [`gamut-forms`](../gamut-forms/SKILL.md) — FormGroup wiring, error regions, and validation UX.
|
|
13
|
-
|
|
14
|
-
Storybook: [Atoms / FormInputs / SelectDropdown](https://gamut.codecademy.com/?path=/docs-atoms-forminputs-selectdropdown--docs)
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## When to use SelectDropdown vs Select
|
|
19
|
-
|
|
20
|
-
Use `Select` for standard single-select forms with minimal bundle cost. Use `SelectDropdown` when designs specify the styled dropdown menu, search, multi-select tags, creatable options, icons, groups, or abbreviations. SelectDropdown has a larger JavaScript dependency (react-select).
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Options
|
|
25
|
-
|
|
26
|
-
`options` accepts plain strings or option objects. `value` is always a string and references an option's `value`.
|
|
27
|
-
|
|
28
|
-
| Field | Required | Notes |
|
|
29
|
-
| -------------- | -------- | -------------------------------------------------------------------- |
|
|
30
|
-
| `label` | yes | Display text |
|
|
31
|
-
| `value` | yes | Unique string; what `value` / `string[]` reference |
|
|
32
|
-
| `disabled` | no | Option cannot be selected |
|
|
33
|
-
| `subtitle` | no | Secondary text below the label |
|
|
34
|
-
| `rightLabel` | no | Text on the right side of the option |
|
|
35
|
-
| `icon` | no | A `@codecademy/gamut-icons` component |
|
|
36
|
-
| `abbreviation` | no | Short text shown in the input while the full label shows in the menu |
|
|
37
|
-
|
|
38
|
-
Grouped options: `{ label, options: [...], divider? }` (extends react-select `GroupBase`; `divider` draws a rule above the group).
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Controlled vs uncontrolled
|
|
43
|
-
|
|
44
|
-
SelectDropdown does **not** accept `defaultValue`.
|
|
45
|
-
|
|
46
|
-
| Mode | Uncontrolled | Controlled |
|
|
47
|
-
| ---------------- | -------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
48
|
-
| Single | Not supported | `value` (string) + update in `onChange` |
|
|
49
|
-
| Multi | Omit `value` or pass non-array (`undefined`, `''`) | `value: string[]` + update in `onChange` |
|
|
50
|
-
| Creatable single | Not supported | Same as single; `onCreateOption` appends to `options` |
|
|
51
|
-
| Creatable multi | Omit `value`; `onCreateOption` for options | `value: string[]`; update in `onChange` on every change including `create-option` |
|
|
52
|
-
|
|
53
|
-
Single-select selection is derived from the `value` prop only — internal state is not kept. Multi-select without `value: string[]` keeps selection in internal `multiValues`.
|
|
54
|
-
|
|
55
|
-
**Controlled creatable multi pitfall:** Updating `options` alone without syncing `value` in `onChange` clears selection when options re-render.
|
|
56
|
-
|
|
57
|
-
### When to use uncontrolled (multi only)
|
|
58
|
-
|
|
59
|
-
Uncontrolled multi is appropriate when:
|
|
60
|
-
|
|
61
|
-
- No other part of the UI needs to react to the current selection (no live summary, no dependent field, no enabled/disabled button).
|
|
62
|
-
- You only need the value at form submission — via `FormData`, a submit handler reading the DOM, or react-hook-form's `getValues`.
|
|
63
|
-
- Simplicity is the priority; omitting `value` means one less piece of state to manage.
|
|
64
|
-
|
|
65
|
-
```tsx
|
|
66
|
-
// Good fit: a "tags" field where only the submitted array matters
|
|
67
|
-
<SelectDropdown
|
|
68
|
-
multiple
|
|
69
|
-
name="tags"
|
|
70
|
-
options={tagOptions}
|
|
71
|
-
onCreateOption={(v) => setTagOptions((prev) => [...prev, v])}
|
|
72
|
-
/>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### When to use controlled
|
|
76
|
-
|
|
77
|
-
Use controlled when:
|
|
78
|
-
|
|
79
|
-
- Another part of the UI must reflect the current selection in real time (summary text, a filtered list, an enable/disable condition).
|
|
80
|
-
- You need to pre-populate from an API response, reset on cancel, or sync with a form library like react-hook-form.
|
|
81
|
-
- You are using single-select (the only supported mode for single).
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
// Good fit: pre-populate from API, clear on cancel, show live summary
|
|
85
|
-
const [selected, setSelected] = useState<string[]>(initialValues);
|
|
86
|
-
|
|
87
|
-
<SelectDropdown
|
|
88
|
-
multiple
|
|
89
|
-
name="languages"
|
|
90
|
-
options={languageOptions}
|
|
91
|
-
value={selected}
|
|
92
|
-
onChange={(opts) => setSelected(opts.map((o) => o.value))}
|
|
93
|
-
/>
|
|
94
|
-
<p>Selected: {selected.join(', ') || 'none'}</p>
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## onChange contract
|
|
100
|
-
|
|
101
|
-
`onChange` receives option object(s), not `event.target.value`:
|
|
102
|
-
|
|
103
|
-
```tsx
|
|
104
|
-
// Single
|
|
105
|
-
onChange={(option) => setValue(option.value)}
|
|
106
|
-
|
|
107
|
-
// Multi
|
|
108
|
-
onChange={(selected) => setValue(selected.map((o) => o.value))}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Second argument is react-select `ActionMeta`. For creatable creates: `meta.action === 'create-option'`. Do **not** pass `onCreateOption` to react-select directly — Gamut invokes it from `changeHandler` while still forwarding `create-option` to consumer `onChange`.
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## Creatable
|
|
116
|
-
|
|
117
|
-
- `isCreatable` forces `isSearchable: true` (TypeScript enforces this).
|
|
118
|
-
- `onCreateOption(inputValue)` — convenience hook to append to `options`.
|
|
119
|
-
- `onChange(selected, meta)` — use `meta.action === 'create-option'` to sync controlled `value` and `options` together.
|
|
120
|
-
- `isValidNewOption` — return `false` to hide the Add row.
|
|
121
|
-
- `validationMessage` — replaces menu "No options" text; mirror in `FormGroup` `error` for field-level feedback.
|
|
122
|
-
|
|
123
|
-
**Validation after blur:** react-select clears input on blur before `onBlur` fires, so the value is gone by the time you'd validate it. Store the last typed value in a ref and re-validate from it on `input-blur`:
|
|
124
|
-
|
|
125
|
-
```tsx
|
|
126
|
-
const lastInput = useRef('');
|
|
127
|
-
|
|
128
|
-
<SelectDropdown
|
|
129
|
-
isCreatable
|
|
130
|
-
onInputChange={(value, { action }) => {
|
|
131
|
-
if (action === 'input-change') lastInput.current = value;
|
|
132
|
-
if (action === 'input-blur') validate(lastInput.current);
|
|
133
|
-
}}
|
|
134
|
-
/>;
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## FormGroup wiring
|
|
140
|
-
|
|
141
|
-
- `FormGroup` `htmlFor` must match control `id` (not `name`). Alternatively, pass `htmlFor` directly on SelectDropdown and it becomes `id` downstream.
|
|
142
|
-
- Pass `name` on SelectDropdown (required for forms).
|
|
143
|
-
- Pass `aria-label` (required for forms); it must match the FormGroupLabel `htmlFor`.
|
|
144
|
-
- Pass `error` boolean when FormGroup has an error.
|
|
145
|
-
- Generic FormGroup live-region behavior: see [`gamut-forms`](../gamut-forms/SKILL.md).
|
|
146
|
-
|
|
147
|
-
```tsx
|
|
148
|
-
<FormGroup htmlFor="country" isSoloField label="Country" error={errors.country}>
|
|
149
|
-
<SelectDropdown
|
|
150
|
-
id="country"
|
|
151
|
-
name="country"
|
|
152
|
-
aria-label="country"
|
|
153
|
-
options={options}
|
|
154
|
-
value={value}
|
|
155
|
-
error={Boolean(errors.country)}
|
|
156
|
-
onChange={(option) => setValue(option.value)}
|
|
157
|
-
/>
|
|
158
|
-
</FormGroup>
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## Styling & layout props
|
|
164
|
-
|
|
165
|
-
| Prop | Type | Default | Notes |
|
|
166
|
-
| ------------------- | ------------------------ | -------- | --------------------------------------------------------- |
|
|
167
|
-
| `size` | `'small' \| 'medium'` | `medium` | Control height/density |
|
|
168
|
-
| `shownOptionsLimit` | `1`–`6` | `6` | Visible options before the menu scrolls |
|
|
169
|
-
| `inputWidth` | `string \| number` | — | Width of the input independent of the menu |
|
|
170
|
-
| `dropdownWidth` | `string \| number` | — | Width of the menu independent of the input |
|
|
171
|
-
| `menuAlignment` | `'left' \| 'right'` | `left` | Menu edge alignment |
|
|
172
|
-
| `zIndex` | `number` | auto | Menu z-index |
|
|
173
|
-
| `inputProps` | `{ hidden?, combobox? }` | — | `data-*` / `aria-*` only, forwarded to the input elements |
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
## Examples
|
|
178
|
-
|
|
179
|
-
### Single (controlled)
|
|
180
|
-
|
|
181
|
-
```tsx
|
|
182
|
-
const [value, setValue] = useState('us');
|
|
183
|
-
|
|
184
|
-
<SelectDropdown
|
|
185
|
-
name="country"
|
|
186
|
-
options={options}
|
|
187
|
-
value={value}
|
|
188
|
-
onChange={(option) => setValue(option.value)}
|
|
189
|
-
/>;
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Multi (uncontrolled)
|
|
193
|
-
|
|
194
|
-
```tsx
|
|
195
|
-
<SelectDropdown
|
|
196
|
-
multiple
|
|
197
|
-
name="tags"
|
|
198
|
-
options={options}
|
|
199
|
-
onChange={(selected) => console.log(selected)}
|
|
200
|
-
/>
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Creatable multi (uncontrolled)
|
|
204
|
-
|
|
205
|
-
```tsx
|
|
206
|
-
const [options, setOptions] = useState(['Apple', 'Banana']);
|
|
207
|
-
|
|
208
|
-
<SelectDropdown
|
|
209
|
-
isCreatable
|
|
210
|
-
multiple
|
|
211
|
-
name="fruits"
|
|
212
|
-
options={options}
|
|
213
|
-
onCreateOption={(v) => setOptions((prev) => [...prev, v])}
|
|
214
|
-
/>;
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Creatable multi (controlled)
|
|
218
|
-
|
|
219
|
-
```tsx
|
|
220
|
-
const [options, setOptions] = useState(['Apple', 'Banana']);
|
|
221
|
-
const [value, setValue] = useState<string[]>([]);
|
|
222
|
-
|
|
223
|
-
<SelectDropdown
|
|
224
|
-
isCreatable
|
|
225
|
-
multiple
|
|
226
|
-
name="fruits"
|
|
227
|
-
options={options}
|
|
228
|
-
value={value}
|
|
229
|
-
onChange={(selected, meta) => {
|
|
230
|
-
setValue(selected.map((o) => o.value));
|
|
231
|
-
if (meta.action === 'create-option' && meta.option) {
|
|
232
|
-
setOptions((prev) => [...prev, meta.option.value]);
|
|
233
|
-
}
|
|
234
|
-
}}
|
|
235
|
-
/>;
|
|
236
|
-
```
|