@yamada-ui/radio 0.3.19 → 0.4.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.
- package/dist/{chunk-FHZRCWV7.mjs → chunk-UX7EGSYQ.mjs} +155 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -4
- package/dist/index.mjs +2 -4
- package/dist/radio-group.d.mts +21 -3
- package/dist/radio-group.d.ts +21 -3
- package/dist/radio-group.js +269 -18
- package/dist/radio-group.mjs +1 -1
- package/dist/radio.d.mts +3 -3
- package/dist/radio.d.ts +3 -3
- package/dist/radio.js +10 -4
- package/dist/radio.mjs +1 -2
- package/package.json +4 -4
- package/dist/chunk-577WYHY3.mjs +0 -148
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
"use client"
|
|
2
|
+
|
|
3
|
+
// src/radio-group.tsx
|
|
4
|
+
import { useFormControl as useFormControl2 } from "@yamada-ui/form-control";
|
|
5
|
+
import { Flex } from "@yamada-ui/layouts";
|
|
6
|
+
import { useControllableState } from "@yamada-ui/use-controllable-state";
|
|
7
|
+
import {
|
|
8
|
+
createContext,
|
|
9
|
+
cx as cx2,
|
|
10
|
+
isObject,
|
|
11
|
+
mergeRefs,
|
|
12
|
+
useCallbackRef as useCallbackRef2,
|
|
13
|
+
omitObject as omitObject2,
|
|
14
|
+
getValidChildren
|
|
15
|
+
} from "@yamada-ui/utils";
|
|
2
16
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
17
|
+
useCallback as useCallback2,
|
|
18
|
+
useId,
|
|
19
|
+
useRef,
|
|
20
|
+
forwardRef as forwardRef2
|
|
21
|
+
} from "react";
|
|
5
22
|
|
|
6
23
|
// src/radio.tsx
|
|
7
24
|
import {
|
|
@@ -234,14 +251,14 @@ var Radio = forwardRef(
|
|
|
234
251
|
/* @__PURE__ */ jsx(
|
|
235
252
|
ui.input,
|
|
236
253
|
{
|
|
237
|
-
className: "ui-
|
|
254
|
+
className: "ui-radio__input",
|
|
238
255
|
...getInputProps(inputProps, ref)
|
|
239
256
|
}
|
|
240
257
|
),
|
|
241
258
|
/* @__PURE__ */ jsx(
|
|
242
259
|
ui.span,
|
|
243
260
|
{
|
|
244
|
-
className: "ui-
|
|
261
|
+
className: "ui-radio__icon",
|
|
245
262
|
...getIconProps(iconProps),
|
|
246
263
|
__css: {
|
|
247
264
|
position: "relative",
|
|
@@ -254,7 +271,7 @@ var Radio = forwardRef(
|
|
|
254
271
|
/* @__PURE__ */ jsx(
|
|
255
272
|
ui.span,
|
|
256
273
|
{
|
|
257
|
-
className: "ui-
|
|
274
|
+
className: "ui-radio__label",
|
|
258
275
|
...getLabelProps(labelProps),
|
|
259
276
|
__css: { ...styles.label },
|
|
260
277
|
children
|
|
@@ -267,7 +284,140 @@ var Radio = forwardRef(
|
|
|
267
284
|
);
|
|
268
285
|
Radio.displayName = "Radio";
|
|
269
286
|
|
|
287
|
+
// src/radio-group.tsx
|
|
288
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
289
|
+
var isEvent = (value) => value && isObject(value) && isObject(value.target);
|
|
290
|
+
var useRadioGroup = ({
|
|
291
|
+
id,
|
|
292
|
+
name,
|
|
293
|
+
isNative,
|
|
294
|
+
...props
|
|
295
|
+
}) => {
|
|
296
|
+
id = id != null ? id : useId();
|
|
297
|
+
name = name != null ? name : `radio-${id}`;
|
|
298
|
+
props.onChange = useCallbackRef2(props.onChange);
|
|
299
|
+
const [value, setValue] = useControllableState({
|
|
300
|
+
value: props.value,
|
|
301
|
+
defaultValue: props.defaultValue,
|
|
302
|
+
onChange: props.onChange
|
|
303
|
+
});
|
|
304
|
+
const containerRef = useRef(null);
|
|
305
|
+
const onFocus = useCallback2(() => {
|
|
306
|
+
const container = containerRef.current;
|
|
307
|
+
if (!container)
|
|
308
|
+
return;
|
|
309
|
+
let query = `input:not(:disabled):checked`;
|
|
310
|
+
let firstInput = container.querySelector(query);
|
|
311
|
+
if (firstInput) {
|
|
312
|
+
firstInput.focus();
|
|
313
|
+
} else {
|
|
314
|
+
query = `input:not(:disabled)`;
|
|
315
|
+
firstInput = container.querySelector(query);
|
|
316
|
+
firstInput == null ? void 0 : firstInput.focus();
|
|
317
|
+
}
|
|
318
|
+
}, []);
|
|
319
|
+
const onChange = useCallback2(
|
|
320
|
+
(evOrValue) => {
|
|
321
|
+
const nextValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
|
|
322
|
+
setValue(nextValue);
|
|
323
|
+
},
|
|
324
|
+
[setValue]
|
|
325
|
+
);
|
|
326
|
+
const getContainerProps = useCallback2(
|
|
327
|
+
(props2 = {}, ref = null) => ({
|
|
328
|
+
...props2,
|
|
329
|
+
ref: mergeRefs(ref, containerRef),
|
|
330
|
+
role: "group"
|
|
331
|
+
}),
|
|
332
|
+
[]
|
|
333
|
+
);
|
|
334
|
+
const getRadioProps = useCallback2(
|
|
335
|
+
(props2 = {}, ref = null) => ({
|
|
336
|
+
...props2,
|
|
337
|
+
ref,
|
|
338
|
+
name,
|
|
339
|
+
[isNative ? "checked" : "isChecked"]: value != null ? props2.value === value : void 0,
|
|
340
|
+
onChange
|
|
341
|
+
}),
|
|
342
|
+
[name, value, onChange, isNative]
|
|
343
|
+
);
|
|
344
|
+
return {
|
|
345
|
+
name,
|
|
346
|
+
value,
|
|
347
|
+
setValue,
|
|
348
|
+
onChange,
|
|
349
|
+
onFocus,
|
|
350
|
+
getContainerProps,
|
|
351
|
+
getRadioProps
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
var [RadioGroupProvider, useRadioGroupContenxt] = createContext({
|
|
355
|
+
strict: false,
|
|
356
|
+
name: "RadioGroupContext"
|
|
357
|
+
});
|
|
358
|
+
var RadioGroup = forwardRef2(
|
|
359
|
+
({
|
|
360
|
+
className,
|
|
361
|
+
size,
|
|
362
|
+
variant,
|
|
363
|
+
colorScheme,
|
|
364
|
+
children,
|
|
365
|
+
items = [],
|
|
366
|
+
direction = "column",
|
|
367
|
+
gap,
|
|
368
|
+
...props
|
|
369
|
+
}, ref) => {
|
|
370
|
+
const { name, value, onChange, getContainerProps } = useRadioGroup(props);
|
|
371
|
+
const { isRequired, isReadOnly, isDisabled, isInvalid } = useFormControl2(props);
|
|
372
|
+
const validChildren = getValidChildren(children);
|
|
373
|
+
let computedChildren = [];
|
|
374
|
+
if (!validChildren.length && items.length) {
|
|
375
|
+
computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ jsx2(Radio, { value: value2, ...props2, children: label }, i));
|
|
376
|
+
}
|
|
377
|
+
return /* @__PURE__ */ jsx2(
|
|
378
|
+
RadioGroupProvider,
|
|
379
|
+
{
|
|
380
|
+
value: {
|
|
381
|
+
size,
|
|
382
|
+
variant,
|
|
383
|
+
colorScheme,
|
|
384
|
+
isRequired,
|
|
385
|
+
isReadOnly,
|
|
386
|
+
isDisabled,
|
|
387
|
+
isInvalid,
|
|
388
|
+
name,
|
|
389
|
+
value,
|
|
390
|
+
onChange
|
|
391
|
+
},
|
|
392
|
+
children: /* @__PURE__ */ jsx2(
|
|
393
|
+
Flex,
|
|
394
|
+
{
|
|
395
|
+
ref,
|
|
396
|
+
className: cx2("ui-radio-group", className),
|
|
397
|
+
direction,
|
|
398
|
+
gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
|
|
399
|
+
...getContainerProps(
|
|
400
|
+
omitObject2(props, [
|
|
401
|
+
"onChange",
|
|
402
|
+
"isInvalid",
|
|
403
|
+
"isDisabled",
|
|
404
|
+
"isRequired",
|
|
405
|
+
"isReadOnly"
|
|
406
|
+
])
|
|
407
|
+
),
|
|
408
|
+
children: children != null ? children : computedChildren
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
RadioGroup.displayName = "RadioGroup";
|
|
416
|
+
|
|
270
417
|
export {
|
|
418
|
+
useRadioGroup,
|
|
419
|
+
useRadioGroupContenxt,
|
|
420
|
+
RadioGroup,
|
|
271
421
|
useRadio,
|
|
272
422
|
Radio
|
|
273
423
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Radio, RadioProps, UseRadioProps, UseRadioReturn, useRadio } from './radio.mjs';
|
|
2
|
-
export { RadioGroup, RadioGroupProps, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup } from './radio-group.mjs';
|
|
2
|
+
export { RadioGroup, RadioGroupProps, RadioItem, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup } from './radio-group.mjs';
|
|
3
3
|
import '@yamada-ui/core';
|
|
4
4
|
import '@yamada-ui/form-control';
|
|
5
5
|
import '@yamada-ui/utils';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Radio, RadioProps, UseRadioProps, UseRadioReturn, useRadio } from './radio.js';
|
|
2
|
-
export { RadioGroup, RadioGroupProps, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup } from './radio-group.js';
|
|
2
|
+
export { RadioGroup, RadioGroupProps, RadioItem, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup } from './radio-group.js';
|
|
3
3
|
import '@yamada-ui/core';
|
|
4
4
|
import '@yamada-ui/form-control';
|
|
5
5
|
import '@yamada-ui/utils';
|
package/dist/index.js
CHANGED
|
@@ -118,12 +118,18 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
118
118
|
variant,
|
|
119
119
|
colorScheme,
|
|
120
120
|
children,
|
|
121
|
+
items = [],
|
|
121
122
|
direction = "column",
|
|
122
123
|
gap,
|
|
123
124
|
...props
|
|
124
125
|
}, ref) => {
|
|
125
126
|
const { name, value, onChange, getContainerProps } = useRadioGroup(props);
|
|
126
127
|
const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
|
|
128
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
129
|
+
let computedChildren = [];
|
|
130
|
+
if (!validChildren.length && items.length) {
|
|
131
|
+
computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Radio, { value: value2, ...props2, children: label }, i));
|
|
132
|
+
}
|
|
127
133
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
128
134
|
RadioGroupProvider,
|
|
129
135
|
{
|
|
@@ -155,7 +161,7 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
155
161
|
"isReadOnly"
|
|
156
162
|
])
|
|
157
163
|
),
|
|
158
|
-
children
|
|
164
|
+
children: children != null ? children : computedChildren
|
|
159
165
|
}
|
|
160
166
|
)
|
|
161
167
|
}
|
|
@@ -369,14 +375,14 @@ var Radio = (0, import_react2.forwardRef)(
|
|
|
369
375
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
370
376
|
import_core.ui.input,
|
|
371
377
|
{
|
|
372
|
-
className: "ui-
|
|
378
|
+
className: "ui-radio__input",
|
|
373
379
|
...getInputProps(inputProps, ref)
|
|
374
380
|
}
|
|
375
381
|
),
|
|
376
382
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
377
383
|
import_core.ui.span,
|
|
378
384
|
{
|
|
379
|
-
className: "ui-
|
|
385
|
+
className: "ui-radio__icon",
|
|
380
386
|
...getIconProps(iconProps),
|
|
381
387
|
__css: {
|
|
382
388
|
position: "relative",
|
|
@@ -389,7 +395,7 @@ var Radio = (0, import_react2.forwardRef)(
|
|
|
389
395
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
390
396
|
import_core.ui.span,
|
|
391
397
|
{
|
|
392
|
-
className: "ui-
|
|
398
|
+
className: "ui-radio__label",
|
|
393
399
|
...getLabelProps(labelProps),
|
|
394
400
|
__css: { ...styles.label },
|
|
395
401
|
children
|
package/dist/index.mjs
CHANGED
package/dist/radio-group.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RadioProps } from './radio.mjs';
|
|
1
2
|
import * as react from 'react';
|
|
2
3
|
import { ChangeEvent, Ref } from 'react';
|
|
3
4
|
import { ThemeProps, ComponentArgs } from '@yamada-ui/core';
|
|
@@ -5,6 +6,9 @@ import { FormControlOptions } from '@yamada-ui/form-control';
|
|
|
5
6
|
import { FlexProps } from '@yamada-ui/layouts';
|
|
6
7
|
import { PropGetter, DOMAttributes } from '@yamada-ui/utils';
|
|
7
8
|
|
|
9
|
+
type RadioItem<Y extends string | number = string> = RadioProps<Y> & {
|
|
10
|
+
label?: string;
|
|
11
|
+
};
|
|
8
12
|
type UseRadioGroupProps<Y extends string | number = string> = {
|
|
9
13
|
/**
|
|
10
14
|
* The top-level id string that will be applied to the radios.
|
|
@@ -57,8 +61,15 @@ declare const useRadioGroup: <Y extends string | number = string>({ id, name, is
|
|
|
57
61
|
}>;
|
|
58
62
|
};
|
|
59
63
|
type UseRadioGroupReturn = ReturnType<typeof useRadioGroup>;
|
|
60
|
-
type RadioGroupProps<Y extends string | number = string> = ThemeProps<
|
|
61
|
-
|
|
64
|
+
type RadioGroupProps<Y extends string | number = string> = ThemeProps<"Radio"> & Omit<FlexProps, "onChange"> & UseRadioGroupProps<Y> & FormControlOptions & {
|
|
65
|
+
/**
|
|
66
|
+
* If provided, generate radios based on items.
|
|
67
|
+
*
|
|
68
|
+
* @default '[]'
|
|
69
|
+
*/
|
|
70
|
+
items?: RadioItem<Y>[];
|
|
71
|
+
};
|
|
72
|
+
type RadioGroupContext = ThemeProps<"Radio"> & FormControlOptions & {
|
|
62
73
|
name: string;
|
|
63
74
|
value: string | number;
|
|
64
75
|
onChange: (evOrValue: ChangeEvent<HTMLInputElement> | string | number) => void;
|
|
@@ -66,7 +77,14 @@ type RadioGroupContext = ThemeProps<'Radio'> & FormControlOptions & {
|
|
|
66
77
|
declare const useRadioGroupContenxt: () => RadioGroupContext | undefined;
|
|
67
78
|
|
|
68
79
|
declare const RadioGroup: (<Y extends string | number = string>(props: ThemeProps<"Radio"> & Omit<FlexProps, "onChange"> & UseRadioGroupProps<Y> & FormControlOptions & {
|
|
80
|
+
/**
|
|
81
|
+
* If provided, generate radios based on items.
|
|
82
|
+
*
|
|
83
|
+
* @default '[]'
|
|
84
|
+
*/
|
|
85
|
+
items?: RadioItem<Y>[] | undefined;
|
|
86
|
+
} & {
|
|
69
87
|
ref?: Ref<HTMLDivElement> | undefined;
|
|
70
88
|
}) => JSX.Element) & ComponentArgs;
|
|
71
89
|
|
|
72
|
-
export { RadioGroup, RadioGroupProps, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup, useRadioGroupContenxt };
|
|
90
|
+
export { RadioGroup, RadioGroupProps, RadioItem, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup, useRadioGroupContenxt };
|
package/dist/radio-group.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RadioProps } from './radio.js';
|
|
1
2
|
import * as react from 'react';
|
|
2
3
|
import { ChangeEvent, Ref } from 'react';
|
|
3
4
|
import { ThemeProps, ComponentArgs } from '@yamada-ui/core';
|
|
@@ -5,6 +6,9 @@ import { FormControlOptions } from '@yamada-ui/form-control';
|
|
|
5
6
|
import { FlexProps } from '@yamada-ui/layouts';
|
|
6
7
|
import { PropGetter, DOMAttributes } from '@yamada-ui/utils';
|
|
7
8
|
|
|
9
|
+
type RadioItem<Y extends string | number = string> = RadioProps<Y> & {
|
|
10
|
+
label?: string;
|
|
11
|
+
};
|
|
8
12
|
type UseRadioGroupProps<Y extends string | number = string> = {
|
|
9
13
|
/**
|
|
10
14
|
* The top-level id string that will be applied to the radios.
|
|
@@ -57,8 +61,15 @@ declare const useRadioGroup: <Y extends string | number = string>({ id, name, is
|
|
|
57
61
|
}>;
|
|
58
62
|
};
|
|
59
63
|
type UseRadioGroupReturn = ReturnType<typeof useRadioGroup>;
|
|
60
|
-
type RadioGroupProps<Y extends string | number = string> = ThemeProps<
|
|
61
|
-
|
|
64
|
+
type RadioGroupProps<Y extends string | number = string> = ThemeProps<"Radio"> & Omit<FlexProps, "onChange"> & UseRadioGroupProps<Y> & FormControlOptions & {
|
|
65
|
+
/**
|
|
66
|
+
* If provided, generate radios based on items.
|
|
67
|
+
*
|
|
68
|
+
* @default '[]'
|
|
69
|
+
*/
|
|
70
|
+
items?: RadioItem<Y>[];
|
|
71
|
+
};
|
|
72
|
+
type RadioGroupContext = ThemeProps<"Radio"> & FormControlOptions & {
|
|
62
73
|
name: string;
|
|
63
74
|
value: string | number;
|
|
64
75
|
onChange: (evOrValue: ChangeEvent<HTMLInputElement> | string | number) => void;
|
|
@@ -66,7 +77,14 @@ type RadioGroupContext = ThemeProps<'Radio'> & FormControlOptions & {
|
|
|
66
77
|
declare const useRadioGroupContenxt: () => RadioGroupContext | undefined;
|
|
67
78
|
|
|
68
79
|
declare const RadioGroup: (<Y extends string | number = string>(props: ThemeProps<"Radio"> & Omit<FlexProps, "onChange"> & UseRadioGroupProps<Y> & FormControlOptions & {
|
|
80
|
+
/**
|
|
81
|
+
* If provided, generate radios based on items.
|
|
82
|
+
*
|
|
83
|
+
* @default '[]'
|
|
84
|
+
*/
|
|
85
|
+
items?: RadioItem<Y>[] | undefined;
|
|
86
|
+
} & {
|
|
69
87
|
ref?: Ref<HTMLDivElement> | undefined;
|
|
70
88
|
}) => JSX.Element) & ComponentArgs;
|
|
71
89
|
|
|
72
|
-
export { RadioGroup, RadioGroupProps, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup, useRadioGroupContenxt };
|
|
90
|
+
export { RadioGroup, RadioGroupProps, RadioItem, UseRadioGroupProps, UseRadioGroupReturn, useRadioGroup, useRadioGroupContenxt };
|
package/dist/radio-group.js
CHANGED
|
@@ -26,29 +26,274 @@ __export(radio_group_exports, {
|
|
|
26
26
|
useRadioGroupContenxt: () => useRadioGroupContenxt
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(radio_group_exports);
|
|
29
|
-
var
|
|
29
|
+
var import_form_control2 = require("@yamada-ui/form-control");
|
|
30
30
|
var import_layouts = require("@yamada-ui/layouts");
|
|
31
31
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
32
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
33
|
+
var import_react2 = require("react");
|
|
34
|
+
|
|
35
|
+
// src/radio.tsx
|
|
36
|
+
var import_core = require("@yamada-ui/core");
|
|
37
|
+
var import_form_control = require("@yamada-ui/form-control");
|
|
38
|
+
var import_use_focus_visible = require("@yamada-ui/use-focus-visible");
|
|
32
39
|
var import_utils = require("@yamada-ui/utils");
|
|
33
40
|
var import_react = require("react");
|
|
34
41
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
-
var
|
|
42
|
+
var useRadio = (props) => {
|
|
43
|
+
const { id, name, value, required, disabled, readOnly, ...rest } = (0, import_form_control.useFormControlProps)(props);
|
|
44
|
+
const [isFocusVisible, setIsFocusVisible] = (0, import_react.useState)(false);
|
|
45
|
+
const [isFocused, setFocused] = (0, import_react.useState)(false);
|
|
46
|
+
const [isHovered, setHovered] = (0, import_react.useState)(false);
|
|
47
|
+
const [isActive, setActive] = (0, import_react.useState)(false);
|
|
48
|
+
const [isChecked, setIsChecked] = (0, import_react.useState)(!!props.defaultChecked);
|
|
49
|
+
const isControlled = props.isChecked !== void 0;
|
|
50
|
+
const checked = isControlled ? props.isChecked : isChecked;
|
|
51
|
+
(0, import_react.useEffect)(() => {
|
|
52
|
+
return (0, import_use_focus_visible.trackFocusVisible)(setIsFocusVisible);
|
|
53
|
+
}, []);
|
|
54
|
+
const onChange = (0, import_utils.useCallbackRef)(
|
|
55
|
+
(ev) => {
|
|
56
|
+
var _a;
|
|
57
|
+
if (readOnly || disabled) {
|
|
58
|
+
ev.preventDefault();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!isControlled)
|
|
62
|
+
setIsChecked(ev.target.checked);
|
|
63
|
+
(_a = rest.onChange) == null ? void 0 : _a.call(rest, ev);
|
|
64
|
+
},
|
|
65
|
+
[readOnly, disabled, isControlled]
|
|
66
|
+
);
|
|
67
|
+
const onBlur = (0, import_utils.useCallbackRef)(rest.onBlur);
|
|
68
|
+
const onFocus = (0, import_utils.useCallbackRef)(rest.onFocus);
|
|
69
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
70
|
+
({ key }) => {
|
|
71
|
+
if (key === " ")
|
|
72
|
+
setActive(true);
|
|
73
|
+
},
|
|
74
|
+
[setActive]
|
|
75
|
+
);
|
|
76
|
+
const onKeyUp = (0, import_react.useCallback)(
|
|
77
|
+
({ key }) => {
|
|
78
|
+
if (key === " ")
|
|
79
|
+
setActive(false);
|
|
80
|
+
},
|
|
81
|
+
[setActive]
|
|
82
|
+
);
|
|
83
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
84
|
+
(props2 = {}, ref = null) => ({
|
|
85
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
86
|
+
...props2,
|
|
87
|
+
ref,
|
|
88
|
+
"data-checked": (0, import_utils.dataAttr)(checked)
|
|
89
|
+
}),
|
|
90
|
+
[checked, rest]
|
|
91
|
+
);
|
|
92
|
+
const getIconProps = (0, import_react.useCallback)(
|
|
93
|
+
(props2 = {}, ref = null) => ({
|
|
94
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
95
|
+
...props2,
|
|
96
|
+
ref,
|
|
97
|
+
"data-active": (0, import_utils.dataAttr)(isActive),
|
|
98
|
+
"data-hover": (0, import_utils.dataAttr)(isHovered),
|
|
99
|
+
"data-checked": (0, import_utils.dataAttr)(checked),
|
|
100
|
+
"data-focus": (0, import_utils.dataAttr)(isFocused),
|
|
101
|
+
"data-focus-visible": (0, import_utils.dataAttr)(isFocused && isFocusVisible),
|
|
102
|
+
"aria-hidden": true,
|
|
103
|
+
onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, () => setActive(true)),
|
|
104
|
+
onMouseUp: (0, import_utils.handlerAll)(props2.onMouseUp, () => setActive(false)),
|
|
105
|
+
onMouseEnter: (0, import_utils.handlerAll)(props2.onMouseEnter, () => setHovered(true)),
|
|
106
|
+
onMouseLeave: (0, import_utils.handlerAll)(props2.onMouseLeave, () => setHovered(false))
|
|
107
|
+
}),
|
|
108
|
+
[checked, isActive, isFocused, isFocusVisible, isHovered, rest]
|
|
109
|
+
);
|
|
110
|
+
const getInputProps = (0, import_react.useCallback)(
|
|
111
|
+
(props2 = {}, ref = null) => ({
|
|
112
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
113
|
+
...props2,
|
|
114
|
+
ref,
|
|
115
|
+
id,
|
|
116
|
+
type: "radio",
|
|
117
|
+
name,
|
|
118
|
+
value,
|
|
119
|
+
required,
|
|
120
|
+
disabled,
|
|
121
|
+
readOnly,
|
|
122
|
+
checked,
|
|
123
|
+
style: {
|
|
124
|
+
border: "0px",
|
|
125
|
+
clip: "rect(0px, 0px, 0px, 0px)",
|
|
126
|
+
height: "1px",
|
|
127
|
+
width: "1px",
|
|
128
|
+
margin: "-1px",
|
|
129
|
+
padding: "0px",
|
|
130
|
+
overflow: "hidden",
|
|
131
|
+
whiteSpace: "nowrap",
|
|
132
|
+
position: "absolute"
|
|
133
|
+
},
|
|
134
|
+
onChange: (0, import_utils.handlerAll)(props2.onChange, onChange),
|
|
135
|
+
onBlur: (0, import_utils.handlerAll)(props2.onBlur, onBlur, () => setFocused(false)),
|
|
136
|
+
onFocus: (0, import_utils.handlerAll)(props2.onFocus, onFocus, () => setFocused(true)),
|
|
137
|
+
onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
|
|
138
|
+
onKeyUp: (0, import_utils.handlerAll)(props2.onKeyUp, onKeyUp)
|
|
139
|
+
}),
|
|
140
|
+
[
|
|
141
|
+
rest,
|
|
142
|
+
id,
|
|
143
|
+
name,
|
|
144
|
+
value,
|
|
145
|
+
required,
|
|
146
|
+
disabled,
|
|
147
|
+
readOnly,
|
|
148
|
+
checked,
|
|
149
|
+
onChange,
|
|
150
|
+
onBlur,
|
|
151
|
+
onFocus,
|
|
152
|
+
onKeyDown,
|
|
153
|
+
onKeyUp
|
|
154
|
+
]
|
|
155
|
+
);
|
|
156
|
+
const getLabelProps = (0, import_react.useCallback)(
|
|
157
|
+
(props2 = {}, ref = null) => ({
|
|
158
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
159
|
+
props: props2,
|
|
160
|
+
ref,
|
|
161
|
+
onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, (ev) => {
|
|
162
|
+
ev.preventDefault();
|
|
163
|
+
ev.stopPropagation();
|
|
164
|
+
}),
|
|
165
|
+
onTouchStart: (0, import_utils.handlerAll)(props2.onTouchStart, (ev) => {
|
|
166
|
+
ev.preventDefault();
|
|
167
|
+
ev.stopPropagation();
|
|
168
|
+
}),
|
|
169
|
+
"data-checked": (0, import_utils.dataAttr)(checked)
|
|
170
|
+
}),
|
|
171
|
+
[checked, rest]
|
|
172
|
+
);
|
|
173
|
+
return {
|
|
174
|
+
isFocusVisible,
|
|
175
|
+
isFocused,
|
|
176
|
+
isHovered,
|
|
177
|
+
isActive,
|
|
178
|
+
isChecked: checked,
|
|
179
|
+
getContainerProps,
|
|
180
|
+
getInputProps,
|
|
181
|
+
getIconProps,
|
|
182
|
+
getLabelProps
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
var Radio = (0, import_react.forwardRef)(
|
|
186
|
+
(props, ref) => {
|
|
187
|
+
var _a, _b, _c, _d;
|
|
188
|
+
const group = useRadioGroupContenxt();
|
|
189
|
+
const control = (0, import_form_control.useFormControl)(props);
|
|
190
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Radio", {
|
|
191
|
+
...group,
|
|
192
|
+
...props
|
|
193
|
+
});
|
|
194
|
+
const {
|
|
195
|
+
className,
|
|
196
|
+
gap = "0.5rem",
|
|
197
|
+
isRequired = (_a = group == null ? void 0 : group.isRequired) != null ? _a : control.isRequired,
|
|
198
|
+
isReadOnly = (_b = group == null ? void 0 : group.isReadOnly) != null ? _b : control.isReadOnly,
|
|
199
|
+
isDisabled = (_c = group == null ? void 0 : group.isDisabled) != null ? _c : control.isDisabled,
|
|
200
|
+
isInvalid = (_d = group == null ? void 0 : group.isInvalid) != null ? _d : control.isInvalid,
|
|
201
|
+
iconProps,
|
|
202
|
+
inputProps,
|
|
203
|
+
labelProps,
|
|
204
|
+
children,
|
|
205
|
+
...rest
|
|
206
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
207
|
+
const { getContainerProps, getInputProps, getIconProps, getLabelProps } = useRadio({
|
|
208
|
+
...rest,
|
|
209
|
+
isRequired,
|
|
210
|
+
isReadOnly,
|
|
211
|
+
isDisabled,
|
|
212
|
+
isInvalid,
|
|
213
|
+
isChecked: (group == null ? void 0 : group.value) && rest.value ? group.value === rest.value : rest.isChecked,
|
|
214
|
+
onChange: (group == null ? void 0 : group.onChange) && rest.value ? (0, import_utils.funcAll)(group.onChange, rest.onChange) : rest.onChange
|
|
215
|
+
});
|
|
216
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
217
|
+
import_core.ui.label,
|
|
218
|
+
{
|
|
219
|
+
className: (0, import_utils.cx)("ui-radio", className),
|
|
220
|
+
...getContainerProps(),
|
|
221
|
+
...(0, import_utils.omitObject)(rest, [
|
|
222
|
+
"id",
|
|
223
|
+
"name",
|
|
224
|
+
"value",
|
|
225
|
+
"defaultValue",
|
|
226
|
+
"defaultChecked",
|
|
227
|
+
"isChecked",
|
|
228
|
+
"onChange",
|
|
229
|
+
"onBlur",
|
|
230
|
+
"onFocus"
|
|
231
|
+
]),
|
|
232
|
+
__css: {
|
|
233
|
+
cursor: "pointer",
|
|
234
|
+
position: "relative",
|
|
235
|
+
display: "inline-flex",
|
|
236
|
+
alignItems: "center",
|
|
237
|
+
verticalAlign: "top",
|
|
238
|
+
gap,
|
|
239
|
+
...styles.container
|
|
240
|
+
},
|
|
241
|
+
children: [
|
|
242
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
243
|
+
import_core.ui.input,
|
|
244
|
+
{
|
|
245
|
+
className: "ui-radio__input",
|
|
246
|
+
...getInputProps(inputProps, ref)
|
|
247
|
+
}
|
|
248
|
+
),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
250
|
+
import_core.ui.span,
|
|
251
|
+
{
|
|
252
|
+
className: "ui-radio__icon",
|
|
253
|
+
...getIconProps(iconProps),
|
|
254
|
+
__css: {
|
|
255
|
+
position: "relative",
|
|
256
|
+
display: "inline-block",
|
|
257
|
+
userSelect: "none",
|
|
258
|
+
...styles.icon
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
),
|
|
262
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
263
|
+
import_core.ui.span,
|
|
264
|
+
{
|
|
265
|
+
className: "ui-radio__label",
|
|
266
|
+
...getLabelProps(labelProps),
|
|
267
|
+
__css: { ...styles.label },
|
|
268
|
+
children
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
Radio.displayName = "Radio";
|
|
277
|
+
|
|
278
|
+
// src/radio-group.tsx
|
|
279
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
280
|
+
var isEvent = (value) => value && (0, import_utils2.isObject)(value) && (0, import_utils2.isObject)(value.target);
|
|
36
281
|
var useRadioGroup = ({
|
|
37
282
|
id,
|
|
38
283
|
name,
|
|
39
284
|
isNative,
|
|
40
285
|
...props
|
|
41
286
|
}) => {
|
|
42
|
-
id = id != null ? id : (0,
|
|
287
|
+
id = id != null ? id : (0, import_react2.useId)();
|
|
43
288
|
name = name != null ? name : `radio-${id}`;
|
|
44
|
-
props.onChange = (0,
|
|
289
|
+
props.onChange = (0, import_utils2.useCallbackRef)(props.onChange);
|
|
45
290
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
46
291
|
value: props.value,
|
|
47
292
|
defaultValue: props.defaultValue,
|
|
48
293
|
onChange: props.onChange
|
|
49
294
|
});
|
|
50
|
-
const containerRef = (0,
|
|
51
|
-
const onFocus = (0,
|
|
295
|
+
const containerRef = (0, import_react2.useRef)(null);
|
|
296
|
+
const onFocus = (0, import_react2.useCallback)(() => {
|
|
52
297
|
const container = containerRef.current;
|
|
53
298
|
if (!container)
|
|
54
299
|
return;
|
|
@@ -62,22 +307,22 @@ var useRadioGroup = ({
|
|
|
62
307
|
firstInput == null ? void 0 : firstInput.focus();
|
|
63
308
|
}
|
|
64
309
|
}, []);
|
|
65
|
-
const onChange = (0,
|
|
310
|
+
const onChange = (0, import_react2.useCallback)(
|
|
66
311
|
(evOrValue) => {
|
|
67
312
|
const nextValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
|
|
68
313
|
setValue(nextValue);
|
|
69
314
|
},
|
|
70
315
|
[setValue]
|
|
71
316
|
);
|
|
72
|
-
const getContainerProps = (0,
|
|
317
|
+
const getContainerProps = (0, import_react2.useCallback)(
|
|
73
318
|
(props2 = {}, ref = null) => ({
|
|
74
319
|
...props2,
|
|
75
|
-
ref: (0,
|
|
320
|
+
ref: (0, import_utils2.mergeRefs)(ref, containerRef),
|
|
76
321
|
role: "group"
|
|
77
322
|
}),
|
|
78
323
|
[]
|
|
79
324
|
);
|
|
80
|
-
const getRadioProps = (0,
|
|
325
|
+
const getRadioProps = (0, import_react2.useCallback)(
|
|
81
326
|
(props2 = {}, ref = null) => ({
|
|
82
327
|
...props2,
|
|
83
328
|
ref,
|
|
@@ -97,24 +342,30 @@ var useRadioGroup = ({
|
|
|
97
342
|
getRadioProps
|
|
98
343
|
};
|
|
99
344
|
};
|
|
100
|
-
var [RadioGroupProvider, useRadioGroupContenxt] = (0,
|
|
345
|
+
var [RadioGroupProvider, useRadioGroupContenxt] = (0, import_utils2.createContext)({
|
|
101
346
|
strict: false,
|
|
102
347
|
name: "RadioGroupContext"
|
|
103
348
|
});
|
|
104
|
-
var RadioGroup = (0,
|
|
349
|
+
var RadioGroup = (0, import_react2.forwardRef)(
|
|
105
350
|
({
|
|
106
351
|
className,
|
|
107
352
|
size,
|
|
108
353
|
variant,
|
|
109
354
|
colorScheme,
|
|
110
355
|
children,
|
|
356
|
+
items = [],
|
|
111
357
|
direction = "column",
|
|
112
358
|
gap,
|
|
113
359
|
...props
|
|
114
360
|
}, ref) => {
|
|
115
361
|
const { name, value, onChange, getContainerProps } = useRadioGroup(props);
|
|
116
|
-
const { isRequired, isReadOnly, isDisabled, isInvalid } = (0,
|
|
117
|
-
|
|
362
|
+
const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control2.useFormControl)(props);
|
|
363
|
+
const validChildren = (0, import_utils2.getValidChildren)(children);
|
|
364
|
+
let computedChildren = [];
|
|
365
|
+
if (!validChildren.length && items.length) {
|
|
366
|
+
computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Radio, { value: value2, ...props2, children: label }, i));
|
|
367
|
+
}
|
|
368
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
118
369
|
RadioGroupProvider,
|
|
119
370
|
{
|
|
120
371
|
value: {
|
|
@@ -129,15 +380,15 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
129
380
|
value,
|
|
130
381
|
onChange
|
|
131
382
|
},
|
|
132
|
-
children: /* @__PURE__ */ (0,
|
|
383
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
133
384
|
import_layouts.Flex,
|
|
134
385
|
{
|
|
135
386
|
ref,
|
|
136
|
-
className: (0,
|
|
387
|
+
className: (0, import_utils2.cx)("ui-radio-group", className),
|
|
137
388
|
direction,
|
|
138
389
|
gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
|
|
139
390
|
...getContainerProps(
|
|
140
|
-
(0,
|
|
391
|
+
(0, import_utils2.omitObject)(props, [
|
|
141
392
|
"onChange",
|
|
142
393
|
"isInvalid",
|
|
143
394
|
"isDisabled",
|
|
@@ -145,7 +396,7 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
145
396
|
"isReadOnly"
|
|
146
397
|
])
|
|
147
398
|
),
|
|
148
|
-
children
|
|
399
|
+
children: children != null ? children : computedChildren
|
|
149
400
|
}
|
|
150
401
|
)
|
|
151
402
|
}
|
package/dist/radio-group.mjs
CHANGED
package/dist/radio.d.mts
CHANGED
|
@@ -46,11 +46,11 @@ declare const useRadio: <Y extends string | number = string>(props: UseRadioProp
|
|
|
46
46
|
};
|
|
47
47
|
type UseRadioReturn = ReturnType<typeof useRadio>;
|
|
48
48
|
type RadioOptions = {
|
|
49
|
-
iconProps?: HTMLUIProps<
|
|
49
|
+
iconProps?: HTMLUIProps<"span">;
|
|
50
50
|
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
51
|
-
labelProps?: HTMLUIProps<
|
|
51
|
+
labelProps?: HTMLUIProps<"span">;
|
|
52
52
|
};
|
|
53
|
-
type RadioProps<Y extends string | number = string> = Omit<HTMLUIProps<
|
|
53
|
+
type RadioProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">, keyof UseRadioProps> & ThemeProps<"Radio"> & UseRadioProps<Y> & RadioOptions;
|
|
54
54
|
declare const Radio: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "value" | "name" | "id" | "onChange" | "defaultChecked" | keyof FormControlOptions | "isChecked"> & ThemeProps<"Radio"> & FormControlOptions & {
|
|
55
55
|
/**
|
|
56
56
|
* id assigned to input.
|
package/dist/radio.d.ts
CHANGED
|
@@ -46,11 +46,11 @@ declare const useRadio: <Y extends string | number = string>(props: UseRadioProp
|
|
|
46
46
|
};
|
|
47
47
|
type UseRadioReturn = ReturnType<typeof useRadio>;
|
|
48
48
|
type RadioOptions = {
|
|
49
|
-
iconProps?: HTMLUIProps<
|
|
49
|
+
iconProps?: HTMLUIProps<"span">;
|
|
50
50
|
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
51
|
-
labelProps?: HTMLUIProps<
|
|
51
|
+
labelProps?: HTMLUIProps<"span">;
|
|
52
52
|
};
|
|
53
|
-
type RadioProps<Y extends string | number = string> = Omit<HTMLUIProps<
|
|
53
|
+
type RadioProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">, keyof UseRadioProps> & ThemeProps<"Radio"> & UseRadioProps<Y> & RadioOptions;
|
|
54
54
|
declare const Radio: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "value" | "name" | "id" | "onChange" | "defaultChecked" | keyof FormControlOptions | "isChecked"> & ThemeProps<"Radio"> & FormControlOptions & {
|
|
55
55
|
/**
|
|
56
56
|
* id assigned to input.
|
package/dist/radio.js
CHANGED
|
@@ -114,12 +114,18 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
114
114
|
variant,
|
|
115
115
|
colorScheme,
|
|
116
116
|
children,
|
|
117
|
+
items = [],
|
|
117
118
|
direction = "column",
|
|
118
119
|
gap,
|
|
119
120
|
...props
|
|
120
121
|
}, ref) => {
|
|
121
122
|
const { name, value, onChange, getContainerProps } = useRadioGroup(props);
|
|
122
123
|
const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
|
|
124
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
125
|
+
let computedChildren = [];
|
|
126
|
+
if (!validChildren.length && items.length) {
|
|
127
|
+
computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Radio, { value: value2, ...props2, children: label }, i));
|
|
128
|
+
}
|
|
123
129
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
130
|
RadioGroupProvider,
|
|
125
131
|
{
|
|
@@ -151,7 +157,7 @@ var RadioGroup = (0, import_react.forwardRef)(
|
|
|
151
157
|
"isReadOnly"
|
|
152
158
|
])
|
|
153
159
|
),
|
|
154
|
-
children
|
|
160
|
+
children: children != null ? children : computedChildren
|
|
155
161
|
}
|
|
156
162
|
)
|
|
157
163
|
}
|
|
@@ -365,14 +371,14 @@ var Radio = (0, import_react2.forwardRef)(
|
|
|
365
371
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
366
372
|
import_core.ui.input,
|
|
367
373
|
{
|
|
368
|
-
className: "ui-
|
|
374
|
+
className: "ui-radio__input",
|
|
369
375
|
...getInputProps(inputProps, ref)
|
|
370
376
|
}
|
|
371
377
|
),
|
|
372
378
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
373
379
|
import_core.ui.span,
|
|
374
380
|
{
|
|
375
|
-
className: "ui-
|
|
381
|
+
className: "ui-radio__icon",
|
|
376
382
|
...getIconProps(iconProps),
|
|
377
383
|
__css: {
|
|
378
384
|
position: "relative",
|
|
@@ -385,7 +391,7 @@ var Radio = (0, import_react2.forwardRef)(
|
|
|
385
391
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
386
392
|
import_core.ui.span,
|
|
387
393
|
{
|
|
388
|
-
className: "ui-
|
|
394
|
+
className: "ui-radio__label",
|
|
389
395
|
...getLabelProps(labelProps),
|
|
390
396
|
__css: { ...styles.label },
|
|
391
397
|
children
|
package/dist/radio.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/radio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Yamada UI radio component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@yamada-ui/core": "0.12.
|
|
38
|
+
"@yamada-ui/core": "0.12.6",
|
|
39
39
|
"@yamada-ui/utils": "0.3.3",
|
|
40
|
-
"@yamada-ui/form-control": "0.3.
|
|
41
|
-
"@yamada-ui/layouts": "0.3.
|
|
40
|
+
"@yamada-ui/form-control": "0.3.19",
|
|
41
|
+
"@yamada-ui/layouts": "0.3.17",
|
|
42
42
|
"@yamada-ui/use-controllable-state": "0.3.0",
|
|
43
43
|
"@yamada-ui/use-focus-visible": "0.2.5"
|
|
44
44
|
},
|
package/dist/chunk-577WYHY3.mjs
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
// src/radio-group.tsx
|
|
4
|
-
import { useFormControl } from "@yamada-ui/form-control";
|
|
5
|
-
import { Flex } from "@yamada-ui/layouts";
|
|
6
|
-
import { useControllableState } from "@yamada-ui/use-controllable-state";
|
|
7
|
-
import {
|
|
8
|
-
createContext,
|
|
9
|
-
cx,
|
|
10
|
-
isObject,
|
|
11
|
-
mergeRefs,
|
|
12
|
-
useCallbackRef,
|
|
13
|
-
omitObject
|
|
14
|
-
} from "@yamada-ui/utils";
|
|
15
|
-
import {
|
|
16
|
-
useCallback,
|
|
17
|
-
useId,
|
|
18
|
-
useRef,
|
|
19
|
-
forwardRef
|
|
20
|
-
} from "react";
|
|
21
|
-
import { jsx } from "react/jsx-runtime";
|
|
22
|
-
var isEvent = (value) => value && isObject(value) && isObject(value.target);
|
|
23
|
-
var useRadioGroup = ({
|
|
24
|
-
id,
|
|
25
|
-
name,
|
|
26
|
-
isNative,
|
|
27
|
-
...props
|
|
28
|
-
}) => {
|
|
29
|
-
id = id != null ? id : useId();
|
|
30
|
-
name = name != null ? name : `radio-${id}`;
|
|
31
|
-
props.onChange = useCallbackRef(props.onChange);
|
|
32
|
-
const [value, setValue] = useControllableState({
|
|
33
|
-
value: props.value,
|
|
34
|
-
defaultValue: props.defaultValue,
|
|
35
|
-
onChange: props.onChange
|
|
36
|
-
});
|
|
37
|
-
const containerRef = useRef(null);
|
|
38
|
-
const onFocus = useCallback(() => {
|
|
39
|
-
const container = containerRef.current;
|
|
40
|
-
if (!container)
|
|
41
|
-
return;
|
|
42
|
-
let query = `input:not(:disabled):checked`;
|
|
43
|
-
let firstInput = container.querySelector(query);
|
|
44
|
-
if (firstInput) {
|
|
45
|
-
firstInput.focus();
|
|
46
|
-
} else {
|
|
47
|
-
query = `input:not(:disabled)`;
|
|
48
|
-
firstInput = container.querySelector(query);
|
|
49
|
-
firstInput == null ? void 0 : firstInput.focus();
|
|
50
|
-
}
|
|
51
|
-
}, []);
|
|
52
|
-
const onChange = useCallback(
|
|
53
|
-
(evOrValue) => {
|
|
54
|
-
const nextValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
|
|
55
|
-
setValue(nextValue);
|
|
56
|
-
},
|
|
57
|
-
[setValue]
|
|
58
|
-
);
|
|
59
|
-
const getContainerProps = useCallback(
|
|
60
|
-
(props2 = {}, ref = null) => ({
|
|
61
|
-
...props2,
|
|
62
|
-
ref: mergeRefs(ref, containerRef),
|
|
63
|
-
role: "group"
|
|
64
|
-
}),
|
|
65
|
-
[]
|
|
66
|
-
);
|
|
67
|
-
const getRadioProps = useCallback(
|
|
68
|
-
(props2 = {}, ref = null) => ({
|
|
69
|
-
...props2,
|
|
70
|
-
ref,
|
|
71
|
-
name,
|
|
72
|
-
[isNative ? "checked" : "isChecked"]: value != null ? props2.value === value : void 0,
|
|
73
|
-
onChange
|
|
74
|
-
}),
|
|
75
|
-
[name, value, onChange, isNative]
|
|
76
|
-
);
|
|
77
|
-
return {
|
|
78
|
-
name,
|
|
79
|
-
value,
|
|
80
|
-
setValue,
|
|
81
|
-
onChange,
|
|
82
|
-
onFocus,
|
|
83
|
-
getContainerProps,
|
|
84
|
-
getRadioProps
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
var [RadioGroupProvider, useRadioGroupContenxt] = createContext({
|
|
88
|
-
strict: false,
|
|
89
|
-
name: "RadioGroupContext"
|
|
90
|
-
});
|
|
91
|
-
var RadioGroup = forwardRef(
|
|
92
|
-
({
|
|
93
|
-
className,
|
|
94
|
-
size,
|
|
95
|
-
variant,
|
|
96
|
-
colorScheme,
|
|
97
|
-
children,
|
|
98
|
-
direction = "column",
|
|
99
|
-
gap,
|
|
100
|
-
...props
|
|
101
|
-
}, ref) => {
|
|
102
|
-
const { name, value, onChange, getContainerProps } = useRadioGroup(props);
|
|
103
|
-
const { isRequired, isReadOnly, isDisabled, isInvalid } = useFormControl(props);
|
|
104
|
-
return /* @__PURE__ */ jsx(
|
|
105
|
-
RadioGroupProvider,
|
|
106
|
-
{
|
|
107
|
-
value: {
|
|
108
|
-
size,
|
|
109
|
-
variant,
|
|
110
|
-
colorScheme,
|
|
111
|
-
isRequired,
|
|
112
|
-
isReadOnly,
|
|
113
|
-
isDisabled,
|
|
114
|
-
isInvalid,
|
|
115
|
-
name,
|
|
116
|
-
value,
|
|
117
|
-
onChange
|
|
118
|
-
},
|
|
119
|
-
children: /* @__PURE__ */ jsx(
|
|
120
|
-
Flex,
|
|
121
|
-
{
|
|
122
|
-
ref,
|
|
123
|
-
className: cx("ui-radio-group", className),
|
|
124
|
-
direction,
|
|
125
|
-
gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
|
|
126
|
-
...getContainerProps(
|
|
127
|
-
omitObject(props, [
|
|
128
|
-
"onChange",
|
|
129
|
-
"isInvalid",
|
|
130
|
-
"isDisabled",
|
|
131
|
-
"isRequired",
|
|
132
|
-
"isReadOnly"
|
|
133
|
-
])
|
|
134
|
-
),
|
|
135
|
-
children
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
RadioGroup.displayName = "RadioGroup";
|
|
143
|
-
|
|
144
|
-
export {
|
|
145
|
-
useRadioGroup,
|
|
146
|
-
useRadioGroupContenxt,
|
|
147
|
-
RadioGroup
|
|
148
|
-
};
|