@antadesign/anta 0.3.18 → 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.
Files changed (92) hide show
  1. package/README.md +38 -242
  2. package/dist/anta_helpers.d.ts +2 -2
  3. package/dist/components/Banner.d.ts +3 -3
  4. package/dist/components/Button.d.ts +1 -1
  5. package/dist/components/Calendar.d.ts +11 -12
  6. package/dist/components/Card.d.ts +1 -1
  7. package/dist/components/Card.js +1 -1
  8. package/dist/components/Checkbox.d.ts +8 -9
  9. package/dist/components/Dialog.d.ts +1 -1
  10. package/dist/components/Expander.d.ts +5 -6
  11. package/dist/components/Input.d.ts +6 -3
  12. package/dist/components/Input.js +3 -1
  13. package/dist/components/InputAutocomplete.d.ts +8 -8
  14. package/dist/components/InputDate.css +1 -0
  15. package/dist/components/InputDate.d.ts +1 -0
  16. package/dist/components/InputDate.js +5 -5
  17. package/dist/components/InputTime.d.ts +3 -3
  18. package/dist/components/InputTime.js +1 -1
  19. package/dist/components/Menu.d.ts +7 -3
  20. package/dist/components/Menu.js +3 -2
  21. package/dist/components/MenuItem.d.ts +1 -1
  22. package/dist/components/MenuItem.js +1 -1
  23. package/dist/components/Progress.d.ts +1 -1
  24. package/dist/components/RadioGroup.d.ts +12 -13
  25. package/dist/components/Select.d.ts +32 -38
  26. package/dist/components/Select.js +9 -13
  27. package/dist/components/SelectFaceted.d.ts +28 -33
  28. package/dist/components/SelectFaceted.js +29 -23
  29. package/dist/components/Slider.d.ts +5 -5
  30. package/dist/components/Switch.d.ts +4 -4
  31. package/dist/components/Tabs.d.ts +7 -7
  32. package/dist/components/Title.d.ts +1 -1
  33. package/dist/components/Toaster.d.ts +1 -1
  34. package/dist/components/Tooltip.d.ts +1 -1
  35. package/dist/components/select-parts.css +1 -0
  36. package/dist/elements/a-card.css +1 -1
  37. package/dist/elements/a-dialog.css +1 -1
  38. package/dist/elements/a-expander.css +1 -1
  39. package/dist/elements/a-expander.d.ts +1 -0
  40. package/dist/elements/a-expander.js +12 -2
  41. package/dist/elements/a-input.css +1 -1
  42. package/dist/elements/a-menu.js +12 -0
  43. package/dist/elements/a-progress.css +1 -1
  44. package/dist/elements/a-slider.css +1 -1
  45. package/dist/elements/a-tabs.css +1 -1
  46. package/dist/elements/a-tabs.d.ts +3 -0
  47. package/dist/elements/a-tabs.js +40 -1
  48. package/dist/elements/a-tooltip.css +1 -1
  49. package/dist/elements/a-tooltip.d.ts +1 -1
  50. package/dist/elements/a-tooltip.js +1 -1
  51. package/dist/elements/index.d.ts +1 -1
  52. package/dist/general_types.d.ts +24 -22
  53. package/dist/index.d.ts +3 -3
  54. package/dist/jsx-runtime.d.ts +9 -0
  55. package/docs/accessibility.md +34 -0
  56. package/docs/changelog.md +561 -0
  57. package/docs/colors.md +42 -0
  58. package/docs/comparison.md +28 -0
  59. package/docs/components/banner.md +267 -0
  60. package/docs/components/button.md +603 -0
  61. package/docs/components/card.md +321 -0
  62. package/docs/components/checkbox.md +296 -0
  63. package/docs/components/dialog.md +314 -0
  64. package/docs/components/expander.md +526 -0
  65. package/docs/components/icon.md +155 -0
  66. package/docs/components/input-autocomplete.md +100 -0
  67. package/docs/components/input-date.md +401 -0
  68. package/docs/components/input-time.md +174 -0
  69. package/docs/components/input.md +610 -0
  70. package/docs/components/loader.md +139 -0
  71. package/docs/components/menu.md +511 -0
  72. package/docs/components/progress.md +182 -0
  73. package/docs/components/radio.md +368 -0
  74. package/docs/components/select-faceted.md +451 -0
  75. package/docs/components/select.md +926 -0
  76. package/docs/components/slider.md +147 -0
  77. package/docs/components/switch.md +198 -0
  78. package/docs/components/tabs.md +471 -0
  79. package/docs/components/tag.md +185 -0
  80. package/docs/components/text.md +148 -0
  81. package/docs/components/title.md +146 -0
  82. package/docs/components/toaster.md +313 -0
  83. package/docs/components/tooltip.md +177 -0
  84. package/docs/credits.md +18 -0
  85. package/docs/index.md +52 -0
  86. package/docs/install-config.md +240 -0
  87. package/docs/normalization.md +102 -0
  88. package/docs/overview.md +10 -0
  89. package/docs/packages/stickers.md +187 -0
  90. package/docs/packages/table.md +153 -0
  91. package/docs/theming.md +13 -0
  92. package/package.json +10 -6
@@ -0,0 +1,147 @@
1
+ # Slider
2
+
3
+ **`Slider`** selects one numeric value from a range. Its label sits above the
4
+ rail, and the value appears at the right side of the label row by default. Use
5
+ `value` with `onValueChange` to control it, or `defaultValue` for uncontrolled use.
6
+
7
+ ## Relative dragging
8
+
9
+ With the default `trackClick="drag-only"`, pressing the rail starts dragging
10
+ from the current value. Moving right increases the value, and moving left
11
+ decreases it. The thumb does not move to the point where the rail was pressed.
12
+
13
+ Set `trackClick="jump"` to move the thumb to the pressed position before
14
+ dragging, as a native range input does.
15
+
16
+ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp and PageDown move by one tenth of the range.
17
+
18
+ ```tsx
19
+ <Slider label="Relative drag" defaultValue={35} />
20
+ <Slider label="Jump on press" defaultValue={35} trackClick="jump" />
21
+ ```
22
+
23
+ ## Value placement
24
+
25
+ `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.
26
+
27
+ ```tsx
28
+ <Slider label="Volume" defaultValue={48} valueSuffix="%" />
29
+ <Slider label="Volume" defaultValue={48} valueDisplay="inline" valueSuffix="%" />
30
+ <Slider label="Volume" defaultValue={48} valueDisplay="thumb" valueSuffix="%" />
31
+ ```
32
+
33
+ ## Size, tones, and radius
34
+
35
+ `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 color. `tone` colors the filled rail. `thumbTone` separately colors 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.
36
+
37
+ ```tsx
38
+ <Slider size="small" tone="info" label="Small" defaultValue={32} />
39
+ <Slider tone="brand" thumbTone="success" trackSize={4} thumbSize={20} thumbFill label="Medium, filled thumb" defaultValue={52} />
40
+ <Slider size="large" tone="success" round={4} label="Large, 4px corners" defaultValue={72} />
41
+ ```
42
+
43
+ ## Markers
44
+
45
+ `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.
46
+
47
+ ```tsx
48
+ <Slider
49
+ label="Playback speed"
50
+ min={0.5}
51
+ max={2}
52
+ step={0.25}
53
+ defaultValue={1}
54
+ markers={[
55
+ { value: 0.5, label: '0.5×' },
56
+ { value: 1, label: 'Normal' },
57
+ { value: 2, label: '2×' },
58
+ ]}
59
+ />
60
+ ```
61
+
62
+ ### Props
63
+
64
+ | Prop | Type | Default | Description |
65
+ |------|------|---------|-------------|
66
+ | `defaultValue?` | number | 0 | Initial uncontrolled value. |
67
+ | `disabled?` | boolean | — | Disables pointer and keyboard interaction. |
68
+ | `label?` | ReactNode | — | Visible field label, shown above the rail. A string supplies the slider's
69
+ accessible name; give a rich label an explicit `aria-label`. |
70
+ | `markers?` | SliderMarker[] | — | Compact text labels positioned below the rail. They do not add dots or
71
+ ticks to the rail. |
72
+ | `max?` | number | 100 | Highest permitted value. |
73
+ | `min?` | number | 0 | Lowest permitted value. |
74
+ | `name?` | string | — | Form field name. The current numeric value submits under this name. |
75
+ | `onValueChange?` | (event, attrs) => void | — | Fires on every keyboard or pointer value change. |
76
+ | `onValueCommit?` | (event, attrs) => void | — | Fires after a drag ends and after each keyboard value change. |
77
+ | `round?` | boolean \| number \| string | — | Fully round the rail and thumb. Pass a number (px) or CSS length string
78
+ for a shared custom radius. |
79
+ | `size?` | 'small' \| 'medium' \| 'large' | 'medium' | Size variant. small=24px, medium=28px, large=32px tall. |
80
+ | `step?` | number | 1 | Smallest keyboard and drag increment. |
81
+ | `thumbFill?` | boolean | false | Fill the thumb with its resolved border color. This follows `thumbTone`
82
+ and interactive states. |
83
+ | `thumbSize?` | number \| string | 18 | Diameter of the thumb. Numbers use pixels; strings are CSS lengths. Keep
84
+ it at least as large as `trackSize`. |
85
+ | `thumbTone?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'neutral' | Color of the thumb stroke. Pass a named tone or a literal CSS color for a
86
+ one-off custom tone. Omit it to keep the thumb neutral. |
87
+ | `tone?` | 'neutral' \| 'brand' \| 'info' \| 'success' \| 'warning' \| 'critical' \| (string & {}) | 'neutral' | Color of the filled rail. Pass a named tone or a literal CSS color for a
88
+ one-off custom tone. The unfilled rail stays neutral. |
89
+ | `trackClick?` | 'drag-only' \| 'jump' | 'drag-only' | Controls what happens when the rail is pressed. `drag-only` starts dragging
90
+ from the current value. `jump` first moves to the pressed position. |
91
+ | `trackSize?` | number \| string | 2 | Thickness of both rail segments. Numbers use pixels; strings are CSS
92
+ lengths. Keep it no larger than the thumb diameter. |
93
+ | `value?` | number | — | Controlled value. Update it from `onValueChange`. |
94
+ | `valueDisplay?` | 'end' \| 'inline' \| 'thumb' \| 'none' | 'end' | Where the live value appears. `end` puts it at the right edge of the label
95
+ row. `inline` renders `Label: value`. `thumb` keeps it above the thumb. |
96
+ | `valuePrefix?` | string | — | Text inserted before the live numeric value, such as `$`. |
97
+ | `valueSuffix?` | string | — | Text inserted after the live numeric value, such as `%` or `°C`. |
98
+
99
+ 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`.
100
+
101
+ ```html
102
+ <a-slider
103
+ role="slider"
104
+ tabindex="0"
105
+ aria-label="Volume"
106
+ name="volume"
107
+ defaultvalue="50"
108
+ track-size="4px"
109
+ thumb-fill
110
+ thumb-size="20px"
111
+ value-suffix="%"
112
+ >
113
+ <span slot="label">Volume</span>
114
+ </a-slider>
115
+ ```
116
+
117
+ ### Native HTML range input
118
+
119
+ Add `data-anta` to a native range input for Anta's rail, fill, thumb, and focus
120
+ treatment while retaining the browser's form, keyboard, and pointer behavior.
121
+
122
+ Use `size="small"` or `"large"` for the 24px and 32px control sizes.
123
+ `track-size` accepts a CSS length and changes both rail segments. `tone`,
124
+ `thumb-tone`, `thumb-fill`, `thumb-size`, and `round` use the same attributes
125
+ as `Slider`. In raw HTML, `round` needs a CSS length such as `"4px"`; JSX
126
+ `round={4}` remains a numeric pixel value.
127
+
128
+ ```html
129
+ <input data-anta type="range" min="0" max="100" value="48" aria-label="Native range">
130
+ <input data-anta type="range" min="0" max="100" value="32" size="small" tone="info" aria-label="Small info native range">
131
+ <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">
132
+ <input data-anta type="range" min="0" max="100" value="72" size="large" tone="success" round="4px" aria-label="Large rounded success native range">
133
+ ```
134
+
135
+ ## Styling
136
+
137
+ `Slider` renders an `<a-slider>` with a circular thumb. `tone` and `thumbTone` accept named or custom CSS colors; 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)` customizes the thumb’s surface and stroke. The element exposes `header`, `label`, `value`, `control`, `track`, `fill`, `thumb`, `thumb-value`, `markers`, and `extras`.
138
+
139
+ ```css
140
+ /* The class is only for the demo. Use your own selector. */
141
+ .warm-slider::part(fill) { background: #e5484d; }
142
+ .warm-slider::part(thumb) {
143
+ background: #fff7ed;
144
+ border-color: #e5484d;
145
+ border-radius: 4px;
146
+ }
147
+ ```
@@ -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` colors 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` colors 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
+ ## Coloring 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 color 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 and 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' | Color of the track and thumb. A tinted tone also colors the unchecked
147
+ track border and thumb; use `toneSelected` to color 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` colors the unchecked
150
+ state and `toneSelected` colors the checked track. |
151
+ | `value?` | string | "on" | Value submitted while checked. |
152
+
153
+ Use the web component directly when you are not using React or Preact and a native control does not fit.
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`** colors the checked track plus the unchecked chrome, while **`toneSelected`** colors 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 color" />
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 in these examples are demo hooks. Replace them with a selector you own.
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
+ ```