@snowui-design-system/components 0.3.0-alpha.6 → 0.3.0-alpha.7
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/AGENTS.md +8 -0
- package/README.md +19 -3
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/component-catalog.json +26 -0
- package/dist/client/blocks/Sidebar.js +108 -95
- package/dist/client/blocks/SidebarItem.js +26 -12
- package/dist/client/blocks/SidebarSection.js +3 -1
- package/dist/client/components/BarChart.js +9 -2
- package/dist/client/components/Breadcrumb.js +10 -6
- package/dist/client/components/ChartGroup.js +23 -10
- package/dist/client/components/CircularChart.js +8 -1
- package/dist/client/components/GaugeChart.js +8 -1
- package/dist/client/components/Image.d.ts +2 -0
- package/dist/client/components/Image.js +14 -2
- package/dist/client/components/Input.js +2 -2
- package/dist/client/components/LineChart.js +9 -2
- package/dist/client/components/Listbox.js +43 -15
- package/dist/client/components/MenuItem.js +7 -1
- package/dist/client/components/OTPInput.d.ts +32 -0
- package/dist/client/components/OTPInput.js +556 -0
- package/dist/client/components/Pagination.js +9 -8
- package/dist/client/components/ScrollArea.js +11 -5
- package/dist/client/components/SearchBox.js +12 -3
- package/dist/client/components/Select.js +3 -1
- package/dist/client/components/SidePanel.js +4 -3
- package/dist/client/components/Slider.js +7 -3
- package/dist/client/components/Spinner.js +9 -2
- package/dist/client/components/Tag.js +8 -1
- package/dist/client/i18n/messages.d.ts +1 -1
- package/dist/client/i18n/messages.js +54 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/keys.d.ts +1 -0
- package/dist/client/keys.js +1 -0
- package/dist/client/lib/media-loading.d.ts +7 -0
- package/dist/client/lib/media-loading.js +12 -0
- package/dist/client/styles/components.css +6 -0
- package/dist/client/styles/layout.css +12 -2
- package/dist/server/blocks/Sidebar.js +5 -5
- package/dist/server/blocks/SidebarItem.js +4 -2
- package/dist/server/blocks/SidebarSection.js +3 -1
- package/dist/server/components/BarChart.js +5 -2
- package/dist/server/components/Breadcrumb.js +5 -2
- package/dist/server/components/ChartGroup.js +6 -3
- package/dist/server/components/CircularChart.js +4 -1
- package/dist/server/components/GaugeChart.js +4 -1
- package/dist/server/components/Image.d.ts +2 -0
- package/dist/server/components/Image.js +11 -4
- package/dist/server/components/Input.js +2 -2
- package/dist/server/components/LineChart.js +5 -2
- package/dist/server/components/Listbox.js +32 -14
- package/dist/server/components/MenuItem.js +4 -1
- package/dist/server/components/OTPInput.d.ts +32 -0
- package/dist/server/components/OTPInput.js +401 -0
- package/dist/server/components/Pagination.js +2 -2
- package/dist/server/components/ScrollArea.js +5 -2
- package/dist/server/components/SearchBox.js +9 -3
- package/dist/server/components/Select.js +3 -1
- package/dist/server/components/SidePanel.js +4 -3
- package/dist/server/components/Slider.js +7 -3
- package/dist/server/components/Spinner.js +4 -2
- package/dist/server/components/Tag.js +4 -1
- package/dist/server/i18n/messages.d.ts +1 -1
- package/dist/server/i18n/messages.js +54 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/keys.d.ts +1 -0
- package/dist/server/keys.js +1 -0
- package/dist/server/lib/media-loading.d.ts +7 -0
- package/dist/server/lib/media-loading.js +12 -0
- package/dist/server/styles/components.css +6 -0
- package/dist/server/styles/layout.css +12 -2
- package/llms.txt +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { onDestroy } from "svelte";
|
|
3
|
+
import Text from "./Text.js";
|
|
4
|
+
import { useLocale } from "../i18n/locale.js";
|
|
5
|
+
import { NUMBER_POP_APPEAR_MOTION } from "../motion/presets/effects.js";
|
|
6
|
+
import { TAB_INDICATOR_MOTION_STYLE } from "../motion/presets/tab.js";
|
|
7
|
+
import Frame from "./Frame.js";
|
|
8
|
+
import { splitFrameHostProps } from "../logic/frame-prop-filter.js";
|
|
9
|
+
|
|
10
|
+
const $$css = {
|
|
11
|
+
hash: 'svelte-qr73h1',
|
|
12
|
+
code: ':where(.snowui-otp-input) {--snowui-otp-input-gap: var(--gap-2);--snowui-otp-input-size: var(--size-10);--snowui-otp-input-radius: var(--radius-4);--snowui-otp-input-font-size: var(--text-16);--snowui-otp-input-line-height: var(--leading-14);position:relative;display:inline-flex;flex-direction:column;align-items:flex-start;gap:var(--gap-2);width:fit-content;max-width:100%;color:var(--black-100, #000000);cursor:text;}:where(.snowui-otp-slots) {position:relative;display:flex;gap:var(--snowui-otp-input-gap-override, var(--snowui-otp-input-gap, var(--gap-2)));}:where(.snowui-otp-slot, .snowui-otp-indicator) {display:grid;place-items:center;width:var(--snowui-otp-input-size-override, var(--snowui-otp-input-size, var(--size-10)));height:var(--snowui-otp-input-size-override, var(--snowui-otp-input-size, var(--size-10)));box-sizing:border-box;border:0;border-radius:var(--snowui-otp-input-radius-override, var(--snowui-otp-input-radius, var(--radius-4)));font-size:var(--snowui-otp-input-font-size-override, var(--snowui-otp-input-font-size, var(--text-16)));line-height:var(--snowui-otp-input-line-height-override, var(--snowui-otp-input-line-height, var(--leading-14)));font-variant-numeric:tabular-nums;}:where(.snowui-otp-slot) {background:var(--surface-1, #ffffffcc);}.snowui-otp-input :where(.snowui-otp-indicator) {position:absolute;left:0;top:0;pointer-events:none;opacity:0;transform:translateX(calc(var(--snowui-otp-input-active-index) * (var(--snowui-otp-input-size-override, var(--snowui-otp-input-size)) + var(--snowui-otp-input-gap-override, var(--snowui-otp-input-gap)))));transition:transform var(--snowui-frame-control-motion-duration) var(--snowui-frame-control-motion-easing), box-shadow var(--snowui-frame-control-motion-duration) var(--snowui-frame-control-motion-easing);}.snowui-otp-input :where(.snowui-otp-indicator[data-field-focus="true"]) {opacity:1;}:where(.snowui-otp-input[data-disabled="true"]) {cursor:not-allowed;opacity:0.4;}:where(.snowui-otp-input[data-readonly="true"]) {cursor:default;}:where(.snowui-otp-input[data-readonly="true"] .snowui-otp-slot) {background:var(--surface-2, #00000008);box-shadow:none;}.snowui-otp-input[data-readonly="true"] :where(.snowui-otp-indicator) {opacity:0;}:where(.snowui-otp-native) {position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;cursor:inherit;}\n @media (prefers-reduced-motion: reduce) {.snowui-otp-input :where(.snowui-otp-indicator) {transition:none;}\n }'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function OTPInput($$renderer, $$props) {
|
|
16
|
+
$$renderer.global.css.add($$css);
|
|
17
|
+
|
|
18
|
+
$$renderer.component(($$renderer) => {
|
|
19
|
+
const instanceId = $.props_id($$renderer);
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
value = void 0,
|
|
23
|
+
defaultValue,
|
|
24
|
+
length = 6,
|
|
25
|
+
name,
|
|
26
|
+
form,
|
|
27
|
+
disabled = false,
|
|
28
|
+
readonly = false,
|
|
29
|
+
required = false,
|
|
30
|
+
autocomplete = "one-time-code",
|
|
31
|
+
autofocus,
|
|
32
|
+
tabindex,
|
|
33
|
+
id,
|
|
34
|
+
title,
|
|
35
|
+
invalid = false,
|
|
36
|
+
error,
|
|
37
|
+
enableResponsive = true,
|
|
38
|
+
enableContext = true,
|
|
39
|
+
oncomplete,
|
|
40
|
+
oninput,
|
|
41
|
+
onchange,
|
|
42
|
+
onfocus,
|
|
43
|
+
onblur,
|
|
44
|
+
onkeydown,
|
|
45
|
+
onpaste,
|
|
46
|
+
class: userClass = "",
|
|
47
|
+
style: userStyle = "",
|
|
48
|
+
$$slots,
|
|
49
|
+
$$events,
|
|
50
|
+
...rest
|
|
51
|
+
} = $$props;
|
|
52
|
+
|
|
53
|
+
let inputElement = void 0;
|
|
54
|
+
const locale = useLocale();
|
|
55
|
+
const errorId = `${instanceId}-error`;
|
|
56
|
+
let focused = false;
|
|
57
|
+
let hoveredIndex = void 0;
|
|
58
|
+
let pasteInvalid = false;
|
|
59
|
+
let errorTimer;
|
|
60
|
+
const resolvedInvalid = $.derived(() => invalid || pasteInvalid);
|
|
61
|
+
const errorContent = $.derived(() => error ?? locale.t("otpInput.invalidCode", { length }));
|
|
62
|
+
|
|
63
|
+
onDestroy(() => {
|
|
64
|
+
if (errorTimer) clearTimeout(errorTimer);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
let selectionIndex = 0;
|
|
68
|
+
let initialValue = "";
|
|
69
|
+
let initialized = false;
|
|
70
|
+
let lastUserCompletion = "";
|
|
71
|
+
let resetTimer;
|
|
72
|
+
const splitProps = $.derived(() => splitFrameHostProps(rest));
|
|
73
|
+
const frameRestProps = $.derived(() => splitProps().frameProps);
|
|
74
|
+
const inputRestProps = $.derived(() => splitProps().hostProps);
|
|
75
|
+
const normalize = (raw) => String(raw ?? "").replace(/\D/g, "").slice(0, length);
|
|
76
|
+
const currentValue = $.derived(() => normalize(value === undefined ? defaultValue : value));
|
|
77
|
+
const digits = $.derived(() => Array.from({ length }, (_, index) => currentValue()[index] ?? ""));
|
|
78
|
+
const activeIndex = $.derived(() => Math.min(selectionIndex, currentValue().length, length - 1));
|
|
79
|
+
const groupLabel = $.derived(() => inputRestProps()["aria-label"]);
|
|
80
|
+
const groupLabelledby = $.derived(() => inputRestProps()["aria-labelledby"]);
|
|
81
|
+
|
|
82
|
+
const nativeInputProps = $.derived(() => {
|
|
83
|
+
const {
|
|
84
|
+
"aria-label": _label,
|
|
85
|
+
"aria-labelledby": _labelledby,
|
|
86
|
+
...props
|
|
87
|
+
} = inputRestProps();
|
|
88
|
+
|
|
89
|
+
return props;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function formReset(node, formId) {
|
|
93
|
+
let active = true;
|
|
94
|
+
|
|
95
|
+
const reset = (event) => {
|
|
96
|
+
if (event.target !== node.form) return;
|
|
97
|
+
|
|
98
|
+
const valueBeforeReset = normalize(node.value);
|
|
99
|
+
|
|
100
|
+
if (resetTimer) clearTimeout(resetTimer);
|
|
101
|
+
|
|
102
|
+
resetTimer = setTimeout(
|
|
103
|
+
() => {
|
|
104
|
+
if (!active) return;
|
|
105
|
+
|
|
106
|
+
value = normalize(event.defaultPrevented ? valueBeforeReset : initialValue);
|
|
107
|
+
|
|
108
|
+
if (inputElement) inputElement.value = value;
|
|
109
|
+
|
|
110
|
+
selectionIndex = value.length;
|
|
111
|
+
|
|
112
|
+
if (!event.defaultPrevented) {
|
|
113
|
+
lastUserCompletion = "";
|
|
114
|
+
clearPasteError();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
0
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
document.addEventListener("reset", reset, true);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
update(nextFormId) {
|
|
125
|
+
formId = nextFormId;
|
|
126
|
+
void formId;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
destroy() {
|
|
130
|
+
active = false;
|
|
131
|
+
document.removeEventListener("reset", reset, true);
|
|
132
|
+
|
|
133
|
+
if (resetTimer) clearTimeout(resetTimer);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function commitFromUser(raw) {
|
|
139
|
+
const next = normalize(raw);
|
|
140
|
+
const previous = currentValue();
|
|
141
|
+
|
|
142
|
+
value = next;
|
|
143
|
+
selectionIndex = inputElement?.selectionStart ?? next.length;
|
|
144
|
+
|
|
145
|
+
if (next.length === length && next !== previous && next !== lastUserCompletion) {
|
|
146
|
+
lastUserCompletion = next;
|
|
147
|
+
oncomplete?.(next);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function clearPasteError() {
|
|
152
|
+
if (errorTimer) clearTimeout(errorTimer);
|
|
153
|
+
|
|
154
|
+
errorTimer = undefined;
|
|
155
|
+
pasteInvalid = false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function rejectPaste(clear) {
|
|
159
|
+
if (clear) {
|
|
160
|
+
value = "";
|
|
161
|
+
|
|
162
|
+
if (inputElement) inputElement.value = "";
|
|
163
|
+
|
|
164
|
+
moveCaret(0);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (errorTimer) clearTimeout(errorTimer);
|
|
168
|
+
|
|
169
|
+
pasteInvalid = true;
|
|
170
|
+
errorTimer = setTimeout(clearPasteError, 2000);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function moveCaret(index, select = false) {
|
|
174
|
+
const at = Math.max(0, Math.min(index, currentValue().length, length - 1));
|
|
175
|
+
|
|
176
|
+
selectionIndex = at;
|
|
177
|
+
inputElement?.setSelectionRange(at, select && at < currentValue().length ? at + 1 : at);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function handleInput(event) {
|
|
181
|
+
const target = event.currentTarget;
|
|
182
|
+
|
|
183
|
+
if (disabled || readonly) {
|
|
184
|
+
target.value = currentValue();
|
|
185
|
+
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const caret = normalize(target.value.slice(0, target.selectionStart ?? target.value.length)).length;
|
|
190
|
+
|
|
191
|
+
commitFromUser(target.value);
|
|
192
|
+
target.value = normalize(target.value);
|
|
193
|
+
|
|
194
|
+
// Use the accepted digit count, not the raw text length, so filtering cannot skip a slot.
|
|
195
|
+
target.setSelectionRange(caret, caret);
|
|
196
|
+
|
|
197
|
+
selectionIndex = Math.min(caret, target.value.length, length - 1);
|
|
198
|
+
oninput?.(event);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function handlePaste(event) {
|
|
202
|
+
onpaste?.(event);
|
|
203
|
+
|
|
204
|
+
if (event.defaultPrevented || disabled || readonly) return;
|
|
205
|
+
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
|
|
208
|
+
const pasted = event.clipboardData?.getData("text") ?? "";
|
|
209
|
+
const at = Math.min(selectionIndex, currentValue().length, length - 1);
|
|
210
|
+
|
|
211
|
+
if (!(/^[0-9]+$/).test(pasted)) {
|
|
212
|
+
rejectPaste(false);
|
|
213
|
+
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let next;
|
|
218
|
+
let caret;
|
|
219
|
+
|
|
220
|
+
if (pasted.length === length) {
|
|
221
|
+
next = pasted;
|
|
222
|
+
caret = length;
|
|
223
|
+
} else if (at > 0 && pasted.length <= length - at) {
|
|
224
|
+
// Interior paste may complete or partially fill the remaining contiguous suffix.
|
|
225
|
+
next = currentValue().slice(0, at) + pasted + currentValue().slice(at + pasted.length);
|
|
226
|
+
|
|
227
|
+
caret = at + pasted.length;
|
|
228
|
+
} else {
|
|
229
|
+
rejectPaste(at === 0);
|
|
230
|
+
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
commitFromUser(next);
|
|
235
|
+
|
|
236
|
+
if (inputElement) {
|
|
237
|
+
inputElement.value = next;
|
|
238
|
+
inputElement.setSelectionRange(caret, caret);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
selectionIndex = Math.min(caret, length - 1);
|
|
242
|
+
oninput?.(event);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function pointerIndex(event) {
|
|
246
|
+
const row = event.currentTarget.parentElement;
|
|
247
|
+
const slots = Array.from(row?.querySelectorAll(".snowui-otp-slot") ?? []);
|
|
248
|
+
|
|
249
|
+
return slots.findIndex((slot) => {
|
|
250
|
+
const rect = slot.getBoundingClientRect();
|
|
251
|
+
|
|
252
|
+
return event.clientX >= rect.left && event.clientX <= rect.right;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function handlePointerDown(event) {
|
|
257
|
+
if (disabled) return;
|
|
258
|
+
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
|
|
261
|
+
const index = pointerIndex(event);
|
|
262
|
+
|
|
263
|
+
inputElement?.focus();
|
|
264
|
+
moveCaret(index < 0 ? currentValue().length : index, true);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function syncSelection() {
|
|
268
|
+
if (!inputElement) return;
|
|
269
|
+
|
|
270
|
+
const index = Math.min(inputElement.selectionStart ?? currentValue().length, currentValue().length, length - 1);
|
|
271
|
+
|
|
272
|
+
selectionIndex = index;
|
|
273
|
+
|
|
274
|
+
// A contiguous prefix is the only editable code; never activate a later empty slot.
|
|
275
|
+
if ((inputElement.selectionStart ?? 0) > currentValue().length) moveCaret(index);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
Frame($$renderer, $.spread_props([
|
|
279
|
+
frameRestProps(),
|
|
280
|
+
{
|
|
281
|
+
tag: 'div',
|
|
282
|
+
class: `snowui-otp-input${resolvedInvalid() ? " snowui-feedback-error-shake" : ""} ${userClass}`.trim(),
|
|
283
|
+
style: userStyle || undefined,
|
|
284
|
+
'data-disabled': disabled ? "true" : undefined,
|
|
285
|
+
'data-readonly': readonly ? "true" : undefined,
|
|
286
|
+
'data-invalid': resolvedInvalid() ? "true" : undefined,
|
|
287
|
+
'data-focus': focused ? "true" : undefined,
|
|
288
|
+
role: 'group',
|
|
289
|
+
'aria-label': groupLabel(),
|
|
290
|
+
'aria-labelledby': groupLabelledby(),
|
|
291
|
+
enableAutoLayout: false,
|
|
292
|
+
enableResponsive,
|
|
293
|
+
enableContext,
|
|
294
|
+
enableScaleObserver: false,
|
|
295
|
+
children: ($$renderer) => {
|
|
296
|
+
$$renderer.push(`<span class="snowui-otp-slots"><input${$.attributes(
|
|
297
|
+
{
|
|
298
|
+
...nativeInputProps(),
|
|
299
|
+
class: 'snowui-otp-native',
|
|
300
|
+
type: 'text',
|
|
301
|
+
value: currentValue(),
|
|
302
|
+
name,
|
|
303
|
+
form,
|
|
304
|
+
disabled,
|
|
305
|
+
readonly,
|
|
306
|
+
required,
|
|
307
|
+
autocomplete,
|
|
308
|
+
autofocus,
|
|
309
|
+
tabindex,
|
|
310
|
+
id,
|
|
311
|
+
title,
|
|
312
|
+
'aria-label': groupLabel(),
|
|
313
|
+
'aria-labelledby': groupLabelledby(),
|
|
314
|
+
'aria-describedby': [
|
|
315
|
+
inputRestProps()["aria-describedby"],
|
|
316
|
+
resolvedInvalid() ? errorId : undefined
|
|
317
|
+
].filter(Boolean).join(" ") || undefined,
|
|
318
|
+
inputmode: 'numeric',
|
|
319
|
+
pattern: `[0-9]{${length}}`,
|
|
320
|
+
minlength: length,
|
|
321
|
+
'aria-invalid': resolvedInvalid() || undefined
|
|
322
|
+
},
|
|
323
|
+
void 0,
|
|
324
|
+
void 0,
|
|
325
|
+
void 0,
|
|
326
|
+
4
|
|
327
|
+
)}/> <!--[-->`);
|
|
328
|
+
|
|
329
|
+
const each_array = $.ensure_array_like(digits());
|
|
330
|
+
|
|
331
|
+
for (let index = 0, $$length = each_array.length; index < $$length; index++) {
|
|
332
|
+
let digit = each_array[index];
|
|
333
|
+
|
|
334
|
+
$$renderer.push(`<span class="snowui-otp-slot snowui-field-bordered snowui-rounded-rectangle" aria-hidden="true"${$.attr('data-active', focused && index === activeIndex() || undefined)}${$.attr('data-field-hover', hoveredIndex === index && !disabled ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr('data-filled', !!digit || undefined)}>`);
|
|
335
|
+
|
|
336
|
+
if (digit) {
|
|
337
|
+
$$renderer.push('<!--[0-->');
|
|
338
|
+
$$renderer.push(`<!---->`);
|
|
339
|
+
|
|
340
|
+
{
|
|
341
|
+
Frame($$renderer, {
|
|
342
|
+
tag: 'span',
|
|
343
|
+
class: 'snowui-otp-digit',
|
|
344
|
+
enableAutoLayout: false,
|
|
345
|
+
enableContext: false,
|
|
346
|
+
enableResponsive: false,
|
|
347
|
+
enableScaleObserver: false,
|
|
348
|
+
whileAppear: NUMBER_POP_APPEAR_MOTION,
|
|
349
|
+
children: ($$renderer) => {
|
|
350
|
+
$$renderer.push(`<!---->${$.escape(digit)}`);
|
|
351
|
+
},
|
|
352
|
+
$$slots: { default: true }
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
$$renderer.push(`<!---->`);
|
|
357
|
+
} else {
|
|
358
|
+
$$renderer.push('<!--[-1-->');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
$$renderer.push(`<!--]--></span>`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
$$renderer.push(`<!--]--> <span aria-hidden="true" class="snowui-otp-indicator snowui-field-bordered snowui-rounded-rectangle"${$.attr('data-field-focus', focused && !disabled ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr_style(`${TAB_INDICATOR_MOTION_STYLE}; --snowui-otp-input-active-index: ${activeIndex()}`)}></span></span> `);
|
|
365
|
+
|
|
366
|
+
if (resolvedInvalid()) {
|
|
367
|
+
$$renderer.push('<!--[0-->');
|
|
368
|
+
|
|
369
|
+
Text($$renderer, {
|
|
370
|
+
id: errorId,
|
|
371
|
+
as: 'error',
|
|
372
|
+
role: 'status',
|
|
373
|
+
'aria-live': 'polite',
|
|
374
|
+
class: 'snowui-field-error-message',
|
|
375
|
+
children: ($$renderer) => {
|
|
376
|
+
if (typeof errorContent() === "function") {
|
|
377
|
+
$$renderer.push('<!--[0-->');
|
|
378
|
+
errorContent()($$renderer);
|
|
379
|
+
$$renderer.push(`<!---->`);
|
|
380
|
+
} else {
|
|
381
|
+
$$renderer.push('<!--[-1-->');
|
|
382
|
+
$$renderer.push(`${$.escape(errorContent())}`);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
$$renderer.push(`<!--]-->`);
|
|
386
|
+
},
|
|
387
|
+
$$slots: { default: true }
|
|
388
|
+
});
|
|
389
|
+
} else {
|
|
390
|
+
$$renderer.push('<!--[-1-->');
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
$$renderer.push(`<!--]-->`);
|
|
394
|
+
},
|
|
395
|
+
$$slots: { default: true }
|
|
396
|
+
}
|
|
397
|
+
]));
|
|
398
|
+
|
|
399
|
+
$.bind_props($$props, { value });
|
|
400
|
+
});
|
|
401
|
+
}
|
|
@@ -27,7 +27,7 @@ export default function Pagination($$renderer, $$props) {
|
|
|
27
27
|
total = 1,
|
|
28
28
|
disabled = false,
|
|
29
29
|
disabledPages = [],
|
|
30
|
-
ariaLabel =
|
|
30
|
+
ariaLabel = undefined,
|
|
31
31
|
variant = "outline",
|
|
32
32
|
responsive = "auto",
|
|
33
33
|
widthMode = "fill",
|
|
@@ -933,7 +933,7 @@ export default function Pagination($$renderer, $$props) {
|
|
|
933
933
|
enableContext,
|
|
934
934
|
enableScaleObserver,
|
|
935
935
|
enableAutoLayout: false,
|
|
936
|
-
'aria-label': ariaLabel,
|
|
936
|
+
'aria-label': ariaLabel ?? localeContext.t("pagination.navigation"),
|
|
937
937
|
'data-disabled': disabled ? "true" : undefined,
|
|
938
938
|
'data-responsive': responsive,
|
|
939
939
|
'data-width-mode': widthMode,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { useLocale } from "../i18n/locale.js";
|
|
2
3
|
import Frame from "./Frame.js";
|
|
3
4
|
import { useOverlayScrollbar } from "../lib/overlay-scrollbar.js";
|
|
4
5
|
|
|
@@ -11,12 +12,14 @@ export default function ScrollArea($$renderer, $$props) {
|
|
|
11
12
|
$$renderer.global.css.add($$css);
|
|
12
13
|
|
|
13
14
|
$$renderer.component(($$renderer) => {
|
|
15
|
+
const localeContext = useLocale();
|
|
16
|
+
|
|
14
17
|
/** 横向滚动条常显,或仅在鼠标移入区域时显示 */
|
|
15
18
|
let {
|
|
16
19
|
axis = "vertical",
|
|
17
20
|
horizontalTrackPosition = "container",
|
|
18
21
|
horizontalScrollbarVisibility = "always",
|
|
19
|
-
ariaLabel =
|
|
22
|
+
ariaLabel = undefined,
|
|
20
23
|
viewport = void 0,
|
|
21
24
|
onscroll,
|
|
22
25
|
children,
|
|
@@ -64,7 +67,7 @@ export default function ScrollArea($$renderer, $$props) {
|
|
|
64
67
|
},
|
|
65
68
|
|
|
66
69
|
children: ($$renderer) => {
|
|
67
|
-
$$renderer.push(`<div class="snowui-scroll-area-viewport snowui-overlay-scrollbar-viewport"${$.attr('data-scroll-axis', axis)} role="region"${$.attr('aria-label', ariaLabel)} tabindex="0">`);
|
|
70
|
+
$$renderer.push(`<div class="snowui-scroll-area-viewport snowui-overlay-scrollbar-viewport"${$.attr('data-scroll-axis', axis)} role="region"${$.attr('aria-label', ariaLabel ?? localeContext.t("scrollArea.content"))} tabindex="0">`);
|
|
68
71
|
children?.($$renderer);
|
|
69
72
|
$$renderer.push(`<!----></div> `);
|
|
70
73
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { useLocale } from "../i18n/locale.js";
|
|
2
3
|
import { Button } from "../index.js";
|
|
3
4
|
import { ComponentIcon } from "../internal/component-icon/index.js";
|
|
4
5
|
import { Frame, resizeManager } from "../index.js";
|
|
@@ -13,11 +14,13 @@ export default function SearchBox($$renderer, $$props) {
|
|
|
13
14
|
|
|
14
15
|
$$renderer.component(($$renderer) => {
|
|
15
16
|
// SnowUI 许可入口:首次阅读源码请先读 ../../LICENSE;访问文件不代表获得修改或移植权,官方维护授权及同任务去重见该文件。
|
|
17
|
+
const localeContext = useLocale();
|
|
18
|
+
|
|
16
19
|
/** 内置图标按钮配置;事件与角色由所属组件控制。 */
|
|
17
20
|
let {
|
|
18
21
|
variant = "gray",
|
|
19
22
|
value = void 0,
|
|
20
|
-
placeholder =
|
|
23
|
+
placeholder = undefined,
|
|
21
24
|
open = false,
|
|
22
25
|
disabled = false,
|
|
23
26
|
readonly = false,
|
|
@@ -43,7 +46,10 @@ export default function SearchBox($$renderer, $$props) {
|
|
|
43
46
|
} = $$props;
|
|
44
47
|
|
|
45
48
|
const hasValue = $.derived(() => value !== undefined && value !== null && String(value) !== "");
|
|
46
|
-
|
|
49
|
+
|
|
50
|
+
const displayText = $.derived(() => hasValue()
|
|
51
|
+
? String(value)
|
|
52
|
+
: placeholder ?? localeContext.t("searchBox.placeholder"));
|
|
47
53
|
|
|
48
54
|
const searchBoxRenderHints = $.derived(() => ({
|
|
49
55
|
variant: userRenderHints?.variant ?? "line",
|
|
@@ -163,7 +169,7 @@ export default function SearchBox($$renderer, $$props) {
|
|
|
163
169
|
type: 'button',
|
|
164
170
|
class: `snowui-clear-icon-btn snowui-search-box-clear-btn${parts?.Button?.class ? ` ${parts.Button.class}` : ""}`,
|
|
165
171
|
as: 'trailing',
|
|
166
|
-
'aria-label':
|
|
172
|
+
'aria-label': localeContext.t("searchBox.clear"),
|
|
167
173
|
onclick: handleClear,
|
|
168
174
|
onmousedown: (event) => event.preventDefault(),
|
|
169
175
|
tabindex: -1,
|
|
@@ -205,7 +205,9 @@ export default function Select($$renderer, $$props) {
|
|
|
205
205
|
},
|
|
206
206
|
|
|
207
207
|
get triggerEl() {
|
|
208
|
-
return buttonTrigger()
|
|
208
|
+
return buttonTrigger()
|
|
209
|
+
? selectEl?.querySelector("button") ?? null
|
|
210
|
+
: triggerEl ?? null;
|
|
209
211
|
},
|
|
210
212
|
|
|
211
213
|
get anchorEl() {
|
|
@@ -50,7 +50,7 @@ export default function SidePanel($$renderer, $$props) {
|
|
|
50
50
|
bottomTrailing = undefined,
|
|
51
51
|
bottomLeadingActions = undefined,
|
|
52
52
|
bottomTrailingActions = undefined,
|
|
53
|
-
title =
|
|
53
|
+
title = undefined,
|
|
54
54
|
showTitle = false,
|
|
55
55
|
backdrop = false,
|
|
56
56
|
closeOnEscape = true,
|
|
@@ -78,6 +78,7 @@ export default function SidePanel($$renderer, $$props) {
|
|
|
78
78
|
provideComponentParts(() => parts);
|
|
79
79
|
|
|
80
80
|
const locale = useLocale();
|
|
81
|
+
const resolvedTitle = $.derived(() => title ?? locale.t("sidePanel.title"));
|
|
81
82
|
let panelEl = void 0;
|
|
82
83
|
let viewportEl = void 0;
|
|
83
84
|
let scrollbarEl = void 0;
|
|
@@ -415,7 +416,7 @@ export default function SidePanel($$renderer, $$props) {
|
|
|
415
416
|
enableAutoLayout: false,
|
|
416
417
|
role: 'dialog',
|
|
417
418
|
'aria-modal': placement === "floating" ? "true" : undefined,
|
|
418
|
-
'aria-label':
|
|
419
|
+
'aria-label': resolvedTitle(),
|
|
419
420
|
tabindex: '-1',
|
|
420
421
|
'data-placement': placement,
|
|
421
422
|
'data-inline-motion-owner': placement === "inline" ? inlineMotionOwner : undefined,
|
|
@@ -460,7 +461,7 @@ export default function SidePanel($$renderer, $$props) {
|
|
|
460
461
|
|
|
461
462
|
if (showTitle) {
|
|
462
463
|
$$renderer.push('<!--[0-->');
|
|
463
|
-
$$renderer.push(`<span class="snowui-side-panel-title">${$.escape(
|
|
464
|
+
$$renderer.push(`<span class="snowui-side-panel-title">${$.escape(resolvedTitle())}</span>`);
|
|
464
465
|
} else {
|
|
465
466
|
$$renderer.push('<!--[-1-->');
|
|
466
467
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { useLocale } from "../i18n/locale.js";
|
|
2
3
|
import Frame from "./Frame.js";
|
|
3
4
|
import Text from "./Text.js";
|
|
4
5
|
import { resolveSnowUIColor } from "../lib/color.js";
|
|
@@ -22,6 +23,8 @@ export default function Slider($$renderer, $$props) {
|
|
|
22
23
|
|
|
23
24
|
$$renderer.component(($$renderer) => {
|
|
24
25
|
// SnowUI 许可入口:首次阅读源码请先读 ../../LICENSE;访问文件不代表获得修改或移植权,官方维护授权及同任务去重见该文件。
|
|
26
|
+
const localeContext = useLocale();
|
|
27
|
+
|
|
25
28
|
let {
|
|
26
29
|
value = 0,
|
|
27
30
|
minValue = 0,
|
|
@@ -29,7 +32,7 @@ export default function Slider($$renderer, $$props) {
|
|
|
29
32
|
step = 1,
|
|
30
33
|
orientation = "horizontal",
|
|
31
34
|
variant = "default",
|
|
32
|
-
title =
|
|
35
|
+
title = undefined,
|
|
33
36
|
showSteps = false,
|
|
34
37
|
showLabel = false,
|
|
35
38
|
thickness = undefined,
|
|
@@ -55,6 +58,7 @@ export default function Slider($$renderer, $$props) {
|
|
|
55
58
|
...rest
|
|
56
59
|
} = $$props;
|
|
57
60
|
|
|
61
|
+
const resolvedTitle = $.derived(() => title ?? localeContext.t("slider.title"));
|
|
58
62
|
let controlRef = void 0;
|
|
59
63
|
let labelsRef = void 0;
|
|
60
64
|
let activeIndex = 0;
|
|
@@ -264,13 +268,13 @@ export default function Slider($$renderer, $$props) {
|
|
|
264
268
|
children: ($$renderer) => {
|
|
265
269
|
$$renderer.push(`<div class="snowui-slider-control" role="group">`);
|
|
266
270
|
|
|
267
|
-
if (isBarVariant() &&
|
|
271
|
+
if (isBarVariant() && resolvedTitle()) {
|
|
268
272
|
$$renderer.push('<!--[0-->');
|
|
269
273
|
|
|
270
274
|
Text($$renderer, {
|
|
271
275
|
class: 'snowui-slider-title',
|
|
272
276
|
children: ($$renderer) => {
|
|
273
|
-
$$renderer.push(`<!---->${$.escape(
|
|
277
|
+
$$renderer.push(`<!---->${$.escape(resolvedTitle())}`);
|
|
274
278
|
},
|
|
275
279
|
$$slots: { default: true }
|
|
276
280
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { useLocale } from "../i18n/locale.js";
|
|
2
3
|
import Frame from "./Frame.js";
|
|
3
4
|
import { getSizeContext, getSize } from "../context.js";
|
|
4
5
|
import { resolveResourceSizeToken } from "../logic/resource-size.js";
|
|
@@ -14,8 +15,9 @@ export default function Spinner($$renderer, $$props) {
|
|
|
14
15
|
|
|
15
16
|
$$renderer.component(($$renderer) => {
|
|
16
17
|
// SnowUI 许可入口:首次阅读源码请先读 ../../LICENSE;访问文件不代表获得修改或移植权,官方维护授权及同任务去重见该文件。
|
|
17
|
-
const
|
|
18
|
+
const localeContext = useLocale();
|
|
18
19
|
|
|
20
|
+
const inheritedSpinnerPart = useComponentPart("Spinner");
|
|
19
21
|
let { $$slots, $$events, ...explicitProps } = $$props;
|
|
20
22
|
|
|
21
23
|
let $$d = $.derived(() => mergeComponentPartProps(inheritedSpinnerPart.current, explicitProps)),
|
|
@@ -107,7 +109,7 @@ export default function Spinner($$renderer, $$props) {
|
|
|
107
109
|
].filter(Boolean).join("; "),
|
|
108
110
|
responsive: responsive(),
|
|
109
111
|
role: 'status',
|
|
110
|
-
'aria-label':
|
|
112
|
+
'aria-label': localeContext.t("spinner.loading"),
|
|
111
113
|
renderHints: spinnerRenderHints()
|
|
112
114
|
},
|
|
113
115
|
rest(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from 'svelte/internal/server';
|
|
2
|
+
import { useLocale } from "../i18n/locale.js";
|
|
2
3
|
import Button from "./Button.js";
|
|
3
4
|
import { ComponentIcon } from "../internal/component-icon/index.js";
|
|
4
5
|
import { resizeManager } from "../logic/observer.js";
|
|
@@ -14,6 +15,8 @@ export default function Tag($$renderer, $$props) {
|
|
|
14
15
|
|
|
15
16
|
$$renderer.component(($$renderer) => {
|
|
16
17
|
// SnowUI 许可入口:首次阅读源码请先读 ../../LICENSE;访问文件不代表获得修改或移植权,官方维护授权及同任务去重见该文件。
|
|
18
|
+
const localeContext = useLocale();
|
|
19
|
+
|
|
17
20
|
/** 内置图标按钮配置;事件与角色由所属组件控制。 */
|
|
18
21
|
let {
|
|
19
22
|
variant = "default",
|
|
@@ -243,7 +246,7 @@ export default function Tag($$renderer, $$props) {
|
|
|
243
246
|
{
|
|
244
247
|
type: 'button',
|
|
245
248
|
class: `snowui-clear-icon-btn snowui-tag-close${parts?.Button?.class ? ` ${parts.Button.class}` : ""}`,
|
|
246
|
-
'aria-label':
|
|
249
|
+
'aria-label': localeContext.t("tag.close"),
|
|
247
250
|
onclick: handleCloseClick,
|
|
248
251
|
children: ($$renderer) => {
|
|
249
252
|
ComponentIcon($$renderer, { name: 'close', 'aria-hidden': 'true' });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** SnowUI 组件内置 UI 文案 catalog。文档: ../../../specs/maintainers/LocalizationSpec.md */
|
|
2
2
|
export declare const DEFAULT_LOCALE = "zh-CN";
|
|
3
|
-
export type SnowUIMessageKey = "copyButton.copy" | "copyButton.copied" | "codeBlock.copyCode" | "codeBlock.fullscreen" | "codeBlock.exitFullscreen" | "codeBlock.resize" | "codeBlock.fullscreenDialog" | "expandButton.expand" | "expandButton.collapse" | "sidebar.resize" | "pagination.pageSize" | "pagination.previous" | "pagination.next" | "pagination.page" | "input.clear" | "input.increment" | "input.decrement" | "input.openTime" | "input.openDate" | "input.year" | "input.month" | "input.day" | "input.week" | "input.hour" | "input.minute" | "input.second" | "input.yearPlaceholder" | "input.monthPlaceholder" | "input.dayPlaceholder" | "input.weekPlaceholder" | "imageViewer.previous" | "imageViewer.next" | "imageViewer.close" | "toast.close" | "table.scrollRegion" | "table.scrollRegionNamed" | "tableHead.selectAll" | "tableHead.resizeColumn" | "tableHead.resizeColumnGeneric" | "tableCell.selectRow" | "text.expand" | "textarea.resize" | "indicator.resizeWidth" | "indicator.resizeHeight" | "indicator.resizeBoth" | "colorSchemeButton.toLight" | "colorSchemeButton.toDark" | "styleButton.toSnowUI" | "styleButton.toApple" | "sidePanel.placement.toInline" | "sidePanel.placement.toFloating" | "sidePanel.previous" | "sidePanel.next" | "sidePanel.copy" | "sidePanel.delete" | "sidePanel.cancel" | "sidePanel.save" | "sidePanel.close" | "sidePanel.resize" | "tableToolbar.name" | "tableToolbar.search" | "tableToolbar.sort" | "tableToolbar.filter" | "tableToolbar.clear" | "tableToolbar.copy" | "tableToolbar.delete" | "tableToolbar.selected" | "tableToolbar.deleting" | "tableToolbar.defaultSort" | "tableToolbar.ascending" | "tableToolbar.descending" | "tableToolbar.defaultFilter" | "overflowActions.more" | "dialog.close";
|
|
3
|
+
export type SnowUIMessageKey = "copyButton.copy" | "copyButton.copied" | "codeBlock.copyCode" | "codeBlock.fullscreen" | "codeBlock.exitFullscreen" | "codeBlock.resize" | "codeBlock.fullscreenDialog" | "expandButton.expand" | "expandButton.collapse" | "sidebarSection.expand" | "sidebarSection.collapse" | "breadcrumb.navigation" | "pagination.navigation" | "spinner.loading" | "scrollArea.content" | "barChart.name" | "barChart.cells" | "lineChart.name" | "lineChart.cells" | "circularChart.name" | "gaugeChart.name" | "chartGroup.name" | "chartGroup.cells" | "chartGroup.cell" | "searchBox.placeholder" | "searchBox.clear" | "sidePanel.title" | "slider.title" | "menuItem.deleteCustom" | "listbox.search" | "tag.close" | "sidebar.navigation" | "sidebar.expand" | "sidebar.collapse" | "sidebarItem.updated" | "sidebar.resize" | "pagination.pageSize" | "pagination.previous" | "pagination.next" | "pagination.page" | "otpInput.invalidCode" | "input.clear" | "input.increment" | "input.decrement" | "input.openTime" | "input.openDate" | "input.year" | "input.month" | "input.day" | "input.week" | "input.hour" | "input.minute" | "input.second" | "input.yearPlaceholder" | "input.monthPlaceholder" | "input.dayPlaceholder" | "input.weekPlaceholder" | "imageViewer.previous" | "imageViewer.next" | "imageViewer.close" | "toast.close" | "table.scrollRegion" | "table.scrollRegionNamed" | "tableHead.selectAll" | "tableHead.resizeColumn" | "tableHead.resizeColumnGeneric" | "tableCell.selectRow" | "text.expand" | "textarea.resize" | "indicator.resizeWidth" | "indicator.resizeHeight" | "indicator.resizeBoth" | "colorSchemeButton.toLight" | "colorSchemeButton.toDark" | "styleButton.toSnowUI" | "styleButton.toApple" | "sidePanel.placement.toInline" | "sidePanel.placement.toFloating" | "sidePanel.previous" | "sidePanel.next" | "sidePanel.copy" | "sidePanel.delete" | "sidePanel.cancel" | "sidePanel.save" | "sidePanel.close" | "sidePanel.resize" | "tableToolbar.name" | "tableToolbar.search" | "tableToolbar.sort" | "tableToolbar.filter" | "tableToolbar.clear" | "tableToolbar.copy" | "tableToolbar.delete" | "tableToolbar.selected" | "tableToolbar.deleting" | "tableToolbar.defaultSort" | "tableToolbar.ascending" | "tableToolbar.descending" | "tableToolbar.defaultFilter" | "overflowActions.more" | "dialog.close";
|
|
4
4
|
export type SnowUIMessageValues = Record<string, string | number>;
|
|
5
5
|
export type SnowUIMessageOverrides = Partial<Record<SnowUIMessageKey, string>>;
|
|
6
6
|
export declare const SNOWUI_MESSAGES: Record<string, Record<SnowUIMessageKey, string>>;
|