ui-ingredients 0.0.41 → 0.0.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/README.md +1 -0
  2. package/dist/accordion/item-content.svelte +17 -6
  3. package/dist/accordion/root.svelte +18 -6
  4. package/dist/color-picker/root.svelte +1 -1
  5. package/dist/combobox/content.svelte +8 -6
  6. package/dist/combobox/positioner.svelte +8 -6
  7. package/dist/combobox/root.svelte +21 -6
  8. package/dist/date-picker/content.svelte +8 -6
  9. package/dist/date-picker/positioner.svelte +8 -6
  10. package/dist/date-picker/root.svelte +21 -6
  11. package/dist/dialog/backdrop.svelte +17 -6
  12. package/dist/dialog/content.svelte +8 -6
  13. package/dist/dialog/positioner.svelte +8 -6
  14. package/dist/dialog/root.svelte +25 -3
  15. package/dist/file-upload/create-file-upload.svelte.js +1 -0
  16. package/dist/file-upload/root.svelte +1 -0
  17. package/dist/floating-panel/create-floating-panel.svelte.d.ts +6 -0
  18. package/dist/floating-panel/create-floating-panel.svelte.js +18 -0
  19. package/dist/hover-card/content.svelte +8 -6
  20. package/dist/hover-card/positioner.svelte +8 -6
  21. package/dist/hover-card/root.svelte +27 -2
  22. package/dist/menu/content.svelte +8 -6
  23. package/dist/menu/positioner.svelte +8 -6
  24. package/dist/menu/root.svelte +38 -2
  25. package/dist/popover/content.svelte +8 -6
  26. package/dist/popover/positioner.svelte +8 -6
  27. package/dist/popover/root.svelte +35 -2
  28. package/dist/portal/root.svelte +32 -28
  29. package/dist/presence/context.svelte.d.ts +2 -1
  30. package/dist/presence/context.svelte.js +1 -0
  31. package/dist/presence/create-presence.svelte.d.ts +9 -2
  32. package/dist/presence/create-presence.svelte.js +25 -5
  33. package/dist/presence/root.svelte +16 -6
  34. package/dist/select/content.svelte +8 -6
  35. package/dist/select/positioner.svelte +8 -6
  36. package/dist/select/root.svelte +19 -4
  37. package/dist/switch/control.svelte +24 -24
  38. package/dist/switch/hidden-input.svelte +23 -23
  39. package/dist/switch/label.svelte +24 -24
  40. package/dist/switch/root.svelte +54 -54
  41. package/dist/switch/thumb.svelte +24 -24
  42. package/dist/time-picker/content.svelte +14 -4
  43. package/dist/time-picker/positioner.svelte +7 -1
  44. package/dist/time-picker/root.svelte +29 -4
  45. package/dist/toast/actor.svelte +19 -19
  46. package/dist/toast/toaster.svelte +39 -39
  47. package/dist/tooltip/content.svelte +8 -6
  48. package/dist/tooltip/positioner.svelte +8 -6
  49. package/dist/tooltip/root.svelte +20 -2
  50. package/dist/tour/create-tour.svelte.d.ts +7 -0
  51. package/dist/tour/create-tour.svelte.js +18 -0
  52. package/package.json +46 -46
  53. package/dist/floating-panel/.gitkeep +0 -0
  54. package/dist/tour/.gitkeep +0 -0
@@ -1,11 +1,14 @@
1
1
  <script lang="ts" module>
2
+ import type {PresenceStrategyProps} from '../presence/create-presence.svelte.js';
2
3
  import type {Snippet} from 'svelte';
3
4
  import {
4
5
  type CreateMenuProps,
5
6
  type CreateMenuReturn,
6
7
  } from './create-menu.svelte.js';
7
8
 
8
- export interface MenuRootProps extends CreateMenuProps {
9
+ export interface MenuRootProps
10
+ extends CreateMenuProps,
11
+ PresenceStrategyProps {
9
12
  children?: Snippet<[CreateMenuReturn]>;
10
13
  }
11
14
  </script>
@@ -13,16 +16,49 @@
13
16
  <script lang="ts">
14
17
  import {setPresenceContext} from '../presence/context.svelte.js';
15
18
  import {createPresence} from '../presence/create-presence.svelte.js';
19
+ import {reflect} from '@zag-js/svelte';
20
+ import {createSplitProps} from '@zag-js/utils';
16
21
  import {setMenuContext} from './context.svelte.js';
17
22
  import {createMenu} from './create-menu.svelte.js';
18
23
 
19
24
  let {children, ...props}: MenuRootProps = $props();
20
25
 
21
- let menu = createMenu(props);
26
+ let [menuProps, presenceStrategyProps] = $derived(
27
+ createSplitProps<CreateMenuProps>([
28
+ 'anchorPoint',
29
+ 'aria-label',
30
+ 'closeOnSelect',
31
+ 'composite',
32
+ 'defaultOpen',
33
+ 'highlightedValue',
34
+ 'id',
35
+ 'ids',
36
+ 'loopFocus',
37
+ 'onEscapeKeyDown',
38
+ 'onFocusOutside',
39
+ 'onHighlightChange',
40
+ 'onInteractOutside',
41
+ 'onOpenChange',
42
+ 'onPointerDownOutside',
43
+ 'onSelect',
44
+ 'open',
45
+ 'positioning',
46
+ 'typeahead',
47
+ ])(props),
48
+ );
49
+
50
+ let menu = createMenu(reflect(() => menuProps));
51
+
22
52
  let presence = createPresence({
23
53
  get present() {
24
54
  return menu.open;
25
55
  },
56
+ get lazyMount() {
57
+ return presenceStrategyProps.lazyMount;
58
+ },
59
+ get keepMounted() {
60
+ return presenceStrategyProps.keepMounted;
61
+ },
26
62
  });
27
63
 
28
64
  setMenuContext(menu);
@@ -21,10 +21,12 @@
21
21
  );
22
22
  </script>
23
23
 
24
- {#if asChild}
25
- {@render asChild(presence.ref, mergedProps)}
26
- {:else}
27
- <div use:presence.ref {...mergedProps}>
28
- {@render children?.()}
29
- </div>
24
+ {#if presence.mounted}
25
+ {#if asChild}
26
+ {@render asChild(presence.ref, mergedProps)}
27
+ {:else}
28
+ <div use:presence.ref {...mergedProps}>
29
+ {@render children?.()}
30
+ </div>
31
+ {/if}
30
32
  {/if}
@@ -23,10 +23,12 @@
23
23
  );
24
24
  </script>
25
25
 
26
- {#if asChild}
27
- {@render asChild(mergedProps)}
28
- {:else}
29
- <div {...mergedProps}>
30
- {@render children?.()}
31
- </div>
26
+ {#if presence.mounted}
27
+ {#if asChild}
28
+ {@render asChild(mergedProps)}
29
+ {:else}
30
+ <div {...mergedProps}>
31
+ {@render children?.()}
32
+ </div>
33
+ {/if}
32
34
  {/if}
@@ -1,11 +1,14 @@
1
1
  <script lang="ts" module>
2
+ import type {PresenceStrategyProps} from '../presence/create-presence.svelte.js';
2
3
  import type {Snippet} from 'svelte';
3
4
  import type {
4
5
  CreatePopoverProps,
5
6
  CreatePopoverReturn,
6
7
  } from './create-popover.svelte.js';
7
8
 
8
- export interface PopoverProps extends CreatePopoverProps {
9
+ export interface PopoverProps
10
+ extends CreatePopoverProps,
11
+ PresenceStrategyProps {
9
12
  children?: Snippet<[CreatePopoverReturn]>;
10
13
  }
11
14
  </script>
@@ -13,16 +16,46 @@
13
16
  <script lang="ts">
14
17
  import {setPresenceContext} from '../presence/context.svelte.js';
15
18
  import {createPresence} from '../presence/create-presence.svelte.js';
19
+ import {reflect} from '@zag-js/svelte';
20
+ import {createSplitProps} from '@zag-js/utils';
16
21
  import {setPopoverContext} from './context.svelte.js';
17
22
  import {createPopover} from './create-popover.svelte.js';
18
23
 
19
24
  let {children, ...props}: PopoverProps = $props();
20
25
 
21
- let popover = createPopover(props);
26
+ let [popoverProps, presenceStrategyProps] = $derived(
27
+ createSplitProps<CreatePopoverProps>([
28
+ 'autoFocus',
29
+ 'closeOnEscape',
30
+ 'closeOnInteractOutside',
31
+ 'defaultOpen',
32
+ 'id',
33
+ 'ids',
34
+ 'initialFocusEl',
35
+ 'modal',
36
+ 'onEscapeKeyDown',
37
+ 'onFocusOutside',
38
+ 'onInteractOutside',
39
+ 'onOpenChange',
40
+ 'onPointerDownOutside',
41
+ 'open',
42
+ 'persistentElements',
43
+ 'portalled',
44
+ 'positioning',
45
+ ])(props),
46
+ );
47
+
48
+ let popover = createPopover(reflect(() => popoverProps));
22
49
  let presence = createPresence({
23
50
  get present() {
24
51
  return popover.open;
25
52
  },
53
+ get lazyMount() {
54
+ return presenceStrategyProps.lazyMount;
55
+ },
56
+ get keepMounted() {
57
+ return presenceStrategyProps.keepMounted;
58
+ },
26
59
  });
27
60
 
28
61
  setPopoverContext(popover);
@@ -1,28 +1,32 @@
1
- <script module lang="ts">
2
- import {type Snippet} from 'svelte';
3
-
4
- export interface PortalProps {
5
- container?: HTMLElement;
6
- disabled?: boolean;
7
- children: Snippet;
8
- }
9
- </script>
10
-
11
- <script lang="ts">
12
- import {getEnvironmentContext} from '../environment-provider/index.js';
13
- import {portal} from '@zag-js/svelte';
14
-
15
- let {container, disabled, children}: PortalProps = $props();
16
-
17
- let environment = getEnvironmentContext();
18
- </script>
19
-
20
- <div
21
- use:portal={{
22
- disabled,
23
- container,
24
- getRootNode: environment?.getRootNode,
25
- }}
26
- >
27
- {@render children?.()}
28
- </div>
1
+ <script module lang="ts">
2
+ import {type Snippet} from 'svelte';
3
+
4
+ export interface PortalProps {
5
+ container?: HTMLElement;
6
+ disabled?: boolean;
7
+ children: Snippet;
8
+ [x: `data-${string}`]: string | number | boolean | null | undefined;
9
+ }
10
+ </script>
11
+
12
+ <script lang="ts">
13
+ import {getEnvironmentContext} from '../environment-provider/index.js';
14
+ import {portal} from '@zag-js/svelte';
15
+
16
+ let {container, disabled, children, ...props}: PortalProps = $props();
17
+
18
+ let environment = getEnvironmentContext();
19
+ </script>
20
+
21
+ <div
22
+ use:portal={{
23
+ disabled,
24
+ container,
25
+ getRootNode: environment?.getRootNode,
26
+ }}
27
+ data-scope="portal"
28
+ data-part="root"
29
+ {...props}
30
+ >
31
+ {@render children?.()}
32
+ </div>
@@ -1,2 +1,3 @@
1
- import type { CreatePresenceReturn } from './create-presence.svelte.js';
1
+ import type { CreatePresenceReturn, PresenceStrategyProps } from './create-presence.svelte.js';
2
2
  export declare const getPresenceContext: () => CreatePresenceReturn, setPresenceContext: (context: CreatePresenceReturn | (() => CreatePresenceReturn)) => void;
3
+ export declare const getPresenceStrategyPropsContext: () => PresenceStrategyProps, setPresenceStrategyPropsContext: (context: PresenceStrategyProps | (() => PresenceStrategyProps)) => void;
@@ -1,2 +1,3 @@
1
1
  import { createContext } from '../create-context.svelte.js';
2
2
  export const [getPresenceContext, setPresenceContext] = createContext('Presence');
3
+ export const [getPresenceStrategyPropsContext, setPresenceStrategyPropsContext,] = createContext('PresenceStrategyProps');
@@ -1,10 +1,17 @@
1
1
  import type { HTMLAttributes } from 'svelte/elements';
2
- export interface CreatePresenceProps {
3
- present?: boolean;
2
+ export interface PresenceStrategyProps {
3
+ /** @default false */
4
+ lazyMount?: boolean;
5
+ /** @default true */
6
+ keepMounted?: boolean;
7
+ }
8
+ export interface CreatePresenceProps extends PresenceStrategyProps {
9
+ present: boolean;
4
10
  }
5
11
  export interface CreatePresenceReturn extends ReturnType<typeof createPresence> {
6
12
  }
7
13
  export declare function createPresence(props: CreatePresenceProps): {
8
14
  ref: (node: HTMLElement) => void;
9
15
  getPresenceProps: () => HTMLAttributes<HTMLElement>;
16
+ readonly mounted: boolean;
10
17
  };
@@ -1,10 +1,12 @@
1
1
  import * as presence from '@zag-js/presence';
2
2
  import { normalizeProps, useMachine } from '@zag-js/svelte';
3
- import { tick } from 'svelte';
4
3
  export function createPresence(props) {
4
+ const present = $derived(props.present);
5
+ const lazyMount = $derived(props.lazyMount ?? false);
6
+ const keepMounted = $derived(props.keepMounted ?? true);
5
7
  const context = $derived({
6
8
  get present() {
7
- return props.present;
9
+ return present;
8
10
  },
9
11
  });
10
12
  const [state, send] = useMachine(presence.machine(context), { context });
@@ -15,13 +17,31 @@ export function createPresence(props) {
15
17
  'data-state': context.present ? 'open' : 'closed',
16
18
  };
17
19
  }
20
+ let wasPresent = $state(false);
21
+ $effect(() => {
22
+ if (!api.present)
23
+ return;
24
+ if (wasPresent)
25
+ return;
26
+ wasPresent = true;
27
+ });
28
+ const unmounted = $derived.by(() => {
29
+ if (api.present)
30
+ return false;
31
+ if (!wasPresent && lazyMount)
32
+ return true;
33
+ if (wasPresent && !keepMounted)
34
+ return true;
35
+ return false;
36
+ });
18
37
  function ref(node) {
19
- tick().then(() => {
20
- api.setNode(node);
21
- });
38
+ api.setNode(node);
22
39
  }
23
40
  return {
24
41
  ref,
25
42
  getPresenceProps,
43
+ get mounted() {
44
+ return !unmounted;
45
+ },
26
46
  };
27
47
  }
@@ -1,18 +1,22 @@
1
1
  <script lang="ts" module>
2
- import type {Assign, HtmlProps} from '../types.js';
2
+ import type {Assign, HtmlIngredientProps} from '../types.js';
3
3
  import type {CreatePresenceProps} from './create-presence.svelte.js';
4
4
 
5
5
  export interface PresenceProps
6
- extends Assign<HtmlProps<'div'>, CreatePresenceProps> {}
6
+ extends Assign<
7
+ HtmlIngredientProps<'div', never, Action>,
8
+ CreatePresenceProps
9
+ > {}
7
10
  </script>
8
11
 
9
12
  <script lang="ts">
10
13
  import {mergeProps} from '../merge-props.js';
11
14
  import {reflect} from '@zag-js/svelte';
12
15
  import {createSplitProps} from '@zag-js/utils';
16
+ import type {Action} from 'svelte/action';
13
17
  import {createPresence} from './create-presence.svelte.js';
14
18
 
15
- let {children, ...props}: PresenceProps = $props();
19
+ let {asChild, children, ...props}: PresenceProps = $props();
16
20
 
17
21
  let [presenceProps, otherProps] = $derived(
18
22
  createSplitProps<CreatePresenceProps>(['present'])(props),
@@ -25,6 +29,12 @@
25
29
  );
26
30
  </script>
27
31
 
28
- <div use:presence.ref {...mergedProps}>
29
- {@render children?.()}
30
- </div>
32
+ {#if presence.mounted}
33
+ {#if asChild}
34
+ {@render asChild(presence.ref, mergedProps)}
35
+ {:else}
36
+ <div use:presence.ref {...mergedProps}>
37
+ {@render children?.()}
38
+ </div>
39
+ {/if}
40
+ {/if}
@@ -21,10 +21,12 @@
21
21
  );
22
22
  </script>
23
23
 
24
- {#if asChild}
25
- {@render asChild(presence.ref, mergedProps)}
26
- {:else}
27
- <div use:presence.ref {...mergedProps}>
28
- {@render children?.()}
29
- </div>
24
+ {#if presence.mounted}
25
+ {#if asChild}
26
+ {@render asChild(presence.ref, mergedProps)}
27
+ {:else}
28
+ <div use:presence.ref {...mergedProps}>
29
+ {@render children?.()}
30
+ </div>
31
+ {/if}
30
32
  {/if}
@@ -19,10 +19,12 @@
19
19
  );
20
20
  </script>
21
21
 
22
- {#if asChild}
23
- {@render asChild(mergedProps)}
24
- {:else}
25
- <div {...mergedProps}>
26
- {@render children?.()}
27
- </div>
22
+ {#if presence.mounted}
23
+ {#if asChild}
24
+ {@render asChild(mergedProps)}
25
+ {:else}
26
+ <div {...mergedProps}>
27
+ {@render children?.()}
28
+ </div>
29
+ {/if}
28
30
  {/if}
@@ -1,4 +1,5 @@
1
1
  <script lang="ts" module>
2
+ import type {PresenceStrategyProps} from '../presence/create-presence.svelte.js';
2
3
  import type {Assign, HtmlIngredientProps} from '../types.js';
3
4
  import type {
4
5
  CreateSelectProps,
@@ -7,9 +8,10 @@
7
8
 
8
9
  export interface SelectProps<T>
9
10
  extends Assign<
10
- HtmlIngredientProps<'div', CreateSelectReturn>,
11
- CreateSelectProps<T>
12
- > {}
11
+ HtmlIngredientProps<'div', CreateSelectReturn>,
12
+ CreateSelectProps<T>
13
+ >,
14
+ PresenceStrategyProps {}
13
15
  </script>
14
16
 
15
17
  <script lang="ts" generics="T">
@@ -57,13 +59,26 @@
57
59
  );
58
60
 
59
61
  let select = createSelect(reflect(() => selectProps));
62
+
63
+ let [presenceStrategyProps, elementProps] = $derived(
64
+ createSplitProps<PresenceStrategyProps>(['lazyMount', 'keepMounted'])(
65
+ otherProps,
66
+ ),
67
+ );
68
+
60
69
  let presence = createPresence({
61
70
  get present() {
62
71
  return select.open;
63
72
  },
73
+ get lazyMount() {
74
+ return presenceStrategyProps.lazyMount;
75
+ },
76
+ get keepMounted() {
77
+ return presenceStrategyProps.keepMounted;
78
+ },
64
79
  });
65
80
 
66
- let mergedProps = $derived(mergeProps(otherProps, select.getRootProps()));
81
+ let mergedProps = $derived(mergeProps(elementProps, select.getRootProps()));
67
82
 
68
83
  setSelectContext(select);
69
84
  setPresenceContext(presence);
@@ -1,24 +1,24 @@
1
- <script lang="ts" module>
2
- import type {HtmlIngredientProps} from '../types.js';
3
-
4
- export interface SwitchControlProps extends HtmlIngredientProps<'div'> {}
5
- </script>
6
-
7
- <script lang="ts">
8
- import {mergeProps} from '../merge-props.js';
9
- import {getSwitchContext} from './context.svelte.js';
10
-
11
- let {asChild, children, ...props}: SwitchControlProps = $props();
12
-
13
- let switch$ = getSwitchContext();
14
-
15
- let mergedProps = $derived(mergeProps(props, switch$.getControlProps()));
16
- </script>
17
-
18
- {#if asChild}
19
- {@render asChild(mergedProps)}
20
- {:else}
21
- <div {...mergedProps}>
22
- {@render children?.()}
23
- </div>
24
- {/if}
1
+ <script lang="ts" module>
2
+ import type {HtmlIngredientProps} from '../types.js';
3
+
4
+ export interface SwitchControlProps extends HtmlIngredientProps<'div'> {}
5
+ </script>
6
+
7
+ <script lang="ts">
8
+ import {mergeProps} from '../merge-props.js';
9
+ import {getSwitchContext} from './context.svelte.js';
10
+
11
+ let {asChild, children, ...props}: SwitchControlProps = $props();
12
+
13
+ let switch$ = getSwitchContext();
14
+
15
+ let mergedProps = $derived(mergeProps(props, switch$.getControlProps()));
16
+ </script>
17
+
18
+ {#if asChild}
19
+ {@render asChild(mergedProps)}
20
+ {:else}
21
+ <div {...mergedProps}>
22
+ {@render children?.()}
23
+ </div>
24
+ {/if}
@@ -1,23 +1,23 @@
1
- <script lang="ts" module>
2
- import type {HtmlIngredientProps} from '../types.js';
3
-
4
- export interface SwitchHiddenInputProps
5
- extends HtmlIngredientProps<'input'> {}
6
- </script>
7
-
8
- <script lang="ts">
9
- import {mergeProps} from '../merge-props.js';
10
- import {getSwitchContext} from './context.svelte.js';
11
-
12
- let {asChild, ...props}: SwitchHiddenInputProps = $props();
13
-
14
- let switch$ = getSwitchContext();
15
-
16
- let mergedProps = $derived(mergeProps(props, switch$.getHiddenInputProps()));
17
- </script>
18
-
19
- {#if asChild}
20
- {@render asChild(mergedProps)}
21
- {:else}
22
- <input {...mergedProps} />
23
- {/if}
1
+ <script lang="ts" module>
2
+ import type {HtmlIngredientProps} from '../types.js';
3
+
4
+ export interface SwitchHiddenInputProps
5
+ extends HtmlIngredientProps<'input'> {}
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import {mergeProps} from '../merge-props.js';
10
+ import {getSwitchContext} from './context.svelte.js';
11
+
12
+ let {asChild, ...props}: SwitchHiddenInputProps = $props();
13
+
14
+ let switch$ = getSwitchContext();
15
+
16
+ let mergedProps = $derived(mergeProps(props, switch$.getHiddenInputProps()));
17
+ </script>
18
+
19
+ {#if asChild}
20
+ {@render asChild(mergedProps)}
21
+ {:else}
22
+ <input {...mergedProps} />
23
+ {/if}
@@ -1,24 +1,24 @@
1
- <script lang="ts" module>
2
- import type {HtmlIngredientProps} from '../types.js';
3
-
4
- export interface SwitchLabelProps extends HtmlIngredientProps<'span'> {}
5
- </script>
6
-
7
- <script lang="ts">
8
- import {mergeProps} from '../merge-props.js';
9
- import {getSwitchContext} from './context.svelte.js';
10
-
11
- let {asChild, children, ...props}: SwitchLabelProps = $props();
12
-
13
- let switch$ = getSwitchContext();
14
-
15
- let mergedProps = $derived(mergeProps(props, switch$.getLabelProps()));
16
- </script>
17
-
18
- {#if asChild}
19
- {@render asChild(mergedProps)}
20
- {:else}
21
- <span {...mergedProps}>
22
- {@render children?.()}
23
- </span>
24
- {/if}
1
+ <script lang="ts" module>
2
+ import type {HtmlIngredientProps} from '../types.js';
3
+
4
+ export interface SwitchLabelProps extends HtmlIngredientProps<'span'> {}
5
+ </script>
6
+
7
+ <script lang="ts">
8
+ import {mergeProps} from '../merge-props.js';
9
+ import {getSwitchContext} from './context.svelte.js';
10
+
11
+ let {asChild, children, ...props}: SwitchLabelProps = $props();
12
+
13
+ let switch$ = getSwitchContext();
14
+
15
+ let mergedProps = $derived(mergeProps(props, switch$.getLabelProps()));
16
+ </script>
17
+
18
+ {#if asChild}
19
+ {@render asChild(mergedProps)}
20
+ {:else}
21
+ <span {...mergedProps}>
22
+ {@render children?.()}
23
+ </span>
24
+ {/if}