Files
kycnotme/web/src/components/PillsRadioGroup.astro

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-05-19 10:23:36 +00:00
---
import { cn } from '../lib/cn'
import type { HTMLAttributes } from 'astro/types'
type Props = HTMLAttributes<'div'> & {
name: string
options: {
value: HTMLAttributes<'input'>['value']
label: string
}[]
2025-05-22 19:19:07 +00:00
inputProps?: Omit<HTMLAttributes<'input'>, 'checked' | 'class' | 'name' | 'type' | 'value'>
2025-05-19 10:23:36 +00:00
selectedValue?: string | null
}
2025-05-22 19:19:07 +00:00
const { name, options, selectedValue, inputProps, class: className, ...rest } = Astro.props
2025-05-19 10:23:36 +00:00
---
<div
class={cn(
2025-05-19 21:31:29 +00:00
'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',
2025-05-19 10:23:36 +00:00
className
)}
{...rest}
>
{
options.map((option) => (
<label>
<input
type="radio"
name={name}
value={option.value}
checked={selectedValue === option.value}
2025-05-19 21:31:29 +00:00
class="peer sr-only"
2025-05-22 19:19:07 +00:00
{...inputProps}
2025-05-19 10:23:36 +00:00
/>
<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>