Files
kycnotme/web/src/components/PillsRadioGroup.astro
2025-05-22 19:19:07 +00:00

44 lines
1.2 KiB
Plaintext

---
import { cn } from '../lib/cn'
import type { HTMLAttributes } from 'astro/types'
type Props = HTMLAttributes<'div'> & {
name: string
options: {
value: HTMLAttributes<'input'>['value']
label: string
}[]
inputProps?: Omit<HTMLAttributes<'input'>, 'checked' | 'class' | 'name' | 'type' | 'value'>
selectedValue?: string | null
}
const { name, options, selectedValue, inputProps, class: className, ...rest } = Astro.props
---
<div
class={cn(
'bg-night-500 divide-night-700 has-focus-visible:ring-offset-night-700 flex divide-x-2 overflow-hidden rounded-md text-[0.6875rem] has-focus-visible:ring-2 has-focus-visible:ring-blue-500 has-focus-visible:ring-offset-2',
className
)}
{...rest}
>
{
options.map((option) => (
<label>
<input
type="radio"
name={name}
value={option.value}
checked={selectedValue === option.value}
class="peer sr-only"
{...inputProps}
/>
<span class="peer-checked:bg-night-400 inline-block cursor-pointer px-1.5 py-0.5 text-white peer-checked:text-green-500">
{option.label}
</span>
</label>
))
}
</div>