@destyler/switch 0.0.6 → 0.0.7-beta.2

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.d.ts CHANGED
@@ -1,286 +1,143 @@
1
- import * as vue from 'vue';
2
- import { PropType, Ref } from 'vue';
3
- import * as _destyler_primitive from '@destyler/primitive';
4
- import { ExtractPublicPropTypes } from '@destyler/shared';
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
5
 
6
- declare const switchRootProps: {
7
- /**
8
- * @default button
9
- */
10
- readonly as: {
11
- readonly default: "button";
12
- readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
13
- readonly required: false;
14
- };
15
- /**
16
- * The state of the switch when it is initially rendered.
17
- * Use when you do not need to control its state.
18
- */
19
- readonly defaultChecked: {
20
- readonly type: PropType<boolean>;
21
- readonly required: false;
22
- };
6
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "control" | "thumb">;
7
+
8
+ interface CheckedChangeDetails {
9
+ checked: boolean;
10
+ }
11
+ type ElementIds = Partial<{
12
+ root: string;
13
+ hiddenInput: string;
14
+ control: string;
15
+ label: string;
16
+ thumb: string;
17
+ }>;
18
+ interface PublicContext extends DirectionProperty, CommonProperties {
23
19
  /**
24
- * The controlled state of the switch.
25
- * Can be bind as `v-model:checked`.
20
+ * The ids of the elements in the switch. Useful for composition.
26
21
  */
27
- readonly checked: {
28
- readonly type: PropType<boolean>;
29
- readonly required: false;
30
- readonly default: undefined;
31
- };
22
+ ids?: ElementIds | undefined;
32
23
  /**
33
- * When `true`, prevents the user from interacting with the switch.
24
+ * Specifies the localized strings that identifies the accessibility elements and their states
34
25
  */
35
- readonly disabled: {
36
- readonly type: PropType<boolean>;
37
- readonly required: false;
38
- };
26
+ label: string;
39
27
  /**
40
- * When `true`, indicates that the user must check the switch before the owning form can be submitted.
28
+ * Whether the switch is disabled.
41
29
  */
42
- readonly required: {
43
- readonly type: PropType<boolean>;
44
- readonly required: false;
45
- };
30
+ disabled?: boolean | undefined;
46
31
  /**
47
- * The name of the switch. Submitted with its owning form as part of a name/value pair.
32
+ * If `true`, the switch is marked as invalid.
48
33
  */
49
- readonly name: {
50
- readonly type: PropType<string>;
51
- readonly required: false;
52
- };
34
+ invalid?: boolean | undefined;
53
35
  /**
54
- * Id of the element
36
+ * If `true`, the switch input is marked as required,
55
37
  */
56
- readonly id: {
57
- readonly type: PropType<string>;
58
- readonly required: false;
59
- };
38
+ required?: boolean | undefined;
60
39
  /**
61
- * The value given as data when submitted with a `name`.
40
+ * Whether the switch is read-only
62
41
  */
63
- readonly value: {
64
- readonly type: PropType<string>;
65
- readonly required: false;
66
- readonly default: "on";
67
- };
68
- readonly asChild: {
69
- readonly type: PropType<boolean>;
70
- readonly required: false;
71
- readonly default: false;
72
- };
73
- };
74
- type SwitchRootProps = ExtractPublicPropTypes<typeof switchRootProps>;
75
- declare const switchRootEmits: {
76
- 'update:checked': (_checked: boolean) => boolean;
77
- };
78
- interface SwitchRootContext {
79
- checked?: Ref<boolean>;
80
- toggleCheck: () => void;
81
- disabled: Ref<boolean | undefined>;
82
- }
83
- declare const SwitchRoot: vue.DefineComponent<{
42
+ readOnly?: boolean | undefined;
84
43
  /**
85
- * @default button
44
+ * Function to call when the switch is clicked.
86
45
  */
87
- readonly as: {
88
- readonly default: "button";
89
- readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
90
- readonly required: false;
91
- };
46
+ onCheckedChange?: ((details: CheckedChangeDetails) => void) | undefined;
92
47
  /**
93
- * The state of the switch when it is initially rendered.
94
- * Use when you do not need to control its state.
48
+ * Whether the switch is checked.
95
49
  */
96
- readonly defaultChecked: {
97
- readonly type: PropType<boolean>;
98
- readonly required: false;
99
- };
50
+ checked: boolean;
100
51
  /**
101
- * The controlled state of the switch.
102
- * Can be bind as `v-model:checked`.
52
+ * The name of the input field in a switch
53
+ * (Useful for form submission).
103
54
  */
104
- readonly checked: {
105
- readonly type: PropType<boolean>;
106
- readonly required: false;
107
- readonly default: undefined;
108
- };
55
+ name?: string | undefined;
109
56
  /**
110
- * When `true`, prevents the user from interacting with the switch.
57
+ * The id of the form that the switch belongs to
111
58
  */
112
- readonly disabled: {
113
- readonly type: PropType<boolean>;
114
- readonly required: false;
115
- };
59
+ form?: string | undefined;
116
60
  /**
117
- * When `true`, indicates that the user must check the switch before the owning form can be submitted.
61
+ * The value of switch input. Useful for form submission.
62
+ * @default "on"
118
63
  */
119
- readonly required: {
120
- readonly type: PropType<boolean>;
121
- readonly required: false;
122
- };
64
+ value?: string | number | undefined;
65
+ }
66
+ type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
67
+ type ComputedContext = Readonly<{
123
68
  /**
124
- * The name of the switch. Submitted with its owning form as part of a name/value pair.
69
+ * Whether the switch is disabled
125
70
  */
126
- readonly name: {
127
- readonly type: PropType<string>;
128
- readonly required: false;
129
- };
71
+ isDisabled: boolean;
72
+ }>;
73
+ interface PrivateContext {
130
74
  /**
131
- * Id of the element
75
+ * @internal
76
+ * Whether the checkbox is pressed
132
77
  */
133
- readonly id: {
134
- readonly type: PropType<string>;
135
- readonly required: false;
136
- };
78
+ active?: boolean | undefined;
137
79
  /**
138
- * The value given as data when submitted with a `name`.
80
+ * @internal
81
+ * Whether the checkbox has focus
139
82
  */
140
- readonly value: {
141
- readonly type: PropType<string>;
142
- readonly required: false;
143
- readonly default: "on";
144
- };
145
- readonly asChild: {
146
- readonly type: PropType<boolean>;
147
- readonly required: false;
148
- readonly default: false;
149
- };
150
- }, {
151
- forwardRef: (ref: Element | vue.ComponentPublicInstance | null) => void;
152
- toggleCheck: () => void;
153
- isFormControl: vue.ComputedRef<boolean>;
154
- ariaLabel: vue.ComputedRef<string | null | undefined>;
155
- checked: Ref<boolean>;
156
- disabled: Ref<boolean | undefined>;
157
- }, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
158
- 'update:checked': (_checked: boolean) => boolean;
159
- }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
83
+ focused?: boolean | undefined;
160
84
  /**
161
- * @default button
85
+ * @internal
86
+ * Whether the checkbox has focus visible
162
87
  */
163
- readonly as: {
164
- readonly default: "button";
165
- readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
166
- readonly required: false;
167
- };
88
+ focusVisible?: boolean | undefined;
168
89
  /**
169
- * The state of the switch when it is initially rendered.
170
- * Use when you do not need to control its state.
90
+ * @internal
91
+ * Whether the checkbox is hovered
171
92
  */
172
- readonly defaultChecked: {
173
- readonly type: PropType<boolean>;
174
- readonly required: false;
175
- };
93
+ hovered?: boolean | undefined;
176
94
  /**
177
- * The controlled state of the switch.
178
- * Can be bind as `v-model:checked`.
95
+ * @internal
96
+ * Whether the checkbox fieldset is disabled
179
97
  */
180
- readonly checked: {
181
- readonly type: PropType<boolean>;
182
- readonly required: false;
183
- readonly default: undefined;
184
- };
98
+ fieldsetDisabled: boolean;
99
+ }
100
+ interface MachineContext extends PublicContext, PrivateContext, ComputedContext {
101
+ }
102
+ interface MachineState {
103
+ value: 'ready';
104
+ }
105
+ type State = StateMachine.State<MachineContext, MachineState>;
106
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
107
+ type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
108
+ interface MachineApi<T extends PropTypes = PropTypes> {
185
109
  /**
186
- * When `true`, prevents the user from interacting with the switch.
110
+ * Whether the checkbox is checked
187
111
  */
188
- readonly disabled: {
189
- readonly type: PropType<boolean>;
190
- readonly required: false;
191
- };
112
+ checked: boolean;
192
113
  /**
193
- * When `true`, indicates that the user must check the switch before the owning form can be submitted.
114
+ * Whether the checkbox is disabled
194
115
  */
195
- readonly required: {
196
- readonly type: PropType<boolean>;
197
- readonly required: false;
198
- };
116
+ disabled: boolean | undefined;
199
117
  /**
200
- * The name of the switch. Submitted with its owning form as part of a name/value pair.
118
+ * Whether the checkbox is focused
201
119
  */
202
- readonly name: {
203
- readonly type: PropType<string>;
204
- readonly required: false;
205
- };
120
+ focused: boolean | undefined;
206
121
  /**
207
- * Id of the element
122
+ * Function to set the checked state of the switch.
208
123
  */
209
- readonly id: {
210
- readonly type: PropType<string>;
211
- readonly required: false;
212
- };
124
+ setChecked: (checked: boolean) => void;
213
125
  /**
214
- * The value given as data when submitted with a `name`.
126
+ * Function to toggle the checked state of the checkbox
215
127
  */
216
- readonly value: {
217
- readonly type: PropType<string>;
218
- readonly required: false;
219
- readonly default: "on";
220
- };
221
- readonly asChild: {
222
- readonly type: PropType<boolean>;
223
- readonly required: false;
224
- readonly default: false;
225
- };
226
- }>> & {
227
- "onUpdate:checked"?: ((_checked: boolean) => any) | undefined;
228
- }, {
229
- readonly as: _destyler_primitive.AsTag | vue.Component;
230
- readonly checked: boolean;
231
- readonly value: string;
232
- readonly asChild: boolean;
233
- }, {}>;
128
+ toggleChecked: () => void;
129
+ getRootProps: () => T['label'];
130
+ getLabelProps: () => T['element'];
131
+ getThumbProps: () => T['element'];
132
+ getControlProps: () => T['element'];
133
+ getHiddenInputProps: () => T['input'];
134
+ }
234
135
 
235
- declare const switchThumbProps: {
236
- /**
237
- * @default span
238
- */
239
- readonly as: {
240
- readonly default: "span";
241
- readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
242
- readonly required: false;
243
- };
244
- readonly asChild: {
245
- readonly type: vue.PropType<boolean>;
246
- readonly required: false;
247
- readonly default: false;
248
- };
249
- };
250
- type SwitchThumbProps = ExtractPublicPropTypes<typeof switchThumbProps>;
251
- declare const SwitchThumb: vue.DefineComponent<{
252
- /**
253
- * @default span
254
- */
255
- readonly as: {
256
- readonly default: "span";
257
- readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
258
- readonly required: false;
259
- };
260
- readonly asChild: {
261
- readonly type: vue.PropType<boolean>;
262
- readonly required: false;
263
- readonly default: false;
264
- };
265
- }, {
266
- rootContext: SwitchRootContext;
267
- }, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
268
- /**
269
- * @default span
270
- */
271
- readonly as: {
272
- readonly default: "span";
273
- readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
274
- readonly required: false;
275
- };
276
- readonly asChild: {
277
- readonly type: vue.PropType<boolean>;
278
- readonly required: false;
279
- readonly default: false;
280
- };
281
- }>>, {
282
- readonly as: _destyler_primitive.AsTag | vue.Component;
283
- readonly asChild: boolean;
284
- }, {}>;
136
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
137
+
138
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
139
+
140
+ declare const props: ("label" | "ids" | "disabled" | "invalid" | "required" | "readOnly" | "onCheckedChange" | "checked" | "name" | "form" | "value" | "id" | "dir" | "getRootNode")[];
141
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "label" | "ids" | "disabled" | "invalid" | "required" | "readOnly" | "onCheckedChange" | "checked" | "name" | "form" | "value" | "id" | "dir" | "getRootNode">];
285
142
 
286
- export { SwitchRoot, type SwitchRootProps, SwitchThumb, type SwitchThumbProps, switchRootEmits, switchRootProps, switchThumbProps };
143
+ export { type MachineApi as Api, type CheckedChangeDetails, type UserDefinedContext as Context, type ElementIds, type Service, anatomy, connect, machine, props, splitProps };