2022-09-07 23:25:32 -07:00
|
|
|
import { FunctionComponent } from 'react'
|
|
|
|
|
|
|
|
interface ChartRangeButtonsProps {
|
2022-11-29 21:30:18 -08:00
|
|
|
activeValue: string
|
2022-09-07 23:25:32 -07:00
|
|
|
className?: string
|
2022-11-29 21:30:18 -08:00
|
|
|
onChange: (x: string) => void
|
|
|
|
values: Array<string>
|
2022-09-07 23:25:32 -07:00
|
|
|
names?: Array<string>
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChartRangeButtons: FunctionComponent<ChartRangeButtonsProps> = ({
|
|
|
|
activeValue,
|
|
|
|
className,
|
|
|
|
values,
|
|
|
|
onChange,
|
|
|
|
names,
|
|
|
|
}) => {
|
|
|
|
return (
|
2023-02-11 04:40:23 -08:00
|
|
|
<div className="relative flex">
|
|
|
|
{activeValue && values.includes(activeValue) ? (
|
|
|
|
<div
|
2023-04-19 18:12:45 -07:00
|
|
|
className="absolute left-0 top-0 h-full transform rounded-md bg-th-bkg-3"
|
2023-02-11 04:40:23 -08:00
|
|
|
style={{
|
|
|
|
transform: `translateX(${
|
|
|
|
values.findIndex((v) => v === activeValue) * 100
|
|
|
|
}%)`,
|
|
|
|
width: `${100 / values.length}%`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{values.map((v, i) => (
|
|
|
|
<button
|
2023-04-19 18:12:45 -07:00
|
|
|
className={`${className} relative h-6 cursor-pointer rounded-md px-3 text-center text-xs focus-visible:bg-th-bkg-3 focus-visible:text-th-fgd-1
|
2022-09-07 23:25:32 -07:00
|
|
|
${
|
|
|
|
v === activeValue
|
2022-11-30 19:32:32 -08:00
|
|
|
? `text-th-active`
|
|
|
|
: `text-th-fgd-3 md:hover:text-th-active`
|
2022-09-07 23:25:32 -07:00
|
|
|
}
|
|
|
|
`}
|
2023-02-11 04:40:23 -08:00
|
|
|
key={`${v}${i}`}
|
|
|
|
onClick={() => onChange(v)}
|
|
|
|
style={{
|
|
|
|
width: `${100 / values.length}%`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{names ? names[i] : v}
|
|
|
|
</button>
|
|
|
|
))}
|
2022-09-07 23:25:32 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChartRangeButtons
|