svelte-ant-design 0.4.0 → 0.5.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/README.md +13 -4
- package/dist/Checkbox/Checkbox.svelte +27 -0
- package/dist/Checkbox/README.md +1 -0
- package/dist/Input/README.md +3 -1
- package/dist/Input/types.d.ts +4 -1
- package/dist/Select/README.md +104 -0
- package/dist/Select/Select.svelte +1554 -0
- package/dist/Select/Select.svelte.d.ts +7 -0
- package/dist/Select/SelectIcon.svelte +76 -0
- package/dist/Select/SelectIcon.svelte.d.ts +7 -0
- package/dist/Select/SelectOptGroup.svelte +29 -0
- package/dist/Select/SelectOptGroup.svelte.d.ts +4 -0
- package/dist/Select/SelectOption.svelte +37 -0
- package/dist/Select/SelectOption.svelte.d.ts +4 -0
- package/dist/Select/context.d.ts +39 -0
- package/dist/Select/context.js +17 -0
- package/dist/Select/options.d.ts +116 -0
- package/dist/Select/options.js +289 -0
- package/dist/Select/types.d.ts +216 -0
- package/dist/Select/types.js +1 -0
- package/dist/Switch/README.md +1 -0
- package/dist/Switch/Switch.svelte +69 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -1
- package/dist/internal/popup/Popup.svelte +484 -0
- package/dist/internal/popup/Popup.svelte.d.ts +50 -0
- package/dist/internal/popup/layers.d.ts +30 -0
- package/dist/internal/popup/layers.js +75 -0
- package/dist/internal/popup/placement.d.ts +61 -0
- package/dist/internal/popup/placement.js +108 -0
- package/dist/internal/popup/triggers.d.ts +29 -0
- package/dist/internal/popup/triggers.js +90 -0
- package/dist/internal/popup/types.d.ts +32 -0
- package/dist/internal/popup/types.js +23 -0
- package/dist/tokens-accessible.css +10 -1
- package/dist/tokens.css +67 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Ant Design.
|
|
|
18
18
|
|
|
19
19
|
## Status
|
|
20
20
|
|
|
21
|
-
Version `0.
|
|
21
|
+
Version `0.5.0`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Select` (with `SelectOption` and `SelectOptGroup`), `Switch`. More components are planned.
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
@@ -51,11 +51,13 @@ Vite in `tests/packaging`; other bundlers are not covered.
|
|
|
51
51
|
|
|
52
52
|
See the [Button](https://prostreyd.github.io/ant-design-svelte/components/button/),
|
|
53
53
|
[Checkbox](https://prostreyd.github.io/ant-design-svelte/components/checkbox/),
|
|
54
|
-
[Input](https://prostreyd.github.io/ant-design-svelte/components/input/)
|
|
54
|
+
[Input](https://prostreyd.github.io/ant-design-svelte/components/input/),
|
|
55
|
+
[Select](https://prostreyd.github.io/ant-design-svelte/components/select/) and
|
|
55
56
|
[Switch](https://prostreyd.github.io/ant-design-svelte/components/switch/) pages of the documentation site for
|
|
56
57
|
examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/README.md),
|
|
57
58
|
[`src/lib/Checkbox/README.md`](./src/lib/Checkbox/README.md),
|
|
58
|
-
[`src/lib/Input/README.md`](./src/lib/Input/README.md)
|
|
59
|
+
[`src/lib/Input/README.md`](./src/lib/Input/README.md),
|
|
60
|
+
[`src/lib/Select/README.md`](./src/lib/Select/README.md) and
|
|
59
61
|
[`src/lib/Switch/README.md`](./src/lib/Switch/README.md) in the repository.
|
|
60
62
|
|
|
61
63
|
### Colors and contrast
|
|
@@ -86,13 +88,20 @@ npm install
|
|
|
86
88
|
npm run dev # documentation site (SvelteKit, in docs/), with live reload
|
|
87
89
|
npm test # unit and accessibility tests of the library and of the site content (Vitest)
|
|
88
90
|
npm run test:coverage
|
|
89
|
-
npm run test:e2e # library tests in
|
|
91
|
+
npm run test:e2e # library tests in Chromium, Firefox and WebKit (Playwright)
|
|
90
92
|
npm run check # svelte-check (type checking of the library)
|
|
91
93
|
npm run check:docs # svelte-check of the documentation site
|
|
92
94
|
npm run lint # ESLint
|
|
93
95
|
npm run package # build dist/ with svelte-package
|
|
94
96
|
```
|
|
95
97
|
|
|
98
|
+
The browser tests run in Chromium, Firefox and WebKit. Install them once, and again after Playwright is
|
|
99
|
+
updated (the builds belong to a version of Playwright):
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
npx playwright install chromium firefox webkit # on Linux add --with-deps for the system packages
|
|
103
|
+
```
|
|
104
|
+
|
|
96
105
|
The documentation site lives in `docs/` and imports the library from `src/lib`, so its examples
|
|
97
106
|
always show the code in the repository. To build it the way GitHub Pages serves it and test the result:
|
|
98
107
|
|
|
@@ -315,6 +315,33 @@
|
|
|
315
315
|
--_bar: var(--ads-checkbox-disabled-check-color);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/*
|
|
319
|
+
* Forced colors (Windows High Contrast): the system replaces the author's backgrounds, and the bar of an
|
|
320
|
+
* indeterminate box is a background, so it would vanish and the box would look unchecked. The bar and the
|
|
321
|
+
* disabled parts take system colors. The check mark is a border and keeps showing.
|
|
322
|
+
*/
|
|
323
|
+
@media (forced-colors: active) {
|
|
324
|
+
.ads-checkbox-indeterminate .ads-checkbox-icon::after {
|
|
325
|
+
background-color: ButtonText;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.ads-checkbox-disabled {
|
|
329
|
+
color: GrayText;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.ads-checkbox-disabled .ads-checkbox-icon {
|
|
333
|
+
border-color: GrayText;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.ads-checkbox-disabled .ads-checkbox-icon::after {
|
|
337
|
+
border-color: GrayText;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.ads-checkbox-disabled.ads-checkbox-indeterminate .ads-checkbox-icon::after {
|
|
341
|
+
background-color: GrayText;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
318
345
|
@media (prefers-reduced-motion: reduce) {
|
|
319
346
|
.ads-checkbox-icon,
|
|
320
347
|
.ads-checkbox-icon::after {
|
package/dist/Checkbox/README.md
CHANGED
|
@@ -156,6 +156,7 @@ It darkens the unchecked border (`#737373`) and the checked hover fill (`#0958d9
|
|
|
156
156
|
- A group has `role="group"`; name it with `aria-label` or `aria-labelledby`, or wrap it in a `<fieldset>` with a `<legend>`.
|
|
157
157
|
- A visible `:focus-visible` outline from the design tokens around the box, at least 3:1 against the page.
|
|
158
158
|
- The border, the check mark, the bar and the focus ring keep at least 3:1 contrast, and the label text 4.5:1, in every state: in the dark theme, and in the light theme when `tokens-accessible.css` is imported (see Colors).
|
|
159
|
+
- In forced-colors modes such as Windows High Contrast the bar of an indeterminate box is drawn in the text color, so it still differs from an unchecked box, and a disabled checkbox uses the disabled color.
|
|
159
160
|
- Under `prefers-reduced-motion: reduce` the transitions are disabled.
|
|
160
161
|
- Positions use logical properties, so the checkbox mirrors in right-to-left layouts. Toggling `checked`, `indeterminate` or `disabled` never changes the size of the control or moves its neighbours.
|
|
161
162
|
|
package/dist/Input/README.md
CHANGED
|
@@ -31,7 +31,9 @@ import 'svelte-ant-design/tokens.css';
|
|
|
31
31
|
A field has no label of its own: name it with an external `<label for>` (and the `id` of the field), `aria-label`
|
|
32
32
|
or `aria-labelledby`.
|
|
33
33
|
|
|
34
|
-
`onchange` is called on every edit with the new text and the
|
|
34
|
+
`onchange` is called on every edit with the new text and the event of the edit, as `onChange` in React: the native
|
|
35
|
+
`input` event, or `compositionend` when a browser (Firefox, for one) ends an IME composition before its last `input`
|
|
36
|
+
event. The text and the number of calls are the same either way.
|
|
35
37
|
|
|
36
38
|
```svelte
|
|
37
39
|
<Input onchange={(value, event) => console.log(value, event.type)} aria-label="Query" />
|
package/dist/Input/types.d.ts
CHANGED
|
@@ -79,7 +79,10 @@ interface FieldProps {
|
|
|
79
79
|
};
|
|
80
80
|
/** Character counting configuration (a soft limit, a custom count, cutting). */
|
|
81
81
|
count?: CountConfig;
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Called once per user edit, with the new text and the event of the edit: the native `input` event, or
|
|
84
|
+
* `compositionend` when the browser ends an IME composition before its last `input` event (Firefox does).
|
|
85
|
+
*/
|
|
83
86
|
onchange?: (value: string, event: Event) => void;
|
|
84
87
|
/** Called when the clear button emptied the text. */
|
|
85
88
|
onclear?: (event: MouseEvent) => void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Select
|
|
2
|
+
|
|
3
|
+
A drop-down list with Ant Design-inspired styles and a Svelte 5 API. Three components:
|
|
4
|
+
|
|
5
|
+
| Component | What it is |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `Select` | the field and its list, in the modes single (default), `multiple` and `tags` |
|
|
8
|
+
| `SelectOption` | one option, written inside `Select` or `SelectOptGroup` (the markup form of an `options` entry) |
|
|
9
|
+
| `SelectOptGroup` | a labelled group of `SelectOption`s |
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Import the design tokens once in the application entry point:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import 'svelte-ant-design/tokens.css';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```svelte
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { Select } from 'svelte-ant-design';
|
|
22
|
+
|
|
23
|
+
let city = $state<string | number | undefined>();
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<Select
|
|
27
|
+
bind:value={city}
|
|
28
|
+
aria-label="City"
|
|
29
|
+
placeholder="Pick a city"
|
|
30
|
+
options={['Bishkek', 'Almaty', { value: 'tashkent', label: 'Tashkent' }]}
|
|
31
|
+
style="width: 240px"
|
|
32
|
+
/>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
A Select has no label of its own: name it with an external `<label for>` (and the `id` of the field), `aria-label`
|
|
36
|
+
or `aria-labelledby`. The placeholder is not a name. The field fills its container like `Input`; set the width with
|
|
37
|
+
`class` or `style`.
|
|
38
|
+
|
|
39
|
+
`options` take strings and numbers (both the value and the label), objects (`{ value, label, disabled, title, class }`,
|
|
40
|
+
other keys pass through to the callbacks) and groups (an object with an `options` array). `fieldNames` maps the keys of
|
|
41
|
+
your own data. `onchange` receives the value and the option object; for `multiple` and `tags` the value is an array and
|
|
42
|
+
the option is an array of objects.
|
|
43
|
+
|
|
44
|
+
```svelte
|
|
45
|
+
<Select mode="multiple" bind:value={languages} options={['Svelte', 'Rust', 'Go']} aria-label="Languages" maxTagCount={2} />
|
|
46
|
+
<Select mode="tags" bind:value={tags} tokenSeparators={[',']} aria-label="Tags" />
|
|
47
|
+
<Select showSearch options={people} optionFilterProp={['label', 'team']} aria-label="Person" />
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Options as markup
|
|
51
|
+
|
|
52
|
+
`SelectOption` and `SelectOptGroup` written inside `Select` give the same options as `options`, in the order of the
|
|
53
|
+
markup, also after `{#each}` and `{#if}` insert or move one. A non-empty `options` wins and the children are ignored.
|
|
54
|
+
|
|
55
|
+
```svelte
|
|
56
|
+
<Select bind:value aria-label="Mood">
|
|
57
|
+
<SelectOption value="happy" label="Happy" />
|
|
58
|
+
<SelectOptGroup label="Other">
|
|
59
|
+
<SelectOption value="sad" label="Sad" />
|
|
60
|
+
</SelectOptGroup>
|
|
61
|
+
</Select>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The text that search, type-ahead and the accessible name use is the `label` when it is a string, then the `title`, then
|
|
65
|
+
the value. The content of an option (its `children`) is only drawn, so write a `label` for an option that has to be found
|
|
66
|
+
by search.
|
|
67
|
+
|
|
68
|
+
## Behavior to know
|
|
69
|
+
|
|
70
|
+
- DOM focus never leaves the field: the highlighted option is shown by `aria-activedescendant`, and a press inside the
|
|
71
|
+
list does not blur the field.
|
|
72
|
+
- The list is put at the end of the page (`container` changes that), so it is never cut off by the container of the field.
|
|
73
|
+
It flips at the edge of the screen and follows the field while the page scrolls.
|
|
74
|
+
- The search text is cleared when the list closes, and `onsearch` is told. `filterOption={false}` leaves the list to you
|
|
75
|
+
(server-side search).
|
|
76
|
+
- Tab only closes the list and keeps the value.
|
|
77
|
+
- A long list renders all its options in this version (there is no `virtual` yet); `listHeight` makes it scroll.
|
|
78
|
+
- The built-in texts (`No data`, `Clear`, `Remove ...`, and the number of matches announced while searching) are English;
|
|
79
|
+
`notFoundContent`, `allowClear.label` and `resultsText` replace three of them.
|
|
80
|
+
- The type of an option object is `SelectOptionItem`, because `SelectOption` is the component.
|
|
81
|
+
- The field is not a native form control: it does not submit with a `<form>`. Read `value`.
|
|
82
|
+
|
|
83
|
+
## Accessibility
|
|
84
|
+
|
|
85
|
+
The focused element is a `<div>` or, with `showSearch`, an `<input>`, with `role="combobox"`, `aria-expanded`,
|
|
86
|
+
`aria-controls` and `aria-activedescendant`; the list is a `listbox` of `option`s and `group`s. Keys: Down, Up, Alt+Down,
|
|
87
|
+
Alt+Up, Enter, Space, Home, End, PageUp, PageDown, Escape, Tab, Backspace, and typing characters in a field that cannot
|
|
88
|
+
search. Forced-colors modes (Windows High Contrast) are supported. Support for `aria-activedescendant` in iOS VoiceOver has
|
|
89
|
+
been weak, so check a Select by hand there.
|
|
90
|
+
|
|
91
|
+
Known limitation: Orca announces a change of `aria-selected` only after the Space key. In a field that searches (the default
|
|
92
|
+
of `multiple` and `tags`) Space types a space and Enter toggles an option, so Orca says nothing when one is toggled; the
|
|
93
|
+
field reads the selected values when it gets focus. The React, Vue and Angular demos of Ant Design are silent in the same
|
|
94
|
+
case. An announcement of the toggled option (`selectionText`) is planned for v1.1 with the translation of the built-in texts,
|
|
95
|
+
after NVDA, JAWS and VoiceOver have been tried.
|
|
96
|
+
|
|
97
|
+
The default light colors are Ant Design's own and do not reach WCAG AA for every text. Import `tokens-accessible.css`
|
|
98
|
+
after `tokens.css` for colors that do.
|
|
99
|
+
|
|
100
|
+
## API and examples
|
|
101
|
+
|
|
102
|
+
The API tables, the methods and the design tokens are on the
|
|
103
|
+
[Select page](https://prostreyd.github.io/ant-design-svelte/components/select/) of the documentation site, with a live
|
|
104
|
+
example for every property. The specification is [`specs/select.md`](../../../specs/select.md).
|