Skip to content

Instantly share code, notes, and snippets.

@lightsound
Last active January 16, 2022 13:21
Show Gist options
  • Save lightsound/2cd22bf30f850fbb56d31a6324e51bea to your computer and use it in GitHub Desktop.
Save lightsound/2cd22bf30f850fbb56d31a6324e51bea to your computer and use it in GitHub Desktop.
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