@destyler/switch 0.0.2 → 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/dist/index.mjs CHANGED
@@ -1,56 +1,80 @@
1
1
  import { defineComponent, toRefs, computed, withDirectives, h, mergeProps, withModifiers } from 'vue';
2
- import { DestylerPrimitive } from '@destyler/primitive';
2
+ import { primitiveProps, Primitive } from '@destyler/primitive';
3
3
  import { useVModel, useForwardExpose, useFormControl } from '@destyler/composition';
4
4
  import { createContext } from '@destyler/shared';
5
5
  import { BindOnceDirective } from '@destyler/directives';
6
6
 
7
- const destylerSwitchRootProps = {
7
+ const switchRootProps = {
8
+ ...primitiveProps,
9
+ /**
10
+ * @default button
11
+ */
8
12
  as: {
9
- type: [String, Object],
10
- required: false,
13
+ ...primitiveProps.as,
11
14
  default: "button"
12
15
  },
13
- asChild: {
14
- type: Boolean,
15
- required: false,
16
- default: false
17
- },
16
+ /**
17
+ * The state of the switch when it is initially rendered.
18
+ * Use when you do not need to control its state.
19
+ */
18
20
  defaultChecked: {
19
21
  type: Boolean,
20
22
  required: false
21
23
  },
24
+ /**
25
+ * The controlled state of the switch.
26
+ * Can be bind as `v-model:checked`.
27
+ */
22
28
  checked: {
23
29
  type: Boolean,
24
30
  required: false,
25
31
  default: void 0
26
32
  },
33
+ /**
34
+ * When `true`, prevents the user from interacting with the switch.
35
+ */
27
36
  disabled: {
28
37
  type: Boolean,
29
38
  required: false
30
39
  },
40
+ /**
41
+ * When `true`, indicates that the user must check the switch before the owning form can be submitted.
42
+ */
31
43
  required: {
32
44
  type: Boolean,
33
45
  required: false
34
46
  },
47
+ /**
48
+ * The name of the switch. Submitted with its owning form as part of a name/value pair.
49
+ */
35
50
  name: {
36
51
  type: String,
37
52
  required: false
38
53
  },
54
+ /**
55
+ * Id of the element
56
+ */
39
57
  id: {
40
58
  type: String,
41
59
  required: false
42
60
  },
61
+ /**
62
+ * The value given as data when submitted with a `name`.
63
+ */
43
64
  value: {
44
65
  type: String,
45
66
  required: false,
46
67
  default: "on"
47
68
  }
48
69
  };
70
+ const switchRootEmits = {
71
+ "update:checked": (_checked) => true
72
+ };
49
73
  const [injectSwitchRootContext, provideSwitchRootContext] = createContext("DestylerSwitchRoot");
50
- const DestylerSwitchRoot = defineComponent({
74
+ const SwitchRoot = defineComponent({
51
75
  name: "DestylerSwitchRoot",
52
- props: destylerSwitchRootProps,
53
- emits: ["update:checked"],
76
+ props: switchRootProps,
77
+ emits: switchRootEmits,
54
78
  setup(props, { emit }) {
55
79
  const { disabled } = toRefs(props);
56
80
  const checked = useVModel(props, "checked", emit, {
@@ -81,7 +105,7 @@ const DestylerSwitchRoot = defineComponent({
81
105
  },
82
106
  render() {
83
107
  return [
84
- withDirectives(h(DestylerPrimitive, mergeProps(this.$attrs, {
108
+ withDirectives(h(Primitive, mergeProps(this.$attrs, {
85
109
  "ref": (el) => this.forwardRef(el),
86
110
  "role": "switch",
87
111
  "type": this.$props.as === "button" ? "button" : void 0,
@@ -100,9 +124,7 @@ const DestylerSwitchRoot = defineComponent({
100
124
  "onKeydown": withModifiers(() => {
101
125
  this.toggleCheck();
102
126
  }, ["enter", "prevent"])
103
- }), {
104
- default: () => this.$slots.default?.()
105
- }), [
127
+ }), () => this.$slots.default?.()), [
106
128
  [BindOnceDirective, { id: this.$props.id }]
107
129
  ]),
108
130
  this.isFormControl ? h("input", {
@@ -128,21 +150,19 @@ const DestylerSwitchRoot = defineComponent({
128
150
  }
129
151
  });
130
152
 
131
- const destylerSwitchThumpProps = {
153
+ const switchThumbProps = {
154
+ ...primitiveProps,
155
+ /**
156
+ * @default span
157
+ */
132
158
  as: {
133
- type: [String, Object],
134
- required: false,
159
+ ...primitiveProps.as,
135
160
  default: "span"
136
- },
137
- asChild: {
138
- type: Boolean,
139
- required: false,
140
- default: false
141
161
  }
142
162
  };
143
- const DestylerSwitchThump = defineComponent({
163
+ const SwitchThumb = defineComponent({
144
164
  name: "DestylerSwitchThump",
145
- props: destylerSwitchThumpProps,
165
+ props: switchThumbProps,
146
166
  setup(_) {
147
167
  const rootContext = injectSwitchRootContext();
148
168
  useForwardExpose();
@@ -151,13 +171,13 @@ const DestylerSwitchThump = defineComponent({
151
171
  };
152
172
  },
153
173
  render() {
154
- return h(DestylerPrimitive, {
174
+ return h(Primitive, {
155
175
  "data-state": this.rootContext.checked?.value ? "checked" : "unchecked",
156
176
  "data-disabled": this.rootContext.disabled.value ? "" : void 0,
157
177
  "asChild": this.$props.asChild,
158
178
  "as": this.$props.as
159
- }, this.$slots.default?.());
179
+ }, () => this.$slots.default?.());
160
180
  }
161
181
  });
162
182
 
163
- export { DestylerSwitchRoot, DestylerSwitchThump };
183
+ export { SwitchRoot, SwitchThumb, switchRootEmits, switchRootProps, switchThumbProps };
package/dist/resolver.cjs CHANGED
@@ -4,9 +4,10 @@ const name = "@destyler/switch";
4
4
 
5
5
  const packageName = name;
6
6
  const switchComponentName = [
7
- "DestylerTemplate"
7
+ "SwitchRoot",
8
+ "SwitchThumb"
8
9
  ];
9
- function DestylerTemplateResolver() {
10
+ function SwitchResolver() {
10
11
  return {
11
12
  type: "component",
12
13
  resolve: (name2) => {
@@ -16,5 +17,5 @@ function DestylerTemplateResolver() {
16
17
  };
17
18
  }
18
19
 
19
- exports.DestylerTemplateResolver = DestylerTemplateResolver;
20
+ exports.SwitchResolver = SwitchResolver;
20
21
  exports.switchComponentName = switchComponentName;
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
3
  declare const switchComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
4
+ declare function SwitchResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, switchComponentName };
6
+ export { SwitchResolver, switchComponentName };
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
3
  declare const switchComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
4
+ declare function SwitchResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, switchComponentName };
6
+ export { SwitchResolver, switchComponentName };
@@ -1,6 +1,6 @@
1
1
  import { ComponentResolver } from 'unplugin-vue-components';
2
2
 
3
3
  declare const switchComponentName: string[];
4
- declare function DestylerTemplateResolver(): ComponentResolver;
4
+ declare function SwitchResolver(): ComponentResolver;
5
5
 
6
- export { DestylerTemplateResolver, switchComponentName };
6
+ export { SwitchResolver, switchComponentName };
package/dist/resolver.mjs CHANGED
@@ -2,9 +2,10 @@ const name = "@destyler/switch";
2
2
 
3
3
  const packageName = name;
4
4
  const switchComponentName = [
5
- "DestylerTemplate"
5
+ "SwitchRoot",
6
+ "SwitchThumb"
6
7
  ];
7
- function DestylerTemplateResolver() {
8
+ function SwitchResolver() {
8
9
  return {
9
10
  type: "component",
10
11
  resolve: (name2) => {
@@ -14,4 +15,4 @@ function DestylerTemplateResolver() {
14
15
  };
15
16
  }
16
17
 
17
- export { DestylerTemplateResolver, switchComponentName };
18
+ export { SwitchResolver, switchComponentName };
package/package.json CHANGED
@@ -1,24 +1,22 @@
1
1
  {
2
2
  "name": "@destyler/switch",
3
- "version": "0.0.2",
4
- "description": "unstyled switch component for vue",
3
+ "type": "module",
4
+ "version": "0.0.4",
5
+ "description": "a control that allows the user to toggle between checked and not checked.",
5
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
6
7
  "license": "MIT",
7
8
  "exports": {
8
9
  ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
12
12
  },
13
13
  "./resolver": {
14
- "types": "./dist/resolver.d.ts",
15
- "import": "./dist/resolver.mjs",
16
- "require": "./dist/resolver.cjs"
14
+ "types": "./dist/resolver.d.mts",
15
+ "default": "./dist/resolver.mjs"
17
16
  },
18
17
  "./component": {
19
- "types": "./dist/component.d.ts",
20
- "import": "./dist/component.mjs",
21
- "require": "./dist/component.cjs"
18
+ "types": "./dist/component.d.mts",
19
+ "default": "./dist/component.mjs"
22
20
  },
23
21
  "./*": "./*"
24
22
  },
@@ -30,16 +28,17 @@
30
28
  "dist"
31
29
  ],
32
30
  "peerDependencies": {
33
- "vue": ">=3.3.4"
31
+ "vue": ">=3.4.21"
34
32
  },
35
33
  "dependencies": {
36
- "@destyler/composition": "0.0.2",
37
- "@destyler/shared": "0.0.2",
38
- "@destyler/directives": "0.0.2",
39
- "@destyler/primitive": "0.0.2"
34
+ "@destyler/shared": "0.0.4",
35
+ "@destyler/directives": "0.0.4",
36
+ "@destyler/composition": "0.0.4",
37
+ "@destyler/primitive": "0.0.4"
40
38
  },
41
39
  "scripts": {
42
40
  "clear": "rimraf ./dist",
43
- "build": "pnpm run clear && unbuild"
41
+ "build": "pnpm run clear && unbuild",
42
+ "stub": "unbuild --stub"
44
43
  }
45
44
  }