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