@antadesign/anta 0.3.18 → 0.3.19

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 (59) hide show
  1. package/README.md +38 -242
  2. package/dist/components/Input.d.ts +4 -1
  3. package/dist/components/Input.js +2 -0
  4. package/dist/components/InputDate.css +1 -0
  5. package/dist/components/InputDate.d.ts +1 -0
  6. package/dist/components/InputDate.js +5 -5
  7. package/dist/components/Menu.d.ts +5 -1
  8. package/dist/components/Menu.js +3 -2
  9. package/dist/components/Select.d.ts +1 -0
  10. package/dist/components/Select.js +9 -13
  11. package/dist/components/SelectFaceted.d.ts +1 -0
  12. package/dist/components/SelectFaceted.js +29 -23
  13. package/dist/components/select-parts.css +1 -0
  14. package/dist/elements/a-input.css +1 -1
  15. package/dist/elements/a-menu.js +12 -0
  16. package/dist/elements/a-slider.css +1 -1
  17. package/dist/elements/a-tabs.css +1 -1
  18. package/dist/elements/a-tabs.d.ts +3 -0
  19. package/dist/elements/a-tabs.js +40 -1
  20. package/dist/general_types.d.ts +2 -0
  21. package/dist/jsx-runtime.d.ts +9 -0
  22. package/docs/accessibility.md +34 -0
  23. package/docs/changelog.md +551 -0
  24. package/docs/colors.md +42 -0
  25. package/docs/comparison.md +28 -0
  26. package/docs/components/banner.md +267 -0
  27. package/docs/components/button.md +603 -0
  28. package/docs/components/card.md +322 -0
  29. package/docs/components/checkbox.md +297 -0
  30. package/docs/components/dialog.md +314 -0
  31. package/docs/components/expander.md +529 -0
  32. package/docs/components/icon.md +155 -0
  33. package/docs/components/input-autocomplete.md +101 -0
  34. package/docs/components/input-date.md +406 -0
  35. package/docs/components/input-time.md +174 -0
  36. package/docs/components/input.md +610 -0
  37. package/docs/components/loader.md +139 -0
  38. package/docs/components/menu.md +447 -0
  39. package/docs/components/progress.md +182 -0
  40. package/docs/components/radio.md +369 -0
  41. package/docs/components/select-faceted.md +456 -0
  42. package/docs/components/select.md +931 -0
  43. package/docs/components/slider.md +142 -0
  44. package/docs/components/switch.md +198 -0
  45. package/docs/components/tabs.md +471 -0
  46. package/docs/components/tag.md +185 -0
  47. package/docs/components/text.md +148 -0
  48. package/docs/components/title.md +146 -0
  49. package/docs/components/toaster.md +313 -0
  50. package/docs/components/tooltip.md +177 -0
  51. package/docs/credits.md +22 -0
  52. package/docs/index.md +52 -0
  53. package/docs/install-config.md +240 -0
  54. package/docs/normalization.md +105 -0
  55. package/docs/overview.md +10 -0
  56. package/docs/packages/stickers.md +187 -0
  57. package/docs/packages/table.md +153 -0
  58. package/docs/theming.md +13 -0
  59. package/package.json +10 -6
@@ -0,0 +1,142 @@
1
+ # Slider
2
+
3
+ **`Slider`** selects one numeric value from a range. Its label sits above the rail, and the value appears at the label row’s right edge by default. It works controlled with `value` and `onValueChange`, or uncontrolled with `defaultValue`.
4
+
5
+ ## Relative dragging
6
+
7
+ Pressing the rail starts a grab from its current value. Moving right increases the value; moving left decreases it. The thumb does not jump to the press position. This is the default `trackClick="drag-only"` behaviour.
8
+
9
+ Set `trackClick="jump"` for the conventional range-input interaction, where pressing the rail first moves the thumb to that position.
10
+
11
+ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp and PageDown move by one tenth of the range.
12
+
13
+ ```tsx
14
+ <Slider label="Relative drag" defaultValue={35} />
15
+ <Slider label="Jump on press" defaultValue={35} trackClick="jump" />
16
+ ```
17
+
18
+ ## Value placement
19
+
20
+ `valueDisplay="end"` is the default. Use `inline` for `Label: value`, `thumb` to keep a value above the thumb, or `none` to omit it. `valuePrefix` and `valueSuffix` add text to every live value display.
21
+
22
+ ```tsx
23
+ <Slider label="Volume" defaultValue={48} valueSuffix="%" />
24
+ <Slider label="Volume" defaultValue={48} valueDisplay="inline" valueSuffix="%" />
25
+ <Slider label="Volume" defaultValue={48} valueDisplay="thumb" valueSuffix="%" />
26
+ ```
27
+
28
+ ## Size, tones, and radius
29
+
30
+ `size` follows the input height scale: 24px, 28px, and 32px. `trackSize` sets the thickness of both rail segments without changing the control height; numbers use pixels and strings accept CSS lengths. `thumbSize` controls the thumb diameter, and `thumbFill` fills it with its resolved border colour. `tone` colours the filled rail. `thumbTone` separately colours the thumb stroke. The unfilled rail stays neutral. `round` shapes both the rail and thumb. Pass `true` for fully round corners or a number or CSS length for a shared custom radius.
31
+
32
+ ```tsx
33
+ <Slider size="small" tone="info" label="Small" defaultValue={32} />
34
+ <Slider tone="brand" thumbTone="success" trackSize={4} thumbSize={20} thumbFill label="Medium, filled thumb" defaultValue={52} />
35
+ <Slider size="large" tone="success" round={4} label="Large, 4px corners" defaultValue={72} />
36
+ ```
37
+
38
+ ## Markers
39
+
40
+ `markers` places compact, muted labels below the rail. Values at or below `min` align left; values at or above `max` align right. Markers do not add dots or ticks to the rail.
41
+
42
+ ```tsx
43
+ <Slider
44
+ label="Playback speed"
45
+ min={0.5}
46
+ max={2}
47
+ step={0.25}
48
+ defaultValue={1}
49
+ markers={[
50
+ { value: 0.5, label: '0.5×' },
51
+ { value: 1, label: 'Normal' },
52
+ { value: 2, label: '2×' },
53
+ ]}
54
+ />
55
+ ```
56
+
57
+ ### Props
58
+
59
+ | Prop | Type | Default | Description |
60
+ |------|------|---------|-------------|
61
+ | `defaultValue?` | number | 0 | Initial uncontrolled value. |
62
+ | `disabled?` | boolean | — | Disables pointer and keyboard interaction. |
63
+ | `label?` | ReactNode | — | Visible field label, shown above the rail. A string supplies the slider's
64
+ accessible name; give a rich label an explicit `aria-label`. |
65
+ | `markers?` | SliderMarker[] | — | Compact text labels positioned below the rail. They do not add dots or
66
+ ticks to the rail. |
67
+ | `max?` | number | 100 | Highest permitted value. |
68
+ | `min?` | number | 0 | Lowest permitted value. |
69
+ | `name?` | string | — | Form field name. The current numeric value submits under this name. |
70
+ | `onValueChange?` | (event, attrs) => void | — | Fires on every keyboard or pointer value change. |
71
+ | `onValueCommit?` | (event, attrs) => void | — | Fires after a drag ends and after each keyboard value change. |
72
+ | `round?` | boolean \| number \| string | — | Fully round the rail and thumb. Pass a number (px) or CSS length string
73
+ for a shared custom radius. |
74
+ | `size?` | 'small' \| 'medium' \| 'large' | 'medium' | Size variant. small=24px, medium=28px, large=32px tall. |
75
+ | `step?` | number | 1 | Smallest keyboard and drag increment. |
76
+ | `thumbFill?` | boolean | false | Fill the thumb with its resolved border colour. This follows `thumbTone`
77
+ and interactive states. |
78
+ | `thumbSize?` | number \| string | 18 | Diameter of the thumb. Numbers use pixels; strings are CSS lengths. Keep
79
+ it at least as large as `trackSize`. |
80
+ | `thumbTone?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'neutral' | Colour of the thumb stroke. Pass a named tone or a literal CSS colour for a
81
+ one-off custom tone. Omit it to keep the thumb neutral. |
82
+ | `tone?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'neutral' | Colour of the filled rail. Pass a named tone or a literal CSS colour for a
83
+ one-off custom tone. The unfilled rail stays neutral. |
84
+ | `trackClick?` | 'drag-only' \| 'jump' | 'drag-only' | Track press behaviour. `drag-only` starts a relative grab from the current
85
+ value; `jump` first moves to the press position. |
86
+ | `trackSize?` | number \| string | 2 | Thickness of both rail segments. Numbers use pixels; strings are CSS
87
+ lengths. Keep it no larger than the thumb diameter. |
88
+ | `value?` | number | — | Controlled value. Update it from `onValueChange`. |
89
+ | `valueDisplay?` | 'end' \| 'inline' \| 'thumb' \| 'none' | 'end' | Where the live value appears. `end` puts it at the right edge of the label
90
+ row. `inline` renders `Label: value`. `thumb` keeps it above the thumb. |
91
+ | `valuePrefix?` | string | — | Text inserted before the live numeric value, such as `$`. |
92
+ | `valueSuffix?` | string | — | Text inserted after the live numeric value, such as `%` or `°C`. |
93
+
94
+ Use `<a-slider>` when you are not using React or Preact. Add its `role` and accessible name yourself, then register it from `@antadesign/anta/elements`.
95
+
96
+ ```html
97
+ <a-slider
98
+ role="slider"
99
+ tabindex="0"
100
+ aria-label="Volume"
101
+ name="volume"
102
+ defaultvalue="50"
103
+ track-size="4px"
104
+ thumb-fill
105
+ thumb-size="20px"
106
+ value-suffix="%"
107
+ >
108
+ <span slot="label">Volume</span>
109
+ </a-slider>
110
+ ```
111
+
112
+ ### Native HTML range input
113
+
114
+ Add `data-anta` to a native range input for Anta's rail, fill, thumb, and focus
115
+ treatment while retaining the browser's form, keyboard, and pointer behavior.
116
+
117
+ Use `size="small"` or `"large"` for the 24px and 32px control sizes.
118
+ `track-size` accepts a CSS length and changes both rail segments. `tone`,
119
+ `thumb-tone`, `thumb-fill`, `thumb-size`, and `round` use the same attributes
120
+ as `Slider`. In raw HTML, `round` needs a CSS length such as `"4px"`; JSX
121
+ `round={4}` remains a numeric pixel value.
122
+
123
+ ```html
124
+ <input data-anta type="range" min="0" max="100" value="48" aria-label="Native range">
125
+ <input data-anta type="range" min="0" max="100" value="32" size="small" tone="info" aria-label="Small info native range">
126
+ <input data-anta type="range" min="0" max="100" value="52" tone="brand" thumb-tone="success" track-size="4px" thumb-fill thumb-size="20px" aria-label="Brand native range with a large filled success thumb">
127
+ <input data-anta type="range" min="0" max="100" value="72" size="large" tone="success" round="4px" aria-label="Large rounded success native range">
128
+ ```
129
+
130
+ ## Styling
131
+
132
+ `Slider` renders an `<a-slider>` with a circular thumb. `tone` and `thumbTone` accept named or custom CSS colours; custom values use the public `--slider-tone-source` and `--slider-thumb-tone-source` knobs. Use `round` to shape the rail and thumb together. Target its shadow parts to change their presentation without taking on the interaction code: `::part(thumb)` customises the thumb’s surface and stroke. The element exposes `header`, `label`, `value`, `control`, `track`, `fill`, `thumb`, `thumb-value`, `markers`, and `extras`.
133
+
134
+ ```css
135
+ /* The class is only for the demo. Use your own selector. */
136
+ .warm-slider::part(fill) { background: #e5484d; }
137
+ .warm-slider::part(thumb) {
138
+ background: #fff7ed;
139
+ border-color: #e5484d;
140
+ border-radius: 4px;
141
+ }
142
+ ```
@@ -0,0 +1,198 @@
1
+ # Switch
2
+
3
+ Switches change a single setting immediately. Use a checkbox when people select one or more values to submit together.
4
+
5
+ The `Switch` wrapper renders a form-associated `<a-switch>` element. It works uncontrolled with `defaultChecked`, or controlled with `checked` and `onStateChange`.
6
+
7
+ ## Tone
8
+
9
+ `tone` colours the whole control: the checked track, plus the unchecked track border and thumb. Six named tones are available, or pass any CSS color for a custom tone. The label and hint stay neutral.
10
+
11
+ ```tsx
12
+ <Switch defaultChecked tone="neutral" label="Neutral" />
13
+ <Switch defaultChecked tone="brand" label="Brand" />
14
+ <Switch defaultChecked tone="critical" label="Critical" />
15
+ <Switch defaultChecked tone="mediumaquamarine" label="Custom color" />
16
+ ```
17
+
18
+ ## Selected-only tone
19
+
20
+ `toneSelected` colours the checked track only. The unchecked track and thumb stay neutral until the switch is on. Use it when a resting tinted control could imply a validation state. It accepts the same values as `tone`.
21
+
22
+ ```tsx
23
+ <Switch toneSelected="brand" label="Off stays neutral" />
24
+ <Switch defaultChecked toneSelected="critical" label="Checked track tinted" />
25
+ ```
26
+
27
+ ## Colouring the text
28
+
29
+ There is no text-tone prop. To tint the label, set `color` on the switch with a theme-aware `--text-N-{tone}` token; to tint the hint, target `a-switch-hint`. Pair either with `tone` or `toneSelected` to colour the whole control.
30
+
31
+ ```css
32
+ /* The class is only for the demo — use your own selector. */
33
+ a-switch.toned-text { color: var(--text-1-critical); }
34
+ a-switch.toned-text a-switch-hint { color: var(--text-3-critical); }
35
+ ```
36
+
37
+ ## Size
38
+
39
+ Three sizes scale the track, thumb, and label together: `small` (26×16px track), `medium` (30×18px, the default), and `large` (34×20px).
40
+
41
+ ```tsx
42
+ <Switch defaultChecked size="small" label="Small" />
43
+ <Switch defaultChecked label="Medium" />
44
+ <Switch defaultChecked size="large" label="Large" />
45
+ ```
46
+
47
+ ## Round or square
48
+
49
+ Switches are fully rounded by default. Pass `round` with a number (pixels) or CSS length to set the track radius; the thumb radius is 3px smaller. Pass `round={0}` for square track corners.
50
+
51
+ ```tsx
52
+ <Switch defaultChecked round={6} label="6px round" />
53
+ <Switch defaultChecked round={2} label="2px round" />
54
+ <Switch defaultChecked round={0} label="Square" />
55
+ ```
56
+
57
+ ## Label & hint
58
+
59
+ Pass a plain label through `label`, or pass richer label content as children. Add `hint` for a secondary line beneath. `labelPosition="start"` places the label and hint before the control visually while source order remains stable. For a label-less switch, pass `aria-label`.
60
+
61
+ ```tsx
62
+ <Switch defaultChecked label="Email notifications" hint="Weekly digest, never marketing." />
63
+ <Switch defaultChecked label="Automatic updates" labelPosition="start" />
64
+ ```
65
+
66
+ ## States
67
+
68
+ Switches are either unchecked or checked.
69
+
70
+ ```tsx
71
+ <Switch label="Unchecked" />
72
+ <Switch defaultChecked label="Checked" />
73
+ ```
74
+
75
+ ## Disabled
76
+
77
+ The `disabled` attribute dims the switch and removes it from the tab order.
78
+
79
+ ```tsx
80
+ <Switch disabled label="Disabled" />
81
+ <Switch disabled defaultChecked label="Disabled checked" />
82
+ ```
83
+
84
+ ## Controlled
85
+
86
+ Uncontrolled by default: pass `defaultChecked` and read the value from `onStateChange` or at form submit. Make it controlled with `checked` and `onStateChange` to drive it from your store.
87
+
88
+ ```tsx
89
+ const [enabled, setEnabled] = useState(false)
90
+
91
+ <Switch
92
+ checked={enabled}
93
+ onStateChange={(_e, { next }) => setEnabled(next)}
94
+ label="Enable notifications"
95
+ />
96
+ ```
97
+
98
+ `onStateChange` fires before the element applies a user toggle, with `(event, { next, prev })`. Call `event.preventDefault()` to veto an uncontrolled change. A controlled switch with no `onStateChange` is read-only.
99
+
100
+ ## Events
101
+
102
+ Three callbacks, in firing order:
103
+
104
+ | Callback | When | Cancelable | Payload |
105
+ |---|---|---|---|
106
+ | `onStateChange(e, { next, prev })` | **before** the toggle applies | ✅ `e.preventDefault()` vetoes | next / previous boolean |
107
+ | `onChange(e)` | **after** it applies | — | native `change` event |
108
+ | `onValueChange(e, attrs)` | **after** it applies | — | `{ checked, name, value }` |
109
+
110
+ Use **`onStateChange`** to intercept a toggle or drive a controlled switch. Use **`onValueChange`** when you only need the new form value.
111
+
112
+ ```tsx
113
+ <Switch
114
+ name="notifications"
115
+ onValueChange={(_e, { checked }) => saveNotificationPreference(checked)}
116
+ label="Email notifications"
117
+ />
118
+ ```
119
+
120
+ ## Accessibility
121
+
122
+ The wrapper sets `role="switch"` and keeps `aria-checked` in sync with the current value. It derives the accessible name from `label` or text children. For a label-less switch, pass `aria-label`.
123
+
124
+ Space toggles the switch. It follows the [WAI-ARIA switch pattern](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
125
+
126
+ ### Props
127
+
128
+ | Prop | Type | Default | Description |
129
+ |------|------|---------|-------------|
130
+ | `checked?` | boolean | — | Controlled checked value. In controlled mode, update this in `onStateChange`. |
131
+ | `defaultChecked?` | boolean | false | Initial checked value for an uncontrolled switch. |
132
+ | `disabled?` | boolean | — | Disables interaction and removes the switch from the tab order. |
133
+ | `hint?` | ReactNode | — | Secondary text rendered under the label. It does not become part of the
134
+ accessible name. |
135
+ | `label?` | string | — | Visible, stable label for the setting. Use `children` for richer label content. |
136
+ | `labelPosition?` | 'start' \| 'end' | 'end' | Put the visible label before or after the control. Grid layout changes only
137
+ the visual order, preserving DOM/source order for assistive technologies. |
138
+ | `name?` | string | — | Form field name. A checked switch submits `value` under this name. |
139
+ | `onChange?` | (event) => void | — | Native post-apply `change` event. |
140
+ | `onStateChange?` | (event, detail) => void | — | Fired before a user toggle applies. Call `event.preventDefault()` to veto an
141
+ uncontrolled change; controlled consumers accept by updating `checked`. |
142
+ | `onValueChange?` | (event, attrs) => void | — | Post-apply callback with the new form-relevant value snapshot. |
143
+ | `round?` | boolean \| number \| string | — | Fully round the thumb and track. Pass a `number` (px) or CSS length string
144
+ for a custom track radius; the thumb radius is 3px smaller. |
145
+ | `size?` | 'small' \| 'medium' \| 'large' | 'medium' | Size variant. small=26×16px, medium=30×18px, large=34×20px. |
146
+ | `tone?` | 'brand' \| 'neutral' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'brand' | Colour of the track and thumb. A tinted tone also colours the unchecked
147
+ track border and thumb; use `toneSelected` to colour only the checked track. |
148
+ | `toneSelected?` | 'brand' \| 'neutral' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'brand' | Like `tone`, but applies only while the switch is checked. The unchecked
149
+ track and thumb stay neutral. If both are set, `tone` colours the unchecked
150
+ state and `toneSelected` colours the checked track. |
151
+ | `value?` | string | "on" | Value submitted while checked. |
152
+
153
+ Use this when you are not using the React or Preact wrapper and a native HTML control does not fit: construct the equivalent Anta web component from the elements below.
154
+
155
+ The focusable host carries the state. Label and hint are light-DOM children.
156
+
157
+ ```html
158
+ <a-switch role="switch" tabindex="0" name="updates" default-state="checked">
159
+ <a-switch-label>Email updates</a-switch-label>
160
+ <a-switch-hint>Product and security notices.</a-switch-hint>
161
+ </a-switch>
162
+ ```
163
+
164
+ Reach for the props first: **`tone`** colours the checked track plus the unchecked chrome, while **`toneSelected`** colours only the checked track. Both accept any CSS color; **`size`** scales the control, label, and hint. The focus ring is the global [`--focus-ring`](../colors.md#focus-ring).
165
+
166
+ ```tsx
167
+ <Switch tone="#e0457b" defaultChecked label="Custom colour" />
168
+ ```
169
+
170
+ `<a-switch>` is light DOM. The **track is `::before`**, the **thumb is `::after`**, and the label / hint are `a-switch-label` / `a-switch-hint` children. Target them with plain CSS. The classes below are only for the demos.
171
+
172
+ ```css
173
+ a-switch.strong-label {
174
+ color: var(--text-1-brand);
175
+ font-weight: 700;
176
+ }
177
+
178
+ /* A CSS-only check / × in the free part of the track. */
179
+ a-switch.track-marks::before {
180
+ display: flex;
181
+ align-items: center;
182
+ font-size: 10px;
183
+ font-weight: 700;
184
+ line-height: 1;
185
+ }
186
+ a-switch.track-marks:state(checked)::before {
187
+ content: "✓";
188
+ justify-content: flex-start;
189
+ padding-inline-start: 4px;
190
+ color: var(--switch-thumb);
191
+ }
192
+ a-switch.track-marks:not(:state(checked))::before {
193
+ content: "×";
194
+ justify-content: flex-end;
195
+ padding-inline-end: 4px;
196
+ color: var(--switch-track-off-stroke);
197
+ }
198
+ ```