<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ shadcn - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ shadcn - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 09 Jun 2026 10:25:23 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/shadcn/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Admin Dashboard Sidebar with shadcn/ui and Base UI ]]>
                </title>
                <description>
                    <![CDATA[ Admin dashboards are one of the most common real-world UI components you will build as a React developer. At the heart of nearly every dashboard is a sidebar, a persistent navigation panel that organi ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-an-admin-dashboard-sidebar-with-shadcn-ui-and-base-ui/</link>
                <guid isPermaLink="false">69de6a6491716f3cfb542305</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ UI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ baseui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Vaibhav Gupta ]]>
                </dc:creator>
                <pubDate>Tue, 14 Apr 2026 16:25:08 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/3ce152b1-9a34-4c72-85f0-cabf7d4f3460.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Admin dashboards are one of the most common real-world UI components you will build as a React developer. At the heart of nearly every dashboard is a sidebar, a persistent navigation panel that organizes pages, tools, and features into a clean, scannable structure.</p>
<p>Building a sidebar from scratch involves much more than an <code>&lt;nav&gt;</code> element. You need collapsible submenus, active state tracking across parent and child items, accessible keyboard navigation, a scroll area for long nav lists, and a consistent design system that holds together across screen sizes.</p>
<p>In this tutorial, you'll learn how to build a fully functional, accessible admin dashboard sidebar using shadcn/ui, a collection of beautifully designed, accessible React components, and a pre-built community block from Shadcn Space, which extends shadcn/ui with ready-to-use dashboard UI patterns.</p>
<p>By the end of this tutorial, you'll have a working sidebar that includes:</p>
<ul>
<li><p>Grouped navigation sections with uppercase labels</p>
</li>
<li><p>Collapsible parent menu items with child links</p>
</li>
<li><p>Active state tracking across both parent and child items</p>
</li>
<li><p>A floating sidebar with an independent scroll area</p>
</li>
<li><p>A promotional card pinned inside the sidebar footer</p>
</li>
</ul>
<h2 id="heading-table-of-contents"><strong>Table of Contents</strong></h2>
<ul>
<li><p><a href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-what-you-will-build">What You Will Build</a></p>
</li>
<li><p><a href="#heading-why-shadcnui">Why shadcn/ui?</a></p>
</li>
<li><p><a href="#heading-what-is-shadcn-space">What is Shadcn Space?</a></p>
</li>
<li><p><a href="#heading-how-to-install-the-sidebar-block">How to Install the Sidebar Block</a></p>
</li>
<li><p><a href="#heading-how-to-understand-the-folder-structure">How to Understand the Folder Structure</a></p>
</li>
<li><p><a href="#heading-how-to-build-the-page-layout">How to Build the Page Layout</a></p>
</li>
<li><p><a href="#heading-how-to-build-the-appsidebar-component">How to Build the AppSidebar Component</a></p>
</li>
<li><p><a href="#heading-how-to-define-the-navigation-data">How to Define the Navigation Data</a></p>
</li>
<li><p><a href="#heading-how-to-build-the-navmain-component">How to Build the NavMain Component</a></p>
</li>
<li><p><a href="#heading-how-to-handle-active-states-and-collapsible-menus">How to Handle Active States and Collapsible Menus</a></p>
</li>
<li><p><a href="#heading-how-to-style-the-sidebar">How to Style the Sidebar</a></p>
</li>
<li><p><a href="#heading-live-preview">Live Preview</a></p>
</li>
<li><p><a href="#heading-summary">Summary</a></p>
</li>
</ul>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<p>Before you start, make sure you have the following:</p>
<ul>
<li><p>Node.js 18+ installed on your machine</p>
</li>
<li><p>Basic knowledge of React and TypeScript</p>
</li>
<li><p>Familiarity with Tailwind CSS utility classes</p>
</li>
<li><p>A package manager installed (npm, pnpm, yarn, or bun)</p>
</li>
</ul>
<p>You don't need prior experience with shadcn/ui, but it helps to have read through <a href="https://ui.shadcn.com/docs">the official docs</a> at least once.</p>
<h2 id="heading-what-you-will-build"><strong>What You Will Build</strong></h2>
<p>In this article, you'll build a fully functional admin dashboard sidebar with the following features:</p>
<ol>
<li><p><strong>Floating sidebar shell</strong>: a card-style sidebar with rounded corners, a drop shadow, and a configurable width</p>
</li>
<li><p><strong>Grouped navigation</strong>: navigation items organized under section labels like Dashboards, Pages, Apps, and Form Elements</p>
</li>
<li><p><strong>Collapsible submenus</strong>: parent items like Blogs and Shadcn Forms that expand on click to reveal child links</p>
</li>
<li><p><strong>Active state tracking</strong>: visual highlighting of the selected parent and child item at all times</p>
</li>
<li><p><strong>Sidebar toggle</strong>: a trigger button in the page header that opens and closes the sidebar</p>
</li>
<li><p><strong>Promotional card</strong>: a "Get Premium" card at the bottom of the sidebar scroll area</p>
</li>
</ol>
<h2 id="heading-why-shadcnui"><strong>Why shadcn/ui?</strong></h2>
<p><a href="https://ui.shadcn.com/"><strong>shadcn/ui</strong></a> is a collection of beautifully designed, accessible React components built on top of Radix UI and styled with Tailwind CSS.</p>
<p>Instead of installing a traditional component library as a dependency, you copy components directly into your project using a CLI. This gives you full ownership of the code structure and styling. You can read every line, change anything, and the components never break because of a library update you didn't control.</p>
<p>Some key benefits of shadcn/ui include:</p>
<ul>
<li><p>Accessible by default, built on Radix and Base UI primitives</p>
</li>
<li><p>Fully styled with Tailwind CSS utility classes</p>
</li>
<li><p>Zero lock-in: the code lives in your project, not inside <code>node_modules</code></p>
</li>
<li><p>Works with Next.js, React, Astro, Vite, and other frameworks</p>
</li>
<li><p>A growing ecosystem of community-built blocks and registries</p>
</li>
</ul>
<p>The <code>Sidebar, Collapsible, ScrollArea, Card, and Button</code> Components you'll use in this tutorial all come from shadcn/ui.</p>
<h2 id="heading-what-is-shadcn-space"><strong>What is Shadcn Space?</strong></h2>
<p><strong>Shadcn Space</strong> is an open-source library of pre-built <a href="https://shadcnspace.com/blocks"><strong>UI blocks</strong></a> built on top of shadcn/ui. It provides ready-to-use dashboard layouts, sidebars, tables, cards, and other common admin UI patterns so you don't have to assemble them from individual primitives every time.</p>
<p>Each block in Shadcn Space is installable directly into your project using the shadcn CLI. Once installed, the code is yours: you can read it, extend it, and adapt it to your design system without any runtime dependency on Shadcn Space itself.</p>
<p>For this tutorial, you'll use the <code>sidebar-06</code> block (it’s free to use), which is a floating admin sidebar with grouped navigation, collapsible submenus, and an integrated scroll area.</p>
<p>Shadcn Space also provides a companion <a href="https://www.figma.com/community/file/1597967874273587400/shadcn-space-figma-ui-kit"><strong>Figma UI Kit</strong></a> that matches the design system used in the blocks, which is useful if you do design work alongside development.</p>
<p>You can explore the full block library and the getting-started documentation in the <a href="https://shadcnspace.com/docs/getting-started/blocks"><strong>official Shadcn Space docs</strong></a>.</p>
<h3 id="heading-how-to-set-up-the-project">How to Set Up the Project</h3>
<p>Start by creating a new Next.js project if you don't already have one:</p>
<pre><code class="language-javascript">npx shadcn@latest init --preset b0 --base base --template next
</code></pre>
<p>This command:</p>
<ul>
<li><p>Creates a Next.js project</p>
</li>
<li><p>Configures Tailwind CSS</p>
</li>
<li><p>Sets up Base UI as the component foundation</p>
</li>
<li><p>Uses Nova style preset</p>
</li>
<li><p>Configures Lucide icons</p>
</li>
<li><p>Uses Inter font</p>
</li>
<li><p>Applies neutral theme tokens</p>
</li>
</ul>
<p>Follow the prompts to configure your base color, CSS variables, and component output directory. This sets up the <code>components/ui</code> directory and the required Tailwind configuration that all shadcn/ui components depend on.</p>
<p>Once the initialization is complete, your <code>components.json</code> project will be created at the root of your project. This file tells the shadcn CLI where to place components, what path aliases you're using, and which styling configuration to follow.</p>
<p>Add this in <code>components.json</code>:</p>
<pre><code class="language-javascript">{
  "registries": {
    "@shadcn-space": {
      "url": "https://shadcnspace.com/r/{name}.json",
    }
  }
}
</code></pre>
<h2 id="heading-how-to-install-the-sidebar-block"><strong>How to Install the Sidebar Block</strong></h2>
<p>With shadcn/ui initialized, you can now pull in the <code>sidebar-06</code> block from Shadcn Space. While Shadcn Space provides components for both Radix UI and Base UI, this tutorial uses the Base UI version. Run one of the following commands depending on your package manager:</p>
<p><strong>npm:</strong></p>
<pre><code class="language-javascript">npx shadcn@latest add @shadcn-space/sidebar-06
</code></pre>
<p><strong>pnpm:</strong></p>
<pre><code class="language-javascript">pnpm dlx shadcn@latest add @shadcn-space/sidebar-06
</code></pre>
<p><strong>yarn:</strong></p>
<pre><code class="language-javascript">yarn dlx shadcn@latest add @shadcn-space/sidebar-06
</code></pre>
<p><strong>bun:</strong></p>
<pre><code class="language-javascript">bunx --bun shadcn@latest add @shadcn-space/sidebar-06
</code></pre>
<p>This command fetches the block from the Shadcn Space registry and scaffolds all the required component files into your project automatically. It also installs any shadcn/ui primitives the block depends on (such as <code>Sidebar, ScrollArea, Card, Button,</code> and <code>Collapsible</code>) if they aren't already present in your components/ui directory.</p>
<p>You can preview the live block and find the installation command on their <a href="https://shadcnspace.com/blocks/dashboard-ui/sidebars"><strong>shadcn sidebar</strong></a> page.</p>
<h2 id="heading-how-to-understand-the-folder-structure"><strong>How to Understand the Folder Structure</strong></h2>
<p>After installation, your project will contain the following new files:</p>
<pre><code class="language-javascript">app/
  sidebar-06/
    page.tsx                  ← Route entry point
assets/
  logo/
    logo.tsx                  ← Logo component
components/
  shadcn-space/
    blocks/
      sidebar-06/
        app-sidebar.tsx       ← Main sidebar shell
        nav-main.tsx          ← Navigation logic and rendering
</code></pre>
<p>Each file has a clearly defined responsibility:</p>
<ul>
<li><p><code>app/sidebar-06/page.tsx</code>: the route entry point that wires the sidebar into a page layout using SidebarProvider</p>
</li>
<li><p><code>assets/logo/logo.tsx</code>: the logo component rendered in the sidebar header</p>
</li>
<li><p><code>components/shadcn-space/blocks/sidebar-06/app-sidebar.tsx</code>: the main sidebar shell, including the header, scroll area, nav data, and promotional card</p>
</li>
<li><p><code>components/shadcn-space/blocks/sidebar-06/nav-main.tsx</code>: all navigation rendering logic, including section labels, leaf items, collapsible parents, and active state management</p>
</li>
</ul>
<p>You'll work through each of these files in detail in the sections below.</p>
<h2 id="heading-how-to-build-the-page-layout"><strong>How to Build the Page Layout</strong></h2>
<p>Open <code>app/sidebar-06/page.tsx</code>. This file is the entry point for your dashboard page. It uses <code>SidebarProvider</code> to establish sidebar context across the page, and <code>SidebarTrigger</code> to render a toggle button inside the header.</p>
<pre><code class="language-javascript">import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import { AppSidebar } from "@/components/shadcn-space/blocks/sidebar-06/app-sidebar";

const Page = () =&gt; {
  return (
    &lt;SidebarProvider
      className="p-4 bg-muted"
      style={{ "--sidebar-width": "300px" } as React.CSSProperties}
    &gt;
      &lt;AppSidebar /&gt;

      {/* Main content area */}
      &lt;div className="flex flex-1 flex-col gap-4"&gt;
        &lt;header className="flex h-14 shrink-0 items-center gap-2 rounded-xl bg-background px-4 shadow-sm"&gt;
          &lt;SidebarTrigger className="cursor-pointer" /&gt;
        &lt;/header&gt;
        &lt;main className="flex-1 rounded-xl bg-background" /&gt;
      &lt;/div&gt;
    &lt;/SidebarProvider&gt;
  );
};

export default Page;
</code></pre>
<p>Let's break down the key parts of this layout:</p>
<p><strong>SidebarProvider</strong> wraps everything on the page. It manages the sidebar's open/closed state and passes it down to child components via React context. Any component that needs to read or change the sidebar state, including <code>SidebarTrigger</code> and <code>AppSidebar</code>, must be a descendant of <code>SidebarProvider</code>.</p>
<p><strong>The</strong> <code>--sidebar-width</code> <strong>CSS custom property</strong> controls the rendered width of the sidebar. It's set inline using a type assertion (<code>as React.CSSProperties</code>) because TypeScript doesn't know about this custom property by default. Setting it here rather than in a CSS file keeps the width configurable on a per-page basis.</p>
<p><code>SidebarTrigger</code> is a toggle button component that reads the sidebar open/closed state from the nearest <code>SidebarProvider</code> context and flips it on click. It renders in the header so users always have access to the toggle regardless of scroll position.</p>
<p><code>bg-muted</code> on <code>SidebarProvider</code> creates the light gray outer background that makes the floating sidebar card visually stand out from the page.</p>
<h2 id="heading-how-to-build-the-appsidebar-component"><strong>How to Build the AppSidebar Component</strong></h2>
<p>Open <code>components/shadcn-space/blocks/sidebar-06/app-sidebar.tsx</code>. This component is the main sidebar shell. It composes shadcn/ui's <code>Sidebar</code>, <code>SidebarHeader</code>, and <code>SidebarContent</code> layout primitives and wraps the scrollable navigation area in a <code>ScrollArea</code> component to handle overflow independently.</p>
<pre><code class="language-javascript">"use client";

import {
  Sidebar,
  SidebarContent,
  SidebarHeader,
  SidebarMenu,
  SidebarMenuItem,
} from "@/components/ui/sidebar";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import Logo from "@/assets/logo/logo";
import { NavItem, NavMain } from "@/components/shadcn-space/blocks/sidebar-06/nav-main";
import {
  AlignStartVertical,
  PieChart,
  CircleUserRound,
  ClipboardList,
  Notebook,
  NotepadText,
  Table,
  Languages,
  Ticket,
} from "lucide-react";
</code></pre>
<p>The <code>"use client"</code> directive at the top is required because this component uses React state (through <code>NavMain</code>) and event handlers, both of which require the component to run in the browser rather than being server-rendered by Next.js.</p>
<h2 id="heading-how-to-define-the-navigation-data"><strong>How to Define the Navigation Data</strong></h2>
<p>Inside <code>app-sidebar.tsx</code>the navigation structure is defined as a flat array of <code>NavItem</code> objects. Each item belongs to one of three categories:</p>
<ol>
<li><p><strong>A section label</strong> marked with <code>isSection: true</code> and a <code>label</code> string. Renders as an uppercase group heading.</p>
</li>
<li><p><strong>A leaf item</strong> has a <code>title, icon</code>, and <code>href</code>, but no <code>children</code>. Renders as a direct navigation link.</p>
</li>
<li><p><strong>A parent item</strong> has a <code>title, icon</code>, and a <code>children</code> array of sub-items. Renders as a collapsible trigger.</p>
</li>
</ol>
<pre><code class="language-javascript">
export const navData: NavItem[] = [
  // Dashboards Section
  { label: "Dashboards", isSection: true },
  { title: "Analytics", icon: PieChart, href: "#" },
  { title: "CRM Dashboard", icon: ClipboardList, href: "#" },

  // Pages Section
  { label: "Pages", isSection: true },
  { title: "Tables", icon: Table, href: "#" },
  { title: "Forms", icon: ClipboardList, href: "#" },
  { title: "User Profile", icon: CircleUserRound, href: "#" },

  // Apps Section
  { label: "Apps", isSection: true },
  { title: "Notes", icon: Notebook, href: "#" },
  { title: "Tickets", icon: Ticket, href: "#" },
  {
    title: "Blogs",
    icon: Languages,
    children: [
      { title: "Blog Post", href: "#" },
      { title: "Blog Detail", href: "#" },
      { title: "Blog Edit", href: "#" },
      { title: "Blog Create", href: "#" },
      { title: "Manage Blogs", href: "#" },
    ],
  },

  // Form Elements Section
  { label: "Form Elements", isSection: true },
  {
    title: "Shadcn Forms",
    icon: NotepadText,
    children: [
      { title: "Button", href: "#" },
      { title: "Input", href: "#" },
      { title: "Select", href: "#" },
      { title: "Checkbox", href: "#" },
      { title: "Radio", href: "#" },
    ],
  },
  {
    title: "Form layouts",
    icon: AlignStartVertical,
    children: [
      { title: "Forms Horizontal", href: "#" },
      { title: "Forms Vertical", href: "#" },
      { title: "Forms Validation", href: "#" },
      { title: "Forms Examples", href: "#" },
      { title: "Forms Wizard", href: "#" },
    ],
  },
];
</code></pre>
<p>This flat array approach is intentionally simple to maintain. You don't need a nested tree structure because the <code>NavMain</code> component handles the rendering logic for each item type by inspecting each item's shape. Adding a new section, item, or submenu is as straightforward as appending a new object to the array.</p>
<h2 id="heading-how-to-build-the-navmain-component"><strong>How to Build the NavMain Component</strong></h2>
<p>Open <code>components/shadcn-space/blocks/sidebar-06/nav-main.tsx</code>. This file contains all the navigation rendering logic. Start with the type definition and the top-level <code>NavMain</code> function:</p>
<pre><code class="language-javascript">"use client";

import * as React from "react";
import { ChevronRight, LucideIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import {
  Collapsible,
  CollapsibleTrigger,
  CollapsibleContent,
} from "@/components/ui/collapsible";
import {
  SidebarGroup,
  SidebarGroupLabel,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSub,
  SidebarMenuSubItem,
  SidebarMenuSubButton,
} from "@/components/ui/sidebar";

export type NavItem = {
  label?: string;
  isSection?: boolean;
  title?: string;
  icon?: LucideIcon;
  href?: string;
  children?: NavItem[];
};

export function NavMain({ items }: { items: NavItem[] }) {
  const [activeParent, setActiveParent] = React.useState&lt;string | null&gt;(
    items.find((i) =&gt; !i.isSection)?.title || null
  );
  const [activeChild, setActiveChild] = React.useState&lt;string | null&gt;(null);

  return (
    &lt;&gt;
      {items.map((item, index) =&gt; (
        &lt;NavMainItem
          key={item.title || item.label || index}
          item={item}
          activeParent={activeParent}
          setActiveParent={setActiveParent}
          activeChild={activeChild}
          setActiveChild={setActiveChild}
        /&gt;
      ))}
    &lt;/&gt;
  );
}
</code></pre>
<p><code>activeParent</code> tracks which top-level nav item is currently selected. It initializes to the title of the first non-section item, so the sidebar always has a selection on first render, and you never show the sidebar with nothing highlighted. <code>activeChild</code> tracks which sub-item inside a collapsible menu is selected.</p>
<p>Both state values are passed down as props to each <code>NavMainItem</code>, so every item in the list can read the current selection and trigger updates to it.</p>
<h2 id="heading-how-to-handle-active-states-and-collapsible-menus"><strong>How to Handle Active States and Collapsible Menus</strong></h2>
<p>The <code>NavMainItem</code> function branches into one of three rendering paths based on the shape of the incoming item.</p>
<h3 id="heading-how-to-render-section-labels">How to Render Section Labels</h3>
<pre><code class="language-javascript">if (item.isSection &amp;&amp; item.label) {
  return (
    &lt;SidebarGroup className="p-0 pt-5 first:pt-0"&gt;
      &lt;SidebarGroupLabel className="p-0 text-xs font-medium uppercase text-sidebar-foreground"&gt;
        {item.label}
      &lt;/SidebarGroupLabel&gt;
    &lt;/SidebarGroup&gt;
  );
}
</code></pre>
<p>Section labels use <code>first:pt-0</code> to remove the top padding from the very first section, so the nav starts flush with the header.</p>
<h3 id="heading-how-to-render-collapsible-parent-items">How to Render Collapsible Parent Items</h3>
<pre><code class="language-javascript">if (hasChildren &amp;&amp; item.title) {
  return (
    &lt;SidebarGroup className="p-0"&gt;
      &lt;SidebarMenu&gt;
        &lt;Collapsible open={isOpen} onOpenChange={setIsOpen}&gt;
          &lt;SidebarMenuItem&gt;
            &lt;CollapsibleTrigger
              className="w-full"
              render={
                &lt;SidebarMenuButton
                  id={`nav-main-trigger-${item.title.toLowerCase().replace(/\s+/g, '-')}`}
                  tooltip={item.title}
                  isActive={isParentActive}
                  onClick={() =&gt; setActiveParent(item.title!)}
                  className={cn(
                    "rounded-md text-sm font-medium px-3 py-2 h-9 transition-colors cursor-pointer",
                    isParentActive ? "bg-primary! text-primary-foreground!" : ""
                  )}
                &gt;
                  {item.icon &amp;&amp; &lt;item.icon size={16} /&gt;}
                  &lt;span&gt;{item.title}&lt;/span&gt;
                  &lt;ChevronRight
                    className={cn(
                      "ml-auto transition-transform duration-200",
                      isOpen &amp;&amp; "rotate-90"
                    )}
                  /&gt;
                &lt;/SidebarMenuButton&gt;
              }
            /&gt;
            &lt;CollapsibleContent&gt;
              &lt;SidebarMenuSub className="me-0 pe-0"&gt;
                {item.children!.map((child, index) =&gt; (
                  &lt;NavMainSubItem
                    key={child.title || index}
                    item={child}
                    activeParent={activeParent}
                    setActiveParent={setActiveParent}
                    activeChild={activeChild}
                    setActiveChild={setActiveChild}
                    parentTitle={item.title}
                  /&gt;
                ))}
              &lt;/SidebarMenuSub&gt;
            &lt;/CollapsibleContent&gt;
          &lt;/SidebarMenuItem&gt;
        &lt;/Collapsible&gt;
      &lt;/SidebarMenu&gt;
    &lt;/SidebarGroup&gt;
  );
}
</code></pre>
<p>A <code>useEffect</code> inside <code>NavMainItem</code> syncs the local <code>isOpen</code> state with <code>activeParent</code> so that when a different parent is activated, the previously open collapsible stays open until the user explicitly closes it:</p>
<pre><code class="language-javascript">React.useEffect(() =&gt; {
  if (isParentActive) {
    setIsOpen(true);
  }
}, [isParentActive]);
</code></pre>
<p>The <code>ChevronRight</code> icon rotates 90 degrees when the submenu is open, using a Tailwind transition class:</p>
<pre><code class="language-javascript">&lt;ChevronRight
  className={cn(
    "ml-auto transition-transform duration-200",
    isOpen &amp;&amp; "rotate-90"
  )}
/&gt;
</code></pre>
<h3 id="heading-how-to-render-leaf-items">How to Render Leaf Items</h3>
<pre><code class="language-javascript">if (item.title) {
  return (
    &lt;SidebarGroup className="p-0"&gt;
      &lt;SidebarMenu&gt;
        &lt;SidebarMenuItem&gt;
          &lt;SidebarMenuButton
            id={`nav-main-button-${item.title.toLowerCase().replace(/\s+/g, '-')}`}
            tooltip={item.title}
            isActive={isParentActive}
            onClick={() =&gt; {
              setActiveParent(item.title!);
              setActiveChild(null);
            }}
            className={cn(
              "rounded-md text-sm font-medium px-3 py-2 h-9 transition-colors cursor-pointer",
              isParentActive ? "bg-primary! text-primary-foreground!" : ""
            )}
            render={&lt;a href={item.href} /&gt;}
          &gt;
            {item.icon &amp;&amp; &lt;item.icon /&gt;}
            {item.title}
          &lt;/SidebarMenuButton&gt;
        &lt;/SidebarMenuItem&gt;
      &lt;/SidebarMenu&gt;
    &lt;/SidebarGroup&gt;
  );
}
</code></pre>
<p>The <code>render</code> prop on <code>SidebarMenuButton</code> replaces the default button element with an <code>&lt;a&gt;</code> tag. This preserves correct anchor link semantics and accessibility while keeping the button's visual styling. When a leaf item is clicked, <code>activeChild</code> is reset to <code>null</code> since there is no child to track.</p>
<h3 id="heading-how-to-render-child-items-in-a-submenu">How to Render Child Items in a Submenu</h3>
<p>The <code>NavMainSubItem</code> function handles sub-items inside a collapsible. When a child is clicked, it sets both <code>activeChild</code> to itself and <code>activeParent</code> to its parent's title so the parent item remains visually highlighted:</p>
<pre><code class="language-javascript">if (item.title) {
  return (
    &lt;SidebarMenuSubItem className="w-full"&gt;
      &lt;SidebarMenuSubButton
        id={`nav-sub-button-${item.title.toLowerCase().replace(/\s+/g, '-')}`}
        className={cn(
          "w-full rounded-md transition-colors",
          activeChild === item.title ? "bg-muted! text-foreground!" : ""
        )}
        isActive={activeChild === item.title}
        onClick={() =&gt; {
          setActiveParent(parentTitle || "");
          setActiveChild(item.title!);
        }}
        render={&lt;a href={item.href}&gt;{item.title}&lt;/a&gt;}
      /&gt;
    &lt;/SidebarMenuSubItem&gt;
  );
}
</code></pre>
<p>The child uses a different active style (<code>bg-muted</code> with <code>text-foreground</code>) compared to the parent (<code>bg-primary</code> with <code>text-primary-foreground</code>). This visual distinction makes it easy to see both which section you are in and which specific page is currently active.</p>
<p>Sub-items also support nesting. If a child item itself has a <code>children</code> array, <code>NavMainSubItem</code> renders another <code>Collapsible</code> with a nested <code>SidebarMenuSub</code>, allowing you to build multi-level navigation trees without any changes to the data structure.</p>
<h2 id="heading-how-to-style-the-sidebar"><strong>How to Style the Sidebar</strong></h2>
<p>The full <code>AppSidebar</code> render function puts all of the pieces together:</p>
<pre><code class="language-javascript">export function AppSidebar() {
  return (
    &lt;Sidebar variant="floating" className="p-4 h-full [&amp;_[data-slot=sidebar-inner]]:h-full"&gt;
      &lt;div className="flex flex-col gap-6 overflow-hidden"&gt;

        {/* Header with Logo */}
        &lt;SidebarHeader className="px-4"&gt;
          &lt;SidebarMenu&gt;
            &lt;SidebarMenuItem&gt;
              &lt;a href="#" className="w-full h-full"&gt;
                &lt;Logo /&gt;
              &lt;/a&gt;
            &lt;/SidebarMenuItem&gt;
          &lt;/SidebarMenu&gt;
        &lt;/SidebarHeader&gt;

        {/* Scrollable Navigation Content */}
        &lt;SidebarContent className="overflow-hidden"&gt;
          &lt;ScrollArea className="h-[calc(100vh-100px)]"&gt;
            &lt;div className="px-4"&gt;
              &lt;NavMain items={navData} /&gt;
            &lt;/div&gt;

            {/* Promotional Card */}
            &lt;div className="pt-5 px-4"&gt;
              &lt;Card className="shadow-none ring-0 bg-secondary px-4 py-6"&gt;
                &lt;CardContent className="p-0 flex flex-col gap-3 items-center"&gt;
                  &lt;img
                    src="https://images.shadcnspace.com/assets/backgrounds/download-img.png"
                    alt="sidebar-img"
                    width={74}
                    height={74}
                    className="h-20 w-20"
                  /&gt;
                  &lt;div className="flex flex-col gap-4 items-center"&gt;
                    &lt;div&gt;
                      &lt;p className="text-base font-semibold text-card-foreground text-center"&gt;
                        Grab Pro Now
                      &lt;/p&gt;
                      &lt;p className="text-sm font-regular text-muted-foreground text-center"&gt;
                        Customize your admin
                      &lt;/p&gt;
                    &lt;/div&gt;
                    &lt;Button className="w-fit h-9 px-4 py-2 shadow-none cursor-pointer rounded-xl hover:bg-primary/80"&gt;
                      Get Premium
                    &lt;/Button&gt;
                  &lt;/div&gt;
                &lt;/CardContent&gt;
              &lt;/Card&gt;
            &lt;/div&gt;
          &lt;/ScrollArea&gt;
        &lt;/SidebarContent&gt;

      &lt;/div&gt;
    &lt;/Sidebar&gt;
  );
}
</code></pre>
<p>Let's walk through the key styling decisions:</p>
<p><code>variant="floating"</code> gives the sidebar a card-like appearance with rounded corners and a subtle drop shadow. It visually lifts the sidebar off the background rather than making it flush with the page edge like a standard sidebar would.</p>
<p><code>[&amp;_[data-slot=sidebar-inner]]:h-full</code> is an arbitrary Tailwind variant selector that targets shadcn/ui's internal sidebar slot element. Without this, the sidebar inner container doesn't fill the full available height, which breaks the layout. The <code>data-slot</code> attribute is how shadcn/ui identifies internal sub-elements of compound components.</p>
<p><code>h-[calc(100vh-100px)]</code> on <code>ScrollArea</code> makes the navigation list independently scrollable. The 100px offset accounts for the sidebar header and padding, so the scroll area doesn't overflow the viewport. The rest of the page layout remains static while the nav scrolls.</p>
<p>The <code>bg-secondary</code> card at the bottom of the scroll area is a common admin dashboard pattern, a soft prompt for an upgrade or onboarding action that lives passively in the sidebar without blocking navigation.</p>
<p>For more details on the Sidebar component's API, variants, and configuration options, refer to the official shadcn/ui sidebar docs.</p>
<h2 id="heading-live-preview"><strong>Live Preview</strong></h2>
<img src="https://cdn.hashnode.com/uploads/covers/68b53a3d851476bd2ce87f12/f1538441-fa73-4eb0-af91-04f5bf4fab08.png" alt="f1538441-fa73-4eb0-af91-04f5bf4fab08" style="display:block;margin:0 auto" width="1440" height="892" loading="lazy">

<h2 id="heading-summary"><strong>Summary</strong></h2>
<p>Congratulations! You have now built a complete, production-ready admin dashboard sidebar using shadcn/ui and a community block from Shadcn Space.</p>
<p>Here is a recap of everything you covered:</p>
<ul>
<li><p>Setting up a Next.js project with shadcn/ui initialized and a pre-built sidebar block installed from Shadcn Space</p>
</li>
<li><p>Using <code>SidebarProvider</code> and <code>SidebarTrigger</code> to manage the sidebar open/closed state across a page layout through React context</p>
</li>
<li><p>Defining navigation data as a flat array of typed <code>NavItem</code> objects covering section labels, leaf items, and collapsible parent items</p>
</li>
<li><p>Rendering all three item types from a single <code>navData</code> source in the <code>NavMain</code> and <code>NavMainItem</code> components</p>
</li>
<li><p>Tracking <code>activeParent</code> and <code>activeChild</code> state in a single location and passing them as props so every item can read and update the shared selection state</p>
</li>
<li><p>Using <code>Collapsible</code> with a <code>useEffect</code> sync to keep parent items open when they are active, and animate the chevron icon on expand and collapse</p>
</li>
<li><p>Applying the <code>floating</code> variant, an arbitrary Tailwind slot selector, and <code>ScrollArea</code> with a calculated height to produce a polished, production-appropriate sidebar layout</p>
</li>
</ul>
<p>This pattern scales well beyond what you built here. You can extend <code>NavItem</code> with additional fields like badge counts, permission flags, or external link indicators. You can swap in real <code>href</code> values and connect <code>activeParent</code> and <code>activeChild</code> to your router so the selection always reflects the current URL. You can also add more sections to <code>navData</code> without touching any rendering logic.</p>
<p>For a quick checkout, we have used the Shadcn Space free Shadcn dashboard block in this <a href="https://shadcnspace.com/blocks/dashboard-ui/dashboard-shell"><strong>dashboard shell</strong></a>.</p>
<p>If you want to explore more pre-built admin UI blocks, components, and templates built on top of shadcn/ui, you can browse the full library at <a href="https://shadcnspace.com/"><strong>Shadcn Space</strong></a>.</p>
<h3 id="heading-resources"><strong>Resources</strong></h3>
<ul>
<li><p><a href="https://shadcnspace.com/blocks"><strong>Shadcn UI Blocks</strong></a></p>
</li>
<li><p><a href="https://shadcnspace.com/components"><strong>Shadcn UI Components</strong></a></p>
</li>
<li><p><a href="https://shadcnspace.com/docs/getting-started/blocks"><strong>Shadcn Space Getting Started Docs</strong></a></p>
</li>
<li><p><a href="https://www.figma.com/community/file/1597967874273587400/shadcn-space-figma-ui-kit"><strong>Figma UI Kit Design System</strong></a></p>
</li>
<li><p><a href="https://ui.shadcn.com/docs/components/sidebar"><strong>shadcn/ui Sidebar Docs</strong></a></p>
</li>
<li><p><a href="https://base-ui.com/"><strong>Base UI</strong></a></p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Animated Shadcn Tab Component with Shadcn/ui ]]>
                </title>
                <description>
                    <![CDATA[ Tab components are everywhere: dashboards, settings panels, product pages. But most implementations are static, lifeless, and forgettable. What if your tabs felt alive, with smooth spring animations,  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-an-animated-shadcn-tab-component-with-shadcn-ui/</link>
                <guid isPermaLink="false">69ca85f69fffa747403074fe</guid>
                
                    <category>
                        <![CDATA[ UI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Vaibhav Gupta ]]>
                </dc:creator>
                <pubDate>Mon, 30 Mar 2026 14:17:26 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/961a288f-30b9-4085-a1fc-7da13ffce38f.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Tab components are everywhere: dashboards, settings panels, product pages. But most implementations are static, lifeless, and forgettable. What if your tabs felt alive, with smooth spring animations, a stacked card effect on hover, and a polished active indicator that glides between buttons?</p>
<p>A basic tab switcher can show and hide content. A better one gives users a clear active state, smooth transitions, and a little bit of motion that makes the interface feel alive. That's the idea behind this component: a reusable animated tab system built in the Shadcn style, with React, Tailwind CSS, and Motion.</p>
<p>In this tutorial, you’ll build exactly that: a fully animated tab component built by Shadcn/ui, Framer Motion, and a ready-to-use registry component from Shadcn Space.</p>
<p>By the end, you’ll have a reusable <code>&lt;Tabs/&gt;</code> component with:</p>
<ul>
<li><p>A spring-animated active pill indicator</p>
</li>
<li><p>A stacked card effect that fans out on hover</p>
</li>
<li><p>A smooth entrance animation when the active tab changes</p>
</li>
<li><p>Fully theme-aware styling using Shadcn/ui CSS variables</p>
</li>
</ul>
<p><strong>Video walkthrough</strong>: If you prefer to follow along visually, watch the full tutorial on YouTube:</p>
<div class="embed-wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/n6dvjVxy02U" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>

<h2 id="heading-table-of-contents"><strong>Table of Contents</strong></h2>
<ul>
<li><p><a href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-what-youll-build">What You’ll Build</a></p>
</li>
<li><p><a href="#heading-install-the-component-via-shadcn-space-cli">Install the Component via Shadcn Space CLI</a></p>
</li>
<li><p><a href="#heading-understand-the-component-structure">Understand the Component Structure</a></p>
</li>
<li><p><a href="#heading-step-1-define-the-tab-data-types">Step 1 - Define the Tab Data Types</a></p>
</li>
<li><p><a href="#heading-step-2-build-the-tab-data-array">Step 2 - Build the Tab Data Array</a></p>
</li>
<li><p><a href="#heading-step-3-build-the-tabs-component-tab-bar-state">Step 3 - Build the Tabs Component (Tab Bar + State)</a></p>
</li>
<li><p><a href="#heading-step-4-build-the-fadeinstack-component">Step 4 - Build the FadeInStack Component</a></p>
</li>
<li><p><a href="#heading-step-5-compose-the-page-component">Step 5 - Compose the Page Component</a></p>
</li>
<li><p><a href="#heading-step-6-customize-the-component">Step 6 - Customize the Component</a></p>
</li>
<li><p><a href="#heading-live-preview">Live Preview</a></p>
</li>
<li><p><a href="#heading-key-concepts-recap">Key Concepts Recap</a></p>
</li>
<li><p><a href="#heading-conclusion">Conclusion</a></p>
</li>
<li><p><a href="#heading-resources">Resources</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before you begin, make sure you have a working knowledge of:</p>
<ul>
<li><p>React and TypeScript basics</p>
</li>
<li><p>Tailwind CSS utility classes</p>
</li>
<li><p>The basics of Shadcn/ui (component installation and theming)</p>
</li>
</ul>
<p>You’ll also need a Next.js or Vite project with the following already set up:</p>
<ul>
<li><p>Shadcn/ui installed and initialized</p>
</li>
<li><p>Framer Motion (also referred to as motion/react) installed</p>
</li>
</ul>
<h2 id="heading-what-youll-build">What You’ll Build</h2>
<p>Here’s an overview of the component architecture you’ll create in this tutorial:</p>
<pre><code class="language-typescript">AnimatedTabMotion (page/demo entry point)
└── Tabs (tab bar + content orchestrator)
├── Tab buttons (with spring-animated active pill)
└── FadeInStack (stacked, animated content panels)
</code></pre>
<p>The key behaviors are:</p>
<ol>
<li><p><strong>Spring pill animation</strong> – A spring pill animation is a UI effect in which the active tab indicator, a rounded, pill-shaped highlight, physically moves from one button to another using a spring physics curve rather than a standard CSS transition. Instead of teleporting or fading, the pill slides between tabs with a subtle bounce at the end, mimicking the momentum of a real physical object.</p>
</li>
<li><p><strong>Stacked card effect</strong> – inactive tab panels are rendered behind the active one, scaled down and slightly faded, giving a layered depth illusion.</p>
</li>
<li><p><strong>Fan-out on hover</strong> – when the user hovers over the content area, the stacked cards spread out vertically.</p>
</li>
<li><p><strong>Bounce entrance</strong> – the top (active) card animates downward and back into place when a new tab is selected.</p>
</li>
</ol>
<h2 id="heading-install-the-component-via-shadcn-space-cli">Install the Component via Shadcn Space CLI</h2>
<p>Shadcn Space is a registry of production-ready Shadcn/ui-compatible components. Instead of scaffolding this component from scratch, you can pull it directly into your project using the Shadcn CLI.</p>
<p>Check out their <a href="https://shadcnspace.com/docs/getting-started/how-to-use-shadcn-cli">Getting Started guide</a> to learn how to use the Shadcn CLI with third-party registries.</p>
<p>Run <strong>one</strong> of the following commands, depending on your package manager:</p>
<p><strong>pnpm</strong></p>
<pre><code class="language-typescript">pnpm dlx shadcn@latest add @shadcn-space/tabs-01
</code></pre>
<p><strong>npm</strong></p>
<pre><code class="language-typescript">npx shadcn@latest add @shadcn-space/tabs-01
</code></pre>
<p><strong>Yarn</strong></p>
<pre><code class="language-typescript">yarn dlx shadcn@latest add @shadcn-space/tabs-01
</code></pre>
<p><strong>Bun</strong></p>
<pre><code class="language-typescript">bunx --bun shadcn@latest add @shadcn-space/tabs-01
</code></pre>
<p>This scaffolds the component file into your project, pre-wired to your existing Shadcn/ui theme tokens. You can then customize or extend it as needed, which is exactly what you’ll learn in this tutorial.</p>
<h2 id="heading-understand-the-component-structure">Understand the Component Structure</h2>
<p>Before writing any code, let’s review the full component and break it into logical pieces. Here is the complete implementation:</p>
<pre><code class="language-typescript">"use client";

import { useState } from "react";
import { motion } from "motion/react";
import { cn } from "@/lib/utils";

type Tab = {
  title: string;
  value: string;
  content?: React.ReactNode;
};

type TabsProps = {
  tabs: Tab[];
    containerClassName?: string;
  activeTabClassName?: string;
  tabClassName?: string;
  contentClassName?: string;
};

const tabs = [
  {
    title: "Product",
    value: "product",
    content: (
      &lt;div className="w-full overflow-hidden relative rounded-2xl p-10 text-xl md:text-4xl font-bold text-foreground bg-muted h-[300px] border border-border"&gt;
        &lt;p&gt;Product Tab&lt;/p&gt;
      &lt;/div&gt;
    ),
  },
  {title: "Services",
    value: "services",
    content: (
      &lt;div className="w-full overflow-hidden relative rounded-2xl p-10 text-xl md:text-4xl font-bold text-foreground bg-muted h-[300px] border border-border"&gt;
        &lt;p&gt;Services tab&lt;/p&gt;
      &lt;/div&gt;
    ),
  },
  {
    title: "Playground",
    value: "playground",
    content: (
      &lt;div className="w-full overflow-hidden relative rounded-2xl p-10 text-xl md:text-4xl font-bold text-foreground bg-muted h-[300px] border border-border"&gt;
        &lt;p&gt;Playground tab&lt;/p&gt;
      &lt;/div&gt;
    ),
  },
 {
    title: "Content",
    value: "content",
    content: (
      &lt;div className="w-full overflow-hidden relative rounded-2xl p-10 text-xl md:text-4xl font-bold text-foreground bg-muted h-[300px] border border-border"&gt;
        &lt;p&gt;Content tab&lt;/p&gt;
      &lt;/div&gt;
    ),
  },
  {
    title: "Random",
    value: "random",
    content: (
      &lt;div className="w-full overflow-hidden relative rounded-2xl p-10 text-xl md:text-4xl font-bold text-foreground bg-muted h-[300px] border border-border"&gt;
        &lt;p&gt;Random tab&lt;/p&gt;
      &lt;/div&gt;
    ),
  },
];

const Tabs = ({
  tabs,
  containerClassName,
  activeTabClassName,
  tabClassName,
  contentClassName,
}: TabsProps) =&gt; {
  const [activeIdx, setActiveIdx] = useState(0);
  const [hovering, setHovering] = useState(false);

  const handleSelect = (idx: number) =&gt; {
    setActiveIdx(idx);
  };
const reorderedTabs = [
    tabs[activeIdx],
    ...tabs.filter((_, i) =&gt; i !== activeIdx),
  ];

  return (
    &lt;&gt;
      &lt;div
        className={cn(
          "flex flex-row items-center justify-start [perspective:1000px] relative overflow-auto sm:overflow-visible no-visible-scrollbar max-w-full w-full",
          containerClassName,
        )}
      &gt;
        {tabs.map((tab, idx) =&gt; {
          const isActive = idx === activeIdx;
          return (
            &lt;button
            key={tab.value}
              onClick={() =&gt; handleSelect(idx)}
              onMouseEnter={() =&gt; setHovering(true)}
              onMouseLeave={() =&gt; setHovering(false)}
              className={cn("relative px-4 py-2 rounded-full", tabClassName)}
              style={{ transformStyle: "preserve-3d" }}
            &gt;
              {isActive &amp;&amp; (
                &lt;motion.div
                  layoutId="clickedbutton"
                  transition={{ type: "spring", bounce: 0.3, duration: 0.6 }}
                  className={cn(
                    "absolute inset-0 bg-primary rounded-full",
                    activeTabClassName,
                  )}
                /&gt;
              )}
&lt;span
                className={cn(
                  "relative block text-sm",
                  isActive ? "text-background": "text-foreground",
                )}
              &gt;
                {tab.title}
              &lt;/span&gt;
            &lt;/button&gt;
          );
        })}
      &lt;/div&gt;
      &lt;FadeInStack
        tabs={reorderedTabs}
        hovering={hovering}
        className={cn("mt-10", contentClassName)}
      /&gt;
    &lt;/&gt;
  );
};

type FadeInStackProps = {
  className?: string;
  tabs: Tab[];
  hovering?: boolean;
};

const FadeInStack = ({ className, tabs, hovering }: FadeInStackProps) =&gt; {
  return (
    &lt;div className="relative w-full h-[300px]"&gt;
      {tabs.map((tab, idx) =&gt; (
        &lt;motion.div
          key={tab.value}
          layoutId={tab.value}
          style={{
            scale: 1 - idx * 0.1,
            top: hovering ? idx * -15 : 0,
            zIndex: -idx,
            opacity: idx &lt; 3 ? 1 - idx * 0.1 : 0,
          }}
          animate={{
            y: idx === 0 ? [0, 40, 0] : 0,
          }}
          className={cn("w-full h-full absolute top-0 left-0", className)}
        &gt;
          {tab.content}
        &lt;/motion.div&gt;
      ))}
    &lt;/div&gt;
  );
};

export default function AnimatedTabMotion() {
  return (
    &lt;&gt;
      &lt;div className="[perspective:1000px] relative flex flex-col max-w-5xl mx-auto w-full items-start justify-start mb-13"&gt;
        &lt;Tabs tabs={tabs} /&gt;
      &lt;/div&gt;
    &lt;/&gt;
  );

}
</code></pre>
<p>Now, let’s break this down piece by piece.</p>
<h2 id="heading-step-1-define-the-tab-data-types">Step 1: Define the Tab Data Types</h2>
<pre><code class="language-typescript">type Tab = {
title: string;
value: string;
content?: React.ReactNode;
};
type TabsProps = {
tabs: Tab[];
containerClassName?: string;
activeTabClassName?: string;
tabClassName?: string;
contentClassName?: string;
};
</code></pre>
<p>The <code>Tab</code> type defines the shape of each tab item:</p>
<ul>
<li><p><code>title</code> – the label rendered in the tab button.</p>
</li>
<li><p><code>value</code> – a unique key used to identify each tab (and as the Framer Motion <code>layoutId</code>).</p>
</li>
<li><p><code>content</code> – an optional <code>React.ReactNode</code>, meaning you can pass any JSX as the panel body.</p>
</li>
</ul>
<p>The <code>TabsProps</code> type makes the <code>Tabs</code> component highly composable. Every visual layer has an override <code>className</code>, so you can restyle the active pill, individual tab buttons, and the content area independently without touching the core logic.</p>
<h2 id="heading-step-2-build-the-tab-data-array">Step 2: Build the Tab Data Array</h2>
<pre><code class="language-typescript">const tabs = [
{
title: “Product”,
value: “product”,
content: (

Product Tab

), }, // ... more tabs ];
</code></pre>
<p>Each tab’s <code>content</code> is a JSX element styled with Shadcn/ui semantic tokens like <code>bg-muted</code>, <code>text-foreground</code> and <code>border-border</code>. This is intentional: these tokens automatically adapt to your light/dark theme without any extra configuration.</p>
<p>You can replace these placeholder <code>&lt;div&gt;</code> panels with any real content: charts, forms, tables, media, whatever your use case demands.</p>
<h2 id="heading-step-3-build-the-tabs-component-tab-bar-state">Step 3: Build the Tabs Component (Tab Bar + State)</h2>
<pre><code class="language-typescript">const [activeIdx, setActiveIdx] = useState(0);
const [hovering, setHovering] = useState(false);
</code></pre>
<p>Two pieces of state drive the entire component:</p>
<ul>
<li><p><code>activeIdx</code> tracks which tab is currently selected (by array index).</p>
</li>
<li><p><code>hovering</code> tracks whether the user’s cursor is over any tab button, which is passed to <code>FadeInStack</code> to trigger the fan-out effect.</p>
</li>
</ul>
<h3 id="heading-reorder-tabs-for-the-stack-effect">Reorder Tabs for the Stack Effect</h3>
<pre><code class="language-typescript">const reorderedTabs = [
tabs[activeIdx],
…tabs.filter((_, i) =&gt; i !== activeIdx),
];
</code></pre>
<p>This is one of the most clever aspects of the architecture. Instead of showing only the active tab’s content, you <strong>always render all tab panels</strong> – but you put the active one first in the array. This is what enables the stacked-cards visual:</p>
<ul>
<li><p>Index 0 = the active panel, rendered on top with full scale and opacity.</p>
</li>
<li><p>Index 1, 2 = the next panels, stacked behind with reduced scale and opacity.</p>
</li>
<li><p>Index 3+ = hidden (opacity 0).</p>
</li>
</ul>
<h3 id="heading-render-the-tab-buttons-with-a-spring-pill">Render the Tab Buttons with a Spring Pill</h3>
<pre><code class="language-typescript">{tabs.map((tab, idx) =&gt; {
const isActive = idx === activeIdx;
return (
   &lt;button
    key={tab.value}
    onClick={() =&gt; handleSelect(idx)}
    onMouseEnter={() =&gt; setHovering(true)}
    onMouseLeave={() =&gt; setHovering(false)}
    className={cn(“relative px-4 py-2 rounded-full”, tabClassName)}
    style={{ transformStyle: “preserve-3d” }}
    &gt;
    {isActive &amp;&amp; (
       &lt;motion.div
        layoutId=“clickedbutton”
        transition={{ type: “spring”, bounce: 0.3, duration: 0.6 }}
        className={cn(
        “absolute inset-0 bg-primary rounded-full”,
        activeTabClassName,
     )}
   /&gt;
)}
&lt;span
    className={cn(
        “relative block text-sm”,
        isActive ? “text-background” : “text-foreground”,
    )}
    &gt;
      {tab.title}
     &lt;/span&gt;
  &lt;/button&gt;
);
})}
</code></pre>
<p>The magic here is <code>layoutId=“clickedbutton”</code> on the <code>motion.div</code>. When only one element with a given <code>layoutId</code> is mounted at a time, Framer Motion tracks its position in the DOM. When it unmounts from one button and mounts onto another, Framer Motion <code>automatically animates the transition</code> is between the two DOM positions. This creates the sliding pill effect with zero manual calculation.</p>
<p>The transition config uses a spring with <code>bounce: 0.3</code> a <code>duration: 0.6</code>, giving it a natural, slightly elastic feel rather than a mechanical linear slide.</p>
<p>The <code>transformStyle: “preserve-3d”</code> on the button enables 3D CSS transforms, which pair with the <code>[perspective:1000px]</code> on the container for a subtle depth effect.</p>
<h2 id="heading-step-4-build-the-fadeinstack-component">Step 4: Build the FadeInStack Component</h2>
<pre><code class="language-typescript">const FadeInStack = ({ className, tabs, hovering }: FadeInStackProps) =&gt; {
  return (
    &lt;div className="relative w-full h-[300px]"&gt;
      {tabs.map((tab, idx) =&gt; (
        &lt;motion.div
          key={tab.value}
          layoutId={tab.value}
          style={{
            scale: 1 - idx * 0.1,
            top: hovering ? idx * -15 : 0,
            zIndex: -idx,
            opacity: idx &lt; 3 ? 1 - idx * 0.1 : 0,
          }}
          animate={{
            y: idx === 0 ? [0, 40, 0] : 0,
          }}
          className={cn("w-full h-full absolute top-0 left-0", className)}
        &gt;
          {tab.content}
        &lt;/motion.div&gt;
      ))}
    &lt;/div&gt;
  );
};
</code></pre>
<p>Let’s unpack the visual logic for each <code>motion.div</code>:</p>
<h3 id="heading-scale-1-idx-01"><code>scale: 1 - idx * 0.1</code></h3>
<p>Each card behind the active one is scaled down by 10% per layer. So:</p>
<ul>
<li><p>Active card (idx 0): <code>scale: 1.0</code></p>
</li>
<li><p>Second card (idx 1): <code>scale: 0.9</code></p>
</li>
<li><p>Third card (idx 2): <code>scale: 0.8</code></p>
</li>
</ul>
<p>This creates clear depth separation between the stacked layers.</p>
<h3 id="heading-top-hovering-idx-15-0"><code>top: hovering ? idx * -15 : 0</code></h3>
<p>When <code>hovering</code> is <code>true</code>, each card shifts upward by <code>idx * 15px</code><em>. The active card doesn’t move</em> <code>(idx 15 = 0)</code>, but the cards behind it fan out at -15px, -30px, and so on. This gives a satisfying “deck spreading” effect on hover.</p>
<h3 id="heading-zindex-idx"><code>zIndex: -idx</code></h3>
<p>Negative z-index stacks cards in order: the active card sits on top (z-index 0), while subsequent cards descend further behind.</p>
<h3 id="heading-opacity-idx-lt-3-1-idx-01-0"><code>opacity: idx &lt; 3 ? 1 - idx * 0.1 : 0</code></h3>
<p>Cards at index 3 and beyond are hidden entirely. The first three cards fade progressively: 1.0, 0.9, 0.8.</p>
<h3 id="heading-animate-y-idx-0-0-40-0-0"><code>animate={{ y: idx === 0 ? [0, 40, 0] : 0 }}</code></h3>
<p>Only the active card (idx 0) gets this keyframe animation. When a tab is selected, and the <code>reorderedTabs</code> array is rebuilt, the new active card enters via a downward dip (<code>y: 40</code>) and bounces back to its rest position. This is a quick, tactile confirmation that the tab has changed.</p>
<h3 id="heading-layoutidtabvalue"><code>layoutId={tab.value}</code></h3>
<p>Each card also has a <code>layoutId</code> matching one <code>value</code>. When <code>reorderedTabs</code> is recomputed, and array positions shift, Framer Motion can track each card’s identity and animate it smoothly between positions, preventing jarring jumps.</p>
<h2 id="heading-step-5-compose-the-page-component">Step 5: Compose the Page Component</h2>
<pre><code class="language-typescript">export default function AnimatedTabMotion() {
  return (
    &lt;div className="[perspective:1000px] relative flex flex-col max-w-5xl mx-auto w-full items-start justify-start mb-13"&gt;
      &lt;Tabs tabs={tabs} /&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<p>The outer wrapper applies <code>[perspective:1000px]</code> – a Tailwind arbitrary property that sets the CSS <code>perspective</code> value. This is what gives the 3D depth to the <code>transformStyle: “preserve-3d”</code> on the tab buttons.</p>
<p>The <code>max-w-5xl</code> and <code>mx-auto</code> center the component on wide screens while <code>items-start</code> left-aligns the tab bar, which matches most real-world UI patterns.</p>
<h2 id="heading-step-6-customize-the-component">Step 6: Customize the Component</h2>
<p>Because <code>Tabs</code> accepts class-name overrides for every visual layer, so you can fully restyle the component to match your design system. Here’s an example with a darker active pill and a tighter layout:</p>
<pre><code class="language-typescript">&lt;Tabs
  tabs={tabs}
  containerClassName="gap-1"
  tabClassName="text-xs px-3 py-1.5"
  activeTabClassName="bg-zinc-900 dark:bg-white"
  contentClassName="mt-6"
/&gt;
</code></pre>
<p>You can also replace the placeholder content panels with real content. Here’s an example using a card with a real description:</p>
<pre><code class="language-typescript">const tabs = [
  {
    title: "Overview",
    value: "overview",
    content: (
      &lt;div className="w-full rounded-2xl p-8 bg-muted border border-border h-[300px] flex flex-col gap-4"&gt;
        &lt;h2 className="text-2xl font-bold text-foreground"&gt;Product Overview&lt;/h2&gt;
        &lt;p className="text-muted-foreground text-sm leading-relaxed"&gt;
          Our platform helps teams ship faster with a fully integrated design-to-code workflow.
        &lt;/p&gt;
      &lt;/div&gt;
    ),
  },
  // ...
];
</code></pre>
<h2 id="heading-live-preview">Live Preview</h2>
<img src="https://cdn.hashnode.com/uploads/covers/68b53a3d851476bd2ce87f12/af4a2ba6-dd70-4e77-8c38-7d390060db0d.gif" alt="af4a2ba6-dd70-4e77-8c38-7d390060db0d" style="display:block;margin:0 auto" width="1016" height="608" loading="lazy">

<h2 id="heading-key-concepts-recap">Key Concepts Recap</h2>
<p>Here’s a summary of the core Framer Motion techniques used in this component:</p>
<table style="min-width:415px"><colgroup><col style="min-width:25px"><col style="width:390px"></colgroup><tbody><tr><td><p><strong>Technique</strong></p></td><td><p><strong>What it does</strong></p></td></tr><tr><td><p><code>layoutId</code> on <code>motion.div</code></p></td><td><p>Animates a shared element between DOM positions (the sliding pill)</p></td></tr><tr><td><p><code>layoutId</code> on <code>motion.div</code> per tab</p></td><td><p>Tracks card identity during re-ordering, so Framer Motion animates position changes</p></td></tr><tr><td><p><code>animate={{ y: [0, 40, 0] }}</code></p></td><td><p>Keyframe animation for the bounce entrance on tab change</p></td></tr><tr><td><p><code>style={{ scale, top, zIndex, opacity }}</code></p></td><td><p>Inline reactive styles that create the stacked-card depth effect</p></td></tr><tr><td><p><code>transition={{ type: "spring" }}</code></p></td><td><p>Applies a physics-based spring curve instead of a CSS easing function</p></td></tr></tbody></table>

<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, you built a fully animated, theme-aware tab component using Shadcn/ui and Framer Motion. You learned how to:</p>
<ul>
<li><p>Use <code>layoutId</code> to create a spring-animated sliding pill indicator</p>
</li>
<li><p>Render all tab panels simultaneously and reorder them to create a stacked card effect</p>
</li>
<li><p>Drive hover and depth effects with inline reactive <code>style</code> props</p>
</li>
<li><p>Apply Framer Motion keyframe animations for a tactile bounce entrance</p>
</li>
<li><p>Keep the component fully customizable via class name overrides</p>
</li>
</ul>
<p>This pattern, combining Shadcn/ui’s semantic design tokens with Framer Motion’s layout animations, scales well beyond tabs. You can apply the same <code>layoutId</code> and stack reorder technique to carousels, image galleries, notification toasts, and more.</p>
<p>You can explore the full component and more animated UI blocks at Shadcn Space, where the CLI command makes it trivial to drop production-quality components directly into your project.</p>
<h2 id="heading-resources">Resources</h2>
<ul>
<li><p><a href="https://shadcnspace.com/components/tabs">Shadcn Space Tabs Component</a></p>
</li>
<li><p><a href="https://shadcnspace.com/docs/getting-started/how-to-use-shadcn-cli">Shadcn Space Getting Started Guide</a></p>
</li>
<li><p><a href="https://motion.dev/">Framer Motion Documentation</a></p>
</li>
<li><p><a href="https://ui.shadcn.com/">Shadcn/ui Documentation</a></p>
</li>
<li><p><a href="https://youtu.be/n6dvjVxy02U?si=pDpi2vC8oBjZlVsF">Video Tutorial on YouTube</a></p>
</li>
</ul>
<p>I wrote this article with the help of Mihir Koshti (Sr. Full Stack Developer) – <a href="https://www.linkedin.com/in/mihir-koshti/">Connect on LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Admin Dashboard with shadcn/ui and TanStack Start ]]>
                </title>
                <description>
                    <![CDATA[ In this guide, we’ll build a feature-rich admin dashboard using shadcn/ui for beautiful, reusable components and TanStack Start for a powerful, type-safe full-stack framework. By the end, you’ll have: A fully functional /dashboard layout A statisti... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-an-admin-dashboard-with-shadcnui-and-tanstack-start/</link>
                <guid isPermaLink="false">6931bd617fcd342128f08ed6</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcnui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcn ui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tanstack-start ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tanstack ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Thu, 04 Dec 2025 16:57:05 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1764780775287/b8cb826d-ac42-497c-8bb9-b9ffe797df83.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this guide, we’ll build a feature-rich admin dashboard using shadcn/ui for beautiful, reusable components and TanStack Start for a powerful, type-safe full-stack framework.</p>
<p>By the end, you’ll have:</p>
<ul>
<li><p>A fully functional <code>/dashboard</code> layout</p>
</li>
<li><p>A statistics-rich dashboard home page with charts and tables</p>
</li>
<li><p>A Products page using TanStack Query and TanStack Table</p>
</li>
<li><p>A Settings page with profile and notification controls</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764155564957/eda17d57-3f13-4526-be89-be55ec27453c.png" alt="TanStack Start dashboard" class="image--center mx-auto" width="1905" height="1050" loading="lazy"></p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-why-tanstack-start">Why TanStack Start?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-shadcnui">Why shadcn/ui?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-build-the-admin-dashboard-using-shadcnui-and-tanstack-start">How to Build the Admin Dashboard Using shadcn/ui and TanStack Start</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-1-create-a-new-tanstack-app">1. Create a new TanStack app</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-2-initial-cleanup">2. Initial Cleanup</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-3-setting-up-shadcnstudio-blocks">3. Setting Up shadcn/studio Blocks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-4-routing-structure-for-the-dashboard">4. Routing Structure for the Dashboard</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-5-creating-the-dashboard-layout">5. Creating the /dashboard Layout</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-6-building-the-dashboard-home-page">6. Building the Dashboard Home Page</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-7-set-up-the-products-page">7. Set up the Products Page.</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-8-settings-page">8. Settings Page</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-live-demo-amp-source-code">Live Demo &amp; Source Code</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-summary">Summary</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-whats-next">What’s Next?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-resources">Resources:</a></p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>Before we start the guide, let’s understand the basic requirements of the project:</p>
<ul>
<li><p>Node.js 18+ installed</p>
</li>
<li><p>Basic knowledge of React and TypeScript</p>
</li>
<li><p>Familiarity with TailwindCSS</p>
</li>
</ul>
<h3 id="heading-what-we-will-build">What we will build</h3>
<p>In this article, we’ll build a fully functional admin dashboard with three main sections:</p>
<ol>
<li><p><strong>Dashboard overview</strong>: A home page that displays various charts showing sales metrics, product insights widgets, and a transaction history table.</p>
</li>
<li><p><strong>Products:</strong> A product page that demonstrates data fetching, server-side pagination, and advanced table features like column searching, sorting, and column filtering.</p>
</li>
<li><p><strong>Settings:</strong> A user-friendly settings page with profile management and notification preferences.</p>
</li>
</ol>
<p>The dashboard will include a responsive sidebar navigation, breadcrumb trails, a user profile dropdown, and a language selector.</p>
<h2 id="heading-why-tanstack-start">Why TanStack Start?</h2>
<p><a target="_blank" href="https://tanstack.com/start/latest">TanStack Start</a> is a modern full-stack React framework built on top of TanStack Router. It aims to be a flexible, type-safe alternative to traditional meta-frameworks like Next.js.</p>
<p>Some key benefits of TanStack Start include:</p>
<ul>
<li><p>Type-safe routing and data loading</p>
</li>
<li><p>Server-side rendering (SSR) out of the box</p>
</li>
<li><p>Built on TanStack Router, with file-based routing</p>
</li>
<li><p>Great DX with TypeScript and TanStack Query integration</p>
</li>
</ul>
<p>We’ll pair it with shadcn/ui to quickly build a polished admin dashboard.</p>
<h2 id="heading-why-shadcnui">Why shadcn/ui?</h2>
<p><a target="_blank" href="https://ui.shadcn.com/">shadcn/ui</a> is a collection of beautifully designed, accessible React components built on top of Radix UI and styled with Tailwind CSS.</p>
<p>Instead of installing a package, you can copy and paste the component's code directly into your project or use a CLI to generate it. This gives you full control over the code structure &amp; styling. This approach makes Shadcn highly customizable for frameworks like TanStack Start, Next.js, Astro, and so on.</p>
<h2 id="heading-how-to-build-the-admin-dashboard-using-shadcnui-and-tanstack-start">How to Build the Admin Dashboard Using shadcn/ui and TanStack Start</h2>
<h3 id="heading-1-create-a-new-tanstack-app">1. Create a new TanStack app</h3>
<p>To get started, you’ll need to create a new TanStack Start app. You can do that with the following command:</p>
<pre><code class="lang-typescript">pnpm create <span class="hljs-meta">@tanstack</span>/start<span class="hljs-meta">@latest</span>
</code></pre>
<p>During the CLI setup, when it asks about add-ons, make sure to select:</p>
<ul>
<li><p>Shadcn</p>
</li>
<li><p>Table</p>
</li>
<li><p>Query</p>
</li>
</ul>
<p>These will give you the shadcn/ui setup and the TanStack Query + Table integrations we’ll use later.</p>
<h3 id="heading-2-initial-cleanup">2. Initial Cleanup</h3>
<p>TanStack Start’s starter template comes with some demo routes and a header we don’t need.</p>
<p>Clean up the project as follows:</p>
<ol>
<li><p>Remove the demo folder inside the <code>src/routes</code> directory (or wherever your router directory lives).</p>
</li>
<li><p>Delete <code>Header.tsx</code> from <code>src/components</code>.</p>
</li>
<li><p>Remove the <code>Header</code> import and usage from <code>src/routes/__root.tsx</code>.</p>
</li>
<li><p>Clean up the <code>src/routes/index.tsx</code> file to something minimal (or leave a simple landing page).</p>
</li>
</ol>
<p>At this point, you can make the initial commit to your repo.</p>
<h3 id="heading-3-setting-up-shadcnstudio-blocks">3. Setting Up shadcn/studio Blocks</h3>
<p>Before we set up, let’s make sure you’re clear on what the shadcn/studio and Shadcn registries are.</p>
<h4 id="heading-what-is-shadcnstudio">What is shadcn/studio?</h4>
<p><a target="_blank" href="https://shadcnstudio.com">shadcn/studio</a> is an open-source collection of copy-and-paste shadcn/ui components, blocks, and templates. It’s paired with a powerful shadcn theme generator to help you craft, customize, and ship faster.</p>
<h4 id="heading-what-is-shadcn-registry">What is Shadcn Registry?</h4>
<p>A shadcn registry is a system for sharing and distributing reusable code assets such as UI components, hooks, and theme configurations across different projects. Running your own registry allows you to publish your custom components that others can then use. The registry uses a <code>registry.json</code> file to define and organize the components and their associated files. </p>
<p>If you want to know more about registries, you can refer to the <a target="_blank" href="https://ui.shadcn.com/docs/registry">official documentation here</a>.</p>
<p>For quick building, we will use shadcn/studio’s free shadcn block – dashboard shell.</p>
<p>First, configure the registries in your <code>components.json</code>:</p>
<pre><code class="lang-typescript">{
  <span class="hljs-comment">// ...existing config</span>
  <span class="hljs-string">"registries"</span>: {
    <span class="hljs-string">"@shadcn-studio"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/{name}.json"</span>,
    <span class="hljs-string">"@ss-components"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/components/{name}.json"</span>,
    <span class="hljs-string">"@ss-blocks"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/blocks/{name}.json"</span>,
    <span class="hljs-string">"@ss-themes"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/themes/{name}.json"</span>
  }
}
</code></pre>
<p>If you face any issues while setting up, you can refer to the <a target="_blank" href="https://shadcnstudio.com/docs/getting-started/how-to-use-shadcn-cli">docs</a>.</p>
<h4 id="heading-install-the-dashboard-shell-block">Install the Dashboard Shell Block</h4>
<p>To get started, visit <a target="_blank" href="https://shadcnstudio.com/blocks">Shadcn blocks</a> and navigate to the Dashboard and App section. Then select the <a target="_blank" href="https://shadcnstudio.com/blocks/dashboard-and-application/dashboard-shell#dashboard-shell-1">Dashboard Shell 1</a> block (it’s free to use).</p>
<p>On the top-right, you’ll see a command to install the block into your project:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764155098742/23d1bee2-e082-4b19-860a-8112fe6bf41c.png" alt="shadcn/stuidio dashboard shell " class="image--center mx-auto" width="1232" height="725" loading="lazy"></p>
<p>Copy that command, paste it into your terminal, and run it. This will install all the components needed for the dashboard layout (sidebar, header, dropdowns, and so on).</p>
<h3 id="heading-4-routing-structure-for-the-dashboard">4. Routing Structure for the Dashboard</h3>
<p>Next, we’ll set up the dashboard routes.</p>
<p>First, create a new layout route for <code>/dashboard</code> by adding a file at:</p>
<p><code>src/routes/dashboard.tsx</code></p>
<p>Then, inside a <code>dashboard</code> directory, create the three pages that will live under this layout:</p>
<ul>
<li><p><code>src/routes/dashboard/index.tsx</code> – main dashboard overview</p>
</li>
<li><p><code>src/routes/dashboard/products.tsx</code> – products table page</p>
</li>
<li><p><code>src/routes/dashboard/settings.tsx</code> – settings page</p>
</li>
</ul>
<p>Your <code>routes</code> folder should look like this:</p>
<pre><code class="lang-typescript">src/routes/
├── __root.tsx
├── index.tsx
├── dashboard.tsx          <span class="hljs-comment">// Layout for all /dashboard/* pages</span>
└── dashboard/
    ├── index.tsx          <span class="hljs-comment">// /dashboard</span>
    ├── products.tsx       <span class="hljs-comment">// /dashboard/products</span>
    └── settings.tsx       <span class="hljs-comment">// /dashboard/settings</span>
</code></pre>
<h3 id="heading-5-creating-the-dashboard-layout">5. Creating the <code>/dashboard</code> Layout</h3>
<p>This will set up the layout for the dashboard. Create <code>src/routes/dashboard.tsx</code> and paste:</p>
<p>file: <code>src/routes/dashboard.tsx</code></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> LanguageDropdown <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/dropdown-language'</span>
<span class="hljs-keyword">import</span> ProfileDropdown <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/dropdown-profile'</span>
<span class="hljs-keyword">import</span> { Avatar, AvatarImage } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/avatar'</span>
<span class="hljs-keyword">import</span> {
    Breadcrumb,
    BreadcrumbItem,
    BreadcrumbLink,
    BreadcrumbList,
    BreadcrumbPage,
    BreadcrumbSeparator
} <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/breadcrumb'</span>
<span class="hljs-keyword">import</span> { Button } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/button'</span>
<span class="hljs-keyword">import</span> { Separator } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/separator'</span>
<span class="hljs-keyword">import</span> {
    Sidebar,
    SidebarContent,
    SidebarGroup,
    SidebarGroupContent,
    SidebarGroupLabel,
    SidebarHeader,
    SidebarMenu,
    SidebarMenuButton,
    SidebarMenuItem,
    SidebarProvider,
    SidebarTrigger
} <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/sidebar'</span>
<span class="hljs-keyword">import</span> { createFileRoute, Link, Outlet, useLocation } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-router'</span>
<span class="hljs-keyword">import</span> {
    FacebookIcon,
    InstagramIcon,
    LanguagesIcon,
    LayoutDashboard,
    LinkedinIcon,
    LogIn,
    Package,
    Settings,
    TwitterIcon,
    User2
} <span class="hljs-keyword">from</span> <span class="hljs-string">'lucide-react'</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Route = createFileRoute(<span class="hljs-string">'/dashboard'</span>)({
    component: DashboardLayout
})

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">DashboardLayout</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> location = useLocation()
    <span class="hljs-keyword">const</span> pathSegments = location.pathname.split(<span class="hljs-string">'/'</span>).filter(<span class="hljs-built_in">Boolean</span>)

    <span class="hljs-keyword">return</span> (
        &lt;div className=<span class="hljs-string">'flex min-h-dvh w-full'</span>&gt;
            &lt;SidebarProvider&gt;
                &lt;Sidebar&gt;
                    &lt;SidebarContent&gt;
                        &lt;SidebarHeader&gt;
                            &lt;SidebarMenu&gt;
                                &lt;SidebarMenuItem&gt;
                                    &lt;SidebarMenuButton size=<span class="hljs-string">"lg"</span> asChild&gt;
                                        &lt;Link to=<span class="hljs-string">"/"</span>&gt;
                                            &lt;div className=<span class="hljs-string">"flex aspect-square size-8 items-center justify-center rounded-lg bg-primary text-primary-foreground"</span>&gt;
                                                &lt;User2 className=<span class="hljs-string">"size-4"</span> /&gt;
                                            &lt;/div&gt;
                                            &lt;div className=<span class="hljs-string">"grid flex-1 text-left text-sm leading-tight"</span>&gt;
                                                &lt;span className=<span class="hljs-string">"truncate font-semibold"</span>&gt;Your App&lt;/span&gt;
                                                &lt;span className=<span class="hljs-string">"truncate text-xs"</span>&gt;Dashboard&lt;/span&gt;
                                            &lt;/div&gt;
                                        &lt;/Link&gt;
                                    &lt;/SidebarMenuButton&gt;
                                &lt;/SidebarMenuItem&gt;
                            &lt;/SidebarMenu&gt;
                        &lt;/SidebarHeader&gt;

                        &lt;SidebarGroup&gt;
                            &lt;SidebarGroupLabel&gt;General&lt;/SidebarGroupLabel&gt;
                            &lt;SidebarGroupContent&gt;
                                &lt;SidebarMenu&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard'</span>&gt;
                                                &lt;LayoutDashboard /&gt;
                                                &lt;span&gt;Dashboard&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard/products'</span>&gt;
                                                &lt;Package /&gt;
                                                &lt;span&gt;Products&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard/settings'</span>&gt;
                                                &lt;Settings /&gt;
                                                &lt;span&gt;Settings&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                &lt;/SidebarMenu&gt;
                            &lt;/SidebarGroupContent&gt;
                        &lt;/SidebarGroup&gt;
                    &lt;/SidebarContent&gt;
                &lt;/Sidebar&gt;
                &lt;div className=<span class="hljs-string">'flex flex-1 flex-col'</span>&gt;
                    &lt;header className=<span class="hljs-string">'bg-card sticky top-0 z-50 border-b'</span>&gt;
                        &lt;div className=<span class="hljs-string">'mx-auto flex max-w-7xl items-center justify-between gap-6 px-4 py-2 sm:px-6'</span>&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-4'</span>&gt;
                                &lt;SidebarTrigger className=<span class="hljs-string">'[&amp;_svg]:h-5 [&amp;_svg]:w-5'</span> /&gt;
                                &lt;Separator orientation=<span class="hljs-string">'vertical'</span> className=<span class="hljs-string">'hidden h-4 sm:block'</span> /&gt;
                                &lt;Breadcrumb className=<span class="hljs-string">'hidden sm:block'</span>&gt;
                                    &lt;BreadcrumbList&gt;
                                        &lt;BreadcrumbItem&gt;
                                            &lt;BreadcrumbLink asChild&gt;
                                                &lt;Link to=<span class="hljs-string">'/'</span>&gt;Home&lt;/Link&gt;
                                            &lt;/BreadcrumbLink&gt;
                                        &lt;/BreadcrumbItem&gt;
                                        &lt;BreadcrumbSeparator /&gt;
                                        {pathSegments.map(<span class="hljs-function">(<span class="hljs-params">segment, index</span>) =&gt;</span> {
                                            <span class="hljs-keyword">const</span> path = <span class="hljs-string">`/<span class="hljs-subst">${pathSegments.slice(<span class="hljs-number">0</span>, index + <span class="hljs-number">1</span>).join(<span class="hljs-string">'/'</span>)}</span>`</span>
                                            <span class="hljs-keyword">const</span> isLast = index === pathSegments.length - <span class="hljs-number">1</span>
                                            <span class="hljs-keyword">const</span> title = segment.charAt(<span class="hljs-number">0</span>).toUpperCase() + segment.slice(<span class="hljs-number">1</span>)

                                            <span class="hljs-keyword">return</span> (
                                                &lt;React.Fragment key={path}&gt;
                                                    &lt;BreadcrumbItem&gt;
                                                        {isLast ? (
                                                            &lt;BreadcrumbPage&gt;{title}&lt;/BreadcrumbPage&gt;
                                                        ) : (
                                                            &lt;BreadcrumbLink asChild&gt;
                                                                &lt;Link to={path <span class="hljs-keyword">as</span> <span class="hljs-built_in">any</span>}&gt;{title}&lt;/Link&gt;
                                                            &lt;/BreadcrumbLink&gt;
                                                        )}
                                                    &lt;/BreadcrumbItem&gt;
                                                    {!isLast &amp;&amp; &lt;BreadcrumbSeparator /&gt;}
                                                &lt;/React.Fragment&gt;
                                            )
                                        })}
                                    &lt;/BreadcrumbList&gt;
                                &lt;/Breadcrumb&gt;
                            &lt;/div&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-1.5'</span>&gt;
                                &lt;LanguageDropdown
                                    trigger={
                                        &lt;Button variant=<span class="hljs-string">'ghost'</span> size=<span class="hljs-string">'icon'</span>&gt;
                                            &lt;LanguagesIcon /&gt;
                                        &lt;/Button&gt;
                                    }
                                /&gt;
                                &lt;ProfileDropdown
                                    trigger={
                                        &lt;Button variant=<span class="hljs-string">'ghost'</span> size=<span class="hljs-string">'icon'</span> className=<span class="hljs-string">'h-10 w-10'</span>&gt;
                                            &lt;Avatar className=<span class="hljs-string">'h-10 w-10 rounded-md'</span>&gt;
                                                &lt;AvatarImage src=<span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png'</span> /&gt;
                                            &lt;/Avatar&gt;
                                        &lt;/Button&gt;
                                    }
                                /&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/header&gt;
                    &lt;main className=<span class="hljs-string">'mx-auto w-full max-w-7xl flex-1 px-4 py-6 sm:px-6'</span>&gt;
                        &lt;Outlet /&gt;
                    &lt;/main&gt;
                    &lt;footer&gt;
                        &lt;div className=<span class="hljs-string">'text-muted-foreground mx-auto flex w-full items-center justify-between gap-3 px-4 py-3 flex-col sm:flex-row sm:gap-6 sm:px-6'</span>&gt;
                            &lt;p className=<span class="hljs-string">'text-sm text-center sm:text-left'</span>&gt;
                                {<span class="hljs-string">`©<span class="hljs-subst">${<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getFullYear()}</span>`</span>}{<span class="hljs-string">' '</span>}
                                &lt;a href=<span class="hljs-string">'#'</span> className=<span class="hljs-string">'text-primary'</span>&gt;
                                    TanStack Start
                                &lt;/a&gt;
                                , Made <span class="hljs-keyword">for</span> better web design
                            &lt;/p&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-5'</span>&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;FacebookIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;InstagramIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;LinkedinIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;TwitterIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/footer&gt;
                &lt;/div&gt;
            &lt;/SidebarProvider&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>You now have a full layout for all <code>/dashboard/*</code> routes.</p>
<p>Let's break down the key parts of our dashboard layout:</p>
<ul>
<li><p><strong>Sidebar structure:</strong> The <code>&lt;Sidebar&gt;</code> component wraps our navigation menu. Inside, we use <code>&lt;SidebarMenu&gt;</code> and <code>&lt;SidebarMenuItem&gt;</code> to create navigation links. Each menu item uses TanStack Router's <code>&lt;Link&gt;</code> component for type-safe navigation. We also have a header set up in the <code>&lt;SidebarProvider&gt;</code></p>
</li>
<li><p><strong>Dynamic breadcrumbs:</strong> The breadcrumb section uses <code>location.pathname</code> to split the current URL into segments, then maps over them to create breadcrumb links. The <code>isLast</code> check ensures the final breadcrumb renders as plain text rather than a link.</p>
</li>
<li><p><strong>Header actions</strong>: The header includes two dropdowns: <code>&lt;LanguageDropdown&gt;</code> for internationalization and <code>&lt;ProfileDropdown&gt;</code> for user account actions. These come from the <code>shadcn/studio</code> blocks we installed.</p>
</li>
<li><p><strong>Outlet component:</strong> The <code>&lt;Outlet /&gt;</code> component is where child routes (like <code>/dashboard</code>, <code>/dashboard/products</code>) will render. This makes our layout reusable across all dashboard pages. The layout uses Tailwind's utility classes for spacing, colors, and responsive behavior, making it easy to customize for your use case.</p>
</li>
</ul>
<p>For more details regarding the Sidebar component, you can <a target="_blank" href="https://ui.shadcn.com/docs/components/sidebar">refer to the official docs here</a>.</p>
<p>You now have a full layout for all <code>/dashboard/*</code> routes.</p>
<h3 id="heading-6-building-the-dashboard-home-page">6. Building the Dashboard Home Page</h3>
<p>Create <code>src/routes/dashboard/index.tsx</code>:</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { <span class="hljs-keyword">type</span> Item } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/datatable-transaction'</span>
<span class="hljs-keyword">import</span> { createFileRoute } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-router'</span>

<span class="hljs-keyword">import</span> { Card } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/card'</span>

<span class="hljs-keyword">import</span> SalesMetricsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/chart-sales-metrics'</span>
<span class="hljs-keyword">import</span> TransactionDatatable <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/datatable-transaction'</span>
<span class="hljs-keyword">import</span> StatisticsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/statistics-card-01'</span>
<span class="hljs-keyword">import</span> ProductInsightsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/widget-product-insights'</span>
<span class="hljs-keyword">import</span> TotalEarningCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/widget-total-earning'</span>

<span class="hljs-keyword">import</span> {
    CalendarX2Icon,
    TriangleAlertIcon,
    TruckIcon
} <span class="hljs-keyword">from</span> <span class="hljs-string">'lucide-react'</span>

<span class="hljs-comment">// Statistics card data</span>
<span class="hljs-keyword">const</span> StatisticsCardData = [
    {
        icon: &lt;TruckIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'42'</span>,
        title: <span class="hljs-string">'Shipped Orders'</span>,
        changePercentage: <span class="hljs-string">'+18.2%'</span>
    },
    {
        icon: &lt;TriangleAlertIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'8'</span>,
        title: <span class="hljs-string">'Damaged Returns'</span>,
        changePercentage: <span class="hljs-string">'-8.7%'</span>
    },
    {
        icon: &lt;CalendarX2Icon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'27'</span>,
        title: <span class="hljs-string">'Missed Delivery Slots'</span>,
        changePercentage: <span class="hljs-string">'+4.3%'</span>
    }
]

<span class="hljs-comment">// Earning data for Total Earning card</span>
<span class="hljs-keyword">const</span> earningData = [
    {
        img: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/blocks/dashboard-application/widgets/zipcar.png'</span>,
        platform: <span class="hljs-string">'Zipcar'</span>,
        technologies: <span class="hljs-string">'Vuejs &amp; HTML'</span>,
        earnings: <span class="hljs-string">'-$23,569.26'</span>,
        progressPercentage: <span class="hljs-number">75</span>
    },
    {
        img: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/blocks/dashboard-application/widgets/bitbank.png'</span>,
        platform: <span class="hljs-string">'Bitbank'</span>,
        technologies: <span class="hljs-string">'Figma &amp; React'</span>,
        earnings: <span class="hljs-string">'-$12,650.31'</span>,
        progressPercentage: <span class="hljs-number">25</span>
    }
]

<span class="hljs-comment">// Transaction table data</span>
<span class="hljs-keyword">const</span> transactionData: Item[] = [
    {
        id: <span class="hljs-string">'1'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png'</span>,
        avatarFallback: <span class="hljs-string">'JA'</span>,
        name: <span class="hljs-string">'Jack Alfredo'</span>,
        amount: <span class="hljs-number">315.0</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'jack@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'2'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-2.png'</span>,
        avatarFallback: <span class="hljs-string">'MG'</span>,
        name: <span class="hljs-string">'Maria Gonzalez'</span>,
        amount: <span class="hljs-number">253.4</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'maria.g@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'3'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-3.png'</span>,
        avatarFallback: <span class="hljs-string">'JD'</span>,
        name: <span class="hljs-string">'John Doe'</span>,
        amount: <span class="hljs-number">852.0</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'john.doe@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'4'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-4.png'</span>,
        avatarFallback: <span class="hljs-string">'EC'</span>,
        name: <span class="hljs-string">'Emily Carter'</span>,
        amount: <span class="hljs-number">889.0</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'emily.carter@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'5'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-5.png'</span>,
        avatarFallback: <span class="hljs-string">'DL'</span>,
        name: <span class="hljs-string">'David Lee'</span>,
        amount: <span class="hljs-number">723.16</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'david.lee@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'6'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-6.png'</span>,
        avatarFallback: <span class="hljs-string">'SP'</span>,
        name: <span class="hljs-string">'Sophia Patel'</span>,
        amount: <span class="hljs-number">612.0</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'sophia.patel@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'7'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-7.png'</span>,
        avatarFallback: <span class="hljs-string">'RW'</span>,
        name: <span class="hljs-string">'Robert Wilson'</span>,
        amount: <span class="hljs-number">445.25</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'robert.wilson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'8'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-8.png'</span>,
        avatarFallback: <span class="hljs-string">'LM'</span>,
        name: <span class="hljs-string">'Lisa Martinez'</span>,
        amount: <span class="hljs-number">297.8</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'lisa.martinez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'9'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-9.png'</span>,
        avatarFallback: <span class="hljs-string">'MT'</span>,
        name: <span class="hljs-string">'Michael Thompson'</span>,
        amount: <span class="hljs-number">756.9</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'michael.thompson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'10'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-10.png'</span>,
        avatarFallback: <span class="hljs-string">'AJ'</span>,
        name: <span class="hljs-string">'Amanda Johnson'</span>,
        amount: <span class="hljs-number">189.5</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'amanda.johnson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'11'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-11.png'</span>,
        avatarFallback: <span class="hljs-string">'KB'</span>,
        name: <span class="hljs-string">'Kevin Brown'</span>,
        amount: <span class="hljs-number">1024.75</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'kevin.brown@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'12'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-12.png'</span>,
        avatarFallback: <span class="hljs-string">'SD'</span>,
        name: <span class="hljs-string">'Sarah Davis'</span>,
        amount: <span class="hljs-number">367.2</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'sarah.davis@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'13'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-13.png'</span>,
        avatarFallback: <span class="hljs-string">'CG'</span>,
        name: <span class="hljs-string">'Christopher Garcia'</span>,
        amount: <span class="hljs-number">598.45</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'christopher.garcia@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'14'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-14.png'</span>,
        avatarFallback: <span class="hljs-string">'JR'</span>,
        name: <span class="hljs-string">'Jennifer Rodriguez'</span>,
        amount: <span class="hljs-number">821.3</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'jennifer.rodriguez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'15'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-15.png'</span>,
        avatarFallback: <span class="hljs-string">'DM'</span>,
        name: <span class="hljs-string">'Daniel Miller'</span>,
        amount: <span class="hljs-number">156.75</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'daniel.miller@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'16'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-16.png'</span>,
        avatarFallback: <span class="hljs-string">'NW'</span>,
        name: <span class="hljs-string">'Nicole White'</span>,
        amount: <span class="hljs-number">934.1</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'nicole.white@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'17'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-17.png'</span>,
        avatarFallback: <span class="hljs-string">'AL'</span>,
        name: <span class="hljs-string">'Anthony Lopez'</span>,
        amount: <span class="hljs-number">412.85</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'anthony.lopez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'18'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-18.png'</span>,
        avatarFallback: <span class="hljs-string">'MH'</span>,
        name: <span class="hljs-string">'Michelle Harris'</span>,
        amount: <span class="hljs-number">675.5</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'michelle.harris@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'19'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-19.png'</span>,
        avatarFallback: <span class="hljs-string">'JC'</span>,
        name: <span class="hljs-string">'James Clark'</span>,
        amount: <span class="hljs-number">289.95</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'james.clark@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'20'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-20.png'</span>,
        avatarFallback: <span class="hljs-string">'RL'</span>,
        name: <span class="hljs-string">'Rachel Lewis'</span>,
        amount: <span class="hljs-number">1156.25</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'rachel.lewis@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'21'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-21.png'</span>,
        avatarFallback: <span class="hljs-string">'TY'</span>,
        name: <span class="hljs-string">'Thomas Young'</span>,
        amount: <span class="hljs-number">543.6</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'thomas.young@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'22'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-22.png'</span>,
        avatarFallback: <span class="hljs-string">'SB'</span>,
        name: <span class="hljs-string">'Stephanie Brown'</span>,
        amount: <span class="hljs-number">789.3</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'stephanie.brown@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'23'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-23.png'</span>,
        avatarFallback: <span class="hljs-string">'BM'</span>,
        name: <span class="hljs-string">'Brandon Moore'</span>,
        amount: <span class="hljs-number">425.75</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'brandon.moore@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'24'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-24.png'</span>,
        avatarFallback: <span class="hljs-string">'KT'</span>,
        name: <span class="hljs-string">'Kelly Taylor'</span>,
        amount: <span class="hljs-number">1203.5</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'kelly.taylor@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'25'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-25.png'</span>,
        avatarFallback: <span class="hljs-string">'MA'</span>,
        name: <span class="hljs-string">'Mark Anderson'</span>,
        amount: <span class="hljs-number">356.2</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'mark.anderson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    }
]

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Route = createFileRoute(<span class="hljs-string">'/dashboard/'</span>)({
    component: RouteComponent,
})

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">RouteComponent</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        &lt;div className=<span class="hljs-string">'grid grid-cols-2 gap-6 lg:grid-cols-3'</span>&gt;
            {<span class="hljs-comment">/* Statistics Cards */</span>}
            &lt;div className=<span class="hljs-string">'col-span-full grid gap-6 sm:grid-cols-3 md:max-lg:grid-cols-1'</span>&gt;
                {StatisticsCardData.map(<span class="hljs-function">(<span class="hljs-params">card, index</span>) =&gt;</span> (
                    &lt;StatisticsCard
                        key={index}
                        icon={card.icon}
                        title={card.title}
                        value={card.value}
                        changePercentage={card.changePercentage}
                    /&gt;
                ))}
            &lt;/div&gt;

            &lt;div className=<span class="hljs-string">'grid gap-6 max-xl:col-span-full lg:max-xl:grid-cols-2'</span>&gt;
                {<span class="hljs-comment">/* Product Insights Card */</span>}
                &lt;ProductInsightsCard className=<span class="hljs-string">'justify-between gap-3 *:data-[slot=card-content]:space-y-5'</span> /&gt;

                {<span class="hljs-comment">/* Total Earning Card */</span>}
                &lt;TotalEarningCard
                    title=<span class="hljs-string">'Total Earning'</span>
                    earning={<span class="hljs-number">24650</span>}
                    trend=<span class="hljs-string">'up'</span>
                    percentage={<span class="hljs-number">10</span>}
                    comparisonText=<span class="hljs-string">'Compare to last year ($84,325)'</span>
                    earningData={earningData}
                    className=<span class="hljs-string">'justify-between gap-5 sm:min-w-0 *:data-[slot=card-content]:space-y-7'</span>
                /&gt;
            &lt;/div&gt;

            &lt;SalesMetricsCard className=<span class="hljs-string">'col-span-full xl:col-span-2 *:data-[slot=card-content]:space-y-6'</span> /&gt;
            &lt;Card className=<span class="hljs-string">'col-span-full w-full py-0'</span>&gt;
                &lt;TransactionDatatable data={transactionData} /&gt;
            &lt;/Card&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>Our dashboard homepage uses various shadcn-studio blocks like:</p>
<ul>
<li><p><strong>Statistics cards</strong> display KPIs (Shipped Orders, Damaged Returns, and so on) with trend indicators. Each card receives props for the icon, value, title, and percentage change, making them reusable for any metric.</p>
</li>
<li><p><strong>Chart components</strong> like <code>&lt;SalesMetricsCard&gt;</code> use <code>recharts</code> under the hood to visualize data. The styling comes from shadcn/ui's card component and Tailwind utilities.</p>
</li>
<li><p><strong>Transaction data table</strong> demonstrates TanStack Table integration. We pass an array of transaction objects, and the <code>&lt;TransactionDatatable&gt;</code> component handles rendering, sorting, and pagination. Notice how we use TypeScript's <code>Item[]</code> type for full type safety.</p>
</li>
</ul>
<p>If you now navigate to <code>/dashboard</code>, you should see an admin dashboard with KPI statistics, charts, a dashboard, and a transaction table. Here is what it would look like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764747793227/ca1c0e10-e295-45c4-8e3c-15702583c887.jpeg" alt="tanstack start dashboard demo" class="image--center mx-auto" width="1454" height="1388" loading="lazy"></p>
<p>We have built this beautiful dashboard quickly by using the shadcn/studio’s pre-built blocks.</p>
<h3 id="heading-7-set-up-the-products-page">7. Set up the Products Page.</h3>
<p>Before building our products table, we need to install <strong>Zod</strong>, a TypeScript-first schema validation library. We'll use it to validate the data structure of requests to our server function.</p>
<h4 id="heading-why-zod">Why Zod?</h4>
<p>TanStack Start's server functions use Zod to ensure type-safe data transfer between client and server. When we request to fetch products, Zod validates that the request includes the correct types for <code>page</code>, <code>pageSize</code>, <code>sortBy</code>, and <code>filters</code>. This catches errors at runtime and provides excellent TypeScript inference.</p>
<p>Now, let’s set up the products page with a products table. But before that, let’s install the zod package dependency. Here is the command for it:</p>
<pre><code class="lang-bash">pnpm add zod
</code></pre>
<h4 id="heading-creating-mock-product-data">Creating Mock Product Data</h4>
<p>We will need to store our mock products’ data somewhere. For that, we will create a new file <code>data/products.ts</code> and paste the code below. This will help us mock the product data for our products table.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { createServerFn } <span class="hljs-keyword">from</span> <span class="hljs-string">"@tanstack/react-start"</span>;
<span class="hljs-keyword">import</span> { z } <span class="hljs-keyword">from</span> <span class="hljs-string">"zod"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">type</span> Product = {
    id: <span class="hljs-built_in">string</span>
    name: <span class="hljs-built_in">string</span>
    category: <span class="hljs-built_in">string</span>
    price: <span class="hljs-built_in">number</span>
    stock: <span class="hljs-built_in">number</span>
    status: <span class="hljs-string">'active'</span> | <span class="hljs-string">'draft'</span> | <span class="hljs-string">'archived'</span>
    image: <span class="hljs-built_in">string</span>
}

<span class="hljs-comment">// Define the type for the data parameter</span>
<span class="hljs-keyword">type</span> ProductQueryParams = {
    page: <span class="hljs-built_in">number</span>;
    pageSize: <span class="hljs-built_in">number</span>;
    sortBy?: <span class="hljs-built_in">string</span>;
    sortOrder?: <span class="hljs-string">"asc"</span> | <span class="hljs-string">"desc"</span>;
    filters?: {
        name?: <span class="hljs-built_in">string</span>;
        category?: <span class="hljs-built_in">string</span>;
        status?: <span class="hljs-built_in">string</span>;
    };
};

<span class="hljs-keyword">const</span> products: Product[] = [
    {
        id: <span class="hljs-string">'PROD-001'</span>,
        name: <span class="hljs-string">'Wireless Noise Cancelling Headphones'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">299.99</span>,
        stock: <span class="hljs-number">45</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-002'</span>,
        name: <span class="hljs-string">'Ergonomic Office Chair'</span>,
        category: <span class="hljs-string">'Furniture'</span>,
        price: <span class="hljs-number">199.50</span>,
        stock: <span class="hljs-number">12</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1592078615290-033ee584e267?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-003'</span>,
        name: <span class="hljs-string">'Mechanical Gaming Keyboard'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">129.99</span>,
        stock: <span class="hljs-number">0</span>,
        status: <span class="hljs-string">'archived'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1587829741301-dc798b91add1?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-004'</span>,
        name: <span class="hljs-string">'Smart Fitness Watch'</span>,
        category: <span class="hljs-string">'Wearables'</span>,
        price: <span class="hljs-number">149.00</span>,
        stock: <span class="hljs-number">89</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-005'</span>,
        name: <span class="hljs-string">'Minimalist Desk Lamp'</span>,
        category: <span class="hljs-string">'Lighting'</span>,
        price: <span class="hljs-number">45.00</span>,
        stock: <span class="hljs-number">23</span>,
        status: <span class="hljs-string">'draft'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1507473888900-52e1ad14723b?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-006'</span>,
        name: <span class="hljs-string">'Portable Bluetooth Speaker'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">79.99</span>,
        stock: <span class="hljs-number">150</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1608043152269-423dbba4e7e1?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-007'</span>,
        name: <span class="hljs-string">'Ceramic Coffee Mug Set'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">24.99</span>,
        stock: <span class="hljs-number">200</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1514228742587-6b1558fcca3d?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-008'</span>,
        name: <span class="hljs-string">'Leather Messenger Bag'</span>,
        category: <span class="hljs-string">'Accessories'</span>,
        price: <span class="hljs-number">129.50</span>,
        stock: <span class="hljs-number">15</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1553062407-98eeb64c6a62?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-009'</span>,
        name: <span class="hljs-string">'Wireless Charging Pad'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">39.99</span>,
        stock: <span class="hljs-number">75</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1586816879360-004f5b0c51e3?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-010'</span>,
        name: <span class="hljs-string">'Succulent Plant Set'</span>,
        category: <span class="hljs-string">'Home &amp; Garden'</span>,
        price: <span class="hljs-number">29.99</span>,
        stock: <span class="hljs-number">30</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1485955900006-10f4d324d411?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-011'</span>,
        name: <span class="hljs-string">'Professional Chef Knife'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">89.95</span>,
        stock: <span class="hljs-number">42</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1593618998160-e34014e67546?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-012'</span>,
        name: <span class="hljs-string">'Yoga Mat'</span>,
        category: <span class="hljs-string">'Fitness'</span>,
        price: <span class="hljs-number">35.00</span>,
        stock: <span class="hljs-number">100</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-013'</span>,
        name: <span class="hljs-string">'Smart Thermostat'</span>,
        category: <span class="hljs-string">'Home Automation'</span>,
        price: <span class="hljs-number">199.00</span>,
        stock: <span class="hljs-number">0</span>,
        status: <span class="hljs-string">'archived'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1567789884554-0b844b597180?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-014'</span>,
        name: <span class="hljs-string">'Vintage Film Camera'</span>,
        category: <span class="hljs-string">'Photography'</span>,
        price: <span class="hljs-number">450.00</span>,
        stock: <span class="hljs-number">3</span>,
        status: <span class="hljs-string">'draft'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1526170375885-4d8ecf77b99f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-015'</span>,
        name: <span class="hljs-string">'Cotton T-Shirt Pack'</span>,
        category: <span class="hljs-string">'Apparel'</span>,
        price: <span class="hljs-number">49.99</span>,
        stock: <span class="hljs-number">150</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-016'</span>,
        name: <span class="hljs-string">'Electric Toothbrush'</span>,
        category: <span class="hljs-string">'Personal Care'</span>,
        price: <span class="hljs-number">69.99</span>,
        stock: <span class="hljs-number">55</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1559656914-a30970c1affd?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-017'</span>,
        name: <span class="hljs-string">'Gaming Mouse'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">59.99</span>,
        stock: <span class="hljs-number">88</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1527864550417-7fd91fc51a46?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-018'</span>,
        name: <span class="hljs-string">'Essential Oil Diffuser'</span>,
        category: <span class="hljs-string">'Home &amp; Garden'</span>,
        price: <span class="hljs-number">34.50</span>,
        stock: <span class="hljs-number">25</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1602928321679-560bb453f190?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-019'</span>,
        name: <span class="hljs-string">'Running Shoes'</span>,
        category: <span class="hljs-string">'Footwear'</span>,
        price: <span class="hljs-number">119.99</span>,
        stock: <span class="hljs-number">60</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-020'</span>,
        name: <span class="hljs-string">'Digital Drawing Tablet'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">249.00</span>,
        stock: <span class="hljs-number">18</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1561525140-c2a4cc68e4bd?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-021'</span>,
        name: <span class="hljs-string">'Bamboo Cutting Board'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">22.99</span>,
        stock: <span class="hljs-number">95</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1594385208974-2e75f8d7bb48?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-022'</span>,
        name: <span class="hljs-string">'Sunglasses'</span>,
        category: <span class="hljs-string">'Accessories'</span>,
        price: <span class="hljs-number">159.00</span>,
        stock: <span class="hljs-number">40</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1511499767150-a48a237f0083?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-023'</span>,
        name: <span class="hljs-string">'Water Bottle'</span>,
        category: <span class="hljs-string">'Fitness'</span>,
        price: <span class="hljs-number">19.99</span>,
        stock: <span class="hljs-number">300</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1602143407151-01114192003f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-024'</span>,
        name: <span class="hljs-string">'Throw Pillow Set'</span>,
        category: <span class="hljs-string">'Home Decor'</span>,
        price: <span class="hljs-number">45.99</span>,
        stock: <span class="hljs-number">28</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1584100936595-c0654b55a2e6?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-025'</span>,
        name: <span class="hljs-string">'Wireless Earbuds'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">89.99</span>,
        stock: <span class="hljs-number">120</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1590658268037-6bf12165a8df?w=100&amp;q=80'</span>,
    }
]

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getProducts = createServerFn({ method: <span class="hljs-string">"GET"</span> })
    .inputValidator(
        z.object({
            page: z.number().default(<span class="hljs-number">0</span>),
            pageSize: z.number().default(<span class="hljs-number">10</span>),
            sortBy: z.string().optional(),
            sortOrder: z.enum([<span class="hljs-string">"asc"</span>, <span class="hljs-string">"desc"</span>]).optional(),
            filters: z
                .object({
                    name: z.string().optional(),
                    category: z.string().optional(),
                    status: z.string().optional(),
                })
                .optional(),
        })
    )
    .handler(<span class="hljs-keyword">async</span> ({ data }: { data: ProductQueryParams }) =&gt; {
        <span class="hljs-keyword">const</span> { page, pageSize, sortBy, sortOrder, filters } = data;

        <span class="hljs-comment">// Apply filters</span>
        <span class="hljs-keyword">let</span> filteredProducts = [...products];

        <span class="hljs-keyword">if</span> (filters) {
            <span class="hljs-keyword">if</span> (filters.name) {
                filteredProducts = filteredProducts.filter(<span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span>
                    product.name.toLowerCase().includes(filters.name!.toLowerCase())
                );
            }

            <span class="hljs-keyword">if</span> (filters.category) {
                filteredProducts = filteredProducts.filter(
                    <span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span>
                        product.category.toLowerCase() === filters.category!.toLowerCase()
                );
            }

            <span class="hljs-keyword">if</span> (filters.status) {
                filteredProducts = filteredProducts.filter(
                    <span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span> product.status === filters.status
                );
            }
        }

        <span class="hljs-comment">// Apply sorting</span>
        <span class="hljs-keyword">if</span> (sortBy) {
            filteredProducts.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
                <span class="hljs-keyword">const</span> aValue = a[sortBy <span class="hljs-keyword">as</span> keyof Product];
                <span class="hljs-keyword">const</span> bValue = b[sortBy <span class="hljs-keyword">as</span> keyof Product];

                <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> aValue === <span class="hljs-string">"string"</span> &amp;&amp; <span class="hljs-keyword">typeof</span> bValue === <span class="hljs-string">"string"</span>) {
                    <span class="hljs-keyword">return</span> sortOrder === <span class="hljs-string">"desc"</span>
                        ? bValue.localeCompare(aValue)
                        : aValue.localeCompare(bValue);
                }

                <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> aValue === <span class="hljs-string">"number"</span> &amp;&amp; <span class="hljs-keyword">typeof</span> bValue === <span class="hljs-string">"number"</span>) {
                    <span class="hljs-keyword">return</span> sortOrder === <span class="hljs-string">"desc"</span> ? bValue - aValue : aValue - bValue;
                }

                <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
            });
        }

        <span class="hljs-comment">// Calculate pagination</span>
        <span class="hljs-keyword">const</span> totalCount = filteredProducts.length;
        <span class="hljs-keyword">const</span> totalPages = <span class="hljs-built_in">Math</span>.ceil(totalCount / pageSize);
        <span class="hljs-keyword">const</span> paginatedProducts = filteredProducts.slice(
            page * pageSize,
            (page + <span class="hljs-number">1</span>) * pageSize
        );

        <span class="hljs-comment">// Simulate network delay</span>
        <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =&gt;</span> <span class="hljs-built_in">setTimeout</span>(resolve, <span class="hljs-number">500</span>));

        <span class="hljs-keyword">return</span> {
            products: paginatedProducts,
            pagination: {
                page,
                pageSize,
                totalCount,
                totalPages,
            },
        };
    });
</code></pre>
<p>Let’s understand the server function and break down what's happening in <code>getProducts</code>:</p>
<ul>
<li><p><strong>Input validation</strong>: The <code>.inputValidator()</code> method uses a Zod schema to validate incoming requests. It ensures <code>page</code> and <code>pageSize</code> are numbers, <code>sortOrder</code> is either "asc" or "desc", and filters are optional strings.</p>
</li>
<li><p><strong>Filtering products</strong>: The function filters the products array based on the provided filters (name, category, status). This simulates what a real database query would do.</p>
</li>
<li><p><strong>Sorting</strong>: Products are sorted by the specified column (<code>sortBy</code>) in ascending or descending order (<code>sortOrder</code>).</p>
</li>
<li><p><strong>Pagination</strong>: We calculate which slice of products to return based on <code>page</code> and <code>pageSize</code>, along with metadata like <code>totalCount</code> and <code>totalPages</code>.</p>
</li>
</ul>
<h4 id="heading-create-the-products-table">Create the Products table:</h4>
<p>Once the data is done, let’s create a table in <code>/dashboard/products.tsx</code>. This table will use our mock product data and will provide multiple functions in the table, like search, sort, and filter. This table demonstrates the powerful combination of TanStack Query for data management and TanStack Table for rendering.</p>
<p>Paste the code below in the <code>products.tsx</code> file:</p>
<pre><code class="lang-bash">import { useQuery } from <span class="hljs-string">'@tanstack/react-query'</span>
import { createFileRoute } from <span class="hljs-string">'@tanstack/react-router'</span>
import {
    ColumnDef,
    ColumnFiltersState,
    flexRender,
    getCoreRowModel,
    getFilteredRowModel,
    getPaginationRowModel,
    getSortedRowModel,
    SortingState,
    useReactTable,
    VisibilityState,
} from <span class="hljs-string">'@tanstack/react-table'</span>
import {
    ArrowUpDown,
    ChevronDown,
    Filter,
    Loader2,
    MoreHorizontal,
    Plus,
    Search
} from <span class="hljs-string">'lucide-react'</span>
import { useState } from <span class="hljs-string">'react'</span>

import { Badge } from <span class="hljs-string">'@/components/ui/badge'</span>
import { Button } from <span class="hljs-string">'@/components/ui/button'</span>
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from <span class="hljs-string">'@/components/ui/card'</span>
import {
    DropdownMenu,
    DropdownMenuCheckboxItem,
    DropdownMenuContent,
    DropdownMenuItem,
    DropdownMenuLabel,
    DropdownMenuSeparator,
    DropdownMenuTrigger,
} from <span class="hljs-string">'@/components/ui/dropdown-menu'</span>
import { Input } from <span class="hljs-string">'@/components/ui/input'</span>
import {
    Table,
    TableBody,
    TableCell,
    TableHead,
    TableHeader,
    TableRow,
} from <span class="hljs-string">'@/components/ui/table'</span>
import { getProducts, <span class="hljs-built_in">type</span> Product } from <span class="hljs-string">'@/data/products'</span>

<span class="hljs-built_in">export</span> const Route = createFileRoute(<span class="hljs-string">'/dashboard/products'</span>)({
    component: ProductsPage,
})

<span class="hljs-built_in">export</span> const columns: ColumnDef&lt;Product&gt;[] = [
    {
        accessorKey: <span class="hljs-string">'name'</span>,
        header: ({ column }) =&gt; {
            <span class="hljs-built_in">return</span> (
                &lt;Button
                    variant=<span class="hljs-string">"ghost"</span>
                    onClick={() =&gt; column.toggleSorting(column.getIsSorted() === <span class="hljs-string">"asc"</span>)}
                &gt;
                    Product Name
                    &lt;ArrowUpDown className=<span class="hljs-string">"ml-2 h-4 w-4"</span> /&gt;
                &lt;/Button&gt;
            )
        },
        cell: ({ row }) =&gt; (
            &lt;div className=<span class="hljs-string">"flex items-center gap-3"</span>&gt;
                &lt;img
                    src={row.original.image}
                    alt={row.getValue(<span class="hljs-string">'name'</span>)}
                    className=<span class="hljs-string">"h-10 w-10 rounded-md object-cover"</span>
                /&gt;
                &lt;div className=<span class="hljs-string">"flex flex-col"</span>&gt;
                    &lt;span className=<span class="hljs-string">"font-medium"</span>&gt;{row.getValue(<span class="hljs-string">'name'</span>)}&lt;/span&gt;
                    &lt;span className=<span class="hljs-string">"text-xs text-muted-foreground"</span>&gt;{row.original.id}&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        ),
    },
    {
        accessorKey: <span class="hljs-string">'category'</span>,
        header: <span class="hljs-string">'Category'</span>,
        cell: ({ row }) =&gt; &lt;div&gt;{row.getValue(<span class="hljs-string">'category'</span>)}&lt;/div&gt;,
    },
    {
        accessorKey: <span class="hljs-string">'status'</span>,
        header: <span class="hljs-string">'Status'</span>,
        cell: ({ row }) =&gt; {
            const status = row.getValue(<span class="hljs-string">'status'</span>) as string
            <span class="hljs-built_in">return</span> (
                &lt;Badge variant={status === <span class="hljs-string">'active'</span> ? <span class="hljs-string">'default'</span> : status === <span class="hljs-string">'draft'</span> ? <span class="hljs-string">'secondary'</span> : <span class="hljs-string">'outline'</span>}&gt;
                    {status}
                &lt;/Badge&gt;
            )
        },
    },
    {
        accessorKey: <span class="hljs-string">'price'</span>,
        header: () =&gt; &lt;div className=<span class="hljs-string">"text-right"</span>&gt;Price&lt;/div&gt;,
        cell: ({ row }) =&gt; {
            const amount = parseFloat(row.getValue(<span class="hljs-string">'price'</span>))
            const formatted = new Intl.NumberFormat(<span class="hljs-string">'en-US'</span>, {
                style: <span class="hljs-string">'currency'</span>,
                currency: <span class="hljs-string">'USD'</span>,
            }).format(amount)

            <span class="hljs-built_in">return</span> &lt;div className=<span class="hljs-string">"text-right font-medium"</span>&gt;{formatted}&lt;/div&gt;
        },
    },
    {
        accessorKey: <span class="hljs-string">'stock'</span>,
        header: () =&gt; &lt;div className=<span class="hljs-string">"text-right"</span>&gt;Stock&lt;/div&gt;,
        cell: ({ row }) =&gt; {
            const stock = parseFloat(row.getValue(<span class="hljs-string">'stock'</span>))
            <span class="hljs-built_in">return</span> &lt;div className={`text-right <span class="hljs-variable">${stock === 0 ? 'text-red-500 font-medium' : ''}</span>`}&gt;{stock}&lt;/div&gt;
        },
    },
    {
        id: <span class="hljs-string">'actions'</span>,
        enableHiding: <span class="hljs-literal">false</span>,
        cell: ({ row }) =&gt; {
            const product = row.original

            <span class="hljs-built_in">return</span> (
                &lt;DropdownMenu&gt;
                    &lt;DropdownMenuTrigger asChild&gt;
                        &lt;Button variant=<span class="hljs-string">"ghost"</span> className=<span class="hljs-string">"h-8 w-8 p-0"</span>&gt;
                            &lt;span className=<span class="hljs-string">"sr-only"</span>&gt;Open menu&lt;/span&gt;
                            &lt;MoreHorizontal className=<span class="hljs-string">"h-4 w-4"</span> /&gt;
                        &lt;/Button&gt;
                    &lt;/DropdownMenuTrigger&gt;
                    &lt;DropdownMenuContent align=<span class="hljs-string">"end"</span>&gt;
                        &lt;DropdownMenuLabel&gt;Actions&lt;/DropdownMenuLabel&gt;
                        &lt;DropdownMenuItem
                            onClick={() =&gt; navigator.clipboard.writeText(product.id)}
                        &gt;
                            Copy Product ID
                        &lt;/DropdownMenuItem&gt;
                        &lt;DropdownMenuSeparator /&gt;
                        &lt;DropdownMenuItem&gt;Edit Product&lt;/DropdownMenuItem&gt;
                        &lt;DropdownMenuItem&gt;View Details&lt;/DropdownMenuItem&gt;
                    &lt;/DropdownMenuContent&gt;
                &lt;/DropdownMenu&gt;
            )
        },
    },
]

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">ProductsPage</span></span>() {
    const [sorting, setSorting] = useState&lt;SortingState&gt;([])
    const [columnFilters, setColumnFilters] = useState&lt;ColumnFiltersState&gt;([])
    const [columnVisibility, setColumnVisibility] = useState&lt;VisibilityState&gt;({})
    const [rowSelection, setRowSelection] = useState({})
    const [pagination, setPagination] = useState({
        pageIndex: 0,
        pageSize: 10,
    })

    const { data, isLoading } = useQuery({
        queryKey: [<span class="hljs-string">'products'</span>, pagination, sorting, columnFilters],
        queryFn: () =&gt; getProducts({
            data: {
                page: pagination.pageIndex,
                pageSize: pagination.pageSize,
                sortBy: sorting[0]?.id,
                sortOrder: sorting[0]?.desc ? <span class="hljs-string">'desc'</span> : <span class="hljs-string">'asc'</span>,
                filters: {
                    name: (columnFilters.find((f) =&gt; f.id === <span class="hljs-string">'name'</span>)?.value as string) || undefined,
                    status: (columnFilters.find((f) =&gt; f.id === <span class="hljs-string">'status'</span>)?.value as string) || undefined,
                }
            }
        }),
    })

    const products = data?.products || []
    const totalPages = data?.pagination.totalPages || 0
    const totalCount = data?.pagination.totalCount || 0

    const table = useReactTable({
        data: products,
        columns,
        pageCount: totalPages,
        manualPagination: <span class="hljs-literal">true</span>,
        manualSorting: <span class="hljs-literal">true</span>,
        manualFiltering: <span class="hljs-literal">true</span>,
        onSortingChange: setSorting,
        onColumnFiltersChange: setColumnFilters,
        getCoreRowModel: getCoreRowModel(),
        getPaginationRowModel: getPaginationRowModel(),
        getSortedRowModel: getSortedRowModel(),
        getFilteredRowModel: getFilteredRowModel(),
        onColumnVisibilityChange: setColumnVisibility,
        onRowSelectionChange: setRowSelection,
        onPaginationChange: setPagination,
        state: {
            sorting,
            columnFilters,
            columnVisibility,
            rowSelection,
            pagination,
        },
    })

    <span class="hljs-built_in">return</span> (
        &lt;div className=<span class="hljs-string">"w-full space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between"</span>&gt;
                &lt;h2 className=<span class="hljs-string">"text-2xl font-bold tracking-tight"</span>&gt;Products&lt;/h2&gt;
                &lt;div className=<span class="hljs-string">"flex items-center gap-2"</span>&gt;
                    &lt;Button variant=<span class="hljs-string">"outline"</span> size=<span class="hljs-string">"sm"</span>&gt;
                        &lt;Filter className=<span class="hljs-string">"mr-2 h-4 w-4"</span> /&gt;
                        Filter
                    &lt;/Button&gt;
                    &lt;Button size=<span class="hljs-string">"sm"</span>&gt;
                        &lt;Plus className=<span class="hljs-string">"mr-2 h-4 w-4"</span> /&gt;
                        Add Product
                    &lt;/Button&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;Card&gt;
                &lt;CardHeader&gt;
                    &lt;CardTitle&gt;Product Management&lt;/CardTitle&gt;
                    &lt;CardDescription&gt;
                        Manage your product catalog, track inventory, and update prices.
                    &lt;/CardDescription&gt;
                &lt;/CardHeader&gt;
                &lt;CardContent&gt;
                    &lt;div className=<span class="hljs-string">"flex items-center py-4 gap-2"</span>&gt;
                        &lt;div className=<span class="hljs-string">"relative flex-1"</span>&gt;
                            &lt;Search className=<span class="hljs-string">"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"</span> /&gt;
                            &lt;Input
                                placeholder=<span class="hljs-string">"Filter products..."</span>
                                value={(table.getColumn(<span class="hljs-string">"name"</span>)?.getFilterValue() as string) ?? <span class="hljs-string">""</span>}
                                onChange={(event) =&gt;
                                    table.getColumn(<span class="hljs-string">"name"</span>)?.setFilterValue(event.target.value)
                                }
                                className=<span class="hljs-string">"pl-8 max-w-sm"</span>
                            /&gt;
                        &lt;/div&gt;
                        &lt;DropdownMenu&gt;
                            &lt;DropdownMenuTrigger asChild&gt;
                                &lt;Button variant=<span class="hljs-string">"outline"</span> className=<span class="hljs-string">"ml-auto"</span>&gt;
                                    Columns &lt;ChevronDown className=<span class="hljs-string">"ml-2 h-4 w-4"</span> /&gt;
                                &lt;/Button&gt;
                            &lt;/DropdownMenuTrigger&gt;
                            &lt;DropdownMenuContent align=<span class="hljs-string">"end"</span>&gt;
                                {table
                                    .getAllColumns()
                                    .filter((column) =&gt; column.getCanHide())
                                    .map((column) =&gt; {
                                        <span class="hljs-built_in">return</span> (
                                            &lt;DropdownMenuCheckboxItem
                                                key={column.id}
                                                className=<span class="hljs-string">"capitalize"</span>
                                                checked={column.getIsVisible()}
                                                onCheckedChange={(value) =&gt;
                                                    column.toggleVisibility(!!value)
                                                }
                                            &gt;
                                                {column.id}
                                            &lt;/DropdownMenuCheckboxItem&gt;
                                        )
                                    })}
                            &lt;/DropdownMenuContent&gt;
                        &lt;/DropdownMenu&gt;
                    &lt;/div&gt;
                    &lt;div className=<span class="hljs-string">"rounded-md border"</span>&gt;
                        &lt;Table&gt;
                            &lt;TableHeader&gt;
                                {table.getHeaderGroups().map((headerGroup) =&gt; (
                                    &lt;TableRow key={headerGroup.id}&gt;
                                        {headerGroup.headers.map((header) =&gt; {
                                            <span class="hljs-built_in">return</span> (
                                                &lt;TableHead key={header.id}&gt;
                                                    {header.isPlaceholder
                                                        ? null
                                                        : flexRender(
                                                            header.column.columnDef.header,
                                                            header.getContext()
                                                        )}
                                                &lt;/TableHead&gt;
                                            )
                                        })}
                                    &lt;/TableRow&gt;
                                ))}
                            &lt;/TableHeader&gt;
                            &lt;TableBody&gt;
                                {isLoading ? (
                                    &lt;TableRow&gt;
                                        &lt;TableCell colSpan={columns.length} className=<span class="hljs-string">"h-24 text-center"</span>&gt;
                                            &lt;div className=<span class="hljs-string">"flex items-center justify-center gap-2"</span>&gt;
                                                &lt;Loader2 className=<span class="hljs-string">"h-6 w-6 animate-spin"</span> /&gt;
                                                &lt;span&gt;Loading products...&lt;/span&gt;
                                            &lt;/div&gt;
                                        &lt;/TableCell&gt;
                                    &lt;/TableRow&gt;
                                ) : table.getRowModel().rows?.length ? (
                                    table.getRowModel().rows.map((row) =&gt; (
                                        &lt;TableRow
                                            key={row.id}
                                            data-state={row.getIsSelected() &amp;&amp; <span class="hljs-string">"selected"</span>}
                                        &gt;
                                            {row.getVisibleCells().map((cell) =&gt; (
                                                &lt;TableCell key={cell.id}&gt;
                                                    {flexRender(
                                                        cell.column.columnDef.cell,
                                                        cell.getContext()
                                                    )}
                                                &lt;/TableCell&gt;
                                            ))}
                                        &lt;/TableRow&gt;
                                    ))
                                ) : (
                                    &lt;TableRow&gt;
                                        &lt;TableCell
                                            colSpan={columns.length}
                                            className=<span class="hljs-string">"h-24 text-center"</span>
                                        &gt;
                                            No results.
                                        &lt;/TableCell&gt;
                                    &lt;/TableRow&gt;
                                )}
                            &lt;/TableBody&gt;
                        &lt;/Table&gt;
                    &lt;/div&gt;
                    &lt;div className=<span class="hljs-string">"flex items-center justify-end space-x-2 py-4"</span>&gt;
                        &lt;div className=<span class="hljs-string">"flex-1 text-sm text-muted-foreground"</span>&gt;
                            {table.getFilteredSelectedRowModel().rows.length} of{<span class="hljs-string">" "</span>}
                            {totalCount} row(s) selected.
                        &lt;/div&gt;
                        &lt;div className=<span class="hljs-string">"space-x-2"</span>&gt;
                            &lt;Button
                                variant=<span class="hljs-string">"outline"</span>
                                size=<span class="hljs-string">"sm"</span>
                                onClick={() =&gt; table.previousPage()}
                                disabled={!table.getCanPreviousPage()}
                            &gt;
                                Previous
                            &lt;/Button&gt;
                            &lt;Button
                                variant=<span class="hljs-string">"outline"</span>
                                size=<span class="hljs-string">"sm"</span>
                                onClick={() =&gt; table.nextPage()}
                                disabled={!table.getCanNextPage()}
                            &gt;
                                Next
                            &lt;/Button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/CardContent&gt;
            &lt;/Card&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>Now you can see the fully functional products page by navigating the <code>/products</code> where you can search and sort the products.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764748681745/6f73dc04-ac9a-4f75-a1ab-88ed1fc5c6f3.jpeg" alt="tanstack start dashboard demo" class="image--center mx-auto" width="1454" height="1059" loading="lazy"></p>
<h4 id="heading-how-do-tanstack-query-and-tanstack-table-work-in-the-products-table">How do TanStack Query and TanStack Table Work in the products table?</h4>
<p>Our products page uses TanStack Query for data fetching and TanStack Table for rendering.</p>
<p><code>useQuery</code> is a fundamental hook in TanStack Query for managing server state in web applications. It simplifies data fetching, caching, and synchronization.</p>
<p>The below code snippet below shows how we have used useQuery in our product table:</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { useQuery } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-query'</span>;

<span class="hljs-keyword">const</span> { data, isLoading } = useQuery({
    queryKey: [<span class="hljs-string">'products'</span>, pagination, sorting, columnFilters],
    queryFn: <span class="hljs-function">() =&gt;</span> getProducts({...})
}
</code></pre>
<p>The <code>useQuery</code> hook manages data fetching in our application. For more details, you can <a target="_blank" href="https://tanstack.com/query/latest">refer to the official docs here</a>.</p>
<p><strong>useReactTable:</strong></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { useReactTable } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-table'</span>

<span class="hljs-keyword">const</span> table = useReactTable({
    data: products,
    columns,
    manualPagination: <span class="hljs-literal">true</span>,
    manualSorting: <span class="hljs-literal">true</span>,
    manualFiltering: <span class="hljs-literal">true</span>,
})
</code></pre>
<p><strong>TanStack Table</strong> manages the UI state and rendering. By setting <code>manualPagination</code>, <code>manualSorting</code>, and <code>manualFiltering</code> to <code>true</code>, we tell the table that server-side logic handles these operations.</p>
<p>When users sort, filter, or paginate, the table updates its states, and React Query detects the state change in the <code>queryKey</code>. It refetches data from the server, and the table re-renders with fresh data.</p>
<p>This architecture is production-ready and scales to thousands of rows. You just need to replace the mock API endpoint with your real API endpoint.</p>
<h3 id="heading-8-settings-page">8. Settings Page</h3>
<p>Finally, let’s add a simple Settings page with a profile section and some basic notification preferences.</p>
<p>Below is the code for the Settings Page. You can paste it into <code>/dashboard/settings.tsx</code>:</p>
<pre><code class="lang-bash">import { Avatar, AvatarFallback, AvatarImage } from <span class="hljs-string">'@/components/ui/avatar'</span>
import { Button } from <span class="hljs-string">'@/components/ui/button'</span>
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from <span class="hljs-string">'@/components/ui/card'</span>
import { Checkbox } from <span class="hljs-string">"@/components/ui/checkbox"</span>
import { Input } from <span class="hljs-string">'@/components/ui/input'</span>
import { Separator } from <span class="hljs-string">'@/components/ui/separator'</span>
import { createFileRoute } from <span class="hljs-string">'@tanstack/react-router'</span>

<span class="hljs-built_in">export</span> const Route = createFileRoute(<span class="hljs-string">'/dashboard/settings'</span>)({
  component: SettingsPage,
})

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">SettingsPage</span></span>() {
  <span class="hljs-built_in">return</span> (
    &lt;div className=<span class="hljs-string">"space-y-6"</span>&gt;
      &lt;div&gt;
        &lt;h3 className=<span class="hljs-string">"text-lg font-medium"</span>&gt;Settings&lt;/h3&gt;
        &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
          Manage your account settings and <span class="hljs-built_in">set</span> e-mail preferences.
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;Separator /&gt;

      &lt;div className=<span class="hljs-string">"grid gap-6"</span>&gt;
        &lt;Card&gt;
          &lt;CardHeader&gt;
            &lt;CardTitle&gt;Profile&lt;/CardTitle&gt;
            &lt;CardDescription&gt;
              This is how others will see you on the site.
            &lt;/CardDescription&gt;
          &lt;/CardHeader&gt;
          &lt;CardContent className=<span class="hljs-string">"space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center gap-4"</span>&gt;
              &lt;Avatar className=<span class="hljs-string">"h-20 w-20"</span>&gt;
                &lt;AvatarImage src=<span class="hljs-string">"https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png"</span> /&gt;
                &lt;AvatarFallback&gt;JD&lt;/AvatarFallback&gt;
              &lt;/Avatar&gt;
              &lt;Button variant=<span class="hljs-string">"outline"</span>&gt;Change Avatar&lt;/Button&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"username"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Username&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"username"</span> defaultValue=<span class="hljs-string">"jdoe"</span> /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"email"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Email&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"email"</span> defaultValue=<span class="hljs-string">"john.doe@example.com"</span> /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"bio"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Bio&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"bio"</span> placeholder=<span class="hljs-string">"Tell us a little bit about yourself"</span> /&gt;
            &lt;/div&gt;
          &lt;/CardContent&gt;
          &lt;CardFooter&gt;
            &lt;Button&gt;Save Changes&lt;/Button&gt;
          &lt;/CardFooter&gt;
        &lt;/Card&gt;

        &lt;Card&gt;
          &lt;CardHeader&gt;
            &lt;CardTitle&gt;Notifications&lt;/CardTitle&gt;
            &lt;CardDescription&gt;
              Configure how you receive notifications.
            &lt;/CardDescription&gt;
          &lt;/CardHeader&gt;
          &lt;CardContent className=<span class="hljs-string">"space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between rounded-lg border p-4"</span>&gt;
              &lt;div className=<span class="hljs-string">"space-y-0.5"</span>&gt;
                &lt;label className=<span class="hljs-string">"text-base font-medium"</span>&gt;Communication emails&lt;/label&gt;
                &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
                  Receive emails about your account activity.
                &lt;/p&gt;
              &lt;/div&gt;
              {/* Toggle would go here, using a simple checkbox <span class="hljs-keyword">for</span> now */}
              &lt;Checkbox defaultChecked /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between rounded-lg border p-4"</span>&gt;
              &lt;div className=<span class="hljs-string">"space-y-0.5"</span>&gt;
                &lt;label className=<span class="hljs-string">"text-base font-medium"</span>&gt;Marketing emails&lt;/label&gt;
                &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
                  Receive emails about new products, features, and more.
                &lt;/p&gt;
              &lt;/div&gt;
              &lt;Checkbox /&gt;
            &lt;/div&gt;
          &lt;/CardContent&gt;
          &lt;CardFooter&gt;
            &lt;Button variant=<span class="hljs-string">"outline"</span>&gt;Update Preferences&lt;/Button&gt;
          &lt;/CardFooter&gt;
        &lt;/Card&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  )
}
</code></pre>
<p>In this page, we have created two sections:</p>
<ol>
<li><p>Profile Section</p>
</li>
<li><p>Notification Section</p>
</li>
</ol>
<p>These two sections have been built using shadcn/ui components like Card, Footer, Checkbox, Avatar, Input, and so on.</p>
<p>At this point, we have:</p>
<ul>
<li><p>A dashboard layout with sidebar, header, breadcrumbs, and footer</p>
</li>
<li><p>A Dashboard page with charts, insights, and a transaction table</p>
</li>
<li><p>A Products page powered by:</p>
<ul>
<li><p>TanStack Start server functions</p>
</li>
<li><p>TanStack Query</p>
</li>
<li><p>TanStack Table</p>
</li>
</ul>
</li>
<li><p>A clean Settings page using shadcn/ui components</p>
</li>
</ul>
<h2 id="heading-live-demo-amp-source-code">Live Demo &amp; Source Code</h2>
<p>You can check out the full source code on GitHub here:</p>
<ul>
<li><p>GitHub Repository: <a target="_blank" href="https://github.com/themeselection/tanstack-dashboard-demo">https://github.com/themeselection/tanstack-dashboard-demo</a></p>
</li>
<li><p>Live Demo: <a target="_blank" href="https://tanstack-dashboard-demo.vercel.app/dashboard">https://tanstack-dashboard-demo.vercel.app/dashboard</a></p>
</li>
</ul>
<p>Feel free to clone, experiment, and extend it to fit your own application needs!</p>
<h2 id="heading-summary">Summary</h2>
<p>Congratulations! You've built a complete, production-ready admin dashboard using TanStack Start, TanStack Table, TanStack Query, Shadcn/ui, and shadcn/studio.</p>
<p>Throughout this tutorial, you’ve gained some hands-on experience in:</p>
<ul>
<li><p><strong>Full-stack application development with type safety</strong>: We’ve developed a full-stack application with TanStack Start's server functions with Zod validation to create type-safe APIs.</p>
</li>
<li><p><strong>Advanced data fetching</strong>: We’ve implemented TanStack Query for data fetching with automatic caching and background updates.</p>
</li>
<li><p><strong>Complex table interactions</strong>: We’ve built feature-rich data tables with TanStack Table, including server-side pagination, sorting, and filtering.</p>
</li>
<li><p><strong>Building UI quicker</strong>: We’ve leveraged shadcn/ui and shadcn/studio blocks to quickly build polished interfaces.</p>
</li>
<li><p><strong>Responsive layouts</strong>: And we’ve created adaptive designs that work seamlessly from mobile to desktop</p>
</li>
</ul>
<h3 id="heading-whats-next">What’s Next?</h3>
<p>Now that you have a solid foundation, consider implementing some or all of the below features if you want to work more on this:</p>
<ul>
<li><p><strong>Authentication</strong>: Add user authentication with Clerk, NextAuth, or Auth.js</p>
</li>
<li><p><strong>Real database</strong>: Replace mock data with Prisma + PostgreSQL or Drizzle + SQLite</p>
</li>
<li><p><strong>Form validation</strong>: Integrate React Hook Form with Zod for robust form handling</p>
</li>
<li><p><strong>Theming</strong>: Implement dark mode and custom color schemes using shadcn/ui's theming system</p>
</li>
<li><p><strong>API routes for CRUD</strong>: Add CRUD operations for products (create, update, delete)</p>
</li>
<li><p><strong>Internationalization:</strong> Make the dashboard compatible with multiple languages by integrating internationalization.</p>
</li>
</ul>
<p>We shipped a scalable and production-ready dashboard much faster than starting from scratch. Hope you enjoyed the process – and thanks for reading!</p>
<h3 id="heading-resources">Resources:</h3>
<ul>
<li><p><a target="_blank" href="https://tanstack.com/start">TanStack Start Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://tanstack.com/table">TanStack Table Docs</a></p>
</li>
<li><p><a target="_blank" href="https://tanstack.com/query">TanStack Query Docs</a></p>
</li>
<li><p><a target="_blank" href="https://shadcnstudio.com/components">Shadcn UI Components</a></p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Set Up a Registry in shadcn ]]>
                </title>
                <description>
                    <![CDATA[ In this guide, you’ll learn how to set up a registry in shadcn. If you’re not familiar with this tool, shadcn is a collection of reusable and accessible components you can use in your projects. You’ll learn about essential concepts such as setting up... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-a-registry-in-shadcn/</link>
                <guid isPermaLink="false">68ff81486f611e7895c9f9ca</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcn ui ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Abhijeet Dave ]]>
                </dc:creator>
                <pubDate>Mon, 27 Oct 2025 14:27:20 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1761575215365/54597001-a10f-4a3d-a082-3eb5ac8b9a7d.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this guide, you’ll learn how to set up a registry in shadcn. If you’re not familiar with this tool, shadcn is a collection of reusable and accessible components you can use in your projects.</p>
<p>You’ll learn about essential concepts such as setting up and configuring the registry, adding authentication, CLI commands you can use, and more.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-a-registry-in-shadcn">What is a Registry in shadcn?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-create-and-configure-your-registry">How to Create and Configure Your Registry</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-namespace-system">Namespace System</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-authentication-for-private-registries">Authentication for Private Registries</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-cli-commands">CLI Commands</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-dependency-resolution">Dependency Resolution</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-error-handling">Error Handling</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-what-is-a-registry-in-shadcn"><strong>What is a registry in shadcn?</strong></h2>
<p>A <strong>registry</strong> in shadcn is a central place for sharing and managing your reusable components, utilities, and UI elements (along with other resources) across different projects. It lets developers give numbers to and organize components in a standard way. This makes it easier to integrate and share resources within and across teams.</p>
<p>The registry system helps make these components easily reusable. It also helps teams keep their code clean and manage dependencies more effectively.</p>
<p>shadcn's main system uses the <code>registry.json</code> file. The file provides key information about the registry, such as resource names and places along with the files that go with them.</p>
<h3 id="heading-why-use-a-shadcn-registry">Why use a shadcn registry?</h3>
<p>Using registries is helpful because it helps you standardize rules for your components. Every component, UI element, or utility follows a clear plan, which makes it easier to integrate and manage them.</p>
<p>Also, version numbers let you manage different versions of a component. This makes sure various parts work together and lets you update them without trouble.</p>
<p>Registries also give you the ability to organize resources into groups while managing what depends on what. Everything is flexible this way.</p>
<p>And if you create a registry, it lets you share your components with other developers (either everyone or just certain people). This allows for both inside and open-source work.</p>
<h2 id="heading-how-to-create-and-configure-your-registry">How to Create and Configure Your Registry</h2>
<p>Creating a shadcn registry involves setting up a configuration file (<code>registry.json</code>) at the root of your project. This file contains the metadata and structure of your registry, helping define components and their relationships.</p>
<p>shadcn provides this <a target="_blank" href="https://github.com/shadcn-ui/registry-template">starter template</a> to help you understand how registries work.</p>
<h3 id="heading-step-by-step-guide-to-create-a-registry">Step by Step Guide to Create a Registry</h3>
<h4 id="heading-1-define-the-registrys-metadata">1. Define the Registry's Metadata</h4>
<p>You’ll need to fill in the following information:</p>
<ul>
<li><p><code>name</code>: A unique name for the registry.</p>
</li>
<li><p><code>homepage</code>: A URL pointing to the homepage for the registry.</p>
</li>
<li><p><code>items</code>: An array that contains all available components, UI elements, or utilities in the registry.</p>
</li>
</ul>
<p>Here’s an example of a simple <code>registry.json</code>:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"$schema"</span>: <span class="hljs-string">"&lt;https://ui.shadcn.com/schema/registry.json&gt;"</span>,
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"acme"</span>,
  <span class="hljs-attr">"homepage"</span>: <span class="hljs-string">"&lt;https://acme.com&gt;"</span>,
  <span class="hljs-attr">"items"</span>: [
    <span class="hljs-comment">// Components will go here</span>
  ]
}
</code></pre>
<h4 id="heading-2-components-structure">2. Components Structure</h4>
<p>Each item in the registry can be a component, theme, hook, or utility. These items have the following properties:</p>
<ul>
<li><p><code>name</code>: Unique name of the component.</p>
</li>
<li><p><code>type</code>: Specifies the type of item (for example, <code>registry:component</code>, <code>registry:block</code>).</p>
</li>
<li><p><code>files</code>: An array of files that make up the component.</p>
</li>
</ul>
<p>Here’s an example:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"name"</span>,
  <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:block"</span>,
  <span class="hljs-attr">"title"</span>: <span class="hljs-string">"title"</span>,
  <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Simple description"</span>,
  <span class="hljs-attr">"files"</span>: [
    {
      <span class="hljs-attr">"path"</span>: <span class="hljs-string">"registry/new-york/..."</span>,
      <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:component"</span>
    }
  ]
}
</code></pre>
<p>This component contains a simple button. You can keep adding more components to the <code>items</code> array.</p>
<h4 id="heading-3-adding-components">3. Adding Components</h4>
<p>After creating the <code>registry.json</code> file, you can add components to the registry. These components can be UI elements, functions, or utilities.</p>
<p><strong>Example 1: Adding a Simple Button Component</strong></p>
<p>First, create the component file. You can define your component in a separate directory. For example, we will create a <code>HelloWorld</code> component.</p>
<pre><code class="lang-json"><span class="hljs-comment">// registry/new-york/hello-world/hello-world.tsx</span>
import { Button } from <span class="hljs-string">"@/components/ui/button"</span>

export function HelloWorld() {
  return &lt;Button&gt;Hello World&lt;/Button&gt;
}
</code></pre>
<p>Reference the component in your <code>registry.json</code> like this:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"hello-world"</span>,
  <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:block"</span>,
  <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Hello World"</span>,
  <span class="hljs-attr">"description"</span>: <span class="hljs-string">"A simple hello world component."</span>,
  <span class="hljs-attr">"files"</span>: [
    {
      <span class="hljs-attr">"path"</span>: <span class="hljs-string">"registry/new-york/hello-world/hello-world.tsx"</span>,
      <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:component"</span>
    }
  ]
}
</code></pre>
<p>The <code>"files"</code> key points to the path where the component is stored, while the <code>type</code> helps categorize the item.</p>
<p><strong>Example 2: Adding Multiple Components</strong></p>
<p>You can add multiple components to the registry as well. For instance, a button and a form could be part of a UI package:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"ui-kit"</span>,
  <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:block"</span>,
  <span class="hljs-attr">"title"</span>: <span class="hljs-string">"UI Kit"</span>,
  <span class="hljs-attr">"description"</span>: <span class="hljs-string">"A collection of basic UI components."</span>,
  <span class="hljs-attr">"files"</span>: [
    {
      <span class="hljs-attr">"path"</span>: <span class="hljs-string">"registry/ui-kit/button/button.tsx"</span>,
      <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:component"</span>
    },
    {
      <span class="hljs-attr">"path"</span>: <span class="hljs-string">"registry/ui-kit/form/form.tsx"</span>,
      <span class="hljs-attr">"type"</span>: <span class="hljs-string">"registry:component"</span>
    }
  ]
}
</code></pre>
<p>This modular approach allows for scalable development, enabling easy additions or updates to the registry without affecting other parts of the application.</p>
<blockquote>
<p>You can learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/getting-started">registry basics</a> in the shadcn UI docs.</p>
</blockquote>
<h2 id="heading-namespace-system"><strong>Namespace System</strong></h2>
<p>Namespaces in shadcn help arrange components, utilities, themes, or other resources. The goal is to avoid conflicts and provide a good structure for your resources.</p>
<h3 id="heading-what-is-a-namespace">What is a Namespace?</h3>
<p>A namespace groups resources under a plain identifier, usually prefixed with an '@'. With this, you can separate different types of resources, teams, or even public versus private components.</p>
<p><strong>For instance:</strong></p>
<ul>
<li><p><code>@shadcn/button</code> could represent a button component from shadcn's registry.</p>
</li>
<li><p><code>@acme/auth-utils</code> could represent authentication utilities developed by the Acme company.</p>
</li>
</ul>
<h3 id="heading-how-to-configure-multiple-registries-using-namespaces">How to Configure Multiple Registries Using Namespaces</h3>
<p>You can configure multiple registries under different namespaces, which helps organize resources by type or team:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"registries"</span>: {
    <span class="hljs-attr">"@acme-ui"</span>: <span class="hljs-string">"&lt;https://registry.acme.com/ui/{name}.json&gt;"</span>,
    <span class="hljs-attr">"@acme-docs"</span>: <span class="hljs-string">"&lt;https://registry.acme.com/docs/{name}.json&gt;"</span>,
    <span class="hljs-attr">"@acme-ai"</span>: <span class="hljs-string">"&lt;https://registry.acme.com/ai/{name}.json&gt;"</span>,
    <span class="hljs-attr">"@acme-internal"</span>: {
      <span class="hljs-attr">"url"</span>: <span class="hljs-string">"&lt;https://internal.acme.com/registry/{name}.json&gt;"</span>,
      <span class="hljs-attr">"headers"</span>: {
        <span class="hljs-attr">"Authorization"</span>: <span class="hljs-string">"Bearer ${INTERNAL_TOKEN}"</span>
      }
    }
  }
}
</code></pre>
<p>This setup allows you to:</p>
<ul>
<li><p>Keep UI components, documentation, AI resources, and internal libraries separate.</p>
</li>
<li><p>Easily manage public and private resources within the same registry configuration.</p>
</li>
</ul>
<p>You can learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/namespace#authentication--security"><strong>Namespace</strong></a> in the shadcn UI docs.</p>
<h2 id="heading-authentication-for-private-registries">Authentication for Private Registries</h2>
<p>If you have private registries, shadcn offers several authentication methods to ensure that only authorized users can access them. These include Bearer Token (OAuth 2.0), API Key, Basic Authentication, and Query Parameter Authentication. Let’s look at each one in more detail.</p>
<h3 id="heading-bearer-token-oauth-20">Bearer Token (OAuth 2.0)</h3>
<p>Bearer tokens are ideal for integrating with external APIs like GitHub or internal services that support OAuth 2.0.</p>
<p>You include the token in the <code>Authorization</code> header of the request. You typically get this token through an OAuth 2.0 flow, and it grants access to protected resources.</p>
<p>Here’s an example:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"@github"</span>: {
    <span class="hljs-attr">"url"</span>: <span class="hljs-string">"&lt;https://api.github.com/repos/org/registry/contents/{name}.json&gt;"</span>,
    <span class="hljs-attr">"headers"</span>: {
      <span class="hljs-attr">"Authorization"</span>: <span class="hljs-string">"Bearer ${GITHUB_TOKEN}"</span>
    }
  }
}
</code></pre>
<h3 id="heading-api-key">API Key</h3>
<p>You commonly use API keys for private NPM registries or internal APIs where a simple key is sufficient for access control.</p>
<p>An API key is included in the request headers, often under <code>X-API-Key</code>. This key is issued by the service and you should keep it confidential.</p>
<p><strong>Here’s an example</strong>:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"@private"</span>: {
    <span class="hljs-attr">"url"</span>: <span class="hljs-string">"&lt;https://api.company.com/registry/{name}&gt;"</span>,
    <span class="hljs-attr">"headers"</span>: {
      <span class="hljs-attr">"X-API-Key"</span>: <span class="hljs-string">"${API_KEY}"</span>
    }
  }
}
</code></pre>
<h3 id="heading-basic-authentication">Basic Authentication</h3>
<p>You’ll typically use basic authentication in legacy systems that require basic HTTP authentication.</p>
<p>The <code>Authorization</code> header contains a base64-encoded string of the format <code>username:password</code>. While it’s pretty easy to implement, it’s less secure than more modern methods like OAuth 2.0.</p>
<p><strong>Here’s an example</strong>:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"@internal"</span>: {
    <span class="hljs-attr">"url"</span>: <span class="hljs-string">"&lt;https://registry.company.com/{name}.json&gt;"</span>,
    <span class="hljs-attr">"headers"</span>: {
      <span class="hljs-attr">"Authorization"</span>: <span class="hljs-string">"Basic ${BASE64_CREDENTIALS}"</span>
    }
  }
}
</code></pre>
<h3 id="heading-query-parameter-authentication">Query Parameter Authentication</h3>
<p>Query parameter auth is a simpler form of authentication using query parameters for APIs.</p>
<p>It works by passing authentication details as query parameters in the URL. While this is convenient, it’s less secure than other methods since query parameters can be exposed in logs or URLs.</p>
<p><strong>Here’s an example:</strong></p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"@secure"</span>: {
    <span class="hljs-attr">"url"</span>: <span class="hljs-string">"&lt;https://registry.example.com/{name}.json&gt;"</span>,
    <span class="hljs-attr">"params"</span>: {
      <span class="hljs-attr">"api_key"</span>: <span class="hljs-string">"${API_KEY}"</span>,
      <span class="hljs-attr">"client_id"</span>: <span class="hljs-string">"${CLIENT_ID}"</span>,
      <span class="hljs-attr">"signature"</span>: <span class="hljs-string">"${REQUEST_SIGNATURE}"</span>
    }
  }
}
</code></pre>
<h3 id="heading-multiple-authentication-methods">Multiple Authentication Methods</h3>
<p>Some registries require multiple authentication methods simultaneously – for example, a combination of a Bearer token and an API key.</p>
<p>The request includes multiple headers and possibly query parameters to satisfy all required authentication mechanisms. This is common in enterprise environments where different layers of security are enforced.</p>
<p><strong>Here’s an example</strong>:</p>
<pre><code class="lang-bash">{
  <span class="hljs-string">"@enterprise"</span>: {
    <span class="hljs-string">"url"</span>: <span class="hljs-string">"https://api.enterprise.com/v2/registry/{name}"</span>,
    <span class="hljs-string">"headers"</span>: {
      <span class="hljs-string">"Authorization"</span>: <span class="hljs-string">"Bearer <span class="hljs-variable">${ACCESS_TOKEN}</span>"</span>,
      <span class="hljs-string">"X-API-Key"</span>: <span class="hljs-string">"<span class="hljs-variable">${API_KEY}</span>"</span>,
      <span class="hljs-string">"X-Workspace-Id"</span>: <span class="hljs-string">"<span class="hljs-variable">${WORKSPACE_ID}</span>"</span>
    },
    <span class="hljs-string">"params"</span>: {
      <span class="hljs-string">"version"</span>: <span class="hljs-string">"latest"</span>
    }
  }
}
</code></pre>
<p>You can learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/namespace#authentication--security"><strong>Authentication and Security</strong></a> in the shadcn UI docs.</p>
<h2 id="heading-cli-commands">CLI Commands</h2>
<p>The shadcn CLI lets you interact with the registry directly from the command line. With commands like <code>add</code>, <code>view</code>, <code>search</code>, and <code>list</code>, you can easily install and manage resources. Let’s look at some examples to see how this works.</p>
<h3 id="heading-install-resources-from-the-registry">Install Resources from the Registry</h3>
<p>Use the following commands to add resources to your project:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Install a specific component</span>
npx shadcn@latest add @acme/button

<span class="hljs-comment"># Install multiple components at once</span>
npx shadcn@latest add @acme/button @lib/utils @ai/prompt
</code></pre>
<p>These commands fetch the specified components from the registry and integrate them into your project, ensuring all necessary dependencies are also installed.</p>
<h3 id="heading-viewing-metadata">Viewing Metadata</h3>
<p>Before integrating a component, it's crucial to understand its structure and dependencies. The <code>view</code> command allows you to inspect a component's metadata:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># View a specific component</span>
npx shadcn@latest view @acme/button

<span class="hljs-comment"># View multiple components</span>
npx shadcn@latest view @acme/button @lib/utils @ai/prompt

<span class="hljs-comment"># View from a URL directly</span>
npx shadcn@latest view https://registry.example.com/button.json

<span class="hljs-comment"># View from a local file</span>
npx shadcn@latest view ./local-registry/button.json
</code></pre>
<p>So what does the <code>view</code> command display?</p>
<ul>
<li><p>Resource metadata: Information such as the component's name, type, and description.</p>
</li>
<li><p>Dependencies: Lists both direct and registry dependencies required by the component.</p>
</li>
<li><p>File contents: Displays the actual code that will be installed.</p>
</li>
<li><p>CSS variables and Tailwind configuration: Shows any styling configurations associated with the component.</p>
</li>
<li><p>Required environment variables: Lists any environment variables needed for the component to function correctly.</p>
</li>
</ul>
<p>This command is invaluable for reviewing a component's details before installation, ensuring compatibility and understanding its requirements.</p>
<h3 id="heading-searching-resources"><strong>Searching Resources</strong></h3>
<p>To discover components within a registry, you can use these commands:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Search a specific registry</span>
npx shadcn@latest search @v0

<span class="hljs-comment"># Search with a query</span>
npx shadcn@latest search @acme --query <span class="hljs-string">"auth"</span>

<span class="hljs-comment"># Search multiple registries</span>
npx shadcn@latest search @v0 @acme @lib

<span class="hljs-comment"># Limit results</span>
npx shadcn@latest search @v0 --<span class="hljs-built_in">limit</span> 10 --offset 20

<span class="hljs-comment"># List all items (alias for search)</span>
npx shadcn@latest list @acme
</code></pre>
<p>They help you find components based on criteria like registry, query terms, and result limits.</p>
<p>Learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/namespace#cli-commands"><strong>CLI Commands</strong></a> in the shadcn UI docs.</p>
<h2 id="heading-dependency-resolution">Dependency Resolution</h2>
<p>The CLI automatically resolves and installs all dependencies from their respective registries.</p>
<p>Understanding how dependencies are resolved internally is important if you're developing registries or need to customize third-party resources.</p>
<p>In shadcn, components often rely on other resources from various registries. When you install a component, shadcn ensures that all its dependencies are also installed, even if they reside in different registries. This process is known as <strong>dependency resolution</strong>.</p>
<h3 id="heading-what-does-it-mean-to-resolve-dependencies"><strong>What Does It Mean to "Resolve Dependencies"?</strong></h3>
<p>So to be clear resolving dependencies involves identifying, fetching, and installing dependencies.</p>
<p>First, shadcn determines which components a resource requires to function correctly. Then it retrieves these dependent components from their respective registries. Finally, it ensures that all dependencies are installed before the main component, maintaining the correct order.</p>
<p>This process guarantees that when you install a component, all its prerequisites are also installed, ensuring smooth functionality.</p>
<h3 id="heading-understanding-topological-sorting-in-dependency-resolution"><strong>Understanding Topological Sorting in Dependency Resolution</strong></h3>
<p><strong>Topological sorting</strong> might sound complicated, but it's essentially a method of organizing tasks (or components) in a way that makes sure everything gets done in the right order.</p>
<p>Imagine you have a list of tasks, and some tasks depend on others to be completed first. For example, you can't make a cake without first measuring out and then mixing the ingredients. So, the tasks “measure ingredients” and "mix ingredients" need to be completed before "bake the cake."</p>
<p>In the context of shadcn, topological sorting works in a similar way to organizing the installation of components:</p>
<ul>
<li><p>Each component (like <code>dashboard</code>) can depend on other components (like <code>@shadcn/card</code> or <code>@acme/data-table</code>).</p>
</li>
<li><p>Topological sorting arranges the components so that each one is installed only after the components it depends on have been installed.</p>
</li>
</ul>
<h4 id="heading-why-is-topological-sorting-important">Why Is Topological Sorting Important?</h4>
<p>Topological sorting takes care of a couple key things. First, it makes sure that components are installed in the correct order. For example, if Component A depends on Component B, then Component B will be installed first, followed by Component A.</p>
<p>It also prevents circular dependencies. If two components depend on each other, topological sorting detects this and prevents a never-ending loop (also called a circular dependency).</p>
<h4 id="heading-example-of-dependency-resolution">Example of Dependency Resolution:</h4>
<p>Consider the following component with its dependencies:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"dashboard"</span>,
  <span class="hljs-attr">"registryDependencies"</span>: [
    <span class="hljs-string">"@shadcn/card"</span>,
    <span class="hljs-string">"@v0/chart"</span>,
    <span class="hljs-string">"@acme/data-table"</span>
  ]
}
</code></pre>
<p>In this example, we have a <strong>component</strong>: <code>dashboard</code> and its <strong>dependencies</strong>: <code>@shadcn/card</code>, <code>@v0/chart</code>, and <code>@acme/data-table</code>.</p>
<p>In this case, shadcn will first identify the dependencies by recognizing that <code>dashboard</code> depends on <code>@shadcn/card</code>, <code>@v0/chart</code>, and <code>@acme/data-table</code>. Then it will fetch these components from their respective registries. Finally, it’ll install <code>@shadcn/card</code>, <code>@v0/chart</code>, and <code>@acme/data-table</code> first, before installing <code>dashboard</code>, ensuring all prerequisites are met.</p>
<p>You can learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/namespace#authentication--security">Dependency Resolution</a> in the shadcn UI docs.</p>
<h2 id="heading-error-handling"><strong>Error Handling</strong></h2>
<p>shadcn’s CLI is equipped to handle several types of errors. Here are some common scenarios and how to resolve them:</p>
<h3 id="heading-common-errors"><strong>Common Errors</strong></h3>
<p><strong>1. Unknown Registry</strong></p>
<p>This error occurs when the registry isn’t defined in the configuration.</p>
<p>Here’s an example:</p>
<pre><code class="lang-json">Error: Unknown registry <span class="hljs-string">"@non-existent"</span>
</code></pre>
<p><strong>Solution:</strong> To fix this, just add the registry in the <code>registries</code> section of your configuration.</p>
<p><strong>2. Missing Environment Variables</strong></p>
<p>If your registry requires certain environment variables that are not set, you'll get an error.</p>
<p>Here’s an example:</p>
<pre><code class="lang-json">Registry <span class="hljs-string">"@private"</span> requires REGISTRY_TOKEN
</code></pre>
<p><strong>Solution:</strong> To fix this, just add the required environment variables to <code>.env</code> or <code>.env.local</code>.</p>
<p><strong>3. 404 Not Found</strong></p>
<p>The resource may not exist or the URL could be incorrect.</p>
<p>Here’s an example:</p>
<pre><code class="lang-json">Error: The resource was not found at &lt;https:<span class="hljs-comment">//api.company.com/button.json&gt;</span>
</code></pre>
<p><strong>4. Authentication Failures (401/403)</strong></p>
<p>If you’re not authorized to access a resource, you’ll see 401 or 403 errors.</p>
<p>To fix this, make sure your tokens, API keys, or credentials are valid.</p>
<p>You can learn more about <a target="_blank" href="https://ui.shadcn.com/docs/registry/namespace#authentication--security">Error Handling</a> in the shadcn UI docs.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The shadcn registry system provides a good, modular solution for managing and sharing components or utilities across projects. If you’re looking to explore practical implementations, platforms like <a target="_blank" href="https://shadcnstudio.com/">shadcn/studio</a> which showcase how you can leverage <a target="_blank" href="https://shadcnstudio.com/components">shadcn components</a> to build sleek, modern UI solutions with minimal setup.</p>
<p>With its structured approach to dependencies, flexible namespaces, good authentication, and CLI commands, registries enable teams to share secure resources and customize them along the way.</p>
<p>I have prepared this article with the help of <a target="_blank" href="https://github.com/PruthviPraj00">Pruthvi Prajapati</a>, a front-end developer with 3 years of experience.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Make a Dropdown Menu with shadcn/ui ]]>
                </title>
                <description>
                    <![CDATA[ Dropdown menus are little pop-up menus that help you show more options without cluttering your screen. They’re super helpful in websites and apps. In this guide, you’ll learn how to build a dropdown menu using shadcn/ui. It’s a tool that works well w... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/shadcn-ui-dropdown-menu/</link>
                <guid isPermaLink="false">687964f6562b6ce291fda4e2</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ UI ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Kalal ]]>
                </dc:creator>
                <pubDate>Thu, 17 Jul 2025 21:02:46 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752786132476/fef60fd2-ad5e-4f9d-9dcf-de4b99adac99.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Dropdown menus are little pop-up menus that help you show more options without cluttering your screen. They’re super helpful in websites and apps.</p>
<p>In this guide, you’ll learn how to build a dropdown menu using shadcn/ui. It’s a tool that works well with Tailwind CSS and Radix UI to help you make nice-looking, easy-to-use menus.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-shadcnui">What is shadcn/ui?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-use-shadcnui-for-dropdowns">Why Use shadcn/ui for Dropdowns?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-lets-build-a-dropdown-step-by-step">Let’s Build a Dropdown Step-by-Step</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-step-1-start-a-new-project">Step 1: Start a New Project</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-2-add-the-dropdown-menu-component">Step 2: Add the Dropdown Menu Component</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-3-import-what-you-need">Step 3: Import What You Need</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-4-build-a-simple-dropdown">Step 4: Build a Simple Dropdown</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-5-make-it-look-better">Step 5: Make It Look Better</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-6-make-it-work-on-all-screens">Step 6: Make It Work on All Screens</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-7-add-cool-icons">Step 7: Add Cool Icons</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-8-its-already-accessible">Step 8: It’s Already Accessible!</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-real-world-use-case-country-dropdown-with-flags">Real-World Use Case: Country Dropdown with Flags</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-thoughts">Final Thoughts</a></p>
</li>
</ul>
<h3 id="heading-prerequisites">💡 Prerequisites</h3>
<p>Before we start, make sure you have:</p>
<ul>
<li><p>Basic knowledge of React and JavaScript</p>
</li>
<li><p>Node.js and a package manager like npm, pnpm, or yarn are installed</p>
</li>
<li><p>Familiarity with Tailwind CSS is a bonus, but not required</p>
</li>
</ul>
<p>We’ll walk through everything step by step, so don’t worry if you’re not an expert yet.</p>
<h2 id="heading-what-is-shadcnui">What is shadcn/ui?</h2>
<p><a target="_blank" href="https://ui.shadcn.com/docs/installation">shadcn/ui</a> is a group of tools (called components) that help you build parts of a website, like buttons, modals, and dropdowns. It’s built with Radix UI and styled using Tailwind CSS. It’s perfect if you’re using React or Next.js.</p>
<p>With shadcn/ui, you don’t get just styled components, you get full control over how everything works and looks. That makes it perfect for teams that want consistency in design without giving up flexibility.</p>
<h3 id="heading-why-use-shadcnui-for-dropdowns">Why Use shadcn/ui for Dropdowns?</h3>
<p>Dropdown menus are a great use case for shadcn/ui because:</p>
<ul>
<li><p>It’s easy to use with keyboard and screen readers</p>
</li>
<li><p>You can create custom looks using Tailwind CSS</p>
</li>
<li><p>You control how it works and looks</p>
</li>
<li><p>It works great in real websites and apps</p>
</li>
<li><p>It integrates well with modern React workflows</p>
</li>
</ul>
<h2 id="heading-lets-build-a-dropdown-step-by-step">Let’s Build a Dropdown Step-by-Step</h2>
<h3 id="heading-step-1-start-a-new-project-with-shadcnui">Step 1: Start a New Project with shadcn/ui</h3>
<p>You don’t need to set up React, Next.js, or Tailwind manually. Just run this command:</p>
<pre><code class="lang-bash">pnpm dlx shadcn@latest init
</code></pre>
<p>This will automatically create a new Next.js app with Tailwind CSS and shadcn/ui preconfigured.</p>
<p>Tip: You can also use <code>npx</code> instead of <code>pnpm dlx</code> if you prefer:</p>
<pre><code class="lang-bash">npx shadcn@latest init
</code></pre>
<h3 id="heading-step-2-add-the-dropdown-menu-component">Step 2: Add the Dropdown Menu Component</h3>
<p>After your project is ready, add the dropdown component using:</p>
<pre><code class="lang-bash">npx shadcn@latest add dropdown-menu
</code></pre>
<p>This will pull in all the necessary components to create a dropdown menu.</p>
<h3 id="heading-step-3-import-what-you-need">Step 3: Import What You Need</h3>
<p>In your React file, import the full dropdown module so you can access all its features:</p>
<pre><code class="lang-tsx">import {
  DropdownMenu,
  DropdownMenuTrigger,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuGroup,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuPortal,
} from "@/components/ui/dropdown-menu"
</code></pre>
<h3 id="heading-step-4-build-a-simple-dropdown">Step 4: Build a Simple Dropdown</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752690572839/4cb2bd61-b843-4fe3-8530-4b341d38a633.jpeg" alt="Screenshot of basic dropdown we're building" class="image--center mx-auto" width="630" height="577" loading="lazy"></p>
<p>Here’s a basic dropdown example:</p>
<pre><code class="lang-tsx">export function ProfileMenu() {
  return (
    &lt;DropdownMenu&gt;
      &lt;DropdownMenuTrigger asChild&gt;
        &lt;button className="px-4 py-2 bg-primary text-white rounded"&gt;
          Open Menu
        &lt;/button&gt;
      &lt;/DropdownMenuTrigger&gt;
      &lt;DropdownMenuContent className="w-56"&gt;
        &lt;DropdownMenuLabel&gt;My Account&lt;/DropdownMenuLabel&gt;
        &lt;DropdownMenuSeparator /&gt;
        &lt;DropdownMenuItem&gt;Profile&lt;/DropdownMenuItem&gt;
        &lt;DropdownMenuItem&gt;Settings&lt;/DropdownMenuItem&gt;
        &lt;DropdownMenuItem&gt;Log out&lt;/DropdownMenuItem&gt;
      &lt;/DropdownMenuContent&gt;
    &lt;/DropdownMenu&gt;
  )
}
</code></pre>
<p>This is just the start. You can add groups, submenus, and keyboard shortcuts for power users.</p>
<h3 id="heading-step-5-make-it-look-better">Step 5: Make It Look Better</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752690441156/0c2b8e39-72ca-4823-8dd2-6af305f02275.jpeg" alt="Screenshot showing dropdown with styling applied" class="image--center mx-auto" width="671" height="601" loading="lazy"></p>
<p>Use Tailwind CSS to style your dropdown, and hover effects like this:</p>
<pre><code class="lang-tsx">&lt;DropdownMenu&gt;
        &lt;DropdownMenuTrigger asChild&gt;
          &lt;button className="px-3 py-1.5 bg-primary text-white text-sm font-medium rounded-md hover:bg-primary/90 transition-colors"&gt;
            Open Menu
          &lt;/button&gt;
        &lt;/DropdownMenuTrigger&gt;
        &lt;DropdownMenuContent className="w-52 border-gray-200 shadow-lg rounded-md space-y-0.5"&gt;
          &lt;DropdownMenuLabel className="text-xs text-gray-500"&gt;
            My Account
          &lt;/DropdownMenuLabel&gt;
          &lt;DropdownMenuSeparator className="border-t border-gray-100" /&gt;
          &lt;DropdownMenuItem className="px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100 rounded-md cursor-pointer transition-colors"&gt;
            Profile
          &lt;/DropdownMenuItem&gt;
          &lt;DropdownMenuItem className="px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100 rounded-md cursor-pointer transition-colors"&gt;
            Settings
          &lt;/DropdownMenuItem&gt;
          &lt;DropdownMenuItem className="px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 rounded-md cur
</code></pre>
<h3 id="heading-step-6-make-it-work-on-all-screens">Step 6: Make It Work on All Screens</h3>
<p>Want your dropdown to be responsive? Use Tailwind’s responsive classes:</p>
<pre><code class="lang-tsx">&lt;DropdownMenuContent className="w-full md:w-64"&gt;
</code></pre>
<p>You can also dynamically position the dropdown using Radix's built-in portal support.</p>
<h3 id="heading-step-7-add-cool-icons">Step 7: Add Cool Icons</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752691587711/0a96c5ca-0fa2-4916-92d2-087f2071d40e.jpeg" alt="Screenshot of dropdown with icons added" class="image--center mx-auto" width="618" height="565" loading="lazy"></p>
<p>Install Lucide icons:</p>
<pre><code class="lang-bash">npm install lucide-react
</code></pre>
<p>Then use them in your menu:</p>
<pre><code class="lang-tsx">import { User, Settings, LogOut } from "lucide-react"

&lt;DropdownMenuItem&gt;
  &lt;User className="mr-2 h-4 w-4" /&gt; Profile
&lt;/DropdownMenuItem&gt;
</code></pre>
<p>Icons help users scan options quickly – a great touch for UX.</p>
<h3 id="heading-step-8-its-already-accessible">Step 8: It’s Already Accessible!</h3>
<p>shadcn/ui (thanks to Radix UI) makes your dropdown menu:</p>
<ul>
<li><p>Keyboard friendly</p>
</li>
<li><p>Screen-reader ready</p>
</li>
<li><p>Following best web practices</p>
</li>
</ul>
<p>You don’t need to configure accessibility – it just works :)</p>
<h2 id="heading-real-world-use-case-country-dropdown-with-flags">Real-World Use Case: Country Dropdown with Flags</h2>
<p>Looking for a more advanced dropdown? Here’s an amazing example that includes search, flag icons, and grouping:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752598285627/6cb8b27e-7cba-4d92-95c5-3bea44e0c01c.png" alt="Shadcn dropdown example" class="image--center mx-auto" width="879" height="483" loading="lazy"></p>
<p>👉 <a target="_blank" href="https://shadcn-country-dropdown.vercel.app/">shadcn-country-dropdown.vercel.app</a></p>
<p>It’s open-source and a great place to see what’s possible with shadcn/ui.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>Using shadcn/ui to create a dropdown menu is fast, simple, and powerful. You get great styling, accessibility, and full control over how things look and work. Whether you’re just starting out or building for production, this is a solid tool to use.</p>
<p>Dropdowns are just the beginning. shadcn/ui offers a whole library of headless components for building modern UIs.</p>
<p>I hope you found this article helpful! If you're building a SaaS product or any web app that involves user interaction or conversion, consider enhancing user trust with real-time notifications like modal pop-ups, <a target="_blank" href="http://toastie.saasindie.com">sales pop up</a>, etc.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Mastering Shadcn UI Components ]]>
                </title>
                <description>
                    <![CDATA[ We just published a course on the freeCodeCamp.org YouTube channel that will help you master Shadcn. This comprehensive course dives deep into the versatile world of Shadcn, a powerful toolset for building modern web applications with customizable an... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/mastering-shadcn-ui-components/</link>
                <guid isPermaLink="false">667ee3fd8663f80bd6d96481</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Fri, 28 Jun 2024 16:25:33 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719591920182/350c938e-9faa-4292-9a9c-826cbcf43bc7.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>We just published a course on the <a target="_blank" href="http://freeCodeCamp.org">freeCodeCamp.org</a> YouTube channel that will help you master Shadcn. This comprehensive course dives deep into the versatile world of Shadcn, a powerful toolset for building modern web applications with customizable and reusable components. Mathew from CodeByDesign designed this course.</p>
<h3 id="heading-what-is-shadcn">What is Shadcn?</h3>
<p>Shadcn is not your typical component library. Instead of installing it as a dependency through npm, Shadcn offers a collection of beautifully designed, accessible, and customizable React components that you can copy and paste directly into your project. This unique approach allows developers to have complete control over their components, enabling greater customization and integration flexibility.</p>
<p>The Shadcn components are designed to be easily integrated into any React or Next.js project. They come with built-in styling options and support theming through CSS variables or Tailwind CSS utility classes, making it simple to maintain a consistent look and feel across your application.</p>
<p>This course covers all the main UI components provided by Shadcn, offering a thorough introduction and practical examples to help you get started quickly.</p>
<h3 id="heading-why-learn-shadcn">Why Learn Shadcn?</h3>
<p>Shadcn offers a flexible and efficient way to build modern web applications with React and Next.js. By mastering Shadcn, you can:</p>
<ul>
<li><p>Speed up your development process by reusing high-quality, pre-built components.</p>
</li>
<li><p>Maintain complete control over your component styling and behavior.</p>
</li>
<li><p>Ensure your application is accessible and user-friendly with components designed with accessibility in mind.</p>
</li>
</ul>
<p>Whether you are a beginner looking to get started with React UI components or an experienced developer aiming to enhance your toolkit, this course provides valuable insights and practical knowledge to help you succeed. Watch the <a target="_blank" href="https://youtu.be/oidnyW71W0A">course on the freeCodeCamp.org YouTube channel</a> (3-hour watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/oidnyW71W0A" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
