@destyler/radio 0.0.6 → 0.0.7-beta.2

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,405 +0,0 @@
1
- import { defineComponent, toRefs, h, computed, mergeProps, withModifiers, ref, withKeys } from 'vue';
2
- import { primitiveProps, Primitive } from '@destyler/primitive';
3
- import { createContext } from '@destyler/shared';
4
- import { useVModel, useDirection, useForwardExpose, useFormControl } from '@destyler/composition';
5
- import { RovingFocusGroup, RovingFocusItem } from '@destyler/roving-focus';
6
- import { useEventListener } from '@vueuse/core';
7
- import { Presence } from '@destyler/presence';
8
-
9
- const radioGroupRootProps = {
10
- ...primitiveProps,
11
- /**
12
- * The controlled value of the radio item to check. Can be binded as `v-model`.
13
- */
14
- modelValue: {
15
- type: String,
16
- required: false
17
- },
18
- /**
19
- * The value of the radio item that should be checked when initially rendered.
20
- *
21
- * Use when you do not need to control the state of the radio items.
22
- */
23
- defaultValue: {
24
- type: String,
25
- required: false
26
- },
27
- /**
28
- * When `true`, prevents the user from interacting with radio items.
29
- */
30
- disabled: {
31
- type: Boolean,
32
- required: false,
33
- default: false
34
- },
35
- /**
36
- * The name of the group. Submitted with its owning form as part of a name/value pair.
37
- */
38
- name: {
39
- type: String,
40
- required: false
41
- },
42
- /**
43
- * When `true`, indicates that the user must check a radio item before the owning form can be submitted.
44
- *
45
- * @default false
46
- */
47
- required: {
48
- type: Boolean,
49
- required: false,
50
- default: false
51
- },
52
- /**
53
- * The orientation of the component.
54
- *
55
- * @default undefined
56
- */
57
- orientation: {
58
- type: String,
59
- required: false,
60
- default: void 0
61
- },
62
- /**
63
- * The reading direction of the radio when applicable.
64
- */
65
- dir: {
66
- type: String,
67
- required: false
68
- },
69
- /**
70
- * When `true`, keyboard navigation will loop from last item to first, and vice versa.
71
- *
72
- * @default true
73
- */
74
- loop: {
75
- type: Boolean,
76
- required: false,
77
- default: true
78
- }
79
- };
80
- const radioGroupRootEmits = {
81
- /**
82
- * Event handler called when the radio group value changes
83
- */
84
- "update:modelValue": (_value) => true
85
- };
86
- const [injectRadioGroupRootContext, provideRadioGroupRootContext] = createContext("DestylerRadioGroupRoot");
87
- const RadioGroupRoot = defineComponent({
88
- name: "DestylerRadioGroupRoot",
89
- props: radioGroupRootProps,
90
- emits: radioGroupRootEmits,
91
- setup(props, { emit }) {
92
- const modelValue = useVModel(props, "modelValue", emit, {
93
- defaultValue: props.defaultValue,
94
- passive: props.modelValue === void 0
95
- });
96
- const { disabled, loop, orientation, name, required, dir: propDir } = toRefs(props);
97
- const dir = useDirection(propDir);
98
- provideRadioGroupRootContext({
99
- modelValue,
100
- changeModelValue: (value) => {
101
- modelValue.value = value;
102
- },
103
- disabled,
104
- loop,
105
- orientation,
106
- name: name?.value,
107
- required
108
- });
109
- return {
110
- orientation,
111
- dir,
112
- loop,
113
- disabled,
114
- required,
115
- name
116
- };
117
- },
118
- render() {
119
- return h(RovingFocusGroup, {
120
- asChild: true,
121
- orientation: this.orientation,
122
- dir: this.dir,
123
- loop: this.loop
124
- }, () => h(Primitive, {
125
- "role": "radiogroup",
126
- "data-disabled": this.disabled ? "" : void 0,
127
- "asChild": this.$props.asChild,
128
- "aria-required": this.required,
129
- "dir": this.dir,
130
- "name": this.name
131
- }, () => this.$slots.default?.()));
132
- }
133
- });
134
-
135
- const radioProps = {
136
- ...primitiveProps,
137
- /**
138
- * @default button
139
- */
140
- as: {
141
- ...primitiveProps.as,
142
- default: "button"
143
- },
144
- /**
145
- * The name of the input fields in the radio (Useful for form submission).
146
- */
147
- id: {
148
- type: String,
149
- required: false
150
- },
151
- /**
152
- * The value given as data when submitted with a `name`.
153
- */
154
- value: {
155
- type: String,
156
- required: false
157
- },
158
- /**
159
- * When `true`, prevents the user from interacting with the radio item.
160
- */
161
- disabled: {
162
- type: Boolean,
163
- required: false,
164
- default: false
165
- },
166
- /**
167
- * When `true`, indicates that the user must check the radio item before the owning form can be submitted.
168
- */
169
- required: {
170
- type: Boolean,
171
- required: false
172
- },
173
- /**
174
- * The controlled value of the radio item to check. Can be binded as `v-model`.
175
- *
176
- * @default undefined
177
- */
178
- checked: {
179
- type: Boolean,
180
- required: false,
181
- default: void 0
182
- },
183
- /**
184
- * The name of the input fields in the radio (Useful for form submission).
185
- */
186
- name: {
187
- type: String,
188
- required: false
189
- }
190
- };
191
- const radioEmits = {
192
- /**
193
- * Event handler called when the radio item is checked.
194
- */
195
- "update:checked": (_value) => true
196
- };
197
- const Radio = defineComponent({
198
- name: "DestylerRadio",
199
- props: radioProps,
200
- emits: radioEmits,
201
- setup(props, { emit }) {
202
- const checkedRef = useVModel(props, "checked", emit, {
203
- passive: props.checked === void 0
204
- });
205
- const { value } = toRefs(props);
206
- const { forwardRef, currentElement: triggerElement } = useForwardExpose();
207
- const isFormControl = useFormControl(triggerElement);
208
- const ariaLabel = computed(() => props.id && triggerElement.value ? document.querySelector(`[for="${props.id}"]`)?.textContent ?? props.value : void 0);
209
- function handleClick(event) {
210
- checkedRef.value = true;
211
- if (isFormControl.value)
212
- event.stopPropagation();
213
- }
214
- return {
215
- forwardRef,
216
- checkedRef,
217
- ariaLabel,
218
- value,
219
- isFormControl,
220
- handleClick
221
- };
222
- },
223
- render() {
224
- return h(Primitive, mergeProps(this.$attrs, {
225
- "id": this.$props.id,
226
- "role": "radio",
227
- "ref": this.forwardRef,
228
- "type": this.$props.as === "button" ? "button" : void 0,
229
- "as": this.$props.as,
230
- "aria-checked": this.checkedRef,
231
- "aria-label": this.ariaLabel,
232
- "asChild": this.$props.asChild,
233
- "disabled": this.disabled ? true : void 0,
234
- "data-state": this.checkedRef ? "checked" : "unchecked",
235
- "data-disabled": this.disabled ? "" : void 0,
236
- "value": this.value,
237
- "required": this.$props.required,
238
- "name": this.$props.name,
239
- "onClick": withModifiers((event) => {
240
- this.handleClick(event);
241
- }, ["stop"])
242
- }), () => [
243
- this.$slots.default?.(),
244
- this.isFormControl ? h("input", {
245
- "type": "radio",
246
- "tabindex": -1,
247
- "aria-hidden": "",
248
- "value": this.value,
249
- "checked": this.checkedRef,
250
- "name": this.$props.name,
251
- "disabled": this.disabled,
252
- "required": this.required,
253
- "style": {
254
- transform: "translateX(-100%)",
255
- position: "absolute",
256
- pointerEvents: "none",
257
- opacity: 0,
258
- margin: 0
259
- }
260
- }) : null
261
- ]);
262
- }
263
- });
264
-
265
- const radioGroupItemProps = {
266
- asChild: {
267
- ...radioProps.asChild
268
- },
269
- as: {
270
- ...radioProps.as
271
- },
272
- /**
273
- * The name of the input fields in the radio (Useful for form submission).
274
- */
275
- id: {
276
- ...radioProps.id
277
- },
278
- /**
279
- * The value given as data when submitted with a `name`.
280
- */
281
- value: {
282
- ...radioProps.value
283
- },
284
- /**
285
- * When `true`, prevents the user from interacting with the radio item.
286
- */
287
- disabled: {
288
- ...radioProps.disabled
289
- },
290
- /**
291
- * When `true`, indicates that the user must check the radio item before the owning form can be submitted.
292
- */
293
- required: {
294
- ...radioProps.required
295
- },
296
- /**
297
- * The name of the input fields in the radio (Useful for form submission).
298
- */
299
- name: {
300
- ...radioProps.name
301
- }
302
- };
303
- const [injectRadioGroupItemContext, provideRadiogroupItemContext] = createContext("RadioGroupItem");
304
- const RadioGroupItem = defineComponent({
305
- name: "RadioGroupItem",
306
- inheritAttrs: false,
307
- props: radioGroupItemProps,
308
- setup(props) {
309
- const { forwardRef, currentElement } = useForwardExpose();
310
- const rootContext = injectRadioGroupRootContext();
311
- const disabled = computed(() => rootContext.disabled.value || props.disabled);
312
- const required = computed(() => rootContext.required.value || props.required);
313
- const checked = computed(() => rootContext.modelValue?.value === props.value);
314
- provideRadiogroupItemContext({ disabled, checked });
315
- const isArrowKeyPressed = ref(false);
316
- const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
317
- useEventListener("keydown", (event) => {
318
- if (ARROW_KEYS.includes(event.key))
319
- isArrowKeyPressed.value = true;
320
- });
321
- useEventListener("keyup", () => {
322
- isArrowKeyPressed.value = false;
323
- });
324
- function handleFocus() {
325
- setTimeout(() => {
326
- if (isArrowKeyPressed.value)
327
- currentElement.value?.click();
328
- }, 0);
329
- }
330
- return {
331
- checked,
332
- disabled,
333
- required,
334
- forwardRef,
335
- rootContext,
336
- handleFocus
337
- };
338
- },
339
- render() {
340
- return h(RovingFocusItem, {
341
- asChild: true,
342
- checked: this.checked,
343
- disabled: this.disabled,
344
- focusable: !this.disabled,
345
- active: this.checked
346
- }, () => h(Radio, mergeProps(this.$attrs, this.$props, {
347
- "ref": (el) => this.forwardRef(el),
348
- "checked": this.checked,
349
- "required": this.required,
350
- "onUpdate:checked": () => {
351
- this.rootContext.changeModelValue(this.$props.value);
352
- },
353
- "onKeydown": withKeys((event) => {
354
- event.preventDefault();
355
- }, ["enter"]),
356
- "onFocus": () => {
357
- this.handleFocus();
358
- }
359
- }), () => this.$slots.default?.()));
360
- }
361
- });
362
-
363
- const radioGroupIndicatorProps = {
364
- ...primitiveProps,
365
- /**
366
- * @default span
367
- */
368
- as: {
369
- ...primitiveProps.as,
370
- default: "span"
371
- },
372
- /**
373
- * Used to force mounting when more control is needed. Useful when
374
- * controlling animation with Vue animation libraries.
375
- */
376
- forceMount: {
377
- type: Boolean,
378
- required: false
379
- }
380
- };
381
- const RadioGroupIndicator = defineComponent({
382
- name: "DestylerRadioGroupindicator",
383
- props: radioGroupIndicatorProps,
384
- setup() {
385
- const itemContext = injectRadioGroupItemContext();
386
- const { forwardRef } = useForwardExpose();
387
- return {
388
- forwardRef,
389
- itemContext
390
- };
391
- },
392
- render() {
393
- return h(Presence, {
394
- present: this.$props.forceMount || this.itemContext.checked.value
395
- }, () => h(Primitive, mergeProps(this.$attrs, {
396
- "ref": (el) => this.forwardRef(el),
397
- "data-state": this.itemContext.checked.value ? "checked" : "unchecked",
398
- "data-disabled": this.itemContext.disabled.value ? "" : void 0,
399
- "asChild": this.$props.asChild,
400
- "as": this.$props.as
401
- }), () => this.$slots.default?.()));
402
- }
403
- });
404
-
405
- export { Radio, RadioGroupIndicator, RadioGroupItem, RadioGroupRoot, radioEmits, radioGroupIndicatorProps, radioGroupItemProps, radioGroupRootEmits, radioGroupRootProps, radioProps };
package/dist/resolver.cjs DELETED
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- const name = "@destyler/radio";
4
-
5
- const packageName = name;
6
- const radioComponentName = [
7
- "RadioGroupRoot",
8
- "RadioGroupItem",
9
- "RadioGroupindicator"
10
- ];
11
- function RadioResolver() {
12
- return {
13
- type: "component",
14
- resolve: (name2) => {
15
- if (radioComponentName.includes(name2))
16
- return { name: name2, from: packageName };
17
- }
18
- };
19
- }
20
-
21
- exports.RadioResolver = RadioResolver;
22
- exports.radioComponentName = radioComponentName;
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const radioComponentName: string[];
4
- declare function RadioResolver(): ComponentResolver;
5
-
6
- export { RadioResolver, radioComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const radioComponentName: string[];
4
- declare function RadioResolver(): ComponentResolver;
5
-
6
- export { RadioResolver, radioComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const radioComponentName: string[];
4
- declare function RadioResolver(): ComponentResolver;
5
-
6
- export { RadioResolver, radioComponentName };
package/dist/resolver.mjs DELETED
@@ -1,19 +0,0 @@
1
- const name = "@destyler/radio";
2
-
3
- const packageName = name;
4
- const radioComponentName = [
5
- "RadioGroupRoot",
6
- "RadioGroupItem",
7
- "RadioGroupindicator"
8
- ];
9
- function RadioResolver() {
10
- return {
11
- type: "component",
12
- resolve: (name2) => {
13
- if (radioComponentName.includes(name2))
14
- return { name: name2, from: packageName };
15
- }
16
- };
17
- }
18
-
19
- export { RadioResolver, radioComponentName };