svelte-ant-design 0.2.0 → 0.2.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 CHANGED
@@ -18,7 +18,7 @@ Ant Design.
18
18
 
19
19
  ## Status
20
20
 
21
- Version `0.2.0`. Available components: `Button`, `Switch`. More components are planned.
21
+ Version `0.2.1`. Available components: `Button`, `Switch`. More components are planned.
22
22
 
23
23
  ## Installation
24
24
 
@@ -54,6 +54,21 @@ See the [Button](https://prostreyd.github.io/ant-design-svelte/components/button
54
54
  examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/README.md) and
55
55
  [`src/lib/Switch/README.md`](./src/lib/Switch/README.md) in the repository.
56
56
 
57
+ ### Colors and contrast
58
+
59
+ In the light theme the colors are the values of the Ant Design token documentation, so the components look
60
+ like Ant Design. Those values do not reach WCAG AA for text: white on the primary fill is 4.10:1 and on the
61
+ danger fill 3.27:1 (4.5:1 is needed), and the off track of a switch is 1.84:1 against a white page (3:1 is
62
+ needed). For a contrast guarantee import one more file after the tokens:
63
+
64
+ ```ts
65
+ import 'svelte-ant-design/tokens.css';
66
+ import 'svelte-ant-design/tokens-accessible.css';
67
+ ```
68
+
69
+ It darkens the fills, the link and text colors and the switch tracks; every text pair is then at least 4.5:1.
70
+ The dark theme needs no extra file. The contrast tests run with the accessible file.
71
+
57
72
  ### Dark theme
58
73
 
59
74
  `tokens.css` does not touch the rest of your page: it sets no `color-scheme` for the light
@@ -314,17 +314,22 @@
314
314
  border-style: dashed;
315
315
  }
316
316
 
317
+ /* A text button keeps its text color on hover and pressed and only gets a background. */
317
318
  .ads-btn-text {
319
+ --_fg-hover: var(--ads-color-text);
320
+ --_fg-active: var(--ads-color-text);
318
321
  --_bg: transparent;
319
- --_bg-hover: var(--ads-color-bg-text-hover);
320
- --_bg-active: var(--ads-color-bg-text-hover);
322
+ --_bg-hover: var(--ads-button-text-hover-bg);
323
+ --_bg-active: var(--ads-button-text-active-bg);
321
324
  --_border: transparent;
322
325
  --_border-hover: transparent;
323
326
  --_border-active: transparent;
324
327
  }
325
328
 
326
329
  .ads-btn-link {
327
- --_fg: var(--ads-color-primary-text);
330
+ --_fg: var(--ads-color-link);
331
+ --_fg-hover: var(--ads-color-link-hover);
332
+ --_fg-active: var(--ads-color-link-active);
328
333
  --_bg: transparent;
329
334
  --_border: transparent;
330
335
  --_border-hover: transparent;
@@ -338,6 +343,13 @@
338
343
  --_fg: var(--ads-color-danger-text);
339
344
  }
340
345
 
346
+ /* More specific than the text and link rules above, so a danger one keeps its danger states. */
347
+ .ads-btn-danger.ads-btn-text,
348
+ .ads-btn-danger.ads-btn-link {
349
+ --_fg-hover: var(--ads-color-danger-text-hover);
350
+ --_fg-active: var(--ads-color-danger-text-active);
351
+ }
352
+
341
353
  .ads-btn-danger.ads-btn-primary {
342
354
  --_bg: var(--ads-color-danger-solid);
343
355
  --_bg-hover: var(--ads-color-danger-solid-hover);
@@ -82,6 +82,22 @@ the delay expires cancels the pending timer.
82
82
  - States/modifiers: `disabled`, `loading`, `danger`, `block`, `ghost`.
83
83
  - Loading supports immediate and delayed presentation.
84
84
 
85
+ ## Colors
86
+
87
+ In the light theme the default tokens are the values of the Ant Design token documentation, so the button
88
+ looks like Ant Design: primary `#1677ff` (hover `#4096ff`, pressed `#0958d9`), danger `#ff4d4f`, links
89
+ `#1677ff` (hover `#69b1ff`). A text button keeps its text color on hover and gets the background
90
+ `rgba(0, 0, 0, 0.04)`. These colors do **not** reach WCAG AA for text: white on `#1677ff` is 4.10:1 and on the
91
+ danger fill 3.27:1 (4.5:1 is needed). For a contrast guarantee import the optional file after the tokens:
92
+
93
+ ```ts
94
+ import 'svelte-ant-design/tokens.css';
95
+ import 'svelte-ant-design/tokens-accessible.css';
96
+ ```
97
+
98
+ It darkens the `-solid`, `-text` and link tokens (white on the primary fill becomes 5.19:1). The dark theme
99
+ needs no extra file.
100
+
85
101
  ## Accessibility
86
102
 
87
103
  - Uses native `<button>` and `<a>` elements and forwards their supported attributes.
@@ -90,7 +106,7 @@ the delay expires cancels the pending timer.
90
106
  - Disabled/loading anchors are rendered without `href`, with `role="link"`, `aria-disabled="true"`, and `tabindex="-1"`, so they cannot be opened by click, middle click, or the context menu.
91
107
  - Both element types expose `aria-busy="true"` while loading.
92
108
  - The spinner and icon snippet are hidden from assistive technology. An icon-only button must receive an accessible name, for example `aria-label="Close"`.
93
- - A visible `:focus-visible` outline is provided using design tokens. The outline has at least 3:1 contrast against the page, and text in every type, `danger`, and `ghost` combination keeps at least 4.5:1 in the light and dark themes, including hover, focus, and pressed states.
109
+ - A visible `:focus-visible` outline is provided using design tokens. The outline has at least 3:1 contrast against the page. Text in every type, `danger`, and `ghost` combination keeps at least 4.5:1 in the dark theme, and in the light theme when `tokens-accessible.css` is imported (see Colors), including hover, focus, and pressed states.
94
110
  - Under `prefers-reduced-motion: reduce`, color transitions are disabled and the spinner turns more slowly.
95
111
 
96
112
  ## Scope decisions and limitations
@@ -84,13 +84,30 @@ The parts: `root` is the `<button>`, `content` holds the on/off text, `indicator
84
84
 
85
85
  `focus(options?: FocusOptions)` and `blur()`, available through `bind:this`.
86
86
 
87
+ ## Colors
88
+
89
+ In the light theme the default tokens are the values of the Ant Design token documentation: the on track
90
+ `#1677ff` (hover `#4096ff`), the off track `rgba(0, 0, 0, 0.25)` (hover `rgba(0, 0, 0, 0.45)`), a white handle and
91
+ a loading switch dimmed to `0.65`. The documentation names no separate pressed color, so pressed equals hover.
92
+ These colors do **not** keep the contrast of the accessible set: the off track is 1.84:1 against a white page
93
+ (3:1 is needed) and the white text on the on track 4.10:1 (4.5:1 is needed). For a contrast guarantee import the
94
+ optional file after the tokens:
95
+
96
+ ```ts
97
+ import 'svelte-ant-design/tokens.css';
98
+ import 'svelte-ant-design/tokens-accessible.css';
99
+ ```
100
+
101
+ It restores a darker off track (`#737373`), a darker on track (`#1668dc`) and no dimming while loading. The dark
102
+ theme needs no extra file.
103
+
87
104
  ## Accessibility
88
105
 
89
106
  - A native `<button>` with `role="switch"` and `aria-checked`. Enter and Space toggle it. Arrow keys are not part of the pattern and do nothing.
90
107
  - **A switch needs an accessible name:** `aria-label`, `aria-labelledby` or a `<label for>` that points at its `id`. The on/off text is `aria-hidden`, because as a name it would only repeat the state.
91
108
  - A loading switch is not natively disabled: it keeps keyboard focus when loading starts, exposes `aria-busy="true"` and `aria-disabled="true"`, and ignores clicks, Enter and Space. A disabled switch is natively disabled.
92
109
  - A visible `:focus-visible` outline from the design tokens, at least 3:1 against the page.
93
- - The track and the handle keep at least 3:1 contrast, and the on/off text 4.5:1, in the light and dark themes and in the rest, hover, focus and pressed states. For that reason the off track is darker than in the Ant Design design, and a loading switch is not dimmed.
110
+ - The track and the handle keep at least 3:1 contrast, and the on/off text 4.5:1, in every state: in the dark theme, and in the light theme when `tokens-accessible.css` is imported (see Colors). For that the accessible light set has a darker off track and does not dim a loading switch.
94
111
  - Under `prefers-reduced-motion: reduce`, transitions are disabled and the spinner turns more slowly.
95
112
  - Positions use logical properties, so the switch mirrors in right-to-left layouts.
96
113
 
@@ -288,6 +288,7 @@
288
288
 
289
289
  .ads-switch-loading {
290
290
  cursor: not-allowed;
291
+ opacity: var(--ads-switch-loading-opacity);
291
292
  }
292
293
 
293
294
  .ads-switch-disabled {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.2.0";
1
+ export declare const VERSION = "0.2.1";
2
2
  export { default as Button } from './Button/Button.svelte';
3
3
  export { default as Switch } from './Switch/Switch.svelte';
4
4
  export type { SwitchClassNames, SwitchSemanticName, SwitchSize, SwitchStyles } from './Switch/types.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Public API of the library. Components are re-exported from here.
2
- export const VERSION = '0.2.0';
2
+ export const VERSION = '0.2.1';
3
3
  export { default as Button } from './Button/Button.svelte';
4
4
  export { default as Switch } from './Switch/Switch.svelte';
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Accessible light-theme colors (optional).
3
+ *
4
+ * tokens.css uses the values of the Ant Design token documentation, which do not reach WCAG AA for
5
+ * text: white on the primary fill is 4.10:1 and on the danger fill 3.27:1 (4.5:1 is needed), and the
6
+ * off track of a Switch is 1.84:1 against a white page (3:1 is needed). Import this file AFTER tokens.css
7
+ * to get darker values for the `-solid`, `-text` and link tokens and for the Switch:
8
+ *
9
+ * import 'svelte-ant-design/tokens.css';
10
+ * import 'svelte-ant-design/tokens-accessible.css';
11
+ *
12
+ * Every text pair is at least 4.5:1 and every track and handle at least 3:1, in every state. The dark
13
+ * theme needs no override and is not touched: the selector below does not apply when
14
+ * `data-theme="dark"` is set. The selector is more specific than the `:root` of tokens.css, so the
15
+ * order of the two imports does not matter.
16
+ */
17
+
18
+ :root:not([data-theme='dark']) {
19
+ --ads-color-primary-solid: #1668dc;
20
+ --ads-color-primary-solid-hover: #0958d9;
21
+ --ads-color-primary-solid-active: #003eb3;
22
+ --ads-color-primary-text: #1668dc;
23
+ --ads-color-primary-text-hover: #0958d9;
24
+ --ads-color-primary-text-active: #003eb3;
25
+ --ads-color-danger-solid: #d9363e;
26
+ --ads-color-danger-solid-hover: #cf1322;
27
+ --ads-color-danger-solid-active: #a8071a;
28
+ --ads-color-danger-text: #cf1322;
29
+ --ads-color-danger-text-hover: #a8071a;
30
+ --ads-color-danger-text-active: #820014;
31
+ --ads-color-link: #1668dc;
32
+ --ads-color-link-hover: #0958d9;
33
+ --ads-color-link-active: #003eb3;
34
+
35
+ --ads-switch-track-off: #737373;
36
+ --ads-switch-track-off-hover: #666666;
37
+ --ads-switch-track-off-active: #595959;
38
+ --ads-switch-track-on: #1668dc;
39
+ --ads-switch-track-on-hover: #0958d9;
40
+ --ads-switch-track-on-active: #003eb3;
41
+ --ads-switch-loading-opacity: 1;
42
+ }
package/dist/tokens.css CHANGED
@@ -17,21 +17,27 @@
17
17
  --ads-color-danger-active: #d9363e;
18
18
 
19
19
  /*
20
- * Accessible variants. `-solid` is a fill behind `--ads-color-text-inverse`;
21
- * `-text` is a foreground on the page background. All pairs reach WCAG AA (4.5:1).
20
+ * `-solid` is a fill behind `--ads-color-text-inverse`; `-text` and the link tokens are a foreground
21
+ * on the page background. In the light theme the values are the ones of the Ant Design token
22
+ * documentation, so the library looks like Ant Design. They do not reach WCAG AA (4.5:1) for
23
+ * text: import `tokens-accessible.css` after this file for values that do. The dark theme below
24
+ * keeps AA without it.
22
25
  */
23
- --ads-color-primary-solid: #1668dc;
24
- --ads-color-primary-solid-hover: #0958d9;
25
- --ads-color-primary-solid-active: #003eb3;
26
- --ads-color-primary-text: #1668dc;
27
- --ads-color-primary-text-hover: #0958d9;
28
- --ads-color-primary-text-active: #003eb3;
29
- --ads-color-danger-solid: #d9363e;
30
- --ads-color-danger-solid-hover: #cf1322;
31
- --ads-color-danger-solid-active: #a8071a;
32
- --ads-color-danger-text: #cf1322;
33
- --ads-color-danger-text-hover: #a8071a;
34
- --ads-color-danger-text-active: #820014;
26
+ --ads-color-primary-solid: #1677ff;
27
+ --ads-color-primary-solid-hover: #4096ff;
28
+ --ads-color-primary-solid-active: #0958d9;
29
+ --ads-color-primary-text: #1677ff;
30
+ --ads-color-primary-text-hover: #4096ff;
31
+ --ads-color-primary-text-active: #0958d9;
32
+ --ads-color-danger-solid: #ff4d4f;
33
+ --ads-color-danger-solid-hover: #ff7875;
34
+ --ads-color-danger-solid-active: #d9363e;
35
+ --ads-color-danger-text: #ff4d4f;
36
+ --ads-color-danger-text-hover: #ff7875;
37
+ --ads-color-danger-text-active: #d9363e;
38
+ --ads-color-link: #1677ff;
39
+ --ads-color-link-hover: #69b1ff;
40
+ --ads-color-link-active: #0958d9;
35
41
 
36
42
  --ads-color-text: rgba(0, 0, 0, 0.88);
37
43
  --ads-color-text-secondary: rgba(0, 0, 0, 0.65);
@@ -46,6 +52,8 @@
46
52
  --ads-color-bg-container: #ffffff;
47
53
  --ads-color-bg-container-disabled: rgba(0, 0, 0, 0.04);
48
54
  --ads-color-bg-text-hover: rgba(0, 0, 0, 0.06);
55
+ --ads-button-text-hover-bg: rgba(0, 0, 0, 0.04);
56
+ --ads-button-text-active-bg: rgba(0, 0, 0, 0.15);
49
57
 
50
58
  --ads-border-width: 1px;
51
59
  --ads-focus-outline-width: 2px;
@@ -99,18 +107,22 @@
99
107
  --ads-switch-disabled-opacity: 0.4;
100
108
 
101
109
  /*
102
- * Switch colors. Both track states keep 3:1 against the page background (WCAG 1.4.11),
103
- * and the handle and the on/off text keep their contrast against the track (3:1 and 4.5:1)
104
- * in every state, so the unchecked track is darker than the default Ant Design gray.
110
+ * Switch colors. In the light theme the values are the ones of the Ant Design token documentation
111
+ * (the documentation names no separate pressed color, so pressed equals hover, and a loading switch
112
+ * is dimmed to `opacityLoading`). They do not keep the contrast of the accessible set: the off track
113
+ * is 1.84:1 against a white page and the white text on the on track 4.10:1. `tokens-accessible.css`
114
+ * restores a darker off track, a darker on track and no dimming, which keep 3:1 for the tracks and the
115
+ * handle and 4.5:1 for the text. The dark theme below keeps these ratios without it.
105
116
  */
106
- --ads-switch-track-off: #737373;
107
- --ads-switch-track-off-hover: #666666;
108
- --ads-switch-track-off-active: #595959;
109
- --ads-switch-track-on: #1668dc;
110
- --ads-switch-track-on-hover: #0958d9;
111
- --ads-switch-track-on-active: #003eb3;
117
+ --ads-switch-track-off: rgba(0, 0, 0, 0.25);
118
+ --ads-switch-track-off-hover: rgba(0, 0, 0, 0.45);
119
+ --ads-switch-track-off-active: rgba(0, 0, 0, 0.45);
120
+ --ads-switch-track-on: #1677ff;
121
+ --ads-switch-track-on-hover: #4096ff;
122
+ --ads-switch-track-on-active: #4096ff;
112
123
  --ads-switch-handle-bg: #ffffff;
113
124
  --ads-switch-content-color: #ffffff;
125
+ --ads-switch-loading-opacity: 0.65;
114
126
  }
115
127
 
116
128
  :root[data-theme='dark'] {
@@ -137,6 +149,9 @@
137
149
  --ads-color-danger-text: #ff7875;
138
150
  --ads-color-danger-text-hover: #ffa39e;
139
151
  --ads-color-danger-text-active: #ff7875;
152
+ --ads-color-link: #69b1ff;
153
+ --ads-color-link-hover: #91caff;
154
+ --ads-color-link-active: #69b1ff;
140
155
 
141
156
  --ads-color-text: rgb(255 255 255 / 88%);
142
157
  --ads-color-text-secondary: rgb(255 255 255 / 65%);
@@ -151,6 +166,8 @@
151
166
  --ads-color-bg-container: #141414;
152
167
  --ads-color-bg-container-disabled: rgb(255 255 255 / 8%);
153
168
  --ads-color-bg-text-hover: rgb(255 255 255 / 12%);
169
+ --ads-button-text-hover-bg: rgb(255 255 255 / 12%);
170
+ --ads-button-text-active-bg: rgb(255 255 255 / 12%);
154
171
 
155
172
  /* In the dark theme a lighter track would lose contrast against the white handle, so hover and pressed go darker. */
156
173
  --ads-switch-track-off: #8c8c8c;
@@ -161,4 +178,5 @@
161
178
  --ads-switch-track-on-active: #2f7ff0;
162
179
  --ads-switch-handle-bg: #ffffff;
163
180
  --ads-switch-content-color: #141414;
181
+ --ads-switch-loading-opacity: 1;
164
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-ant-design",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "An independent UI component library for Svelte 5, inspired by Ant Design.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,7 +44,8 @@
44
44
  "svelte": "./dist/index.js",
45
45
  "default": "./dist/index.js"
46
46
  },
47
- "./tokens.css": "./dist/tokens.css"
47
+ "./tokens.css": "./dist/tokens.css",
48
+ "./tokens-accessible.css": "./dist/tokens-accessible.css"
48
49
  },
49
50
  "scripts": {
50
51
  "dev": "npm run dev -w docs",