import { ChangeEvent, forwardRef, useRef } from 'react'; import classnames from 'classnames/bind'; import { RtFrame } from '@dpa/react-frame-intro'; import { RtBaseProps, useRtBaseProps } from '@dpa/react-hoc'; import config from './styles/component-values-radio.module.css'; import styles from './styles/rt-radio.module.css'; import { RtRadioProps } from './rt-radio.types'; const cn = classnames.bind(styles); export const RtRadio = forwardRef( ( props: RtRadioProps & RtBaseProps, ref: React.ForwardedRef ) => { const { name, use, modifier, size = 'sm', width = 'min-content', height = 'min-content', isActive = false, disabled = false, isLoading = false, value, onChange, } = props; const inputRef = useRef(null); const { 'data-size-scheme': dataSizeScheme, id, ...baseProps } = useRtBaseProps(props, '0.2.2'); // TODO: status isLoading const handleChange = (event: ChangeEvent) => { const { checked: value } = event.currentTarget; if (onChange) { onChange({ event, value, name: name || '', id }); } }; const state = disabled ? 'disabled' : isLoading ? 'loading' : undefined; return ( { if (e.code === 'Space') inputRef.current?.click(); }} > { e.stopPropagation(); }} aria-label={props.ariaLabel} aria-labelledby={props.ariaLabelledBy} /> {isActive &&
} ); } ); RtRadio.displayName = 'RtRadio';