40 lines
871 B
TypeScript
Raw Normal View History

2022-05-29 17:53:27 +08:00
import { cx } from '@emotion/css'
2023-03-03 03:12:27 +08:00
function Tabs<T>({
2022-05-29 17:53:27 +08:00
tabs,
value,
onChange,
2022-06-09 20:16:05 +08:00
className,
2023-01-24 16:29:33 +08:00
style,
2022-05-29 17:53:27 +08:00
}: {
tabs: {
2023-03-03 03:12:27 +08:00
id: T
2022-05-29 17:53:27 +08:00
name: string
}[]
value: string
2023-03-03 03:12:27 +08:00
onChange: (id: T) => void
2022-06-09 20:16:05 +08:00
className?: string
2023-01-24 16:29:33 +08:00
style?: React.CSSProperties
2023-03-03 03:12:27 +08:00
}) {
2022-05-29 17:53:27 +08:00
return (
2023-01-24 16:29:33 +08:00
<div className={cx('no-scrollbar flex overflow-y-auto', className)} style={style}>
2022-05-29 17:53:27 +08:00
{tabs.map(tab => (
<div
2023-03-03 03:12:27 +08:00
key={tab.id as string}
2022-05-29 17:53:27 +08:00
className={cx(
2022-06-14 23:23:34 +08:00
'mr-2.5 rounded-12 py-3 px-6 text-16 font-medium backdrop-blur transition duration-500',
2022-05-29 17:53:27 +08:00
value === tab.id
? 'bg-brand-700 text-white'
2022-06-14 23:23:34 +08:00
: 'dark:bg-white/10 dark:text-white/20 hover:dark:bg-white/20 hover:dark:text-white/40'
2022-05-29 17:53:27 +08:00
)}
2022-06-08 00:07:04 +08:00
onClick={() => onChange(tab.id)}
2022-05-29 17:53:27 +08:00
>
{tab.name}
</div>
))}
</div>
)
}
export default Tabs