import * as React from 'react'; import clsx from 'clsx'; import plugin from 'tailwindcss/plugin'; import { useFallbackId } from '@modal-sh/react-utils'; /** * Derived HTML element of the {@link RadioTickBox} component. */ export type RadioTickBoxDerivedElement = HTMLInputElement; /** * Props of the {@link RadioTickBox} component. */ export interface RadioTickBoxProps extends Omit, 'type' | 'size'> { /** * Should the component occupy the whole width of its parent? */ block?: boolean; /** * Complementary content of the component. */ subtext?: React.ReactNode; } export const radioTickBoxPlugin = plugin(({ addComponents }) => { addComponents({ '.radio-tick-box': { '& + label + label > :first-child > :first-child': { 'display': 'none', }, '&:checked + label + label > :first-child > :first-child': { 'display': 'block', }, }, }); }); /** * Component for selecting a single value from an array of choices grouped by name. * * This component is displayed as a tick box, i.e. a typical radio button. */ export const RadioTickBox = React.forwardRef(( { children, block = false as const, id: idProp, className, subtext, style, ...etcProps }, forwardedRef, ) => { const id = useFallbackId(idProp); return (
{subtext && (
{subtext}
)}
); }); RadioTickBox.displayName = 'RadioTickBox' as const; RadioTickBox.defaultProps = { block: false as const, subtext: undefined, };