@antadesign/anta 0.3.19 → 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/anta_helpers.d.ts +2 -2
- package/dist/components/Banner.d.ts +3 -3
- package/dist/components/Button.d.ts +1 -1
- package/dist/components/Calendar.d.ts +11 -12
- package/dist/components/Card.d.ts +1 -1
- package/dist/components/Card.js +1 -1
- package/dist/components/Checkbox.d.ts +8 -9
- package/dist/components/Dialog.d.ts +1 -1
- package/dist/components/Expander.d.ts +5 -6
- package/dist/components/Input.d.ts +2 -2
- package/dist/components/Input.js +1 -1
- package/dist/components/InputAutocomplete.d.ts +8 -8
- package/dist/components/InputTime.d.ts +3 -3
- package/dist/components/InputTime.js +1 -1
- package/dist/components/Menu.d.ts +2 -2
- package/dist/components/MenuItem.d.ts +1 -1
- package/dist/components/MenuItem.js +1 -1
- package/dist/components/Progress.d.ts +1 -1
- package/dist/components/RadioGroup.d.ts +12 -13
- package/dist/components/Select.d.ts +31 -38
- package/dist/components/Select.js +1 -1
- package/dist/components/SelectFaceted.d.ts +27 -33
- package/dist/components/Slider.d.ts +5 -5
- package/dist/components/Switch.d.ts +4 -4
- package/dist/components/Tabs.d.ts +7 -7
- package/dist/components/Title.d.ts +1 -1
- package/dist/components/Toaster.d.ts +1 -1
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/elements/a-card.css +1 -1
- package/dist/elements/a-dialog.css +1 -1
- package/dist/elements/a-expander.css +1 -1
- package/dist/elements/a-expander.d.ts +1 -0
- package/dist/elements/a-expander.js +12 -2
- package/dist/elements/a-progress.css +1 -1
- package/dist/elements/a-tooltip.css +1 -1
- package/dist/elements/a-tooltip.d.ts +1 -1
- package/dist/elements/a-tooltip.js +1 -1
- package/dist/elements/index.d.ts +1 -1
- package/dist/general_types.d.ts +22 -22
- package/dist/index.d.ts +3 -3
- package/docs/accessibility.md +4 -4
- package/docs/changelog.md +23 -13
- package/docs/comparison.md +1 -1
- package/docs/components/banner.md +17 -17
- package/docs/components/button.md +6 -6
- package/docs/components/card.md +5 -6
- package/docs/components/checkbox.md +17 -18
- package/docs/components/dialog.md +2 -2
- package/docs/components/expander.md +27 -30
- package/docs/components/icon.md +1 -1
- package/docs/components/input-autocomplete.md +15 -16
- package/docs/components/input-date.md +54 -59
- package/docs/components/input-time.md +7 -7
- package/docs/components/input.md +14 -14
- package/docs/components/menu.md +72 -8
- package/docs/components/progress.md +2 -2
- package/docs/components/radio.md +24 -25
- package/docs/components/select-faceted.md +95 -100
- package/docs/components/select.md +110 -115
- package/docs/components/slider.md +15 -10
- package/docs/components/switch.md +13 -13
- package/docs/components/tabs.md +23 -23
- package/docs/components/tag.md +5 -5
- package/docs/components/text.md +4 -4
- package/docs/components/title.md +1 -1
- package/docs/components/toaster.md +4 -4
- package/docs/components/tooltip.md +2 -2
- package/docs/credits.md +0 -4
- package/docs/index.md +1 -1
- package/docs/install-config.md +7 -7
- package/docs/normalization.md +6 -9
- package/docs/overview.md +1 -1
- package/docs/packages/stickers.md +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# SelectFaceted
|
|
2
2
|
|
|
3
|
-
A faceted filter
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
A faceted filter lets people filter a result set by several categories. Anta
|
|
4
|
+
calls each category a **facet**. The trigger opens a menu of facets, and each
|
|
5
|
+
facet opens a control for choosing its value.
|
|
6
|
+
|
|
7
|
+
The value is a `Record<facetKey, value>`. This keeps values separate when two
|
|
8
|
+
facets use the same option. For example, `assignee` and `owner` below are
|
|
9
|
+
application-defined facet keys, not Anta terms. Each facet has one of four
|
|
10
|
+
`kind` values: `single`, `multiple`, `text`, or `custom`.
|
|
11
|
+
|
|
12
|
+
`SelectFaceted` uses [Menu](./menu.md), [Select](./select.md)'s option model,
|
|
13
|
+
[Input](./input.md), and [Tag](./tag.md). It does not create a custom element.
|
|
14
|
+
Use `value` with `onValueChange` to control it, or use `defaultValue` for an
|
|
15
|
+
uncontrolled filter.
|
|
15
16
|
|
|
16
17
|
Pass `placement` to control where the root facet menu opens relative to its
|
|
17
18
|
trigger. It uses the same values as `Menu` and still flips or clamps when space
|
|
@@ -55,7 +56,8 @@ function Demo() {
|
|
|
55
56
|
|
|
56
57
|
{active.length > 0 && (
|
|
57
58
|
<div style={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap', gap: 8, alignItems: 'center' }}>
|
|
58
|
-
{/*
|
|
59
|
+
{/* Show one editable control for each active facet. Its label becomes
|
|
60
|
+
the control's `leading` prefix. */}
|
|
59
61
|
{active.map((facet) => {
|
|
60
62
|
// Options facets → an editable Select (single shows the trailing check;
|
|
61
63
|
// both are filterable + have a clearable footer).
|
|
@@ -114,18 +116,18 @@ function Demo() {
|
|
|
114
116
|
}
|
|
115
117
|
```
|
|
116
118
|
|
|
117
|
-
The trigger opens the facet menu
|
|
118
|
-
|
|
119
|
-
`leading
|
|
119
|
+
The trigger opens the facet menu. The example renders one editable
|
|
120
|
+
[Select](./select.md) below it for each active facet. Each Select receives the
|
|
121
|
+
facet label through `leading`, which displays it as a prefix.
|
|
120
122
|
|
|
121
|
-
### Value
|
|
123
|
+
### Value and changes
|
|
122
124
|
|
|
123
|
-
The value is a
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
The value is a record keyed by facet key: `{ [facetKey]: value }`. Its shape
|
|
126
|
+
depends on `kind`: an option value for `single`, an array for `multiple`, a
|
|
127
|
+
string for `text`, and a value of type `V` for `custom`. A cleared facet is
|
|
128
|
+
absent from the record, rather than set to `undefined`. The trigger badge counts
|
|
129
|
+
the keys that remain. Use `value` with `onValueChange` to control the filter, or
|
|
130
|
+
use `defaultValue` for the uncontrolled case.
|
|
129
131
|
|
|
130
132
|
Because one control mixes facets that hold different value types, the record is typed
|
|
131
133
|
`Record<string, unknown>`; narrow per facet when you read it.
|
|
@@ -151,36 +153,34 @@ Because one control mixes facets that hold different value types, the record is
|
|
|
151
153
|
|
|
152
154
|
### Value types
|
|
153
155
|
|
|
154
|
-
|
|
155
|
-
`string`, `number`, or `boolean` (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
it holds any shape and reports it back untouched.
|
|
156
|
+
`single` and `multiple` facets use [Select](./select.md#value-and-changes) option
|
|
157
|
+
values: `string`, `number`, or `boolean` (`OptionValue`). Anta compares them
|
|
158
|
+
with `===` and returns them unchanged. For a non-primitive value, use a stable
|
|
159
|
+
primitive key such as a date's ISO string or a record ID. Look up the full value
|
|
160
|
+
with that key. Use a `custom` facet when the facet value is an object, such as a
|
|
161
|
+
date range or numeric comparison. Its editor can return any value of type `V`.
|
|
161
162
|
|
|
162
163
|
### Custom facet
|
|
163
164
|
|
|
164
|
-
A `custom` facet has
|
|
165
|
-
|
|
166
|
-
provide two functions:
|
|
165
|
+
A `custom` facet has no option list. Provide its editor and choose the value it
|
|
166
|
+
returns: a number, date, range, or any other object. In addition to `key`,
|
|
167
|
+
`label`, and `icon`, provide two functions:
|
|
167
168
|
|
|
168
|
-
- **`render(ctx)`**
|
|
169
|
-
`ctx.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
- **`summary(value)`**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
what you read from `value[key]`. The chip caps its width and ellipsizes a long
|
|
176
|
-
summary so it can't stretch the menu.
|
|
169
|
+
- **`render(ctx)`** renders the editor. `ctx.value` is the current value.
|
|
170
|
+
`ctx.onChange(next)` sets it, and `undefined` clears the facet. `ctx.close()`
|
|
171
|
+
closes the menu. Anta stores the value passed to `onChange` at `value[key]`
|
|
172
|
+
without changing it.
|
|
173
|
+
- **`summary(value)`** renders the chip on the facet row when a value is set.
|
|
174
|
+
It does not change the stored value. It can return any node or `null`. Long
|
|
175
|
+
summaries are truncated so that they do not widen the menu.
|
|
177
176
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
`SelectFacetCustom<V>` so `ctx.value` and `summary`
|
|
177
|
+
`SelectFaceted` does not filter application data. It stores the facet values and
|
|
178
|
+
reports them through `onValueChange`. Filter the application's rows from that
|
|
179
|
+
value. Type the facet as `SelectFacetCustom<V>` so `ctx.value` and `summary`
|
|
180
|
+
use the same value type.
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
For a minimum-duration filter, the editor is one `Input`. Because that Input
|
|
183
|
+
does not open a popup, it appears directly in the facet menu.
|
|
184
184
|
|
|
185
185
|
```tsx
|
|
186
186
|
import type { SelectFacetCustom } from '@antadesign/anta'
|
|
@@ -211,10 +211,9 @@ const duration: SelectFacetCustom<string> = {
|
|
|
211
211
|
rows.filter((r) => value.duration == null || r.seconds >= Number(value.duration))
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
`
|
|
216
|
-
|
|
217
|
-
ISO strings and the `Date` you store.
|
|
214
|
+
For dates, the example converts between the Calendar's ISO strings and a stored
|
|
215
|
+
`Date`. Editors that open a menu, including `InputDate` and `Select`, also work
|
|
216
|
+
inside a custom facet. Their menu opens above the facet menu, which remains open.
|
|
218
217
|
|
|
219
218
|
```tsx
|
|
220
219
|
import type { SelectFacetCustom } from '@antadesign/anta'
|
|
@@ -246,17 +245,16 @@ const since: SelectFacetCustom<Date> = {
|
|
|
246
245
|
rows.filter((r) => value.since == null || r.createdAt >= value.since)
|
|
247
246
|
```
|
|
248
247
|
|
|
249
|
-
A
|
|
250
|
-
|
|
248
|
+
A custom facet stores a `Date` directly. Unlike the value of a `single` or
|
|
249
|
+
`multiple` facet, it is not compared with `===` to find an option.
|
|
251
250
|
|
|
252
251
|
#### A recency filter: presets plus a range
|
|
253
252
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
flyout, which stays open throughout.
|
|
253
|
+
This editor combines a `RadioGroup` of presets with a **Custom range** option
|
|
254
|
+
that reveals two `InputDate` fields. Its value is either `{ preset }` or
|
|
255
|
+
`{ from, to }`. The `resolveRange` helper converts either shape into the date
|
|
256
|
+
range used to filter the result set. Each InputDate calendar opens above the
|
|
257
|
+
facet menu without closing it.
|
|
260
258
|
|
|
261
259
|
```tsx
|
|
262
260
|
type Recency = { preset: 'today' | 'yesterday' | 'last14' | 'last30' } | { from: string; to: string }
|
|
@@ -313,11 +311,11 @@ const recency: SelectFacetCustom<Recency> = {
|
|
|
313
311
|
|
|
314
312
|
#### Menu-item presets, calendar on the right
|
|
315
313
|
|
|
316
|
-
|
|
317
|
-
a
|
|
318
|
-
|
|
319
|
-
a wide layout. `placement`
|
|
320
|
-
|
|
314
|
+
This version renders the presets as `MenuItem` rows and marks the selected row
|
|
315
|
+
with a check. **Custom day** reveals one `InputDate`. Its calendar opens to the
|
|
316
|
+
right with `placement="right-start"`, which is useful when the trigger is on the
|
|
317
|
+
left side of a wide layout. `placement` and `offset` are passed to the
|
|
318
|
+
calendar's Menu.
|
|
321
319
|
|
|
322
320
|
```tsx
|
|
323
321
|
type Recency = { preset: 'today' | 'yesterday' | 'last14' | 'last30' } | { day: string }
|
|
@@ -364,10 +362,10 @@ const recency: SelectFacetCustom<Recency> = {
|
|
|
364
362
|
|
|
365
363
|
| Prop | Type | Default | Description |
|
|
366
364
|
|------|------|---------|-------------|
|
|
367
|
-
| `facets` | SelectFacet[] | — |
|
|
365
|
+
| `facets` | SelectFacet[] | — | Categories to filter by. Each facet has a `kind` that determines its editor. |
|
|
368
366
|
| `clearable?` | boolean | true | Show the per-facet "Clear" row and the "Clear all" row. |
|
|
369
367
|
| `clearAllLabel?` | string | Clear all | Label for the "Clear all" row. |
|
|
370
|
-
| `defaultValue?` | SelectFacetedValue | — | Initial value for
|
|
368
|
+
| `defaultValue?` | SelectFacetedValue | — | Initial value for uncontrolled use. |
|
|
371
369
|
| `disabled?` | boolean | — | Disable the whole control. |
|
|
372
370
|
| `icon?` | IconShape | filter | Default trigger's leading icon. |
|
|
373
371
|
| `label?` | string | Filter | Default trigger's button label. |
|
|
@@ -379,47 +377,44 @@ const recency: SelectFacetCustom<Recency> = {
|
|
|
379
377
|
| `placement?` | 'left' \| 'right' \| 'bottom' \| 'top' \| 'bottom-start' \| 'bottom-end' \| 'top-start' \| 'top-end' \| 'right-start' \| 'right-end' \| 'left-start' \| 'left-end' | bottom-start | Preferred placement of the root filter menu relative to its trigger. The
|
|
380
378
|
menu auto-flips vertically and clamps horizontally when needed. |
|
|
381
379
|
| `priority?` | 'primary' \| 'secondary' | secondary | Default trigger's button priority. |
|
|
382
|
-
| `renderTrigger?` | (state) => ReactNode | — |
|
|
383
|
-
`SelectFacetedTriggerState
|
|
384
|
-
menu
|
|
385
|
-
`aria-haspopup="menu"`
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
| `searchable?` | boolean | — |
|
|
389
|
-
`single`
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
built-in substring match. |
|
|
380
|
+
| `renderTrigger?` | (state) => ReactNode | — | Replaces the default `Button` with a trigger returned from this function.
|
|
381
|
+
Receives a `SelectFacetedTriggerState`. Return exactly one focusable element:
|
|
382
|
+
the menu is positioned relative to that element and opens when it is clicked.
|
|
383
|
+
Add `aria-haspopup="menu"` and `aria-expanded={state.open}` to the returned
|
|
384
|
+
element. `className`, `style`, and other trigger props apply only to the
|
|
385
|
+
default Button, so add styling and attributes to the returned element. |
|
|
386
|
+
| `searchable?` | boolean | — | Adds a search field at the top of the root menu. It searches the options of
|
|
387
|
+
every `single` and `multiple` facet in one list. For example, "alice" can
|
|
388
|
+
appear under application-defined Assignee and Owner facets. `text` and
|
|
389
|
+
`custom` facets remain available when the search is empty. Each facet uses
|
|
390
|
+
its `filter` function when supplied, or the built-in substring match. |
|
|
394
391
|
| `searchPlaceholder?` | string | Filter… | Placeholder for the global search field. |
|
|
395
392
|
| `size?` | 'small' \| 'medium' \| 'large' | medium | Default trigger's button size. |
|
|
396
393
|
| `toneSelected?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | — | Tone applied to a selected option row in the facet flyouts (label, selected
|
|
397
394
|
tint, and the check / checkbox indicator). A named tone or a custom CSS
|
|
398
|
-
|
|
399
|
-
| `value?` | SelectFacetedValue | — | Controlled value
|
|
400
|
-
|
|
401
|
-
not updating). Leave undefined for uncontrolled. |
|
|
395
|
+
color, matching `Select`'s `toneSelected`. Defaults to a neutral selection. |
|
|
396
|
+
| `value?` | SelectFacetedValue | — | Controlled value record, keyed by facet. When provided, update it through
|
|
397
|
+
`onValueChange`. Leave it undefined for uncontrolled use. |
|
|
402
398
|
|
|
403
399
|
### The `SelectFacet` type
|
|
404
400
|
|
|
405
|
-
`facets` takes a `SelectFacet[]`.
|
|
406
|
-
|
|
401
|
+
`facets` takes a `SelectFacet[]`. Every facet has a `key`, `label`, and optional
|
|
402
|
+
`icon`. The `kind` field selects one of the shapes below.
|
|
407
403
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
the same rule: a `single`/`multiple` facet reports the chosen option's `value` (or an array
|
|
413
|
-
of them), exactly as [Select](./select.md#value--changes) does under its own key.
|
|
404
|
+
`single` and `multiple` facets use the same `options`, `filter`, and `selectAll`
|
|
405
|
+
properties as [Select](./select.md). They use `kind` in place of Select's
|
|
406
|
+
`selection`. `text` and `custom` do not use Select options. A `single` facet
|
|
407
|
+
returns one option value; a `multiple` facet returns an array of option values.
|
|
414
408
|
|
|
415
409
|
| Field | Type | Description |
|
|
416
410
|
|---|---|---|
|
|
417
|
-
| `key` | `string` | The facet's
|
|
411
|
+
| `key` | `string` | The key for this facet's value in the record. `attrs.facet` returns it. It must be unique in `facets`. |
|
|
418
412
|
| `label` | `string` | The facet's row label in the menu. |
|
|
419
413
|
| `icon` | `IconShape` | Leading icon on the facet's row. |
|
|
420
414
|
|
|
421
|
-
**`single`** (`SelectFacetSingle`)
|
|
422
|
-
absent when cleared
|
|
415
|
+
**`single`** (`SelectFacetSingle`) selects one option. Its value is the selected
|
|
416
|
+
option's `value`, or is absent when cleared. Selecting the current option again
|
|
417
|
+
clears it.
|
|
423
418
|
|
|
424
419
|
| Field | Type | Description |
|
|
425
420
|
|---|---|---|
|
|
@@ -427,8 +422,8 @@ absent when cleared (re-picking the selected option clears it).
|
|
|
427
422
|
| `options` | `SelectItem[]` | The choices — bare strings or `SelectOption`s (groups / submenus flatten to their leaves). Option `value`s may be `string` / `number` / `boolean`. |
|
|
428
423
|
| `filter` | `FacetFilter` | Search field over this facet's options: `true` for the built-in substring match, or `(option, query) => boolean`. |
|
|
429
424
|
|
|
430
|
-
**`multiple`** (`SelectFacetMultiple`)
|
|
431
|
-
|
|
425
|
+
**`multiple`** (`SelectFacetMultiple`) selects any number of options. Its value
|
|
426
|
+
is an array of the selected option values. An empty array clears it.
|
|
432
427
|
|
|
433
428
|
| Field | Type | Description |
|
|
434
429
|
|---|---|---|
|
|
@@ -438,19 +433,19 @@ absent when cleared (re-picking the selected option clears it).
|
|
|
438
433
|
| `selectAll` | `boolean` | A "Select all" row toggling every visible option. Default `true`. |
|
|
439
434
|
| `selectAllLabel` | `string` | Label for that row. Default `Select all`. |
|
|
440
435
|
|
|
441
|
-
**`text`** (`SelectFacetText`)
|
|
442
|
-
|
|
436
|
+
**`text`** (`SelectFacetText`) accepts a free-form string. It applies on Enter or
|
|
437
|
+
blur and is absent when empty.
|
|
443
438
|
|
|
444
439
|
| Field | Type | Description |
|
|
445
440
|
|---|---|---|
|
|
446
441
|
| `kind` | `'text'` | Discriminant. |
|
|
447
442
|
| `placeholder` | `string` | Placeholder for the text field. |
|
|
448
443
|
|
|
449
|
-
**`custom`** (`SelectFacetCustom<V>`)
|
|
450
|
-
|
|
444
|
+
**`custom`** (`SelectFacetCustom<V>`) renders the editor supplied by `render`.
|
|
445
|
+
It can store a value of type `V`, including an object such as a date range.
|
|
451
446
|
|
|
452
447
|
| Field | Type | Description |
|
|
453
448
|
|---|---|---|
|
|
454
449
|
| `kind` | `'custom'` | Discriminant. |
|
|
455
|
-
| `render` | `(ctx) => ReactNode` |
|
|
450
|
+
| `render` | `(ctx) => ReactNode` | Renders the editor. `ctx.value` is the current `V`; `ctx.onChange(next)` sets it, and `undefined` clears the facet. `ctx.close()` closes the menu. |
|
|
456
451
|
| `summary` | `(value: V) => ReactNode` | The chip on the facet's row while a value is set. |
|