@broxus/react-uikit 0.13.7 → 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 +2 -2
- 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>;
|
|
@@ -6,20 +6,27 @@ import { useCheckboxGroup } from '../../../components/Control/Checkbox/CheckboxG
|
|
|
6
6
|
export const Checkbox = React.forwardRef((props, ref) => {
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
const checkboxGroup = useCheckboxGroup();
|
|
9
|
-
const { block, children, className, direction = config.direction, disabled, id, prefixCls = config.prefixCls, size, skipGroup, style, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
9
|
+
const { block, children, className, direction = config.direction, disabled, id, prefixCls = config.prefixCls, size, skipGroup, style, type = 'checkbox', onChange: onChangeCallback, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
10
10
|
const prevValue = React.useRef(restProps.value);
|
|
11
11
|
const [internalChecked, setInternalChecked] = React.useState(restProps.checked || restProps.defaultChecked);
|
|
12
12
|
const onChange = React.useCallback((event) => {
|
|
13
13
|
setInternalChecked(!internalChecked);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
onChangeCallback?.({
|
|
15
|
+
nativeEvent: event.nativeEvent,
|
|
16
|
+
preventDefault: event.preventDefault,
|
|
17
|
+
stopPropagation: event.stopPropagation,
|
|
18
|
+
target: { ...props, checked: !internalChecked },
|
|
19
|
+
});
|
|
20
|
+
}, [internalChecked, props, onChangeCallback]);
|
|
16
21
|
const checkboxProps = React.useMemo(() => ({
|
|
17
22
|
...restProps,
|
|
18
23
|
checked: internalChecked,
|
|
19
24
|
disabled,
|
|
20
25
|
id,
|
|
26
|
+
type,
|
|
27
|
+
// eslint-disable-next-line sort-keys
|
|
21
28
|
onChange,
|
|
22
|
-
}), [disabled, id, internalChecked,
|
|
29
|
+
}), [disabled, id, internalChecked, restProps, type, onChange]);
|
|
23
30
|
if (checkboxGroup && !skipGroup) {
|
|
24
31
|
checkboxProps.onChange = (...args) => {
|
|
25
32
|
onChange(...args);
|
|
@@ -40,7 +47,7 @@ export const Checkbox = React.forwardRef((props, ref) => {
|
|
|
40
47
|
[`${controlCls}-${size}`]: block && size,
|
|
41
48
|
[`${rootCls}-wrapper`]: true,
|
|
42
49
|
[`${rootCls}-rtl`]: direction === 'rtl',
|
|
43
|
-
[`${prefixCls || config.prefixCls}-checked`]:
|
|
50
|
+
[`${prefixCls || config.prefixCls}-checked`]: checkboxProps.checked,
|
|
44
51
|
[`${prefixCls || config.prefixCls}-disabled`]: checkboxProps.disabled,
|
|
45
52
|
}, className), [
|
|
46
53
|
controlCls,
|
|
@@ -50,15 +57,15 @@ export const Checkbox = React.forwardRef((props, ref) => {
|
|
|
50
57
|
direction,
|
|
51
58
|
prefixCls,
|
|
52
59
|
config.prefixCls,
|
|
53
|
-
|
|
60
|
+
checkboxProps.checked,
|
|
54
61
|
checkboxProps.disabled,
|
|
55
62
|
className,
|
|
56
63
|
]);
|
|
57
64
|
const checkboxClasses = React.useMemo(() => classNames(rootCls, {
|
|
58
|
-
[`${rootCls}-checked`]:
|
|
65
|
+
[`${rootCls}-checked`]: checkboxProps.checked,
|
|
59
66
|
[`${rootCls}-disabled`]: disabled,
|
|
60
67
|
[`${rootCls}-indeterminate`]: checkboxProps.indeterminate,
|
|
61
|
-
}), [rootCls,
|
|
68
|
+
}), [rootCls, checkboxProps.checked, disabled, checkboxProps.indeterminate]);
|
|
62
69
|
const globalAttributes = React.useMemo(() => retrieveGlobalAttributes(restProps), [restProps]);
|
|
63
70
|
React.useEffect(() => {
|
|
64
71
|
checkboxGroup?.registerValue(restProps.value);
|
|
@@ -76,9 +83,6 @@ export const Checkbox = React.forwardRef((props, ref) => {
|
|
|
76
83
|
return () => checkboxGroup?.cancelValue(restProps.value);
|
|
77
84
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
85
|
}, [restProps.value, skipGroup]);
|
|
79
|
-
React.useEffect(() => {
|
|
80
|
-
setInternalChecked(restProps.checked || restProps.defaultChecked);
|
|
81
|
-
}, [restProps.checked, restProps.defaultChecked]);
|
|
82
86
|
return (React.createElement("label", { className: wrapperClasses, htmlFor: id, style: style, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave },
|
|
83
87
|
React.createElement("span", { className: classNames(checkboxClasses) },
|
|
84
88
|
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 {};
|
|
@@ -2,28 +2,25 @@ import classNames from 'classnames';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useConfig } from '../../../components/ConfigProvider';
|
|
4
4
|
import { Checkbox } from '../../../components/Control/Checkbox/Checkbox';
|
|
5
|
-
import { CheckboxGroupContext
|
|
5
|
+
import { CheckboxGroupContext } from '../../../components/Control/Checkbox/CheckboxGroupContext';
|
|
6
6
|
export const Group = React.forwardRef((props, ref) => {
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
const { block, children, className, defaultValue, direction = config.direction, options = [], prefixCls = config.prefixCls, size, stack, style, onChange, ...restProps } = props;
|
|
9
9
|
const [value, setValue] = React.useState(restProps.value || defaultValue || []);
|
|
10
10
|
const [registeredValues, setRegisteredValues] = React.useState([]);
|
|
11
|
-
const
|
|
12
|
-
if (typeof option === 'string') {
|
|
13
|
-
return {
|
|
14
|
-
label: option,
|
|
15
|
-
value: option,
|
|
16
|
-
};
|
|
11
|
+
const memoOptions = React.useMemo(() => options.map((option) => {
|
|
12
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
13
|
+
return { label: option, value: option };
|
|
17
14
|
}
|
|
18
15
|
return option;
|
|
19
16
|
}), [options]);
|
|
20
|
-
const cancelValue =
|
|
17
|
+
const cancelValue = val => {
|
|
21
18
|
setRegisteredValues(prevValues => prevValues.filter(v => v !== val));
|
|
22
|
-
}
|
|
23
|
-
const registerValue =
|
|
19
|
+
};
|
|
20
|
+
const registerValue = val => {
|
|
24
21
|
setRegisteredValues(prevValues => [...prevValues, val]);
|
|
25
|
-
}
|
|
26
|
-
const toggleOption =
|
|
22
|
+
};
|
|
23
|
+
const toggleOption = option => {
|
|
27
24
|
const optionIndex = value.indexOf(option.value);
|
|
28
25
|
const newValue = [...value];
|
|
29
26
|
if (optionIndex === -1) {
|
|
@@ -35,28 +32,28 @@ export const Group = React.forwardRef((props, ref) => {
|
|
|
35
32
|
if (!('value' in restProps)) {
|
|
36
33
|
setValue(newValue);
|
|
37
34
|
}
|
|
38
|
-
const opts = getOptions();
|
|
39
35
|
onChange?.(newValue
|
|
40
36
|
.filter(val => registeredValues.indexOf(val) !== -1)
|
|
41
37
|
.sort((a, b) => {
|
|
42
|
-
const indexA =
|
|
43
|
-
const indexB =
|
|
38
|
+
const indexA = memoOptions.findIndex(opt => opt.value === a);
|
|
39
|
+
const indexB = memoOptions.findIndex(opt => opt.value === b);
|
|
44
40
|
return indexA - indexB;
|
|
45
41
|
}));
|
|
46
|
-
}
|
|
42
|
+
};
|
|
47
43
|
const rootCls = React.useMemo(() => config.getRootPrefixCls(prefixCls || config.prefixCls, 'checkbox-group'), [config, prefixCls]);
|
|
48
44
|
const checkboxGroupClasses = React.useMemo(() => classNames(rootCls, {
|
|
49
45
|
[`${rootCls}-rtl`]: direction === 'rtl',
|
|
50
46
|
[`${rootCls}-stack`]: stack,
|
|
51
47
|
}, className), [className, direction, rootCls, stack]);
|
|
52
|
-
|
|
48
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
49
|
+
const context = {
|
|
53
50
|
cancelValue,
|
|
54
51
|
disabled: restProps.disabled,
|
|
55
52
|
name: restProps.name,
|
|
56
53
|
registerValue,
|
|
57
54
|
toggleOption,
|
|
58
55
|
value,
|
|
59
|
-
}
|
|
56
|
+
};
|
|
60
57
|
React.useEffect(() => {
|
|
61
58
|
if ('value' in restProps) {
|
|
62
59
|
setValue(restProps.value || []);
|
|
@@ -64,7 +61,7 @@ export const Group = React.forwardRef((props, ref) => {
|
|
|
64
61
|
}, [restProps, restProps.value]);
|
|
65
62
|
return (React.createElement("div", { className: checkboxGroupClasses, style: style, ...restProps, ref: ref },
|
|
66
63
|
React.createElement(CheckboxGroupContext.Provider, { value: context }, options?.length > 0
|
|
67
|
-
?
|
|
64
|
+
? memoOptions.map(option => (React.createElement(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)))
|
|
68
65
|
: children)));
|
|
69
66
|
});
|
|
70
67
|
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,6 +1,5 @@
|
|
|
1
|
-
import { Checkbox as InternalCheckbox } from '../../../components/Control/Checkbox/Checkbox';
|
|
2
|
-
import { Group } from '../../../components/Control/Checkbox/Group';
|
|
1
|
+
import { Checkbox as InternalCheckbox, } from '../../../components/Control/Checkbox/Checkbox';
|
|
2
|
+
import { Group, } from '../../../components/Control/Checkbox/Group';
|
|
3
3
|
import './index.scss';
|
|
4
|
-
export * from '../../../components/Control/Checkbox/types';
|
|
5
4
|
export const Checkbox = InternalCheckbox;
|
|
6
5
|
Checkbox.Group = Group;
|
|
@@ -31,8 +31,8 @@ export const Group = React.forwardRef((props, ref) => {
|
|
|
31
31
|
const renderGroup = () => {
|
|
32
32
|
let childrenToRender = children;
|
|
33
33
|
if (options && options.length > 0) {
|
|
34
|
-
childrenToRender = options.map(
|
|
35
|
-
if (typeof option === 'string') {
|
|
34
|
+
childrenToRender = options.map(option => {
|
|
35
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
36
36
|
return (React.createElement(Radio, { key: option, block: block, className: `${rootCls}-item`, checked: value === option, direction: direction, disabled: disabled, size: size, value: option }, option));
|
|
37
37
|
}
|
|
38
38
|
return (React.createElement(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>>;
|
|
@@ -6,15 +6,20 @@ import { useRadioGroup } from '../../../components/Control/Radio/RadioGroupConte
|
|
|
6
6
|
export const Radio = React.forwardRef((props, ref) => {
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
const radioGroup = useRadioGroup();
|
|
9
|
-
const { block, size, className, children, direction = config.direction, disabled, id, prefixCls = config.prefixCls, skipGroup, style, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
9
|
+
const { block, size, className, children, direction = config.direction, disabled, id, prefixCls = config.prefixCls, skipGroup, style, onChange: onChangeCallback, onMouseEnter, onMouseLeave, ...restProps } = props;
|
|
10
10
|
const [internalChecked, setInternalChecked] = React.useState(restProps.checked
|
|
11
11
|
?? restProps.defaultChecked
|
|
12
12
|
?? ('value' in restProps && restProps.value === radioGroup?.value));
|
|
13
13
|
const onChange = React.useCallback(event => {
|
|
14
14
|
setInternalChecked(true);
|
|
15
|
-
|
|
15
|
+
onChangeCallback?.({
|
|
16
|
+
nativeEvent: event.nativeEvent,
|
|
17
|
+
preventDefault: event.preventDefault,
|
|
18
|
+
stopPropagation: event.stopPropagation,
|
|
19
|
+
target: { ...props, checked: !internalChecked },
|
|
20
|
+
});
|
|
16
21
|
radioGroup?.onChange?.(event);
|
|
17
|
-
}, [radioGroup,
|
|
22
|
+
}, [internalChecked, props, radioGroup, onChangeCallback]);
|
|
18
23
|
const radioProps = React.useMemo(() => ({
|
|
19
24
|
...restProps,
|
|
20
25
|
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;
|