@destyler/radio 0.0.3 → 0.0.4

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