@destyler/switch 0.0.3 → 0.0.5

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,
@@ -126,21 +150,19 @@ const DestylerSwitchRoot = defineComponent({
126
150
  }
127
151
  });
128
152
 
129
- const destylerSwitchThumpProps = {
153
+ const switchThumbProps = {
154
+ ...primitiveProps,
155
+ /**
156
+ * @default span
157
+ */
130
158
  as: {
131
- type: [String, Object],
132
- required: false,
159
+ ...primitiveProps.as,
133
160
  default: "span"
134
- },
135
- asChild: {
136
- type: Boolean,
137
- required: false,
138
- default: false
139
161
  }
140
162
  };
141
- const DestylerSwitchThump = defineComponent({
163
+ const SwitchThumb = defineComponent({
142
164
  name: "DestylerSwitchThump",
143
- props: destylerSwitchThumpProps,
165
+ props: switchThumbProps,
144
166
  setup(_) {
145
167
  const rootContext = injectSwitchRootContext();
146
168
  useForwardExpose();
@@ -149,7 +171,7 @@ const DestylerSwitchThump = defineComponent({
149
171
  };
150
172
  },
151
173
  render() {
152
- return h(DestylerPrimitive, {
174
+ return h(Primitive, {
153
175
  "data-state": this.rootContext.checked?.value ? "checked" : "unchecked",
154
176
  "data-disabled": this.rootContext.disabled.value ? "" : void 0,
155
177
  "asChild": this.$props.asChild,
@@ -158,4 +180,4 @@ const DestylerSwitchThump = defineComponent({
158
180
  }
159
181
  });
160
182
 
161
- 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,25 +1,22 @@
1
1
  {
2
2
  "name": "@destyler/switch",
3
3
  "type": "module",
4
- "version": "0.0.3",
5
- "description": "unstyled switch component for vue",
4
+ "version": "0.0.5",
5
+ "description": "a control that allows the user to toggle between checked and not checked.",
6
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
7
7
  "license": "MIT",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs"
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
13
12
  },
14
13
  "./resolver": {
15
- "types": "./dist/resolver.d.ts",
16
- "import": "./dist/resolver.mjs",
17
- "require": "./dist/resolver.cjs"
14
+ "types": "./dist/resolver.d.mts",
15
+ "default": "./dist/resolver.mjs"
18
16
  },
19
17
  "./component": {
20
- "types": "./dist/component.d.ts",
21
- "import": "./dist/component.mjs",
22
- "require": "./dist/component.cjs"
18
+ "types": "./dist/component.d.mts",
19
+ "default": "./dist/component.mjs"
23
20
  },
24
21
  "./*": "./*"
25
22
  },
@@ -31,16 +28,17 @@
31
28
  "dist"
32
29
  ],
33
30
  "peerDependencies": {
34
- "vue": ">=3.3.4"
31
+ "vue": ">=3.4.21"
35
32
  },
36
33
  "dependencies": {
37
- "@destyler/composition": "0.0.3",
38
- "@destyler/shared": "0.0.3",
39
- "@destyler/primitive": "0.0.3",
40
- "@destyler/directives": "0.0.3"
34
+ "@destyler/composition": "0.0.5",
35
+ "@destyler/directives": "0.0.5",
36
+ "@destyler/primitive": "0.0.5",
37
+ "@destyler/shared": "0.0.5"
41
38
  },
42
39
  "scripts": {
43
40
  "clear": "rimraf ./dist",
44
- "build": "pnpm run clear && unbuild"
41
+ "build": "pnpm run clear && unbuild",
42
+ "stub": "unbuild --stub"
45
43
  }
46
44
  }