erictsai83

Expandable Toolbar

Buttons

About

A controlled or uncontrolled toolbar primitive that measures its action slot and expands from either side.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Expandable Toolbar to your project and fits it to your theme.

Code

How Expandable Toolbar is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import type { ComponentProps, ReactNode } from "react";
import {
  ChevronsLeft,
  ChevronsLeftRight,
  ChevronsRight,
  ChevronsRightLeft,
  FilePlus2,
  FolderPlus,
  Mail,
  UserPlus,
} from "lucide-react";

import { Button } from "@/components/ui/button";
import { ExpandableToolbar } from "@/components/ui/ericts-expandable-toolbar";

type ToolbarSide = NonNullable<
  ComponentProps<typeof ExpandableToolbar>["side"]
>;

const DEMOS: {
  side: ToolbarSide;
  caption: string;
  expandIcon: ReactNode;
  collapseIcon: ReactNode;
}[] = [
  {
    side: "start",
    caption: 'side="start" — grows left',
    expandIcon: <ChevronsLeft aria-hidden />,
    collapseIcon: <ChevronsRight aria-hidden />,
  },
  {
    side: "center",
    caption: 'side="center" — grows both ways',
    expandIcon: <ChevronsLeftRight aria-hidden />,
    collapseIcon: <ChevronsRightLeft aria-hidden />,
  },
  {
    side: "end",
    caption: 'side="end" — grows right',
    expandIcon: <ChevronsRight aria-hidden />,
    collapseIcon: <ChevronsLeft aria-hidden />,
  },
];

// Returned as an array (not a fragment): side="center" splits the toolbar's
// direct children between its two panels, and a fragment would arrive as a
// single child.
function toolbarActions() {
  return [
    <Button
      key="file"
      type="button"
      variant="ghost"
      size="icon-sm"
      aria-label="New file"
    >
      <FilePlus2 aria-hidden />
    </Button>,
    <Button
      key="folder"
      type="button"
      variant="ghost"
      size="icon-sm"
      aria-label="New folder"
    >
      <FolderPlus aria-hidden />
    </Button>,
    <Button
      key="invite"
      type="button"
      variant="ghost"
      size="icon-sm"
      aria-label="Invite teammate"
    >
      <UserPlus aria-hidden />
    </Button>,
    <Button
      key="mail"
      type="button"
      variant="ghost"
      size="icon-sm"
      aria-label="Send invite"
    >
      <Mail aria-hidden />
    </Button>,
  ];
}

export default function Preview() {
  return (
    <div className="flex min-h-72 w-full flex-col items-center justify-center gap-9">
      {DEMOS.map(({ side, caption, expandIcon, collapseIcon }) => (
        <div key={side} className="flex flex-col items-center gap-2.5">
          {/* anchor="trigger" keeps each row's layout fixed while the toolbar
              overlays outward in its own direction. */}
          <ExpandableToolbar
            side={side}
            anchor="trigger"
            expandIcon={expandIcon}
            collapseIcon={collapseIcon}
            expandLabel={`Show quick actions (${side})`}
            collapseLabel={`Hide quick actions (${side})`}
          >
            {toolbarActions()}
          </ExpandableToolbar>
          <p className="font-mono text-[11px] font-medium text-muted-foreground">
            {caption}
          </p>
        </div>
      ))}
    </div>
  );
}

Dependencies

More by erictsai83

View all
  • Adaptive Drawer

    Adaptive Drawer

  • Status Button

    Status Button

  • Floating Shortcut Button

    Floating Shortcut Button

  • Filter Tags

    Filter Tags

  • Feedback Popover

    Feedback Popover

  • Expandable Toggle Button

    Expandable Toggle Button

  • Arc Menu

    Arc Menu

  • Multi-Step Flow

    Multi-Step Flow

More in Buttons

View all
  • Button

    Button

    166
  • Texture Button

    Texture Button

    121
  • Button

    Button

    21
  • Figma File Button

    Figma File Button

    39
  • Native Button

    Native Button

    12
  • Button

    Button

    88
  • HeroUI Button Group

    HeroUI Button Group

    11
  • Great UI Button

    Great UI Button

    19