Last active
January 16, 2022 13:21
-
-
Save lightsound/2cd22bf30f850fbb56d31a6324e51bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Tab } from "@headlessui/react"; | |
import type { VFC } from "react"; | |
import { Fragment } from "react"; | |
type Props = { | |
items: { label: string; content: JSX.Element }[]; | |
}; | |
export const HorizontalTab: VFC<Props> = (props) => { | |
return ( | |
<Tab.Group> | |
<Tab.List className="flex gap-x-1 border-b"> | |
{props.items.map((item) => { | |
return ( | |
<Tab key={item.label} as={Fragment}> | |
{({ selected }) => { | |
return ( | |
<div className={selected ? "text-red-500" : ""}> | |
{item.label} | |
</div> | |
); | |
}} | |
</Tab> | |
); | |
})} | |
</Tab.List> | |
<Tab.Panels className="mt-4"> | |
{props.items.map((item) => { | |
return ( | |
<Tab.Panel key={item.label} as={Fragment}> | |
{item.content} | |
</Tab.Panel> | |
); | |
})} | |
</Tab.Panels> | |
</Tab.Group> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment