All files / src/shared/components SelectorCardGroup.tsx

100% Statements 2/2
70% Branches 7/10
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                          228x               859x                                        
import type { ReactNode } from 'react'
 
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
import { cn } from '@/lib/utils'
 
export interface SelectorCardOption {
  value: string
  label: ReactNode
  description?: ReactNode
  media?: ReactNode
}
 
interface SelectorCardGroupProps {
  value: string | undefined
  onValueChange: (value: string) => void
  options: SelectorCardOption[]
  name?: string
  className?: string
  layout?: 'horizontal' | 'vertical'
}
 
export function SelectorCardGroup({
  value,
  onValueChange,
  options,
  name,
  className,
  layout = 'horizontal',
}: SelectorCardGroupProps) {
  return (
    <RadioGroup
      value={value}
      onValueChange={onValueChange}
      name={name}
      className={cn(layout === 'vertical' ? 'flex flex-col gap-3' : 'grid grid-cols-2 gap-3 sm:grid-cols-3', className)}
    >
      {options.map((option) => (
        <label
          key={option.value}
          className={cn(
            'has-data-checked:border-primary has-data-checked:bg-primary/5 flex cursor-pointer rounded-2xl border-2 border-border transition-all hover:border-border',
            layout === 'vertical' ? 'items-start gap-3.5 p-4' : 'items-center gap-3 p-3',
          )}
        >
          <RadioGroupItem value={option.value} className={layout === 'vertical' ? 'mt-1' : undefined} />
          {option.media}
          <span className="min-w-0 flex-1">
            <span className="block text-sm font-bold text-ink-muted">{option.label}</span>
            {layout === 'vertical' && option.description && (
              <span className="mt-0.5 block text-xs font-normal text-ink-muted">{option.description}</span>
            )}
          </span>
        </label>
      ))}
    </RadioGroup>
  )
}