@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/README.md +7 -0
- package/dist/component.cjs +5 -2
- package/dist/component.d.cts +1 -1
- package/dist/component.d.mts +1 -1
- package/dist/component.d.ts +1 -1
- package/dist/component.mjs +1 -1
- package/dist/index.cjs +52 -29
- package/dist/index.d.cts +133 -41
- package/dist/index.d.mts +133 -41
- package/dist/index.d.ts +133 -41
- package/dist/index.mjs +49 -29
- package/dist/resolver.cjs +4 -3
- package/dist/resolver.d.cts +2 -2
- package/dist/resolver.d.mts +2 -2
- package/dist/resolver.d.ts +2 -2
- package/dist/resolver.mjs +4 -3
- package/package.json +16 -17
package/dist/index.mjs
CHANGED
|
@@ -1,56 +1,80 @@
|
|
|
1
1
|
import { defineComponent, toRefs, computed, withDirectives, h, mergeProps, withModifiers } from 'vue';
|
|
2
|
-
import {
|
|
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
|
|
7
|
+
const switchRootProps = {
|
|
8
|
+
...primitiveProps,
|
|
9
|
+
/**
|
|
10
|
+
* @default button
|
|
11
|
+
*/
|
|
8
12
|
as: {
|
|
9
|
-
|
|
10
|
-
required: false,
|
|
13
|
+
...primitiveProps.as,
|
|
11
14
|
default: "button"
|
|
12
15
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
74
|
+
const SwitchRoot = defineComponent({
|
|
51
75
|
name: "DestylerSwitchRoot",
|
|
52
|
-
props:
|
|
53
|
-
emits:
|
|
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(
|
|
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
|
|
153
|
+
const switchThumbProps = {
|
|
154
|
+
...primitiveProps,
|
|
155
|
+
/**
|
|
156
|
+
* @default span
|
|
157
|
+
*/
|
|
132
158
|
as: {
|
|
133
|
-
|
|
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
|
|
163
|
+
const SwitchThumb = defineComponent({
|
|
144
164
|
name: "DestylerSwitchThump",
|
|
145
|
-
props:
|
|
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(
|
|
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 {
|
|
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
|
-
"
|
|
7
|
+
"SwitchRoot",
|
|
8
|
+
"SwitchThumb"
|
|
8
9
|
];
|
|
9
|
-
function
|
|
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.
|
|
20
|
+
exports.SwitchResolver = SwitchResolver;
|
|
20
21
|
exports.switchComponentName = switchComponentName;
|
package/dist/resolver.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
2
|
|
|
3
3
|
declare const switchComponentName: string[];
|
|
4
|
-
declare function
|
|
4
|
+
declare function SwitchResolver(): ComponentResolver;
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { SwitchResolver, switchComponentName };
|
package/dist/resolver.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
2
|
|
|
3
3
|
declare const switchComponentName: string[];
|
|
4
|
-
declare function
|
|
4
|
+
declare function SwitchResolver(): ComponentResolver;
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { SwitchResolver, switchComponentName };
|
package/dist/resolver.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
2
|
|
|
3
3
|
declare const switchComponentName: string[];
|
|
4
|
-
declare function
|
|
4
|
+
declare function SwitchResolver(): ComponentResolver;
|
|
5
5
|
|
|
6
|
-
export {
|
|
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
|
-
"
|
|
5
|
+
"SwitchRoot",
|
|
6
|
+
"SwitchThumb"
|
|
6
7
|
];
|
|
7
|
-
function
|
|
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 {
|
|
18
|
+
export { SwitchResolver, switchComponentName };
|
package/package.json
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/switch",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
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.
|
|
10
|
-
"
|
|
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.
|
|
15
|
-
"
|
|
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.
|
|
20
|
-
"
|
|
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.
|
|
31
|
+
"vue": ">=3.4.21"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"@destyler/
|
|
37
|
-
"@destyler/
|
|
38
|
-
"@destyler/
|
|
39
|
-
"@destyler/primitive": "0.0.
|
|
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
|
}
|