@pzerelles/headlessui-svelte 2.1.2-next.3 → 2.1.2-next.5
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 +84 -54
- package/dist/checkbox/Checkbox.svelte +174 -120
- package/dist/close-button/CloseButton.svelte +12 -6
- package/dist/combobox/Combobox.svelte +50 -3
- package/dist/data-interactive/DataInteractive.svelte +57 -29
- package/dist/description/Description.svelte +32 -21
- package/dist/dialog/Dialog.svelte +69 -34
- package/dist/dialog/DialogBackdrop.svelte +29 -12
- package/dist/dialog/DialogPanel.svelte +49 -26
- package/dist/dialog/DialogTitle.svelte +38 -23
- package/dist/dialog/InternalDialog.svelte +263 -202
- package/dist/field/Field.svelte +49 -26
- package/dist/fieldset/Fieldset.svelte +50 -29
- package/dist/focus-trap/FocusTrap.svelte +419 -290
- package/dist/focus-trap/FocusTrap.svelte.d.ts +2 -14
- package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
- package/dist/focus-trap/FocusTrapFeatures.js +15 -0
- package/dist/input/Input.svelte +85 -53
- package/dist/internal/FocusSentinel.svelte +16 -8
- package/dist/internal/ForcePortalRoot.svelte +7 -3
- package/dist/internal/FormFields.svelte +31 -20
- package/dist/internal/FormResolver.svelte +20 -15
- package/dist/internal/Hidden.svelte +44 -27
- package/dist/internal/Hidden.svelte.d.ts +2 -5
- package/dist/internal/HiddenFeatures.d.ts +5 -0
- package/dist/internal/HiddenFeatures.js +9 -0
- package/dist/internal/HoistFormFields.svelte +7 -4
- package/dist/internal/MainTreeProvider.svelte +89 -36
- package/dist/internal/Portal.svelte +18 -14
- package/dist/label/Label.svelte +91 -57
- package/dist/legend/Legend.svelte +18 -3
- package/dist/listbox/Listbox.svelte +588 -409
- package/dist/listbox/Listbox.svelte.d.ts +2 -12
- package/dist/listbox/ListboxButton.svelte +176 -127
- package/dist/listbox/ListboxOption.svelte +166 -125
- package/dist/listbox/ListboxOptions.svelte +340 -244
- package/dist/listbox/ListboxSelectedOption.svelte +38 -15
- package/dist/listbox/ListboxStates.d.ts +12 -0
- package/dist/listbox/ListboxStates.js +15 -0
- package/dist/menu/Menu.svelte +307 -218
- package/dist/menu/MenuButton.svelte +157 -115
- package/dist/menu/MenuHeading.svelte +34 -14
- package/dist/menu/MenuItem.svelte +145 -107
- package/dist/menu/MenuItems.svelte +298 -224
- package/dist/menu/MenuSection.svelte +26 -9
- package/dist/menu/MenuSeparator.svelte +20 -4
- package/dist/portal/InternalPortal.svelte +141 -85
- package/dist/portal/Portal.svelte +5 -2
- package/dist/portal/PortalGroup.svelte +30 -9
- package/dist/switch/Switch.svelte +179 -122
- package/dist/switch/Switch.svelte.d.ts +4 -4
- package/dist/switch/SwitchGroup.svelte +44 -31
- package/dist/tabs/Tab.svelte +195 -143
- package/dist/tabs/TabGroup.svelte +292 -205
- package/dist/tabs/TabList.svelte +31 -11
- package/dist/tabs/TabPanel.svelte +68 -43
- package/dist/tabs/TabPanels.svelte +18 -7
- package/dist/textarea/Textarea.svelte +83 -53
- package/dist/transition/InternalTransitionChild.svelte +259 -170
- package/dist/transition/Transition.svelte +96 -66
- package/dist/transition/TransitionChild.svelte +31 -11
- package/dist/utils/ElementOrComponent.svelte +44 -23
- package/dist/utils/Generic.svelte +29 -17
- package/dist/utils/StableCollection.svelte +54 -36
- package/package.json +10 -10
|
@@ -1,61 +1,91 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Props, ElementType } from "../utils/types.js"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
const { pressed: active, pressProps } = $derived(
|
|
27
|
-
useActivePress({
|
|
28
|
-
get disabled() {
|
|
29
|
-
return disabled;
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
);
|
|
33
|
-
const { isFocusVisible: focus, focusProps } = $derived(
|
|
34
|
-
useFocusRing({
|
|
35
|
-
get autofocus() {
|
|
36
|
-
return autofocus;
|
|
4
|
+
const DEFAULT_BUTTON_TAG = "button" as const
|
|
5
|
+
|
|
6
|
+
type ButtonRenderPropArg = {
|
|
7
|
+
disabled: boolean
|
|
8
|
+
hover: boolean
|
|
9
|
+
focus: boolean
|
|
10
|
+
active: boolean
|
|
11
|
+
autofocus: boolean
|
|
12
|
+
}
|
|
13
|
+
type ButtonPropsWeControl = never
|
|
14
|
+
|
|
15
|
+
export type ButtonProps<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG> = Props<
|
|
16
|
+
TTag,
|
|
17
|
+
ButtonRenderPropArg,
|
|
18
|
+
ButtonPropsWeControl,
|
|
19
|
+
{
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
autofocus?: boolean
|
|
22
|
+
type?: "button" | "submit" | "reset"
|
|
37
23
|
}
|
|
24
|
+
>
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BUTTON_TAG">
|
|
28
|
+
import { useActivePress } from "../hooks/use-active-press.svelte.js"
|
|
29
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
|
|
30
|
+
import { useDisabled } from "../hooks/use-disabled.js"
|
|
31
|
+
import { useHover } from "../hooks/use-hover.svelte.js"
|
|
32
|
+
import { mergeProps } from "../utils/render.js"
|
|
33
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
34
|
+
|
|
35
|
+
const providedDisabled = useDisabled()
|
|
36
|
+
|
|
37
|
+
let {
|
|
38
|
+
ref = $bindable(),
|
|
39
|
+
disabled: ownDisabled = false,
|
|
40
|
+
autofocus = false,
|
|
41
|
+
type = "button",
|
|
42
|
+
...theirProps
|
|
43
|
+
}: { as?: TTag } & ButtonProps<TTag> = $props()
|
|
44
|
+
|
|
45
|
+
const disabled = $derived(providedDisabled.value || ownDisabled)
|
|
46
|
+
|
|
47
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
48
|
+
useHover({
|
|
49
|
+
get disabled() {
|
|
50
|
+
return disabled
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
)
|
|
54
|
+
const { pressed: active, pressProps } = $derived(
|
|
55
|
+
useActivePress({
|
|
56
|
+
get disabled() {
|
|
57
|
+
return disabled
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
const { isFocusVisible: focus, focusProps } = $derived(
|
|
62
|
+
useFocusRing({
|
|
63
|
+
get autofocus() {
|
|
64
|
+
return autofocus
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const slot = $derived({
|
|
70
|
+
disabled,
|
|
71
|
+
hover,
|
|
72
|
+
focus,
|
|
73
|
+
active,
|
|
74
|
+
autofocus,
|
|
38
75
|
})
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
disabled: disabled || void 0,
|
|
52
|
-
autofocus
|
|
53
|
-
},
|
|
54
|
-
focusProps,
|
|
55
|
-
hoverProps,
|
|
56
|
-
pressProps
|
|
76
|
+
|
|
77
|
+
const ourProps = $derived(
|
|
78
|
+
mergeProps(
|
|
79
|
+
{
|
|
80
|
+
type,
|
|
81
|
+
disabled: disabled || undefined,
|
|
82
|
+
autofocus,
|
|
83
|
+
},
|
|
84
|
+
focusProps,
|
|
85
|
+
hoverProps,
|
|
86
|
+
pressProps
|
|
87
|
+
)
|
|
57
88
|
)
|
|
58
|
-
);
|
|
59
89
|
</script>
|
|
60
90
|
|
|
61
91
|
<ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_BUTTON_TAG} name="Button" bind:ref />
|
|
@@ -1,129 +1,183 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ElementType, Props } from "../utils/types.js"
|
|
3
|
+
|
|
4
|
+
let DEFAULT_CHECKBOX_TAG = "span" as const
|
|
5
|
+
type CheckboxRenderPropArg = {
|
|
6
|
+
checked: boolean
|
|
7
|
+
changing: boolean
|
|
8
|
+
focus: boolean
|
|
9
|
+
active: boolean
|
|
10
|
+
hover: boolean
|
|
11
|
+
autofocus: boolean
|
|
12
|
+
disabled: boolean
|
|
13
|
+
indeterminate: boolean
|
|
14
|
+
}
|
|
15
|
+
type CheckboxPropsWeControl =
|
|
16
|
+
| "aria-checked"
|
|
17
|
+
| "aria-describedby"
|
|
18
|
+
| "aria-disabled"
|
|
19
|
+
| "aria-labelledby"
|
|
20
|
+
| "role"
|
|
21
|
+
| "tabIndex"
|
|
22
|
+
|
|
23
|
+
export type CheckboxProps<TTag extends ElementType = typeof DEFAULT_CHECKBOX_TAG, TType = string> = Props<
|
|
24
|
+
TTag,
|
|
25
|
+
CheckboxRenderPropArg,
|
|
26
|
+
CheckboxPropsWeControl,
|
|
27
|
+
{
|
|
28
|
+
id?: string
|
|
29
|
+
value?: TType
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
indeterminate?: boolean
|
|
32
|
+
|
|
33
|
+
checked?: boolean
|
|
34
|
+
defaultChecked?: boolean
|
|
35
|
+
autofocus?: boolean
|
|
36
|
+
form?: string
|
|
37
|
+
name?: string
|
|
38
|
+
onchange?: (checked: boolean) => void
|
|
39
|
+
}
|
|
40
|
+
>
|
|
2
41
|
</script>
|
|
3
42
|
|
|
4
|
-
<script lang="ts" generics="TType, TTag extends ElementType = typeof DEFAULT_CHECKBOX_TAG">
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
<script lang="ts" generics="TType, TTag extends ElementType = typeof DEFAULT_CHECKBOX_TAG">
|
|
44
|
+
import { tick } from "svelte"
|
|
45
|
+
import { attemptSubmit } from "../utils/form.js"
|
|
46
|
+
import { getIdContext, htmlid } from "../utils/id.js"
|
|
47
|
+
import { useActivePress } from "../hooks/use-active-press.svelte.js"
|
|
48
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
|
|
49
|
+
import FormFields from "../internal/FormFields.svelte"
|
|
50
|
+
import { useDisabled } from "../hooks/use-disabled.js"
|
|
51
|
+
import { useLabelledBy } from "../label/context.svelte.js"
|
|
52
|
+
import { useDescribedBy } from "../description/context.svelte.js"
|
|
53
|
+
import { useHover } from "../hooks/use-hover.svelte.js"
|
|
54
|
+
import { mergeProps } from "../utils/render.js"
|
|
55
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
56
|
+
import { useControllable } from "../hooks/use-controllable.svelte.js"
|
|
57
|
+
|
|
58
|
+
const internalId = htmlid()
|
|
59
|
+
const providedId = getIdContext()
|
|
60
|
+
const providedDisabled = useDisabled()
|
|
61
|
+
|
|
62
|
+
let {
|
|
63
|
+
ref = $bindable(),
|
|
64
|
+
id = providedId || `headlessui-checkbox-${internalId}`,
|
|
65
|
+
disabled: theirDisabled = false,
|
|
66
|
+
autofocus = false,
|
|
67
|
+
checked: controlledChecked = $bindable(),
|
|
68
|
+
defaultChecked: _defaultChecked,
|
|
69
|
+
onchange: controlledOnChange,
|
|
70
|
+
name,
|
|
71
|
+
value,
|
|
72
|
+
form,
|
|
73
|
+
indeterminate = false,
|
|
74
|
+
...theirProps
|
|
75
|
+
}: { as?: TTag } & CheckboxProps<TTag, TType> = $props()
|
|
76
|
+
|
|
77
|
+
const defaultChecked = _defaultChecked
|
|
78
|
+
const controllable = useControllable(
|
|
79
|
+
{
|
|
80
|
+
get controlledValue() {
|
|
81
|
+
return controlledChecked
|
|
82
|
+
},
|
|
83
|
+
set controlledValue(checked) {
|
|
84
|
+
controlledChecked = checked
|
|
85
|
+
},
|
|
39
86
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
87
|
+
controlledOnChange,
|
|
88
|
+
defaultChecked ?? false
|
|
89
|
+
)
|
|
90
|
+
const { value: checked, onchange } = $derived(controllable)
|
|
91
|
+
|
|
92
|
+
const disabled = $derived(providedDisabled?.value ?? theirDisabled)
|
|
93
|
+
|
|
94
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
95
|
+
useHover({
|
|
96
|
+
get disabled() {
|
|
97
|
+
return disabled
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
)
|
|
101
|
+
const { pressed: active, pressProps } = $derived(
|
|
102
|
+
useActivePress({
|
|
103
|
+
get disabled() {
|
|
104
|
+
return disabled
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
)
|
|
108
|
+
const { isFocusVisible: focus, focusProps } = $derived(
|
|
109
|
+
useFocusRing({
|
|
110
|
+
get autofocus() {
|
|
111
|
+
return autofocus
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const labelledBy = useLabelledBy()
|
|
117
|
+
const describedBy = useDescribedBy()
|
|
118
|
+
|
|
119
|
+
let changing = $state(false)
|
|
120
|
+
|
|
121
|
+
const toggle = () => {
|
|
122
|
+
changing = true
|
|
123
|
+
onchange?.(!checked)
|
|
124
|
+
tick().then(() => {
|
|
125
|
+
changing = false
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const handleClick = (event: MouseEvent) => {
|
|
130
|
+
if (disabled) return event.preventDefault()
|
|
131
|
+
event.preventDefault()
|
|
132
|
+
toggle()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const handleKeyUp = (event: KeyboardEvent) => {
|
|
136
|
+
if (event.key === " ") {
|
|
137
|
+
event.preventDefault()
|
|
138
|
+
toggle()
|
|
139
|
+
} else if (event.key === "Enter") {
|
|
140
|
+
if (event.currentTarget) attemptSubmit(event.currentTarget as HTMLElement)
|
|
67
141
|
}
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
const labelledBy = useLabelledBy();
|
|
71
|
-
const describedBy = useDescribedBy();
|
|
72
|
-
let changing = $state(false);
|
|
73
|
-
const toggle = () => {
|
|
74
|
-
changing = true;
|
|
75
|
-
onchange?.(!checked);
|
|
76
|
-
tick().then(() => {
|
|
77
|
-
changing = false;
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const handleClick = (event) => {
|
|
81
|
-
if (disabled) return event.preventDefault();
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
toggle();
|
|
84
|
-
};
|
|
85
|
-
const handleKeyUp = (event) => {
|
|
86
|
-
if (event.key === " ") {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
toggle();
|
|
89
|
-
} else if (event.key === "Enter") {
|
|
90
|
-
if (event.currentTarget) attemptSubmit(event.currentTarget);
|
|
91
142
|
}
|
|
92
|
-
|
|
93
|
-
const handleKeyPress = (event) => event.preventDefault()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
143
|
+
|
|
144
|
+
const handleKeyPress = (event: KeyboardEvent) => event.preventDefault()
|
|
145
|
+
|
|
146
|
+
const slot = $derived({
|
|
147
|
+
checked,
|
|
148
|
+
changing,
|
|
149
|
+
focus,
|
|
150
|
+
active,
|
|
151
|
+
hover,
|
|
152
|
+
autofocus: autofocus ?? false,
|
|
153
|
+
disabled,
|
|
154
|
+
indeterminate,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const ourProps = $derived(
|
|
158
|
+
mergeProps(
|
|
159
|
+
{
|
|
160
|
+
id,
|
|
161
|
+
role: "checkbox",
|
|
162
|
+
"aria-checked": indeterminate ? ("mixed" as "mixed") : checked ? true : false,
|
|
163
|
+
"aria-labelledby": labelledBy.value,
|
|
164
|
+
"aria-describedby": describedBy.value,
|
|
165
|
+
"aria-disabled": disabled ? true : undefined,
|
|
166
|
+
tabindex: disabled ? undefined : 0,
|
|
167
|
+
onkeyup: disabled ? undefined : handleKeyUp,
|
|
168
|
+
onkeypress: disabled ? undefined : handleKeyPress,
|
|
169
|
+
onclick: disabled ? undefined : handleClick,
|
|
170
|
+
},
|
|
171
|
+
focusProps,
|
|
172
|
+
hoverProps,
|
|
173
|
+
pressProps
|
|
174
|
+
)
|
|
121
175
|
)
|
|
122
|
-
|
|
123
|
-
const reset = $derived(() => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
176
|
+
|
|
177
|
+
const reset = $derived(() => {
|
|
178
|
+
if (defaultChecked === undefined) return
|
|
179
|
+
return onchange?.(defaultChecked)
|
|
180
|
+
})
|
|
127
181
|
</script>
|
|
128
182
|
|
|
129
183
|
{#if name}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import Button, { type ButtonProps } from "../button/Button.svelte"
|
|
3
|
+
import { useClose } from "../internal/close-provider.js"
|
|
4
|
+
import type { ElementType } from "../utils/types.js"
|
|
5
|
+
|
|
6
|
+
let DEFAULT_BUTTON_TAG = "button" as const
|
|
7
|
+
|
|
8
|
+
export type CloseButtonProps<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG> = ButtonProps<TTag>
|
|
4
9
|
</script>
|
|
5
10
|
|
|
6
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BUTTON_TAG">
|
|
7
|
-
const
|
|
8
|
-
|
|
11
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BUTTON_TAG">
|
|
12
|
+
const closeContext = useClose()
|
|
13
|
+
const close = $derived(closeContext?.close)
|
|
14
|
+
let { ...props }: { as?: TTag } & CloseButtonProps<TTag> = $props()
|
|
9
15
|
</script>
|
|
10
16
|
|
|
11
17
|
<Button onclick={close} {...props} />
|
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ElementType, EnsureArray, Props } from "../utils/types.js"
|
|
3
|
+
import type { ByComparator } from "../hooks/use-by-comparator.js"
|
|
4
|
+
|
|
5
|
+
const DEFAULT_COMBOBOX_TAG = "svelte:fragment" as const
|
|
6
|
+
type ComboboxRenderPropArg<TValue, TActive = TValue> = {
|
|
7
|
+
open: boolean
|
|
8
|
+
disabled: boolean
|
|
9
|
+
activeIndex: number | null
|
|
10
|
+
activeOption: TActive | null
|
|
11
|
+
value: TValue
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type CheckboxProps<
|
|
15
|
+
TValue,
|
|
16
|
+
TMultiple extends boolean | undefined,
|
|
17
|
+
TTag extends ElementType = typeof DEFAULT_COMBOBOX_TAG,
|
|
18
|
+
> = Props<
|
|
19
|
+
TTag,
|
|
20
|
+
ComboboxRenderPropArg<NoInfer<TValue>>,
|
|
21
|
+
"value" | "defaultValue" | "multiple" | "onChange" | "by",
|
|
22
|
+
{
|
|
23
|
+
value?: TMultiple extends true ? EnsureArray<TValue> : TValue
|
|
24
|
+
defaultValue?: TMultiple extends true ? EnsureArray<NoInfer<TValue>> : NoInfer<TValue>
|
|
25
|
+
|
|
26
|
+
onChange?(value: TMultiple extends true ? EnsureArray<NoInfer<TValue>> : NoInfer<TValue> | null): void
|
|
27
|
+
by?: ByComparator<TMultiple extends true ? EnsureArray<NoInfer<TValue>>[number] : NoInfer<TValue>>
|
|
28
|
+
|
|
29
|
+
/** @deprecated The `<Combobox />` is now nullable default */
|
|
30
|
+
nullable?: boolean
|
|
31
|
+
|
|
32
|
+
multiple?: TMultiple
|
|
33
|
+
disabled?: boolean
|
|
34
|
+
form?: string
|
|
35
|
+
name?: string
|
|
36
|
+
immediate?: boolean
|
|
37
|
+
virtual?: {
|
|
38
|
+
options: NoInfer<TValue>[]
|
|
39
|
+
disabled?: (value: NoInfer<TValue>) => boolean
|
|
40
|
+
} | null
|
|
41
|
+
|
|
42
|
+
onclose?(): void
|
|
43
|
+
|
|
44
|
+
__demoMode?: boolean
|
|
45
|
+
}
|
|
46
|
+
>
|
|
2
47
|
</script>
|
|
3
48
|
|
|
4
|
-
<script lang="ts" generics="TType, TTag extends ElementType = typeof DEFAULT_COMBOBOX_TAG">
|
|
5
|
-
|
|
49
|
+
<script lang="ts" generics="TType, TTag extends ElementType = typeof DEFAULT_COMBOBOX_TAG">
|
|
50
|
+
import { useDisabled } from "../hooks/use-disabled.js"
|
|
51
|
+
|
|
52
|
+
const providedDisabled = useDisabled()
|
|
6
53
|
</script>
|
|
@@ -1,34 +1,62 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Props, ElementType } from "../utils/types.js"
|
|
3
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
|
|
4
|
+
import { useActivePress } from "../hooks/use-active-press.svelte.js"
|
|
5
|
+
import type { Snippet } from "svelte"
|
|
6
|
+
import { useHover } from "../hooks/use-hover.svelte.js"
|
|
7
|
+
import { mergeProps } from "../utils/render.js"
|
|
8
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DATA_INTERACTIVE_TAG = "svelte:fragment" as const
|
|
11
|
+
|
|
12
|
+
type DataInteractiveRenderPropArg = {
|
|
13
|
+
hover: boolean
|
|
14
|
+
focus: boolean
|
|
15
|
+
active: boolean
|
|
16
|
+
}
|
|
17
|
+
type DataInteractivePropsWeControl = never
|
|
18
|
+
|
|
19
|
+
export type DataInteractiveProps<TTag extends ElementType = typeof DEFAULT_DATA_INTERACTIVE_TAG> = Props<
|
|
20
|
+
TTag,
|
|
21
|
+
DataInteractiveRenderPropArg,
|
|
22
|
+
DataInteractivePropsWeControl,
|
|
23
|
+
{}
|
|
24
|
+
>
|
|
25
|
+
|
|
26
|
+
export type DataInteractiveChildren = Snippet<[DataInteractiveRenderPropArg]>
|
|
7
27
|
</script>
|
|
8
28
|
|
|
9
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DATA_INTERACTIVE_TAG">
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
29
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DATA_INTERACTIVE_TAG">
|
|
30
|
+
let { ref = $bindable(), ...theirProps }: { as?: TTag } & DataInteractiveProps<TTag> = $props()
|
|
31
|
+
|
|
32
|
+
// Ideally we can use a `disabled` prop, but that would depend on the props of the child element
|
|
33
|
+
// and we don't have access to that in this component.
|
|
34
|
+
|
|
35
|
+
const disabled = false
|
|
36
|
+
|
|
37
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
38
|
+
useHover({
|
|
39
|
+
get disabled() {
|
|
40
|
+
return disabled
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
const { pressed: active, pressProps } = $derived(
|
|
45
|
+
useActivePress({
|
|
46
|
+
get disabled() {
|
|
47
|
+
return disabled
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
const { isFocusVisible: focus, focusProps } = $derived(useFocusRing())
|
|
52
|
+
|
|
53
|
+
const slot = $derived({
|
|
54
|
+
hover,
|
|
55
|
+
focus,
|
|
56
|
+
active,
|
|
57
|
+
} satisfies DataInteractiveRenderPropArg)
|
|
58
|
+
|
|
59
|
+
const ourProps = $derived(mergeProps(focusProps, hoverProps, pressProps))
|
|
32
60
|
</script>
|
|
33
61
|
|
|
34
62
|
<ElementOrComponent
|