@human-kit/ui 1.0.0-beta.6 → 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/autocomplete/item/autocomplete-item.svelte +10 -0
- 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/button/root/button-root.svelte +9 -0
- package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
- package/dist/checkbox/root/checkbox-root.svelte +106 -30
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
- package/dist/checkbox-group/README.md +95 -0
- package/dist/checkbox-group/index.d.ts +15 -0
- package/dist/checkbox-group/index.js +6 -0
- package/dist/checkbox-group/index.parts.d.ts +4 -0
- package/dist/checkbox-group/index.parts.js +7 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
- package/dist/checkbox-group/root/context.svelte.js +251 -0
- package/dist/checkbox-group/types.d.ts +57 -0
- package/dist/checkbox-group/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 +18 -0
- package/dist/index.js +17 -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/focus-visible.svelte.d.ts +14 -0
- package/dist/primitives/focus-visible.svelte.js +19 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/input-modality.d.ts +7 -0
- package/dist/primitives/input-modality.js +32 -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/radio-group/README.md +103 -0
- package/dist/radio-group/index.d.ts +18 -0
- package/dist/radio-group/index.js +9 -0
- package/dist/radio-group/index.parts.d.ts +4 -0
- package/dist/radio-group/index.parts.js +4 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
- package/dist/radio-group/item/context.d.ts +18 -0
- package/dist/radio-group/item/context.js +15 -0
- package/dist/radio-group/item/radio-group-item.svelte +377 -0
- package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
- package/dist/radio-group/label/radio-group-label.svelte +37 -0
- package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
- package/dist/radio-group/root/context.svelte.d.ts +57 -0
- package/dist/radio-group/root/context.svelte.js +284 -0
- package/dist/radio-group/root/radio-group-root.svelte +193 -0
- package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
- package/dist/radio-group/types.d.ts +50 -0
- package/dist/radio-group/types.js +1 -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/switch/root/switch-root.svelte +9 -0
- package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
- package/dist/table/root/table-root.svelte +29 -6
- package/dist/timepicker/input/time-picker-input.svelte +12 -4
- package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
- package/dist/toggle/root/toggle-root.svelte +28 -0
- package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
- package/dist/toggle-group/README.md +6 -4
- package/dist/toggle-group/index.d.ts +2 -0
- package/dist/toggle-group/index.parts.d.ts +1 -0
- package/dist/toggle-group/index.parts.js +4 -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 +46 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAnchorAttributes, HTMLAttributes, HTMLButtonAttributes, HTMLOlAttributes } from 'svelte/elements';
|
|
3
|
+
export type { BreadcrumbsContext } from './root/context.js';
|
|
4
|
+
export type BreadcrumbsRootProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
5
|
+
/** `Breadcrumbs.List`. */
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
/** The CSS class names of the element. */
|
|
8
|
+
class?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the landmark. Without it, the name is "Breadcrumb" in the locale of
|
|
11
|
+
* `LocaleProvider`. Give one when the page has two sets of breadcrumbs.
|
|
12
|
+
*/
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The count of items past which the middle of the trail folds behind a `Breadcrumbs.Ellipsis`.
|
|
16
|
+
* The first item and the last `maxItems - 1` stay in view. Without it, every item is in view.
|
|
17
|
+
*/
|
|
18
|
+
maxItems?: number;
|
|
19
|
+
/** True once the user unfolds the trail. Use `bind:expanded` to read it, or to fold it again. */
|
|
20
|
+
expanded?: boolean;
|
|
21
|
+
/** Called when the trail unfolds or folds. */
|
|
22
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
23
|
+
/** The `<nav>` element. Use `bind:element` to read it. */
|
|
24
|
+
element?: HTMLElement | null;
|
|
25
|
+
};
|
|
26
|
+
export type BreadcrumbsListProps = Omit<HTMLOlAttributes, 'children' | 'class' | 'role'> & {
|
|
27
|
+
/** The items. */
|
|
28
|
+
children?: Snippet;
|
|
29
|
+
/** The CSS class names of the element. */
|
|
30
|
+
class?: string;
|
|
31
|
+
/** The `<ol>` element. Use `bind:element` to read it. */
|
|
32
|
+
element?: HTMLOListElement | null;
|
|
33
|
+
};
|
|
34
|
+
export type BreadcrumbsItemProps = Omit<HTMLAttributes<HTMLLIElement>, 'children' | 'class'> & {
|
|
35
|
+
/** `Breadcrumbs.Link`, and a `Breadcrumbs.Separator` after it. */
|
|
36
|
+
children?: Snippet;
|
|
37
|
+
/** The CSS class names of the element. */
|
|
38
|
+
class?: string;
|
|
39
|
+
/** The `<li>` element. Use `bind:element` to read it. */
|
|
40
|
+
element?: HTMLLIElement | null;
|
|
41
|
+
};
|
|
42
|
+
export type BreadcrumbsLinkProps = Omit<HTMLAnchorAttributes, 'children' | 'class' | 'href' | 'aria-current' | 'aria-disabled'> & {
|
|
43
|
+
/** The text of the link. */
|
|
44
|
+
children?: Snippet;
|
|
45
|
+
/** The CSS class names of the element. */
|
|
46
|
+
class?: string;
|
|
47
|
+
/** The address of the page. Without it, the link is plain text. */
|
|
48
|
+
href?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Marks the page the user is on. The link gets `aria-current="page"`. Set it on the last
|
|
51
|
+
* item: a screen reader user then knows where the trail ends.
|
|
52
|
+
*/
|
|
53
|
+
current?: boolean;
|
|
54
|
+
/** Takes the link out of use: it keeps its text, and it loses its `href` and its tab stop. */
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
/** The `<a>` element, or the `<span>` without an `href`. Use `bind:element` to read it. */
|
|
57
|
+
element?: HTMLAnchorElement | HTMLSpanElement | null;
|
|
58
|
+
};
|
|
59
|
+
export type BreadcrumbsEllipsisProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'type' | 'aria-label'> & {
|
|
60
|
+
/** The content of the button. Three dots without children. */
|
|
61
|
+
children?: Snippet;
|
|
62
|
+
/** The CSS class names of the button. */
|
|
63
|
+
class?: string;
|
|
64
|
+
/** The CSS class names of the `<li>` around the button. */
|
|
65
|
+
itemClass?: string;
|
|
66
|
+
/** The sign after the button, such as a `Breadcrumbs.Separator`. */
|
|
67
|
+
separator?: Snippet;
|
|
68
|
+
/** The name of the button. Without it, "Show N more pages" in the locale of `LocaleProvider`. */
|
|
69
|
+
'aria-label'?: string;
|
|
70
|
+
/** The button element, while the trail is folded. Use `bind:element` to read it. */
|
|
71
|
+
element?: HTMLButtonElement | null;
|
|
72
|
+
};
|
|
73
|
+
export type BreadcrumbsSeparatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'aria-hidden'> & {
|
|
74
|
+
/** The sign between two items. A slash without children. */
|
|
75
|
+
children?: Snippet;
|
|
76
|
+
/** The CSS class names of the element. */
|
|
77
|
+
class?: string;
|
|
78
|
+
/** The `<span>` element. Use `bind:element` to read it. */
|
|
79
|
+
element?: HTMLSpanElement | null;
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
shouldShowFocusVisible,
|
|
6
6
|
trackInteractionModality
|
|
7
7
|
} from '../../primitives/input-modality';
|
|
8
|
+
import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
|
|
8
9
|
import { cn } from '../../utils/cn';
|
|
9
10
|
|
|
10
11
|
export type ButtonRenderState = {
|
|
@@ -120,6 +121,14 @@
|
|
|
120
121
|
let pressed = $state(false);
|
|
121
122
|
let focused = $state(false);
|
|
122
123
|
let focusVisible = $state(false);
|
|
124
|
+
|
|
125
|
+
// The focus ring must appear when a pointer press is followed by a key press, and the
|
|
126
|
+
// modality alone changes there — no focus event fires to re-read it.
|
|
127
|
+
watchFocusVisible({
|
|
128
|
+
isFocused: () => focused,
|
|
129
|
+
element: () => buttonRef,
|
|
130
|
+
set: (visible) => (focusVisible = visible)
|
|
131
|
+
});
|
|
123
132
|
let pressedKey: 'Enter' | 'Space' | null = $state(null);
|
|
124
133
|
let expandedPressed = $state(false);
|
|
125
134
|
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
shouldShowFocusVisible,
|
|
59
59
|
trackInteractionModality
|
|
60
60
|
} from '../../primitives/input-modality';
|
|
61
|
+
import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
|
|
61
62
|
|
|
62
63
|
type CalendarBodyCellProps = Omit<HTMLAttributes<HTMLTableCellElement>, 'children'> & {
|
|
63
64
|
date: string;
|
|
@@ -154,6 +155,12 @@
|
|
|
154
155
|
calendar.setFocusVisible(shouldShowFocusVisible(buttonElement ?? null));
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
watchFocusVisible({
|
|
159
|
+
isFocused: () => hasDomFocus,
|
|
160
|
+
element: () => buttonElement ?? null,
|
|
161
|
+
set: (visible) => calendar.setFocusVisible(visible)
|
|
162
|
+
});
|
|
163
|
+
|
|
157
164
|
function handleBlur() {
|
|
158
165
|
hasDomFocus = false;
|
|
159
166
|
isHovered = false;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { useCheckboxContext } from '../root/context';
|
|
5
5
|
|
|
6
6
|
type CheckboxIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
|
|
7
|
+
/** Keeps the indicator in the DOM even while the checkbox is unchecked. */
|
|
7
8
|
forceMount?: boolean;
|
|
8
9
|
children?: Snippet;
|
|
9
10
|
class?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
type CheckboxIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
|
|
4
|
+
/** Keeps the indicator in the DOM even while the checkbox is unchecked. */
|
|
4
5
|
forceMount?: boolean;
|
|
5
6
|
children?: Snippet;
|
|
6
7
|
class?: string;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { untrack, type Snippet } from 'svelte';
|
|
2
|
+
import { onDestroy, untrack, type Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
import {
|
|
5
5
|
shouldShowFocusVisible,
|
|
6
6
|
trackInteractionModality
|
|
7
7
|
} from '../../primitives/input-modality';
|
|
8
|
+
import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
|
|
9
|
+
import { getCheckboxGroupContext } from '../../checkbox-group/root/context.svelte';
|
|
8
10
|
import { setCheckboxContext, type CheckboxContext, type CheckboxState } from './context';
|
|
9
11
|
|
|
10
12
|
type CheckboxRootProps = Omit<
|
|
@@ -46,15 +48,20 @@
|
|
|
46
48
|
defaultIndeterminate?: boolean;
|
|
47
49
|
/** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
|
|
48
50
|
controlledIndeterminate?: boolean;
|
|
51
|
+
/** The component calls it when the user changes the checked state. */
|
|
49
52
|
onCheckedChange?: (checked: boolean) => void;
|
|
53
|
+
/** The component calls it when the user changes the indeterminate state. From the indeterminate state, the first user action makes the checkbox checked. */
|
|
50
54
|
onIndeterminateChange?: (indeterminate: boolean) => void;
|
|
51
55
|
disabled?: boolean;
|
|
52
56
|
readonly?: boolean;
|
|
53
57
|
required?: boolean;
|
|
54
58
|
children?: Snippet;
|
|
55
59
|
class?: string;
|
|
60
|
+
/** The accessible name, for when the user sees no name. */
|
|
56
61
|
'aria-label'?: string;
|
|
62
|
+
/** The id of the element that gives the checkbox its name. */
|
|
57
63
|
'aria-labelledby'?: string;
|
|
64
|
+
/** Replaces the default position in the tab order. */
|
|
58
65
|
tabindex?: number;
|
|
59
66
|
onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
|
|
60
67
|
onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
|
|
@@ -138,6 +145,13 @@
|
|
|
138
145
|
const inputId = instanceId;
|
|
139
146
|
const rootId = `${instanceId}-root`;
|
|
140
147
|
|
|
148
|
+
// Inside a `CheckboxGroup.Root` the group owns the checked state, and this checkbox becomes
|
|
149
|
+
// one entry of its `value` array. Outside one the context is undefined and every path below
|
|
150
|
+
// keeps the standalone behavior.
|
|
151
|
+
const checkboxGroup = getCheckboxGroupContext();
|
|
152
|
+
const registrationOwner = Symbol('checkbox-root');
|
|
153
|
+
let registeredValue = untrack(() => value);
|
|
154
|
+
|
|
141
155
|
const initialChecked = untrack(() => checked ?? defaultChecked);
|
|
142
156
|
const initialIndeterminate = untrack(() => indeterminate ?? defaultIndeterminate);
|
|
143
157
|
const initialState = resolveState(initialChecked, initialIndeterminate);
|
|
@@ -151,6 +165,35 @@
|
|
|
151
165
|
let rootRef: HTMLSpanElement | null = $state(null);
|
|
152
166
|
let inputRef: HTMLInputElement | null = $state(null);
|
|
153
167
|
|
|
168
|
+
// Registered while the script runs, before the element exists, so the group knows the
|
|
169
|
+
// checkbox at its first render. The effect below repeats it with the element attached,
|
|
170
|
+
// which is what gives the group its DOM order.
|
|
171
|
+
untrack(() => {
|
|
172
|
+
checkboxGroup?.registerCheckbox(registeredValue, {
|
|
173
|
+
isDisabled: disabled,
|
|
174
|
+
owner: registrationOwner
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
$effect(() => {
|
|
179
|
+
if (!checkboxGroup) return;
|
|
180
|
+
|
|
181
|
+
if (registeredValue !== value) {
|
|
182
|
+
checkboxGroup.unregisterCheckbox(registeredValue);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
registeredValue = value;
|
|
186
|
+
checkboxGroup.registerCheckbox(value, {
|
|
187
|
+
isDisabled: disabled,
|
|
188
|
+
element: rootRef,
|
|
189
|
+
owner: registrationOwner
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
onDestroy(() => {
|
|
194
|
+
checkboxGroup?.unregisterCheckbox(registeredValue);
|
|
195
|
+
});
|
|
196
|
+
|
|
154
197
|
$effect(() => {
|
|
155
198
|
element = rootRef;
|
|
156
199
|
return () => {
|
|
@@ -158,10 +201,21 @@
|
|
|
158
201
|
};
|
|
159
202
|
});
|
|
160
203
|
|
|
204
|
+
// A grouped checkbox adds the disabled and read-only state of the group to its own.
|
|
205
|
+
// `required` is NOT among them: native `required` on a checkbox demands THAT box, so
|
|
206
|
+
// spreading it would turn "at least one" into "every one". The group carries that
|
|
207
|
+
// meaning itself, with `aria-required` on its own element.
|
|
208
|
+
const renderedDisabled = $derived(
|
|
209
|
+
checkboxGroup ? checkboxGroup.isCheckboxDisabled(value) : disabled
|
|
210
|
+
);
|
|
211
|
+
const renderedReadOnly = $derived(readonly || Boolean(checkboxGroup?.isReadOnly));
|
|
212
|
+
const renderedRequired = $derived(required);
|
|
213
|
+
const renderedName = $derived(name ?? checkboxGroup?.name);
|
|
214
|
+
|
|
161
215
|
$effect(() => {
|
|
162
|
-
if (!
|
|
216
|
+
if (!renderedDisabled && !renderedReadOnly) return;
|
|
163
217
|
clearPressState();
|
|
164
|
-
if (
|
|
218
|
+
if (renderedDisabled) {
|
|
165
219
|
focusVisible = false;
|
|
166
220
|
}
|
|
167
221
|
});
|
|
@@ -171,7 +225,9 @@
|
|
|
171
225
|
// broke every `bind:checked` seeded with `false`. It is opt-in per prop instead.
|
|
172
226
|
// Write the initial state back so `bind:` parents see the resolved default. Read
|
|
173
227
|
// untracked: this is a deliberate one-time seed at init, not a reactive mirror.
|
|
174
|
-
|
|
228
|
+
// Skipped when grouped: there the group holds the checked state, and seeding the prop would
|
|
229
|
+
// report a value the group never agreed to.
|
|
230
|
+
if (!checkboxGroup && !untrack(() => controlledChecked)) {
|
|
175
231
|
checked = initialState === 'checked';
|
|
176
232
|
}
|
|
177
233
|
|
|
@@ -180,10 +236,15 @@
|
|
|
180
236
|
}
|
|
181
237
|
|
|
182
238
|
// The prop wins whenever it is supplied — that covers both `bind:` and a plain
|
|
183
|
-
// value — and the internal state only carries the fully uncontrolled case.
|
|
239
|
+
// value — and the internal state only carries the fully uncontrolled case. A group
|
|
240
|
+
// outranks all of it.
|
|
184
241
|
const currentState = $derived.by(() =>
|
|
185
242
|
resolveState(
|
|
186
|
-
|
|
243
|
+
checkboxGroup
|
|
244
|
+
? checkboxGroup.isSelected(value)
|
|
245
|
+
: controlledChecked
|
|
246
|
+
? Boolean(checked)
|
|
247
|
+
: (checked ?? checkedInternal),
|
|
187
248
|
controlledIndeterminate ? Boolean(indeterminate) : (indeterminate ?? indeterminateInternal)
|
|
188
249
|
)
|
|
189
250
|
);
|
|
@@ -192,6 +253,14 @@
|
|
|
192
253
|
const currentIndeterminate = $derived(currentState === 'indeterminate');
|
|
193
254
|
const currentUnchecked = $derived(currentState === 'unchecked');
|
|
194
255
|
|
|
256
|
+
// The focus ring must appear when a pointer press is followed by a key press, and the modality
|
|
257
|
+
// alone changes there — no focus event fires to re-read it.
|
|
258
|
+
watchFocusVisible({
|
|
259
|
+
isFocused: () => focused,
|
|
260
|
+
element: () => rootRef,
|
|
261
|
+
set: (visible) => (focusVisible = visible)
|
|
262
|
+
});
|
|
263
|
+
|
|
195
264
|
function clearPressState() {
|
|
196
265
|
pressed = false;
|
|
197
266
|
pressedKey = null;
|
|
@@ -202,8 +271,15 @@
|
|
|
202
271
|
const nextIndeterminate = nextState === 'indeterminate';
|
|
203
272
|
const previousChecked = currentChecked;
|
|
204
273
|
const previousIndeterminate = currentIndeterminate;
|
|
205
|
-
|
|
206
|
-
|
|
274
|
+
let didChangeChecked = nextChecked !== previousChecked;
|
|
275
|
+
|
|
276
|
+
if (checkboxGroup) {
|
|
277
|
+
// The group owns the checked state, so the standalone `checked` prop is not written
|
|
278
|
+
// back. The group reports the whole selection through its own `value` and `onChange`,
|
|
279
|
+
// and it answers whether it took the change — a group that refuses one must not make
|
|
280
|
+
// this checkbox announce it.
|
|
281
|
+
didChangeChecked = checkboxGroup.setValueSelected(value, nextChecked) !== null;
|
|
282
|
+
} else if (!controlledChecked) {
|
|
207
283
|
checkedInternal = nextChecked;
|
|
208
284
|
checked = nextChecked;
|
|
209
285
|
}
|
|
@@ -213,7 +289,7 @@
|
|
|
213
289
|
indeterminate = nextIndeterminate;
|
|
214
290
|
}
|
|
215
291
|
|
|
216
|
-
if (
|
|
292
|
+
if (didChangeChecked) {
|
|
217
293
|
onCheckedChange?.(nextChecked);
|
|
218
294
|
}
|
|
219
295
|
|
|
@@ -227,7 +303,7 @@
|
|
|
227
303
|
}
|
|
228
304
|
|
|
229
305
|
function setState(nextState: CheckboxState, event?: Event) {
|
|
230
|
-
if (
|
|
306
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
231
307
|
publishState(nextState, event);
|
|
232
308
|
}
|
|
233
309
|
|
|
@@ -236,7 +312,7 @@
|
|
|
236
312
|
}
|
|
237
313
|
|
|
238
314
|
function requestNativeToggle(event?: Event) {
|
|
239
|
-
if (
|
|
315
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
240
316
|
if (!inputRef) {
|
|
241
317
|
toggle(event);
|
|
242
318
|
return;
|
|
@@ -249,7 +325,7 @@
|
|
|
249
325
|
trackInteractionModality(event, rootRef);
|
|
250
326
|
|
|
251
327
|
if (event.defaultPrevented) return;
|
|
252
|
-
if (
|
|
328
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
253
329
|
event.preventDefault();
|
|
254
330
|
return;
|
|
255
331
|
}
|
|
@@ -307,7 +383,7 @@
|
|
|
307
383
|
trackInteractionModality(event, rootRef);
|
|
308
384
|
focusVisible = false;
|
|
309
385
|
|
|
310
|
-
if (
|
|
386
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
311
387
|
event.preventDefault();
|
|
312
388
|
clearPressState();
|
|
313
389
|
return;
|
|
@@ -330,7 +406,7 @@
|
|
|
330
406
|
}
|
|
331
407
|
|
|
332
408
|
function handlePointerEnter(event: PointerEvent) {
|
|
333
|
-
if (
|
|
409
|
+
if (renderedDisabled || renderedReadOnly) return;
|
|
334
410
|
|
|
335
411
|
if ((event.buttons & 1) === 1 && pressedKey === null) {
|
|
336
412
|
pressed = true;
|
|
@@ -347,7 +423,7 @@
|
|
|
347
423
|
trackInteractionModality(event, rootRef);
|
|
348
424
|
focusVisible = false;
|
|
349
425
|
|
|
350
|
-
if (
|
|
426
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
351
427
|
event.preventDefault();
|
|
352
428
|
clearPressState();
|
|
353
429
|
return;
|
|
@@ -386,7 +462,7 @@
|
|
|
386
462
|
const target = event.currentTarget;
|
|
387
463
|
if (!(target instanceof HTMLInputElement)) return;
|
|
388
464
|
|
|
389
|
-
if (
|
|
465
|
+
if (renderedDisabled || renderedReadOnly) {
|
|
390
466
|
target.checked = currentChecked;
|
|
391
467
|
target.indeterminate = currentIndeterminate;
|
|
392
468
|
return;
|
|
@@ -459,13 +535,13 @@
|
|
|
459
535
|
return currentIndeterminate;
|
|
460
536
|
},
|
|
461
537
|
get isDisabled() {
|
|
462
|
-
return
|
|
538
|
+
return renderedDisabled;
|
|
463
539
|
},
|
|
464
540
|
get isReadOnly() {
|
|
465
|
-
return
|
|
541
|
+
return renderedReadOnly;
|
|
466
542
|
},
|
|
467
543
|
get required() {
|
|
468
|
-
return
|
|
544
|
+
return renderedRequired;
|
|
469
545
|
},
|
|
470
546
|
get focused() {
|
|
471
547
|
return focused;
|
|
@@ -483,11 +559,11 @@
|
|
|
483
559
|
bind:this={rootRef}
|
|
484
560
|
id={rootId}
|
|
485
561
|
role="checkbox"
|
|
486
|
-
tabindex={
|
|
562
|
+
tabindex={renderedDisabled ? undefined : (tabindex ?? 0)}
|
|
487
563
|
aria-checked={currentIndeterminate ? 'mixed' : currentChecked ? 'true' : 'false'}
|
|
488
|
-
aria-disabled={
|
|
489
|
-
aria-readonly={
|
|
490
|
-
aria-required={
|
|
564
|
+
aria-disabled={renderedDisabled || undefined}
|
|
565
|
+
aria-readonly={renderedReadOnly || undefined}
|
|
566
|
+
aria-required={renderedRequired || undefined}
|
|
491
567
|
aria-label={ariaLabel}
|
|
492
568
|
aria-labelledby={ariaLabelledby}
|
|
493
569
|
data-checkbox-root="true"
|
|
@@ -495,9 +571,9 @@
|
|
|
495
571
|
data-unchecked={currentUnchecked || undefined}
|
|
496
572
|
data-indeterminate={currentIndeterminate || undefined}
|
|
497
573
|
data-pressed={pressed || undefined}
|
|
498
|
-
data-disabled={
|
|
499
|
-
data-readonly={
|
|
500
|
-
data-required={
|
|
574
|
+
data-disabled={renderedDisabled || undefined}
|
|
575
|
+
data-readonly={renderedReadOnly || undefined}
|
|
576
|
+
data-required={renderedRequired || undefined}
|
|
501
577
|
data-focused={focused || undefined}
|
|
502
578
|
data-focus-visible={focusVisible || undefined}
|
|
503
579
|
onclick={composeEventHandlers(onClickExternal ?? undefined, handleClick)}
|
|
@@ -522,13 +598,13 @@
|
|
|
522
598
|
id={inputId}
|
|
523
599
|
tabindex={-1}
|
|
524
600
|
type="checkbox"
|
|
525
|
-
{
|
|
601
|
+
name={renderedName}
|
|
526
602
|
{value}
|
|
527
603
|
{form}
|
|
528
604
|
checked={currentChecked}
|
|
529
|
-
{
|
|
530
|
-
{
|
|
531
|
-
{
|
|
605
|
+
disabled={renderedDisabled}
|
|
606
|
+
required={renderedRequired}
|
|
607
|
+
readonly={renderedReadOnly}
|
|
532
608
|
aria-hidden="true"
|
|
533
609
|
data-checkbox-input="true"
|
|
534
610
|
onclick={handleInputClick}
|
|
@@ -26,15 +26,20 @@ type CheckboxRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'cla
|
|
|
26
26
|
defaultIndeterminate?: boolean;
|
|
27
27
|
/** Give your own code full control of `indeterminate`. Read `controlledChecked`. */
|
|
28
28
|
controlledIndeterminate?: boolean;
|
|
29
|
+
/** The component calls it when the user changes the checked state. */
|
|
29
30
|
onCheckedChange?: (checked: boolean) => void;
|
|
31
|
+
/** The component calls it when the user changes the indeterminate state. From the indeterminate state, the first user action makes the checkbox checked. */
|
|
30
32
|
onIndeterminateChange?: (indeterminate: boolean) => void;
|
|
31
33
|
disabled?: boolean;
|
|
32
34
|
readonly?: boolean;
|
|
33
35
|
required?: boolean;
|
|
34
36
|
children?: Snippet;
|
|
35
37
|
class?: string;
|
|
38
|
+
/** The accessible name, for when the user sees no name. */
|
|
36
39
|
'aria-label'?: string;
|
|
40
|
+
/** The id of the element that gives the checkbox its name. */
|
|
37
41
|
'aria-labelledby'?: string;
|
|
42
|
+
/** Replaces the default position in the tab order. */
|
|
38
43
|
tabindex?: number;
|
|
39
44
|
onclick?: HTMLAttributes<HTMLSpanElement>['onclick'];
|
|
40
45
|
onkeydown?: HTMLAttributes<HTMLSpanElement>['onkeydown'];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# CheckboxGroup
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`CheckboxGroup` coordinates several `Checkbox.Root` boxes as one field. It holds an array value,
|
|
6
|
+
and it shares a `name` for form submission. It also spreads group-wide disabled, read-only and
|
|
7
|
+
required state, and it reports the counts a parent "select all" checkbox needs.
|
|
8
|
+
|
|
9
|
+
## Anatomy
|
|
10
|
+
|
|
11
|
+
- `CheckboxGroup.Root`
|
|
12
|
+
- `CheckboxGroup.Label`
|
|
13
|
+
- `CheckboxGroup.Item`
|
|
14
|
+
- `CheckboxGroup.Indicator`
|
|
15
|
+
|
|
16
|
+
```svelte
|
|
17
|
+
<CheckboxGroup.Root name="colors" defaultValue={['red']}>
|
|
18
|
+
<CheckboxGroup.Label>Colors</CheckboxGroup.Label>
|
|
19
|
+
<Checkbox.Root value="red">
|
|
20
|
+
<Checkbox.Indicator>x</Checkbox.Indicator>
|
|
21
|
+
Red
|
|
22
|
+
</Checkbox.Root>
|
|
23
|
+
<Checkbox.Root value="green">
|
|
24
|
+
<Checkbox.Indicator>x</Checkbox.Indicator>
|
|
25
|
+
Green
|
|
26
|
+
</Checkbox.Root>
|
|
27
|
+
</CheckboxGroup.Root>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage guidelines
|
|
31
|
+
|
|
32
|
+
- Use `bind:value` to hand the group your state, or plain `value` + `onChange` to own it
|
|
33
|
+
yourself. There is no flag to declare which: supplying `value` makes it the source of
|
|
34
|
+
truth either way, and `onChange` always reports.
|
|
35
|
+
- A parent that holds `value` and refuses a change — it sends no new value down — still sees the
|
|
36
|
+
group move. The group then goes back to the value of the parent at the next render. Refuse a
|
|
37
|
+
change with a render, and not with silence.
|
|
38
|
+
- Give the group a `name` to submit the checked values as one field. Each `Checkbox.Root` puts its
|
|
39
|
+
own `value` on a hidden input under that name, which is what a native checkbox group does.
|
|
40
|
+
- `CheckboxGroup.Item` is `Checkbox.Root` under the namespace of the group, and the two names
|
|
41
|
+
are the same component. A checkbox works on its own, thus it keeps its own name too.
|
|
42
|
+
- Every box in a group must provide a unique `value`. The default value of a checkbox is
|
|
43
|
+
`on`, so two boxes without a `value` collide and the group reports it.
|
|
44
|
+
- Read `allSelected` and `someSelected` from the context to drive a parent "select all" checkbox,
|
|
45
|
+
and call `selectAll()` or `clearAll()` from it. Keep that parent checkbox **outside** the group:
|
|
46
|
+
it commands the group and is not one of its values.
|
|
47
|
+
|
|
48
|
+
## API reference
|
|
49
|
+
|
|
50
|
+
`CheckboxGroup.Root` supports:
|
|
51
|
+
|
|
52
|
+
- `value?: string[]`
|
|
53
|
+
- `defaultValue?: string[]`
|
|
54
|
+
- `onChange?: (value: string[]) => void`
|
|
55
|
+
- `name?: string`
|
|
56
|
+
- `disabled?: boolean`
|
|
57
|
+
- `readonly?: boolean`
|
|
58
|
+
- `required?: boolean`
|
|
59
|
+
- `orientation?: 'horizontal' | 'vertical'`
|
|
60
|
+
- `context?: CheckboxGroupContext`
|
|
61
|
+
- `children?: Snippet`
|
|
62
|
+
- `...restProps: HTMLAttributes<HTMLDivElement>`
|
|
63
|
+
|
|
64
|
+
## Accessibility
|
|
65
|
+
|
|
66
|
+
- `CheckboxGroup.Root` renders `role="group"`.
|
|
67
|
+
- `required` gives `data-required` only. It marks no element with `aria-required`, because
|
|
68
|
+
`role="group"` does not support that property. It also never goes down to the boxes. Native
|
|
69
|
+
`required` on a checkbox demands that one box. It would thus turn "at least one" into
|
|
70
|
+
"every one". Put the word in the group label, and give the reason with `aria-describedby`.
|
|
71
|
+
- Provide an accessible group name with `CheckboxGroup.Label`, or with `aria-label` on the root for
|
|
72
|
+
a name the user does not see. Two labels read as one name, in the order they appear. An
|
|
73
|
+
`aria-labelledby` that the caller gives stands, thus an element of your own wins.
|
|
74
|
+
- `CheckboxGroup.Label` renders a span, and not a `<label>`: a `<label>` names one control, thus it
|
|
75
|
+
cannot name a set.
|
|
76
|
+
- The id reaches the group through the context. The server cannot do that: the group tag is
|
|
77
|
+
already written when the label registers. Thus `aria-labelledby` appears at hydration. Give
|
|
78
|
+
`aria-label` as well when the name must be there on the first paint.
|
|
79
|
+
- Every checkbox keeps its own tab stop, and `Space` toggles the focused one. The group adds no
|
|
80
|
+
arrow-key navigation. This matches the APG, React Aria and Base UI: React Aria gives each
|
|
81
|
+
checkbox of a group `tabindex="0"`, measured on its own live example. Arrow keys and one tab
|
|
82
|
+
stop for a full set belong to a radio group, which is the `radiogroup` role.
|
|
83
|
+
|
|
84
|
+
## Notes
|
|
85
|
+
|
|
86
|
+
- Grouped checkboxes ignore their standalone `checked` and `defaultChecked` props. The group holds
|
|
87
|
+
the checked state and reports it through its own `value`.
|
|
88
|
+
- A checkbox that becomes disabled keeps its place in the value. This parts with `ToggleGroup`,
|
|
89
|
+
which drops a disabled selection. A checked and disabled checkbox is a state the platform
|
|
90
|
+
supports, and dropping it would rewrite the value a form was seeded with.
|
|
91
|
+
- Removing one `Checkbox.Root` from a mounted group is a real change, and the group reports the
|
|
92
|
+
shorter value. The removal of the full group is not a change, and it reports nothing. Without
|
|
93
|
+
this rule, a move to a different screen would look like the user clearing the boxes.
|
|
94
|
+
- Values are strings only. A grouped checkbox carries its value on a native `<input>`, which stores
|
|
95
|
+
it as a string. A number would thus let `value={[1]}` miss a checkbox declared as `value="1"`.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import type CheckboxIndicatorComponent from '../checkbox/indicator/checkbox-indicator.svelte';
|
|
3
|
+
import type CheckboxRootComponent from '../checkbox/root/checkbox-root.svelte';
|
|
4
|
+
import type CheckboxGroupLabelComponent from './label/checkbox-group-label.svelte';
|
|
5
|
+
import type CheckboxGroupRootComponent from './root/checkbox-group-root.svelte';
|
|
6
|
+
export * as CheckboxGroup from './index.parts.js';
|
|
7
|
+
export { default as CheckboxGroupRoot } from './root/checkbox-group-root.svelte';
|
|
8
|
+
export { default as CheckboxGroupLabel } from './label/checkbox-group-label.svelte';
|
|
9
|
+
export type CheckboxGroupRootProps = ComponentProps<typeof CheckboxGroupRootComponent>;
|
|
10
|
+
export type CheckboxGroupLabelProps = ComponentProps<typeof CheckboxGroupLabelComponent>;
|
|
11
|
+
export type CheckboxGroupItemProps = ComponentProps<typeof CheckboxRootComponent>;
|
|
12
|
+
export type CheckboxGroupIndicatorProps = ComponentProps<typeof CheckboxIndicatorComponent>;
|
|
13
|
+
export { createCheckboxGroupContext, getCheckboxGroupContext, setCheckboxGroupContext, type CheckboxGroupContext, type CheckboxGroupOrientation, type CheckboxGroupValue, type CreateCheckboxGroupContextOptions } from './root/context.svelte';
|
|
14
|
+
import * as CheckboxGroupParts from './index.parts.js';
|
|
15
|
+
export default CheckboxGroupParts;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as CheckboxGroup from './index.parts.js';
|
|
2
|
+
export { default as CheckboxGroupRoot } from './root/checkbox-group-root.svelte';
|
|
3
|
+
export { default as CheckboxGroupLabel } from './label/checkbox-group-label.svelte';
|
|
4
|
+
export { createCheckboxGroupContext, getCheckboxGroupContext, setCheckboxGroupContext } from './root/context.svelte';
|
|
5
|
+
import * as CheckboxGroupParts from './index.parts.js';
|
|
6
|
+
export default CheckboxGroupParts;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Root } from './root/checkbox-group-root.svelte';
|
|
2
|
+
export { default as Label } from './label/checkbox-group-label.svelte';
|
|
3
|
+
export { default as Item } from '../checkbox/root/checkbox-root.svelte';
|
|
4
|
+
export { default as Indicator } from '../checkbox/indicator/checkbox-indicator.svelte';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Root } from './root/checkbox-group-root.svelte';
|
|
2
|
+
export { default as Label } from './label/checkbox-group-label.svelte';
|
|
3
|
+
// `Item` and `Indicator` are `Checkbox.Root` and `Checkbox.Indicator` under the namespace of the
|
|
4
|
+
// group. A checkbox works on its own, so it keeps its own name; this pair only gives every group
|
|
5
|
+
// in the library the same shape — `Group.Root` with `Group.Item` inside.
|
|
6
|
+
export { default as Item } from '../checkbox/root/checkbox-root.svelte';
|
|
7
|
+
export { default as Indicator } from '../checkbox/indicator/checkbox-indicator.svelte';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { CheckboxGroupLabelProps } from '../types.js';
|
|
3
|
+
import { getCheckboxGroupContext } from '../root/context.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CheckboxGroup.Label — the accessible name of the group.
|
|
7
|
+
*
|
|
8
|
+
* It registers its id with the root, which gives it to the group element as
|
|
9
|
+
* `aria-labelledby`. A bare heading beside the group leaves the group unnamed: a
|
|
10
|
+
* `role="group"` takes its name from `aria-labelledby` or `aria-label`, never from the text
|
|
11
|
+
* near it. It renders a `<span>` and not a `<label>`, because a `<label>` names one control.
|
|
12
|
+
*/
|
|
13
|
+
let {
|
|
14
|
+
children,
|
|
15
|
+
class: className = '',
|
|
16
|
+
id: idProp,
|
|
17
|
+
...restProps
|
|
18
|
+
}: CheckboxGroupLabelProps = $props();
|
|
19
|
+
|
|
20
|
+
const checkboxGroup = getCheckboxGroupContext();
|
|
21
|
+
|
|
22
|
+
if (!checkboxGroup) {
|
|
23
|
+
throw new Error('CheckboxGroup.Label must be used within CheckboxGroup.Root.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const group = checkboxGroup;
|
|
27
|
+
const generatedId = $props.id();
|
|
28
|
+
const id = $derived(idProp ?? generatedId);
|
|
29
|
+
|
|
30
|
+
// The returned unregister runs on destroy, and again whenever the id changes.
|
|
31
|
+
$effect(() => group.registerLabel(id));
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<span {...restProps} {id} class={className} data-checkbox-group-label="true">
|
|
35
|
+
{@render children?.()}
|
|
36
|
+
</span>
|