Skip to content
← Blocks

Workspace Navigation

A working workspace navigation with illustrative data and frontend interactions.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/workspace-navigation.json

Use it

Scroll horizontally for long lines
"use client";
import { WorkspaceNavigation } from "@/components/jez-ui/blocks/workspace-navigation";

export default function Example() {
  return (
    <>
      <WorkspaceNavigation />
    </>
  );
}

Compose your own

These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.

Scroll horizontally for long lines
"use client";
import {
  WorkspaceNavigation,
  WorkspaceNavigationToolbar,
  WorkspaceNavigationViews,
  WorkspaceNavigationStatus,
} from "@/components/jez-ui/blocks/workspace-navigation";

export default function Example() {
  return (
    <WorkspaceNavigation>
      <WorkspaceNavigationToolbar />
      <WorkspaceNavigationViews />
      <WorkspaceNavigationStatus />
    </WorkspaceNavigation>
  );
}
Scroll horizontally for long lines
import { WorkspaceNavigation, WorkspaceNavigationHeader, WorkspaceNavigationContent, WorkspaceNavigationItem, WorkspaceNavigationToolbar, WorkspaceNavigationViews, WorkspaceNavigationStatus } from "@/components/jez-ui/blocks/workspace-navigation";
Read the composition guide →

Props & types

Scroll horizontally for long lines
export type WorkspaceNavigationOptions = {
  className?: string;
  onViewChange?: (view: string) => void;
  onCreate?: () => void;
  items?: typeof WorkspaceNavigationDefaultItems;
  views?: typeof WorkspaceNavigationDefaultViews;
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
};

export type WorkspaceNavigationProps = Omit<
  React.ComponentProps<"div">,
  keyof WorkspaceNavigationOptions
> &
  WorkspaceNavigationOptions;

WorkspaceNavigationProps

Source

View 4 source files

registry/blocks/workspace-navigation.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import {
  Layers,
  ChevronRight,
  Plus,
  LayoutGrid,
  List,
  CalendarDays,
  Settings2,
} from "lucide-react";
import { useControllable } from "../ui/use-controllable";
import { cn } from "../ui/utils";
import { Button } from "../ui/button";
export type WorkspaceNavigationOptions = {
  className?: string;
  onViewChange?: (view: string) => void;
  onCreate?: () => void;
  items?: typeof WorkspaceNavigationDefaultItems;
  views?: typeof WorkspaceNavigationDefaultViews;
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
};
export type WorkspaceNavigationProps = Omit<
  React.ComponentProps<"div">,
  keyof WorkspaceNavigationOptions
> &
  WorkspaceNavigationOptions;
const WorkspaceNavigationDefaultItems = ["AM", "SP", "RL"];
const WorkspaceNavigationDefaultViews = [
  { label: "Board", icon: LayoutGrid },
  { label: "List", icon: List },
  { label: "Calendar", icon: CalendarDays },
  { label: "Settings", icon: Settings2 },
];
function useWorkspaceNavigationModel({
  value: suppliedValue,
  defaultValue = "Board",
  onValueChange,
  items = WorkspaceNavigationDefaultItems,
  views = WorkspaceNavigationDefaultViews,
  className,
  onViewChange,
  onCreate,
  children,
  ...rootProps
}: WorkspaceNavigationProps) {
  const [view, setView] = useControllable<string>(
    suppliedValue,
    defaultValue,
    onValueChange,
  );
  const [notice, setNotice] = React.useState("");
  return {
    suppliedValue,
    defaultValue,
    onValueChange,
    items,
    views,
    className,
    onViewChange,
    onCreate,
    children,
    rootProps,
    view,
    setView,
    notice,
    setNotice,
  };
}
const WorkspaceNavigationCompositionContext = React.createContext<ReturnType<
  typeof useWorkspaceNavigationModel
> | null>(null);
function useWorkspaceNavigationComposition() {
  const context = React.useContext(WorkspaceNavigationCompositionContext);
  if (!context)
    throw new Error(
      "WorkspaceNavigation parts must be inside WorkspaceNavigation.",
    );
  return context;
}
export function WorkspaceNavigation(props: WorkspaceNavigationProps) {
  const model = useWorkspaceNavigationModel(props);
  const { className, rootProps, children } = model;
  return (
    <WorkspaceNavigationCompositionContext.Provider value={model}>
      <div
        {...rootProps}
        className={cn(
          "rounded-xl border border-border bg-background",
          className,
        )}
      >
        {children !== undefined ? (
          children
        ) : (
          <>
            <WorkspaceNavigationToolbar />
            <WorkspaceNavigationViews />
            <WorkspaceNavigationStatus />
          </>
        )}
      </div>
    </WorkspaceNavigationCompositionContext.Provider>
  );
}

export function WorkspaceNavigationHeader({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-navigation-header"
      className={cn(
        "flex flex-wrap items-center justify-between gap-4 px-5 py-4",
        className,
      )}
      {...props}
    />
  );
}
export function WorkspaceNavigationContent({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-navigation-content"
      className={cn(
        "flex gap-5 overflow-x-auto border-t border-border px-5",
        className,
      )}
      {...props}
    />
  );
}

export function WorkspaceNavigationItem({
  className,
  ...props
}: React.ComponentProps<"button">) {
  return (
    <button
      type="button"
      data-slot="workspace-navigation-item"
      className={cn(
        "flex shrink-0 items-center gap-2 border-b-2 py-3 text-sm",
        className,
      )}
      {...props}
    />
  );
}

export function WorkspaceNavigationToolbar({
  children,
  ...props
}: Partial<React.ComponentProps<typeof WorkspaceNavigationHeader>> & {
  children?: React.ReactNode;
}) {
  const { items, onCreate, setNotice } = useWorkspaceNavigationComposition();
  return (
    <WorkspaceNavigationHeader {...props}>
      {children === undefined ? (
        <>
          <div className="flex min-w-0 items-center gap-2.5 text-sm">
            <Layers size={18} />
            <span className="text-muted-foreground">Acme</span>
            <ChevronRight size={13} className="text-muted-foreground" />
            <span className="truncate font-medium">Website refresh</span>
          </div>
          <div className="flex items-center gap-3">
            <div className="hidden -space-x-2 sm:flex">
              {items.map((v) => (
                <span
                  key={v}
                  className="grid size-7 place-items-center rounded-full border-2 border-background bg-muted text-xs"
                >
                  {v}
                </span>
              ))}
            </div>
            <Button
              size="sm"
              onClick={() => {
                if (onCreate) onCreate();
                else setNotice("New project action selected.");
              }}
            >
              <Plus size={14} />
              New project
            </Button>
          </div>
        </>
      ) : (
        children
      )}
    </WorkspaceNavigationHeader>
  );
}
export function WorkspaceNavigationViews({
  children,
  ...props
}: Partial<React.ComponentProps<typeof WorkspaceNavigationContent>> & {
  children?: React.ReactNode;
}) {
  const { views, onViewChange, view, setView } =
    useWorkspaceNavigationComposition();
  return (
    <WorkspaceNavigationContent
      role="tablist"
      aria-label="Project view"
      {...props}
    >
      {children === undefined
        ? views.map((item, i) => (
            <WorkspaceNavigationItem
              key={item.label}
              role="tab"
              aria-selected={view === item.label}
              tabIndex={view === item.label ? 0 : -1}
              onKeyDown={(e) => {
                if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
                  e.preventDefault();
                  const siblings =
                    e.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(
                      '[role="tab"]',
                    );
                  const next =
                    siblings?.[(i + (e.key === "ArrowRight" ? 1 : 3)) % 4];
                  next?.focus();
                  next?.click();
                }
              }}
              onClick={() => {
                setView(item.label);
                onViewChange?.(item.label);
              }}
              className={cn(
                view === item.label
                  ? "border-primary font-medium"
                  : "border-transparent text-muted-foreground hover:text-foreground",
              )}
            >
              <item.icon size={15} />
              {item.label}
            </WorkspaceNavigationItem>
          ))
        : children}
    </WorkspaceNavigationContent>
  );
}
export function WorkspaceNavigationStatus({
  children,
}: React.PropsWithChildren) {
  const { notice } = useWorkspaceNavigationComposition();
  return children === undefined
    ? notice && (
        <p
          role="status"
          className="border-t border-border p-4 text-xs text-muted-foreground"
        >
          {notice}
        </p>
      )
    : children;
}

registry/ui/use-controllable.ts

Scroll horizontally for long lines
"use client";
import { useRef, useState, type SetStateAction } from "react";
/** Controlled or instance-local state. Functional updates also work before a rerender. */
export function useControllable<T>(
  value: T | undefined,
  initial: T,
  onChange?: (value: T) => void,
) {
  const [local, setLocal] = useState(initial);
  const current = useRef(value === undefined ? local : value);
  current.current = value === undefined ? local : value;
  return [
    current.current,
    (action: SetStateAction<T>) => {
      const next =
        typeof action === "function"
          ? (action as (previous: T) => T)(current.current)
          : action;
      current.current = next;
      if (value === undefined) setLocal(next);
      onChange?.(next);
    },
  ] as const;
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

registry/ui/button.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ComponentProps<"button"> & {
  variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
  size?: "sm" | "md" | "lg";
  loading?: boolean;
  asChild?: boolean;
};
export function Button({
  variant = "primary",
  size = "md",
  loading,
  asChild,
  className,
  children,
  disabled,
  ...props
}: ButtonProps) {
  const Comp = asChild ? Slot.Root : "button";
  return (
    <Comp
      type={asChild ? undefined : "button"}
      disabled={asChild ? undefined : disabled || loading}
      aria-disabled={disabled || loading || undefined}
      aria-busy={loading || undefined}
      className={cn(
        "relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
        {
          "bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
            variant === "primary",
          "border-border/60 bg-muted text-foreground hover:bg-muted/70":
            variant === "secondary",
          "border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
            variant === "outline",
          "text-muted-foreground hover:bg-muted hover:text-foreground":
            variant === "ghost",
          "bg-danger text-danger-foreground hover:bg-danger/90":
            variant === "danger",
        },
        {
          "h-8 px-3 text-xs": size === "sm",
          "h-10 px-4": size === "md",
          "h-12 px-6": size === "lg",
        },
        className,
      )}
      {...props}
    >
      {asChild ? (
        children
      ) : (
        <>
          <span
            className={cn(
              "inline-flex min-w-0 flex-1 items-center justify-center gap-2",
              loading && "invisible",
            )}
          >
            {children}
          </span>
          {loading && (
            <LoaderCircle
              aria-hidden="true"
              className="absolute size-4 animate-spin motion-reduce:animate-none"
            />
          )}
        </>
      )}
    </Comp>
  );
}

Dependencies

lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · radix-ui@1.6.7

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →