2024-02-01 00:58:19 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
import { RadioProps } from './radio.types';
|
2024-02-01 00:58:19 +03:00
|
|
|
import { RippleArea } from '../ripple/ripple-area';
|
2024-02-01 15:23:59 +03:00
|
|
|
import { forwardRef, useRef, useState } from 'react';
|
2024-02-01 00:58:19 +03:00
|
|
|
import useRippleEffect from '../ripple/hooks/useRippleEffect';
|
|
|
|
import { CheckBoxLayout } from '../checkbox-layout/check-box-layout';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Radio component
|
|
|
|
** description
|
|
|
|
*/
|
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
export const Radio = forwardRef<HTMLInputElement, RadioProps>(
|
|
|
|
({ centralRipple, ...props }, ref) => {
|
|
|
|
const [isActive, setIsActive] = useState<boolean>(false),
|
|
|
|
ripplesRef = useRef(null),
|
|
|
|
events = useRippleEffect(ripplesRef, setIsActive);
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
const classes =
|
|
|
|
`m3 m3-radio-label ${isActive === true ? 'visible' : ''}`.trimEnd();
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
return (
|
|
|
|
<label {...events} className={classes}>
|
|
|
|
<CheckBoxLayout {...props} ref={ref} type={'radio'} />
|
|
|
|
<span className={'m3 m3-radio-state-layer'} />
|
|
|
|
<RippleArea
|
|
|
|
callback={setIsActive}
|
|
|
|
central={centralRipple}
|
|
|
|
className={'m3-checkbox-ripple-layer'}
|
|
|
|
ref={ripplesRef}
|
|
|
|
/>
|
|
|
|
{props.children}
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|