@destyler/radio 0.0.1-beta.11
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/component.cjs +336 -0
- package/dist/component.d.cts +136 -0
- package/dist/component.d.mts +136 -0
- package/dist/component.d.ts +136 -0
- package/dist/component.mjs +331 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +333 -0
- package/dist/index.d.mts +333 -0
- package/dist/index.d.ts +333 -0
- package/dist/index.mjs +8 -0
- package/dist/resolver.cjs +22 -0
- package/dist/resolver.d.cts +6 -0
- package/dist/resolver.d.mts +6 -0
- package/dist/resolver.d.ts +6 -0
- package/dist/resolver.mjs +19 -0
- package/package.json +47 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export { DestylerRadioGroupIndicator, DestylerRadioGroupIndicatorProps, DestylerRadioGroupItem, DestylerRadioGroupItemProps, DestylerRadioGroupRoot, DestylerRadioGroupRootProps } from './index.js';
|
|
2
|
+
import * as vue from 'vue';
|
|
3
|
+
import { PropType, Component } from 'vue';
|
|
4
|
+
import { AsTag } from '@destyler/primitive';
|
|
5
|
+
import { ExtractPublicPropTypes } from '@destyler/shared';
|
|
6
|
+
|
|
7
|
+
declare const destylerRadioProps: {
|
|
8
|
+
readonly as: {
|
|
9
|
+
readonly type: PropType<AsTag | Component>;
|
|
10
|
+
readonly required: false;
|
|
11
|
+
readonly default: "button";
|
|
12
|
+
};
|
|
13
|
+
readonly asChild: {
|
|
14
|
+
readonly type: PropType<boolean>;
|
|
15
|
+
readonly required: false;
|
|
16
|
+
readonly default: false;
|
|
17
|
+
};
|
|
18
|
+
readonly id: {
|
|
19
|
+
readonly type: PropType<string>;
|
|
20
|
+
readonly required: false;
|
|
21
|
+
};
|
|
22
|
+
readonly value: {
|
|
23
|
+
readonly type: PropType<string>;
|
|
24
|
+
readonly required: false;
|
|
25
|
+
};
|
|
26
|
+
readonly disabled: {
|
|
27
|
+
readonly type: PropType<boolean>;
|
|
28
|
+
readonly required: false;
|
|
29
|
+
readonly default: false;
|
|
30
|
+
};
|
|
31
|
+
readonly required: {
|
|
32
|
+
readonly type: PropType<boolean>;
|
|
33
|
+
readonly required: false;
|
|
34
|
+
};
|
|
35
|
+
readonly checked: {
|
|
36
|
+
readonly type: PropType<boolean>;
|
|
37
|
+
readonly required: false;
|
|
38
|
+
readonly default: undefined;
|
|
39
|
+
};
|
|
40
|
+
readonly name: {
|
|
41
|
+
readonly type: PropType<string>;
|
|
42
|
+
readonly required: false;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type DestylerRadioProps = ExtractPublicPropTypes<typeof destylerRadioProps>;
|
|
46
|
+
declare const DestylerRadio: vue.DefineComponent<{
|
|
47
|
+
readonly as: {
|
|
48
|
+
readonly type: PropType<AsTag | Component>;
|
|
49
|
+
readonly required: false;
|
|
50
|
+
readonly default: "button";
|
|
51
|
+
};
|
|
52
|
+
readonly asChild: {
|
|
53
|
+
readonly type: PropType<boolean>;
|
|
54
|
+
readonly required: false;
|
|
55
|
+
readonly default: false;
|
|
56
|
+
};
|
|
57
|
+
readonly id: {
|
|
58
|
+
readonly type: PropType<string>;
|
|
59
|
+
readonly required: false;
|
|
60
|
+
};
|
|
61
|
+
readonly value: {
|
|
62
|
+
readonly type: PropType<string>;
|
|
63
|
+
readonly required: false;
|
|
64
|
+
};
|
|
65
|
+
readonly disabled: {
|
|
66
|
+
readonly type: PropType<boolean>;
|
|
67
|
+
readonly required: false;
|
|
68
|
+
readonly default: false;
|
|
69
|
+
};
|
|
70
|
+
readonly required: {
|
|
71
|
+
readonly type: PropType<boolean>;
|
|
72
|
+
readonly required: false;
|
|
73
|
+
};
|
|
74
|
+
readonly checked: {
|
|
75
|
+
readonly type: PropType<boolean>;
|
|
76
|
+
readonly required: false;
|
|
77
|
+
readonly default: undefined;
|
|
78
|
+
};
|
|
79
|
+
readonly name: {
|
|
80
|
+
readonly type: PropType<string>;
|
|
81
|
+
readonly required: false;
|
|
82
|
+
};
|
|
83
|
+
}, {
|
|
84
|
+
customElement: vue.Ref<vue.ComponentPublicInstance | undefined>;
|
|
85
|
+
checkedRef: vue.WritableComputedRef<boolean | undefined>;
|
|
86
|
+
ariaLabel: vue.ComputedRef<string | undefined>;
|
|
87
|
+
value: vue.Ref<string | undefined>;
|
|
88
|
+
isFormControl: vue.ComputedRef<boolean>;
|
|
89
|
+
handleClick: (event: MouseEvent) => void;
|
|
90
|
+
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:checked"[], "update:checked", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
91
|
+
readonly as: {
|
|
92
|
+
readonly type: PropType<AsTag | Component>;
|
|
93
|
+
readonly required: false;
|
|
94
|
+
readonly default: "button";
|
|
95
|
+
};
|
|
96
|
+
readonly asChild: {
|
|
97
|
+
readonly type: PropType<boolean>;
|
|
98
|
+
readonly required: false;
|
|
99
|
+
readonly default: false;
|
|
100
|
+
};
|
|
101
|
+
readonly id: {
|
|
102
|
+
readonly type: PropType<string>;
|
|
103
|
+
readonly required: false;
|
|
104
|
+
};
|
|
105
|
+
readonly value: {
|
|
106
|
+
readonly type: PropType<string>;
|
|
107
|
+
readonly required: false;
|
|
108
|
+
};
|
|
109
|
+
readonly disabled: {
|
|
110
|
+
readonly type: PropType<boolean>;
|
|
111
|
+
readonly required: false;
|
|
112
|
+
readonly default: false;
|
|
113
|
+
};
|
|
114
|
+
readonly required: {
|
|
115
|
+
readonly type: PropType<boolean>;
|
|
116
|
+
readonly required: false;
|
|
117
|
+
};
|
|
118
|
+
readonly checked: {
|
|
119
|
+
readonly type: PropType<boolean>;
|
|
120
|
+
readonly required: false;
|
|
121
|
+
readonly default: undefined;
|
|
122
|
+
};
|
|
123
|
+
readonly name: {
|
|
124
|
+
readonly type: PropType<string>;
|
|
125
|
+
readonly required: false;
|
|
126
|
+
};
|
|
127
|
+
}>> & {
|
|
128
|
+
"onUpdate:checked"?: ((...args: any[]) => any) | undefined;
|
|
129
|
+
}, {
|
|
130
|
+
readonly as: AsTag | Component;
|
|
131
|
+
readonly asChild: boolean;
|
|
132
|
+
readonly disabled: boolean;
|
|
133
|
+
readonly checked: boolean;
|
|
134
|
+
}, {}>;
|
|
135
|
+
|
|
136
|
+
export { DestylerRadio, type DestylerRadioProps };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { defineComponent, toRefs, h, computed, withDirectives, mergeProps, withModifiers, ref } from 'vue';
|
|
2
|
+
import { DestylerPrimitive } from '@destyler/primitive';
|
|
3
|
+
import { createContext } from '@destyler/shared';
|
|
4
|
+
import { useVModel, useDirection, useCustomElement, useFormControl } from '@destyler/composition';
|
|
5
|
+
import { DestylerRovingFocusGroup, DestylerRovingFocusItem } from '@destyler/roving-focus';
|
|
6
|
+
import { useEventListener } from '@vueuse/core';
|
|
7
|
+
import { BindOnceDirective } from '@destyler/directives';
|
|
8
|
+
|
|
9
|
+
const destylerRadioGroupRootProps = {
|
|
10
|
+
as: {
|
|
11
|
+
type: [String, Object],
|
|
12
|
+
required: false,
|
|
13
|
+
default: "div"
|
|
14
|
+
},
|
|
15
|
+
asChild: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
required: false,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
20
|
+
modelValue: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: false
|
|
23
|
+
},
|
|
24
|
+
defaultValue: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
disabled: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
required: false,
|
|
31
|
+
default: false
|
|
32
|
+
},
|
|
33
|
+
name: {
|
|
34
|
+
type: String,
|
|
35
|
+
required: false
|
|
36
|
+
},
|
|
37
|
+
required: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
required: false,
|
|
40
|
+
default: false
|
|
41
|
+
},
|
|
42
|
+
orientation: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: false,
|
|
45
|
+
default: void 0
|
|
46
|
+
},
|
|
47
|
+
dir: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: false
|
|
50
|
+
},
|
|
51
|
+
loop: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
required: false,
|
|
54
|
+
default: true
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const [injectRadioGroupRootContext, provideRadioGroupRootContext] = createContext("DestylerRadioGroupRoot");
|
|
58
|
+
const DestylerRadioGroupRoot = defineComponent({
|
|
59
|
+
name: "DestylerRadioGroupRoot",
|
|
60
|
+
props: destylerRadioGroupRootProps,
|
|
61
|
+
emits: ["update:modelValue"],
|
|
62
|
+
setup(props, { emit }) {
|
|
63
|
+
const modelValue = useVModel(props, "modelValue", emit, {
|
|
64
|
+
defaultValue: props.defaultValue,
|
|
65
|
+
passive: props.modelValue === void 0
|
|
66
|
+
});
|
|
67
|
+
const { disabled, loop, orientation, name, required, dir: propDir } = toRefs(props);
|
|
68
|
+
const dir = useDirection(propDir);
|
|
69
|
+
provideRadioGroupRootContext({
|
|
70
|
+
modelValue,
|
|
71
|
+
changeModelValue: (value) => {
|
|
72
|
+
modelValue.value = value;
|
|
73
|
+
},
|
|
74
|
+
disabled,
|
|
75
|
+
loop,
|
|
76
|
+
orientation,
|
|
77
|
+
name: name?.value,
|
|
78
|
+
required
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
orientation,
|
|
82
|
+
dir,
|
|
83
|
+
loop,
|
|
84
|
+
disabled,
|
|
85
|
+
required,
|
|
86
|
+
name
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
render() {
|
|
90
|
+
return h(DestylerRovingFocusGroup, {
|
|
91
|
+
asChild: true,
|
|
92
|
+
orientation: this.orientation,
|
|
93
|
+
dir: this.dir,
|
|
94
|
+
loop: this.loop
|
|
95
|
+
}, h(DestylerPrimitive, {
|
|
96
|
+
"role": "radiogroup",
|
|
97
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
98
|
+
"asChild": this.$props.asChild,
|
|
99
|
+
"aria-required": this.required,
|
|
100
|
+
"dir": this.dir,
|
|
101
|
+
"name": this.name
|
|
102
|
+
}, this.$slots.default?.()));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const destylerRadioProps = {
|
|
107
|
+
as: {
|
|
108
|
+
type: [String, Object],
|
|
109
|
+
required: false,
|
|
110
|
+
default: "button"
|
|
111
|
+
},
|
|
112
|
+
asChild: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
required: false,
|
|
115
|
+
default: false
|
|
116
|
+
},
|
|
117
|
+
id: {
|
|
118
|
+
type: String,
|
|
119
|
+
required: false
|
|
120
|
+
},
|
|
121
|
+
value: {
|
|
122
|
+
type: String,
|
|
123
|
+
required: false
|
|
124
|
+
},
|
|
125
|
+
disabled: {
|
|
126
|
+
type: Boolean,
|
|
127
|
+
required: false,
|
|
128
|
+
default: false
|
|
129
|
+
},
|
|
130
|
+
required: {
|
|
131
|
+
type: Boolean,
|
|
132
|
+
required: false
|
|
133
|
+
},
|
|
134
|
+
checked: {
|
|
135
|
+
type: Boolean,
|
|
136
|
+
required: false,
|
|
137
|
+
default: void 0
|
|
138
|
+
},
|
|
139
|
+
name: {
|
|
140
|
+
type: String,
|
|
141
|
+
required: false
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const DestylerRadio = defineComponent({
|
|
145
|
+
name: "DestylerRadio",
|
|
146
|
+
props: destylerRadioProps,
|
|
147
|
+
emits: ["update:checked"],
|
|
148
|
+
setup(props, { emit }) {
|
|
149
|
+
const checkedRef = useVModel(props, "checked", emit, {
|
|
150
|
+
passive: props.checked === void 0
|
|
151
|
+
});
|
|
152
|
+
const { value } = toRefs(props);
|
|
153
|
+
const { customElement, currentElement: triggerElement } = useCustomElement();
|
|
154
|
+
const isFormControl = useFormControl(triggerElement);
|
|
155
|
+
const ariaLabel = computed(() => props.id && triggerElement.value ? document.querySelector(`[for="${props.id}"]`)?.textContent ?? props.value : void 0);
|
|
156
|
+
function handleClick(event) {
|
|
157
|
+
checkedRef.value = true;
|
|
158
|
+
if (isFormControl.value)
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
customElement,
|
|
163
|
+
checkedRef,
|
|
164
|
+
ariaLabel,
|
|
165
|
+
value,
|
|
166
|
+
isFormControl,
|
|
167
|
+
handleClick
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
render() {
|
|
171
|
+
return withDirectives(h(DestylerPrimitive, mergeProps(this.$attrs, {
|
|
172
|
+
"role": "radio",
|
|
173
|
+
"ref": "customElement",
|
|
174
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
175
|
+
"as": this.$props.as,
|
|
176
|
+
"aria-checked": this.checkedRef,
|
|
177
|
+
"aria-label": this.ariaLabel,
|
|
178
|
+
"asChild": this.$props.asChild,
|
|
179
|
+
"disabled": this.disabled ? true : void 0,
|
|
180
|
+
"data-state": this.checkedRef ? "checked" : "unchecked",
|
|
181
|
+
"data-disabled": this.disabled ? "" : void 0,
|
|
182
|
+
"value": this.value,
|
|
183
|
+
"required": this.$props.required,
|
|
184
|
+
"name": this.$props.name,
|
|
185
|
+
"onClick": withModifiers((event) => {
|
|
186
|
+
this.handleClick(event);
|
|
187
|
+
}, ["stop"])
|
|
188
|
+
}), [
|
|
189
|
+
this.$slots.default?.(),
|
|
190
|
+
this.isFormControl ? h("input", {
|
|
191
|
+
role: "radio",
|
|
192
|
+
checked: this.checkedRef,
|
|
193
|
+
name: this.$props.name,
|
|
194
|
+
disabled: this.disabled,
|
|
195
|
+
required: this.required,
|
|
196
|
+
style: {
|
|
197
|
+
transform: "translateX(-100%)",
|
|
198
|
+
position: "absolute",
|
|
199
|
+
pointerEvents: "none",
|
|
200
|
+
opacity: 0,
|
|
201
|
+
margin: 0
|
|
202
|
+
}
|
|
203
|
+
}) : null
|
|
204
|
+
]), [
|
|
205
|
+
[BindOnceDirective, { id: this.$props.id }]
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const destylerRadioGroupItemProps = {
|
|
211
|
+
as: {
|
|
212
|
+
type: [String, Object],
|
|
213
|
+
required: false,
|
|
214
|
+
default: "button"
|
|
215
|
+
},
|
|
216
|
+
asChild: {
|
|
217
|
+
type: Boolean,
|
|
218
|
+
required: false,
|
|
219
|
+
default: false
|
|
220
|
+
},
|
|
221
|
+
id: {
|
|
222
|
+
type: String,
|
|
223
|
+
required: false
|
|
224
|
+
},
|
|
225
|
+
value: {
|
|
226
|
+
type: String,
|
|
227
|
+
required: false
|
|
228
|
+
},
|
|
229
|
+
disabled: {
|
|
230
|
+
type: Boolean,
|
|
231
|
+
required: false,
|
|
232
|
+
default: false
|
|
233
|
+
},
|
|
234
|
+
required: {
|
|
235
|
+
type: Boolean,
|
|
236
|
+
required: false
|
|
237
|
+
},
|
|
238
|
+
name: {
|
|
239
|
+
type: String,
|
|
240
|
+
required: false
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const [injectRadioGroupItemContext, provideRadiogroupItemContext] = createContext("DestylerRadioGroupItem");
|
|
244
|
+
const DestylerRadioGroupItem = defineComponent({
|
|
245
|
+
name: "DestylerRadioGroupItem",
|
|
246
|
+
inheritAttrs: false,
|
|
247
|
+
props: destylerRadioGroupItemProps,
|
|
248
|
+
setup(props) {
|
|
249
|
+
const { customElement, currentElement } = useCustomElement();
|
|
250
|
+
const rootContext = injectRadioGroupRootContext();
|
|
251
|
+
const disabled = computed(() => rootContext.disabled.value || props.disabled);
|
|
252
|
+
const required = computed(() => rootContext.required.value || props.required);
|
|
253
|
+
const checked = computed(() => rootContext.modelValue?.value === props.value);
|
|
254
|
+
provideRadiogroupItemContext({ disabled, checked });
|
|
255
|
+
const isArrowKeyPressed = ref(false);
|
|
256
|
+
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
257
|
+
useEventListener("keydown", (event) => {
|
|
258
|
+
if (ARROW_KEYS.includes(event.key))
|
|
259
|
+
isArrowKeyPressed.value = true;
|
|
260
|
+
});
|
|
261
|
+
useEventListener("keyup", () => {
|
|
262
|
+
isArrowKeyPressed.value = false;
|
|
263
|
+
});
|
|
264
|
+
function handleFocus() {
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
if (isArrowKeyPressed.value)
|
|
267
|
+
currentElement.value?.click();
|
|
268
|
+
}, 0);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
checked,
|
|
272
|
+
disabled,
|
|
273
|
+
required,
|
|
274
|
+
customElement,
|
|
275
|
+
rootContext,
|
|
276
|
+
handleFocus
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
render() {
|
|
280
|
+
return h(DestylerRovingFocusItem, {
|
|
281
|
+
asChild: true,
|
|
282
|
+
checked: this.checked,
|
|
283
|
+
disabled: this.disabled,
|
|
284
|
+
focusable: !this.disabled,
|
|
285
|
+
active: this.checked
|
|
286
|
+
}, h(DestylerRadio, mergeProps(this.$attrs, this.$props, {
|
|
287
|
+
"ref": "customElement",
|
|
288
|
+
"checked": this.checked,
|
|
289
|
+
"required": this.required,
|
|
290
|
+
"onUpdate:checked": () => {
|
|
291
|
+
this.rootContext.changeModelValue(this.$props.value);
|
|
292
|
+
},
|
|
293
|
+
"onFocus": () => {
|
|
294
|
+
this.handleFocus();
|
|
295
|
+
}
|
|
296
|
+
}), this.$slots.default?.()));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const destylerRadioGroupIndicatorProps = {
|
|
301
|
+
as: {
|
|
302
|
+
type: [String, Object],
|
|
303
|
+
required: false,
|
|
304
|
+
default: "span"
|
|
305
|
+
},
|
|
306
|
+
asChild: {
|
|
307
|
+
type: Boolean,
|
|
308
|
+
required: false,
|
|
309
|
+
default: false
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const DestylerRadioGroupIndicator = defineComponent({
|
|
313
|
+
name: "DestylerRadioGroupindicator",
|
|
314
|
+
props: destylerRadioGroupIndicatorProps,
|
|
315
|
+
setup() {
|
|
316
|
+
const itemContext = injectRadioGroupItemContext();
|
|
317
|
+
return {
|
|
318
|
+
itemContext
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
|
+
render() {
|
|
322
|
+
return this.itemContext.checked.value ? h(DestylerPrimitive, {
|
|
323
|
+
"data-state": this.itemContext.checked.value ? "checked" : "unchecked",
|
|
324
|
+
"data-disabled": this.itemContext.disabled.value ? "" : void 0,
|
|
325
|
+
"as": this.$props.as,
|
|
326
|
+
"asChild": this.$props.asChild
|
|
327
|
+
}, this.$slots.default?.()) : null;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
export { DestylerRadio, DestylerRadioGroupIndicator, DestylerRadioGroupItem, DestylerRadioGroupRoot };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const index = require('./component.cjs');
|
|
4
|
+
require('vue');
|
|
5
|
+
require('@destyler/primitive');
|
|
6
|
+
require('@destyler/shared');
|
|
7
|
+
require('@destyler/composition');
|
|
8
|
+
require('@destyler/roving-focus');
|
|
9
|
+
require('@vueuse/core');
|
|
10
|
+
require('@destyler/directives');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.DestylerRadioGroupIndicator = index.DestylerRadioGroupIndicator;
|
|
15
|
+
exports.DestylerRadioGroupItem = index.DestylerRadioGroupItem;
|
|
16
|
+
exports.DestylerRadioGroupRoot = index.DestylerRadioGroupRoot;
|