ui-ingredients 0.0.31 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/dist/checkbox/create-checkbox.svelte.js +10 -0
- package/dist/combobox/create-combobox.svelte.js +10 -0
- package/dist/date-picker/anatomy.d.ts +2 -2
- package/dist/editable/create-editable.svelte.js +10 -0
- package/dist/field/context.svelte.d.ts +1 -0
- package/dist/field/context.svelte.js +2 -1
- package/dist/field/create-field.svelte.d.ts +11 -0
- package/dist/field/create-field.svelte.js +40 -20
- package/dist/file-upload/create-file-upload.svelte.js +8 -0
- package/dist/number-input/create-number-input.svelte.js +10 -0
- package/dist/pin-input/anatomy.d.ts +2 -2
- package/dist/pin-input/create-pin-input.svelte.js +10 -0
- package/dist/rating-group/create-rating-group.svelte.js +9 -0
- package/dist/segment-group/anatomy.d.ts +2 -2
- package/dist/select/create-select.svelte.js +10 -0
- package/dist/switch/create-switch.svelte.js +10 -0
- package/dist/tags-input/create-tags-input.svelte.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as checkbox from '@zag-js/checkbox';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createCheckbox(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(checkbox.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
invalid: field?.invalid,
|
17
|
+
disabled: field?.disabled,
|
18
|
+
readOnly: field?.readOnly,
|
19
|
+
required: field?.required,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as combobox from '@zag-js/combobox';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
@@ -10,9 +11,18 @@ export function createCombobox(props) {
|
|
10
11
|
itemToString: (item) => props.itemToString ? props.itemToString(item) : String(item),
|
11
12
|
isItemDisabled: (item) => props.isItemDisabled ? props.isItemDisabled(item) : false,
|
12
13
|
}));
|
14
|
+
const field = getFieldContext();
|
13
15
|
const locale = getLocaleContext();
|
14
16
|
const environment = getEnvironmentContext();
|
15
17
|
const [state, send] = useMachine(combobox.machine({
|
18
|
+
ids: {
|
19
|
+
label: field?.ids.label,
|
20
|
+
input: field?.ids.control,
|
21
|
+
},
|
22
|
+
invalid: field?.invalid,
|
23
|
+
required: field?.required,
|
24
|
+
disabled: field?.disabled,
|
25
|
+
readOnly: field?.readOnly,
|
16
26
|
...props,
|
17
27
|
id: props.id ?? uid(),
|
18
28
|
dir: locale?.dir,
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"input" | "label" | "table" | "view" | "root" | "content" | "
|
2
|
-
export declare const parts: Record<"input" | "label" | "table" | "view" | "root" | "content" | "
|
1
|
+
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"input" | "label" | "table" | "view" | "root" | "control" | "content" | "trigger" | "clearTrigger" | "positioner" | "monthSelect" | "nextTrigger" | "prevTrigger" | "rangeText" | "tableBody" | "tableCell" | "tableCellTrigger" | "tableHead" | "tableHeader" | "tableRow" | "viewTrigger" | "viewControl" | "yearSelect" | "presetTrigger">;
|
2
|
+
export declare const parts: Record<"input" | "label" | "table" | "view" | "root" | "control" | "content" | "trigger" | "clearTrigger" | "positioner" | "monthSelect" | "nextTrigger" | "prevTrigger" | "rangeText" | "tableBody" | "tableCell" | "tableCellTrigger" | "tableHead" | "tableHeader" | "tableRow" | "viewTrigger" | "viewControl" | "yearSelect" | "presetTrigger", import("@zag-js/anatomy").AnatomyPart>;
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as editable from '@zag-js/editable';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createEditable(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(editable.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
input: field?.ids.control,
|
15
|
+
},
|
16
|
+
invalid: field?.invalid,
|
17
|
+
disabled: field?.disabled,
|
18
|
+
readOnly: field?.readOnly,
|
19
|
+
required: field?.required,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|
@@ -17,6 +17,17 @@ export interface CreateFieldProps {
|
|
17
17
|
export interface CreateFieldReturn extends ReturnType<typeof createField> {
|
18
18
|
}
|
19
19
|
export declare function createField(props: CreateFieldProps): {
|
20
|
+
readonly ids: {
|
21
|
+
root: string;
|
22
|
+
label: string;
|
23
|
+
control: string;
|
24
|
+
errorText: string;
|
25
|
+
helperText: string;
|
26
|
+
};
|
27
|
+
readonly disabled: boolean;
|
28
|
+
readonly required: boolean;
|
29
|
+
readonly readOnly: boolean;
|
30
|
+
readonly invalid: boolean;
|
20
31
|
getRootProps: () => HTMLProps<"div">;
|
21
32
|
getLabelProps: () => HTMLProps<"label">;
|
22
33
|
getErrorTextProps: () => HTMLProps<"div">;
|
@@ -1,11 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { ariaAttr, dataAttr, getDocument, getWindow } from '@zag-js/dom-query';
|
2
3
|
import { uid } from 'uid';
|
3
4
|
import { parts } from './anatomy.js';
|
4
5
|
export function createField(props) {
|
6
|
+
const environment = getEnvironmentContext();
|
5
7
|
const id_ = uid();
|
6
8
|
const {
|
7
9
|
/**/
|
8
|
-
ids, invalid, disabled, required,
|
10
|
+
ids, invalid, disabled, required, readOnly, } = $derived.by(() => {
|
9
11
|
const id = props.id ?? id_;
|
10
12
|
const ids = {
|
11
13
|
root: props.ids?.root ?? `field:${id}`,
|
@@ -19,7 +21,7 @@ export function createField(props) {
|
|
19
21
|
invalid: props.invalid ?? false,
|
20
22
|
required: props.required ?? false,
|
21
23
|
disabled: props.disabled ?? false,
|
22
|
-
|
24
|
+
readOnly: props.readOnly ?? false,
|
23
25
|
};
|
24
26
|
});
|
25
27
|
let hasErrorText = $state(false);
|
@@ -35,14 +37,17 @@ export function createField(props) {
|
|
35
37
|
return l.join(' ');
|
36
38
|
});
|
37
39
|
$effect(() => {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
hasHelperText = true;
|
40
|
+
const rootNode = environment?.getRootNode() ?? document;
|
41
|
+
const doc = getDocument(rootNode);
|
42
|
+
const win = getWindow(rootNode);
|
43
|
+
function handler() {
|
44
|
+
hasErrorText = invalid && doc.getElementById(ids.errorText) !== null;
|
45
|
+
hasHelperText = doc.getElementById(ids.helperText) !== null;
|
45
46
|
}
|
47
|
+
handler();
|
48
|
+
const observer = new win.MutationObserver(handler);
|
49
|
+
observer.observe(rootNode, { childList: true, subtree: true });
|
50
|
+
return () => observer.disconnect();
|
46
51
|
});
|
47
52
|
function getRootProps() {
|
48
53
|
return {
|
@@ -52,7 +57,7 @@ export function createField(props) {
|
|
52
57
|
'data-invalid': dataAttr(invalid),
|
53
58
|
'data-disabled': dataAttr(disabled),
|
54
59
|
'data-required': dataAttr(required),
|
55
|
-
'data-readonly': dataAttr(
|
60
|
+
'data-readonly': dataAttr(readOnly),
|
56
61
|
};
|
57
62
|
}
|
58
63
|
function getLabelProps() {
|
@@ -63,7 +68,7 @@ export function createField(props) {
|
|
63
68
|
'data-invalid': dataAttr(invalid),
|
64
69
|
'data-disabled': dataAttr(disabled),
|
65
70
|
'data-required': dataAttr(required),
|
66
|
-
'data-readonly': dataAttr(
|
71
|
+
'data-readonly': dataAttr(readOnly),
|
67
72
|
};
|
68
73
|
}
|
69
74
|
function getErrorTextProps() {
|
@@ -74,7 +79,7 @@ export function createField(props) {
|
|
74
79
|
'data-invalid': dataAttr(invalid),
|
75
80
|
'data-disabled': dataAttr(disabled),
|
76
81
|
'data-required': dataAttr(required),
|
77
|
-
'data-readonly': dataAttr(
|
82
|
+
'data-readonly': dataAttr(readOnly),
|
78
83
|
};
|
79
84
|
}
|
80
85
|
function getHelperTextProps() {
|
@@ -83,7 +88,7 @@ export function createField(props) {
|
|
83
88
|
'data-invalid': dataAttr(invalid),
|
84
89
|
'data-disabled': dataAttr(disabled),
|
85
90
|
'data-required': dataAttr(required),
|
86
|
-
'data-readonly': dataAttr(
|
91
|
+
'data-readonly': dataAttr(readOnly),
|
87
92
|
};
|
88
93
|
}
|
89
94
|
function getInputProps() {
|
@@ -92,13 +97,13 @@ export function createField(props) {
|
|
92
97
|
id: ids.control,
|
93
98
|
disabled,
|
94
99
|
required,
|
95
|
-
readonly,
|
100
|
+
readonly: readOnly,
|
96
101
|
'aria-invalid': ariaAttr(invalid),
|
97
102
|
'aria-describedby': ariaDescribedby,
|
98
103
|
'data-invalid': dataAttr(invalid),
|
99
104
|
'data-disabled': dataAttr(disabled),
|
100
105
|
'data-required': dataAttr(required),
|
101
|
-
'data-readonly': dataAttr(
|
106
|
+
'data-readonly': dataAttr(readOnly),
|
102
107
|
};
|
103
108
|
}
|
104
109
|
function getSelectProps() {
|
@@ -108,12 +113,12 @@ export function createField(props) {
|
|
108
113
|
disabled,
|
109
114
|
required,
|
110
115
|
'aria-invalid': ariaAttr(invalid),
|
111
|
-
'aria-readonly': ariaAttr(
|
116
|
+
'aria-readonly': ariaAttr(readOnly),
|
112
117
|
'aria-describedby': ariaDescribedby,
|
113
118
|
'data-invalid': dataAttr(invalid),
|
114
119
|
'data-disabled': dataAttr(disabled),
|
115
120
|
'data-required': dataAttr(required),
|
116
|
-
'data-readonly': dataAttr(
|
121
|
+
'data-readonly': dataAttr(readOnly),
|
117
122
|
};
|
118
123
|
}
|
119
124
|
function getTextareaProps() {
|
@@ -122,15 +127,30 @@ export function createField(props) {
|
|
122
127
|
id: ids.control,
|
123
128
|
disabled,
|
124
129
|
required,
|
125
|
-
readonly,
|
130
|
+
readonly: readOnly,
|
126
131
|
'aria-describedby': ariaDescribedby,
|
127
132
|
'data-invalid': dataAttr(invalid),
|
128
133
|
'data-disabled': dataAttr(disabled),
|
129
134
|
'data-required': dataAttr(required),
|
130
|
-
'data-readonly': dataAttr(
|
135
|
+
'data-readonly': dataAttr(readOnly),
|
131
136
|
};
|
132
137
|
}
|
133
138
|
return {
|
139
|
+
get ids() {
|
140
|
+
return ids;
|
141
|
+
},
|
142
|
+
get disabled() {
|
143
|
+
return disabled;
|
144
|
+
},
|
145
|
+
get required() {
|
146
|
+
return required;
|
147
|
+
},
|
148
|
+
get readOnly() {
|
149
|
+
return readOnly;
|
150
|
+
},
|
151
|
+
get invalid() {
|
152
|
+
return invalid;
|
153
|
+
},
|
134
154
|
getRootProps,
|
135
155
|
getLabelProps,
|
136
156
|
getErrorTextProps,
|
@@ -1,12 +1,20 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as fileUpload from '@zag-js/file-upload';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createFileUpload(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(fileUpload.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
disabled: field?.disabled,
|
17
|
+
required: field?.required,
|
10
18
|
...props,
|
11
19
|
id: props.id ?? uid(),
|
12
20
|
dir: locale?.dir,
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as numberInput from '@zag-js/number-input';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createNumberInput(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(numberInput.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
input: field?.ids.control,
|
15
|
+
},
|
16
|
+
invalid: field?.invalid,
|
17
|
+
disabled: field?.disabled,
|
18
|
+
readOnly: field?.readOnly,
|
19
|
+
required: field?.required,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"input" | "label" | "root" | "
|
2
|
-
export declare const parts: Record<"input" | "label" | "root" | "
|
1
|
+
export declare const anatomy: import("@zag-js/anatomy").AnatomyInstance<"input" | "label" | "root" | "control" | "clearTrigger">;
|
2
|
+
export declare const parts: Record<"input" | "label" | "root" | "control" | "clearTrigger", import("@zag-js/anatomy").AnatomyPart>;
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as pinInput from '@zag-js/pin-input';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createPinInputContext(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(pinInput.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
invalid: field?.invalid,
|
17
|
+
required: field?.required,
|
18
|
+
disabled: field?.disabled,
|
19
|
+
readOnly: field?.readOnly,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|
@@ -1,12 +1,21 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as ratingGroup from '@zag-js/rating-group';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createRatingGroup(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(ratingGroup.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
required: field?.required,
|
17
|
+
disabled: field?.disabled,
|
18
|
+
readOnly: field?.readOnly,
|
10
19
|
...props,
|
11
20
|
id: props.id ?? uid(),
|
12
21
|
dir: locale?.dir,
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const anatomy: import("@zag-js/anatomy").Anatomy<"label" | "
|
2
|
-
export declare const parts: Record<"label" | "
|
1
|
+
export declare const anatomy: import("@zag-js/anatomy").Anatomy<"label" | "root" | "item" | "itemText" | "itemControl" | "indicator">;
|
2
|
+
export declare const parts: Record<"label" | "root" | "item" | "itemText" | "itemControl" | "indicator", import("@zag-js/anatomy").AnatomyPart>;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import * as select from '@zag-js/select';
|
4
5
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
@@ -10,9 +11,18 @@ export function createSelect(props) {
|
|
10
11
|
itemToString: (item) => props.itemToString ? props.itemToString(item) : String(item),
|
11
12
|
isItemDisabled: (item) => props.isItemDisabled ? props.isItemDisabled(item) : false,
|
12
13
|
}));
|
14
|
+
const field = getFieldContext();
|
13
15
|
const locale = getLocaleContext();
|
14
16
|
const environment = getEnvironmentContext();
|
15
17
|
const [state, send] = useMachine(select.machine({
|
18
|
+
ids: {
|
19
|
+
label: field?.ids.label,
|
20
|
+
hiddenSelect: field?.ids.control,
|
21
|
+
},
|
22
|
+
invalid: field?.invalid,
|
23
|
+
disabled: field?.disabled,
|
24
|
+
readOnly: field?.readOnly,
|
25
|
+
required: field?.required,
|
16
26
|
...props,
|
17
27
|
id: props.id ?? uid(),
|
18
28
|
dir: locale?.dir,
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
4
5
|
import * as switch$ from '@zag-js/switch';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createSwitch(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(switch$.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
disabled: field?.disabled,
|
17
|
+
readOnly: field?.readOnly,
|
18
|
+
invalid: field?.invalid,
|
19
|
+
required: field?.required,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { getEnvironmentContext } from '../environment-provider/context.svelte.js';
|
2
|
+
import { getFieldContext } from '../field/context.svelte.js';
|
2
3
|
import { getLocaleContext } from '../locale-provider/context.svelte.js';
|
3
4
|
import { normalizeProps, reflect, useMachine } from '@zag-js/svelte';
|
4
5
|
import * as tagsInput from '@zag-js/tags-input';
|
5
6
|
import { uid } from 'uid';
|
6
7
|
export function createTagsInput(props) {
|
8
|
+
const field = getFieldContext();
|
7
9
|
const locale = getLocaleContext();
|
8
10
|
const environment = getEnvironmentContext();
|
9
11
|
const [state, send] = useMachine(tagsInput.machine({
|
12
|
+
ids: {
|
13
|
+
label: field?.ids.label,
|
14
|
+
hiddenInput: field?.ids.control,
|
15
|
+
},
|
16
|
+
invalid: field?.invalid,
|
17
|
+
disabled: field?.disabled,
|
18
|
+
readOnly: field?.readOnly,
|
19
|
+
required: field?.required,
|
10
20
|
...props,
|
11
21
|
id: props.id ?? uid(),
|
12
22
|
dir: locale?.dir,
|