-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTab.tsx
45 lines (41 loc) · 1.59 KB
/
Tab.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Tab } from '@headlessui/react'
function classNames(...classes: string[]) {
return classes.filter(Boolean).join(' ')
}
export default function TabGroup(props: {items: {text: string, child: React.JSX.Element}[]}) {
return (
<>
<Tab.Group>
<Tab.List className="flex space-x-1 rounded-xl p-1">
{props.items && props.items.map((item) => (
<Tab
key={item.text}
className={({ selected }) =>
classNames(
'w-full rounded-lg py-2.5 text-sm font-medium leading-5 border focus:ring-black',
selected
? 'shadow hover:bg-gray-50'
: 'hover:bg-gray-50'
)
}
>
{item.text}
</Tab>
))}
</Tab.List>
<Tab.Panels className="mt-2">
{props.items && Object.values(props.items).map((item, idx) => (
<Tab.Panel
key={idx}
className={classNames(
'rounded-xl p-2',
)}
>
{item.child}
</Tab.Panel>
))}
</Tab.Panels>
</Tab.Group>
</>
)
}