svelte-ant-design 0.3.0 → 0.4.1
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 +15 -6
- package/dist/Checkbox/Checkbox.svelte +27 -0
- package/dist/Checkbox/README.md +1 -0
- package/dist/Input/ClearButton.svelte +89 -0
- package/dist/Input/ClearButton.svelte.d.ts +14 -0
- package/dist/Input/Input.svelte +530 -0
- package/dist/Input/Input.svelte.d.ts +7 -0
- package/dist/Input/InputIcon.svelte +82 -0
- package/dist/Input/InputIcon.svelte.d.ts +7 -0
- package/dist/Input/InputOTP.svelte +248 -0
- package/dist/Input/InputOTP.svelte.d.ts +43 -0
- package/dist/Input/InputPassword.svelte +125 -0
- package/dist/Input/InputPassword.svelte.d.ts +21 -0
- package/dist/Input/InputSearch.svelte +257 -0
- package/dist/Input/InputSearch.svelte.d.ts +24 -0
- package/dist/Input/InputTextArea.svelte +495 -0
- package/dist/Input/InputTextArea.svelte.d.ts +7 -0
- package/dist/Input/README.md +166 -0
- package/dist/Input/field.d.ts +35 -0
- package/dist/Input/field.js +77 -0
- package/dist/Input/types.d.ts +129 -0
- package/dist/Input/types.js +1 -0
- package/dist/Switch/README.md +1 -0
- package/dist/Switch/Switch.svelte +69 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -1
- package/dist/tokens-accessible.css +19 -3
- package/dist/tokens.css +81 -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.4.1`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Switch`. More components are planned.
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
@@ -50,10 +50,12 @@ bundler that supports tree shaking leaves out the components you do not use. Thi
|
|
|
50
50
|
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
|
-
[Checkbox](https://prostreyd.github.io/ant-design-svelte/components/checkbox/)
|
|
53
|
+
[Checkbox](https://prostreyd.github.io/ant-design-svelte/components/checkbox/),
|
|
54
|
+
[Input](https://prostreyd.github.io/ant-design-svelte/components/input/) and
|
|
54
55
|
[Switch](https://prostreyd.github.io/ant-design-svelte/components/switch/) pages of the documentation site for
|
|
55
56
|
examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/README.md),
|
|
56
|
-
[`src/lib/Checkbox/README.md`](./src/lib/Checkbox/README.md)
|
|
57
|
+
[`src/lib/Checkbox/README.md`](./src/lib/Checkbox/README.md),
|
|
58
|
+
[`src/lib/Input/README.md`](./src/lib/Input/README.md) and
|
|
57
59
|
[`src/lib/Switch/README.md`](./src/lib/Switch/README.md) in the repository.
|
|
58
60
|
|
|
59
61
|
### Colors and contrast
|
|
@@ -61,14 +63,14 @@ examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/RE
|
|
|
61
63
|
In the light theme the colors are the values of the Ant Design token documentation, so the components look
|
|
62
64
|
like Ant Design. Those values do not reach WCAG AA for text: white on the primary fill is 4.10:1 and on the
|
|
63
65
|
danger fill 3.27:1 (4.5:1 is needed), the off track of a switch is 1.84:1 against a white page and the border of
|
|
64
|
-
an unchecked checkbox 1.41:1 (3:1 is needed). For a contrast guarantee import one more file after the tokens:
|
|
66
|
+
an unchecked checkbox or the border of an input 1.41:1 (3:1 is needed). For a contrast guarantee import one more file after the tokens:
|
|
65
67
|
|
|
66
68
|
```ts
|
|
67
69
|
import 'svelte-ant-design/tokens.css';
|
|
68
70
|
import 'svelte-ant-design/tokens-accessible.css';
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
It darkens the fills, the link and text colors, the switch tracks and the
|
|
73
|
+
It darkens the fills, the link and text colors, the switch tracks, the checkbox border and the input border, placeholder and count; every text pair is then at least 4.5:1.
|
|
72
74
|
The dark theme needs no extra file. The contrast tests run with the accessible file.
|
|
73
75
|
|
|
74
76
|
### Dark theme
|
|
@@ -84,13 +86,20 @@ npm install
|
|
|
84
86
|
npm run dev # documentation site (SvelteKit, in docs/), with live reload
|
|
85
87
|
npm test # unit and accessibility tests of the library and of the site content (Vitest)
|
|
86
88
|
npm run test:coverage
|
|
87
|
-
npm run test:e2e # library tests in
|
|
89
|
+
npm run test:e2e # library tests in Chromium, Firefox and WebKit (Playwright)
|
|
88
90
|
npm run check # svelte-check (type checking of the library)
|
|
89
91
|
npm run check:docs # svelte-check of the documentation site
|
|
90
92
|
npm run lint # ESLint
|
|
91
93
|
npm run package # build dist/ with svelte-package
|
|
92
94
|
```
|
|
93
95
|
|
|
96
|
+
The browser tests run in Chromium, Firefox and WebKit. Install them once, and again after Playwright is
|
|
97
|
+
updated (the builds belong to a version of Playwright):
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
npx playwright install chromium firefox webkit # on Linux add --with-deps for the system packages
|
|
101
|
+
```
|
|
102
|
+
|
|
94
103
|
The documentation site lives in `docs/` and imports the library from `src/lib`, so its examples
|
|
95
104
|
always show the code in the repository. To build it the way GitHub Pages serves it and test the result:
|
|
96
105
|
|
|
@@ -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
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { AllowClearConfig } from './types.js';
|
|
4
|
+
import InputIcon from './InputIcon.svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
config,
|
|
8
|
+
visible,
|
|
9
|
+
class: extraClass,
|
|
10
|
+
style,
|
|
11
|
+
onclear
|
|
12
|
+
}: {
|
|
13
|
+
/** The object form of `allowClear`, if there is one. */
|
|
14
|
+
config: AllowClearConfig | undefined;
|
|
15
|
+
/** Whether there is something to clear. The button keeps its place in the layout either way. */
|
|
16
|
+
visible: boolean;
|
|
17
|
+
/** Extra classes (the `clear` part of `classNames`); the component's own are static. */
|
|
18
|
+
class: string | undefined;
|
|
19
|
+
style: string | undefined;
|
|
20
|
+
onclear: (event: MouseEvent) => void;
|
|
21
|
+
} = $props();
|
|
22
|
+
|
|
23
|
+
const icon: string | Snippet | undefined = $derived(config?.clearIcon);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!--
|
|
27
|
+
A native button. While there is nothing to clear it is hidden with `visibility`, which keeps its space (the
|
|
28
|
+
field does not change size when the text appears) and takes it out of the Tab order and the accessibility
|
|
29
|
+
tree. A press does not take focus from the field.
|
|
30
|
+
-->
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
class="ads-input-clear {extraClass}"
|
|
34
|
+
{style}
|
|
35
|
+
class:ads-input-clear-hidden={!visible}
|
|
36
|
+
aria-label={config?.label ?? 'Clear'}
|
|
37
|
+
tabindex={config?.tabIndex}
|
|
38
|
+
onmousedown={(event) => event.preventDefault()}
|
|
39
|
+
onclick={onclear}
|
|
40
|
+
>
|
|
41
|
+
{#if icon === undefined}
|
|
42
|
+
<InputIcon name="clear" />
|
|
43
|
+
{:else if typeof icon === 'string'}
|
|
44
|
+
{icon}
|
|
45
|
+
{:else}
|
|
46
|
+
{@render icon()}
|
|
47
|
+
{/if}
|
|
48
|
+
</button>
|
|
49
|
+
|
|
50
|
+
<style>
|
|
51
|
+
.ads-input-clear {
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
flex: none;
|
|
54
|
+
align-items: center;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
margin: 0;
|
|
58
|
+
margin-inline-start: var(--ads-input-gap);
|
|
59
|
+
padding: 0;
|
|
60
|
+
border: 0;
|
|
61
|
+
border-radius: 50%;
|
|
62
|
+
background: transparent;
|
|
63
|
+
color: var(--ads-input-icon-color);
|
|
64
|
+
font: inherit;
|
|
65
|
+
font-size: var(--ads-input-icon-size);
|
|
66
|
+
line-height: 1;
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
transition: color var(--ads-motion-duration) var(--ads-motion-ease);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.ads-input-clear:hover {
|
|
72
|
+
color: var(--ads-input-icon-color-hover);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.ads-input-clear:focus-visible {
|
|
76
|
+
outline: var(--ads-focus-outline-width) solid var(--ads-color-focus-outline);
|
|
77
|
+
outline-offset: 1px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.ads-input-clear-hidden {
|
|
81
|
+
visibility: hidden;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@media (prefers-reduced-motion: reduce) {
|
|
85
|
+
.ads-input-clear {
|
|
86
|
+
transition: none;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AllowClearConfig } from './types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
/** The object form of `allowClear`, if there is one. */
|
|
4
|
+
config: AllowClearConfig | undefined;
|
|
5
|
+
/** Whether there is something to clear. The button keeps its place in the layout either way. */
|
|
6
|
+
visible: boolean;
|
|
7
|
+
/** Extra classes (the `clear` part of `classNames`); the component's own are static. */
|
|
8
|
+
class: string | undefined;
|
|
9
|
+
style: string | undefined;
|
|
10
|
+
onclear: (event: MouseEvent) => void;
|
|
11
|
+
};
|
|
12
|
+
declare const ClearButton: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
13
|
+
type ClearButton = ReturnType<typeof ClearButton>;
|
|
14
|
+
export default ClearButton;
|