Cnippet

Toggle

Buttons

About

A two-state toggle button built on Base UI's Toggle primitive. Ships default and outline variants, three sizes (sm, default, lg), controlled or uncontrolled pressed state via pressed / defaultPressed, disabled styling, and springy pressed feedback. Works as a single button or grouped into a formatting toolbar. Re-exports TogglePrimitive for advanced composition.

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

Code

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

Usage.tsx

"use client";

import { BookmarkCheckIcon, BookmarkIcon } from "lucide-react";
import { useState } from "react";
import { Toggle } from "@/components/ui/cnippet-toggle";

export default function ToggleBookmark() {
  const [pressed, setPressed] = useState(false);

  return (
    <div className="flex items-center justify-center">
      <Toggle
        aria-label="Toggle bookmark"
        onPressedChange={setPressed}
        pressed={pressed}
        variant="outline"
      >
        {pressed ? (
          <BookmarkCheckIcon className="fill-current" />
        ) : (
          <BookmarkIcon />
        )}
        {pressed ? "Bookmarked" : "Bookmark"}
      </Toggle>
    </div>
  );
}

Dependencies

More by Cnippet

View all
  • Team

    Team

    1.3K
  • Davincho Hero-1

    Davincho Hero-1

    686
  • Aero Hero-3

    Aero Hero-3

    576
  • Features

    Features

    514
  • Random Letter Swap Navigation

    Random Letter Swap Navigation

    496
  • Services with Animated Hover Modal

    Services with Animated Hover Modal

    468
  • Blogs

    Blogs

    397
  • Aero Hero-1

    Aero Hero-1

    363

More in Buttons

View all
  • Button

    Button

    5
  • Texture Button

    Texture Button

    97
  • Button Group

    Button Group

  • Eclipse Button

    Eclipse Button

    39
  • Button

    Button

    4
  • HeroUI Button Group

    HeroUI Button Group

  • Base Button

    Base Button

    4
  • App Store Button

    App Store Button

    458