@pzerelles/headlessui-svelte 2.1.2-next.29 → 2.1.2-next.30
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 -173
- package/dist/checkbox/Checkbox.svelte.d.ts +1 -1
- package/dist/close-button/CloseButton.svelte +6 -12
- package/dist/combobox/Combobox.svelte +3 -50
- package/dist/data-interactive/DataInteractive.svelte +29 -55
- package/dist/description/Description.svelte +21 -31
- package/dist/dialog/Dialog.svelte +228 -320
- package/dist/dialog/DialogBackdrop.svelte +12 -29
- package/dist/dialog/DialogPanel.svelte +25 -48
- package/dist/dialog/DialogTitle.svelte +23 -38
- package/dist/field/Field.svelte +25 -47
- 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/FloatingProvider.svelte +9 -14
- package/dist/internal/FocusSentinel.svelte +8 -16
- package/dist/internal/ForcePortalRoot.svelte +3 -7
- package/dist/internal/FormFields.svelte +34 -47
- package/dist/internal/FormFieldsProvider.svelte +5 -9
- package/dist/internal/FormResolver.svelte +15 -20
- package/dist/internal/Hidden.svelte +29 -50
- package/dist/internal/MainTreeProvider.svelte +36 -89
- package/dist/internal/Portal.svelte +14 -18
- package/dist/label/Label.svelte +58 -93
- package/dist/legend/Legend.svelte +3 -12
- package/dist/listbox/Listbox.svelte +387 -525
- package/dist/listbox/Listbox.svelte.d.ts +1 -1
- package/dist/listbox/ListboxButton.svelte +127 -173
- package/dist/listbox/ListboxOption.svelte +129 -170
- package/dist/listbox/ListboxOptions.svelte +304 -400
- package/dist/listbox/ListboxSelectedOption.svelte +15 -38
- package/dist/menu/Menu.svelte +51 -78
- package/dist/menu/MenuButton.svelte +117 -157
- package/dist/menu/MenuHeading.svelte +14 -32
- package/dist/menu/MenuItem.svelte +107 -142
- package/dist/menu/MenuItems.svelte +229 -301
- package/dist/menu/MenuSection.svelte +9 -24
- package/dist/menu/MenuSeparator.svelte +4 -17
- package/dist/popover/Popover.svelte +150 -216
- package/dist/popover/PopoverBackdrop.svelte +41 -67
- package/dist/popover/PopoverButton.svelte +212 -292
- package/dist/popover/PopoverGroup.svelte +35 -62
- package/dist/popover/PopoverPanel.svelte +229 -311
- package/dist/portal/InternalPortal.svelte +85 -141
- package/dist/portal/Portal.svelte +2 -5
- package/dist/portal/PortalGroup.svelte +9 -30
- package/dist/select/Select.svelte +68 -98
- package/dist/switch/Switch.svelte +132 -179
- package/dist/switch/SwitchGroup.svelte +31 -44
- package/dist/tabs/Tab.svelte +142 -194
- package/dist/tabs/TabGroup.svelte +56 -86
- package/dist/tabs/TabGroup.svelte.d.ts +1 -1
- package/dist/tabs/TabList.svelte +11 -31
- package/dist/tabs/TabPanel.svelte +42 -67
- 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/DisabledProvider.svelte +3 -7
- package/dist/utils/ElementOrComponent.svelte +23 -43
- package/dist/utils/Generic.svelte +16 -27
- package/dist/utils/StableCollection.svelte +36 -54
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +12 -27
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +44 -88
- package/package.json +4 -4
|
@@ -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 "../utils/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.current ?? 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}
|
|
@@ -1,50 +1,37 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { ElementType, Props } from "../utils/types.js"
|
|
3
|
-
|
|
4
|
-
const DEFAULT_GROUP_TAG = "svelte:fragment"
|
|
5
|
-
|
|
6
|
-
export type SwitchGroupProps<TTag extends ElementType = typeof DEFAULT_GROUP_TAG> = Props<TTag>
|
|
7
|
-
|
|
8
|
-
export type GroupContext = {
|
|
9
|
-
switchElement: HTMLElement | null
|
|
10
|
-
}
|
|
1
|
+
<script lang="ts" module>const DEFAULT_GROUP_TAG = "svelte:fragment";
|
|
11
2
|
</script>
|
|
12
3
|
|
|
13
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
get htmlFor() {
|
|
24
|
-
return switchElement?.id
|
|
25
|
-
},
|
|
26
|
-
onclick: (event: MouseEvent) => {
|
|
27
|
-
if (!switchElement) return
|
|
28
|
-
if (event.currentTarget instanceof HTMLLabelElement) {
|
|
29
|
-
event.preventDefault()
|
|
30
|
-
}
|
|
31
|
-
switchElement.click()
|
|
32
|
-
switchElement.focus({ preventScroll: true })
|
|
33
|
-
},
|
|
4
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">import { setContext } from "svelte";
|
|
5
|
+
import { useLabels } from "../label/context.svelte.js";
|
|
6
|
+
import { useDescriptions } from "../description/context.svelte.js";
|
|
7
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
8
|
+
let switchElement = $state(null);
|
|
9
|
+
useLabels({
|
|
10
|
+
name: "SwitchGroup",
|
|
11
|
+
props: {
|
|
12
|
+
get htmlFor() {
|
|
13
|
+
return switchElement?.id;
|
|
34
14
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
onclick: (event) => {
|
|
16
|
+
if (!switchElement) return;
|
|
17
|
+
if (event.currentTarget instanceof HTMLLabelElement) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
}
|
|
20
|
+
switchElement.click();
|
|
21
|
+
switchElement.focus({ preventScroll: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
useDescriptions();
|
|
26
|
+
setContext("GroupContext", {
|
|
27
|
+
get switchElement() {
|
|
28
|
+
return switchElement;
|
|
29
|
+
},
|
|
30
|
+
set switchElement(element) {
|
|
31
|
+
switchElement = element;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
let { ref = $bindable(), ...theirProps } = $props();
|
|
48
35
|
</script>
|
|
49
36
|
|
|
50
37
|
<ElementOrComponent {theirProps} defaultTag={DEFAULT_GROUP_TAG} name="SwitchGroup" bind:ref />
|