63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import React from 'react'
|
|
import clsx from 'clsx'
|
|
|
|
export interface RadioOption {
|
|
value: string
|
|
label: string
|
|
description?: string
|
|
}
|
|
|
|
export interface RadioGroupProps {
|
|
name: string
|
|
label?: string
|
|
options: RadioOption[]
|
|
value: string
|
|
onChange: (value: string) => void
|
|
className?: string
|
|
}
|
|
|
|
export const RadioGroup: React.FC<RadioGroupProps> = ({
|
|
name,
|
|
label,
|
|
options,
|
|
value,
|
|
onChange,
|
|
className,
|
|
}) => {
|
|
return (
|
|
<div className={className}>
|
|
{label && <div className="text-sm font-medium text-slate-700 mb-2">{label}</div>}
|
|
<div className="space-y-2">
|
|
{options.map((option) => {
|
|
const checked = value === option.value
|
|
return (
|
|
<label
|
|
key={option.value}
|
|
className={clsx(
|
|
'flex items-start gap-3 rounded-xl border p-3 cursor-pointer transition-colors',
|
|
checked
|
|
? 'border-[#C95C3C] bg-orange-50/40'
|
|
: 'border-slate-200 hover:bg-slate-50'
|
|
)}
|
|
>
|
|
<input
|
|
type="radio"
|
|
name={name}
|
|
value={option.value}
|
|
checked={checked}
|
|
onChange={() => onChange(option.value)}
|
|
className="mt-0.5 h-4 w-4 border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]/30 accent-[#C95C3C]"
|
|
/>
|
|
<div className="text-sm">
|
|
<div className="font-medium text-slate-800">{option.label}</div>
|
|
{option.description && (
|
|
<div className="text-xs text-slate-500 mt-0.5">{option.description}</div>
|
|
)}
|
|
</div>
|
|
</label>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|