@broxus/react-uikit 0.13.6 → 0.14.0
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/cjs/components/Control/Checkbox/Checkbox.d.ts +30 -2
- package/dist/cjs/components/Control/Checkbox/Checkbox.js +15 -11
- package/dist/cjs/components/Control/Checkbox/CheckboxGroupContext.d.ts +7 -21
- package/dist/cjs/components/Control/Checkbox/Group.d.ts +29 -9
- package/dist/cjs/components/Control/Checkbox/Group.js +15 -18
- package/dist/cjs/components/Control/Checkbox/index.d.ts +4 -5
- package/dist/cjs/components/Control/Checkbox/index.js +0 -15
- package/dist/cjs/components/Control/Radio/Group.js +2 -2
- package/dist/cjs/components/Control/Radio/Radio.d.ts +10 -1
- package/dist/cjs/components/Control/Radio/Radio.js +8 -3
- package/dist/cjs/components/Control/Radio/RadioGroupContext.d.ts +3 -3
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/components/Control/Checkbox/Checkbox.d.ts +30 -2
- package/dist/esm/components/Control/Checkbox/Checkbox.js +15 -11
- package/dist/esm/components/Control/Checkbox/CheckboxGroupContext.d.ts +7 -21
- package/dist/esm/components/Control/Checkbox/Group.d.ts +29 -9
- package/dist/esm/components/Control/Checkbox/Group.js +16 -19
- package/dist/esm/components/Control/Checkbox/index.d.ts +4 -5
- package/dist/esm/components/Control/Checkbox/index.js +2 -3
- package/dist/esm/components/Control/Radio/Group.js +2 -2
- package/dist/esm/components/Control/Radio/Radio.d.ts +10 -1
- package/dist/esm/components/Control/Radio/Radio.js +8 -3
- package/dist/esm/components/Control/Radio/RadioGroupContext.d.ts +3 -3
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/dist/cjs/components/Control/Checkbox/types.d.ts +0 -10
- package/dist/cjs/components/Control/Checkbox/types.js +0 -2
- package/dist/esm/components/Control/Checkbox/types.d.ts +0 -10
- package/dist/esm/components/Control/Checkbox/types.js +0 -1
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface
|
|
2
|
+
import { type SizeType } from '../../../components/Control';
|
|
3
|
+
export interface AbstractCheckboxProps<T> extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'type' | 'onChange' | 'onMouseEnter' | 'onMouseLeave'> {
|
|
4
|
+
autoFocus?: boolean;
|
|
5
|
+
block?: boolean;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
defaultChecked?: boolean;
|
|
8
|
+
direction?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
prefixCls?: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
rootClassName?: string;
|
|
13
|
+
size?: SizeType;
|
|
14
|
+
skipGroup?: boolean;
|
|
15
|
+
tabIndex?: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
type?: string;
|
|
18
|
+
value?: any;
|
|
19
|
+
id?: string;
|
|
20
|
+
onChange?: (event: T) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface CheckboxChangeEventTarget extends CheckboxProps {
|
|
23
|
+
checked: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface CheckboxChangeEvent {
|
|
26
|
+
nativeEvent: MouseEvent;
|
|
27
|
+
preventDefault: VoidFunction;
|
|
28
|
+
stopPropagation: VoidFunction;
|
|
29
|
+
target: CheckboxChangeEventTarget;
|
|
30
|
+
}
|
|
31
|
+
export interface CheckboxProps extends AbstractCheckboxProps<CheckboxChangeEvent> {
|
|
4
32
|
indeterminate?: boolean;
|
|
5
33
|
onMouseEnter?: React.MouseEventHandler<HTMLLabelElement>;
|
|
6
34
|
onMouseLeave?: React.MouseEventHandler<HTMLLabelElement>;
|
|
@@ -35,20 +35,27 @@ const CheckboxGroupContext_1 = require("../../../components/Control/Checkbox/Che
|
|
|
35
35
|
exports.Checkbox = React.forwardRef((props, ref) => {
|
|
36
36
|
const config = (0, ConfigProvider_1.useConfig)();
|
|
37
37
|
const checkboxGroup = (0, CheckboxGroupContext_1.useCheckboxGroup)();
|
|
38
|
-
const { block, children, className, direction = config.direction, disabled, id, prefixCls = config.prefixCls, size, skipGroup, style, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
38
|
+
const { block, children, className, direction = config.direction, disabled, id, prefixCls = config.prefixCls, size, skipGroup, style, type = 'checkbox', onChange: onChangeCallback, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
39
39
|
const prevValue = React.useRef(restProps.value);
|
|
40
40
|
const [internalChecked, setInternalChecked] = React.useState(restProps.checked || restProps.defaultChecked);
|
|
41
41
|
const onChange = React.useCallback((event) => {
|
|
42
42
|
setInternalChecked(!internalChecked);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
onChangeCallback?.({
|
|
44
|
+
nativeEvent: event.nativeEvent,
|
|
45
|
+
preventDefault: event.preventDefault,
|
|
46
|
+
stopPropagation: event.stopPropagation,
|
|
47
|
+
target: { ...props, checked: !internalChecked },
|
|
48
|
+
});
|
|
49
|
+
}, [internalChecked, props, onChangeCallback]);
|
|
45
50
|
const checkboxProps = React.useMemo(() => ({
|
|
46
51
|
...restProps,
|
|
47
52
|
checked: internalChecked,
|
|
48
53
|
disabled,
|
|
49
54
|
id,
|
|
55
|
+
type,
|
|
56
|
+
// eslint-disable-next-line sort-keys
|
|
50
57
|
onChange,
|
|
51
|
-
}), [disabled, id, internalChecked,
|
|
58
|
+
}), [disabled, id, internalChecked, restProps, type, onChange]);
|
|
52
59
|
if (checkboxGroup && !skipGroup) {
|
|
53
60
|
checkboxProps.onChange = (...args) => {
|
|
54
61
|
onChange(...args);
|
|
@@ -69,7 +76,7 @@ exports.Checkbox = React.forwardRef((props, ref) => {
|
|
|
69
76
|
[`${controlCls}-${size}`]: block && size,
|
|
70
77
|
[`${rootCls}-wrapper`]: true,
|
|
71
78
|
[`${rootCls}-rtl`]: direction === 'rtl',
|
|
72
|
-
[`${prefixCls || config.prefixCls}-checked`]:
|
|
79
|
+
[`${prefixCls || config.prefixCls}-checked`]: checkboxProps.checked,
|
|
73
80
|
[`${prefixCls || config.prefixCls}-disabled`]: checkboxProps.disabled,
|
|
74
81
|
}, className), [
|
|
75
82
|
controlCls,
|
|
@@ -79,15 +86,15 @@ exports.Checkbox = React.forwardRef((props, ref) => {
|
|
|
79
86
|
direction,
|
|
80
87
|
prefixCls,
|
|
81
88
|
config.prefixCls,
|
|
82
|
-
|
|
89
|
+
checkboxProps.checked,
|
|
83
90
|
checkboxProps.disabled,
|
|
84
91
|
className,
|
|
85
92
|
]);
|
|
86
93
|
const checkboxClasses = React.useMemo(() => (0, classnames_1.default)(rootCls, {
|
|
87
|
-
[`${rootCls}-checked`]:
|
|
94
|
+
[`${rootCls}-checked`]: checkboxProps.checked,
|
|
88
95
|
[`${rootCls}-disabled`]: disabled,
|
|
89
96
|
[`${rootCls}-indeterminate`]: checkboxProps.indeterminate,
|
|
90
|
-
}), [rootCls,
|
|
97
|
+
}), [rootCls, checkboxProps.checked, disabled, checkboxProps.indeterminate]);
|
|
91
98
|
const globalAttributes = React.useMemo(() => (0, js_utils_1.retrieveGlobalAttributes)(restProps), [restProps]);
|
|
92
99
|
React.useEffect(() => {
|
|
93
100
|
checkboxGroup?.registerValue(restProps.value);
|
|
@@ -105,9 +112,6 @@ exports.Checkbox = React.forwardRef((props, ref) => {
|
|
|
105
112
|
return () => checkboxGroup?.cancelValue(restProps.value);
|
|
106
113
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
114
|
}, [restProps.value, skipGroup]);
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
setInternalChecked(restProps.checked || restProps.defaultChecked);
|
|
110
|
-
}, [restProps.checked, restProps.defaultChecked]);
|
|
111
115
|
return (React.createElement("label", { className: wrapperClasses, htmlFor: id, style: style, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave },
|
|
112
116
|
React.createElement("span", { className: (0, classnames_1.default)(checkboxClasses) },
|
|
113
117
|
React.createElement("input", { className: `${rootCls}-input`, ref: ref, ...checkboxProps, id: id, type: "checkbox", ...globalAttributes }),
|
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
className?: string;
|
|
7
|
-
direction?: string;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
id?: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
options?: T[];
|
|
12
|
-
prefixCls?: string;
|
|
13
|
-
size?: SizeType;
|
|
14
|
-
stack?: boolean;
|
|
15
|
-
style?: React.CSSProperties;
|
|
16
|
-
}
|
|
17
|
-
export interface CheckboxGroupConsumerProps<T = any> {
|
|
2
|
+
import { type CheckboxOptionType } from '../../../components/Control/Checkbox/Group';
|
|
3
|
+
export interface CheckboxGroupConsumer<T = any> {
|
|
4
|
+
cancelValue: (value: string) => void;
|
|
18
5
|
disabled?: boolean;
|
|
19
6
|
name?: string;
|
|
20
|
-
value?: any;
|
|
21
|
-
cancelValue: (value: string) => void;
|
|
22
7
|
registerValue: (value: string) => void;
|
|
23
|
-
toggleOption?: (option: T) => void;
|
|
8
|
+
toggleOption?: (option: CheckboxOptionType<T>) => void;
|
|
9
|
+
value?: any;
|
|
24
10
|
}
|
|
25
|
-
export declare const CheckboxGroupContext: React.Context<
|
|
26
|
-
export declare function useCheckboxGroup<T = any>():
|
|
11
|
+
export declare const CheckboxGroupContext: React.Context<CheckboxGroupConsumer<any> | null>;
|
|
12
|
+
export declare function useCheckboxGroup<T = any>(): CheckboxGroupConsumer<T> | null;
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
defaultValue?: T[];
|
|
5
|
-
value?: T[];
|
|
6
|
-
onChange?: (values: T[]) => void;
|
|
7
|
-
}
|
|
2
|
+
import { type SizeType } from '../../../components/Control';
|
|
3
|
+
import { type CheckboxChangeEvent } from '../../../components/Control/Checkbox/Checkbox';
|
|
8
4
|
export interface CheckboxOptionType<T = any> {
|
|
9
|
-
disabled?: boolean;
|
|
10
5
|
label: React.ReactNode;
|
|
11
6
|
value: T;
|
|
12
7
|
style?: React.CSSProperties;
|
|
13
|
-
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
title?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
onChange?: (e: CheckboxChangeEvent) => void;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AbstractCheckboxGroupProps<T = any> {
|
|
15
|
+
block?: boolean;
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
className?: string;
|
|
18
|
+
direction?: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
id?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
options?: (CheckboxOptionType<T> | string | number)[];
|
|
23
|
+
prefixCls?: string;
|
|
24
|
+
size?: SizeType;
|
|
25
|
+
stack?: boolean;
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
}
|
|
28
|
+
export interface CheckboxGroupProps<T = any> extends AbstractCheckboxGroupProps<T> {
|
|
29
|
+
defaultValue?: T[];
|
|
30
|
+
value?: T[];
|
|
31
|
+
onChange?: (values: T[]) => void;
|
|
14
32
|
}
|
|
15
|
-
|
|
33
|
+
type InternalCheckboxValueType = string | number | boolean;
|
|
34
|
+
export declare const Group: React.ForwardRefExoticComponent<CheckboxGroupProps<InternalCheckboxValueType> & React.RefAttributes<HTMLDivElement>>;
|
|
35
|
+
export {};
|
|
@@ -37,22 +37,19 @@ exports.Group = React.forwardRef((props, ref) => {
|
|
|
37
37
|
const { block, children, className, defaultValue, direction = config.direction, options = [], prefixCls = config.prefixCls, size, stack, style, onChange, ...restProps } = props;
|
|
38
38
|
const [value, setValue] = React.useState(restProps.value || defaultValue || []);
|
|
39
39
|
const [registeredValues, setRegisteredValues] = React.useState([]);
|
|
40
|
-
const
|
|
41
|
-
if (typeof option === 'string') {
|
|
42
|
-
return {
|
|
43
|
-
label: option,
|
|
44
|
-
value: option,
|
|
45
|
-
};
|
|
40
|
+
const memoOptions = React.useMemo(() => options.map((option) => {
|
|
41
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
42
|
+
return { label: option, value: option };
|
|
46
43
|
}
|
|
47
44
|
return option;
|
|
48
45
|
}), [options]);
|
|
49
|
-
const cancelValue =
|
|
46
|
+
const cancelValue = val => {
|
|
50
47
|
setRegisteredValues(prevValues => prevValues.filter(v => v !== val));
|
|
51
|
-
}
|
|
52
|
-
const registerValue =
|
|
48
|
+
};
|
|
49
|
+
const registerValue = val => {
|
|
53
50
|
setRegisteredValues(prevValues => [...prevValues, val]);
|
|
54
|
-
}
|
|
55
|
-
const toggleOption =
|
|
51
|
+
};
|
|
52
|
+
const toggleOption = option => {
|
|
56
53
|
const optionIndex = value.indexOf(option.value);
|
|
57
54
|
const newValue = [...value];
|
|
58
55
|
if (optionIndex === -1) {
|
|
@@ -64,28 +61,28 @@ exports.Group = React.forwardRef((props, ref) => {
|
|
|
64
61
|
if (!('value' in restProps)) {
|
|
65
62
|
setValue(newValue);
|
|
66
63
|
}
|
|
67
|
-
const opts = getOptions();
|
|
68
64
|
onChange?.(newValue
|
|
69
65
|
.filter(val => registeredValues.indexOf(val) !== -1)
|
|
70
66
|
.sort((a, b) => {
|
|
71
|
-
const indexA =
|
|
72
|
-
const indexB =
|
|
67
|
+
const indexA = memoOptions.findIndex(opt => opt.value === a);
|
|
68
|
+
const indexB = memoOptions.findIndex(opt => opt.value === b);
|
|
73
69
|
return indexA - indexB;
|
|
74
70
|
}));
|
|
75
|
-
}
|
|
71
|
+
};
|
|
76
72
|
const rootCls = React.useMemo(() => config.getRootPrefixCls(prefixCls || config.prefixCls, 'checkbox-group'), [config, prefixCls]);
|
|
77
73
|
const checkboxGroupClasses = React.useMemo(() => (0, classnames_1.default)(rootCls, {
|
|
78
74
|
[`${rootCls}-rtl`]: direction === 'rtl',
|
|
79
75
|
[`${rootCls}-stack`]: stack,
|
|
80
76
|
}, className), [className, direction, rootCls, stack]);
|
|
81
|
-
|
|
77
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
78
|
+
const context = {
|
|
82
79
|
cancelValue,
|
|
83
80
|
disabled: restProps.disabled,
|
|
84
81
|
name: restProps.name,
|
|
85
82
|
registerValue,
|
|
86
83
|
toggleOption,
|
|
87
84
|
value,
|
|
88
|
-
}
|
|
85
|
+
};
|
|
89
86
|
React.useEffect(() => {
|
|
90
87
|
if ('value' in restProps) {
|
|
91
88
|
setValue(restProps.value || []);
|
|
@@ -93,7 +90,7 @@ exports.Group = React.forwardRef((props, ref) => {
|
|
|
93
90
|
}, [restProps, restProps.value]);
|
|
94
91
|
return (React.createElement("div", { className: checkboxGroupClasses, style: style, ...restProps, ref: ref },
|
|
95
92
|
React.createElement(CheckboxGroupContext_1.CheckboxGroupContext.Provider, { value: context }, options?.length > 0
|
|
96
|
-
?
|
|
93
|
+
? memoOptions.map(option => (React.createElement(Checkbox_1.Checkbox, { key: option.value.toString(), block: block, checked: value.indexOf(option.value) > -1, direction: direction, disabled: 'disabled' in option ? option.disabled : restProps.disabled, size: size, value: option.value, className: `${rootCls}-item`, style: option.style, onChange: option.onChange }, option.label)))
|
|
97
94
|
: children)));
|
|
98
95
|
});
|
|
99
96
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import { type CheckboxProps } from '../../../components/Control/Checkbox/Checkbox';
|
|
3
|
-
import { type
|
|
4
|
-
import { type CheckboxGroupProps, type CheckboxOptionType, Group } from '../../../components/Control/Checkbox/Group';
|
|
2
|
+
import { type AbstractCheckboxProps, type CheckboxProps } from '../../../components/Control/Checkbox/Checkbox';
|
|
3
|
+
import { type CheckboxGroupConsumer } from '../../../components/Control/Checkbox/CheckboxGroupContext';
|
|
4
|
+
import { type AbstractCheckboxGroupProps, type CheckboxGroupProps, type CheckboxOptionType, Group } from '../../../components/Control/Checkbox/Group';
|
|
5
5
|
import './index.scss';
|
|
6
|
-
export type { AbstractCheckboxGroupProps,
|
|
7
|
-
export * from '../../../components/Control/Checkbox/types';
|
|
6
|
+
export type { AbstractCheckboxProps, AbstractCheckboxGroupProps, CheckboxGroupConsumer, CheckboxGroupProps, CheckboxOptionType, CheckboxProps, };
|
|
8
7
|
export interface Checkbox extends React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>> {
|
|
9
8
|
Group: typeof Group;
|
|
10
9
|
}
|
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.Checkbox = void 0;
|
|
18
4
|
const Checkbox_1 = require("../../../components/Control/Checkbox/Checkbox");
|
|
19
5
|
const Group_1 = require("../../../components/Control/Checkbox/Group");
|
|
20
6
|
require("./index.scss");
|
|
21
|
-
__exportStar(require("../../../components/Control/Checkbox/types"), exports);
|
|
22
7
|
exports.Checkbox = Checkbox_1.Checkbox;
|
|
23
8
|
exports.Checkbox.Group = Group_1.Group;
|
|
@@ -60,8 +60,8 @@ exports.Group = React.forwardRef((props, ref) => {
|
|
|
60
60
|
const renderGroup = () => {
|
|
61
61
|
let childrenToRender = children;
|
|
62
62
|
if (options && options.length > 0) {
|
|
63
|
-
childrenToRender = options.map(
|
|
64
|
-
if (typeof option === 'string') {
|
|
63
|
+
childrenToRender = options.map(option => {
|
|
64
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
65
65
|
return (React.createElement(Radio_1.Radio, { key: option, block: block, className: `${rootCls}-item`, checked: value === option, direction: direction, disabled: disabled, size: size, value: option }, option));
|
|
66
66
|
}
|
|
67
67
|
return (React.createElement(Radio_1.Radio, { key: `radio-group-value-options-${option.value}`, block: block, checked: value === option.value, className: `${rootCls}-item`, direction: direction, disabled: option.disabled || disabled, size: size, style: option.style, value: option.value }, option.label));
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type AbstractCheckboxProps } from '../../../components/Control/Checkbox';
|
|
3
|
-
export interface RadioProps extends AbstractCheckboxProps {
|
|
3
|
+
export interface RadioProps extends AbstractCheckboxProps<RadioChangeEvent> {
|
|
4
4
|
onMouseEnter?: React.MouseEventHandler<HTMLLabelElement>;
|
|
5
5
|
onMouseLeave?: React.MouseEventHandler<HTMLLabelElement>;
|
|
6
6
|
}
|
|
7
|
+
export interface RadioChangeEventTarget extends RadioProps {
|
|
8
|
+
checked: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface RadioChangeEvent {
|
|
11
|
+
target: RadioChangeEventTarget;
|
|
12
|
+
stopPropagation: VoidFunction;
|
|
13
|
+
preventDefault: VoidFunction;
|
|
14
|
+
nativeEvent: MouseEvent;
|
|
15
|
+
}
|
|
7
16
|
export declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -35,15 +35,20 @@ const RadioGroupContext_1 = require("../../../components/Control/Radio/RadioGrou
|
|
|
35
35
|
exports.Radio = React.forwardRef((props, ref) => {
|
|
36
36
|
const config = (0, ConfigProvider_1.useConfig)();
|
|
37
37
|
const radioGroup = (0, RadioGroupContext_1.useRadioGroup)();
|
|
38
|
-
const { block, size, className, children, direction = config.direction, disabled, id, prefixCls = config.prefixCls, skipGroup, style, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
38
|
+
const { block, size, className, children, direction = config.direction, disabled, id, prefixCls = config.prefixCls, skipGroup, style, onChange: onChangeCallback, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
39
39
|
const [internalChecked, setInternalChecked] = React.useState(restProps.checked
|
|
40
40
|
?? restProps.defaultChecked
|
|
41
41
|
?? ('value' in restProps && restProps.value === radioGroup?.value));
|
|
42
42
|
const onChange = React.useCallback(event => {
|
|
43
43
|
setInternalChecked(true);
|
|
44
|
-
|
|
44
|
+
onChangeCallback?.({
|
|
45
|
+
nativeEvent: event.nativeEvent,
|
|
46
|
+
preventDefault: event.preventDefault,
|
|
47
|
+
stopPropagation: event.stopPropagation,
|
|
48
|
+
target: { ...props, checked: !internalChecked },
|
|
49
|
+
});
|
|
45
50
|
radioGroup?.onChange?.(event);
|
|
46
|
-
}, [radioGroup,
|
|
51
|
+
}, [internalChecked, props, radioGroup, onChangeCallback]);
|
|
47
52
|
const radioProps = React.useMemo(() => ({
|
|
48
53
|
...restProps,
|
|
49
54
|
checked: internalChecked,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
export interface
|
|
2
|
+
export interface RadioGroupContextConsumer<T = any> {
|
|
3
3
|
disabled?: boolean;
|
|
4
4
|
name?: string;
|
|
5
5
|
value?: T;
|
|
6
6
|
onChange: (option: T) => void;
|
|
7
7
|
}
|
|
8
|
-
export declare const RadioGroupContext: React.Context<
|
|
9
|
-
export declare function useRadioGroup():
|
|
8
|
+
export declare const RadioGroupContext: React.Context<RadioGroupContextConsumer<any> | null>;
|
|
9
|
+
export declare function useRadioGroup(): RadioGroupContextConsumer | null;
|