@destyler/switch 0.0.3 → 0.0.4

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @destyler/switch
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@destyler/switch?color=a1b858&switch=)](https://www.npmjs.com/package/@destyler/switch)
4
+
5
+ > a control that allows the user to toggle between checked and not checked.
6
+
7
+ [GitHub](https://github.com/destyler/destyler) | [Documentation](https://destyler-dev.zeabur.app/)
@@ -9,5 +9,8 @@ require('@destyler/directives');
9
9
 
10
10
 
11
11
 
12
- exports.DestylerSwitchRoot = index.DestylerSwitchRoot;
13
- exports.DestylerSwitchThump = index.DestylerSwitchThump;
12
+ exports.SwitchRoot = index.SwitchRoot;
13
+ exports.SwitchThumb = index.SwitchThumb;
14
+ exports.switchRootEmits = index.switchRootEmits;
15
+ exports.switchRootProps = index.switchRootProps;
16
+ exports.switchThumbProps = index.switchThumbProps;
@@ -1,4 +1,4 @@
1
- export { DestylerSwitchRoot, DestylerSwitchRootProps, DestylerSwitchThump, DestylerSwitchThumpProps } from './index.cjs';
1
+ export { SwitchRoot, SwitchRootProps, SwitchThumb, SwitchThumbProps, switchRootEmits, switchRootProps, switchThumbProps } from './index.cjs';
2
2
  import 'vue';
3
3
  import '@destyler/primitive';
4
4
  import '@destyler/shared';
@@ -1,4 +1,4 @@
1
- export { DestylerSwitchRoot, DestylerSwitchRootProps, DestylerSwitchThump, DestylerSwitchThumpProps } from './index.mjs';
1
+ export { SwitchRoot, SwitchRootProps, SwitchThumb, SwitchThumbProps, switchRootEmits, switchRootProps, switchThumbProps } from './index.mjs';
2
2
  import 'vue';
3
3
  import '@destyler/primitive';
4
4
  import '@destyler/shared';
@@ -1,4 +1,4 @@
1
- export { DestylerSwitchRoot, DestylerSwitchRootProps, DestylerSwitchThump, DestylerSwitchThumpProps } from './index.js';
1
+ export { SwitchRoot, SwitchRootProps, SwitchThumb, SwitchThumbProps, switchRootEmits, switchRootProps, switchThumbProps } from './index.js';
2
2
  import 'vue';
3
3
  import '@destyler/primitive';
4
4
  import '@destyler/shared';
@@ -1,4 +1,4 @@
1
- export { DestylerSwitchRoot, DestylerSwitchThump } from './index.mjs';
1
+ export { SwitchRoot, SwitchThumb, switchRootEmits, switchRootProps, switchThumbProps } from './index.mjs';
2
2
  import 'vue';
3
3
  import '@destyler/primitive';
4
4
  import '@destyler/composition';
package/dist/index.cjs CHANGED
@@ -6,53 +6,77 @@ const composition = require('@destyler/composition');
6
6
  const shared = require('@destyler/shared');
7
7
  const directives = require('@destyler/directives');
8
8
 
9
- const destylerSwitchRootProps = {
9
+ const switchRootProps = {
10
+ ...primitive.primitiveProps,
11
+ /**
12
+ * @default button
13
+ */
10
14
  as: {
11
- type: [String, Object],
12
- required: false,
15
+ ...primitive.primitiveProps.as,
13
16
  default: "button"
14
17
  },
15
- asChild: {
16
- type: Boolean,
17
- required: false,
18
- default: false
19
- },
18
+ /**
19
+ * The state of the switch when it is initially rendered.
20
+ * Use when you do not need to control its state.
21
+ */
20
22
  defaultChecked: {
21
23
  type: Boolean,
22
24
  required: false
23
25
  },
26
+ /**
27
+ * The controlled state of the switch.
28
+ * Can be bind as `v-model:checked`.
29
+ */
24
30
  checked: {
25
31
  type: Boolean,
26
32
  required: false,
27
33
  default: void 0
28
34
  },
35
+ /**
36
+ * When `true`, prevents the user from interacting with the switch.
37
+ */
29
38
  disabled: {
30
39
  type: Boolean,
31
40
  required: false
32
41
  },
42
+ /**
43
+ * When `true`, indicates that the user must check the switch before the owning form can be submitted.
44
+ */
33
45
  required: {
34
46
  type: Boolean,
35
47
  required: false
36
48
  },
49
+ /**
50
+ * The name of the switch. Submitted with its owning form as part of a name/value pair.
51
+ */
37
52
  name: {
38
53
  type: String,
39
54
  required: false
40
55
  },
56
+ /**
57
+ * Id of the element
58
+ */
41
59
  id: {
42
60
  type: String,
43
61
  required: false
44
62
  },
63
+ /**
64
+ * The value given as data when submitted with a `name`.
65
+ */
45
66
  value: {
46
67
  type: String,
47
68
  required: false,
48
69
  default: "on"
49
70
  }
50
71
  };
72
+ const switchRootEmits = {
73
+ "update:checked": (_checked) => true
74
+ };
51
75
  const [injectSwitchRootContext, provideSwitchRootContext] = shared.createContext("DestylerSwitchRoot");
52
- const DestylerSwitchRoot = vue.defineComponent({
76
+ const SwitchRoot = vue.defineComponent({
53
77
  name: "DestylerSwitchRoot",
54
- props: destylerSwitchRootProps,
55
- emits: ["update:checked"],
78
+ props: switchRootProps,
79
+ emits: switchRootEmits,
56
80
  setup(props, { emit }) {
57
81
  const { disabled } = vue.toRefs(props);
58
82
  const checked = composition.useVModel(props, "checked", emit, {
@@ -83,7 +107,7 @@ const DestylerSwitchRoot = vue.defineComponent({
83
107
  },
84
108
  render() {
85
109
  return [
86
- vue.withDirectives(vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$attrs, {
110
+ vue.withDirectives(vue.h(primitive.Primitive, vue.mergeProps(this.$attrs, {
87
111
  "ref": (el) => this.forwardRef(el),
88
112
  "role": "switch",
89
113
  "type": this.$props.as === "button" ? "button" : void 0,
@@ -128,21 +152,19 @@ const DestylerSwitchRoot = vue.defineComponent({
128
152
  }
129
153
  });
130
154
 
131
- const destylerSwitchThumpProps = {
155
+ const switchThumbProps = {
156
+ ...primitive.primitiveProps,
157
+ /**
158
+ * @default span
159
+ */
132
160
  as: {
133
- type: [String, Object],
134
- required: false,
161
+ ...primitive.primitiveProps.as,
135
162
  default: "span"
136
- },
137
- asChild: {
138
- type: Boolean,
139
- required: false,
140
- default: false
141
163
  }
142
164
  };
143
- const DestylerSwitchThump = vue.defineComponent({
165
+ const SwitchThumb = vue.defineComponent({
144
166
  name: "DestylerSwitchThump",
145
- props: destylerSwitchThumpProps,
167
+ props: switchThumbProps,
146
168
  setup(_) {
147
169
  const rootContext = injectSwitchRootContext();
148
170
  composition.useForwardExpose();
@@ -151,7 +173,7 @@ const DestylerSwitchThump = vue.defineComponent({
151
173
  };
152
174
  },
153
175
  render() {
154
- return vue.h(primitive.DestylerPrimitive, {
176
+ return vue.h(primitive.Primitive, {
155
177
  "data-state": this.rootContext.checked?.value ? "checked" : "unchecked",
156
178
  "data-disabled": this.rootContext.disabled.value ? "" : void 0,
157
179
  "asChild": this.$props.asChild,
@@ -160,5 +182,8 @@ const DestylerSwitchThump = vue.defineComponent({
160
182
  }
161
183
  });
162
184
 
163
- exports.DestylerSwitchRoot = DestylerSwitchRoot;
164
- exports.DestylerSwitchThump = DestylerSwitchThump;
185
+ exports.SwitchRoot = SwitchRoot;
186
+ exports.SwitchThumb = SwitchThumb;
187
+ exports.switchRootEmits = switchRootEmits;
188
+ exports.switchRootProps = switchRootProps;
189
+ exports.switchThumbProps = switchThumbProps;
package/dist/index.d.cts CHANGED
@@ -1,97 +1,152 @@
1
1
  import * as vue from 'vue';
2
- import { PropType, Component, Ref } from 'vue';
3
- import { AsTag } from '@destyler/primitive';
2
+ import { PropType, Ref } from 'vue';
3
+ import * as _destyler_primitive from '@destyler/primitive';
4
4
  import { ExtractPublicPropTypes } from '@destyler/shared';
5
5
 
6
- declare const destylerSwitchRootProps: {
6
+ declare const switchRootProps: {
7
+ /**
8
+ * @default button
9
+ */
7
10
  readonly as: {
8
- readonly type: PropType<AsTag | Component>;
9
- readonly required: false;
10
11
  readonly default: "button";
11
- };
12
- readonly asChild: {
13
- readonly type: PropType<boolean>;
12
+ readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
14
13
  readonly required: false;
15
- readonly default: false;
16
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
+ */
17
19
  readonly defaultChecked: {
18
20
  readonly type: PropType<boolean>;
19
21
  readonly required: false;
20
22
  };
23
+ /**
24
+ * The controlled state of the switch.
25
+ * Can be bind as `v-model:checked`.
26
+ */
21
27
  readonly checked: {
22
28
  readonly type: PropType<boolean>;
23
29
  readonly required: false;
24
30
  readonly default: undefined;
25
31
  };
32
+ /**
33
+ * When `true`, prevents the user from interacting with the switch.
34
+ */
26
35
  readonly disabled: {
27
36
  readonly type: PropType<boolean>;
28
37
  readonly required: false;
29
38
  };
39
+ /**
40
+ * When `true`, indicates that the user must check the switch before the owning form can be submitted.
41
+ */
30
42
  readonly required: {
31
43
  readonly type: PropType<boolean>;
32
44
  readonly required: false;
33
45
  };
46
+ /**
47
+ * The name of the switch. Submitted with its owning form as part of a name/value pair.
48
+ */
34
49
  readonly name: {
35
50
  readonly type: PropType<string>;
36
51
  readonly required: false;
37
52
  };
53
+ /**
54
+ * Id of the element
55
+ */
38
56
  readonly id: {
39
57
  readonly type: PropType<string>;
40
58
  readonly required: false;
41
59
  };
60
+ /**
61
+ * The value given as data when submitted with a `name`.
62
+ */
42
63
  readonly value: {
43
64
  readonly type: PropType<string>;
44
65
  readonly required: false;
45
66
  readonly default: "on";
46
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;
47
77
  };
48
- type DestylerSwitchRootProps = ExtractPublicPropTypes<typeof destylerSwitchRootProps>;
49
78
  interface SwitchRootContext {
50
79
  checked?: Ref<boolean>;
51
80
  toggleCheck: () => void;
52
81
  disabled: Ref<boolean | undefined>;
53
82
  }
54
- declare const DestylerSwitchRoot: vue.DefineComponent<{
83
+ declare const SwitchRoot: vue.DefineComponent<{
84
+ /**
85
+ * @default button
86
+ */
55
87
  readonly as: {
56
- readonly type: PropType<AsTag | Component>;
57
- readonly required: false;
58
88
  readonly default: "button";
59
- };
60
- readonly asChild: {
61
- readonly type: PropType<boolean>;
89
+ readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
62
90
  readonly required: false;
63
- readonly default: false;
64
91
  };
92
+ /**
93
+ * The state of the switch when it is initially rendered.
94
+ * Use when you do not need to control its state.
95
+ */
65
96
  readonly defaultChecked: {
66
97
  readonly type: PropType<boolean>;
67
98
  readonly required: false;
68
99
  };
100
+ /**
101
+ * The controlled state of the switch.
102
+ * Can be bind as `v-model:checked`.
103
+ */
69
104
  readonly checked: {
70
105
  readonly type: PropType<boolean>;
71
106
  readonly required: false;
72
107
  readonly default: undefined;
73
108
  };
109
+ /**
110
+ * When `true`, prevents the user from interacting with the switch.
111
+ */
74
112
  readonly disabled: {
75
113
  readonly type: PropType<boolean>;
76
114
  readonly required: false;
77
115
  };
116
+ /**
117
+ * When `true`, indicates that the user must check the switch before the owning form can be submitted.
118
+ */
78
119
  readonly required: {
79
120
  readonly type: PropType<boolean>;
80
121
  readonly required: false;
81
122
  };
123
+ /**
124
+ * The name of the switch. Submitted with its owning form as part of a name/value pair.
125
+ */
82
126
  readonly name: {
83
127
  readonly type: PropType<string>;
84
128
  readonly required: false;
85
129
  };
130
+ /**
131
+ * Id of the element
132
+ */
86
133
  readonly id: {
87
134
  readonly type: PropType<string>;
88
135
  readonly required: false;
89
136
  };
137
+ /**
138
+ * The value given as data when submitted with a `name`.
139
+ */
90
140
  readonly value: {
91
141
  readonly type: PropType<string>;
92
142
  readonly required: false;
93
143
  readonly default: "on";
94
144
  };
145
+ readonly asChild: {
146
+ readonly type: PropType<boolean>;
147
+ readonly required: false;
148
+ readonly default: false;
149
+ };
95
150
  }, {
96
151
  forwardRef: (ref: Element | vue.ComponentPublicInstance | null) => void;
97
152
  toggleCheck: () => void;
@@ -99,96 +154,133 @@ declare const DestylerSwitchRoot: vue.DefineComponent<{
99
154
  ariaLabel: vue.ComputedRef<string | null | undefined>;
100
155
  checked: Ref<boolean>;
101
156
  disabled: Ref<boolean | undefined>;
102
- }, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:checked"[], "update:checked", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
157
+ }, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
158
+ 'update:checked': (_checked: boolean) => boolean;
159
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
160
+ /**
161
+ * @default button
162
+ */
103
163
  readonly as: {
104
- readonly type: PropType<AsTag | Component>;
105
- readonly required: false;
106
164
  readonly default: "button";
107
- };
108
- readonly asChild: {
109
- readonly type: PropType<boolean>;
165
+ readonly type: PropType<_destyler_primitive.AsTag | vue.Component>;
110
166
  readonly required: false;
111
- readonly default: false;
112
167
  };
168
+ /**
169
+ * The state of the switch when it is initially rendered.
170
+ * Use when you do not need to control its state.
171
+ */
113
172
  readonly defaultChecked: {
114
173
  readonly type: PropType<boolean>;
115
174
  readonly required: false;
116
175
  };
176
+ /**
177
+ * The controlled state of the switch.
178
+ * Can be bind as `v-model:checked`.
179
+ */
117
180
  readonly checked: {
118
181
  readonly type: PropType<boolean>;
119
182
  readonly required: false;
120
183
  readonly default: undefined;
121
184
  };
185
+ /**
186
+ * When `true`, prevents the user from interacting with the switch.
187
+ */
122
188
  readonly disabled: {
123
189
  readonly type: PropType<boolean>;
124
190
  readonly required: false;
125
191
  };
192
+ /**
193
+ * When `true`, indicates that the user must check the switch before the owning form can be submitted.
194
+ */
126
195
  readonly required: {
127
196
  readonly type: PropType<boolean>;
128
197
  readonly required: false;
129
198
  };
199
+ /**
200
+ * The name of the switch. Submitted with its owning form as part of a name/value pair.
201
+ */
130
202
  readonly name: {
131
203
  readonly type: PropType<string>;
132
204
  readonly required: false;
133
205
  };
206
+ /**
207
+ * Id of the element
208
+ */
134
209
  readonly id: {
135
210
  readonly type: PropType<string>;
136
211
  readonly required: false;
137
212
  };
213
+ /**
214
+ * The value given as data when submitted with a `name`.
215
+ */
138
216
  readonly value: {
139
217
  readonly type: PropType<string>;
140
218
  readonly required: false;
141
219
  readonly default: "on";
142
220
  };
221
+ readonly asChild: {
222
+ readonly type: PropType<boolean>;
223
+ readonly required: false;
224
+ readonly default: false;
225
+ };
143
226
  }>> & {
144
- "onUpdate:checked"?: ((...args: any[]) => any) | undefined;
227
+ "onUpdate:checked"?: ((_checked: boolean) => any) | undefined;
145
228
  }, {
146
- readonly as: AsTag | Component;
147
- readonly asChild: boolean;
229
+ readonly as: _destyler_primitive.AsTag | vue.Component;
148
230
  readonly checked: boolean;
149
231
  readonly value: string;
232
+ readonly asChild: boolean;
150
233
  }, {}>;
151
234
 
152
- declare const destylerSwitchThumpProps: {
235
+ declare const switchThumbProps: {
236
+ /**
237
+ * @default span
238
+ */
153
239
  readonly as: {
154
- readonly type: PropType<AsTag | Component>;
155
- readonly required: false;
156
240
  readonly default: "span";
241
+ readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
242
+ readonly required: false;
157
243
  };
158
244
  readonly asChild: {
159
- readonly type: PropType<boolean>;
245
+ readonly type: vue.PropType<boolean>;
160
246
  readonly required: false;
161
247
  readonly default: false;
162
248
  };
163
249
  };
164
- type DestylerSwitchThumpProps = ExtractPublicPropTypes<typeof destylerSwitchThumpProps>;
165
- declare const DestylerSwitchThump: vue.DefineComponent<{
250
+ type SwitchThumbProps = ExtractPublicPropTypes<typeof switchThumbProps>;
251
+ declare const SwitchThumb: vue.DefineComponent<{
252
+ /**
253
+ * @default span
254
+ */
166
255
  readonly as: {
167
- readonly type: PropType<AsTag | Component>;
168
- readonly required: false;
169
256
  readonly default: "span";
257
+ readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
258
+ readonly required: false;
170
259
  };
171
260
  readonly asChild: {
172
- readonly type: PropType<boolean>;
261
+ readonly type: vue.PropType<boolean>;
173
262
  readonly required: false;
174
263
  readonly default: false;
175
264
  };
176
265
  }, {
177
266
  rootContext: SwitchRootContext;
178
267
  }, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
268
+ /**
269
+ * @default span
270
+ */
179
271
  readonly as: {
180
- readonly type: PropType<AsTag | Component>;
181
- readonly required: false;
182
272
  readonly default: "span";
273
+ readonly type: vue.PropType<_destyler_primitive.AsTag | vue.Component>;
274
+ readonly required: false;
183
275
  };
184
276
  readonly asChild: {
185
- readonly type: PropType<boolean>;
277
+ readonly type: vue.PropType<boolean>;
186
278
  readonly required: false;
187
279
  readonly default: false;
188
280
  };
189
281
  }>>, {
190
- readonly as: AsTag | Component;
282
+ readonly as: _destyler_primitive.AsTag | vue.Component;
191
283
  readonly asChild: boolean;
192
284
  }, {}>;
193
285
 
194
- export { DestylerSwitchRoot, type DestylerSwitchRootProps, DestylerSwitchThump, type DestylerSwitchThumpProps };
286
+ export { SwitchRoot, type SwitchRootProps, SwitchThumb, type SwitchThumbProps, switchRootEmits, switchRootProps, switchThumbProps };