@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.
Files changed (65) hide show
  1. package/dist/button/Button.svelte +84 -54
  2. package/dist/checkbox/Checkbox.svelte +174 -120
  3. package/dist/close-button/CloseButton.svelte +12 -6
  4. package/dist/combobox/Combobox.svelte +50 -3
  5. package/dist/data-interactive/DataInteractive.svelte +57 -29
  6. package/dist/description/Description.svelte +32 -21
  7. package/dist/dialog/Dialog.svelte +69 -34
  8. package/dist/dialog/DialogBackdrop.svelte +29 -12
  9. package/dist/dialog/DialogPanel.svelte +49 -26
  10. package/dist/dialog/DialogTitle.svelte +38 -23
  11. package/dist/dialog/InternalDialog.svelte +263 -202
  12. package/dist/field/Field.svelte +49 -26
  13. package/dist/fieldset/Fieldset.svelte +50 -29
  14. package/dist/focus-trap/FocusTrap.svelte +419 -290
  15. package/dist/focus-trap/FocusTrap.svelte.d.ts +2 -14
  16. package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
  17. package/dist/focus-trap/FocusTrapFeatures.js +15 -0
  18. package/dist/input/Input.svelte +85 -53
  19. package/dist/internal/FocusSentinel.svelte +16 -8
  20. package/dist/internal/ForcePortalRoot.svelte +7 -3
  21. package/dist/internal/FormFields.svelte +31 -20
  22. package/dist/internal/FormResolver.svelte +20 -15
  23. package/dist/internal/Hidden.svelte +44 -27
  24. package/dist/internal/Hidden.svelte.d.ts +2 -5
  25. package/dist/internal/HiddenFeatures.d.ts +5 -0
  26. package/dist/internal/HiddenFeatures.js +9 -0
  27. package/dist/internal/HoistFormFields.svelte +7 -4
  28. package/dist/internal/MainTreeProvider.svelte +89 -36
  29. package/dist/internal/Portal.svelte +18 -14
  30. package/dist/label/Label.svelte +91 -57
  31. package/dist/legend/Legend.svelte +18 -3
  32. package/dist/listbox/Listbox.svelte +588 -409
  33. package/dist/listbox/Listbox.svelte.d.ts +2 -12
  34. package/dist/listbox/ListboxButton.svelte +176 -127
  35. package/dist/listbox/ListboxOption.svelte +166 -125
  36. package/dist/listbox/ListboxOptions.svelte +340 -244
  37. package/dist/listbox/ListboxSelectedOption.svelte +38 -15
  38. package/dist/listbox/ListboxStates.d.ts +12 -0
  39. package/dist/listbox/ListboxStates.js +15 -0
  40. package/dist/menu/Menu.svelte +307 -218
  41. package/dist/menu/MenuButton.svelte +157 -115
  42. package/dist/menu/MenuHeading.svelte +34 -14
  43. package/dist/menu/MenuItem.svelte +145 -107
  44. package/dist/menu/MenuItems.svelte +298 -224
  45. package/dist/menu/MenuSection.svelte +26 -9
  46. package/dist/menu/MenuSeparator.svelte +20 -4
  47. package/dist/portal/InternalPortal.svelte +141 -85
  48. package/dist/portal/Portal.svelte +5 -2
  49. package/dist/portal/PortalGroup.svelte +30 -9
  50. package/dist/switch/Switch.svelte +179 -122
  51. package/dist/switch/Switch.svelte.d.ts +4 -4
  52. package/dist/switch/SwitchGroup.svelte +44 -31
  53. package/dist/tabs/Tab.svelte +195 -143
  54. package/dist/tabs/TabGroup.svelte +292 -205
  55. package/dist/tabs/TabList.svelte +31 -11
  56. package/dist/tabs/TabPanel.svelte +68 -43
  57. package/dist/tabs/TabPanels.svelte +18 -7
  58. package/dist/textarea/Textarea.svelte +83 -53
  59. package/dist/transition/InternalTransitionChild.svelte +259 -170
  60. package/dist/transition/Transition.svelte +96 -66
  61. package/dist/transition/TransitionChild.svelte +31 -11
  62. package/dist/utils/ElementOrComponent.svelte +44 -23
  63. package/dist/utils/Generic.svelte +29 -17
  64. package/dist/utils/StableCollection.svelte +54 -36
  65. package/package.json +10 -10
@@ -1,49 +1,74 @@
1
- <script lang="ts" module>const DEFAULT_PANEL_TAG = "div";
2
- const PanelRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static;
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props } from "../utils/types.js"
3
+
4
+ const DEFAULT_PANEL_TAG = "div" as const
5
+ type PanelRenderPropArg = {
6
+ selected: boolean
7
+ focus: boolean
8
+ }
9
+ type PanelPropsWeControl = "role" | "aria-labelledby"
10
+ const PanelRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static
11
+
12
+ export type TabPanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<
13
+ TTag,
14
+ PanelRenderPropArg,
15
+ PanelPropsWeControl,
16
+ PropsForFeatures<typeof PanelRenderFeatures> & { id?: string; tabIndex?: number }
17
+ >
3
18
  </script>
4
19
 
5
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">import { useId } from "../hooks/use-id.js";
6
- import { mergeProps, RenderFeatures } from "../utils/render.js";
7
- import { useActions, useData } from "./TabGroup.svelte";
8
- import { useStableCollectionIndex } from "../utils/StableCollection.svelte";
9
- import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
10
- import Hidden from "../internal/Hidden.svelte";
11
- import { onMount } from "svelte";
12
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
13
- const internalId = useId();
14
- let {
15
- ref = $bindable(),
16
- id = `headlessui-tabs-panel-${internalId}`,
17
- tabIndex = 0,
18
- ...theirProps
19
- } = $props();
20
- const data = useData("Tab.Panel");
21
- const { selectedIndex, tabs, panels } = $derived(data);
22
- const actions = useActions("Tab.Panel");
23
- const panelRef = $derived({ current: ref });
24
- onMount(() => actions.registerPanel(panelRef));
25
- const mySSRIndex = useStableCollectionIndex("panels");
26
- const myIndex = $derived.by(() => {
27
- const index = tabs.findIndex((panel) => panel === panelRef);
28
- return index === -1 ? mySSRIndex : index;
29
- });
30
- const selected = $derived(myIndex === selectedIndex);
31
- const { isFocusVisible: focus, focusProps } = $derived(useFocusRing());
32
- const slot = $derived({
33
- selected,
34
- focus
35
- });
36
- const ourProps = $derived(
37
- mergeProps(
38
- {
39
- id,
40
- role: "tabpanel",
41
- "aria-labelledby": tabs[myIndex]?.current?.id,
42
- tabIndex: selected ? 0 : -1
43
- },
44
- focusProps
20
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">
21
+ import { useId } from "../hooks/use-id.js"
22
+ import { mergeProps, RenderFeatures, type PropsForFeatures } from "../utils/render.js"
23
+ import { useActions, useData } from "./TabGroup.svelte"
24
+ import { useStableCollectionIndex } from "../utils/StableCollection.svelte"
25
+ import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
26
+ import Hidden from "../internal/Hidden.svelte"
27
+ import type { MutableRefObject } from "../utils/ref.svelte.js"
28
+ import { onMount } from "svelte"
29
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
30
+
31
+ const internalId = useId()
32
+ let {
33
+ ref = $bindable(),
34
+ id = `headlessui-tabs-panel-${internalId}`,
35
+ tabIndex = 0,
36
+ ...theirProps
37
+ }: { as?: TTag } & TabPanelProps<TTag> = $props()
38
+ const data = useData("Tab.Panel")
39
+ const { selectedIndex, tabs, panels } = $derived(data)
40
+ const actions = useActions("Tab.Panel")
41
+
42
+ const panelRef = $derived<MutableRefObject<HTMLElement | undefined>>({ current: ref })
43
+
44
+ onMount(() => actions.registerPanel(panelRef))
45
+
46
+ const mySSRIndex = useStableCollectionIndex("panels")
47
+
48
+ const myIndex = $derived.by(() => {
49
+ const index = tabs.findIndex((panel) => panel === panelRef)
50
+ return index === -1 ? mySSRIndex : index
51
+ })
52
+
53
+ const selected = $derived(myIndex === selectedIndex)
54
+
55
+ const { isFocusVisible: focus, focusProps } = $derived(useFocusRing())
56
+ const slot = $derived({
57
+ selected,
58
+ focus,
59
+ } satisfies PanelRenderPropArg)
60
+
61
+ const ourProps = $derived(
62
+ mergeProps(
63
+ {
64
+ id,
65
+ role: "tabpanel",
66
+ "aria-labelledby": tabs[myIndex]?.current?.id,
67
+ tabIndex: selected ? 0 : -1,
68
+ },
69
+ focusProps
70
+ )
45
71
  )
46
- );
47
72
  </script>
48
73
 
49
74
  {#if !selected && (theirProps.unmount ?? true) && !(theirProps.static ?? false)}
@@ -1,12 +1,23 @@
1
- <script lang="ts" module>import ElementOrComponent from "../utils/ElementOrComponent.svelte";
2
- import { useData } from "./TabGroup.svelte";
3
- let DEFAULT_PANELS_TAG = "div";
1
+ <script lang="ts" module>
2
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
3
+ import type { ElementType, Props } from "../utils/types.js"
4
+ import { useData } from "./TabGroup.svelte"
5
+
6
+ let DEFAULT_PANELS_TAG = "div" as const
7
+ type PanelsRenderPropArg = {
8
+ selectedIndex: number
9
+ }
10
+
11
+ export type TabPanelsProps<TTag extends ElementType = typeof DEFAULT_PANELS_TAG> = Props<TTag, PanelsRenderPropArg>
4
12
  </script>
5
13
 
6
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANELS_TAG">const data = useData("Tab.Panels");
7
- const { selectedIndex } = $derived(data);
8
- const slot = $derived({ selectedIndex });
9
- let { ref = $bindable(), ...theirProps } = $props();
14
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANELS_TAG">
15
+ const data = useData("Tab.Panels")
16
+ const { selectedIndex } = $derived(data)
17
+
18
+ const slot = $derived({ selectedIndex } satisfies PanelsRenderPropArg)
19
+
20
+ let { ref = $bindable(), ...theirProps }: { as?: TTag } & TabPanelsProps<TTag> = $props()
10
21
  </script>
11
22
 
12
23
  <ElementOrComponent {theirProps} {slot} defaultTag={DEFAULT_PANELS_TAG} name="TabPanel" bind:ref />
@@ -1,59 +1,89 @@
1
- <script lang="ts" module>const DEFAULT_TEXTAREA_TAG = "textarea";
2
- </script>
1
+ <script lang="ts" module>
2
+ import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
3
 
4
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TEXTAREA_TAG">import { htmlid } from "../utils/id.js";
5
- import { useDisabled } from "../hooks/use-disabled.js";
6
- import { useProvidedId } from "../internal/id.js";
7
- import { useLabelledBy } from "../label/context.svelte.js";
8
- import { useDescribedBy } from "../description/context.svelte.js";
9
- import { useHover } from "../hooks/use-hover.svelte.js";
10
- import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
11
- import { mergeProps } from "../utils/render.js";
12
- import ElementOrComponent from "../utils/ElementOrComponent.svelte";
13
- const internalId = htmlid();
14
- const providedId = useProvidedId();
15
- const providedDisabled = useDisabled();
16
- let {
17
- ref = $bindable(),
18
- value = $bindable(),
19
- id = providedId?.value || `headlessui-input-${internalId}`,
20
- disabled: theirDisabled = false,
21
- autofocus = false,
22
- invalid = false,
23
- ...theirProps
24
- } = $props();
25
- const disabled = $derived(providedDisabled?.value ?? theirDisabled);
26
- const labelledBy = useLabelledBy();
27
- const describedBy = useDescribedBy();
28
- const { isFocusVisible: focus, focusProps } = $derived(
29
- useFocusRing({
30
- get autofocus() {
31
- return autofocus;
32
- }
33
- })
34
- );
35
- const { isHovered: hover, hoverProps } = $derived(
36
- useHover({
37
- get disabled() {
38
- return disabled;
39
- }
40
- })
41
- );
42
- const ourProps = $derived(
43
- mergeProps(
4
+ const DEFAULT_TEXTAREA_TAG = "textarea" as const
5
+
6
+ type TextareaRenderPropArg = {
7
+ disabled: boolean
8
+ hover: boolean
9
+ focus: boolean
10
+ autofocus: boolean
11
+ invalid: boolean
12
+ }
13
+ type TextareaPropsWeControl = "aria-labelledby" | "aria-describedby"
14
+
15
+ export type TextareaProps<TTag extends ElementType = typeof DEFAULT_TEXTAREA_TAG> = Props<
16
+ TTag,
17
+ TextareaRenderPropArg,
18
+ TextareaPropsWeControl,
44
19
  {
45
- id,
46
- "aria-labelledby": labelledBy?.value,
47
- "aria-describedby": describedBy?.value,
48
- "aria-invalid": invalid ? "" : void 0,
49
- disabled: disabled || void 0,
50
- autofocus
51
- },
52
- focusProps,
53
- hoverProps
20
+ disabled?: boolean
21
+ invalid?: boolean
22
+ autoFocus?: boolean
23
+ }
24
+ >
25
+ </script>
26
+
27
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TEXTAREA_TAG">
28
+ import { htmlid } from "../utils/id.js"
29
+ import { useDisabled } from "../hooks/use-disabled.js"
30
+ import { useProvidedId } from "../internal/id.js"
31
+ import { useLabelledBy } from "../label/context.svelte.js"
32
+ import { useDescribedBy } from "../description/context.svelte.js"
33
+ import { useHover } from "../hooks/use-hover.svelte.js"
34
+ import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
35
+ import { mergeProps } from "../utils/render.js"
36
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte"
37
+
38
+ const internalId = htmlid()
39
+ const providedId = useProvidedId()
40
+ const providedDisabled = useDisabled()
41
+
42
+ let {
43
+ ref = $bindable(),
44
+ value = $bindable<PropsOf<TTag>["value"]>(),
45
+ id = (providedId?.value || `headlessui-input-${internalId}`) as PropsOf<TTag>["id"],
46
+ disabled: theirDisabled = false,
47
+ autofocus = false as PropsOf<TTag>["autofocus"],
48
+ invalid = false,
49
+ ...theirProps
50
+ }: { as?: TTag } & TextareaProps<TTag> = $props()
51
+ const disabled = $derived(providedDisabled?.value ?? theirDisabled)
52
+
53
+ const labelledBy = useLabelledBy()
54
+ const describedBy = useDescribedBy()
55
+
56
+ const { isFocusVisible: focus, focusProps } = $derived(
57
+ useFocusRing({
58
+ get autofocus() {
59
+ return autofocus
60
+ },
61
+ })
54
62
  )
55
- );
56
- const slot = $derived({ disabled, invalid, hover, focus, autofocus });
63
+ const { isHovered: hover, hoverProps } = $derived(
64
+ useHover({
65
+ get disabled() {
66
+ return disabled
67
+ },
68
+ })
69
+ )
70
+
71
+ const ourProps = $derived(
72
+ mergeProps(
73
+ {
74
+ id,
75
+ "aria-labelledby": labelledBy?.value,
76
+ "aria-describedby": describedBy?.value,
77
+ "aria-invalid": invalid ? "" : undefined,
78
+ disabled: disabled || undefined,
79
+ autofocus,
80
+ },
81
+ focusProps,
82
+ hoverProps
83
+ )
84
+ )
85
+
86
+ const slot = $derived({ disabled, invalid, hover, focus, autofocus } satisfies TextareaRenderPropArg)
57
87
  </script>
58
88
 
59
89
  <ElementOrComponent