项目文件夹

文件
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

38 行
1.0 KiB
TypeScript

import { useState } from 'react'
import './SegmentedControl.css'
interface SegmentedControlProps {
options: string[]
initial?: string
ariaLabel: string
}
export function SegmentedControl({
options,
initial,
ariaLabel,
}: SegmentedControlProps) {
const [selected, setSelected] = useState(initial ?? options[0])
return (
<div className="segmented-control" role="radiogroup" aria-label={ariaLabel}>
{options.map((option) => (
<button
key={option}
type="button"
role="radio"
aria-checked={selected === option}
className={
selected === option
? 'segmented-control__option segmented-control__option--active'
: 'segmented-control__option'
}
onClick={() => setSelected(option)}
>
{option}
</button>
))}
</div>
)
}