ui-ingredients 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -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(
|
34
|
+
mergeProps(
|
35
|
+
field?.getErrorTextProps() ?? {},
|
36
|
+
presence.getPresenceProps(),
|
37
|
+
props,
|
38
|
+
),
|
23
39
|
);
|
24
40
|
</script>
|
25
41
|
|
26
|
-
{#if
|
27
|
-
{
|
28
|
-
{
|
29
|
-
|
30
|
-
{
|
31
|
-
|
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
|
-
|
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
|
-
|
11
|
-
|
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
|
-
])(
|
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;
|