DesignX
Core@paxeer/core/tabsimplemented

Tabs

shadcn Tabs restyled to MD3.

Install

$pnpm exec designx add @paxeer/core/tabs

Source code

components/designx/core/tabs.tsxtsx
"use client";

import { cva, type VariantProps } from "class-variance-authority";
import { type ComponentProps } from "react";
import { Tabs as TabsPrimitive } from "radix-ui";
import { cn } from "../lib/cn";

/** Adapted from shadcn/ui Tabs. */

export function Tabs({
  className,
  orientation = "horizontal",
  ...props
}: ComponentProps<typeof TabsPrimitive.Root>) {
  return (
    <TabsPrimitive.Root
      data-slot="tabs"
      data-orientation={orientation}
      orientation={orientation}
      className={cn("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col", className)}
      {...props}
    />
  );
}

const tabsListVariants = cva(
  "group/tabs-list inline-flex w-fit items-center justify-center rounded-[var(--md-sys-shape-corner-small)] p-[3px] text-on-surface-variant group-data-[orientation=horizontal]/tabs:h-10",
  {
    variants: {
      variant: {
        default: "bg-surface-container-highest",
        line: "gap-1 bg-transparent",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  },
);

export function TabsList({
  className,
  variant = "default",
  ...props
}: ComponentProps<typeof TabsPrimitive.List> & VariantProps<typeof tabsListVariants>) {
  return (
    <TabsPrimitive.List
      data-slot="tabs-list"
      data-variant={variant}
      className={cn(tabsListVariants({ variant }), className)}
      {...props}
    />
  );
}

export function TabsTrigger({
  className,
  ...props
}: ComponentProps<typeof TabsPrimitive.Trigger>) {
  return (
    <TabsPrimitive.Trigger
      data-slot="tabs-trigger"
      className={cn(
        "dx-focus-ring relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-[var(--md-sys-shape-corner-extra-small)] px-3 py-1 text-[length:var(--md-sys-typescale-label-large-size)] font-medium text-on-surface-variant data-[state=active]:bg-surface-container-lowest data-[state=active]:text-on-surface data-[state=active]:shadow-[inset_0_-2px_0_var(--md-sys-color-primary)]",
        className,
      )}
      {...props}
    />
  );
}

export function TabsContent({
  className,
  ...props
}: ComponentProps<typeof TabsPrimitive.Content>) {
  return (
    <TabsPrimitive.Content
      data-slot="tabs-content"
      className={cn("flex-1 outline-none", className)}
      {...props}
    />
  );
}

export { tabsListVariants };

Dependencies

npm packages

radix-ui

Registry dependencies