@antadesign/anta 0.3.32 → 0.3.34
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/avatar-core.d.ts +7 -2
- package/dist/bundle.css +1 -1
- package/dist/bundle.js +48 -58
- package/dist/components/Breadcrumbs.d.ts +0 -1
- package/dist/components/Breadcrumbs.js +0 -1
- package/dist/components/Button.d.ts +2 -3
- package/dist/components/Input.d.ts +9 -3
- package/dist/components/Input.js +2 -0
- package/dist/components/InputDate.d.ts +0 -1
- package/dist/components/InputDate.js +0 -1
- package/dist/components/Select.d.ts +0 -1
- package/dist/components/Select.js +0 -1
- package/dist/components/SelectFaceted.d.ts +0 -1
- package/dist/components/SelectFaceted.js +0 -1
- package/dist/components/Slider.d.ts +22 -10
- package/dist/components/Slider.js +9 -5
- package/dist/components/Steps.d.ts +0 -1
- package/dist/components/Steps.js +0 -1
- package/dist/components/Tabs.js +2 -1
- package/dist/components/Title.d.ts +3 -1
- package/dist/elements/a-avatar.css +1 -1
- package/dist/elements/a-avatar.js +2 -28
- package/dist/elements/a-breadcrumbs.d.ts +1 -0
- package/dist/elements/a-breadcrumbs.js +1 -0
- package/dist/elements/a-button.css +1 -1
- package/dist/elements/a-button.d.ts +8 -6
- package/dist/elements/a-button.js +2 -4
- package/dist/elements/a-dialog.js +3 -1
- package/dist/elements/a-input-date.d.ts +1 -0
- package/dist/elements/a-input-date.js +1 -0
- package/dist/elements/a-input-time.js +1 -2
- package/dist/elements/a-input.css +1 -1
- package/dist/elements/a-input.js +13 -10
- package/dist/elements/a-menu.d.ts +1 -1
- package/dist/elements/a-menu.js +17 -4
- package/dist/elements/a-select-faceted.d.ts +1 -0
- package/dist/elements/a-select-faceted.js +1 -0
- package/dist/elements/a-select.d.ts +1 -0
- package/dist/elements/a-select.js +1 -0
- package/dist/elements/a-slider.d.ts +7 -5
- package/dist/elements/a-slider.js +256 -59
- package/dist/elements/a-steps.d.ts +1 -0
- package/dist/elements/a-steps.js +1 -0
- package/dist/elements/a-tabpanel.d.ts +2 -2
- package/dist/elements/a-tabpanel.js +13 -3
- package/dist/elements/a-tag.d.ts +1 -0
- package/dist/elements/a-tag.js +1 -0
- package/dist/elements/a-title.d.ts +1 -0
- package/dist/elements/a-title.js +1 -0
- package/dist/elements/index.d.ts +7 -1
- package/dist/elements/index.js +4 -0
- package/dist/general_types.d.ts +9 -4
- package/dist/index.d.ts +1 -1
- package/dist/theme-antithesis.css +1 -1
- package/dist/theme-antune.css +1 -1
- package/docs/changelog.md +61 -0
- package/docs/components/breadcrumbs.md +9 -6
- package/docs/components/button.md +9 -6
- package/docs/components/input.md +29 -9
- package/docs/components/panel.md +3 -2
- package/docs/components/select-faceted.md +19 -19
- package/docs/components/slider.md +139 -4
- package/docs/components/steps.md +4 -2
- package/docs/install-config.md +295 -87
- package/docs/packages/plot.md +222 -20
- package/docs/theming.md +22 -13
- package/package.json +7 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Slider
|
|
2
2
|
|
|
3
|
-
**`Slider`** selects one
|
|
3
|
+
**`Slider`** selects one number or an interval between two numbers. Pass a number
|
|
4
|
+
for one thumb or a two-number tuple for two thumbs. Its label sits above the
|
|
4
5
|
rail, and the value appears at the right side of the label row by default. Use
|
|
5
6
|
`value` with `onValueChange` to control it, or `defaultValue` for uncontrolled use.
|
|
6
7
|
|
|
@@ -23,6 +24,55 @@ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp an
|
|
|
23
24
|
<Slider label="Jump on press" defaultValue={35} trackClick="jump" />
|
|
24
25
|
```
|
|
25
26
|
|
|
27
|
+
## Range values
|
|
28
|
+
|
|
29
|
+
Pass two numbers to `value` or `defaultValue` to show two thumbs. Drag either
|
|
30
|
+
thumb across the other to move past it. The thumb you grabbed keeps moving, and
|
|
31
|
+
the value stays ordered from low to high. For example, dragging the thumb at 20
|
|
32
|
+
past 70 to 85 changes `[20, 70]` to `[70, 85]`. Both thumbs can share a value.
|
|
33
|
+
Each thumb has its own keyboard focus. Their tab order stays fixed when they
|
|
34
|
+
cross.
|
|
35
|
+
|
|
36
|
+
`onValueChange` receives a number for a single-value slider and an ordered
|
|
37
|
+
`[number, number]` tuple for a range slider. `onValueCommit` uses the same shape.
|
|
38
|
+
Without `defaultValue`, a form reset selects the full `[min, max]` range.
|
|
39
|
+
|
|
40
|
+
```tsx title="Controlled range"
|
|
41
|
+
import { useState } from 'preact/hooks'
|
|
42
|
+
import { Slider } from '@antadesign/anta'
|
|
43
|
+
|
|
44
|
+
function SliderRangeDemo() {
|
|
45
|
+
const [value, setValue] = useState<[number, number]>([20, 70])
|
|
46
|
+
const [lastChange, setLastChange] = useState<[number, number] | null>(null)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<Slider
|
|
51
|
+
label="Selected interval"
|
|
52
|
+
value={value}
|
|
53
|
+
onValueChange={(_, { value: next }) => {
|
|
54
|
+
setValue(next)
|
|
55
|
+
setLastChange(next)
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
<p className="range-demo-output"><code>onValueChange</code>: <code>{lastChange ? JSON.stringify(lastChange) : '—'}</code></p>
|
|
59
|
+
</>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Inverted fill
|
|
65
|
+
|
|
66
|
+
Set `inverted` to fill the other part of the rail. For one thumb, the fill runs
|
|
67
|
+
from the value to the maximum. For two thumbs, the fill covers the rail outside
|
|
68
|
+
the selected interval. The minimum and maximum stay at their usual rail ends;
|
|
69
|
+
thumb movement and keyboard controls stay the same.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
<Slider label="Inverted single value" defaultValue={40} inverted />
|
|
73
|
+
<Slider label="Inverted range" defaultValue={[20, 70]} inverted />
|
|
74
|
+
```
|
|
75
|
+
|
|
26
76
|
## Value placement
|
|
27
77
|
|
|
28
78
|
`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.
|
|
@@ -66,13 +116,14 @@ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp an
|
|
|
66
116
|
|
|
67
117
|
| Prop | Type | Default | Description |
|
|
68
118
|
|------|------|---------|-------------|
|
|
69
|
-
| `defaultValue?` | number | 0 | Initial uncontrolled value. |
|
|
119
|
+
| `defaultValue?` | number \| SliderRangeValue | 0 | Initial uncontrolled value. |
|
|
70
120
|
| `disabled?` | boolean | — | Disables pointer and keyboard interaction. |
|
|
121
|
+
| `inverted?` | boolean | — | Fill the rail outside the selected value or range. |
|
|
71
122
|
| `label?` | ReactNode | — | Visible field label, shown above the rail. A string supplies the slider's accessible name; give a rich label an explicit `aria-label`. |
|
|
72
123
|
| `markers?` | SliderMarker[] | — | Compact text labels positioned below the rail. They do not add dots or ticks to the rail. |
|
|
73
124
|
| `max?` | number | 100 | Highest permitted value. |
|
|
74
125
|
| `min?` | number | 0 | Lowest permitted value. |
|
|
75
|
-
| `name?` | string | — | Form field name.
|
|
126
|
+
| `name?` | string | — | Form field name. A range submits two values under this name. |
|
|
76
127
|
| `onValueChange?` | (event, attrs) => void | — | Fires on every keyboard or pointer value change. |
|
|
77
128
|
| `onValueCommit?` | (event, attrs) => void | — | Fires after a drag ends and after each keyboard value change. |
|
|
78
129
|
| `round?` | boolean \| number \| string | — | Fully round the rail and thumb. Pass a number (px) or CSS length string for a shared custom radius. |
|
|
@@ -84,7 +135,7 @@ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp an
|
|
|
84
135
|
| `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 one-off custom tone. The unfilled rail stays neutral. |
|
|
85
136
|
| `trackClick?` | 'drag-only' \| 'jump' | 'drag-only' | Controls what happens when the rail is pressed. `drag-only` starts dragging from the current value. `jump` first moves to the pressed position. |
|
|
86
137
|
| `trackSize?` | number \| string | 2 | Thickness of both rail segments. Numbers use pixels; strings are CSS lengths. Keep it no larger than the thumb diameter. |
|
|
87
|
-
| `value?` | number | — | Controlled value. Update it from `onValueChange`. |
|
|
138
|
+
| `value?` | number \| SliderRangeValue | — | Controlled value. A pair of numbers selects a range. Update it from `onValueChange`. |
|
|
88
139
|
| `valueDisplay?` | 'end' \| 'inline' \| 'thumb' \| 'none' | 'end' | Where the live value appears. `end` puts it at the right edge of the label row. `inline` renders `Label: value`. `thumb` keeps it above the thumb. |
|
|
89
140
|
| `valuePrefix?` | string | — | Text inserted before the live numeric value, such as `$`. |
|
|
90
141
|
| `valueSuffix?` | string | — | Text inserted after the live numeric value, such as `%` or `°C`. |
|
|
@@ -93,6 +144,12 @@ Arrow keys change by `step`. Home and End set the minimum and maximum. PageUp an
|
|
|
93
144
|
|
|
94
145
|
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
146
|
|
|
147
|
+
For a range, separate the two numbers with a space in `value` or `defaultvalue`.
|
|
148
|
+
Use `role="group"` and give the range an accessible name. Each thumb receives
|
|
149
|
+
its own slider role and keyboard focus. The element's `value` property and
|
|
150
|
+
change events expose a two-number array. If you set `name`, form submission
|
|
151
|
+
includes both values in low-to-high order. Read them with `FormData.getAll(name)`.
|
|
152
|
+
|
|
96
153
|
```html
|
|
97
154
|
<a-slider
|
|
98
155
|
role="slider"
|
|
@@ -109,6 +166,12 @@ Use `<a-slider>` when you are not using React or Preact. Add its `role` and acce
|
|
|
109
166
|
</a-slider>
|
|
110
167
|
```
|
|
111
168
|
|
|
169
|
+
```html
|
|
170
|
+
<a-slider role="group" aria-label="Selected interval" name="interval" defaultvalue="20 70" inverted>
|
|
171
|
+
<span slot="label">Selected interval</span>
|
|
172
|
+
</a-slider>
|
|
173
|
+
```
|
|
174
|
+
|
|
112
175
|
### Native HTML range input
|
|
113
176
|
|
|
114
177
|
Add `data-anta` to a native range input for Anta's rail, fill, thumb, and focus
|
|
@@ -140,3 +203,75 @@ as `Slider`. In raw HTML, `round` needs a CSS length such as `"4px"`; JSX
|
|
|
140
203
|
border-radius: 4px;
|
|
141
204
|
}
|
|
142
205
|
```
|
|
206
|
+
|
|
207
|
+
### Editable value beside the label
|
|
208
|
+
|
|
209
|
+
Compose `Input` and `Slider` as separate controls. The grid puts the label and
|
|
210
|
+
small input on one row and the slider underneath. Pass `valueDisplay="none"` so the
|
|
211
|
+
slider does not repeat its value. Keep the input's text as a draft; when the
|
|
212
|
+
field loses focus or you press Enter, commit a number within the slider's range.
|
|
213
|
+
Dragging or using the slider's keyboard controls updates both values.
|
|
214
|
+
|
|
215
|
+
```tsx title="Slider with an editable value"
|
|
216
|
+
import { useState } from 'preact/hooks'
|
|
217
|
+
import { Input, Slider } from '@antadesign/anta'
|
|
218
|
+
|
|
219
|
+
function SliderEditableValueDemo() {
|
|
220
|
+
const [value, setValue] = useState(55)
|
|
221
|
+
const [draft, setDraft] = useState('55')
|
|
222
|
+
|
|
223
|
+
const commit = () => {
|
|
224
|
+
const number = Number(draft)
|
|
225
|
+
const next = draft.trim() && Number.isFinite(number)
|
|
226
|
+
? Math.max(0, Math.min(100, Math.round(number)))
|
|
227
|
+
: value
|
|
228
|
+
setValue(next)
|
|
229
|
+
setDraft(String(next))
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<div className="editable-slider">
|
|
234
|
+
<span className="editable-slider-label">Volume</span>
|
|
235
|
+
<Input
|
|
236
|
+
aria-label="Volume value"
|
|
237
|
+
size="small"
|
|
238
|
+
inputMode="numeric"
|
|
239
|
+
trailing="%"
|
|
240
|
+
value={draft}
|
|
241
|
+
onInput={(event) => setDraft(event.currentTarget.value)}
|
|
242
|
+
onBlur={commit}
|
|
243
|
+
onKeyDown={(event) => {
|
|
244
|
+
if (event.key === 'Enter') commit()
|
|
245
|
+
}}
|
|
246
|
+
/>
|
|
247
|
+
<Slider
|
|
248
|
+
aria-label="Volume"
|
|
249
|
+
value={value}
|
|
250
|
+
valueDisplay="none"
|
|
251
|
+
valueSuffix="%"
|
|
252
|
+
onValueChange={(_, { value: next }) => {
|
|
253
|
+
setValue(next)
|
|
254
|
+
setDraft(String(next))
|
|
255
|
+
}}
|
|
256
|
+
/>
|
|
257
|
+
</div>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```css title="Editable Slider layout"
|
|
263
|
+
.editable-slider {
|
|
264
|
+
display: grid;
|
|
265
|
+
grid-template-columns: minmax(0, 1fr) 72px;
|
|
266
|
+
align-items: center;
|
|
267
|
+
gap: 0 12px;
|
|
268
|
+
width: min(100%, 360px);
|
|
269
|
+
margin-inline: auto;
|
|
270
|
+
}
|
|
271
|
+
.editable-slider-label {
|
|
272
|
+
color: var(--text-3);
|
|
273
|
+
font-size: 15px;
|
|
274
|
+
font-weight: 500;
|
|
275
|
+
}
|
|
276
|
+
.editable-slider > a-slider { grid-column: 1 / -1; }
|
|
277
|
+
```
|
package/docs/components/steps.md
CHANGED
|
@@ -288,8 +288,10 @@ shipped Steps stylesheet. The [Tabs Web Component](./tabs.md#web-component) insi
|
|
|
288
288
|
owns selection and panel behavior; markers, states, and tones stay in your markup.
|
|
289
289
|
|
|
290
290
|
```js
|
|
291
|
-
import '@antadesign/anta/elements'
|
|
292
|
-
import '@antadesign/anta/
|
|
291
|
+
import '@antadesign/anta/elements/a-steps'
|
|
292
|
+
import '@antadesign/anta/elements/a-tabs'
|
|
293
|
+
import '@antadesign/anta/elements/a-tab'
|
|
294
|
+
import '@antadesign/anta/elements/a-tabpanel'
|
|
293
295
|
```
|
|
294
296
|
|
|
295
297
|
```html
|