Files

32 lines
809 B
TypeScript

import type { ReactNode } from 'react'
import { cx } from './cx'
export function Segmented({
value,
onChange,
options,
}: {
value: string
onChange: (v: string) => void
options: Array<{ value: string; label: ReactNode }>
}) {
return (
<div className="inline-flex p-0.5 rounded-[10px] bg-rule-2">
{options.map(o => (
<button
key={o.value}
type="button"
aria-pressed={o.value === value}
onClick={() => onChange(o.value)}
className={cx(
'inline-flex items-center gap-1.5 px-2.5 py-[5px] rounded-md text-[13px] cursor-pointer whitespace-nowrap',
o.value === value ? 'bg-surface font-semibold shadow-sm' : 'text-ink-3',
)}
>
{o.label}
</button>
))}
</div>
)
}