import * as React from 'react'; import { Button, tailwind } from '@tesseract-design/web-base'; import { useFallbackId } from '@modal-sh/react-utils'; import { PluginCreator } from 'tailwindcss/types/config'; const { tw } = tailwind; const RadioButtonDerivedElementComponent = 'input' as const; /** * Derived HTML element of the {@link RadioButton} component. */ export type RadioButtonDerivedElement = HTMLElementTagNameMap[ typeof RadioButtonDerivedElementComponent ]; /** * Props of the {@link RadioButton} component. */ export interface RadioButtonProps extends Omit, 'type' | 'size'> { /** * Should the component occupy the whole width of its parent? */ block?: boolean; /** * Should the component's content use minimal space? */ compact?: boolean; /** * Size of the component. */ size?: Button.Size; /** * Complementary content of the component. */ subtext?: React.ReactNode; /** * Short complementary content displayed at the edge of the component. */ badge?: React.ReactNode; /** * Variant of the component. */ variant?: Button.Variant; } export const radioButtonPlugin: PluginCreator = ({ addComponents }) => { addComponents({ '.radio-button': { '& + label > :first-child > :first-child': { 'display': 'none', }, '&:checked + 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 regular button. */ export const RadioButton = React.forwardRef(( { children, block = false as const, compact = false as const, size = 'medium' as const, id: idProp, className, subtext, badge, variant = 'bare' as const, style, ...etcProps }, forwardedRef, ) => { const id = useFallbackId(idProp); return ( ); }); RadioButton.displayName = 'RadioButton' as const; RadioButton.defaultProps = { badge: undefined, block: false as const, compact: false as const, subtext: undefined, size: 'medium' as const, variant: 'bare' as const, };