Tabs with underline #683
melvin-mendoza
started this conversation in
Ideas
Replies: 4 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
-
If someone is interested, i have modified the original tabs component to allow
Usage
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks @tinywaves for the suggestion. You can extract the code to a re-usable component. import {Tabs, TabsContent, TabsList, TabsTrigger} from "@radix-ui/react-tabs";
interface Tab {
value: string;
label: string;
content: React.ReactNode;
}
interface DynamicTabsProps {
tabs: Tab[];
defaultValue: string;
}
const DynamicTabs: React.FC<DynamicTabsProps> = ({tabs, defaultValue}) => {
return (
<Tabs defaultValue={defaultValue}>
<TabsList
className="inline-flex h-9 items-center text-muted-foreground w-full justify-start rounded-none border-b bg-transparent p-0">
{tabs.map((tab) => (
<TabsTrigger
key={tab.value}
value={tab.value}
className="inline-flex items-center justify-center whitespace-nowrap py-1 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background relative h-9 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
>
{tab.label}
</TabsTrigger>
))}
</TabsList>
{tabs.map((tab) => (
<TabsContent key={tab.value} value={tab.value}>
{tab.content}
</TabsContent>
))}
</Tabs>
);
};
export default DynamicTabs;
//Usage
export default function Page() {
const tabs = [
{value: "items", label: "Items", content: <ItemList/>},
{value: "categories", label: "Categories", content: "Item categories here"},
];
return (<DynamicTabs tabs={tabs} defaultValue="items"/>);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would be nice to have a tabs with underline component
Beta Was this translation helpful? Give feedback.
All reactions