@pzerelles/headlessui-svelte 2.1.2-next.7 → 2.1.2-next.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/button/Button.svelte +54 -84
- package/dist/checkbox/Checkbox.svelte +120 -174
- package/dist/close-button/CloseButton.svelte +6 -12
- package/dist/combobox/Combobox.svelte +3 -50
- package/dist/data-interactive/DataInteractive.svelte +29 -57
- package/dist/description/Description.svelte +21 -32
- package/dist/dialog/Dialog.svelte +34 -69
- package/dist/dialog/DialogBackdrop.svelte +12 -29
- package/dist/dialog/DialogPanel.svelte +26 -49
- package/dist/dialog/DialogTitle.svelte +23 -38
- package/dist/dialog/InternalDialog.svelte +202 -263
- package/dist/field/Field.svelte +26 -49
- package/dist/fieldset/Fieldset.svelte +29 -50
- package/dist/focus-trap/FocusTrap.svelte +283 -419
- package/dist/input/Input.svelte +53 -84
- package/dist/internal/FocusSentinel.svelte +8 -16
- package/dist/internal/ForcePortalRoot.svelte +3 -7
- package/dist/internal/FormFields.svelte +20 -31
- package/dist/internal/FormResolver.svelte +15 -20
- package/dist/internal/Hidden.svelte +23 -44
- package/dist/internal/HoistFormFields.svelte +4 -7
- package/dist/internal/MainTreeProvider.svelte +36 -89
- package/dist/internal/Portal.svelte +14 -18
- package/dist/label/Label.svelte +57 -91
- package/dist/legend/Legend.svelte +3 -18
- package/dist/listbox/Listbox.svelte +396 -588
- package/dist/listbox/ListboxButton.svelte +127 -176
- package/dist/listbox/ListboxOption.svelte +125 -166
- package/dist/listbox/ListboxOptions.svelte +244 -340
- package/dist/listbox/ListboxSelectedOption.svelte +15 -38
- package/dist/menu/Menu.svelte +218 -307
- package/dist/menu/MenuButton.svelte +115 -157
- package/dist/menu/MenuHeading.svelte +14 -34
- package/dist/menu/MenuItem.svelte +107 -145
- package/dist/menu/MenuItems.svelte +224 -298
- package/dist/menu/MenuSection.svelte +9 -26
- package/dist/menu/MenuSeparator.svelte +4 -20
- package/dist/portal/InternalPortal.svelte +85 -141
- package/dist/portal/Portal.svelte +2 -5
- package/dist/portal/PortalGroup.svelte +9 -30
- package/dist/switch/Switch.svelte +132 -179
- package/dist/switch/SwitchGroup.svelte +31 -44
- package/dist/tabs/Tab.svelte +143 -195
- package/dist/tabs/TabGroup.svelte +205 -292
- package/dist/tabs/TabList.svelte +11 -31
- package/dist/tabs/TabPanel.svelte +43 -68
- package/dist/tabs/TabPanels.svelte +7 -18
- package/dist/textarea/Textarea.svelte +53 -84
- package/dist/transition/InternalTransitionChild.svelte +170 -259
- package/dist/transition/Transition.svelte +66 -96
- package/dist/transition/TransitionChild.svelte +11 -31
- package/dist/utils/ElementOrComponent.svelte +23 -44
- package/dist/utils/Generic.svelte +17 -29
- package/dist/utils/StableCollection.svelte +36 -54
- package/package.json +1 -1
|
@@ -1,151 +1,95 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (ownerDocument === null) return null
|
|
27
|
-
|
|
28
|
-
let root = ownerDocument.createElement("div")
|
|
29
|
-
root.setAttribute("id", "headlessui-portal-root")
|
|
30
|
-
return ownerDocument.body.appendChild(root)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let target = $state(initialTarget())
|
|
34
|
-
|
|
35
|
-
// Ensure the portal root is always in the DOM
|
|
36
|
-
$effect(() => {
|
|
37
|
-
if (!target) return
|
|
38
|
-
|
|
39
|
-
if (!ownerDocument?.body.contains(target)) {
|
|
40
|
-
ownerDocument?.body.appendChild(target)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
$effect(() => {
|
|
45
|
-
if (forceInRoot?.force) return
|
|
46
|
-
if (!groupTarget) return
|
|
47
|
-
target = groupTarget
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
get target() {
|
|
52
|
-
return target
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// ---
|
|
58
|
-
|
|
59
|
-
type PortalParentContext = {
|
|
60
|
-
register: (portal: HTMLElement) => () => void
|
|
61
|
-
unregister: (portal: HTMLElement) => void
|
|
62
|
-
readonly portals: HTMLElement[]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function useNestedPortals() {
|
|
66
|
-
const parent = getContext<PortalParentContext>("PortalParentContext")
|
|
67
|
-
const portals = $state<HTMLElement[]>([])
|
|
68
|
-
|
|
69
|
-
const register = (portal: HTMLElement) => {
|
|
70
|
-
portals.push(portal)
|
|
71
|
-
if (parent) parent.register(portal)
|
|
72
|
-
return () => unregister(portal)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const unregister = (portal: HTMLElement) => {
|
|
76
|
-
let idx = portals.indexOf(portal)
|
|
77
|
-
if (idx !== -1) portals.splice(idx, 1)
|
|
78
|
-
if (parent) parent.unregister(portal)
|
|
1
|
+
<script lang="ts" module>import { usePortalRoot } from "../internal/portal-force-root.svelte.js";
|
|
2
|
+
import { getOwnerDocument } from "../utils/owner.js";
|
|
3
|
+
import { getContext, onMount, setContext } from "svelte";
|
|
4
|
+
import { env } from "../utils/env.js";
|
|
5
|
+
function usePortalTarget(options) {
|
|
6
|
+
const { element } = $derived(options);
|
|
7
|
+
const forceInRoot = usePortalRoot();
|
|
8
|
+
const portalGroupContext = getContext("PortalGroupContext");
|
|
9
|
+
const { target: groupTarget } = $derived(portalGroupContext ?? {});
|
|
10
|
+
const ownerDocument = $derived(getOwnerDocument(element));
|
|
11
|
+
const initialTarget = () => {
|
|
12
|
+
if (!forceInRoot?.force && groupTarget) return groupTarget ?? null;
|
|
13
|
+
if (env.isServer) return null;
|
|
14
|
+
let existingRoot = ownerDocument?.getElementById("headlessui-portal-root");
|
|
15
|
+
if (existingRoot) return existingRoot;
|
|
16
|
+
if (ownerDocument === null) return null;
|
|
17
|
+
let root = ownerDocument.createElement("div");
|
|
18
|
+
root.setAttribute("id", "headlessui-portal-root");
|
|
19
|
+
return ownerDocument.body.appendChild(root);
|
|
20
|
+
};
|
|
21
|
+
let target = $state(initialTarget());
|
|
22
|
+
$effect(() => {
|
|
23
|
+
if (!target) return;
|
|
24
|
+
if (!ownerDocument?.body.contains(target)) {
|
|
25
|
+
ownerDocument?.body.appendChild(target);
|
|
79
26
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
27
|
+
});
|
|
28
|
+
$effect(() => {
|
|
29
|
+
if (forceInRoot?.force) return;
|
|
30
|
+
if (!groupTarget) return;
|
|
31
|
+
target = groupTarget;
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
get target() {
|
|
35
|
+
return target;
|
|
87
36
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function useNestedPortals() {
|
|
40
|
+
const parent = getContext("PortalParentContext");
|
|
41
|
+
const portals = $state([]);
|
|
42
|
+
const register = (portal) => {
|
|
43
|
+
portals.push(portal);
|
|
44
|
+
if (parent) parent.register(portal);
|
|
45
|
+
return () => unregister(portal);
|
|
46
|
+
};
|
|
47
|
+
const unregister = (portal) => {
|
|
48
|
+
let idx = portals.indexOf(portal);
|
|
49
|
+
if (idx !== -1) portals.splice(idx, 1);
|
|
50
|
+
if (parent) parent.unregister(portal);
|
|
51
|
+
};
|
|
52
|
+
const context = {
|
|
53
|
+
register,
|
|
54
|
+
unregister,
|
|
55
|
+
get portals() {
|
|
56
|
+
return portals;
|
|
105
57
|
}
|
|
106
|
-
|
|
58
|
+
};
|
|
59
|
+
setContext("PortalParentContext", context);
|
|
60
|
+
return context;
|
|
61
|
+
}
|
|
62
|
+
export const DEFAULT_PORTAL_TAG = "div";
|
|
107
63
|
</script>
|
|
108
64
|
|
|
109
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
target.
|
|
65
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
66
|
+
let { ref = $bindable(), ...theirProps } = $props();
|
|
67
|
+
const portalTarget = usePortalTarget({
|
|
68
|
+
get element() {
|
|
69
|
+
return ref ?? null;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const { target } = $derived(portalTarget);
|
|
73
|
+
const parent = getContext("PortalParentContext");
|
|
74
|
+
$effect(() => {
|
|
75
|
+
if (!target || !ref) return;
|
|
76
|
+
if (ref.parentNode !== target) {
|
|
77
|
+
ref.setAttribute("data-headlessui-portal", "");
|
|
78
|
+
target.appendChild(ref);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
onMount(() => {
|
|
82
|
+
if (parent) parent.register(ref);
|
|
83
|
+
return () => {
|
|
84
|
+
if (!target || !ref) return;
|
|
85
|
+
if (ref instanceof Node && target.contains(ref)) {
|
|
86
|
+
target.removeChild(ref);
|
|
131
87
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
onMount(() => {
|
|
135
|
-
if (parent) parent.register(ref!)
|
|
136
|
-
|
|
137
|
-
return () => {
|
|
138
|
-
if (!target || !ref) return
|
|
139
|
-
|
|
140
|
-
if (ref instanceof Node && target.contains(ref)) {
|
|
141
|
-
target.removeChild(ref)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (target.childNodes.length <= 0) {
|
|
145
|
-
target.parentElement?.removeChild(target)
|
|
146
|
-
}
|
|
88
|
+
if (target.childNodes.length <= 0) {
|
|
89
|
+
target.parentElement?.removeChild(target);
|
|
147
90
|
}
|
|
148
|
-
}
|
|
91
|
+
};
|
|
92
|
+
});
|
|
149
93
|
</script>
|
|
150
94
|
|
|
151
95
|
{#if target}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">
|
|
2
|
-
|
|
3
|
-
import InternalPortal, { DEFAULT_PORTAL_TAG, type PortalProps } from "./InternalPortal.svelte"
|
|
4
|
-
|
|
5
|
-
let { ref = $bindable(), enabled = true, ...theirProps }: PortalProps<TTag> = $props()
|
|
1
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PORTAL_TAG">import InternalPortal, { DEFAULT_PORTAL_TAG } from "./InternalPortal.svelte";
|
|
2
|
+
let { ref = $bindable(), enabled = true, ...theirProps } = $props();
|
|
6
3
|
</script>
|
|
7
4
|
|
|
8
5
|
{#if enabled}
|
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { ElementType, Props } from "../utils/types.js"
|
|
3
|
-
|
|
4
|
-
const DEFAULT_GROUP_TAG = "svelte:fragment"
|
|
5
|
-
type GroupRenderPropArg = {}
|
|
6
|
-
type GroupPropsWeControl = never
|
|
7
|
-
|
|
8
|
-
export type PortalGroupContext = {
|
|
9
|
-
readonly target: HTMLElement | null
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type PortalGroupProps<TTag extends ElementType = typeof DEFAULT_GROUP_TAG> = Props<
|
|
13
|
-
TTag,
|
|
14
|
-
GroupRenderPropArg,
|
|
15
|
-
GroupPropsWeControl,
|
|
16
|
-
{
|
|
17
|
-
target: HTMLElement | null
|
|
18
|
-
}
|
|
19
|
-
>
|
|
1
|
+
<script lang="ts" module>const DEFAULT_GROUP_TAG = "svelte:fragment";
|
|
20
2
|
</script>
|
|
21
3
|
|
|
22
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return target
|
|
31
|
-
},
|
|
32
|
-
})
|
|
4
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
5
|
+
import { setContext } from "svelte";
|
|
6
|
+
let { ref = $bindable(), target, ...theirProps } = $props();
|
|
7
|
+
setContext("PortalGroupContext", {
|
|
8
|
+
get target() {
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
33
12
|
</script>
|
|
34
13
|
|
|
35
14
|
<ElementOrComponent {theirProps} defaultTag={DEFAULT_GROUP_TAG} name="PortalGroup" bind:ref />
|
|
@@ -1,190 +1,143 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { ElementType, Props, PropsOf } from "../utils/types.js"
|
|
3
|
-
|
|
4
|
-
const DEFAULT_SWITCH_TAG = "button" as const
|
|
5
|
-
type SwitchRenderPropArg = {
|
|
6
|
-
checked: boolean
|
|
7
|
-
hover: boolean
|
|
8
|
-
focus: boolean
|
|
9
|
-
active: boolean
|
|
10
|
-
autofocus: boolean
|
|
11
|
-
changing: boolean
|
|
12
|
-
disabled: boolean
|
|
13
|
-
}
|
|
14
|
-
type SwitchPropsWeControl = "aria-checked" | "aria-describedby" | "aria-labelledby" | "role"
|
|
15
|
-
|
|
16
|
-
export type SwitchProps<TTag extends ElementType = typeof DEFAULT_SWITCH_TAG> = Props<
|
|
17
|
-
TTag,
|
|
18
|
-
SwitchRenderPropArg,
|
|
19
|
-
SwitchPropsWeControl,
|
|
20
|
-
{
|
|
21
|
-
checked?: boolean
|
|
22
|
-
defaultChecked?: boolean
|
|
23
|
-
onchange?(checked: boolean): void
|
|
24
|
-
name?: string
|
|
25
|
-
value?: string
|
|
26
|
-
form?: string
|
|
27
|
-
autofocus?: boolean
|
|
28
|
-
disabled?: boolean
|
|
29
|
-
tabIndex?: number
|
|
30
|
-
}
|
|
31
|
-
>
|
|
1
|
+
<script lang="ts" module>const DEFAULT_SWITCH_TAG = "button";
|
|
32
2
|
</script>
|
|
33
3
|
|
|
34
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_SWITCH_TAG">
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const controllable = useControllable(
|
|
77
|
-
{
|
|
78
|
-
get controlledValue() {
|
|
79
|
-
return controlledChecked
|
|
80
|
-
},
|
|
81
|
-
set controlledValue(checked) {
|
|
82
|
-
controlledChecked = checked
|
|
83
|
-
},
|
|
4
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_SWITCH_TAG">import { useId } from "../hooks/use-id.js";
|
|
5
|
+
import { useDisabled } from "../hooks/use-disabled.js";
|
|
6
|
+
import { useProvidedId } from "../internal/id.js";
|
|
7
|
+
import { getContext, tick } from "svelte";
|
|
8
|
+
import { attemptSubmit } from "../utils/form.js";
|
|
9
|
+
import { useLabelledBy } from "../label/context.svelte.js";
|
|
10
|
+
import { useDescribedBy } from "../description/context.svelte.js";
|
|
11
|
+
import { mergeProps } from "../utils/render.js";
|
|
12
|
+
import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js";
|
|
13
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
|
|
14
|
+
import { useHover } from "../hooks/use-hover.svelte.js";
|
|
15
|
+
import { useActivePress } from "../hooks/use-active-press.svelte.js";
|
|
16
|
+
import { useControllable } from "../hooks/use-controllable.svelte.js";
|
|
17
|
+
import FormFields from "../internal/FormFields.svelte";
|
|
18
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
19
|
+
const internalId = useId();
|
|
20
|
+
const providedId = useProvidedId();
|
|
21
|
+
const providedDisabled = useDisabled();
|
|
22
|
+
let {
|
|
23
|
+
ref = $bindable(),
|
|
24
|
+
id = providedId || `headlessui-switch-${internalId}`,
|
|
25
|
+
disabled: theirDisabled = false,
|
|
26
|
+
checked: controlledChecked = $bindable(),
|
|
27
|
+
defaultChecked: _defaultChecked,
|
|
28
|
+
onchange: controlledOnChange,
|
|
29
|
+
name,
|
|
30
|
+
value,
|
|
31
|
+
form,
|
|
32
|
+
autofocus = false,
|
|
33
|
+
tabIndex,
|
|
34
|
+
...theirProps
|
|
35
|
+
} = $props();
|
|
36
|
+
const disabled = $derived(providedDisabled?.value ?? theirDisabled);
|
|
37
|
+
const groupContext = getContext("GroupContext");
|
|
38
|
+
$effect(() => {
|
|
39
|
+
if (groupContext) groupContext.switchElement = ref ?? null;
|
|
40
|
+
});
|
|
41
|
+
const defaultChecked = _defaultChecked;
|
|
42
|
+
const controllable = useControllable(
|
|
43
|
+
{
|
|
44
|
+
get controlledValue() {
|
|
45
|
+
return controlledChecked;
|
|
84
46
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
47
|
+
set controlledValue(checked2) {
|
|
48
|
+
controlledChecked = checked2;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
controlledOnChange,
|
|
52
|
+
defaultChecked ?? false
|
|
53
|
+
);
|
|
54
|
+
const { value: checked, onchange } = $derived(controllable);
|
|
55
|
+
let changing = $state(false);
|
|
56
|
+
const toggle = () => {
|
|
57
|
+
changing = true;
|
|
58
|
+
onchange?.(!checked);
|
|
59
|
+
tick().then(() => {
|
|
60
|
+
changing = false;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const handleClick = (event) => {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
toggle();
|
|
66
|
+
};
|
|
67
|
+
const handleKeyUp = (event) => {
|
|
68
|
+
if (event.key === " ") {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
toggle();
|
|
71
|
+
} else if (event.key === "Enter") {
|
|
72
|
+
attemptSubmit(event.currentTarget);
|
|
104
73
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
74
|
+
};
|
|
75
|
+
const handleKeyPress = (event) => event.preventDefault();
|
|
76
|
+
let labelledBy = useLabelledBy();
|
|
77
|
+
let describedBy = useDescribedBy();
|
|
78
|
+
const { isFocusVisible: focus, focusProps } = $derived(
|
|
79
|
+
useFocusRing({
|
|
80
|
+
get autofocus() {
|
|
81
|
+
return autofocus;
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
86
|
+
useHover({
|
|
87
|
+
get disabled() {
|
|
88
|
+
return disabled;
|
|
112
89
|
}
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
const { pressed: active, pressProps } = $derived(
|
|
93
|
+
useActivePress({
|
|
94
|
+
get disabled() {
|
|
95
|
+
return disabled;
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
const slot = $derived({
|
|
100
|
+
checked,
|
|
101
|
+
disabled,
|
|
102
|
+
hover,
|
|
103
|
+
focus,
|
|
104
|
+
active,
|
|
105
|
+
autofocus,
|
|
106
|
+
changing
|
|
107
|
+
});
|
|
108
|
+
const buttonType = useResolveButtonType({
|
|
109
|
+
get props() {
|
|
110
|
+
return { type: theirProps.type, as: theirProps.as };
|
|
111
|
+
},
|
|
112
|
+
get ref() {
|
|
113
|
+
return { current: ref };
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
get disabled() {
|
|
131
|
-
return disabled
|
|
132
|
-
},
|
|
133
|
-
})
|
|
134
|
-
)
|
|
135
|
-
const { pressed: active, pressProps } = $derived(
|
|
136
|
-
useActivePress({
|
|
137
|
-
get disabled() {
|
|
138
|
-
return disabled
|
|
139
|
-
},
|
|
140
|
-
})
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
const slot = $derived({
|
|
144
|
-
checked,
|
|
145
|
-
disabled,
|
|
146
|
-
hover,
|
|
147
|
-
focus,
|
|
148
|
-
active,
|
|
149
|
-
autofocus,
|
|
150
|
-
changing,
|
|
151
|
-
} satisfies SwitchRenderPropArg)
|
|
152
|
-
|
|
153
|
-
const buttonType = useResolveButtonType({
|
|
154
|
-
get props() {
|
|
155
|
-
return { type: theirProps.type, as: theirProps.as }
|
|
156
|
-
},
|
|
157
|
-
get ref() {
|
|
158
|
-
return { current: ref }
|
|
115
|
+
});
|
|
116
|
+
const ourProps = $derived(
|
|
117
|
+
mergeProps(
|
|
118
|
+
{
|
|
119
|
+
id,
|
|
120
|
+
role: "switch",
|
|
121
|
+
type: buttonType.type,
|
|
122
|
+
tabIndex: tabIndex === -1 ? 0 : tabIndex ?? 0,
|
|
123
|
+
"aria-checked": checked,
|
|
124
|
+
"aria-labelledby": labelledBy.value,
|
|
125
|
+
"aria-describedby": describedBy.value,
|
|
126
|
+
disabled: disabled || void 0,
|
|
127
|
+
autofocus,
|
|
128
|
+
onclick: handleClick,
|
|
129
|
+
onkeyup: handleKeyUp,
|
|
130
|
+
onkeypress: handleKeyPress
|
|
159
131
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
mergeProps(
|
|
164
|
-
{
|
|
165
|
-
id,
|
|
166
|
-
role: "switch",
|
|
167
|
-
type: buttonType.type,
|
|
168
|
-
tabIndex: tabIndex === -1 ? 0 : (tabIndex ?? 0),
|
|
169
|
-
"aria-checked": checked,
|
|
170
|
-
"aria-labelledby": labelledBy.value,
|
|
171
|
-
"aria-describedby": describedBy.value,
|
|
172
|
-
disabled: disabled || undefined,
|
|
173
|
-
autofocus,
|
|
174
|
-
onclick: handleClick,
|
|
175
|
-
onkeyup: handleKeyUp,
|
|
176
|
-
onkeypress: handleKeyPress,
|
|
177
|
-
},
|
|
178
|
-
focusProps,
|
|
179
|
-
hoverProps,
|
|
180
|
-
pressProps
|
|
181
|
-
)
|
|
132
|
+
focusProps,
|
|
133
|
+
hoverProps,
|
|
134
|
+
pressProps
|
|
182
135
|
)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
136
|
+
);
|
|
137
|
+
const reset = $derived(() => {
|
|
138
|
+
if (defaultChecked === void 0) return;
|
|
139
|
+
return onchange?.(defaultChecked);
|
|
140
|
+
});
|
|
188
141
|
</script>
|
|
189
142
|
|
|
190
143
|
{#if name}
|