svelte-ant-design 0.3.0 → 0.4.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 +7 -5
- 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 +164 -0
- package/dist/Input/field.d.ts +35 -0
- package/dist/Input/field.js +77 -0
- package/dist/Input/types.d.ts +126 -0
- package/dist/Input/types.js +1 -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.0`. 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
|
|
@@ -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;
|
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { InputFocusOptions, InputProps } from './types.js';
|
|
4
|
+
import { resolveOption } from '../internal/options.js';
|
|
5
|
+
import { classList, styleText } from '../internal/semantic.js';
|
|
6
|
+
import {
|
|
7
|
+
INPUT_SIZES,
|
|
8
|
+
INPUT_VARIANTS,
|
|
9
|
+
clipText,
|
|
10
|
+
countText,
|
|
11
|
+
focusField,
|
|
12
|
+
isOverLimit,
|
|
13
|
+
normalizeSize,
|
|
14
|
+
resolveCount,
|
|
15
|
+
resolveStatus
|
|
16
|
+
} from './field.js';
|
|
17
|
+
import ClearButton from './ClearButton.svelte';
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
value = $bindable(''),
|
|
21
|
+
type = 'text',
|
|
22
|
+
disabled = false,
|
|
23
|
+
readonly = false,
|
|
24
|
+
size = 'medium',
|
|
25
|
+
variant = 'outlined',
|
|
26
|
+
status = undefined,
|
|
27
|
+
prefix = undefined,
|
|
28
|
+
suffix = undefined,
|
|
29
|
+
addonBefore = undefined,
|
|
30
|
+
addonAfter = undefined,
|
|
31
|
+
allowClear = false,
|
|
32
|
+
showCount = false,
|
|
33
|
+
count = undefined,
|
|
34
|
+
maxlength = undefined,
|
|
35
|
+
onchange,
|
|
36
|
+
onpressenter,
|
|
37
|
+
onclear,
|
|
38
|
+
classNames,
|
|
39
|
+
styles,
|
|
40
|
+
class: customClass,
|
|
41
|
+
style: customStyle,
|
|
42
|
+
oninput,
|
|
43
|
+
onkeydown,
|
|
44
|
+
oncompositionstart,
|
|
45
|
+
oncompositionend,
|
|
46
|
+
'aria-describedby': ariaDescribedby = undefined,
|
|
47
|
+
'aria-invalid': ariaInvalid = undefined,
|
|
48
|
+
...rest
|
|
49
|
+
}: InputProps = $props();
|
|
50
|
+
|
|
51
|
+
const countId = $props.id();
|
|
52
|
+
|
|
53
|
+
let input: HTMLInputElement | undefined = $state();
|
|
54
|
+
// Whether an IME composition is open: the edits are reported as they come, but the text is not cut,
|
|
55
|
+
// written back or taken for an Enter until the composition ends.
|
|
56
|
+
let composing = false;
|
|
57
|
+
|
|
58
|
+
// The text; a value that is not a string (`null`, from a loose caller) is empty.
|
|
59
|
+
const text = $derived(value ?? '');
|
|
60
|
+
|
|
61
|
+
// Every option is validated on each render: a value outside the contract throws while developing and
|
|
62
|
+
// falls back to the default in a production build.
|
|
63
|
+
const resolved = $derived({
|
|
64
|
+
size: normalizeSize(resolveOption('Input', 'size', size, INPUT_SIZES, 'medium')),
|
|
65
|
+
variant: resolveOption('Input', 'variant', variant, INPUT_VARIANTS, 'outlined'),
|
|
66
|
+
status: resolveStatus('Input', status)
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const counting = $derived(resolveCount(showCount, count, maxlength));
|
|
70
|
+
const overLimit = $derived(counting.show && isOverLimit(counting, text));
|
|
71
|
+
const clearConfig = $derived(typeof allowClear === 'object' ? allowClear : undefined);
|
|
72
|
+
const clearVisible = $derived(text !== '' && !disabled && !readonly);
|
|
73
|
+
|
|
74
|
+
const describedBy = $derived(
|
|
75
|
+
[ariaDescribedby, counting.show ? countId : undefined].filter(Boolean).join(' ') || undefined
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// The classes that set the look (size, variant, status, state). They go on the field and, when there are
|
|
79
|
+
// addons, on the group too, so the addons read the same colors and sizes.
|
|
80
|
+
const lookClass = $derived(
|
|
81
|
+
classList(
|
|
82
|
+
`ads-input-${resolved.size}`,
|
|
83
|
+
`ads-input-${resolved.variant}`,
|
|
84
|
+
resolved.status && `ads-input-status-${resolved.status}`,
|
|
85
|
+
disabled && 'ads-input-disabled',
|
|
86
|
+
readonly && 'ads-input-readonly',
|
|
87
|
+
addonBefore && 'ads-input-has-addon-before',
|
|
88
|
+
addonAfter && 'ads-input-has-addon-after'
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
const rootClass = $derived(classList(customClass, classNames?.root));
|
|
92
|
+
const grouped = $derived(Boolean(addonBefore || addonAfter));
|
|
93
|
+
|
|
94
|
+
/** Whether the field is marked invalid: the `error` status, or a text past the soft limit. */
|
|
95
|
+
const invalid = $derived(resolved.status === 'error' || overLimit);
|
|
96
|
+
|
|
97
|
+
// A native form reset puts the input back to its default text behind the state's back. The state is the
|
|
98
|
+
// truth (the parent resets it in `onreset`), so the view is restored to it once the reset has run.
|
|
99
|
+
$effect(() => {
|
|
100
|
+
const form = input?.form;
|
|
101
|
+
if (!form) return;
|
|
102
|
+
const restore = () => {
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
if (input && input.value !== text) input.value = text;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
form.addEventListener('reset', restore);
|
|
108
|
+
return () => form.removeEventListener('reset', restore);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Takes the text of the input into `value`. With `settle` the text is cut by `count.exceedFormatter` and the
|
|
113
|
+
* input is written back from the state, which reverts an edit the parent refused (a function binding).
|
|
114
|
+
*/
|
|
115
|
+
function takeEdit(target: HTMLInputElement, event: Event, settle: boolean): void {
|
|
116
|
+
const before = text;
|
|
117
|
+
let next = target.value;
|
|
118
|
+
if (settle) next = clipText(counting, next);
|
|
119
|
+
if (next !== before) {
|
|
120
|
+
value = next;
|
|
121
|
+
onchange?.(next, event);
|
|
122
|
+
}
|
|
123
|
+
if (settle && target.value !== text) target.value = text;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleInput(event: Event & { currentTarget: EventTarget & HTMLInputElement }): void {
|
|
127
|
+
oninput?.(event);
|
|
128
|
+
takeEdit(event.currentTarget, event, !composing);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function handleCompositionStart(
|
|
132
|
+
event: CompositionEvent & { currentTarget: EventTarget & HTMLInputElement }
|
|
133
|
+
): void {
|
|
134
|
+
composing = true;
|
|
135
|
+
oncompositionstart?.(event);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function handleCompositionEnd(
|
|
139
|
+
event: CompositionEvent & { currentTarget: EventTarget & HTMLInputElement }
|
|
140
|
+
): void {
|
|
141
|
+
composing = false;
|
|
142
|
+
oncompositionend?.(event);
|
|
143
|
+
takeEdit(event.currentTarget, event, true);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function handleKeydown(event: KeyboardEvent & { currentTarget: EventTarget & HTMLInputElement }): void {
|
|
147
|
+
onkeydown?.(event);
|
|
148
|
+
if (event.key === 'Enter' && !composing && !event.isComposing) onpressenter?.(event);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function clear(event: MouseEvent): void {
|
|
152
|
+
value = '';
|
|
153
|
+
onchange?.('', event);
|
|
154
|
+
if (input && input.value !== text) input.value = text;
|
|
155
|
+
input?.focus();
|
|
156
|
+
onclear?.(event);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Moves focus to the input; `cursor` places the caret or selects the text. */
|
|
160
|
+
export function focus(options?: InputFocusOptions): void {
|
|
161
|
+
focusField(input, options);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Removes focus from the input. */
|
|
165
|
+
export function blur(): void {
|
|
166
|
+
input?.blur();
|
|
167
|
+
}
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
{#snippet content(node: string | Snippet)}
|
|
171
|
+
{#if typeof node === 'string'}{node}{:else}{@render node()}{/if}
|
|
172
|
+
{/snippet}
|
|
173
|
+
|
|
174
|
+
<!--
|
|
175
|
+
The field is one element: the bordered box that holds the prefix, the input, the clear button, the count and
|
|
176
|
+
the suffix. Those are siblings of the input, so showing or hiding one never re-creates the input (it keeps
|
|
177
|
+
focus and caret). Only the addons need a second element, the group that joins them to the field; it exists
|
|
178
|
+
while at least one addon is set.
|
|
179
|
+
-->
|
|
180
|
+
{#snippet field(extraClass?: string, extraStyle?: string)}
|
|
181
|
+
<span class={classList('ads-input', lookClass, extraClass)} style={extraStyle}>
|
|
182
|
+
{#if prefix}
|
|
183
|
+
<span class={classList('ads-input-prefix', classNames?.prefix)} style={styleText(styles?.prefix)}
|
|
184
|
+
>{@render content(prefix)}</span
|
|
185
|
+
>
|
|
186
|
+
{/if}
|
|
187
|
+
<input
|
|
188
|
+
{...rest}
|
|
189
|
+
bind:this={input}
|
|
190
|
+
{type}
|
|
191
|
+
class={classList('ads-input-input', classNames?.input)}
|
|
192
|
+
style={styleText(styles?.input)}
|
|
193
|
+
value={text}
|
|
194
|
+
{disabled}
|
|
195
|
+
{readonly}
|
|
196
|
+
{maxlength}
|
|
197
|
+
aria-invalid={invalid ? 'true' : ariaInvalid}
|
|
198
|
+
aria-describedby={describedBy}
|
|
199
|
+
oninput={handleInput}
|
|
200
|
+
onkeydown={handleKeydown}
|
|
201
|
+
oncompositionstart={handleCompositionStart}
|
|
202
|
+
oncompositionend={handleCompositionEnd}
|
|
203
|
+
/>
|
|
204
|
+
{#if allowClear}
|
|
205
|
+
<ClearButton
|
|
206
|
+
config={clearConfig}
|
|
207
|
+
visible={clearVisible}
|
|
208
|
+
class={classNames?.clear}
|
|
209
|
+
style={styleText(styles?.clear)}
|
|
210
|
+
onclear={clear}
|
|
211
|
+
/>
|
|
212
|
+
{/if}
|
|
213
|
+
{#if counting.show}
|
|
214
|
+
<span
|
|
215
|
+
id={countId}
|
|
216
|
+
class={classList('ads-input-count', overLimit && 'ads-input-count-exceeded', classNames?.count)}
|
|
217
|
+
style={styleText(styles?.count)}>{countText(counting, text)}</span
|
|
218
|
+
>
|
|
219
|
+
{/if}
|
|
220
|
+
{#if suffix}
|
|
221
|
+
<span class={classList('ads-input-suffix', classNames?.suffix)} style={styleText(styles?.suffix)}
|
|
222
|
+
>{@render content(suffix)}</span
|
|
223
|
+
>
|
|
224
|
+
{/if}
|
|
225
|
+
</span>
|
|
226
|
+
{/snippet}
|
|
227
|
+
|
|
228
|
+
{#if grouped}
|
|
229
|
+
<span class={classList('ads-input-group', lookClass, rootClass)} style={styleText(customStyle, styles?.root)}>
|
|
230
|
+
{#if addonBefore}
|
|
231
|
+
<span class="ads-input-addon ads-input-addon-before">{@render content(addonBefore)}</span>
|
|
232
|
+
{/if}
|
|
233
|
+
{@render field()}
|
|
234
|
+
{#if addonAfter}
|
|
235
|
+
<span class="ads-input-addon ads-input-addon-after">{@render content(addonAfter)}</span>
|
|
236
|
+
{/if}
|
|
237
|
+
</span>
|
|
238
|
+
{:else}
|
|
239
|
+
{@render field(rootClass, styleText(customStyle, styles?.root))}
|
|
240
|
+
{/if}
|
|
241
|
+
|
|
242
|
+
<style>
|
|
243
|
+
/*
|
|
244
|
+
* The states set private `--_*` variables; the rules that paint the field read them, so the variant, the
|
|
245
|
+
* status, hover, focus and disabled combine without fighting over specificity. The values come from the
|
|
246
|
+
* `--ads-input-*` tokens. Positions use logical properties, so the field mirrors in right-to-left layouts.
|
|
247
|
+
*/
|
|
248
|
+
/*
|
|
249
|
+
* The group joins the addons to the field and exists only while an addon is set. It carries the look classes
|
|
250
|
+
* too, so the addons read the same variables as the field. It comes before the shared block: the classes of
|
|
251
|
+
* the look (size, status, ...) set the variables again after these defaults.
|
|
252
|
+
*/
|
|
253
|
+
.ads-input-group {
|
|
254
|
+
--_fs: var(--ads-input-font-size);
|
|
255
|
+
--_lh: var(--ads-input-line-height);
|
|
256
|
+
--_radius: var(--ads-input-radius);
|
|
257
|
+
--_border: var(--ads-input-border);
|
|
258
|
+
|
|
259
|
+
display: inline-flex;
|
|
260
|
+
box-sizing: border-box;
|
|
261
|
+
width: 100%;
|
|
262
|
+
min-width: 0;
|
|
263
|
+
margin: 0;
|
|
264
|
+
color: var(--ads-color-text);
|
|
265
|
+
font-family: var(--ads-font-family);
|
|
266
|
+
vertical-align: top;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/* shared-field-styles:begin (the same block is in InputTextArea.svelte; tests/internal.test.ts keeps the copies equal) */
|
|
270
|
+
.ads-input {
|
|
271
|
+
--_fs: var(--ads-input-font-size);
|
|
272
|
+
--_lh: var(--ads-input-line-height);
|
|
273
|
+
--_pb: var(--ads-input-padding-block);
|
|
274
|
+
--_pi: var(--ads-input-padding-inline);
|
|
275
|
+
--_radius: var(--ads-input-radius);
|
|
276
|
+
--_border: var(--ads-input-border);
|
|
277
|
+
--_border-hover: var(--ads-input-border-hover);
|
|
278
|
+
--_border-active: var(--ads-input-border-active);
|
|
279
|
+
--_bg: var(--ads-input-bg);
|
|
280
|
+
--_bg-hover: var(--ads-input-bg-hover);
|
|
281
|
+
--_bg-active: var(--ads-input-bg-active);
|
|
282
|
+
--_shadow: var(--ads-input-shadow-active);
|
|
283
|
+
|
|
284
|
+
position: relative;
|
|
285
|
+
display: inline-flex;
|
|
286
|
+
align-items: center;
|
|
287
|
+
box-sizing: border-box;
|
|
288
|
+
width: 100%;
|
|
289
|
+
min-width: 0;
|
|
290
|
+
margin: 0;
|
|
291
|
+
padding-block: var(--_pb);
|
|
292
|
+
padding-inline: var(--_pi);
|
|
293
|
+
border: var(--ads-input-border-width) solid var(--_border);
|
|
294
|
+
border-radius: var(--_radius);
|
|
295
|
+
background-color: var(--_bg);
|
|
296
|
+
color: var(--ads-color-text);
|
|
297
|
+
font-family: var(--ads-font-family);
|
|
298
|
+
font-size: var(--_fs);
|
|
299
|
+
line-height: var(--_lh);
|
|
300
|
+
vertical-align: top;
|
|
301
|
+
transition:
|
|
302
|
+
border-color var(--ads-motion-duration) var(--ads-motion-ease),
|
|
303
|
+
background-color var(--ads-motion-duration) var(--ads-motion-ease),
|
|
304
|
+
box-shadow var(--ads-motion-duration) var(--ads-motion-ease);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.ads-input-large {
|
|
308
|
+
--_fs: var(--ads-input-font-size-lg);
|
|
309
|
+
--_lh: var(--ads-input-line-height-lg);
|
|
310
|
+
--_pb: var(--ads-input-padding-block-lg);
|
|
311
|
+
--_pi: var(--ads-input-padding-inline-lg);
|
|
312
|
+
--_radius: var(--ads-input-radius-lg);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.ads-input-small {
|
|
316
|
+
--_fs: var(--ads-input-font-size-sm);
|
|
317
|
+
--_pb: var(--ads-input-padding-block-sm);
|
|
318
|
+
--_pi: var(--ads-input-padding-inline-sm);
|
|
319
|
+
--_radius: var(--ads-input-radius-sm);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.ads-input-filled {
|
|
323
|
+
--_border: transparent;
|
|
324
|
+
--_border-hover: transparent;
|
|
325
|
+
--_bg: var(--ads-input-filled-bg);
|
|
326
|
+
--_bg-hover: var(--ads-input-filled-bg-hover);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.ads-input-borderless {
|
|
330
|
+
--_border: transparent;
|
|
331
|
+
--_border-hover: transparent;
|
|
332
|
+
--_border-active: transparent;
|
|
333
|
+
--_bg: transparent;
|
|
334
|
+
--_bg-hover: transparent;
|
|
335
|
+
--_bg-active: transparent;
|
|
336
|
+
--_shadow: none;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.ads-input-underlined {
|
|
340
|
+
--_bg: transparent;
|
|
341
|
+
--_bg-hover: transparent;
|
|
342
|
+
--_bg-active: transparent;
|
|
343
|
+
--_pi: 0px;
|
|
344
|
+
--_shadow: none;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.ads-input-status-error {
|
|
348
|
+
--_border: var(--ads-input-error);
|
|
349
|
+
--_border-hover: var(--ads-input-error-hover);
|
|
350
|
+
--_border-active: var(--ads-input-error);
|
|
351
|
+
--_shadow: var(--ads-input-error-shadow);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.ads-input-status-warning {
|
|
355
|
+
--_border: var(--ads-input-warning);
|
|
356
|
+
--_border-hover: var(--ads-input-warning-hover);
|
|
357
|
+
--_border-active: var(--ads-input-warning);
|
|
358
|
+
--_shadow: var(--ads-input-warning-shadow);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.ads-input-filled.ads-input-status-error {
|
|
362
|
+
--_border: transparent;
|
|
363
|
+
--_border-hover: transparent;
|
|
364
|
+
--_bg: var(--ads-input-error-bg);
|
|
365
|
+
--_bg-hover: var(--ads-input-error-bg);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.ads-input-filled.ads-input-status-warning {
|
|
369
|
+
--_border: transparent;
|
|
370
|
+
--_border-hover: transparent;
|
|
371
|
+
--_bg: var(--ads-input-warning-bg);
|
|
372
|
+
--_bg-hover: var(--ads-input-warning-bg);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/* Last, so the disabled colors win over the variant and the status. */
|
|
376
|
+
.ads-input-disabled {
|
|
377
|
+
--_border: var(--ads-input-disabled-border);
|
|
378
|
+
--_border-hover: var(--ads-input-disabled-border);
|
|
379
|
+
--_bg: var(--ads-input-disabled-bg);
|
|
380
|
+
--_bg-hover: var(--ads-input-disabled-bg);
|
|
381
|
+
color: var(--ads-color-text-disabled);
|
|
382
|
+
cursor: not-allowed;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.ads-input-disabled.ads-input-borderless,
|
|
386
|
+
.ads-input-disabled.ads-input-underlined {
|
|
387
|
+
--_bg: transparent;
|
|
388
|
+
--_bg-hover: transparent;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.ads-input-disabled.ads-input-borderless {
|
|
392
|
+
--_border: transparent;
|
|
393
|
+
--_border-hover: transparent;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.ads-input.ads-input-underlined {
|
|
397
|
+
border-width: 0 0 var(--ads-input-border-width);
|
|
398
|
+
border-radius: 0;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.ads-input:not(.ads-input-disabled):hover {
|
|
402
|
+
border-color: var(--_border-hover);
|
|
403
|
+
background-color: var(--_bg-hover);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/* As specific as the hover rule above and after it, so a focused field under the pointer keeps the active look. */
|
|
407
|
+
.ads-input:not(.ads-input-disabled):focus-within {
|
|
408
|
+
border-color: var(--_border-active);
|
|
409
|
+
background-color: var(--_bg-active);
|
|
410
|
+
box-shadow: var(--_shadow);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/* The borderless field has no border to change, so keyboard focus gets the outline of the other controls. */
|
|
414
|
+
.ads-input.ads-input-borderless:focus-within {
|
|
415
|
+
outline: var(--ads-focus-outline-width) solid var(--ads-color-focus-outline);
|
|
416
|
+
outline-offset: 0;
|
|
417
|
+
}
|
|
418
|
+
/* shared-field-styles:end */
|
|
419
|
+
|
|
420
|
+
.ads-input-group > .ads-input {
|
|
421
|
+
flex: 1 1 auto;
|
|
422
|
+
width: auto;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.ads-input.ads-input-has-addon-before {
|
|
426
|
+
border-start-start-radius: 0;
|
|
427
|
+
border-end-start-radius: 0;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.ads-input.ads-input-has-addon-after {
|
|
431
|
+
border-start-end-radius: 0;
|
|
432
|
+
border-end-end-radius: 0;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.ads-input-addon {
|
|
436
|
+
display: flex;
|
|
437
|
+
flex: none;
|
|
438
|
+
align-items: center;
|
|
439
|
+
box-sizing: border-box;
|
|
440
|
+
padding-inline: var(--ads-input-addon-padding-inline);
|
|
441
|
+
border: var(--ads-input-border-width) solid var(--_border);
|
|
442
|
+
background-color: var(--ads-input-addon-bg);
|
|
443
|
+
font-size: var(--_fs);
|
|
444
|
+
line-height: var(--_lh);
|
|
445
|
+
white-space: nowrap;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.ads-input-addon-before {
|
|
449
|
+
border-inline-end: 0;
|
|
450
|
+
border-start-start-radius: var(--_radius);
|
|
451
|
+
border-end-start-radius: var(--_radius);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.ads-input-addon-after {
|
|
455
|
+
border-inline-start: 0;
|
|
456
|
+
border-start-end-radius: var(--_radius);
|
|
457
|
+
border-end-end-radius: var(--_radius);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.ads-input-input {
|
|
461
|
+
flex: 1 1 auto;
|
|
462
|
+
box-sizing: border-box;
|
|
463
|
+
min-width: 0;
|
|
464
|
+
height: calc(var(--_fs) * var(--_lh));
|
|
465
|
+
margin: 0;
|
|
466
|
+
padding: 0;
|
|
467
|
+
border: 0;
|
|
468
|
+
outline: 0;
|
|
469
|
+
background: transparent;
|
|
470
|
+
color: inherit;
|
|
471
|
+
font: inherit;
|
|
472
|
+
font-size: var(--_fs);
|
|
473
|
+
line-height: var(--_lh);
|
|
474
|
+
text-overflow: ellipsis;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.ads-input-input::placeholder {
|
|
478
|
+
color: var(--ads-input-placeholder);
|
|
479
|
+
opacity: 1;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.ads-input-disabled .ads-input-input {
|
|
483
|
+
cursor: not-allowed;
|
|
484
|
+
opacity: 1;
|
|
485
|
+
-webkit-text-fill-color: currentColor;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/* The clear button of the library replaces the browser's own cross in a search field. */
|
|
489
|
+
.ads-input-input::-webkit-search-cancel-button,
|
|
490
|
+
.ads-input-input::-webkit-search-decoration {
|
|
491
|
+
appearance: none;
|
|
492
|
+
display: none;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.ads-input-prefix,
|
|
496
|
+
.ads-input-suffix,
|
|
497
|
+
.ads-input-count {
|
|
498
|
+
display: flex;
|
|
499
|
+
flex: none;
|
|
500
|
+
align-items: center;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.ads-input-prefix {
|
|
504
|
+
margin-inline-end: var(--ads-input-gap);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
.ads-input-suffix {
|
|
508
|
+
margin-inline-start: var(--ads-input-gap);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.ads-input-count {
|
|
512
|
+
margin-inline-start: var(--ads-input-gap);
|
|
513
|
+
color: var(--ads-input-count-color);
|
|
514
|
+
white-space: nowrap;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
.ads-input-count-exceeded {
|
|
518
|
+
color: var(--ads-color-danger-text);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
.ads-input-disabled .ads-input-count {
|
|
522
|
+
color: var(--ads-color-text-disabled);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
@media (prefers-reduced-motion: reduce) {
|
|
526
|
+
.ads-input {
|
|
527
|
+
transition: none;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { InputFocusOptions, InputProps } from './types.js';
|
|
2
|
+
declare const Input: import("svelte").Component<InputProps, {
|
|
3
|
+
focus: (options?: InputFocusOptions) => void;
|
|
4
|
+
blur: () => void;
|
|
5
|
+
}, "value">;
|
|
6
|
+
type Input = ReturnType<typeof Input>;
|
|
7
|
+
export default Input;
|