@destyler/checkbox 0.0.5 → 0.0.7-beta.1

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.
@@ -1,206 +0,0 @@
1
- import { defineComponent, toRef, computed, withDirectives, h, mergeProps } from 'vue';
2
- import { primitiveProps, Primitive } from '@destyler/primitive';
3
- import { useVModel, useForwardExpose, useFormControl } from '@destyler/composition';
4
- import { createContext } from '@destyler/shared';
5
- import { BindOnceDirective } from '@destyler/directives';
6
- import { Presence } 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 checkboxRootProps = {
16
- ...primitiveProps,
17
- /**
18
- * @default button
19
- */
20
- as: {
21
- ...primitiveProps.as,
22
- default: "button"
23
- },
24
- /**
25
- * The checked state of the checkbox when it is initially rendered.
26
- * Use when you do not need to control its checked state.
27
- */
28
- defaultChecked: {
29
- type: Boolean,
30
- required: false
31
- },
32
- /**
33
- * The controlled checked state of the checkbox. Can be binded with `v-model`.
34
- *
35
- * @default undefined
36
- */
37
- checked: {
38
- type: [Boolean, String],
39
- required: false,
40
- default: void 0
41
- },
42
- /**
43
- * When `true`, prevents the user from interacting with the checkbox.
44
- *
45
- * @default false
46
- */
47
- disabled: {
48
- type: Boolean,
49
- required: false,
50
- default: false
51
- },
52
- /**
53
- * When `true`, indicates that the user must check the checkbox before the owning form can be submitted.
54
- */
55
- required: {
56
- type: Boolean,
57
- required: false
58
- },
59
- /**
60
- * The name of the checkbox. Submitted with its owning form as part of a name/value pair.
61
- */
62
- name: {
63
- type: String,
64
- required: false
65
- },
66
- /**
67
- * The value given as data when submitted with a `name`.
68
- *
69
- * @default on
70
- */
71
- value: {
72
- type: String,
73
- required: false,
74
- default: "on"
75
- },
76
- /**
77
- * Id of the element
78
- */
79
- id: {
80
- type: String,
81
- required: false
82
- }
83
- };
84
- const checkboxRootEmits = {
85
- /**
86
- * Event handler called when the checked state of the checkbox changes.
87
- */
88
- "update:checked": (_checked) => true
89
- };
90
- const [injectCheckboxRootContext, provideCheckboxRootContext] = createContext("DestylerCheckboxRoot");
91
- const CheckboxRoot = defineComponent({
92
- name: "DestylerCheckboxRoot",
93
- props: checkboxRootProps,
94
- emits: checkboxRootEmits,
95
- setup(props, { emit }) {
96
- const disabledRef = toRef(props.disabled);
97
- const checkedRef = useVModel(props, "checked", emit, {
98
- defaultValue: props.defaultChecked,
99
- passive: props.checked === void 0
100
- });
101
- const { forwardRef, currentElement } = useForwardExpose();
102
- const isFormControl = useFormControl(currentElement);
103
- const ariaLabel = computed(() => props.id && currentElement.value ? document.querySelector(`[for="${props.id}"]`)?.textContent : void 0);
104
- provideCheckboxRootContext({
105
- disabled: disabledRef,
106
- state: checkedRef
107
- });
108
- return {
109
- disabled: disabledRef,
110
- checked: checkedRef,
111
- forwardRef,
112
- isFormControl,
113
- ariaLabel
114
- };
115
- },
116
- render() {
117
- const useVShow = this.isFormControl;
118
- return [
119
- withDirectives(h(Primitive, mergeProps(this.$attrs, {
120
- "ref": (el) => this.forwardRef(el),
121
- "role": "checkbox",
122
- "asChild": this.$props.asChild,
123
- "as": this.$props.as,
124
- "type": this.$props.as === "button" ? "button" : void 0,
125
- "aria-checked": isIndeterminate(this.checked) ? "mixed" : this.checked,
126
- "aria-required": false,
127
- "aria-label": this.$attrs["aria-label"] || this.ariaLabel,
128
- "data-state": getState(this.checked),
129
- "data-disabled": this.disabled ? "" : void 0,
130
- "disabled": this.disabled,
131
- "onClick": () => {
132
- this.checked = !this.checked;
133
- }
134
- }), () => this.$slots.default?.()), [
135
- [BindOnceDirective, { id: this.$props.id }]
136
- ]),
137
- useVShow ? h("input", {
138
- "type": "checkbox",
139
- "tabindex": "-1",
140
- "aria-hidden": "",
141
- "value": this.$props.value,
142
- "checked": this.checked,
143
- "name": this.$props.name,
144
- "disabled": this.disabled,
145
- "required": this.$props.required,
146
- "style": {
147
- transform: "translateX(-100%)",
148
- position: "absolute",
149
- pointerEvents: "none",
150
- opacity: 0,
151
- margin: 0
152
- }
153
- }) : null
154
- ];
155
- }
156
- });
157
-
158
- const checkboxIndicatorProps = {
159
- ...primitiveProps,
160
- /**
161
- * @default span
162
- */
163
- as: {
164
- ...primitiveProps.as,
165
- default: "span"
166
- },
167
- /**
168
- * Used to force mounting when more control is needed.
169
- * Useful when controlling animation with animation libraries.
170
- *
171
- * @default false
172
- */
173
- forceMount: {
174
- type: Boolean,
175
- required: false,
176
- default: false
177
- }
178
- };
179
- const CheckboxIndicator = defineComponent({
180
- name: "DestylerCheckboxIndicator",
181
- props: checkboxIndicatorProps,
182
- setup() {
183
- const rootContext = injectCheckboxRootContext();
184
- const { forwardRef } = useForwardExpose();
185
- return {
186
- rootContext,
187
- forwardRef
188
- };
189
- },
190
- render() {
191
- return h(Presence, {
192
- present: this.$props.forceMount || isIndeterminate(this.rootContext.state.value) || this.rootContext.state.value === true
193
- }, () => h(Primitive, mergeProps(this.$attrs, {
194
- "ref": (el) => this.forwardRef(el),
195
- "data-state": getState(this.rootContext.state.value),
196
- "data-disabled": this.rootContext.disabled.value ? "" : void 0,
197
- "asChild": this.$props.asChild,
198
- "as": this.$props.as,
199
- "style": {
200
- pointerEvents: "none"
201
- }
202
- }), () => this.$slots.default?.()));
203
- }
204
- });
205
-
206
- export { CheckboxIndicator, CheckboxRoot, checkboxIndicatorProps, checkboxRootEmits, checkboxRootProps };
package/dist/resolver.cjs DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- const name = "@destyler/checkbox";
4
-
5
- const packageName = name;
6
- const checkboxComponentName = [
7
- "CheckboxRoot",
8
- "CheckboxIndicator"
9
- ];
10
- function CheckboxResolver() {
11
- return {
12
- type: "component",
13
- resolve: (name2) => {
14
- if (checkboxComponentName.includes(name2))
15
- return { name: name2, from: packageName };
16
- }
17
- };
18
- }
19
-
20
- exports.CheckboxResolver = CheckboxResolver;
21
- exports.checkboxComponentName = checkboxComponentName;
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const checkboxComponentName: string[];
4
- declare function CheckboxResolver(): ComponentResolver;
5
-
6
- export { CheckboxResolver, checkboxComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const checkboxComponentName: string[];
4
- declare function CheckboxResolver(): ComponentResolver;
5
-
6
- export { CheckboxResolver, checkboxComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const checkboxComponentName: string[];
4
- declare function CheckboxResolver(): ComponentResolver;
5
-
6
- export { CheckboxResolver, checkboxComponentName };
package/dist/resolver.mjs DELETED
@@ -1,18 +0,0 @@
1
- const name = "@destyler/checkbox";
2
-
3
- const packageName = name;
4
- const checkboxComponentName = [
5
- "CheckboxRoot",
6
- "CheckboxIndicator"
7
- ];
8
- function CheckboxResolver() {
9
- return {
10
- type: "component",
11
- resolve: (name2) => {
12
- if (checkboxComponentName.includes(name2))
13
- return { name: name2, from: packageName };
14
- }
15
- };
16
- }
17
-
18
- export { CheckboxResolver, checkboxComponentName };