'use client' import { cx } from 'class-variance-authority' import { useFormContext } from 'react-hook-form' import { Divider } from '../../Divider' import { MaterialIcon } from '../../Icons/MaterialIcon' import { Typography } from '../../Typography' import styles from './radioCard.module.css' import type { RadioCardProps } from './types' export default function RadioCard({ Icon, iconHeight = 32, id, name, title, subtitleSecondary, subtitle, value, disabled = false, description, descriptionSecondary, }: RadioCardProps) { const { register, setValue } = useFormContext() function onLabelClick(event: React.MouseEvent) { // Preventing click event on label elements firing twice: https://github.com/facebook/react/issues/14295 event.preventDefault() if (!disabled) { setValue(name, value) } } function onKeyDown(event: React.KeyboardEvent) { if (disabled) return if (event.key === 'Enter') { setValue(name, value) } } return ( ) }