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