@destyler/checkbox 0.0.6 → 0.0.7-beta.1
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.
- package/dist/index.cjs +289 -11
- package/dist/index.d.cts +155 -4
- package/dist/index.d.mts +155 -4
- package/dist/index.d.ts +155 -4
- package/dist/index.mjs +288 -7
- package/package.json +10 -17
- package/README.md +0 -7
- package/dist/component.cjs +0 -212
- package/dist/component.d.cts +0 -346
- package/dist/component.d.mts +0 -346
- package/dist/component.d.ts +0 -346
- package/dist/component.mjs +0 -206
- package/dist/resolver.cjs +0 -21
- package/dist/resolver.d.cts +0 -6
- package/dist/resolver.d.mts +0 -6
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.mjs +0 -18
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,294 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
require('
|
|
5
|
-
require('@
|
|
6
|
-
require('@
|
|
7
|
-
require('@
|
|
8
|
-
require('@
|
|
9
|
-
require('@
|
|
3
|
+
const anatomy$1 = require('@zag-js/anatomy');
|
|
4
|
+
const domQuery = require('@zag-js/dom-query');
|
|
5
|
+
const focusVisible = require('@zag-js/focus-visible');
|
|
6
|
+
const core = require('@zag-js/core');
|
|
7
|
+
const domEvent = require('@zag-js/dom-event');
|
|
8
|
+
const formUtils = require('@zag-js/form-utils');
|
|
9
|
+
const utils = require('@zag-js/utils');
|
|
10
|
+
const types = require('@zag-js/types');
|
|
10
11
|
|
|
12
|
+
const anatomy = anatomy$1.createAnatomy("checkbox").parts("root", "label", "control", "indicator");
|
|
13
|
+
const parts = anatomy.build();
|
|
11
14
|
|
|
15
|
+
const dom = domQuery.createScope({
|
|
16
|
+
getRootId: (ctx) => ctx.ids?.root ?? `checkbox:${ctx.id}`,
|
|
17
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `checkbox:${ctx.id}:label`,
|
|
18
|
+
getControlId: (ctx) => ctx.ids?.control ?? `checkbox:${ctx.id}:control`,
|
|
19
|
+
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `checkbox:${ctx.id}:input`,
|
|
20
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
21
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
22
|
+
});
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
function connect(state, send, normalize) {
|
|
25
|
+
const disabled = state.context.isDisabled;
|
|
26
|
+
const readOnly = state.context.readOnly;
|
|
27
|
+
const focused = !disabled && state.context.focused;
|
|
28
|
+
const focusVisible$1 = !disabled && state.context.focusVisible;
|
|
29
|
+
const checked = state.context.isChecked;
|
|
30
|
+
const indeterminate = state.context.isIndeterminate;
|
|
31
|
+
const dataAttrs = {
|
|
32
|
+
"data-active": domQuery.dataAttr(state.context.active),
|
|
33
|
+
"data-focus": domQuery.dataAttr(focused),
|
|
34
|
+
"data-focus-visible": domQuery.dataAttr(focusVisible$1),
|
|
35
|
+
"data-readonly": domQuery.dataAttr(readOnly),
|
|
36
|
+
"data-hover": domQuery.dataAttr(state.context.hovered),
|
|
37
|
+
"data-disabled": domQuery.dataAttr(disabled),
|
|
38
|
+
"data-state": indeterminate ? "indeterminate" : state.context.checked ? "checked" : "unchecked",
|
|
39
|
+
"data-invalid": domQuery.dataAttr(state.context.invalid)
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
checked,
|
|
43
|
+
disabled,
|
|
44
|
+
indeterminate,
|
|
45
|
+
focused,
|
|
46
|
+
checkedState: state.context.checked,
|
|
47
|
+
setChecked(checked2) {
|
|
48
|
+
send({ type: "CHECKED.SET", checked: checked2, isTrusted: false });
|
|
49
|
+
},
|
|
50
|
+
toggleChecked() {
|
|
51
|
+
send({ type: "CHECKED.TOGGLE", checked, isTrusted: false });
|
|
52
|
+
},
|
|
53
|
+
getRootProps() {
|
|
54
|
+
return normalize.label({
|
|
55
|
+
...parts.root.attrs,
|
|
56
|
+
...dataAttrs,
|
|
57
|
+
dir: state.context.dir,
|
|
58
|
+
id: dom.getRootId(state.context),
|
|
59
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
60
|
+
onPointerMove() {
|
|
61
|
+
if (disabled)
|
|
62
|
+
return;
|
|
63
|
+
send({ type: "CONTEXT.SET", context: { hovered: true } });
|
|
64
|
+
},
|
|
65
|
+
onPointerLeave() {
|
|
66
|
+
if (disabled)
|
|
67
|
+
return;
|
|
68
|
+
send({ type: "CONTEXT.SET", context: { hovered: false } });
|
|
69
|
+
},
|
|
70
|
+
onClick(event) {
|
|
71
|
+
const target = domQuery.getEventTarget(event);
|
|
72
|
+
if (target === dom.getHiddenInputEl(state.context)) {
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
getLabelProps() {
|
|
79
|
+
return normalize.element({
|
|
80
|
+
...parts.label.attrs,
|
|
81
|
+
...dataAttrs,
|
|
82
|
+
dir: state.context.dir,
|
|
83
|
+
id: dom.getLabelId(state.context)
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
getControlProps() {
|
|
87
|
+
return normalize.element({
|
|
88
|
+
...parts.control.attrs,
|
|
89
|
+
...dataAttrs,
|
|
90
|
+
"dir": state.context.dir,
|
|
91
|
+
"id": dom.getControlId(state.context),
|
|
92
|
+
"aria-hidden": true
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
getIndicatorProps() {
|
|
96
|
+
return normalize.element({
|
|
97
|
+
...parts.indicator.attrs,
|
|
98
|
+
...dataAttrs,
|
|
99
|
+
dir: state.context.dir,
|
|
100
|
+
hidden: !indeterminate && !state.context.checked
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
getHiddenInputProps() {
|
|
104
|
+
return normalize.input({
|
|
105
|
+
"id": dom.getHiddenInputId(state.context),
|
|
106
|
+
"type": "checkbox",
|
|
107
|
+
"required": state.context.required,
|
|
108
|
+
"defaultChecked": checked,
|
|
109
|
+
"disabled": disabled,
|
|
110
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
111
|
+
"aria-invalid": state.context.invalid,
|
|
112
|
+
"name": state.context.name,
|
|
113
|
+
"form": state.context.form,
|
|
114
|
+
"value": state.context.value,
|
|
115
|
+
"style": domQuery.visuallyHiddenStyle,
|
|
116
|
+
onFocus() {
|
|
117
|
+
const focusVisible2 = focusVisible.isFocusVisible();
|
|
118
|
+
send({ type: "CONTEXT.SET", context: { focused: true, focusVisible: focusVisible2 } });
|
|
119
|
+
},
|
|
120
|
+
onBlur() {
|
|
121
|
+
send({ type: "CONTEXT.SET", context: { focused: false, focusVisible: false } });
|
|
122
|
+
},
|
|
123
|
+
onClick(event) {
|
|
124
|
+
if (readOnly) {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const checked2 = event.currentTarget.checked;
|
|
129
|
+
send({ type: "CHECKED.SET", checked: checked2, isTrusted: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { not } = core.guards;
|
|
137
|
+
function isIndeterminate(checked) {
|
|
138
|
+
return checked === "indeterminate";
|
|
139
|
+
}
|
|
140
|
+
function isChecked(checked) {
|
|
141
|
+
return isIndeterminate(checked) ? false : !!checked;
|
|
142
|
+
}
|
|
143
|
+
const invoke = {
|
|
144
|
+
change: (ctx) => {
|
|
145
|
+
ctx.onCheckedChange?.({ checked: ctx.checked });
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const set = {
|
|
149
|
+
checked: (ctx, checked) => {
|
|
150
|
+
if (utils.isEqual(ctx.checked, checked))
|
|
151
|
+
return;
|
|
152
|
+
ctx.checked = checked;
|
|
153
|
+
invoke.change(ctx);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
function machine(userContext) {
|
|
157
|
+
const ctx = utils.compact(userContext);
|
|
158
|
+
return core.createMachine(
|
|
159
|
+
{
|
|
160
|
+
id: "checkbox",
|
|
161
|
+
initial: "ready",
|
|
162
|
+
context: {
|
|
163
|
+
checked: false,
|
|
164
|
+
value: "on",
|
|
165
|
+
disabled: false,
|
|
166
|
+
...ctx,
|
|
167
|
+
fieldsetDisabled: false,
|
|
168
|
+
focusVisible: false
|
|
169
|
+
},
|
|
170
|
+
watch: {
|
|
171
|
+
disabled: "removeFocusIfNeeded",
|
|
172
|
+
checked: "syncInputElement"
|
|
173
|
+
},
|
|
174
|
+
activities: ["trackFormControlState", "trackPressEvent", "trackFocusVisible"],
|
|
175
|
+
on: {
|
|
176
|
+
"CHECKED.TOGGLE": [
|
|
177
|
+
{
|
|
178
|
+
guard: not("isTrusted"),
|
|
179
|
+
actions: ["toggleChecked", "dispatchChangeEvent"]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
actions: ["toggleChecked"]
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
"CHECKED.SET": [
|
|
186
|
+
{
|
|
187
|
+
guard: not("isTrusted"),
|
|
188
|
+
actions: ["setChecked", "dispatchChangeEvent"]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
actions: ["setChecked"]
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
"CONTEXT.SET": {
|
|
195
|
+
actions: ["setContext"]
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
computed: {
|
|
199
|
+
isIndeterminate: (ctx2) => isIndeterminate(ctx2.checked),
|
|
200
|
+
isChecked: (ctx2) => isChecked(ctx2.checked),
|
|
201
|
+
isDisabled: (ctx2) => !!ctx2.disabled || ctx2.fieldsetDisabled
|
|
202
|
+
},
|
|
203
|
+
states: {
|
|
204
|
+
ready: {}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
guards: {
|
|
209
|
+
isTrusted: (_ctx, evt) => !!evt.isTrusted
|
|
210
|
+
},
|
|
211
|
+
activities: {
|
|
212
|
+
trackPressEvent(ctx2) {
|
|
213
|
+
if (ctx2.isDisabled)
|
|
214
|
+
return;
|
|
215
|
+
return domEvent.trackPress({
|
|
216
|
+
pointerNode: dom.getRootEl(ctx2),
|
|
217
|
+
keyboardNode: dom.getHiddenInputEl(ctx2),
|
|
218
|
+
isValidKey: (event) => event.key === " ",
|
|
219
|
+
onPress: () => ctx2.active = false,
|
|
220
|
+
onPressStart: () => ctx2.active = true,
|
|
221
|
+
onPressEnd: () => ctx2.active = false
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
trackFocusVisible(ctx2) {
|
|
225
|
+
if (ctx2.isDisabled)
|
|
226
|
+
return;
|
|
227
|
+
return focusVisible.trackFocusVisible({ root: dom.getRootNode(ctx2) });
|
|
228
|
+
},
|
|
229
|
+
trackFormControlState(ctx2, _evt, { send, initialContext }) {
|
|
230
|
+
return formUtils.trackFormControl(dom.getHiddenInputEl(ctx2), {
|
|
231
|
+
onFieldsetDisabledChange(disabled) {
|
|
232
|
+
ctx2.fieldsetDisabled = disabled;
|
|
233
|
+
},
|
|
234
|
+
onFormReset() {
|
|
235
|
+
send({ type: "CHECKED.SET", checked: !!initialContext.checked });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
actions: {
|
|
241
|
+
setContext(ctx2, evt) {
|
|
242
|
+
Object.assign(ctx2, evt.context);
|
|
243
|
+
},
|
|
244
|
+
syncInputElement(ctx2) {
|
|
245
|
+
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
246
|
+
if (!inputEl)
|
|
247
|
+
return;
|
|
248
|
+
formUtils.setElementChecked(inputEl, ctx2.isChecked);
|
|
249
|
+
inputEl.indeterminate = ctx2.isIndeterminate;
|
|
250
|
+
},
|
|
251
|
+
removeFocusIfNeeded(ctx2) {
|
|
252
|
+
if (ctx2.disabled && ctx2.focused) {
|
|
253
|
+
ctx2.focused = false;
|
|
254
|
+
ctx2.focusVisible = false;
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
setChecked(ctx2, evt) {
|
|
258
|
+
set.checked(ctx2, evt.checked);
|
|
259
|
+
},
|
|
260
|
+
toggleChecked(ctx2) {
|
|
261
|
+
const checked = isIndeterminate(ctx2.checked) ? true : !ctx2.checked;
|
|
262
|
+
set.checked(ctx2, checked);
|
|
263
|
+
},
|
|
264
|
+
dispatchChangeEvent(ctx2) {
|
|
265
|
+
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
266
|
+
formUtils.dispatchInputCheckedEvent(inputEl, { checked: isChecked(ctx2.checked) });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const props = types.createProps()([
|
|
274
|
+
"checked",
|
|
275
|
+
"dir",
|
|
276
|
+
"disabled",
|
|
277
|
+
"form",
|
|
278
|
+
"getRootNode",
|
|
279
|
+
"id",
|
|
280
|
+
"ids",
|
|
281
|
+
"invalid",
|
|
282
|
+
"name",
|
|
283
|
+
"onCheckedChange",
|
|
284
|
+
"readOnly",
|
|
285
|
+
"required",
|
|
286
|
+
"value"
|
|
287
|
+
]);
|
|
288
|
+
const splitProps = utils.createSplitProps(props);
|
|
289
|
+
|
|
290
|
+
exports.anatomy = anatomy;
|
|
291
|
+
exports.connect = connect;
|
|
292
|
+
exports.machine = machine;
|
|
293
|
+
exports.props = props;
|
|
294
|
+
exports.splitProps = splitProps;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '@
|
|
4
|
-
import '@
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
|
|
3
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
4
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
5
|
+
|
|
6
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "control" | "indicator">;
|
|
7
|
+
|
|
8
|
+
type CheckedState = boolean | 'indeterminate';
|
|
9
|
+
interface CheckedChangeDetails {
|
|
10
|
+
checked: CheckedState;
|
|
11
|
+
}
|
|
12
|
+
type ElementIds = Partial<{
|
|
13
|
+
root: string;
|
|
14
|
+
hiddenInput: string;
|
|
15
|
+
control: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}>;
|
|
18
|
+
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
19
|
+
/**
|
|
20
|
+
* The ids of the elements in the checkbox. Useful for composition.
|
|
21
|
+
*/
|
|
22
|
+
ids?: ElementIds | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the checkbox is disabled
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the checkbox is invalid
|
|
29
|
+
*/
|
|
30
|
+
invalid?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the checkbox is required
|
|
33
|
+
*/
|
|
34
|
+
required?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The checked state of the checkbox
|
|
37
|
+
*/
|
|
38
|
+
checked: CheckedState;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the checkbox is read-only
|
|
41
|
+
*/
|
|
42
|
+
readOnly?: boolean | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The callback invoked when the checked state changes.
|
|
45
|
+
*/
|
|
46
|
+
onCheckedChange?: (details: CheckedChangeDetails) => void;
|
|
47
|
+
/**
|
|
48
|
+
* The name of the input field in a checkbox.
|
|
49
|
+
* Useful for form submission.
|
|
50
|
+
*/
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The id of the form that the checkbox belongs to.
|
|
54
|
+
*/
|
|
55
|
+
form?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The value of checkbox input. Useful for form submission.
|
|
58
|
+
* @default "on"
|
|
59
|
+
*/
|
|
60
|
+
value: string;
|
|
61
|
+
}
|
|
62
|
+
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
63
|
+
type ComputedContext = Readonly<{
|
|
64
|
+
/**
|
|
65
|
+
* Whether the checkbox is checked
|
|
66
|
+
*/
|
|
67
|
+
isIndeterminate: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the checkbox is checked
|
|
70
|
+
*/
|
|
71
|
+
isChecked: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the checkbox is disabled
|
|
74
|
+
*/
|
|
75
|
+
isDisabled: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
interface PrivateContext {
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
* Whether the checkbox is pressed
|
|
81
|
+
*/
|
|
82
|
+
active?: boolean | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
* Whether the checkbox has focus
|
|
86
|
+
*/
|
|
87
|
+
focused?: boolean | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
* Whether the checkbox is focus visible
|
|
91
|
+
*/
|
|
92
|
+
focusVisible?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* @internal
|
|
95
|
+
* Whether the checkbox is hovered
|
|
96
|
+
*/
|
|
97
|
+
hovered?: boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
* Whether the checkbox's fieldset is disabled
|
|
101
|
+
*/
|
|
102
|
+
fieldsetDisabled: boolean;
|
|
103
|
+
}
|
|
104
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
105
|
+
}
|
|
106
|
+
interface MachineState {
|
|
107
|
+
value: 'ready';
|
|
108
|
+
}
|
|
109
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
110
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
111
|
+
type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|
|
112
|
+
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
113
|
+
/**
|
|
114
|
+
* Whether the checkbox is checked
|
|
115
|
+
*/
|
|
116
|
+
checked: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the checkbox is disabled
|
|
119
|
+
*/
|
|
120
|
+
disabled: boolean | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the checkbox is indeterminate
|
|
123
|
+
*/
|
|
124
|
+
indeterminate: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the checkbox is focused
|
|
127
|
+
*/
|
|
128
|
+
focused: boolean | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The checked state of the checkbox
|
|
131
|
+
*/
|
|
132
|
+
checkedState: CheckedState;
|
|
133
|
+
/**
|
|
134
|
+
* Function to set the checked state of the checkbox
|
|
135
|
+
*/
|
|
136
|
+
setChecked: (checked: CheckedState) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Function to toggle the checked state of the checkbox
|
|
139
|
+
*/
|
|
140
|
+
toggleChecked: () => void;
|
|
141
|
+
getRootProps: () => T['label'];
|
|
142
|
+
getLabelProps: () => T['element'];
|
|
143
|
+
getControlProps: () => T['element'];
|
|
144
|
+
getHiddenInputProps: () => T['input'];
|
|
145
|
+
getIndicatorProps: () => T['element'];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
149
|
+
|
|
150
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
151
|
+
|
|
152
|
+
declare const props: ("ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "value" | "id" | "dir" | "getRootNode")[];
|
|
153
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "value" | "id" | "dir" | "getRootNode">];
|
|
154
|
+
|
|
155
|
+
export { type MachineApi as Api, type CheckedChangeDetails, type CheckedState, type UserDefinedContext as Context, type ElementIds, type Service, anatomy, connect, machine, props, splitProps };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '@
|
|
4
|
-
import '@
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
|
|
3
|
+
import * as _zag_js_core from '@zag-js/core';
|
|
4
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
5
|
+
|
|
6
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "control" | "indicator">;
|
|
7
|
+
|
|
8
|
+
type CheckedState = boolean | 'indeterminate';
|
|
9
|
+
interface CheckedChangeDetails {
|
|
10
|
+
checked: CheckedState;
|
|
11
|
+
}
|
|
12
|
+
type ElementIds = Partial<{
|
|
13
|
+
root: string;
|
|
14
|
+
hiddenInput: string;
|
|
15
|
+
control: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}>;
|
|
18
|
+
interface PublicContext extends DirectionProperty, CommonProperties {
|
|
19
|
+
/**
|
|
20
|
+
* The ids of the elements in the checkbox. Useful for composition.
|
|
21
|
+
*/
|
|
22
|
+
ids?: ElementIds | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the checkbox is disabled
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the checkbox is invalid
|
|
29
|
+
*/
|
|
30
|
+
invalid?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the checkbox is required
|
|
33
|
+
*/
|
|
34
|
+
required?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The checked state of the checkbox
|
|
37
|
+
*/
|
|
38
|
+
checked: CheckedState;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the checkbox is read-only
|
|
41
|
+
*/
|
|
42
|
+
readOnly?: boolean | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The callback invoked when the checked state changes.
|
|
45
|
+
*/
|
|
46
|
+
onCheckedChange?: (details: CheckedChangeDetails) => void;
|
|
47
|
+
/**
|
|
48
|
+
* The name of the input field in a checkbox.
|
|
49
|
+
* Useful for form submission.
|
|
50
|
+
*/
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The id of the form that the checkbox belongs to.
|
|
54
|
+
*/
|
|
55
|
+
form?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The value of checkbox input. Useful for form submission.
|
|
58
|
+
* @default "on"
|
|
59
|
+
*/
|
|
60
|
+
value: string;
|
|
61
|
+
}
|
|
62
|
+
type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
|
|
63
|
+
type ComputedContext = Readonly<{
|
|
64
|
+
/**
|
|
65
|
+
* Whether the checkbox is checked
|
|
66
|
+
*/
|
|
67
|
+
isIndeterminate: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the checkbox is checked
|
|
70
|
+
*/
|
|
71
|
+
isChecked: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the checkbox is disabled
|
|
74
|
+
*/
|
|
75
|
+
isDisabled: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
interface PrivateContext {
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
* Whether the checkbox is pressed
|
|
81
|
+
*/
|
|
82
|
+
active?: boolean | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
* Whether the checkbox has focus
|
|
86
|
+
*/
|
|
87
|
+
focused?: boolean | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
* Whether the checkbox is focus visible
|
|
91
|
+
*/
|
|
92
|
+
focusVisible?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* @internal
|
|
95
|
+
* Whether the checkbox is hovered
|
|
96
|
+
*/
|
|
97
|
+
hovered?: boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
* Whether the checkbox's fieldset is disabled
|
|
101
|
+
*/
|
|
102
|
+
fieldsetDisabled: boolean;
|
|
103
|
+
}
|
|
104
|
+
interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
|
|
105
|
+
}
|
|
106
|
+
interface MachineState {
|
|
107
|
+
value: 'ready';
|
|
108
|
+
}
|
|
109
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
110
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
111
|
+
type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|
|
112
|
+
interface MachineApi<T extends PropTypes = PropTypes> {
|
|
113
|
+
/**
|
|
114
|
+
* Whether the checkbox is checked
|
|
115
|
+
*/
|
|
116
|
+
checked: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the checkbox is disabled
|
|
119
|
+
*/
|
|
120
|
+
disabled: boolean | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the checkbox is indeterminate
|
|
123
|
+
*/
|
|
124
|
+
indeterminate: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the checkbox is focused
|
|
127
|
+
*/
|
|
128
|
+
focused: boolean | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The checked state of the checkbox
|
|
131
|
+
*/
|
|
132
|
+
checkedState: CheckedState;
|
|
133
|
+
/**
|
|
134
|
+
* Function to set the checked state of the checkbox
|
|
135
|
+
*/
|
|
136
|
+
setChecked: (checked: CheckedState) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Function to toggle the checked state of the checkbox
|
|
139
|
+
*/
|
|
140
|
+
toggleChecked: () => void;
|
|
141
|
+
getRootProps: () => T['label'];
|
|
142
|
+
getLabelProps: () => T['element'];
|
|
143
|
+
getControlProps: () => T['element'];
|
|
144
|
+
getHiddenInputProps: () => T['input'];
|
|
145
|
+
getIndicatorProps: () => T['element'];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
149
|
+
|
|
150
|
+
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
151
|
+
|
|
152
|
+
declare const props: ("ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "value" | "id" | "dir" | "getRootNode")[];
|
|
153
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "disabled" | "invalid" | "required" | "checked" | "readOnly" | "onCheckedChange" | "name" | "form" | "value" | "id" | "dir" | "getRootNode">];
|
|
154
|
+
|
|
155
|
+
export { type MachineApi as Api, type CheckedChangeDetails, type CheckedState, type UserDefinedContext as Context, type ElementIds, type Service, anatomy, connect, machine, props, splitProps };
|