@destyler/checkbox 0.0.1-beta.7
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.cjs +180 -0
- package/dist/index.d.cts +227 -0
- package/dist/index.d.mts +227 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.mjs +172 -0
- package/package.json +36 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const primitive = require('@destyler/primitive');
|
|
5
|
+
const composition = require('@destyler/composition');
|
|
6
|
+
const shared = require('@destyler/shared');
|
|
7
|
+
const directives = require('@destyler/directives');
|
|
8
|
+
const presence = require('@destyler/presence');
|
|
9
|
+
|
|
10
|
+
function isIndeterminate(checked) {
|
|
11
|
+
return checked === "indeterminate";
|
|
12
|
+
}
|
|
13
|
+
function getState(checked) {
|
|
14
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const destylerCheckboxRootProps = {
|
|
18
|
+
...primitive.destylerPrimitiveProp,
|
|
19
|
+
as: {
|
|
20
|
+
type: [String, Object],
|
|
21
|
+
required: false,
|
|
22
|
+
default: "button"
|
|
23
|
+
},
|
|
24
|
+
defaultChecked: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
checked: {
|
|
29
|
+
type: [Boolean, String],
|
|
30
|
+
required: false,
|
|
31
|
+
default: void 0
|
|
32
|
+
},
|
|
33
|
+
disabled: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
required: false,
|
|
36
|
+
default: false
|
|
37
|
+
},
|
|
38
|
+
required: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
42
|
+
name: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: false
|
|
45
|
+
},
|
|
46
|
+
value: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: false,
|
|
49
|
+
default: "on"
|
|
50
|
+
},
|
|
51
|
+
id: {
|
|
52
|
+
type: String,
|
|
53
|
+
required: false
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const [injectCheckboxRootContext, provideCheckboxRootContext] = shared.createContext("CheckboxRoot");
|
|
57
|
+
const DestylerCheckboxRoot = vue.defineComponent({
|
|
58
|
+
name: "DestylerCheckboxRoot",
|
|
59
|
+
props: destylerCheckboxRootProps,
|
|
60
|
+
emits: ["update:checked"],
|
|
61
|
+
setup(props, { emit }) {
|
|
62
|
+
const disabledRef = vue.toRef(props.disabled);
|
|
63
|
+
const checkedRef = composition.useVModel(props, "checked", emit, {
|
|
64
|
+
defaultValue: props.defaultChecked,
|
|
65
|
+
passive: props.checked === void 0
|
|
66
|
+
});
|
|
67
|
+
const { customElement, currentElement } = composition.useCustomElement();
|
|
68
|
+
const isFormControl = composition.useFormControl(currentElement);
|
|
69
|
+
const ariaLabel = vue.computed(() => props.id && currentElement.value ? document.querySelector(`[for="${props.id}"]`)?.textContent : void 0);
|
|
70
|
+
provideCheckboxRootContext({
|
|
71
|
+
disabled: disabledRef,
|
|
72
|
+
state: checkedRef
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
disabled: disabledRef,
|
|
76
|
+
checked: checkedRef,
|
|
77
|
+
customElement,
|
|
78
|
+
isFormControl,
|
|
79
|
+
ariaLabel
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
render() {
|
|
83
|
+
const useVShow = this.isFormControl;
|
|
84
|
+
return [
|
|
85
|
+
vue.withDirectives(vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$attrs, {
|
|
86
|
+
"ref": "customElement",
|
|
87
|
+
"role": "checkbox",
|
|
88
|
+
"asChild": this.$props.asChild,
|
|
89
|
+
"as": this.$props.as,
|
|
90
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
91
|
+
"aria-checked": isIndeterminate(this.checked) ? "mixed" : this.checked,
|
|
92
|
+
"aria-required": false,
|
|
93
|
+
"aria-label": this.$attrs["aria-label"] || this.ariaLabel,
|
|
94
|
+
"data-state": getState(this.checked),
|
|
95
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
96
|
+
"disabled": this.disabled,
|
|
97
|
+
"onClick": () => {
|
|
98
|
+
this.checked = !this.checked;
|
|
99
|
+
}
|
|
100
|
+
}), this.$slots.default?.()), [
|
|
101
|
+
[directives.BindOnceDirective, { id: this.$props.id }]
|
|
102
|
+
]),
|
|
103
|
+
useVShow ? vue.h("input", {
|
|
104
|
+
"type": "checkbox",
|
|
105
|
+
"tabindex": "-1",
|
|
106
|
+
"aria-hidden": "",
|
|
107
|
+
"value": this.$props.value,
|
|
108
|
+
"checked": this.checked,
|
|
109
|
+
"name": this.$props.name,
|
|
110
|
+
"disabled": this.disabled,
|
|
111
|
+
"required": this.$props.required,
|
|
112
|
+
"style": {
|
|
113
|
+
transform: "translateX(-100%)",
|
|
114
|
+
position: "absolute",
|
|
115
|
+
pointerEvents: "none",
|
|
116
|
+
opacity: 0,
|
|
117
|
+
margin: 0
|
|
118
|
+
}
|
|
119
|
+
}) : null
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const destylerCheckboxIndicatorProps = {
|
|
125
|
+
...primitive.destylerPrimitiveProp,
|
|
126
|
+
as: {
|
|
127
|
+
type: [String, Object],
|
|
128
|
+
required: false,
|
|
129
|
+
default: "button"
|
|
130
|
+
},
|
|
131
|
+
forceMount: {
|
|
132
|
+
type: Boolean,
|
|
133
|
+
required: false,
|
|
134
|
+
default: false
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const DestylerCheckboxIndicator = vue.defineComponent({
|
|
138
|
+
name: "DestylerCheckboxIndicator",
|
|
139
|
+
props: destylerCheckboxIndicatorProps,
|
|
140
|
+
setup() {
|
|
141
|
+
const rootContext = injectCheckboxRootContext();
|
|
142
|
+
return {
|
|
143
|
+
rootContext
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
render() {
|
|
147
|
+
return vue.h(presence.DestylerPresence, {
|
|
148
|
+
present: this.$props.forceMount || isIndeterminate(this.rootContext.state.value) || this.rootContext.state.value === true
|
|
149
|
+
}, vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$attrs, {
|
|
150
|
+
"data-state": getState(this.rootContext.state.value),
|
|
151
|
+
"data-disabled": this.rootContext.disabled.value ? "" : void 0,
|
|
152
|
+
"asChild": this.$props.asChild,
|
|
153
|
+
"as": this.$props.as,
|
|
154
|
+
"style": {
|
|
155
|
+
pointerEvents: "none"
|
|
156
|
+
}
|
|
157
|
+
}), this.$slots.default?.()));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const name = "@destyler/checkbox";
|
|
162
|
+
|
|
163
|
+
const packageName = name;
|
|
164
|
+
function DestylerCheckboxResolver() {
|
|
165
|
+
return {
|
|
166
|
+
type: "component",
|
|
167
|
+
resolve: (name2) => {
|
|
168
|
+
if (name2 === "DestylerTemplate")
|
|
169
|
+
return { name: name2, from: packageName };
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.DestylerCheckboxIndicator = DestylerCheckboxIndicator;
|
|
175
|
+
exports.DestylerCheckboxResolver = DestylerCheckboxResolver;
|
|
176
|
+
exports.DestylerCheckboxRoot = DestylerCheckboxRoot;
|
|
177
|
+
exports.destylerCheckboxIndicatorProps = destylerCheckboxIndicatorProps;
|
|
178
|
+
exports.destylerCheckboxRootProps = destylerCheckboxRootProps;
|
|
179
|
+
exports.injectCheckboxRootContext = injectCheckboxRootContext;
|
|
180
|
+
exports.provideCheckboxRootContext = provideCheckboxRootContext;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { Component, PropType, Ref } from 'vue';
|
|
3
|
+
import { AsTag } from '@destyler/primitive';
|
|
4
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
5
|
+
|
|
6
|
+
type CheckedState = boolean | 'indeterminate';
|
|
7
|
+
|
|
8
|
+
interface DestylerCheckboxRootProps {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
as?: AsTag | Component;
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
checked?: boolean | 'indeterminate';
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
name?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const destylerCheckboxRootProps: {
|
|
20
|
+
readonly as: {
|
|
21
|
+
readonly type: PropType<AsTag | Component>;
|
|
22
|
+
readonly required: false;
|
|
23
|
+
readonly default: "button";
|
|
24
|
+
};
|
|
25
|
+
readonly defaultChecked: {
|
|
26
|
+
readonly type: PropType<boolean>;
|
|
27
|
+
readonly required: false;
|
|
28
|
+
};
|
|
29
|
+
readonly checked: {
|
|
30
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
31
|
+
readonly required: false;
|
|
32
|
+
readonly default: undefined;
|
|
33
|
+
};
|
|
34
|
+
readonly disabled: {
|
|
35
|
+
readonly type: PropType<boolean>;
|
|
36
|
+
readonly required: false;
|
|
37
|
+
readonly default: false;
|
|
38
|
+
};
|
|
39
|
+
readonly required: {
|
|
40
|
+
readonly type: PropType<boolean>;
|
|
41
|
+
readonly required: false;
|
|
42
|
+
};
|
|
43
|
+
readonly name: {
|
|
44
|
+
readonly type: PropType<string>;
|
|
45
|
+
readonly required: false;
|
|
46
|
+
};
|
|
47
|
+
readonly value: {
|
|
48
|
+
readonly type: PropType<string>;
|
|
49
|
+
readonly required: false;
|
|
50
|
+
readonly default: "on";
|
|
51
|
+
};
|
|
52
|
+
readonly id: {
|
|
53
|
+
readonly type: PropType<string>;
|
|
54
|
+
readonly required: false;
|
|
55
|
+
};
|
|
56
|
+
readonly asChild: {
|
|
57
|
+
type: PropType<boolean>;
|
|
58
|
+
required: boolean;
|
|
59
|
+
default: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
interface CheckboxRootContext {
|
|
63
|
+
disabled: Ref<boolean>;
|
|
64
|
+
state: Ref<CheckedState>;
|
|
65
|
+
}
|
|
66
|
+
declare const injectCheckboxRootContext: <T extends CheckboxRootContext | null | undefined = CheckboxRootContext>(fallback?: T | undefined) => T extends null ? CheckboxRootContext | null : CheckboxRootContext;
|
|
67
|
+
declare const provideCheckboxRootContext: (contextValue: CheckboxRootContext) => CheckboxRootContext;
|
|
68
|
+
declare const DestylerCheckboxRoot: vue.DefineComponent<{
|
|
69
|
+
readonly as: {
|
|
70
|
+
readonly type: PropType<AsTag | Component>;
|
|
71
|
+
readonly required: false;
|
|
72
|
+
readonly default: "button";
|
|
73
|
+
};
|
|
74
|
+
readonly defaultChecked: {
|
|
75
|
+
readonly type: PropType<boolean>;
|
|
76
|
+
readonly required: false;
|
|
77
|
+
};
|
|
78
|
+
readonly checked: {
|
|
79
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
80
|
+
readonly required: false;
|
|
81
|
+
readonly default: undefined;
|
|
82
|
+
};
|
|
83
|
+
readonly disabled: {
|
|
84
|
+
readonly type: PropType<boolean>;
|
|
85
|
+
readonly required: false;
|
|
86
|
+
readonly default: false;
|
|
87
|
+
};
|
|
88
|
+
readonly required: {
|
|
89
|
+
readonly type: PropType<boolean>;
|
|
90
|
+
readonly required: false;
|
|
91
|
+
};
|
|
92
|
+
readonly name: {
|
|
93
|
+
readonly type: PropType<string>;
|
|
94
|
+
readonly required: false;
|
|
95
|
+
};
|
|
96
|
+
readonly value: {
|
|
97
|
+
readonly type: PropType<string>;
|
|
98
|
+
readonly required: false;
|
|
99
|
+
readonly default: "on";
|
|
100
|
+
};
|
|
101
|
+
readonly id: {
|
|
102
|
+
readonly type: PropType<string>;
|
|
103
|
+
readonly required: false;
|
|
104
|
+
};
|
|
105
|
+
readonly asChild: {
|
|
106
|
+
type: PropType<boolean>;
|
|
107
|
+
required: boolean;
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
110
|
+
}, {
|
|
111
|
+
disabled: Ref<false> | Ref<true>;
|
|
112
|
+
checked: Ref<CheckedState>;
|
|
113
|
+
customElement: Ref<vue.ComponentPublicInstance | undefined>;
|
|
114
|
+
isFormControl: vue.ComputedRef<boolean>;
|
|
115
|
+
ariaLabel: vue.ComputedRef<string | null | undefined>;
|
|
116
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:checked"[], "update:checked", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
117
|
+
readonly as: {
|
|
118
|
+
readonly type: PropType<AsTag | Component>;
|
|
119
|
+
readonly required: false;
|
|
120
|
+
readonly default: "button";
|
|
121
|
+
};
|
|
122
|
+
readonly defaultChecked: {
|
|
123
|
+
readonly type: PropType<boolean>;
|
|
124
|
+
readonly required: false;
|
|
125
|
+
};
|
|
126
|
+
readonly checked: {
|
|
127
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
128
|
+
readonly required: false;
|
|
129
|
+
readonly default: undefined;
|
|
130
|
+
};
|
|
131
|
+
readonly disabled: {
|
|
132
|
+
readonly type: PropType<boolean>;
|
|
133
|
+
readonly required: false;
|
|
134
|
+
readonly default: false;
|
|
135
|
+
};
|
|
136
|
+
readonly required: {
|
|
137
|
+
readonly type: PropType<boolean>;
|
|
138
|
+
readonly required: false;
|
|
139
|
+
};
|
|
140
|
+
readonly name: {
|
|
141
|
+
readonly type: PropType<string>;
|
|
142
|
+
readonly required: false;
|
|
143
|
+
};
|
|
144
|
+
readonly value: {
|
|
145
|
+
readonly type: PropType<string>;
|
|
146
|
+
readonly required: false;
|
|
147
|
+
readonly default: "on";
|
|
148
|
+
};
|
|
149
|
+
readonly id: {
|
|
150
|
+
readonly type: PropType<string>;
|
|
151
|
+
readonly required: false;
|
|
152
|
+
};
|
|
153
|
+
readonly asChild: {
|
|
154
|
+
type: PropType<boolean>;
|
|
155
|
+
required: boolean;
|
|
156
|
+
default: boolean;
|
|
157
|
+
};
|
|
158
|
+
}>> & {
|
|
159
|
+
"onUpdate:checked"?: ((...args: any[]) => any) | undefined;
|
|
160
|
+
}, {
|
|
161
|
+
readonly checked: boolean | "indeterminate";
|
|
162
|
+
readonly as: AsTag | Component;
|
|
163
|
+
readonly disabled: boolean;
|
|
164
|
+
readonly value: string;
|
|
165
|
+
readonly asChild: boolean;
|
|
166
|
+
}, {}>;
|
|
167
|
+
|
|
168
|
+
declare const destylerCheckboxIndicatorProps: {
|
|
169
|
+
as: {
|
|
170
|
+
type: PropType<AsTag | Component>;
|
|
171
|
+
required: boolean;
|
|
172
|
+
default: string;
|
|
173
|
+
};
|
|
174
|
+
forceMount: {
|
|
175
|
+
type: PropType<boolean>;
|
|
176
|
+
required: boolean;
|
|
177
|
+
default: boolean;
|
|
178
|
+
};
|
|
179
|
+
asChild: {
|
|
180
|
+
type: PropType<boolean>;
|
|
181
|
+
required: boolean;
|
|
182
|
+
default: boolean;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
declare const DestylerCheckboxIndicator: vue.DefineComponent<{
|
|
186
|
+
as: {
|
|
187
|
+
type: PropType<AsTag | Component>;
|
|
188
|
+
required: boolean;
|
|
189
|
+
default: string;
|
|
190
|
+
};
|
|
191
|
+
forceMount: {
|
|
192
|
+
type: PropType<boolean>;
|
|
193
|
+
required: boolean;
|
|
194
|
+
default: boolean;
|
|
195
|
+
};
|
|
196
|
+
asChild: {
|
|
197
|
+
type: PropType<boolean>;
|
|
198
|
+
required: boolean;
|
|
199
|
+
default: boolean;
|
|
200
|
+
};
|
|
201
|
+
}, {
|
|
202
|
+
rootContext: CheckboxRootContext;
|
|
203
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
204
|
+
as: {
|
|
205
|
+
type: PropType<AsTag | Component>;
|
|
206
|
+
required: boolean;
|
|
207
|
+
default: string;
|
|
208
|
+
};
|
|
209
|
+
forceMount: {
|
|
210
|
+
type: PropType<boolean>;
|
|
211
|
+
required: boolean;
|
|
212
|
+
default: boolean;
|
|
213
|
+
};
|
|
214
|
+
asChild: {
|
|
215
|
+
type: PropType<boolean>;
|
|
216
|
+
required: boolean;
|
|
217
|
+
default: boolean;
|
|
218
|
+
};
|
|
219
|
+
}>>, {
|
|
220
|
+
as: AsTag | Component;
|
|
221
|
+
asChild: boolean;
|
|
222
|
+
forceMount: boolean;
|
|
223
|
+
}, {}>;
|
|
224
|
+
|
|
225
|
+
declare function DestylerCheckboxResolver(): ComponentResolver;
|
|
226
|
+
|
|
227
|
+
export { type CheckboxRootContext, DestylerCheckboxIndicator, DestylerCheckboxResolver, DestylerCheckboxRoot, type DestylerCheckboxRootProps, destylerCheckboxIndicatorProps, destylerCheckboxRootProps, injectCheckboxRootContext, provideCheckboxRootContext };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { Component, PropType, Ref } from 'vue';
|
|
3
|
+
import { AsTag } from '@destyler/primitive';
|
|
4
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
5
|
+
|
|
6
|
+
type CheckedState = boolean | 'indeterminate';
|
|
7
|
+
|
|
8
|
+
interface DestylerCheckboxRootProps {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
as?: AsTag | Component;
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
checked?: boolean | 'indeterminate';
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
name?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const destylerCheckboxRootProps: {
|
|
20
|
+
readonly as: {
|
|
21
|
+
readonly type: PropType<AsTag | Component>;
|
|
22
|
+
readonly required: false;
|
|
23
|
+
readonly default: "button";
|
|
24
|
+
};
|
|
25
|
+
readonly defaultChecked: {
|
|
26
|
+
readonly type: PropType<boolean>;
|
|
27
|
+
readonly required: false;
|
|
28
|
+
};
|
|
29
|
+
readonly checked: {
|
|
30
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
31
|
+
readonly required: false;
|
|
32
|
+
readonly default: undefined;
|
|
33
|
+
};
|
|
34
|
+
readonly disabled: {
|
|
35
|
+
readonly type: PropType<boolean>;
|
|
36
|
+
readonly required: false;
|
|
37
|
+
readonly default: false;
|
|
38
|
+
};
|
|
39
|
+
readonly required: {
|
|
40
|
+
readonly type: PropType<boolean>;
|
|
41
|
+
readonly required: false;
|
|
42
|
+
};
|
|
43
|
+
readonly name: {
|
|
44
|
+
readonly type: PropType<string>;
|
|
45
|
+
readonly required: false;
|
|
46
|
+
};
|
|
47
|
+
readonly value: {
|
|
48
|
+
readonly type: PropType<string>;
|
|
49
|
+
readonly required: false;
|
|
50
|
+
readonly default: "on";
|
|
51
|
+
};
|
|
52
|
+
readonly id: {
|
|
53
|
+
readonly type: PropType<string>;
|
|
54
|
+
readonly required: false;
|
|
55
|
+
};
|
|
56
|
+
readonly asChild: {
|
|
57
|
+
type: PropType<boolean>;
|
|
58
|
+
required: boolean;
|
|
59
|
+
default: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
interface CheckboxRootContext {
|
|
63
|
+
disabled: Ref<boolean>;
|
|
64
|
+
state: Ref<CheckedState>;
|
|
65
|
+
}
|
|
66
|
+
declare const injectCheckboxRootContext: <T extends CheckboxRootContext | null | undefined = CheckboxRootContext>(fallback?: T | undefined) => T extends null ? CheckboxRootContext | null : CheckboxRootContext;
|
|
67
|
+
declare const provideCheckboxRootContext: (contextValue: CheckboxRootContext) => CheckboxRootContext;
|
|
68
|
+
declare const DestylerCheckboxRoot: vue.DefineComponent<{
|
|
69
|
+
readonly as: {
|
|
70
|
+
readonly type: PropType<AsTag | Component>;
|
|
71
|
+
readonly required: false;
|
|
72
|
+
readonly default: "button";
|
|
73
|
+
};
|
|
74
|
+
readonly defaultChecked: {
|
|
75
|
+
readonly type: PropType<boolean>;
|
|
76
|
+
readonly required: false;
|
|
77
|
+
};
|
|
78
|
+
readonly checked: {
|
|
79
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
80
|
+
readonly required: false;
|
|
81
|
+
readonly default: undefined;
|
|
82
|
+
};
|
|
83
|
+
readonly disabled: {
|
|
84
|
+
readonly type: PropType<boolean>;
|
|
85
|
+
readonly required: false;
|
|
86
|
+
readonly default: false;
|
|
87
|
+
};
|
|
88
|
+
readonly required: {
|
|
89
|
+
readonly type: PropType<boolean>;
|
|
90
|
+
readonly required: false;
|
|
91
|
+
};
|
|
92
|
+
readonly name: {
|
|
93
|
+
readonly type: PropType<string>;
|
|
94
|
+
readonly required: false;
|
|
95
|
+
};
|
|
96
|
+
readonly value: {
|
|
97
|
+
readonly type: PropType<string>;
|
|
98
|
+
readonly required: false;
|
|
99
|
+
readonly default: "on";
|
|
100
|
+
};
|
|
101
|
+
readonly id: {
|
|
102
|
+
readonly type: PropType<string>;
|
|
103
|
+
readonly required: false;
|
|
104
|
+
};
|
|
105
|
+
readonly asChild: {
|
|
106
|
+
type: PropType<boolean>;
|
|
107
|
+
required: boolean;
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
110
|
+
}, {
|
|
111
|
+
disabled: Ref<false> | Ref<true>;
|
|
112
|
+
checked: Ref<CheckedState>;
|
|
113
|
+
customElement: Ref<vue.ComponentPublicInstance | undefined>;
|
|
114
|
+
isFormControl: vue.ComputedRef<boolean>;
|
|
115
|
+
ariaLabel: vue.ComputedRef<string | null | undefined>;
|
|
116
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:checked"[], "update:checked", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
117
|
+
readonly as: {
|
|
118
|
+
readonly type: PropType<AsTag | Component>;
|
|
119
|
+
readonly required: false;
|
|
120
|
+
readonly default: "button";
|
|
121
|
+
};
|
|
122
|
+
readonly defaultChecked: {
|
|
123
|
+
readonly type: PropType<boolean>;
|
|
124
|
+
readonly required: false;
|
|
125
|
+
};
|
|
126
|
+
readonly checked: {
|
|
127
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
128
|
+
readonly required: false;
|
|
129
|
+
readonly default: undefined;
|
|
130
|
+
};
|
|
131
|
+
readonly disabled: {
|
|
132
|
+
readonly type: PropType<boolean>;
|
|
133
|
+
readonly required: false;
|
|
134
|
+
readonly default: false;
|
|
135
|
+
};
|
|
136
|
+
readonly required: {
|
|
137
|
+
readonly type: PropType<boolean>;
|
|
138
|
+
readonly required: false;
|
|
139
|
+
};
|
|
140
|
+
readonly name: {
|
|
141
|
+
readonly type: PropType<string>;
|
|
142
|
+
readonly required: false;
|
|
143
|
+
};
|
|
144
|
+
readonly value: {
|
|
145
|
+
readonly type: PropType<string>;
|
|
146
|
+
readonly required: false;
|
|
147
|
+
readonly default: "on";
|
|
148
|
+
};
|
|
149
|
+
readonly id: {
|
|
150
|
+
readonly type: PropType<string>;
|
|
151
|
+
readonly required: false;
|
|
152
|
+
};
|
|
153
|
+
readonly asChild: {
|
|
154
|
+
type: PropType<boolean>;
|
|
155
|
+
required: boolean;
|
|
156
|
+
default: boolean;
|
|
157
|
+
};
|
|
158
|
+
}>> & {
|
|
159
|
+
"onUpdate:checked"?: ((...args: any[]) => any) | undefined;
|
|
160
|
+
}, {
|
|
161
|
+
readonly checked: boolean | "indeterminate";
|
|
162
|
+
readonly as: AsTag | Component;
|
|
163
|
+
readonly disabled: boolean;
|
|
164
|
+
readonly value: string;
|
|
165
|
+
readonly asChild: boolean;
|
|
166
|
+
}, {}>;
|
|
167
|
+
|
|
168
|
+
declare const destylerCheckboxIndicatorProps: {
|
|
169
|
+
as: {
|
|
170
|
+
type: PropType<AsTag | Component>;
|
|
171
|
+
required: boolean;
|
|
172
|
+
default: string;
|
|
173
|
+
};
|
|
174
|
+
forceMount: {
|
|
175
|
+
type: PropType<boolean>;
|
|
176
|
+
required: boolean;
|
|
177
|
+
default: boolean;
|
|
178
|
+
};
|
|
179
|
+
asChild: {
|
|
180
|
+
type: PropType<boolean>;
|
|
181
|
+
required: boolean;
|
|
182
|
+
default: boolean;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
declare const DestylerCheckboxIndicator: vue.DefineComponent<{
|
|
186
|
+
as: {
|
|
187
|
+
type: PropType<AsTag | Component>;
|
|
188
|
+
required: boolean;
|
|
189
|
+
default: string;
|
|
190
|
+
};
|
|
191
|
+
forceMount: {
|
|
192
|
+
type: PropType<boolean>;
|
|
193
|
+
required: boolean;
|
|
194
|
+
default: boolean;
|
|
195
|
+
};
|
|
196
|
+
asChild: {
|
|
197
|
+
type: PropType<boolean>;
|
|
198
|
+
required: boolean;
|
|
199
|
+
default: boolean;
|
|
200
|
+
};
|
|
201
|
+
}, {
|
|
202
|
+
rootContext: CheckboxRootContext;
|
|
203
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
204
|
+
as: {
|
|
205
|
+
type: PropType<AsTag | Component>;
|
|
206
|
+
required: boolean;
|
|
207
|
+
default: string;
|
|
208
|
+
};
|
|
209
|
+
forceMount: {
|
|
210
|
+
type: PropType<boolean>;
|
|
211
|
+
required: boolean;
|
|
212
|
+
default: boolean;
|
|
213
|
+
};
|
|
214
|
+
asChild: {
|
|
215
|
+
type: PropType<boolean>;
|
|
216
|
+
required: boolean;
|
|
217
|
+
default: boolean;
|
|
218
|
+
};
|
|
219
|
+
}>>, {
|
|
220
|
+
as: AsTag | Component;
|
|
221
|
+
asChild: boolean;
|
|
222
|
+
forceMount: boolean;
|
|
223
|
+
}, {}>;
|
|
224
|
+
|
|
225
|
+
declare function DestylerCheckboxResolver(): ComponentResolver;
|
|
226
|
+
|
|
227
|
+
export { type CheckboxRootContext, DestylerCheckboxIndicator, DestylerCheckboxResolver, DestylerCheckboxRoot, type DestylerCheckboxRootProps, destylerCheckboxIndicatorProps, destylerCheckboxRootProps, injectCheckboxRootContext, provideCheckboxRootContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { Component, PropType, Ref } from 'vue';
|
|
3
|
+
import { AsTag } from '@destyler/primitive';
|
|
4
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
5
|
+
|
|
6
|
+
type CheckedState = boolean | 'indeterminate';
|
|
7
|
+
|
|
8
|
+
interface DestylerCheckboxRootProps {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
as?: AsTag | Component;
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
checked?: boolean | 'indeterminate';
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
name?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
id?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const destylerCheckboxRootProps: {
|
|
20
|
+
readonly as: {
|
|
21
|
+
readonly type: PropType<AsTag | Component>;
|
|
22
|
+
readonly required: false;
|
|
23
|
+
readonly default: "button";
|
|
24
|
+
};
|
|
25
|
+
readonly defaultChecked: {
|
|
26
|
+
readonly type: PropType<boolean>;
|
|
27
|
+
readonly required: false;
|
|
28
|
+
};
|
|
29
|
+
readonly checked: {
|
|
30
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
31
|
+
readonly required: false;
|
|
32
|
+
readonly default: undefined;
|
|
33
|
+
};
|
|
34
|
+
readonly disabled: {
|
|
35
|
+
readonly type: PropType<boolean>;
|
|
36
|
+
readonly required: false;
|
|
37
|
+
readonly default: false;
|
|
38
|
+
};
|
|
39
|
+
readonly required: {
|
|
40
|
+
readonly type: PropType<boolean>;
|
|
41
|
+
readonly required: false;
|
|
42
|
+
};
|
|
43
|
+
readonly name: {
|
|
44
|
+
readonly type: PropType<string>;
|
|
45
|
+
readonly required: false;
|
|
46
|
+
};
|
|
47
|
+
readonly value: {
|
|
48
|
+
readonly type: PropType<string>;
|
|
49
|
+
readonly required: false;
|
|
50
|
+
readonly default: "on";
|
|
51
|
+
};
|
|
52
|
+
readonly id: {
|
|
53
|
+
readonly type: PropType<string>;
|
|
54
|
+
readonly required: false;
|
|
55
|
+
};
|
|
56
|
+
readonly asChild: {
|
|
57
|
+
type: PropType<boolean>;
|
|
58
|
+
required: boolean;
|
|
59
|
+
default: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
interface CheckboxRootContext {
|
|
63
|
+
disabled: Ref<boolean>;
|
|
64
|
+
state: Ref<CheckedState>;
|
|
65
|
+
}
|
|
66
|
+
declare const injectCheckboxRootContext: <T extends CheckboxRootContext | null | undefined = CheckboxRootContext>(fallback?: T | undefined) => T extends null ? CheckboxRootContext | null : CheckboxRootContext;
|
|
67
|
+
declare const provideCheckboxRootContext: (contextValue: CheckboxRootContext) => CheckboxRootContext;
|
|
68
|
+
declare const DestylerCheckboxRoot: vue.DefineComponent<{
|
|
69
|
+
readonly as: {
|
|
70
|
+
readonly type: PropType<AsTag | Component>;
|
|
71
|
+
readonly required: false;
|
|
72
|
+
readonly default: "button";
|
|
73
|
+
};
|
|
74
|
+
readonly defaultChecked: {
|
|
75
|
+
readonly type: PropType<boolean>;
|
|
76
|
+
readonly required: false;
|
|
77
|
+
};
|
|
78
|
+
readonly checked: {
|
|
79
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
80
|
+
readonly required: false;
|
|
81
|
+
readonly default: undefined;
|
|
82
|
+
};
|
|
83
|
+
readonly disabled: {
|
|
84
|
+
readonly type: PropType<boolean>;
|
|
85
|
+
readonly required: false;
|
|
86
|
+
readonly default: false;
|
|
87
|
+
};
|
|
88
|
+
readonly required: {
|
|
89
|
+
readonly type: PropType<boolean>;
|
|
90
|
+
readonly required: false;
|
|
91
|
+
};
|
|
92
|
+
readonly name: {
|
|
93
|
+
readonly type: PropType<string>;
|
|
94
|
+
readonly required: false;
|
|
95
|
+
};
|
|
96
|
+
readonly value: {
|
|
97
|
+
readonly type: PropType<string>;
|
|
98
|
+
readonly required: false;
|
|
99
|
+
readonly default: "on";
|
|
100
|
+
};
|
|
101
|
+
readonly id: {
|
|
102
|
+
readonly type: PropType<string>;
|
|
103
|
+
readonly required: false;
|
|
104
|
+
};
|
|
105
|
+
readonly asChild: {
|
|
106
|
+
type: PropType<boolean>;
|
|
107
|
+
required: boolean;
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
110
|
+
}, {
|
|
111
|
+
disabled: Ref<false> | Ref<true>;
|
|
112
|
+
checked: Ref<CheckedState>;
|
|
113
|
+
customElement: Ref<vue.ComponentPublicInstance | undefined>;
|
|
114
|
+
isFormControl: vue.ComputedRef<boolean>;
|
|
115
|
+
ariaLabel: vue.ComputedRef<string | null | undefined>;
|
|
116
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:checked"[], "update:checked", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
117
|
+
readonly as: {
|
|
118
|
+
readonly type: PropType<AsTag | Component>;
|
|
119
|
+
readonly required: false;
|
|
120
|
+
readonly default: "button";
|
|
121
|
+
};
|
|
122
|
+
readonly defaultChecked: {
|
|
123
|
+
readonly type: PropType<boolean>;
|
|
124
|
+
readonly required: false;
|
|
125
|
+
};
|
|
126
|
+
readonly checked: {
|
|
127
|
+
readonly type: PropType<boolean | "indeterminate">;
|
|
128
|
+
readonly required: false;
|
|
129
|
+
readonly default: undefined;
|
|
130
|
+
};
|
|
131
|
+
readonly disabled: {
|
|
132
|
+
readonly type: PropType<boolean>;
|
|
133
|
+
readonly required: false;
|
|
134
|
+
readonly default: false;
|
|
135
|
+
};
|
|
136
|
+
readonly required: {
|
|
137
|
+
readonly type: PropType<boolean>;
|
|
138
|
+
readonly required: false;
|
|
139
|
+
};
|
|
140
|
+
readonly name: {
|
|
141
|
+
readonly type: PropType<string>;
|
|
142
|
+
readonly required: false;
|
|
143
|
+
};
|
|
144
|
+
readonly value: {
|
|
145
|
+
readonly type: PropType<string>;
|
|
146
|
+
readonly required: false;
|
|
147
|
+
readonly default: "on";
|
|
148
|
+
};
|
|
149
|
+
readonly id: {
|
|
150
|
+
readonly type: PropType<string>;
|
|
151
|
+
readonly required: false;
|
|
152
|
+
};
|
|
153
|
+
readonly asChild: {
|
|
154
|
+
type: PropType<boolean>;
|
|
155
|
+
required: boolean;
|
|
156
|
+
default: boolean;
|
|
157
|
+
};
|
|
158
|
+
}>> & {
|
|
159
|
+
"onUpdate:checked"?: ((...args: any[]) => any) | undefined;
|
|
160
|
+
}, {
|
|
161
|
+
readonly checked: boolean | "indeterminate";
|
|
162
|
+
readonly as: AsTag | Component;
|
|
163
|
+
readonly disabled: boolean;
|
|
164
|
+
readonly value: string;
|
|
165
|
+
readonly asChild: boolean;
|
|
166
|
+
}, {}>;
|
|
167
|
+
|
|
168
|
+
declare const destylerCheckboxIndicatorProps: {
|
|
169
|
+
as: {
|
|
170
|
+
type: PropType<AsTag | Component>;
|
|
171
|
+
required: boolean;
|
|
172
|
+
default: string;
|
|
173
|
+
};
|
|
174
|
+
forceMount: {
|
|
175
|
+
type: PropType<boolean>;
|
|
176
|
+
required: boolean;
|
|
177
|
+
default: boolean;
|
|
178
|
+
};
|
|
179
|
+
asChild: {
|
|
180
|
+
type: PropType<boolean>;
|
|
181
|
+
required: boolean;
|
|
182
|
+
default: boolean;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
declare const DestylerCheckboxIndicator: vue.DefineComponent<{
|
|
186
|
+
as: {
|
|
187
|
+
type: PropType<AsTag | Component>;
|
|
188
|
+
required: boolean;
|
|
189
|
+
default: string;
|
|
190
|
+
};
|
|
191
|
+
forceMount: {
|
|
192
|
+
type: PropType<boolean>;
|
|
193
|
+
required: boolean;
|
|
194
|
+
default: boolean;
|
|
195
|
+
};
|
|
196
|
+
asChild: {
|
|
197
|
+
type: PropType<boolean>;
|
|
198
|
+
required: boolean;
|
|
199
|
+
default: boolean;
|
|
200
|
+
};
|
|
201
|
+
}, {
|
|
202
|
+
rootContext: CheckboxRootContext;
|
|
203
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
204
|
+
as: {
|
|
205
|
+
type: PropType<AsTag | Component>;
|
|
206
|
+
required: boolean;
|
|
207
|
+
default: string;
|
|
208
|
+
};
|
|
209
|
+
forceMount: {
|
|
210
|
+
type: PropType<boolean>;
|
|
211
|
+
required: boolean;
|
|
212
|
+
default: boolean;
|
|
213
|
+
};
|
|
214
|
+
asChild: {
|
|
215
|
+
type: PropType<boolean>;
|
|
216
|
+
required: boolean;
|
|
217
|
+
default: boolean;
|
|
218
|
+
};
|
|
219
|
+
}>>, {
|
|
220
|
+
as: AsTag | Component;
|
|
221
|
+
asChild: boolean;
|
|
222
|
+
forceMount: boolean;
|
|
223
|
+
}, {}>;
|
|
224
|
+
|
|
225
|
+
declare function DestylerCheckboxResolver(): ComponentResolver;
|
|
226
|
+
|
|
227
|
+
export { type CheckboxRootContext, DestylerCheckboxIndicator, DestylerCheckboxResolver, DestylerCheckboxRoot, type DestylerCheckboxRootProps, destylerCheckboxIndicatorProps, destylerCheckboxRootProps, injectCheckboxRootContext, provideCheckboxRootContext };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { defineComponent, toRef, computed, withDirectives, h, mergeProps } from 'vue';
|
|
2
|
+
import { destylerPrimitiveProp, DestylerPrimitive } from '@destyler/primitive';
|
|
3
|
+
import { useVModel, useCustomElement, useFormControl } from '@destyler/composition';
|
|
4
|
+
import { createContext } from '@destyler/shared';
|
|
5
|
+
import { BindOnceDirective } from '@destyler/directives';
|
|
6
|
+
import { DestylerPresence } from '@destyler/presence';
|
|
7
|
+
|
|
8
|
+
function isIndeterminate(checked) {
|
|
9
|
+
return checked === "indeterminate";
|
|
10
|
+
}
|
|
11
|
+
function getState(checked) {
|
|
12
|
+
return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const destylerCheckboxRootProps = {
|
|
16
|
+
...destylerPrimitiveProp,
|
|
17
|
+
as: {
|
|
18
|
+
type: [String, Object],
|
|
19
|
+
required: false,
|
|
20
|
+
default: "button"
|
|
21
|
+
},
|
|
22
|
+
defaultChecked: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
required: false
|
|
25
|
+
},
|
|
26
|
+
checked: {
|
|
27
|
+
type: [Boolean, String],
|
|
28
|
+
required: false,
|
|
29
|
+
default: void 0
|
|
30
|
+
},
|
|
31
|
+
disabled: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
required: false,
|
|
34
|
+
default: false
|
|
35
|
+
},
|
|
36
|
+
required: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
name: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
value: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: false,
|
|
47
|
+
default: "on"
|
|
48
|
+
},
|
|
49
|
+
id: {
|
|
50
|
+
type: String,
|
|
51
|
+
required: false
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const [injectCheckboxRootContext, provideCheckboxRootContext] = createContext("CheckboxRoot");
|
|
55
|
+
const DestylerCheckboxRoot = defineComponent({
|
|
56
|
+
name: "DestylerCheckboxRoot",
|
|
57
|
+
props: destylerCheckboxRootProps,
|
|
58
|
+
emits: ["update:checked"],
|
|
59
|
+
setup(props, { emit }) {
|
|
60
|
+
const disabledRef = toRef(props.disabled);
|
|
61
|
+
const checkedRef = useVModel(props, "checked", emit, {
|
|
62
|
+
defaultValue: props.defaultChecked,
|
|
63
|
+
passive: props.checked === void 0
|
|
64
|
+
});
|
|
65
|
+
const { customElement, currentElement } = useCustomElement();
|
|
66
|
+
const isFormControl = useFormControl(currentElement);
|
|
67
|
+
const ariaLabel = computed(() => props.id && currentElement.value ? document.querySelector(`[for="${props.id}"]`)?.textContent : void 0);
|
|
68
|
+
provideCheckboxRootContext({
|
|
69
|
+
disabled: disabledRef,
|
|
70
|
+
state: checkedRef
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
disabled: disabledRef,
|
|
74
|
+
checked: checkedRef,
|
|
75
|
+
customElement,
|
|
76
|
+
isFormControl,
|
|
77
|
+
ariaLabel
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
render() {
|
|
81
|
+
const useVShow = this.isFormControl;
|
|
82
|
+
return [
|
|
83
|
+
withDirectives(h(DestylerPrimitive, mergeProps(this.$attrs, {
|
|
84
|
+
"ref": "customElement",
|
|
85
|
+
"role": "checkbox",
|
|
86
|
+
"asChild": this.$props.asChild,
|
|
87
|
+
"as": this.$props.as,
|
|
88
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
89
|
+
"aria-checked": isIndeterminate(this.checked) ? "mixed" : this.checked,
|
|
90
|
+
"aria-required": false,
|
|
91
|
+
"aria-label": this.$attrs["aria-label"] || this.ariaLabel,
|
|
92
|
+
"data-state": getState(this.checked),
|
|
93
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
94
|
+
"disabled": this.disabled,
|
|
95
|
+
"onClick": () => {
|
|
96
|
+
this.checked = !this.checked;
|
|
97
|
+
}
|
|
98
|
+
}), this.$slots.default?.()), [
|
|
99
|
+
[BindOnceDirective, { id: this.$props.id }]
|
|
100
|
+
]),
|
|
101
|
+
useVShow ? h("input", {
|
|
102
|
+
"type": "checkbox",
|
|
103
|
+
"tabindex": "-1",
|
|
104
|
+
"aria-hidden": "",
|
|
105
|
+
"value": this.$props.value,
|
|
106
|
+
"checked": this.checked,
|
|
107
|
+
"name": this.$props.name,
|
|
108
|
+
"disabled": this.disabled,
|
|
109
|
+
"required": this.$props.required,
|
|
110
|
+
"style": {
|
|
111
|
+
transform: "translateX(-100%)",
|
|
112
|
+
position: "absolute",
|
|
113
|
+
pointerEvents: "none",
|
|
114
|
+
opacity: 0,
|
|
115
|
+
margin: 0
|
|
116
|
+
}
|
|
117
|
+
}) : null
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const destylerCheckboxIndicatorProps = {
|
|
123
|
+
...destylerPrimitiveProp,
|
|
124
|
+
as: {
|
|
125
|
+
type: [String, Object],
|
|
126
|
+
required: false,
|
|
127
|
+
default: "button"
|
|
128
|
+
},
|
|
129
|
+
forceMount: {
|
|
130
|
+
type: Boolean,
|
|
131
|
+
required: false,
|
|
132
|
+
default: false
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const DestylerCheckboxIndicator = defineComponent({
|
|
136
|
+
name: "DestylerCheckboxIndicator",
|
|
137
|
+
props: destylerCheckboxIndicatorProps,
|
|
138
|
+
setup() {
|
|
139
|
+
const rootContext = injectCheckboxRootContext();
|
|
140
|
+
return {
|
|
141
|
+
rootContext
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
render() {
|
|
145
|
+
return h(DestylerPresence, {
|
|
146
|
+
present: this.$props.forceMount || isIndeterminate(this.rootContext.state.value) || this.rootContext.state.value === true
|
|
147
|
+
}, h(DestylerPrimitive, mergeProps(this.$attrs, {
|
|
148
|
+
"data-state": getState(this.rootContext.state.value),
|
|
149
|
+
"data-disabled": this.rootContext.disabled.value ? "" : void 0,
|
|
150
|
+
"asChild": this.$props.asChild,
|
|
151
|
+
"as": this.$props.as,
|
|
152
|
+
"style": {
|
|
153
|
+
pointerEvents: "none"
|
|
154
|
+
}
|
|
155
|
+
}), this.$slots.default?.()));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const name = "@destyler/checkbox";
|
|
160
|
+
|
|
161
|
+
const packageName = name;
|
|
162
|
+
function DestylerCheckboxResolver() {
|
|
163
|
+
return {
|
|
164
|
+
type: "component",
|
|
165
|
+
resolve: (name2) => {
|
|
166
|
+
if (name2 === "DestylerTemplate")
|
|
167
|
+
return { name: name2, from: packageName };
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { DestylerCheckboxIndicator, DestylerCheckboxResolver, DestylerCheckboxRoot, destylerCheckboxIndicatorProps, destylerCheckboxRootProps, injectCheckboxRootContext, provideCheckboxRootContext };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@destyler/checkbox",
|
|
3
|
+
"version": "0.0.1-beta.7",
|
|
4
|
+
"description": "unstyled checkbox component for vue",
|
|
5
|
+
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./*": "./*"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/index.cjs",
|
|
16
|
+
"module": "dist/index.mjs",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"*.d.ts",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"vue": ">=3.3.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@destyler/composition": "0.0.1-beta.7",
|
|
27
|
+
"@destyler/presence": "0.0.1-beta.7",
|
|
28
|
+
"@destyler/shared": "0.0.1-beta.7",
|
|
29
|
+
"@destyler/directives": "0.0.1-beta.7",
|
|
30
|
+
"@destyler/primitive": "0.0.1-beta.7"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"clear": "rimraf ./dist",
|
|
34
|
+
"build": "pnpm run clear && unbuild"
|
|
35
|
+
}
|
|
36
|
+
}
|