Tabs C (Radix UI)

Tabs navigation.

Preview

Code

import * as Tabs from "@radix-ui/react-tabs"; import React from "react"; import styles from "./tabs-radixui-c.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" ; shadow?: "none" | "small" | "medium"; // Put additional variants here, then define them in the CSS variant?: "default" | "style-b"; }; export default function TabsRadixuiC({ 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="style-b" */ .variant-style-b .tabs-trigger::before { background: linear-gradient(to bottom, #DEDEDE, #FFFFFF); box-shadow: inset 0px 2px 2px rgba(0, 0, 0, 0.17); }