Tabs A (Radix UI)
Tabs navigation.
Preview
Trending
Trending content
Trending
Trending content
Trending
Trending content
Trending
Trending content
Trending
Trending content
Code
import * as Tabs from "@radix-ui/react-tabs"; import React from "react"; import styles from "./tabs-radixui-a.module.css"; type TabsItemType = { slug: string; title: React.ReactNode; content: React.ReactNode; icon?: React.ReactNode; }; type Props = { className?: string; tabs?: TabsItemType[]; defaultValue?: string; rounded?: "none" | "small" | "medium" | "large" | "full"; shadow?: "none" | "small" | "medium"; // Put additional variants here, then define them in the CSS variant?: "default" | "blue-outline" | "gray"; }; export default function TabsRadixuiA({ className, tabs, defaultValue, rounded, shadow = "none", variant = "default", }: Props) { return ( <Tabs.Root className={[ styles["tabs-roots"], styles[`r-${rounded}`], styles[`sh-${shadow}`], styles[`variant-${variant}`], className, ].join(" ")} defaultValue={defaultValue || (tabs && tabs[0].slug)} > <div className={styles["tabs-list-wrapper"]}> <Tabs.List className={styles["tabs-list"]} > {tabs?.map((tab) => ( <Tabs.Trigger className={styles["tabs-trigger"]} value={tab.slug} key={tab.slug} > {tab.icon && ( <div className={styles["tabs-icon"]}>{tab.icon}</div> )} <div className={styles["tabs-title"]}>{tab.title}</div> </Tabs.Trigger> ))} </Tabs.List> </div> {tabs?.map((tab) => ( <Tabs.Content className={styles["tabs-content"]} value={tab.slug} key={tab.slug} > {tab.content} </Tabs.Content> ))} </Tabs.Root> ); }
Design
Figma design file:
Documentation
Requirements
It uses Radix UI tabs (@radix-ui/react-tabs
) so, you need to install it first:
npm install @radix-ui/react-tabs
Properties
Props of the component:
-
className
(string): Specifies the CSS class of the component. -
tabs
(Array of TabsItemType): Specifies the tabs and their related content. -
defaultValue
( string): Specifies the slug of the value of the selected tab by default. -
rounded
("none" | "small" | "medium" | "large" | "full"): Specifies the border radius of the frame. -
shadow
("none" | "small" | "medium"): Specifies the shadow of the frame. -
variant
("default" | "blue-outline" | "gray" or a customized value): Specifies the color or theme variant of the component. See the "Sample CSS customization" below for an example of usage.
TabsItemType item arguments
slug
(string): Specifies the reference slug text for a tab item.title
(React.ReactNode): Specifies the title text on the trigger button.content
(React.ReactNode): Specifies the content of the tab.icon
(ReactElement): Specifies the icon element.
Sample CSS customization
/* color="blue-outline" */ .variant-blue-outline { --trigger-fg-color: #567fef; --trigger-bg-color: transparent; --trigger-active-fg-color: #567fef; --trigger-active-bg-color: transparent; } .variant-blue-outline .tabs-trigger::before { border: 2px solid var(--trigger-fg-color); }