@pzerelles/headlessui-svelte 2.1.2-next.39 → 2.1.2-next.40
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.d.ts +1 -0
- package/dist/close-button/CloseButton.svelte.d.ts +1 -0
- package/dist/data-interactive/DataInteractive.svelte.d.ts +1 -0
- package/dist/description/Description.svelte.d.ts +1 -0
- package/dist/dialog/Dialog.svelte.d.ts +1 -0
- package/dist/dialog/DialogBackdrop.svelte.d.ts +1 -0
- package/dist/dialog/DialogPanel.svelte.d.ts +1 -0
- package/dist/dialog/DialogTitle.svelte.d.ts +1 -0
- package/dist/field/Field.svelte.d.ts +1 -0
- package/dist/fieldset/Fieldset.svelte.d.ts +1 -0
- package/dist/focus-trap/FocusTrap.svelte.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/FloatingProvider.svelte.d.ts +4 -2
- package/dist/internal/FocusSentinel.svelte.d.ts +4 -2
- package/dist/internal/ForcePortalRoot.svelte.d.ts +4 -2
- package/dist/internal/FormFields.svelte.d.ts +4 -2
- package/dist/internal/FormFieldsProvider.svelte.d.ts +4 -2
- package/dist/internal/FormResolver.svelte.d.ts +4 -2
- package/dist/internal/Hidden.svelte.d.ts +1 -0
- package/dist/internal/MainTreeProvider.svelte.d.ts +4 -2
- package/dist/internal/Portal.svelte.d.ts +4 -2
- package/dist/label/Label.svelte +0 -2
- package/dist/label/Label.svelte.d.ts +1 -0
- package/dist/legend/Legend.svelte.d.ts +1 -0
- package/dist/listbox/ListboxButton.svelte.d.ts +1 -0
- package/dist/listbox/ListboxOptions.svelte.d.ts +1 -0
- package/dist/listbox/ListboxSelectedOption.svelte.d.ts +1 -0
- package/dist/menu/Menu.svelte.d.ts +1 -0
- package/dist/menu/MenuButton.svelte.d.ts +1 -0
- package/dist/menu/MenuHeading.svelte.d.ts +1 -0
- package/dist/menu/MenuItem.svelte.d.ts +1 -0
- package/dist/menu/MenuItems.svelte.d.ts +1 -0
- package/dist/menu/MenuSection.svelte.d.ts +1 -0
- package/dist/menu/MenuSeparator.svelte.d.ts +1 -0
- package/dist/popover/Popover.svelte.d.ts +1 -0
- package/dist/popover/PopoverBackdrop.svelte.d.ts +1 -0
- package/dist/popover/PopoverButton.svelte.d.ts +1 -0
- package/dist/popover/PopoverGroup.svelte.d.ts +1 -0
- package/dist/popover/PopoverPanel.svelte.d.ts +1 -0
- package/dist/portal/InternalPortal.svelte.d.ts +1 -0
- package/dist/portal/Portal.svelte.d.ts +1 -0
- package/dist/portal/PortalGroup.svelte.d.ts +1 -0
- package/dist/radio-group/Radio.svelte +135 -0
- package/dist/radio-group/Radio.svelte.d.ts +35 -0
- package/dist/radio-group/RadioGroup.svelte +223 -0
- package/dist/radio-group/RadioGroup.svelte.d.ts +34 -0
- package/dist/radio-group/RadioOption.svelte +138 -0
- package/dist/radio-group/RadioOption.svelte.d.ts +37 -0
- package/dist/radio-group/contest.svelte.d.ts +30 -0
- package/dist/radio-group/contest.svelte.js +40 -0
- package/dist/radio-group/index.d.ts +3 -0
- package/dist/radio-group/index.js +3 -0
- package/dist/select/Select.svelte.d.ts +1 -0
- package/dist/switch/Switch.svelte.d.ts +1 -0
- package/dist/switch/SwitchGroup.svelte.d.ts +1 -0
- package/dist/tabs/Tab.svelte.d.ts +1 -0
- package/dist/tabs/TabGroup.svelte.d.ts +1 -0
- package/dist/tabs/TabList.svelte.d.ts +1 -0
- package/dist/tabs/TabPanel.svelte.d.ts +1 -0
- package/dist/tabs/TabPanels.svelte.d.ts +1 -0
- package/dist/transition/InternalTransitionChild.svelte.d.ts +1 -0
- package/dist/transition/Transition.svelte.d.ts +1 -0
- package/dist/transition/TransitionChild.svelte.d.ts +1 -0
- package/dist/utils/DisabledProvider.svelte.d.ts +4 -2
- package/dist/utils/StableCollection.svelte.d.ts +4 -2
- package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +1 -0
- package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +1 -0
- package/package.json +31 -31
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { useByComparator, type ByComparator } from "../hooks/use-by-comparator.js"
|
|
3
|
+
import type { Props } from "../utils/types.js"
|
|
4
|
+
|
|
5
|
+
const DEFAULT_RADIO_GROUP_TAG = "div" as const
|
|
6
|
+
|
|
7
|
+
export type RadioGroupRenderPropArg<TType> = {
|
|
8
|
+
value: TType
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type RadioGroupOwnProps<TType = string> = {
|
|
12
|
+
element?: HTMLElement
|
|
13
|
+
value?: TType
|
|
14
|
+
defaultValue?: TType
|
|
15
|
+
onchange?(value: TType): void
|
|
16
|
+
by?: ByComparator<TType>
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
form?: string
|
|
19
|
+
name?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type RadioGroupProps<TType = string> = Props<
|
|
23
|
+
typeof DEFAULT_RADIO_GROUP_TAG,
|
|
24
|
+
RadioGroupRenderPropArg<TType>,
|
|
25
|
+
RadioGroupOwnProps<TType>
|
|
26
|
+
>
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script lang="ts" generics="TType = string">
|
|
30
|
+
import { createState, type RadioGroupActionsContext, type RadioGroupDataContext } from "./contest.svelte.js"
|
|
31
|
+
import { useId } from "../hooks/use-id.js"
|
|
32
|
+
import { useDisabled } from "../hooks/use-disabled.js"
|
|
33
|
+
import { useLabelledBy } from "../label/context.svelte.js"
|
|
34
|
+
import { useDescribedBy } from "../description/context.svelte.js"
|
|
35
|
+
import { useControllable } from "../hooks/use-controllable.svelte.js"
|
|
36
|
+
import { getOwnerDocument } from "../utils/owner.js"
|
|
37
|
+
import { attemptSubmit } from "../utils/form.js"
|
|
38
|
+
import { Focus, focusIn, FocusResult } from "../utils/focus-management.js"
|
|
39
|
+
import { setContext } from "svelte"
|
|
40
|
+
import FormFields from "../internal/FormFields.svelte"
|
|
41
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
42
|
+
|
|
43
|
+
const internalId = useId()
|
|
44
|
+
const providedDisabled = useDisabled()
|
|
45
|
+
let {
|
|
46
|
+
element = $bindable(),
|
|
47
|
+
id = `headlessui-radiogroup-${internalId}`,
|
|
48
|
+
value: controlledValue,
|
|
49
|
+
form,
|
|
50
|
+
name,
|
|
51
|
+
onchange: controlledOnChange,
|
|
52
|
+
by,
|
|
53
|
+
disabled: theirDisabled = false,
|
|
54
|
+
defaultValue,
|
|
55
|
+
...theirProps
|
|
56
|
+
}: RadioGroupProps<TType> = $props()
|
|
57
|
+
|
|
58
|
+
const compare = useByComparator(by)
|
|
59
|
+
let _state = createState<TType>()
|
|
60
|
+
const options = $derived(_state.options)
|
|
61
|
+
|
|
62
|
+
const disabled = $derived(providedDisabled.current ?? theirDisabled)
|
|
63
|
+
const labelledBy = useLabelledBy()
|
|
64
|
+
const describedBy = useDescribedBy()
|
|
65
|
+
|
|
66
|
+
const controllable = useControllable<any>(
|
|
67
|
+
{
|
|
68
|
+
get controlledValue() {
|
|
69
|
+
return controlledValue
|
|
70
|
+
},
|
|
71
|
+
set controlledValue(value) {
|
|
72
|
+
controlledValue = value
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
controlledOnChange,
|
|
76
|
+
defaultValue
|
|
77
|
+
)
|
|
78
|
+
const { value, onchange } = $derived(controllable)
|
|
79
|
+
|
|
80
|
+
const firstOption = $derived(
|
|
81
|
+
options.find((option) => {
|
|
82
|
+
if (option.propsRef.disabled) return false
|
|
83
|
+
return true
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
const containsCheckedOption = $derived(options.some((option) => compare(option.propsRef.value as TType, value)))
|
|
87
|
+
|
|
88
|
+
const triggerChange = (nextValue: TType) => {
|
|
89
|
+
if (disabled) return false
|
|
90
|
+
if (compare(nextValue, value)) return false
|
|
91
|
+
let nextOption = options.find((option) => compare(option.propsRef.value as TType, nextValue))?.propsRef
|
|
92
|
+
if (nextOption?.disabled) return false
|
|
93
|
+
|
|
94
|
+
onchange?.(nextValue)
|
|
95
|
+
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
100
|
+
console.log("handleKeyDown", event, element)
|
|
101
|
+
let container = element
|
|
102
|
+
if (!container) return
|
|
103
|
+
|
|
104
|
+
let ownerDocument = getOwnerDocument(container)
|
|
105
|
+
|
|
106
|
+
let all = options
|
|
107
|
+
.filter((option) => option.propsRef.disabled === false)
|
|
108
|
+
.map((radio) => radio.element) as HTMLElement[]
|
|
109
|
+
|
|
110
|
+
switch (event.key) {
|
|
111
|
+
case "Enter":
|
|
112
|
+
attemptSubmit(event.currentTarget as HTMLElement)
|
|
113
|
+
break
|
|
114
|
+
case "ArrowLeft":
|
|
115
|
+
case "ArrowUp":
|
|
116
|
+
{
|
|
117
|
+
event.preventDefault()
|
|
118
|
+
event.stopPropagation()
|
|
119
|
+
|
|
120
|
+
let result = focusIn(all, Focus.Previous | Focus.WrapAround)
|
|
121
|
+
|
|
122
|
+
if (result === FocusResult.Success) {
|
|
123
|
+
let activeOption = options.find((option) => option.element === ownerDocument?.activeElement)
|
|
124
|
+
if (activeOption) triggerChange(activeOption.propsRef.value)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
break
|
|
128
|
+
|
|
129
|
+
case "ArrowRight":
|
|
130
|
+
case "ArrowDown":
|
|
131
|
+
{
|
|
132
|
+
event.preventDefault()
|
|
133
|
+
event.stopPropagation()
|
|
134
|
+
|
|
135
|
+
let result = focusIn(all, Focus.Next | Focus.WrapAround)
|
|
136
|
+
|
|
137
|
+
if (result === FocusResult.Success) {
|
|
138
|
+
let activeOption = options.find((option) => option.element === ownerDocument?.activeElement)
|
|
139
|
+
if (activeOption) triggerChange(activeOption.propsRef.value)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break
|
|
143
|
+
|
|
144
|
+
case " ":
|
|
145
|
+
{
|
|
146
|
+
event.preventDefault()
|
|
147
|
+
event.stopPropagation()
|
|
148
|
+
|
|
149
|
+
let activeOption = options.find((option) => option.element === ownerDocument?.activeElement)
|
|
150
|
+
if (activeOption) triggerChange(activeOption.propsRef.value)
|
|
151
|
+
}
|
|
152
|
+
break
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const dataContext: RadioGroupDataContext = {
|
|
157
|
+
get value() {
|
|
158
|
+
return value
|
|
159
|
+
},
|
|
160
|
+
get firstOption() {
|
|
161
|
+
return firstOption
|
|
162
|
+
},
|
|
163
|
+
get containsCheckedOption() {
|
|
164
|
+
return containsCheckedOption
|
|
165
|
+
},
|
|
166
|
+
get disabled() {
|
|
167
|
+
return disabled
|
|
168
|
+
},
|
|
169
|
+
get compare() {
|
|
170
|
+
return compare
|
|
171
|
+
},
|
|
172
|
+
get options() {
|
|
173
|
+
return options
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
setContext("RadioGroupDataContext", dataContext)
|
|
177
|
+
|
|
178
|
+
const actionContext: RadioGroupActionsContext<TType> = {
|
|
179
|
+
registerOption(option) {
|
|
180
|
+
_state.registerOption(option)
|
|
181
|
+
return () => {
|
|
182
|
+
_state.unregisterOption(option.id)
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
change: triggerChange,
|
|
186
|
+
}
|
|
187
|
+
setContext("RadioGroupActionsContext", actionContext)
|
|
188
|
+
|
|
189
|
+
const ourProps = $derived({
|
|
190
|
+
id,
|
|
191
|
+
role: "radiogroup",
|
|
192
|
+
"aria-labelledby": labelledBy.value,
|
|
193
|
+
"aria-describedby": describedBy.value,
|
|
194
|
+
onkeydown: handleKeyDown,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const slot = $derived({
|
|
198
|
+
value,
|
|
199
|
+
} satisfies RadioGroupRenderPropArg<TType>)
|
|
200
|
+
|
|
201
|
+
const reset = () => {
|
|
202
|
+
if (defaultValue === undefined) return
|
|
203
|
+
return triggerChange(defaultValue)
|
|
204
|
+
}
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
{#if name}
|
|
208
|
+
<FormFields
|
|
209
|
+
{disabled}
|
|
210
|
+
data={{ [name]: value || "on" }}
|
|
211
|
+
overrides={{ type: "radio", checked: value != null && value !== undefined }}
|
|
212
|
+
{form}
|
|
213
|
+
onReset={reset}
|
|
214
|
+
/>
|
|
215
|
+
{/if}
|
|
216
|
+
<ElementOrComponent
|
|
217
|
+
{ourProps}
|
|
218
|
+
{theirProps}
|
|
219
|
+
{slot}
|
|
220
|
+
defaultTag={DEFAULT_RADIO_GROUP_TAG}
|
|
221
|
+
bind:element
|
|
222
|
+
name="RadioGroup"
|
|
223
|
+
/>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ByComparator } from "../hooks/use-by-comparator.js";
|
|
2
|
+
import type { Props } from "../utils/types.js";
|
|
3
|
+
declare const DEFAULT_RADIO_GROUP_TAG: "div";
|
|
4
|
+
export type RadioGroupRenderPropArg<TType> = {
|
|
5
|
+
value: TType;
|
|
6
|
+
};
|
|
7
|
+
export type RadioGroupOwnProps<TType = string> = {
|
|
8
|
+
element?: HTMLElement;
|
|
9
|
+
value?: TType;
|
|
10
|
+
defaultValue?: TType;
|
|
11
|
+
onchange?(value: TType): void;
|
|
12
|
+
by?: ByComparator<TType>;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
form?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
export type RadioGroupProps<TType = string> = Props<typeof DEFAULT_RADIO_GROUP_TAG, RadioGroupRenderPropArg<TType>, RadioGroupOwnProps<TType>>;
|
|
18
|
+
declare class __sveltets_Render<TType = string> {
|
|
19
|
+
props(): RadioGroupProps<TType>;
|
|
20
|
+
events(): {};
|
|
21
|
+
slots(): {};
|
|
22
|
+
bindings(): "element";
|
|
23
|
+
exports(): {};
|
|
24
|
+
}
|
|
25
|
+
interface $$IsomorphicComponent {
|
|
26
|
+
new <TType = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TType>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TType>['props']>, ReturnType<__sveltets_Render<TType>['events']>, ReturnType<__sveltets_Render<TType>['slots']>> & {
|
|
27
|
+
$$bindings?: ReturnType<__sveltets_Render<TType>['bindings']>;
|
|
28
|
+
} & ReturnType<__sveltets_Render<TType>['exports']>;
|
|
29
|
+
<TType = string>(internal: unknown, props: ReturnType<__sveltets_Render<TType>['props']> & {}): ReturnType<__sveltets_Render<TType>['exports']>;
|
|
30
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
31
|
+
}
|
|
32
|
+
declare const RadioGroup: $$IsomorphicComponent;
|
|
33
|
+
type RadioGroup<TType = string> = InstanceType<typeof RadioGroup<TType>>;
|
|
34
|
+
export default RadioGroup;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Props } from "../utils/types.js"
|
|
3
|
+
|
|
4
|
+
const DEFAULT_OPTION_TAG = "div" as const
|
|
5
|
+
|
|
6
|
+
export type RadioOptionRenderPropArg = {
|
|
7
|
+
checked: boolean
|
|
8
|
+
/** @deprecated use `focus` instead */
|
|
9
|
+
active: boolean
|
|
10
|
+
hover: boolean
|
|
11
|
+
focus: boolean
|
|
12
|
+
autofocus: boolean
|
|
13
|
+
disabled: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type RadioOptionOwnProps<TType> = {
|
|
17
|
+
element?: HTMLElement
|
|
18
|
+
value: TType
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
autofocus?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type RadioOptionProps<TType> = Props<
|
|
24
|
+
typeof DEFAULT_OPTION_TAG,
|
|
25
|
+
RadioOptionRenderPropArg,
|
|
26
|
+
RadioOptionOwnProps<TType>
|
|
27
|
+
>
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script lang="ts" generics="TType = ComponentProps<typeof RadioGroup>['value']">
|
|
31
|
+
import { default as RadioGroup } from "./RadioGroup.svelte"
|
|
32
|
+
import { useActions, useData } from "./contest.svelte.js"
|
|
33
|
+
import { useId } from "../hooks/use-id.js"
|
|
34
|
+
import { useLabels } from "../label/context.svelte.js"
|
|
35
|
+
import { useDescriptions } from "../description/context.svelte.js"
|
|
36
|
+
import { onMount, type ComponentProps } from "svelte"
|
|
37
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
38
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
|
|
39
|
+
import { useHover } from "../hooks/use-hover.svelte.js"
|
|
40
|
+
import { mergeProps } from "../utils/render.js"
|
|
41
|
+
|
|
42
|
+
const data = useData("RadioOption")
|
|
43
|
+
const actions = useActions<TType>("RadioOption")
|
|
44
|
+
|
|
45
|
+
const internalId = useId()
|
|
46
|
+
let {
|
|
47
|
+
element = $bindable(),
|
|
48
|
+
id: theirId,
|
|
49
|
+
value,
|
|
50
|
+
disabled: theirDisabled = false,
|
|
51
|
+
autofocus = false,
|
|
52
|
+
...theirProps
|
|
53
|
+
}: RadioOptionProps<TType> = $props()
|
|
54
|
+
const id = $derived(theirId || `headlessui-radiogroup-option-${internalId}`)
|
|
55
|
+
const disabled = $derived(data.disabled || theirDisabled)
|
|
56
|
+
|
|
57
|
+
const labelledby = useLabels()
|
|
58
|
+
const describedby = useDescriptions()
|
|
59
|
+
|
|
60
|
+
const propsRef = {
|
|
61
|
+
get value() {
|
|
62
|
+
return value
|
|
63
|
+
},
|
|
64
|
+
get disabled() {
|
|
65
|
+
return disabled
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onMount(() => {
|
|
70
|
+
return actions.registerOption({
|
|
71
|
+
id,
|
|
72
|
+
get element() {
|
|
73
|
+
return element
|
|
74
|
+
},
|
|
75
|
+
get propsRef() {
|
|
76
|
+
return propsRef
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const handleClick = (event: MouseEvent) => {
|
|
82
|
+
//if (isDisabledReactIssue7711(event.currentTarget)) return event.preventDefault()
|
|
83
|
+
if (!actions.change(value)) return
|
|
84
|
+
element?.focus()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const isFirstOption = $derived(data.firstOption?.id === id)
|
|
88
|
+
|
|
89
|
+
const { isFocusVisible: focus, focusProps } = $derived(
|
|
90
|
+
useFocusRing({
|
|
91
|
+
get autofocus() {
|
|
92
|
+
return autofocus
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
97
|
+
useHover({
|
|
98
|
+
get disabled() {
|
|
99
|
+
return disabled
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const checked = $derived(data.compare(data.value as TType, value))
|
|
105
|
+
const ourProps = $derived(
|
|
106
|
+
mergeProps(
|
|
107
|
+
{
|
|
108
|
+
id,
|
|
109
|
+
role: "radio",
|
|
110
|
+
"aria-checked": checked ? "true" : "false",
|
|
111
|
+
"aria-labelledby": labelledby.value,
|
|
112
|
+
"aria-describedby": describedby.value,
|
|
113
|
+
"aria-disabled": disabled ? true : undefined,
|
|
114
|
+
tabIndex: (() => {
|
|
115
|
+
if (disabled) return -1
|
|
116
|
+
if (checked) return 0
|
|
117
|
+
if (!data.containsCheckedOption && isFirstOption) return 0
|
|
118
|
+
return -1
|
|
119
|
+
})(),
|
|
120
|
+
onclick: disabled ? undefined : handleClick,
|
|
121
|
+
autofocus,
|
|
122
|
+
},
|
|
123
|
+
focusProps,
|
|
124
|
+
hoverProps
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
const slot = $derived({
|
|
129
|
+
checked,
|
|
130
|
+
disabled,
|
|
131
|
+
active: focus,
|
|
132
|
+
hover,
|
|
133
|
+
focus,
|
|
134
|
+
autofocus,
|
|
135
|
+
} satisfies RadioOptionRenderPropArg)
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_OPTION_TAG} bind:element name="RadioOption" />
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Props } from "../utils/types.js";
|
|
2
|
+
declare const DEFAULT_OPTION_TAG: "div";
|
|
3
|
+
export type RadioOptionRenderPropArg = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
/** @deprecated use `focus` instead */
|
|
6
|
+
active: boolean;
|
|
7
|
+
hover: boolean;
|
|
8
|
+
focus: boolean;
|
|
9
|
+
autofocus: boolean;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type RadioOptionOwnProps<TType> = {
|
|
13
|
+
element?: HTMLElement;
|
|
14
|
+
value: TType;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
autofocus?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type RadioOptionProps<TType> = Props<typeof DEFAULT_OPTION_TAG, RadioOptionRenderPropArg, RadioOptionOwnProps<TType>>;
|
|
19
|
+
import { default as RadioGroup } from "./RadioGroup.svelte";
|
|
20
|
+
import { type ComponentProps } from "svelte";
|
|
21
|
+
declare class __sveltets_Render<TType = ComponentProps<typeof RadioGroup>['value']> {
|
|
22
|
+
props(): RadioOptionProps<TType>;
|
|
23
|
+
events(): {};
|
|
24
|
+
slots(): {};
|
|
25
|
+
bindings(): "element";
|
|
26
|
+
exports(): {};
|
|
27
|
+
}
|
|
28
|
+
interface $$IsomorphicComponent {
|
|
29
|
+
new <TType = ComponentProps<typeof RadioGroup>['value']>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TType>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TType>['props']>, ReturnType<__sveltets_Render<TType>['events']>, ReturnType<__sveltets_Render<TType>['slots']>> & {
|
|
30
|
+
$$bindings?: ReturnType<__sveltets_Render<TType>['bindings']>;
|
|
31
|
+
} & ReturnType<__sveltets_Render<TType>['exports']>;
|
|
32
|
+
<TType = ComponentProps<typeof RadioGroup>['value']>(internal: unknown, props: ReturnType<__sveltets_Render<TType>['props']> & {}): ReturnType<__sveltets_Render<TType>['exports']>;
|
|
33
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
34
|
+
}
|
|
35
|
+
declare const RadioOption: $$IsomorphicComponent;
|
|
36
|
+
type RadioOption<TType = ComponentProps<typeof RadioGroup>['value']> = InstanceType<typeof RadioOption<TType>>;
|
|
37
|
+
export default RadioOption;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface Option<T = unknown> {
|
|
2
|
+
id: string;
|
|
3
|
+
element?: HTMLElement;
|
|
4
|
+
propsRef: {
|
|
5
|
+
value: T;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface StateDefinition<T = unknown> {
|
|
10
|
+
options: Option<T>[];
|
|
11
|
+
}
|
|
12
|
+
export type RadioGroupDataContext = {
|
|
13
|
+
value: unknown;
|
|
14
|
+
firstOption?: Option;
|
|
15
|
+
containsCheckedOption: boolean;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
compare(a: unknown, z: unknown): boolean;
|
|
18
|
+
} & StateDefinition;
|
|
19
|
+
export declare function useData(component: string): RadioGroupDataContext;
|
|
20
|
+
export type RadioGroupActionsContext<T> = {
|
|
21
|
+
registerOption(option: Option<T>): () => void;
|
|
22
|
+
change(value: T): boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function useActions<T>(component: string): RadioGroupActionsContext<T>;
|
|
25
|
+
export declare function createState<T>(): {
|
|
26
|
+
readonly options: Option<T>[];
|
|
27
|
+
registerOption(option: Option<T>): void;
|
|
28
|
+
unregisterOption(id: string): void;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { sortByDomNode } from "../utils/focus-management.js";
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
export function useData(component) {
|
|
4
|
+
const context = getContext("RadioGroupDataContext");
|
|
5
|
+
if (!context) {
|
|
6
|
+
const err = new Error(`<${component} /> is missing a parent <RadioGroup /> component.`);
|
|
7
|
+
if (Error.captureStackTrace)
|
|
8
|
+
Error.captureStackTrace(err, useData);
|
|
9
|
+
throw err;
|
|
10
|
+
}
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
export function useActions(component) {
|
|
14
|
+
const context = getContext("RadioGroupActionsContext");
|
|
15
|
+
if (!context) {
|
|
16
|
+
const err = new Error(`<${component} /> is missing a parent <RadioGroup /> component.`);
|
|
17
|
+
if (Error.captureStackTrace)
|
|
18
|
+
Error.captureStackTrace(err, useActions);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
export function createState() {
|
|
24
|
+
let options = $state([]);
|
|
25
|
+
return {
|
|
26
|
+
get options() {
|
|
27
|
+
return options;
|
|
28
|
+
},
|
|
29
|
+
registerOption(option) {
|
|
30
|
+
const nextOptions = [...options, option];
|
|
31
|
+
options = sortByDomNode(nextOptions, (option) => option.element ?? null);
|
|
32
|
+
},
|
|
33
|
+
unregisterOption(id) {
|
|
34
|
+
let idx = options.findIndex((radio) => radio.id === id);
|
|
35
|
+
if (idx === -1)
|
|
36
|
+
return;
|
|
37
|
+
options.splice(idx, 1);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { default as Radio, type RadioProps, type RadioRenderPropArg as RadioSlot, type RadioOwnProps, } from "./Radio.svelte";
|
|
2
|
+
export { default as RadioGroup, type RadioGroupProps, type RadioGroupRenderPropArg as RadioGroupSlot, type RadioGroupOwnProps, } from "./RadioGroup.svelte";
|
|
3
|
+
export { default as RadioOption, type RadioOptionProps, type RadioOptionRenderPropArg as RadioOptionSlot, type RadioOptionOwnProps, } from "./RadioOption.svelte";
|
|
@@ -17,4 +17,5 @@ export type SelectOwnProps = {
|
|
|
17
17
|
};
|
|
18
18
|
export type SelectProps = Props<typeof DEFAULT_SELECT_TAG, SelectRenderPropArg, SelectOwnProps>;
|
|
19
19
|
declare const Select: import("svelte").Component<SelectProps, {}, "element">;
|
|
20
|
+
type Select = ReturnType<typeof Select>;
|
|
20
21
|
export default Select;
|
|
@@ -24,4 +24,5 @@ export type SwitchOwnProps = {
|
|
|
24
24
|
};
|
|
25
25
|
export type SwitchProps = Props<typeof DEFAULT_SWITCH_TAG, SwitchRenderPropArg, SwitchOwnProps>;
|
|
26
26
|
declare const Switch: import("svelte").Component<SwitchProps, {}, "element" | "checked">;
|
|
27
|
+
type Switch = ReturnType<typeof Switch>;
|
|
27
28
|
export default Switch;
|
|
@@ -13,4 +13,5 @@ export type TabGroupOwnProps = {
|
|
|
13
13
|
};
|
|
14
14
|
export type TabGroupProps = Props<typeof DEFAULT_TABS_TAG, TabsRenderPropArg, TabGroupOwnProps>;
|
|
15
15
|
declare const TabGroup: import("svelte").Component<TabGroupProps, {}, "element">;
|
|
16
|
+
type TabGroup = ReturnType<typeof TabGroup>;
|
|
16
17
|
export default TabGroup;
|
|
@@ -8,4 +8,5 @@ export type TabListOwnProps = {
|
|
|
8
8
|
};
|
|
9
9
|
export type TabListProps = Props<typeof DEFAULT_LIST_TAG, ListRenderPropArg, TabListOwnProps>;
|
|
10
10
|
declare const TabList: import("svelte").Component<TabListProps, {}, "element">;
|
|
11
|
+
type TabList = ReturnType<typeof TabList>;
|
|
11
12
|
export default TabList;
|
|
@@ -13,4 +13,5 @@ export type TabPanelOwnProps = PropsForFeatures<typeof PanelRenderFeatures> & {
|
|
|
13
13
|
export type TabPanelProps = Props<typeof DEFAULT_PANEL_TAG, PanelRenderPropArg, TabPanelOwnProps>;
|
|
14
14
|
import { type PropsForFeatures } from "../utils/render.js";
|
|
15
15
|
declare const TabPanel: import("svelte").Component<TabPanelProps, {}, "element">;
|
|
16
|
+
type TabPanel = ReturnType<typeof TabPanel>;
|
|
16
17
|
export default TabPanel;
|
|
@@ -8,4 +8,5 @@ export type TabPanelsOwnProps = {
|
|
|
8
8
|
};
|
|
9
9
|
export type TabPanelsProps = Props<typeof DEFAULT_PANELS_TAG, PanelsRenderPropArg, TabPanelsOwnProps>;
|
|
10
10
|
declare const TabPanels: import("svelte").Component<TabPanelsProps, {}, "element">;
|
|
11
|
+
type TabPanels = ReturnType<typeof TabPanels>;
|
|
11
12
|
export default TabPanels;
|
|
@@ -20,4 +20,5 @@ import { type TransitionChildProps } from "./TransitionChild.svelte";
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function shouldForwardRef(props: TransitionRootProps): boolean;
|
|
22
22
|
declare const InternalTransitionChild: import("svelte").Component<TransitionChildProps, {}, "element">;
|
|
23
|
+
type InternalTransitionChild = ReturnType<typeof InternalTransitionChild>;
|
|
23
24
|
export default InternalTransitionChild;
|
|
@@ -13,4 +13,5 @@ export type TransitionChildRenderPropArg = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const TransitionChildRenderFeatures = RenderFeatures.RenderStrategy;
|
|
15
15
|
declare const TransitionChild: import("svelte").Component<TransitionChildProps, {}, "element">;
|
|
16
|
+
type TransitionChild = ReturnType<typeof TransitionChild>;
|
|
16
17
|
export default TransitionChild;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
|
-
|
|
2
|
+
type $$ComponentProps = {
|
|
3
3
|
disabled?: boolean;
|
|
4
4
|
children?: Snippet;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
declare const DisabledProvider: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type DisabledProvider = ReturnType<typeof DisabledProvider>;
|
|
6
8
|
export default DisabledProvider;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Snippet } from "svelte";
|
|
2
2
|
export declare function useStableCollectionIndex(group: string): number;
|
|
3
|
-
|
|
3
|
+
type $$ComponentProps = {
|
|
4
4
|
children: Snippet;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
declare const StableCollection: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type StableCollection = ReturnType<typeof StableCollection>;
|
|
6
8
|
export default StableCollection;
|