import type { ReactNode } from "react"; import { tv } from "../../core/tv"; import { PressableBox } from "../actions/PressableBox"; import { DefaultAccentScope } from "../containers/DefaultAccentScope"; import { Icon, type SVGIconElement } from "../primitives/Icon"; import { Text } from "../primitives/Text"; import { View } from "../primitives/View"; import { CheckboxIndicator } from "../selection/CheckboxIndicator"; import { SelectionAccentScope } from "../selection/SelectionAccentScope"; import { useCheckboxCardGroupAppearance } from "./CheckboxCardGroup"; import { useCheckboxContext } from "./CheckboxContext"; // Same material as RadioCard: every card is the group's PressableBox variant, // a checked card keeps the accent and an unchecked one takes the neutral theme. const checkboxCardVariants = tv({ slots: { frame: "flex-row gap-m rounded-sm p-m min-h-control-md", icon: "", label: "font-body-bold text-base", description: "text-sm", }, variants: { layout: { list: { frame: "items-center" }, stack: { frame: "items-start grow shrink basis-[240px]" }, }, variant: { tonal: {}, outlined: {} }, selected: { true: {}, false: {} }, disabled: { true: { icon: "text-disabled-muted", label: "text-disabled-sharp", description: "text-disabled-muted", }, false: {}, }, }, // Same as RadioCard: the material's inks are enabled-only, so a disabled // checked card does not keep the accent's; `muted` is too dim for a checked // tonal card's accented ground. compoundVariants: [ { variant: "tonal", disabled: false, class: { icon: "text-on-tonal", label: "text-on-tonal" }, }, { variant: "tonal", selected: true, disabled: false, class: { description: "text-on-tonal" }, }, { variant: "tonal", selected: false, disabled: false, class: { description: "text-muted" }, }, { variant: "outlined", disabled: false, class: { icon: "text-muted", label: "text-sharp", description: "text-muted", }, }, ], }); export interface CheckboxCardProps { value: string; label: string; description?: string; icon?: SVGIconElement; disabled?: boolean; className?: string; } export function CheckboxCard({ value, label, description, icon, disabled, className, }: CheckboxCardProps): ReactNode { const { values, onToggle, disabled: groupDisabled } = useCheckboxContext(); const { layout, variant } = useCheckboxCardGroupAppearance(); const selected = values.includes(value); const isDisabled = disabled === true || groupDisabled === true; const styles = checkboxCardVariants({ layout, variant, selected, disabled: isDisabled, }); return ( { onToggle(value); }} > {icon ? ( ) : null} {label} {description ? ( {description} ) : null} ); }