@gechiui/components
Version:
UI components for GeChiUI.
36 lines (30 loc) • 696 B
JavaScript
/**
* External dependencies
*/
import { Radio as ReakitRadio } from 'reakit/Radio';
/**
* GeChiUI dependencies
*/
import { useContext, forwardRef } from '@gechiui/element';
/**
* Internal dependencies
*/
import Button from '../button';
import RadioContext from '../radio-context';
function Radio( { children, value, ...props }, ref ) {
const radioContext = useContext( RadioContext );
const checked = radioContext.state === value;
return (
<ReakitRadio
ref={ ref }
as={ Button }
variant={ checked ? 'primary' : 'secondary' }
value={ value }
{ ...radioContext }
{ ...props }
>
{ children || value }
</ReakitRadio>
);
}
export default forwardRef( Radio );