ui-ingredients 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,6 @@ export function createField(props) {
25
25
  readOnly: props.readOnly ?? false,
26
26
  };
27
27
  });
28
- let focused = $state(false);
29
28
  let hasErrorText = $state(false);
30
29
  let hasHelperText = $state(false);
31
30
  const ariaDescribedby = $derived.by(() => {
@@ -47,7 +46,6 @@ export function createField(props) {
47
46
  'data-disabled': dataAttr(disabled),
48
47
  'data-required': dataAttr(required),
49
48
  'data-readonly': dataAttr(readOnly),
50
- 'data-focus': dataAttr(focused),
51
49
  };
52
50
  }
53
51
  function getLabelProps() {
@@ -59,7 +57,6 @@ export function createField(props) {
59
57
  'data-disabled': dataAttr(disabled),
60
58
  'data-required': dataAttr(required),
61
59
  'data-readonly': dataAttr(readOnly),
62
- 'data-focus': dataAttr(focused),
63
60
  };
64
61
  }
65
62
  function getRequiredIndicatorProps() {
@@ -70,7 +67,6 @@ export function createField(props) {
70
67
  'data-invalid': dataAttr(invalid),
71
68
  'data-disabled': dataAttr(disabled),
72
69
  'data-readonly': dataAttr(readOnly),
73
- 'data-focus': dataAttr(focused),
74
70
  };
75
71
  }
76
72
  function getErrorTextProps() {
@@ -83,7 +79,6 @@ export function createField(props) {
83
79
  'data-disabled': dataAttr(disabled),
84
80
  'data-required': dataAttr(required),
85
81
  'data-readonly': dataAttr(readOnly),
86
- 'data-focus': dataAttr(focused),
87
82
  };
88
83
  }
89
84
  function getHelperTextProps() {
@@ -94,20 +89,11 @@ export function createField(props) {
94
89
  'data-disabled': dataAttr(disabled),
95
90
  'data-required': dataAttr(required),
96
91
  'data-readonly': dataAttr(readOnly),
97
- 'data-focus': dataAttr(focused),
98
92
  };
99
93
  }
100
- function onfocus() {
101
- focused = true;
102
- }
103
- function onblur() {
104
- focused = false;
105
- }
106
94
  function getControlProps() {
107
95
  return {
108
96
  id: ids.control,
109
- onfocus,
110
- onblur,
111
97
  disabled,
112
98
  required,
113
99
  'aria-describedby': ariaDescribedby,
@@ -119,7 +105,6 @@ export function createField(props) {
119
105
  'data-disabled': dataAttr(disabled),
120
106
  'data-required': dataAttr(required),
121
107
  'data-readonly': dataAttr(readOnly),
122
- 'data-focus': dataAttr(focused),
123
108
  };
124
109
  }
125
110
  function getInputProps() {
@@ -161,7 +146,6 @@ export function createField(props) {
161
146
  required,
162
147
  readOnly,
163
148
  invalid,
164
- focused,
165
149
  'aria-describedby': ariaDescribedby,
166
150
  getRootProps,
167
151
  getLabelProps,
@@ -1,12 +1,16 @@
1
1
  <script lang="ts" module>
2
2
  import type {HtmlIngredientProps} from '../types.js';
3
+ import type {Action} from 'svelte/action';
3
4
 
4
5
  export interface FieldErrorTextProps
5
- extends HtmlIngredientProps<'div', HTMLDivElement> {}
6
+ extends HtmlIngredientProps<'div', HTMLDivElement, never, Action> {}
6
7
  </script>
7
8
 
8
9
  <script lang="ts">
9
10
  import {mergeProps} from '../merge-props.js';
11
+ import {createPresence} from '../presence/create-presence.svelte.js';
12
+ import {getPresenceStrategyPropsContext} from '../presence/presence-context.svelte.js';
13
+ import {reflect} from '@zag-js/svelte';
10
14
  import {getFieldContext} from './field-context.svelte.js';
11
15
 
12
16
  let {
@@ -18,15 +22,29 @@
18
22
 
19
23
  let field = getFieldContext();
20
24
 
25
+ let presenceStrategyProps = getPresenceStrategyPropsContext();
26
+ let presence = createPresence(
27
+ reflect(() => ({
28
+ present: field?.invalid ?? true,
29
+ ...presenceStrategyProps,
30
+ })),
31
+ );
32
+
21
33
  let mergedProps = $derived(
22
- mergeProps(field?.getErrorTextProps() ?? {}, props),
34
+ mergeProps(
35
+ field?.getErrorTextProps() ?? {},
36
+ presence.getPresenceProps(),
37
+ props,
38
+ ),
23
39
  );
24
40
  </script>
25
41
 
26
- {#if asChild}
27
- {@render asChild(mergedProps)}
28
- {:else}
29
- <div bind:this={ref} {...mergedProps}>
30
- {@render children?.()}
31
- </div>
42
+ {#if presence.mounted}
43
+ {#if asChild}
44
+ {@render asChild(presence.setReference, mergedProps)}
45
+ {:else}
46
+ <div use:presence.setReference bind:this={ref} {...mergedProps}>
47
+ {@render children?.()}
48
+ </div>
49
+ {/if}
32
50
  {/if}
@@ -1,5 +1,6 @@
1
1
  import type { HtmlIngredientProps } from '../types.js';
2
- export interface FieldErrorTextProps extends HtmlIngredientProps<'div', HTMLDivElement> {
2
+ import type { Action } from 'svelte/action';
3
+ export interface FieldErrorTextProps extends HtmlIngredientProps<'div', HTMLDivElement, never, Action> {
3
4
  }
4
5
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
6
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
@@ -7,13 +7,16 @@
7
7
 
8
8
  export interface FieldProps
9
9
  extends Assign<
10
- HtmlIngredientProps<'div', HTMLDivElement, CreateFieldReturn>,
11
- CreateFieldProps
12
- > {}
10
+ HtmlIngredientProps<'div', HTMLDivElement, CreateFieldReturn>,
11
+ CreateFieldProps
12
+ >,
13
+ PresenceStrategyProps {}
13
14
  </script>
14
15
 
15
16
  <script lang="ts">
16
17
  import {mergeProps} from '../merge-props.js';
18
+ import type {PresenceStrategyProps} from '../presence/create-presence.svelte.js';
19
+ import {setPresenceStrategyPropsContext} from '../presence/presence-context.svelte.js';
17
20
  import {reflect} from '@zag-js/svelte';
18
21
  import {createSplitProps} from '@zag-js/utils';
19
22
  import {createField} from './create-field.svelte.js';
@@ -26,6 +29,12 @@
26
29
  ...props
27
30
  }: FieldProps = $props();
28
31
 
32
+ let [presenceStrategyProps, rest] = $derived(
33
+ createSplitProps<PresenceStrategyProps>(['keepMounted', 'lazyMount'])(
34
+ props,
35
+ ),
36
+ );
37
+
29
38
  let [createFieldProps, localProps] = $derived(
30
39
  createSplitProps<CreateFieldProps>([
31
40
  'id',
@@ -34,7 +43,7 @@
34
43
  'disabled',
35
44
  'readOnly',
36
45
  'required',
37
- ])(props),
46
+ ])(rest),
38
47
  );
39
48
 
40
49
  let field = createField(reflect(() => createFieldProps));
@@ -42,6 +51,7 @@
42
51
  let mergedProps = $derived(mergeProps(field.getRootProps(), localProps));
43
52
 
44
53
  setFieldContext(field);
54
+ setPresenceStrategyPropsContext(() => presenceStrategyProps);
45
55
  </script>
46
56
 
47
57
  {#if asChild}
@@ -1,7 +1,8 @@
1
1
  import type { Assign, HtmlIngredientProps } from '../types.js';
2
2
  import type { CreateFieldProps, CreateFieldReturn } from './create-field.svelte.js';
3
- export interface FieldProps extends Assign<HtmlIngredientProps<'div', HTMLDivElement, CreateFieldReturn>, CreateFieldProps> {
3
+ export interface FieldProps extends Assign<HtmlIngredientProps<'div', HTMLDivElement, CreateFieldReturn>, CreateFieldProps>, PresenceStrategyProps {
4
4
  }
5
+ import type { PresenceStrategyProps } from '../presence/create-presence.svelte.js';
5
6
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
6
7
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
7
8
  $$bindings?: Bindings;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ui-ingredients",
3
3
  "type": "module",
4
4
  "license": "MIT",
5
- "version": "0.5.0",
5
+ "version": "0.7.0",
6
6
  "packageManager": "pnpm@9.7.0",
7
7
  "svelte": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -365,29 +365,29 @@
365
365
  "devDependencies": {
366
366
  "@faker-js/faker": "^9.0.3",
367
367
  "@sveltejs/adapter-vercel": "^5.4.5",
368
- "@sveltejs/kit": "^2.7.0",
368
+ "@sveltejs/kit": "^2.7.1",
369
369
  "@sveltejs/package": "^2.3.5",
370
370
  "@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
371
371
  "@testing-library/jest-dom": "^6.5.0",
372
372
  "@testing-library/svelte": "^5.2.3",
373
373
  "@testing-library/user-event": "^14.5.2",
374
374
  "@types/jsdom": "^21.1.7",
375
- "@untitled-theme/icons-svelte": "^0.10.10",
375
+ "@untitled-theme/icons-svelte": "^0.10.11",
376
376
  "autoprefixer": "^10.4.20",
377
377
  "globals": "^15.11.0",
378
378
  "jsdom": "^25.0.1",
379
379
  "postcss": "^8.4.47",
380
380
  "publint": "^0.2.11",
381
- "release-it": "^17.8.2",
381
+ "release-it": "^17.9.0",
382
382
  "resize-observer-polyfill": "^1.5.1",
383
- "svelte": "^5.0.0-next.264",
383
+ "svelte": "^5.0.0-next.265",
384
384
  "svelte-check": "^4.0.5",
385
- "tailwind-merge": "^2.5.3",
385
+ "tailwind-merge": "^2.5.4",
386
386
  "tailwind-variants": "^0.2.1",
387
387
  "tailwindcss": "^3.4.13",
388
388
  "typescript": "^5.6.3",
389
- "vite": "^5.4.8",
390
- "vitest": "^2.1.2",
389
+ "vite": "^5.4.9",
390
+ "vitest": "^2.1.3",
391
391
  "vitest-axe": "^1.0.0-pre.3",
392
392
  "vitest-canvas-mock": "^0.3.3"
393
393
  },