2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { AbstractCheckboxProps } from '../checkbox/Checkbox';
|
2020-05-27 10:21:17 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2022-04-08 15:23:52 +08:00
|
|
|
import { RadioOptionTypeContextProvider } from './context';
|
2023-09-12 11:40:53 +08:00
|
|
|
import type { RadioChangeEvent, RadioRef } from './interface';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Radio from './radio';
|
2015-11-06 22:03:09 +08:00
|
|
|
|
2018-03-08 20:34:40 +08:00
|
|
|
export type RadioButtonProps = AbstractCheckboxProps<RadioChangeEvent>;
|
2016-08-10 10:26:42 +08:00
|
|
|
|
2023-09-12 11:40:53 +08:00
|
|
|
const RadioButton: React.ForwardRefRenderFunction<RadioRef, RadioButtonProps> = (props, ref) => {
|
2020-05-27 10:21:17 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
2017-03-23 17:19:50 +08:00
|
|
|
|
2020-05-27 10:21:17 +08:00
|
|
|
const { prefixCls: customizePrefixCls, ...radioProps } = props;
|
2022-04-08 15:23:52 +08:00
|
|
|
const prefixCls = getPrefixCls('radio', customizePrefixCls);
|
|
|
|
|
|
|
|
return (
|
2023-09-12 11:40:53 +08:00
|
|
|
<RadioOptionTypeContextProvider value="button">
|
|
|
|
<Radio prefixCls={prefixCls} {...radioProps} type="radio" ref={ref} />
|
2022-04-08 15:23:52 +08:00
|
|
|
</RadioOptionTypeContextProvider>
|
|
|
|
);
|
2020-02-26 16:09:22 +08:00
|
|
|
};
|
2018-11-09 17:38:19 +08:00
|
|
|
|
2023-09-12 11:40:53 +08:00
|
|
|
export default React.forwardRef<RadioRef, RadioButtonProps>(RadioButton);
|