@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.8
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/dist/FOCUS_STATE_CONTRACT.md +15 -4
- package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
- package/dist/avatar/README.md +52 -0
- package/dist/avatar/count/avatar-count.svelte +56 -0
- package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
- package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
- package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
- package/dist/avatar/group/avatar-group.svelte +65 -0
- package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
- package/dist/avatar/group/context.d.ts +15 -0
- package/dist/avatar/group/context.js +15 -0
- package/dist/avatar/image/avatar-image.svelte +104 -0
- package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
- package/dist/avatar/index.d.ts +22 -0
- package/dist/avatar/index.js +10 -0
- package/dist/avatar/index.parts.d.ts +5 -0
- package/dist/avatar/index.parts.js +5 -0
- package/dist/avatar/root/avatar-root.svelte +79 -0
- package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
- package/dist/avatar/root/context.d.ts +14 -0
- package/dist/avatar/root/context.js +15 -0
- package/dist/avatar/types.d.ts +84 -0
- package/dist/avatar/types.js +1 -0
- package/dist/breadcrumbs/README.md +65 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
- package/dist/breadcrumbs/index.d.ts +23 -0
- package/dist/breadcrumbs/index.js +10 -0
- package/dist/breadcrumbs/index.parts.d.ts +6 -0
- package/dist/breadcrumbs/index.parts.js +6 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/context.d.ts +19 -0
- package/dist/breadcrumbs/root/context.js +15 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
- package/dist/breadcrumbs/types.d.ts +80 -0
- package/dist/breadcrumbs/types.js +1 -0
- package/dist/combobox/popover/combobox-popover.svelte +4 -56
- package/dist/dialog/root/dialog-root.svelte +15 -2
- package/dist/drawer/root/drawer-root.svelte +15 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/internal/localized-strings.d.ts +48 -0
- package/dist/internal/localized-strings.js +48 -0
- package/dist/internal/number-precision.d.ts +9 -0
- package/dist/internal/number-precision.js +27 -0
- package/dist/menu/root/focus-state.d.ts +2 -2
- package/dist/menu/root/focus-state.js +8 -32
- package/dist/menu/root/menu-state.svelte.js +5 -1
- package/dist/numberfield/root/number-utils.js +1 -20
- package/dist/popover/root/focus-state.d.ts +2 -2
- package/dist/popover/root/focus-state.js +7 -34
- package/dist/primitives/contain-wheel.d.ts +9 -0
- package/dist/primitives/contain-wheel.js +41 -0
- package/dist/primitives/floating.d.ts +6 -0
- package/dist/primitives/floating.js +26 -5
- package/dist/primitives/keyboard-navigation.d.ts +6 -0
- package/dist/primitives/keyboard-navigation.js +2 -1
- package/dist/primitives/trigger-focus-state.d.ts +29 -0
- package/dist/primitives/trigger-focus-state.js +57 -0
- package/dist/progress/README.md +54 -0
- package/dist/progress/index.d.ts +21 -0
- package/dist/progress/index.js +9 -0
- package/dist/progress/index.parts.d.ts +5 -0
- package/dist/progress/index.parts.js +5 -0
- package/dist/progress/indicator/progress-indicator.svelte +37 -0
- package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
- package/dist/progress/label/progress-label.svelte +34 -0
- package/dist/progress/label/progress-label.svelte.d.ts +4 -0
- package/dist/progress/root/context.d.ts +26 -0
- package/dist/progress/root/context.js +15 -0
- package/dist/progress/root/progress-root.svelte +136 -0
- package/dist/progress/root/progress-root.svelte.d.ts +4 -0
- package/dist/progress/root/progress-utils.d.ts +12 -0
- package/dist/progress/root/progress-utils.js +41 -0
- package/dist/progress/track/progress-track.svelte +27 -0
- package/dist/progress/track/progress-track.svelte.d.ts +4 -0
- package/dist/progress/types.d.ts +81 -0
- package/dist/progress/types.js +1 -0
- package/dist/progress/value/progress-value.svelte +36 -0
- package/dist/progress/value/progress-value.svelte.d.ts +4 -0
- package/dist/select/README.md +129 -0
- package/dist/select/index.d.ts +30 -0
- package/dist/select/index.js +16 -0
- package/dist/select/index.parts.d.ts +8 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/select-item.svelte +68 -0
- package/dist/select/item/select-item.svelte.d.ts +10 -0
- package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
- package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
- package/dist/select/label/select-label.svelte +46 -0
- package/dist/select/label/select-label.svelte.d.ts +4 -0
- package/dist/select/list/select-list.svelte +241 -0
- package/dist/select/list/select-list.svelte.d.ts +62 -0
- package/dist/select/popover/select-popover.svelte +80 -0
- package/dist/select/popover/select-popover.svelte.d.ts +9 -0
- package/dist/select/root/context.d.ts +106 -0
- package/dist/select/root/context.js +22 -0
- package/dist/select/root/select-root.svelte +544 -0
- package/dist/select/root/select-root.svelte.d.ts +25 -0
- package/dist/select/trigger/select-trigger.svelte +192 -0
- package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
- package/dist/select/types.d.ts +133 -0
- package/dist/select/types.js +1 -0
- package/dist/select/value/select-value.svelte +61 -0
- package/dist/select/value/select-value.svelte.d.ts +4 -0
- package/dist/separator/README.md +35 -0
- package/dist/separator/index.d.ts +7 -0
- package/dist/separator/index.js +3 -0
- package/dist/separator/separator.svelte +254 -0
- package/dist/separator/separator.svelte.d.ts +45 -0
- package/dist/separator/types.d.ts +1 -0
- package/dist/separator/types.js +1 -0
- package/dist/slider/README.md +61 -0
- package/dist/slider/fill/slider-fill.svelte +40 -0
- package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
- package/dist/slider/index.d.ts +9 -0
- package/dist/slider/index.js +8 -0
- package/dist/slider/index.parts.d.ts +6 -0
- package/dist/slider/index.parts.js +6 -0
- package/dist/slider/label/slider-label.svelte +44 -0
- package/dist/slider/label/slider-label.svelte.d.ts +4 -0
- package/dist/slider/output/slider-output.svelte +46 -0
- package/dist/slider/output/slider-output.svelte.d.ts +4 -0
- package/dist/slider/root/context.d.ts +106 -0
- package/dist/slider/root/context.js +15 -0
- package/dist/slider/root/slider-root.svelte +545 -0
- package/dist/slider/root/slider-root.svelte.d.ts +4 -0
- package/dist/slider/root/slider-utils.d.ts +57 -0
- package/dist/slider/root/slider-utils.js +88 -0
- package/dist/slider/thumb/slider-thumb.svelte +276 -0
- package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
- package/dist/slider/track/slider-track.svelte +60 -0
- package/dist/slider/track/slider-track.svelte.d.ts +4 -0
- package/dist/slider/types.d.ts +144 -0
- package/dist/slider/types.js +1 -0
- package/dist/tooltip/README.md +53 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
- package/dist/tooltip/content/tooltip-content.svelte +148 -0
- package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
- package/dist/tooltip/index.d.ts +8 -0
- package/dist/tooltip/index.js +7 -0
- package/dist/tooltip/index.parts.d.ts +5 -0
- package/dist/tooltip/index.parts.js +5 -0
- package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
- package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
- package/dist/tooltip/root/context.d.ts +46 -0
- package/dist/tooltip/root/context.js +22 -0
- package/dist/tooltip/root/safe-polygon.d.ts +26 -0
- package/dist/tooltip/root/safe-polygon.js +66 -0
- package/dist/tooltip/root/tooltip-group.d.ts +26 -0
- package/dist/tooltip/root/tooltip-group.js +41 -0
- package/dist/tooltip/root/tooltip-root.svelte +454 -0
- package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
- package/dist/tooltip/types.d.ts +105 -0
- package/dist/tooltip/types.js +1 -0
- package/package.json +36 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { readable } from 'svelte/store';
|
|
4
|
+
import { useLocaleContextOptional } from '../../locale-provider/context';
|
|
5
|
+
import type { ProgressRootProps } from '../types.js';
|
|
6
|
+
import { setProgressContext, type ProgressContext } from './context';
|
|
7
|
+
import {
|
|
8
|
+
clampProgressValue,
|
|
9
|
+
formatProgressValue,
|
|
10
|
+
getProgressPercent,
|
|
11
|
+
getProgressStatus,
|
|
12
|
+
normalizeProgressValue
|
|
13
|
+
} from './progress-utils';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Progress.Root — the status of a task that takes time.
|
|
17
|
+
*
|
|
18
|
+
* It is the `role="progressbar"` element, and it holds the numbers for the parts in it. A
|
|
19
|
+
* screen reader reads its name and its value; it does not read the parts. The value is
|
|
20
|
+
* `aria-valuenow` with `aria-valuetext`, or nothing at all while the end of the task is not
|
|
21
|
+
* known: a number for an indeterminate progress would be a lie.
|
|
22
|
+
*/
|
|
23
|
+
const generatedId = $props.id();
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
id: idProp,
|
|
27
|
+
value: valueProp,
|
|
28
|
+
min = 0,
|
|
29
|
+
max = 100,
|
|
30
|
+
format,
|
|
31
|
+
getValueText,
|
|
32
|
+
'aria-valuetext': ariaValueTextProp,
|
|
33
|
+
'aria-labelledby': ariaLabelledBy,
|
|
34
|
+
orientation = 'horizontal',
|
|
35
|
+
children,
|
|
36
|
+
class: className = '',
|
|
37
|
+
element = $bindable<HTMLDivElement | null>(null),
|
|
38
|
+
context = $bindable(),
|
|
39
|
+
...restProps
|
|
40
|
+
}: ProgressRootProps = $props();
|
|
41
|
+
|
|
42
|
+
const instanceId = untrack(() => idProp) ?? generatedId;
|
|
43
|
+
|
|
44
|
+
const localeContext = useLocaleContextOptional();
|
|
45
|
+
const emptyLocaleStore = readable<string | undefined>(undefined);
|
|
46
|
+
const localeStore = localeContext?.locale ?? emptyLocaleStore;
|
|
47
|
+
|
|
48
|
+
let rootRef: HTMLDivElement | null = $state(null);
|
|
49
|
+
let labelIds = $state<string[]>([]);
|
|
50
|
+
|
|
51
|
+
const rawValue = $derived(normalizeProgressValue(valueProp));
|
|
52
|
+
const value = $derived(rawValue === null ? null : clampProgressValue(rawValue, min, max));
|
|
53
|
+
const percent = $derived(rawValue === null ? null : getProgressPercent(rawValue, min, max));
|
|
54
|
+
const status = $derived(getProgressStatus(rawValue, min, max));
|
|
55
|
+
const formattedValue = $derived(formatProgressValue(rawValue, min, max, $localeStore, format));
|
|
56
|
+
const valueText = $derived.by(() => {
|
|
57
|
+
if (value === null) return undefined;
|
|
58
|
+
if (ariaValueTextProp !== undefined) return ariaValueTextProp;
|
|
59
|
+
if (getValueText) return getValueText(formattedValue, value);
|
|
60
|
+
return formattedValue;
|
|
61
|
+
});
|
|
62
|
+
const labelledBy = $derived(
|
|
63
|
+
ariaLabelledBy ?? (labelIds.length > 0 ? labelIds.join(' ') : undefined)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const progress: ProgressContext = {
|
|
67
|
+
get id() {
|
|
68
|
+
return instanceId;
|
|
69
|
+
},
|
|
70
|
+
get value() {
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
get min() {
|
|
74
|
+
return min;
|
|
75
|
+
},
|
|
76
|
+
get max() {
|
|
77
|
+
return max;
|
|
78
|
+
},
|
|
79
|
+
get percent() {
|
|
80
|
+
return percent;
|
|
81
|
+
},
|
|
82
|
+
get status() {
|
|
83
|
+
return status;
|
|
84
|
+
},
|
|
85
|
+
get orientation() {
|
|
86
|
+
return orientation;
|
|
87
|
+
},
|
|
88
|
+
get formattedValue() {
|
|
89
|
+
return formattedValue;
|
|
90
|
+
},
|
|
91
|
+
get valueText() {
|
|
92
|
+
return valueText;
|
|
93
|
+
},
|
|
94
|
+
get labelledBy() {
|
|
95
|
+
return labelledBy;
|
|
96
|
+
},
|
|
97
|
+
// `untrack` because the caller registers from an effect: reading `labelIds` here would
|
|
98
|
+
// make that effect depend on what it writes, and the pair would run without end.
|
|
99
|
+
registerLabel(id: string) {
|
|
100
|
+
untrack(() => {
|
|
101
|
+
labelIds = [...labelIds, id];
|
|
102
|
+
});
|
|
103
|
+
return () =>
|
|
104
|
+
untrack(() => {
|
|
105
|
+
labelIds = labelIds.filter((candidate) => candidate !== id);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
setProgressContext(progress);
|
|
111
|
+
context = progress;
|
|
112
|
+
|
|
113
|
+
$effect(() => {
|
|
114
|
+
element = rootRef;
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<div
|
|
119
|
+
{...restProps}
|
|
120
|
+
bind:this={rootRef}
|
|
121
|
+
id={instanceId}
|
|
122
|
+
role="progressbar"
|
|
123
|
+
aria-labelledby={labelledBy}
|
|
124
|
+
aria-valuemin={min}
|
|
125
|
+
aria-valuemax={max}
|
|
126
|
+
aria-valuenow={value ?? undefined}
|
|
127
|
+
aria-valuetext={valueText}
|
|
128
|
+
class={className}
|
|
129
|
+
data-progress-root="true"
|
|
130
|
+
data-orientation={orientation}
|
|
131
|
+
data-progressing={status === 'progressing' || undefined}
|
|
132
|
+
data-complete={status === 'complete' || undefined}
|
|
133
|
+
data-indeterminate={status === 'indeterminate' || undefined}
|
|
134
|
+
>
|
|
135
|
+
{@render children?.()}
|
|
136
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ProgressStatus = 'progressing' | 'complete' | 'indeterminate';
|
|
2
|
+
/** A finite number is a value. Anything else keeps the progress indeterminate. */
|
|
3
|
+
export declare function normalizeProgressValue(value: number | null | undefined): number | null;
|
|
4
|
+
export declare function clampProgressValue(value: number, min: number, max: number): number;
|
|
5
|
+
/** The position of a value in the range, from 0 to 100. An empty range reads as 0. */
|
|
6
|
+
export declare function getProgressPercent(value: number, min: number, max: number): number;
|
|
7
|
+
export declare function getProgressStatus(value: number | null, min: number, max: number): ProgressStatus;
|
|
8
|
+
/**
|
|
9
|
+
* The text for a value. With `format`, it is the value in that format. Without it, it is the
|
|
10
|
+
* position in the range as a percentage: `31%` for 31 of 100, and for 62 of 200.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatProgressValue(value: number | null, min: number, max: number, locale: string | undefined, format: Intl.NumberFormatOptions | undefined): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** A finite number is a value. Anything else keeps the progress indeterminate. */
|
|
2
|
+
export function normalizeProgressValue(value) {
|
|
3
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
4
|
+
}
|
|
5
|
+
export function clampProgressValue(value, min, max) {
|
|
6
|
+
if (max < min)
|
|
7
|
+
return min;
|
|
8
|
+
return Math.min(max, Math.max(min, value));
|
|
9
|
+
}
|
|
10
|
+
/** The position of a value in the range, from 0 to 100. An empty range reads as 0. */
|
|
11
|
+
export function getProgressPercent(value, min, max) {
|
|
12
|
+
const span = max - min;
|
|
13
|
+
if (!(span > 0))
|
|
14
|
+
return 0;
|
|
15
|
+
const percent = ((clampProgressValue(value, min, max) - min) / span) * 100;
|
|
16
|
+
return Math.min(100, Math.max(0, percent));
|
|
17
|
+
}
|
|
18
|
+
export function getProgressStatus(value, min, max) {
|
|
19
|
+
if (value === null)
|
|
20
|
+
return 'indeterminate';
|
|
21
|
+
return clampProgressValue(value, min, max) >= max ? 'complete' : 'progressing';
|
|
22
|
+
}
|
|
23
|
+
function createFormatter(locale, options) {
|
|
24
|
+
try {
|
|
25
|
+
return new Intl.NumberFormat(locale, options);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return new Intl.NumberFormat(undefined, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The text for a value. With `format`, it is the value in that format. Without it, it is the
|
|
33
|
+
* position in the range as a percentage: `31%` for 31 of 100, and for 62 of 200.
|
|
34
|
+
*/
|
|
35
|
+
export function formatProgressValue(value, min, max, locale, format) {
|
|
36
|
+
if (value === null)
|
|
37
|
+
return '';
|
|
38
|
+
if (format)
|
|
39
|
+
return createFormatter(locale, format).format(clampProgressValue(value, min, max));
|
|
40
|
+
return createFormatter(locale, { style: 'percent' }).format(getProgressPercent(value, min, max) / 100);
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ProgressTrackProps } from '../types.js';
|
|
3
|
+
import { useProgressContext } from '../root/context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Progress.Track — the full length of the task. The indicator fills a part of it.
|
|
7
|
+
*
|
|
8
|
+
* It is `position: relative` with `overflow: hidden`, thus the indicator takes its place in
|
|
9
|
+
* it with an inset, and an animated indeterminate indicator stays in it.
|
|
10
|
+
*/
|
|
11
|
+
let { children, class: className = '', style, ...restProps }: ProgressTrackProps = $props();
|
|
12
|
+
|
|
13
|
+
const progress = useProgressContext('Progress.Track');
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
{...restProps}
|
|
18
|
+
class={className}
|
|
19
|
+
style="position: relative; overflow: hidden;{style ? ` ${style}` : ''}"
|
|
20
|
+
data-progress-track="true"
|
|
21
|
+
data-orientation={progress.orientation}
|
|
22
|
+
data-progressing={progress.status === 'progressing' || undefined}
|
|
23
|
+
data-complete={progress.status === 'complete' || undefined}
|
|
24
|
+
data-indeterminate={progress.status === 'indeterminate' || undefined}
|
|
25
|
+
>
|
|
26
|
+
{@render children?.()}
|
|
27
|
+
</div>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { ProgressContext, ProgressOrientation, ProgressStatus } from './root/context.js';
|
|
4
|
+
export type { ProgressContext, ProgressOrientation, ProgressStatus } from './root/context.js';
|
|
5
|
+
export type ProgressRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id' | 'role' | 'aria-valuenow' | 'aria-valuemin' | 'aria-valuemax'> & {
|
|
6
|
+
/**
|
|
7
|
+
* The progress of the task, between `min` and `max`. `null` makes the progress indeterminate:
|
|
8
|
+
* the task runs, and its end is not known. A value out of the range is held at the near end.
|
|
9
|
+
*/
|
|
10
|
+
value: number | null;
|
|
11
|
+
/** The value at the start of the task. */
|
|
12
|
+
min?: number;
|
|
13
|
+
/** The value at the end of the task. The progress is complete when the value reaches it. */
|
|
14
|
+
max?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The format of the value as text. Without it, the text is the position in the range as a
|
|
17
|
+
* percentage. Give the options of `Intl.NumberFormat` to show the value itself, in a unit.
|
|
18
|
+
*/
|
|
19
|
+
format?: Intl.NumberFormatOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Makes the text a screen reader gets for the value. It gets the formatted text and the value.
|
|
22
|
+
* Without it, the screen reader gets the formatted text.
|
|
23
|
+
*/
|
|
24
|
+
getValueText?: (formattedValue: string, value: number | null) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The text a screen reader gets for the value. It wins over `getValueText`. It has no effect
|
|
27
|
+
* while the progress is indeterminate: without a number, a text for the number is nothing.
|
|
28
|
+
*/
|
|
29
|
+
'aria-valuetext'?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The direction of the bar. It sets `data-orientation` for your styles, and it tells the
|
|
32
|
+
* indicator which side to fill from.
|
|
33
|
+
*/
|
|
34
|
+
orientation?: ProgressOrientation;
|
|
35
|
+
/** The parts of the progress bar. */
|
|
36
|
+
children?: Snippet;
|
|
37
|
+
/** The CSS class names of the element. */
|
|
38
|
+
class?: string;
|
|
39
|
+
/** The id of the root element. The component makes one when you give none. */
|
|
40
|
+
id?: string;
|
|
41
|
+
/** The root element. Use `bind:element` to read it. */
|
|
42
|
+
element?: HTMLDivElement | null;
|
|
43
|
+
/**
|
|
44
|
+
* The state of the progress. Use `bind:context` to read `percent`, `status` and
|
|
45
|
+
* `formattedValue` for a shape of your own, such as a ring.
|
|
46
|
+
*/
|
|
47
|
+
context?: ProgressContext;
|
|
48
|
+
};
|
|
49
|
+
export type ProgressLabelProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'id'> & {
|
|
50
|
+
/** The name of the task. */
|
|
51
|
+
children?: Snippet;
|
|
52
|
+
/** The CSS class names of the element. */
|
|
53
|
+
class?: string;
|
|
54
|
+
/** The id of the label element. The component makes one when you give none. */
|
|
55
|
+
id?: string;
|
|
56
|
+
};
|
|
57
|
+
export type ProgressTrackProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
58
|
+
/** The indicator. */
|
|
59
|
+
children?: Snippet;
|
|
60
|
+
/** The CSS class names of the element. */
|
|
61
|
+
class?: string;
|
|
62
|
+
};
|
|
63
|
+
export type ProgressIndicatorProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
64
|
+
/** Content inside the indicator, such as a stripe. */
|
|
65
|
+
children?: Snippet;
|
|
66
|
+
/** The CSS class names of the element. */
|
|
67
|
+
class?: string;
|
|
68
|
+
};
|
|
69
|
+
export type ProgressValueState = {
|
|
70
|
+
/** The value as text. Empty while the progress is indeterminate. */
|
|
71
|
+
formattedValue: string;
|
|
72
|
+
/** The value, held in the range. `null` while the progress is indeterminate. */
|
|
73
|
+
value: number | null;
|
|
74
|
+
status: ProgressStatus;
|
|
75
|
+
};
|
|
76
|
+
export type ProgressValueProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
|
|
77
|
+
/** The content in place of the formatted text. It gets the text, the value and the status. */
|
|
78
|
+
children?: Snippet<[ProgressValueState]>;
|
|
79
|
+
/** The CSS class names of the element. */
|
|
80
|
+
class?: string;
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ProgressValueProps } from '../types.js';
|
|
3
|
+
import { useProgressContext } from '../root/context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Progress.Value — the value as text, for the user.
|
|
7
|
+
*
|
|
8
|
+
* It is `aria-hidden`: the screen reader already gets the value from the progress bar, thus a
|
|
9
|
+
* second copy would read twice. Give it children to shape the text; without them, it shows
|
|
10
|
+
* the formatted value, and nothing while the progress is indeterminate.
|
|
11
|
+
*/
|
|
12
|
+
let { children, class: className = '', ...restProps }: ProgressValueProps = $props();
|
|
13
|
+
|
|
14
|
+
const progress = useProgressContext('Progress.Value');
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<span
|
|
18
|
+
{...restProps}
|
|
19
|
+
class={className}
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
data-progress-value="true"
|
|
22
|
+
data-orientation={progress.orientation}
|
|
23
|
+
data-progressing={progress.status === 'progressing' || undefined}
|
|
24
|
+
data-complete={progress.status === 'complete' || undefined}
|
|
25
|
+
data-indeterminate={progress.status === 'indeterminate' || undefined}
|
|
26
|
+
>
|
|
27
|
+
{#if children}
|
|
28
|
+
{@render children({
|
|
29
|
+
formattedValue: progress.formattedValue,
|
|
30
|
+
value: progress.value,
|
|
31
|
+
status: progress.status
|
|
32
|
+
})}
|
|
33
|
+
{:else}
|
|
34
|
+
{progress.formattedValue}
|
|
35
|
+
{/if}
|
|
36
|
+
</span>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Select
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`Select` is a form field with one value from a list of options. The user opens the list from a
|
|
6
|
+
button, and the list is a `ListBox` in a popover. It has the keyboard of the WAI-ARIA select-only
|
|
7
|
+
combobox and a native control for the form. The field and its value have one name in the
|
|
8
|
+
accessibility tree.
|
|
9
|
+
|
|
10
|
+
## Anatomy
|
|
11
|
+
|
|
12
|
+
- `Select.Root`
|
|
13
|
+
- `Select.Label`
|
|
14
|
+
- `Select.Trigger`
|
|
15
|
+
- `Select.Value`
|
|
16
|
+
- `Select.Popover`
|
|
17
|
+
- `Select.List`
|
|
18
|
+
- `Select.Item`
|
|
19
|
+
- `Select.ItemIndicator`
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<Select.Root name="fruit" defaultValue="apple">
|
|
23
|
+
<Select.Label>Fruit</Select.Label>
|
|
24
|
+
<Select.Trigger>
|
|
25
|
+
<Select.Value />
|
|
26
|
+
</Select.Trigger>
|
|
27
|
+
<Select.Popover>
|
|
28
|
+
<Select.List>
|
|
29
|
+
<Select.Item id="apple">Apple <Select.ItemIndicator /></Select.Item>
|
|
30
|
+
<Select.Item id="banana">Banana <Select.ItemIndicator /></Select.Item>
|
|
31
|
+
</Select.List>
|
|
32
|
+
</Select.Popover>
|
|
33
|
+
</Select.Root>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage guidelines
|
|
37
|
+
|
|
38
|
+
- Use `bind:value` to hand the root your state. Use `value` with `onChange` and `controlledValue`
|
|
39
|
+
to hold the state yourself and refuse a change.
|
|
40
|
+
- Give `items` to `Select.Root` when the field starts with a value. The options are not in the DOM
|
|
41
|
+
while the popover is closed, thus the trigger reads the text of the value from `items`. Without
|
|
42
|
+
it, the trigger shows the key until the popover opens one time.
|
|
43
|
+
- Give the root a `name` to send the value with a form. The root makes a native `<select>` that
|
|
44
|
+
the form reads, and that the browser autofill writes to.
|
|
45
|
+
- Set `selectionMode="multiple"` for more than one value. The popover then stays open after a
|
|
46
|
+
selection, and `value` is an array.
|
|
47
|
+
- Put `Select.Value` inside `Select.Trigger`. The trigger then shows the selection, and the value
|
|
48
|
+
is part of the accessible name of the field.
|
|
49
|
+
|
|
50
|
+
## API reference
|
|
51
|
+
|
|
52
|
+
`Select.Root` supports:
|
|
53
|
+
|
|
54
|
+
- `value?: SelectKey | null | SelectKey[]`
|
|
55
|
+
- `defaultValue?: SelectKey | null | SelectKey[]`
|
|
56
|
+
- `controlledValue?: boolean`
|
|
57
|
+
- `onChange?: (value) => void`
|
|
58
|
+
- `open?: boolean`, `defaultOpen?: boolean`, `controlledOpen?: boolean`
|
|
59
|
+
- `onOpenChange?: (open, details) => void`
|
|
60
|
+
- `selectionMode?: 'single' | 'multiple'`
|
|
61
|
+
- `closeOnSelect?: boolean`
|
|
62
|
+
- `disabledKeys?: Iterable<SelectKey>`
|
|
63
|
+
- `loop?: boolean`
|
|
64
|
+
- `disabled?`, `readonly?`, `required?`, `invalid?: boolean`
|
|
65
|
+
- `name?`, `form?`, `autocomplete?: string`
|
|
66
|
+
- `items?: T[]`
|
|
67
|
+
- `placeholder?: string`
|
|
68
|
+
- `aria-label?`, `aria-labelledby?`, `aria-describedby?: string`
|
|
69
|
+
- `context?: SelectContext`, `element?: HTMLDivElement`
|
|
70
|
+
- `...restProps: HTMLAttributes<HTMLDivElement>`
|
|
71
|
+
|
|
72
|
+
`Select.Trigger` is a `Button.Root` with `role="combobox"`. Its `children` snippet receives
|
|
73
|
+
`{ open, placeholder, disabled }`.
|
|
74
|
+
|
|
75
|
+
`Select.Value` shows the text of the selection, or the placeholder. Its `children` snippet
|
|
76
|
+
receives `{ value, label, placeholder }`.
|
|
77
|
+
|
|
78
|
+
`Select.Popover` takes the props of `Popover.Content`. `Select.List` takes the props of
|
|
79
|
+
`ListBox.Root`, and `Select.Item` the props of `ListBox.Item`. `Select.ItemIndicator` supports
|
|
80
|
+
`forceMount`.
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- `Select.Trigger` is a native `<button>` with `role="combobox"`, `aria-haspopup="listbox"`,
|
|
85
|
+
`aria-expanded`, and `aria-controls` while the list is open. This is what a native select is in
|
|
86
|
+
the accessibility tree.
|
|
87
|
+
- The name of the trigger is `Select.Label` and `Select.Value`, in that order: a screen reader
|
|
88
|
+
announces "Fruit, Apple, combo box". An `aria-labelledby` on the root replaces the label, and an
|
|
89
|
+
`aria-label` on the root is read in its place.
|
|
90
|
+
- `Select.Label` is a native `<label for>` the trigger. A click on it moves the focus to the
|
|
91
|
+
trigger. It does not open the list, the same as the label of a native select.
|
|
92
|
+
- `Select.List` has `role="listbox"` with `aria-labelledby` the trigger, and each option has
|
|
93
|
+
`aria-selected`. The list gets the DOM focus when the popover opens, on the selected option.
|
|
94
|
+
- `aria-required`, `aria-readonly` and `aria-invalid` are on the combobox, which supports all
|
|
95
|
+
three.
|
|
96
|
+
- The popover is not a dialog: it has `role="presentation"`, and the listbox is what assistive
|
|
97
|
+
technology lands on.
|
|
98
|
+
- On the closed trigger: `ArrowDown`, `Enter`, `Space` and `Alt+ArrowDown` open the list on the
|
|
99
|
+
selection. `ArrowUp` opens it on the selection, or on the last option. `Home` and `End` open
|
|
100
|
+
it on the first and on the last option. A printable character opens it on the first option
|
|
101
|
+
that starts with that character.
|
|
102
|
+
- In the open list: the arrows move the focus, `Home` and `End` jump to the bounds, `PageUp` and
|
|
103
|
+
`PageDown` move ten options, typed characters search. `Enter`, `Space` and `Alt+ArrowUp` select the
|
|
104
|
+
option and close the list. `Escape` closes it without a change. `Tab` closes it and moves the
|
|
105
|
+
focus past the trigger.
|
|
106
|
+
- The focus returns to the trigger after `Escape`, after a selection, and after a close by code.
|
|
107
|
+
After an outside press, a scroll or a `Tab`, it stays where the user put it. An outside press
|
|
108
|
+
on nothing focusable is the exception: the focus goes back to the trigger, thus the keyboard
|
|
109
|
+
can open the list again.
|
|
110
|
+
- The native control is out of the tab order and hidden from assistive technology. A form that
|
|
111
|
+
reports the validity of a `required` select focuses that control, and the root moves the focus
|
|
112
|
+
to the trigger.
|
|
113
|
+
|
|
114
|
+
## Notes
|
|
115
|
+
|
|
116
|
+
- The focus state follows `FOCUS_STATE_CONTRACT.md`. The root shows `data-focus-within` and
|
|
117
|
+
`data-focus-visible` for the trigger and the list together, and the trigger shows `data-focused`
|
|
118
|
+
and `data-focus-visible` from `Button.Root`.
|
|
119
|
+
- A second press on the selected option changes nothing, and the popover closes, the same as a
|
|
120
|
+
native select. In the multiple mode a press toggles.
|
|
121
|
+
- `onOpenChange` receives the reason of each change: `trigger-press`, `item-select`, `escape-key`,
|
|
122
|
+
`outside-press`, `focus-out`, `scroll` or `imperative-action`. A press on the trigger reports
|
|
123
|
+
`trigger-press` for the open and for the close. `details.cancel()` refuses it.
|
|
124
|
+
- The ids of `Select.Label` and `Select.Value` reach the trigger through the context, and the
|
|
125
|
+
server cannot do that: `aria-labelledby` appears at hydration. Give `aria-label` on the root as
|
|
126
|
+
well when the name must be there on the first paint.
|
|
127
|
+
- `Select.Trigger` shows `data-state`, `data-placeholder`, `data-readonly`, `data-required` and
|
|
128
|
+
`data-invalid`. `Select.Value` shows `data-placeholder`. `Select.Item` shows the attributes of
|
|
129
|
+
`ListBox.Item`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import type SelectItemIndicatorComponent from './item-indicator/select-item-indicator.svelte';
|
|
3
|
+
import type SelectItemComponent from './item/select-item.svelte';
|
|
4
|
+
import type SelectLabelComponent from './label/select-label.svelte';
|
|
5
|
+
import type SelectListComponent from './list/select-list.svelte';
|
|
6
|
+
import type SelectPopoverComponent from './popover/select-popover.svelte';
|
|
7
|
+
import type SelectRootComponent from './root/select-root.svelte';
|
|
8
|
+
import type SelectTriggerComponent from './trigger/select-trigger.svelte';
|
|
9
|
+
import type SelectValueComponent from './value/select-value.svelte';
|
|
10
|
+
export * as Select from './index.parts.js';
|
|
11
|
+
export { default as SelectRoot } from './root/select-root.svelte';
|
|
12
|
+
export { default as SelectLabel } from './label/select-label.svelte';
|
|
13
|
+
export { default as SelectTrigger } from './trigger/select-trigger.svelte';
|
|
14
|
+
export { default as SelectValue } from './value/select-value.svelte';
|
|
15
|
+
export { default as SelectPopover } from './popover/select-popover.svelte';
|
|
16
|
+
export { default as SelectList } from './list/select-list.svelte';
|
|
17
|
+
export { default as SelectItem } from './item/select-item.svelte';
|
|
18
|
+
export { default as SelectItemIndicator } from './item-indicator/select-item-indicator.svelte';
|
|
19
|
+
export type SelectRootProps = ComponentProps<typeof SelectRootComponent>;
|
|
20
|
+
export type SelectLabelProps = ComponentProps<typeof SelectLabelComponent>;
|
|
21
|
+
export type SelectTriggerProps = ComponentProps<typeof SelectTriggerComponent>;
|
|
22
|
+
export type SelectValueProps = ComponentProps<typeof SelectValueComponent>;
|
|
23
|
+
export type SelectPopoverProps = ComponentProps<typeof SelectPopoverComponent>;
|
|
24
|
+
export type SelectListProps = ComponentProps<typeof SelectListComponent>;
|
|
25
|
+
export type SelectItemProps = ComponentProps<typeof SelectItemComponent>;
|
|
26
|
+
export type SelectItemIndicatorProps = ComponentProps<typeof SelectItemIndicatorComponent>;
|
|
27
|
+
export type { SelectTriggerRenderState, SelectValueRenderState } from './types.js';
|
|
28
|
+
export { getSelectContext, setSelectContext, useSelectContext, type SelectContext, type SelectChangeReason, type SelectCloseReason, type SelectOpenChangeDetails, type SelectOpenReason, type SelectKey } from './root/context.js';
|
|
29
|
+
import * as SelectParts from './index.parts.js';
|
|
30
|
+
export default SelectParts;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Namespace export for component composition: <Select.Root>, <Select.Trigger>, etc.
|
|
2
|
+
export * as Select from './index.parts.js';
|
|
3
|
+
// Direct named exports for individual imports
|
|
4
|
+
export { default as SelectRoot } from './root/select-root.svelte';
|
|
5
|
+
export { default as SelectLabel } from './label/select-label.svelte';
|
|
6
|
+
export { default as SelectTrigger } from './trigger/select-trigger.svelte';
|
|
7
|
+
export { default as SelectValue } from './value/select-value.svelte';
|
|
8
|
+
export { default as SelectPopover } from './popover/select-popover.svelte';
|
|
9
|
+
export { default as SelectList } from './list/select-list.svelte';
|
|
10
|
+
export { default as SelectItem } from './item/select-item.svelte';
|
|
11
|
+
export { default as SelectItemIndicator } from './item-indicator/select-item-indicator.svelte';
|
|
12
|
+
// Context and types
|
|
13
|
+
export { getSelectContext, setSelectContext, useSelectContext } from './root/context.js';
|
|
14
|
+
// Default export as namespace object
|
|
15
|
+
import * as SelectParts from './index.parts.js';
|
|
16
|
+
export default SelectParts;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Root } from './root/select-root.svelte';
|
|
2
|
+
export { default as Label } from './label/select-label.svelte';
|
|
3
|
+
export { default as Trigger } from './trigger/select-trigger.svelte';
|
|
4
|
+
export { default as Value } from './value/select-value.svelte';
|
|
5
|
+
export { default as Popover } from './popover/select-popover.svelte';
|
|
6
|
+
export { default as List } from './list/select-list.svelte';
|
|
7
|
+
export { default as Item } from './item/select-item.svelte';
|
|
8
|
+
export { default as ItemIndicator } from './item-indicator/select-item-indicator.svelte';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Short alias exports for namespace usage: Select.Root, Select.Trigger, etc.
|
|
2
|
+
export { default as Root } from './root/select-root.svelte';
|
|
3
|
+
export { default as Label } from './label/select-label.svelte';
|
|
4
|
+
export { default as Trigger } from './trigger/select-trigger.svelte';
|
|
5
|
+
export { default as Value } from './value/select-value.svelte';
|
|
6
|
+
export { default as Popover } from './popover/select-popover.svelte';
|
|
7
|
+
export { default as List } from './list/select-list.svelte';
|
|
8
|
+
export { default as Item } from './item/select-item.svelte';
|
|
9
|
+
export { default as ItemIndicator } from './item-indicator/select-item-indicator.svelte';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export const SELECT_ITEM_CONTEXT_KEY = Symbol.for('select-item');
|
|
3
|
+
|
|
4
|
+
export type SelectItemContext = {
|
|
5
|
+
id: string | number;
|
|
6
|
+
};
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { setContext, untrack } from 'svelte';
|
|
11
|
+
import ListBoxItem from '../../listbox/item/listbox-item.svelte';
|
|
12
|
+
import { getSelectItemDomId, useSelectContext } from '../root/context';
|
|
13
|
+
import type { ComponentProps } from 'svelte';
|
|
14
|
+
|
|
15
|
+
type SelectItemProps = Omit<
|
|
16
|
+
ComponentProps<typeof ListBoxItem>,
|
|
17
|
+
| 'customId'
|
|
18
|
+
| 'disableFocusHandling'
|
|
19
|
+
| 'isFocusedOverride'
|
|
20
|
+
| 'isFocusVisibleOverride'
|
|
21
|
+
| 'onItemSelect'
|
|
22
|
+
| 'onResolvedTextValue'
|
|
23
|
+
| 'onItemHoverStart'
|
|
24
|
+
| 'scrollOnFocus'
|
|
25
|
+
| 'isParentDisabled'
|
|
26
|
+
| 'pressed'
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Select.Item — one option of the list.
|
|
31
|
+
*
|
|
32
|
+
* It is `ListBox.Item` with an id that is unique across selects, and it reports its text to
|
|
33
|
+
* the root, thus the trigger can show the text of the selection after the popover closes and
|
|
34
|
+
* the option leaves the DOM.
|
|
35
|
+
*/
|
|
36
|
+
let { id, textValue, ...props }: SelectItemProps = $props();
|
|
37
|
+
|
|
38
|
+
const ctx = useSelectContext('Select.Item');
|
|
39
|
+
|
|
40
|
+
setContext<SelectItemContext>(SELECT_ITEM_CONTEXT_KEY, {
|
|
41
|
+
get id() {
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const domId = $derived(getSelectItemDomId(ctx.instanceId, id));
|
|
47
|
+
|
|
48
|
+
$effect(() => {
|
|
49
|
+
const key = id;
|
|
50
|
+
const text = textValue;
|
|
51
|
+
if (text) untrack(() => ctx.registerItemLabel(key, text));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function handleResolvedTextValue(label: string) {
|
|
55
|
+
ctx.registerItemLabel(id, label);
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<ListBoxItem
|
|
60
|
+
{...props}
|
|
61
|
+
{id}
|
|
62
|
+
{textValue}
|
|
63
|
+
customId={domId}
|
|
64
|
+
scrollOnFocus={true}
|
|
65
|
+
isParentDisabled={ctx.isDisabled}
|
|
66
|
+
onResolvedTextValue={handleResolvedTextValue}
|
|
67
|
+
data-select-item="true"
|
|
68
|
+
/>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const SELECT_ITEM_CONTEXT_KEY: unique symbol;
|
|
2
|
+
export type SelectItemContext = {
|
|
3
|
+
id: string | number;
|
|
4
|
+
};
|
|
5
|
+
import ListBoxItem from '../../listbox/item/listbox-item.svelte';
|
|
6
|
+
import type { ComponentProps } from 'svelte';
|
|
7
|
+
type SelectItemProps = Omit<ComponentProps<typeof ListBoxItem>, 'customId' | 'disableFocusHandling' | 'isFocusedOverride' | 'isFocusVisibleOverride' | 'onItemSelect' | 'onResolvedTextValue' | 'onItemHoverStart' | 'scrollOnFocus' | 'isParentDisabled' | 'pressed'>;
|
|
8
|
+
declare const SelectItem: import("svelte").Component<SelectItemProps, {}, "">;
|
|
9
|
+
type SelectItem = ReturnType<typeof SelectItem>;
|
|
10
|
+
export default SelectItem;
|