@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.
Files changed (55) hide show
  1. package/dist/button/Button.svelte +54 -84
  2. package/dist/checkbox/Checkbox.svelte +120 -174
  3. package/dist/close-button/CloseButton.svelte +6 -12
  4. package/dist/combobox/Combobox.svelte +3 -50
  5. package/dist/data-interactive/DataInteractive.svelte +29 -57
  6. package/dist/description/Description.svelte +21 -32
  7. package/dist/dialog/Dialog.svelte +34 -69
  8. package/dist/dialog/DialogBackdrop.svelte +12 -29
  9. package/dist/dialog/DialogPanel.svelte +26 -49
  10. package/dist/dialog/DialogTitle.svelte +23 -38
  11. package/dist/dialog/InternalDialog.svelte +202 -263
  12. package/dist/field/Field.svelte +26 -49
  13. package/dist/fieldset/Fieldset.svelte +29 -50
  14. package/dist/focus-trap/FocusTrap.svelte +283 -419
  15. package/dist/input/Input.svelte +53 -84
  16. package/dist/internal/FocusSentinel.svelte +8 -16
  17. package/dist/internal/ForcePortalRoot.svelte +3 -7
  18. package/dist/internal/FormFields.svelte +20 -31
  19. package/dist/internal/FormResolver.svelte +15 -20
  20. package/dist/internal/Hidden.svelte +23 -44
  21. package/dist/internal/HoistFormFields.svelte +4 -7
  22. package/dist/internal/MainTreeProvider.svelte +36 -89
  23. package/dist/internal/Portal.svelte +14 -18
  24. package/dist/label/Label.svelte +57 -91
  25. package/dist/legend/Legend.svelte +3 -18
  26. package/dist/listbox/Listbox.svelte +396 -588
  27. package/dist/listbox/ListboxButton.svelte +127 -176
  28. package/dist/listbox/ListboxOption.svelte +125 -166
  29. package/dist/listbox/ListboxOptions.svelte +244 -340
  30. package/dist/listbox/ListboxSelectedOption.svelte +15 -38
  31. package/dist/menu/Menu.svelte +218 -307
  32. package/dist/menu/MenuButton.svelte +115 -157
  33. package/dist/menu/MenuHeading.svelte +14 -34
  34. package/dist/menu/MenuItem.svelte +107 -145
  35. package/dist/menu/MenuItems.svelte +224 -298
  36. package/dist/menu/MenuSection.svelte +9 -26
  37. package/dist/menu/MenuSeparator.svelte +4 -20
  38. package/dist/portal/InternalPortal.svelte +85 -141
  39. package/dist/portal/Portal.svelte +2 -5
  40. package/dist/portal/PortalGroup.svelte +9 -30
  41. package/dist/switch/Switch.svelte +132 -179
  42. package/dist/switch/SwitchGroup.svelte +31 -44
  43. package/dist/tabs/Tab.svelte +143 -195
  44. package/dist/tabs/TabGroup.svelte +205 -292
  45. package/dist/tabs/TabList.svelte +11 -31
  46. package/dist/tabs/TabPanel.svelte +43 -68
  47. package/dist/tabs/TabPanels.svelte +7 -18
  48. package/dist/textarea/Textarea.svelte +53 -84
  49. package/dist/transition/InternalTransitionChild.svelte +170 -259
  50. package/dist/transition/Transition.svelte +66 -96
  51. package/dist/transition/TransitionChild.svelte +11 -31
  52. package/dist/utils/ElementOrComponent.svelte +23 -44
  53. package/dist/utils/Generic.svelte +17 -29
  54. package/dist/utils/StableCollection.svelte +36 -54
  55. package/package.json +1 -1
@@ -1,37 +1,26 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
-
4
- let DEFAULT_DESCRIPTION_TAG = "p" as const
5
-
6
- export type DescriptionProps<TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG> = Props<TTag>
1
+ <script lang="ts" module>let DEFAULT_DESCRIPTION_TAG = "p";
7
2
  </script>
8
3
 
9
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG">
10
- import { htmlid } from "../utils/id.js"
11
- import { stateFromSlot } from "../utils/state.js"
12
- import { useDisabled } from "../hooks/use-disabled.js"
13
- import { onMount } from "svelte"
14
- import { useDescriptionContext } from "./context.svelte.js"
15
-
16
- const internalId = htmlid()
17
- const providedDisabled = useDisabled()
18
-
19
- let {
20
- as,
21
- id = `headlessui-description-${internalId}` as PropsOf<TTag>["id"],
22
- children,
23
- ...theirProps
24
- }: { as?: TTag } & DescriptionProps<TTag> = $props()
25
-
26
- const context = useDescriptionContext()
27
-
28
- onMount(() => {
29
- context.register(id)
30
- })
31
-
32
- const disabled = $derived(providedDisabled.value || false)
33
- const slot = $derived({ disabled })
34
- const ourProps = $derived({ id, ...stateFromSlot(slot) })
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG">import { htmlid } from "../utils/id.js";
5
+ import { stateFromSlot } from "../utils/state.js";
6
+ import { useDisabled } from "../hooks/use-disabled.js";
7
+ import { onMount } from "svelte";
8
+ import { useDescriptionContext } from "./context.svelte.js";
9
+ const internalId = htmlid();
10
+ const providedDisabled = useDisabled();
11
+ let {
12
+ as,
13
+ id = `headlessui-description-${internalId}`,
14
+ children,
15
+ ...theirProps
16
+ } = $props();
17
+ const context = useDescriptionContext();
18
+ onMount(() => {
19
+ context.register(id);
20
+ });
21
+ const disabled = $derived(providedDisabled.value || false);
22
+ const slot = $derived({ disabled });
23
+ const ourProps = $derived({ id, ...stateFromSlot(slot) });
35
24
  </script>
36
25
 
37
26
  <svelte:element this={as ?? DEFAULT_DESCRIPTION_TAG} {...ourProps} {...theirProps}>
@@ -1,74 +1,39 @@
1
- <script lang="ts" module>
2
- import { MainTreeProvider } from "../hooks/use-root-containers.svelte.js"
3
- import { useOpenClosed } from "../internal/open-closed.js"
4
- import { RenderFeatures, type PropsForFeatures } from "../utils/render.js"
5
- import type { ElementType, Props } from "../utils/types.js"
6
- import { getContext, type Component, type Snippet } from "svelte"
7
- import InternalDialog from "./InternalDialog.svelte"
8
- import Transition from "../transition/Transition.svelte"
9
-
10
- export const DEFAULT_DIALOG_TAG = "div" as const
11
- export type DialogRenderPropArg = {
12
- open: boolean
13
- }
14
- type DialogPropsWeControl = "aria-describedby" | "aria-labelledby" | "aria-modal"
15
-
16
- export const DialogRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static
17
-
18
- export type DialogProps<TTag extends ElementType = typeof DEFAULT_DIALOG_TAG> = Props<
19
- TTag,
20
- DialogRenderPropArg,
21
- DialogPropsWeControl,
22
- PropsForFeatures<typeof DialogRenderFeatures> & {
23
- id?: string
24
- open?: boolean
25
- onclose(value: boolean): void
26
- initialFocus?: HTMLElement
27
- role?: "dialog" | "alertdialog"
28
- autofocus?: boolean
29
- transition?: boolean
30
- __demoMode?: boolean
31
- }
32
- >
33
-
34
- export type DialogChildren = Snippet<[DialogRenderPropArg]>
1
+ <script lang="ts" module>import { MainTreeProvider } from "../hooks/use-root-containers.svelte.js";
2
+ import { useOpenClosed } from "../internal/open-closed.js";
3
+ import { RenderFeatures } from "../utils/render.js";
4
+ import { getContext } from "svelte";
5
+ import InternalDialog from "./InternalDialog.svelte";
6
+ import Transition from "../transition/Transition.svelte";
7
+ export const DEFAULT_DIALOG_TAG = "div";
8
+ export const DialogRenderFeatures = RenderFeatures.RenderStrategy | RenderFeatures.Static;
35
9
  </script>
36
10
 
37
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DIALOG_TAG">
38
- let { ref = $bindable(), transition = false, open, ...rest }: { as?: TTag } & DialogProps<TTag> = $props()
39
-
40
- // Validations
41
- const usesOpenClosedState = useOpenClosed()
42
- const hasOpen = $derived(open !== undefined || usesOpenClosedState)
43
- const hasOnClose = $derived(rest.hasOwnProperty("onclose"))
44
-
45
- $effect(() => {
46
- if (!hasOpen && !hasOnClose) {
47
- throw new Error(`You have to provide an \`open\` and an \`onclose\` prop to the \`Dialog\` component.`)
48
- }
49
-
50
- if (!hasOpen) {
51
- throw new Error(`You provided an \`onclose\` prop to the \`Dialog\`, but forgot an \`open\` prop.`)
52
- }
53
-
54
- if (!hasOnClose) {
55
- throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but forgot an \`onclose\` prop.`)
56
- }
57
-
58
- if (!usesOpenClosedState && typeof open !== "boolean") {
59
- throw new Error(
60
- `You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${open}`
61
- )
62
- }
63
-
64
- if (typeof rest.onclose !== "function") {
65
- throw new Error(
66
- `You provided an \`onclose\` prop to the \`Dialog\`, but the value is not a function. Received: ${rest.onclose}`
67
- )
68
- }
69
- })
70
-
71
- const DialogComponent = InternalDialog as Component<DialogProps<TTag>, any>
11
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_DIALOG_TAG">let { ref = $bindable(), transition = false, open, ...rest } = $props();
12
+ const usesOpenClosedState = useOpenClosed();
13
+ const hasOpen = $derived(open !== void 0 || usesOpenClosedState);
14
+ const hasOnClose = $derived(rest.hasOwnProperty("onclose"));
15
+ $effect(() => {
16
+ if (!hasOpen && !hasOnClose) {
17
+ throw new Error(`You have to provide an \`open\` and an \`onclose\` prop to the \`Dialog\` component.`);
18
+ }
19
+ if (!hasOpen) {
20
+ throw new Error(`You provided an \`onclose\` prop to the \`Dialog\`, but forgot an \`open\` prop.`);
21
+ }
22
+ if (!hasOnClose) {
23
+ throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but forgot an \`onclose\` prop.`);
24
+ }
25
+ if (!usesOpenClosedState && typeof open !== "boolean") {
26
+ throw new Error(
27
+ `You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${open}`
28
+ );
29
+ }
30
+ if (typeof rest.onclose !== "function") {
31
+ throw new Error(
32
+ `You provided an \`onclose\` prop to the \`Dialog\`, but the value is not a function. Received: ${rest.onclose}`
33
+ );
34
+ }
35
+ });
36
+ const DialogComponent = InternalDialog;
72
37
  </script>
73
38
 
74
39
  {#if (open !== undefined || transition) && !rest.static}
@@ -1,34 +1,17 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props } from "../utils/types.js"
3
-
4
- let DEFAULT_BACKDROP_TAG = "div" as const
5
- type BackdropRenderPropArg = {
6
- open: boolean
7
- }
8
-
9
- export type DialogBackdropProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = Props<
10
- TTag,
11
- BackdropRenderPropArg,
12
- never,
13
- { transition?: boolean }
14
- >
1
+ <script lang="ts" module>let DEFAULT_BACKDROP_TAG = "div";
15
2
  </script>
16
3
 
17
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG">
18
- import { DialogStates, useDialogContext } from "./context.svelte.js"
19
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
20
- import { mergeProps } from "../utils/render.js"
21
- import TransitionChild from "../transition/TransitionChild.svelte"
22
-
23
- let { ref = $bindable(), transition = false, ...theirProps }: { as?: TTag } & DialogBackdropProps<TTag> = $props()
24
- const _state = useDialogContext("Dialog.Panel")
25
- const { dialogState, unmount } = $derived(_state)
26
-
27
- const slot = $derived({ open: dialogState === DialogStates.Open } satisfies BackdropRenderPropArg)
28
-
29
- const ourProps = mergeProps({
30
- "aria-hidden": true,
31
- })
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG">import { DialogStates, useDialogContext } from "./context.svelte.js";
5
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte";
6
+ import { mergeProps } from "../utils/render.js";
7
+ import TransitionChild from "../transition/TransitionChild.svelte";
8
+ let { ref = $bindable(), transition = false, ...theirProps } = $props();
9
+ const _state = useDialogContext("Dialog.Panel");
10
+ const { dialogState, unmount } = $derived(_state);
11
+ const slot = $derived({ open: dialogState === DialogStates.Open });
12
+ const ourProps = mergeProps({
13
+ "aria-hidden": true
14
+ });
32
15
  </script>
33
16
 
34
17
  {#if transition}
@@ -1,54 +1,31 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props } from "../utils/types.js"
3
-
4
- let DEFAULT_PANEL_TAG = "div" as const
5
- type PanelRenderPropArg = {
6
- open: boolean
7
- }
8
-
9
- export type DialogPanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<
10
- TTag,
11
- PanelRenderPropArg,
12
- never,
13
- {
14
- id?: string
15
- transition?: boolean
16
- }
17
- >
1
+ <script lang="ts" module>let DEFAULT_PANEL_TAG = "div";
18
2
  </script>
19
3
 
20
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">
21
- import { useId } from "../hooks/use-id.js"
22
- import { DialogStates, useDialogContext } from "./context.svelte.js"
23
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
24
- import { mergeProps } from "../utils/render.js"
25
- import TransitionChild from "../transition/TransitionChild.svelte"
26
- import { onMount } from "svelte"
27
-
28
- let internalId = useId()
29
- let {
30
- ref = $bindable(),
31
- id = `headlessui-dialog-panel-${internalId}`,
32
- transition = false,
33
- ...theirProps
34
- }: { as?: TTag } & DialogPanelProps<TTag> = $props()
35
- const _state = useDialogContext("Dialog.Panel")
36
- const { dialogState, unmount } = $derived(_state)
37
-
38
- const slot = $derived({ open: dialogState === DialogStates.Open } satisfies PanelRenderPropArg)
39
-
40
- // Prevent the click events inside the Dialog.Panel from bubbling through the React Tree which
41
- // could submit wrapping <form> elements even if we portalled the Dialog.
42
- const handleClick = (event: MouseEvent) => {
43
- event.stopPropagation()
44
- }
45
-
46
- const ourProps = $derived(
47
- mergeProps({
48
- id,
49
- onclick: handleClick,
50
- })
51
- )
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_PANEL_TAG">import { useId } from "../hooks/use-id.js";
5
+ import { DialogStates, useDialogContext } from "./context.svelte.js";
6
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte";
7
+ import { mergeProps } from "../utils/render.js";
8
+ import TransitionChild from "../transition/TransitionChild.svelte";
9
+ import { onMount } from "svelte";
10
+ let internalId = useId();
11
+ let {
12
+ ref = $bindable(),
13
+ id = `headlessui-dialog-panel-${internalId}`,
14
+ transition = false,
15
+ ...theirProps
16
+ } = $props();
17
+ const _state = useDialogContext("Dialog.Panel");
18
+ const { dialogState, unmount } = $derived(_state);
19
+ const slot = $derived({ open: dialogState === DialogStates.Open });
20
+ const handleClick = (event) => {
21
+ event.stopPropagation();
22
+ };
23
+ const ourProps = $derived(
24
+ mergeProps({
25
+ id,
26
+ onclick: handleClick
27
+ })
28
+ );
52
29
  </script>
53
30
 
54
31
  {#if transition}
@@ -1,44 +1,29 @@
1
- <script lang="ts" module>
2
- import type { ElementType, Props, PropsOf } from "../utils/types.js"
3
-
4
- let DEFAULT_TITLE_TAG = "h2" as const
5
- type TitleRenderPropArg = {
6
- open: boolean
7
- }
8
-
9
- export type DialogTitleProps<TTag extends ElementType = typeof DEFAULT_TITLE_TAG> = Props<TTag, TitleRenderPropArg>
10
-
11
- //
1
+ <script lang="ts" module>let DEFAULT_TITLE_TAG = "h2";
12
2
  </script>
13
3
 
14
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TITLE_TAG">
15
- import { useId } from "../hooks/use-id.js"
16
- import { DialogStates, useDialogContext } from "./context.svelte.js"
17
- import { onMount } from "svelte"
18
- import ElementOrComponent from "../utils/ElementOrComponent.svelte"
19
- import { mergeProps } from "../utils/render.js"
20
-
21
- const internalId = useId()
22
- let {
23
- ref = $bindable(),
24
- id = `headlessui-dialog-title-${internalId}` as PropsOf<TTag>[string],
25
- ...theirProps
26
- }: { as?: TTag } & DialogTitleProps<TTag> = $props()
27
- const _state = useDialogContext("Dialog.Panel")
28
- const { dialogState, setTitleId } = $derived(_state)
29
-
30
- onMount(() => {
31
- setTitleId(id)
32
- return () => setTitleId(null)
4
+ <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TITLE_TAG">import { useId } from "../hooks/use-id.js";
5
+ import { DialogStates, useDialogContext } from "./context.svelte.js";
6
+ import { onMount } from "svelte";
7
+ import ElementOrComponent from "../utils/ElementOrComponent.svelte";
8
+ import { mergeProps } from "../utils/render.js";
9
+ const internalId = useId();
10
+ let {
11
+ ref = $bindable(),
12
+ id = `headlessui-dialog-title-${internalId}`,
13
+ ...theirProps
14
+ } = $props();
15
+ const _state = useDialogContext("Dialog.Panel");
16
+ const { dialogState, setTitleId } = $derived(_state);
17
+ onMount(() => {
18
+ setTitleId(id);
19
+ return () => setTitleId(null);
20
+ });
21
+ const slot = $derived({ open: dialogState === DialogStates.Open });
22
+ const ourProps = $derived(
23
+ mergeProps({
24
+ id
33
25
  })
34
-
35
- const slot = $derived({ open: dialogState === DialogStates.Open } satisfies TitleRenderPropArg)
36
-
37
- const ourProps = $derived(
38
- mergeProps({
39
- id,
40
- })
41
- )
26
+ );
42
27
  </script>
43
28
 
44
29
  <ElementOrComponent {ourProps} {theirProps} slots={slot} defaultTag={DEFAULT_TITLE_TAG} name="DialogTitle" bind:ref />