# V toggle 10

> Role Filter Chips with Live Count

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/v-toggle-10).

- Page, with a live preview: https://shadcn.exchange/r/cnippet/v-toggle-10
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/cnippet/v-toggle-10-light-3e3256443f0910c0.png
- Registry item: https://ui.cnippet.dev/r/v-toggle-10.json
- Categories: toggle
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.cnippet.dev/r/v-toggle-10.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `@cnippet/toggle`

## Files

### `registry/default/variants/v-toggle-10.tsx`

```tsx
"use client";

import { SlidersHorizontalIcon } from "lucide-react";
import { useState } from "react";

import { Badge } from "@/registry/default/ui/badge";
import { Toggle } from "@/registry/default/ui/toggle";

const filters = [
  { count: 24, id: "design", label: "Design" },
  { count: 41, id: "engineering", label: "Engineering" },
  { count: 18, id: "product", label: "Product" },
  { count: 12, id: "marketing", label: "Marketing" },
  { count: 7, id: "leadership", label: "Leadership" },
  { count: 9, id: "research", label: "Research" },
];

export function Pattern() {
  const [active, setActive] = useState<Set<string>>(new Set());

  const toggle = (id: string) =>
    setActive((prev) => {
      const next = new Set(prev);
      next.has(id) ? next.delete(id) : next.add(id);
      return next;
    });

  const totalResults =
    active.size === 0
      ? filters.reduce((sum, f) => sum + f.count, 0)
      : filters
          .filter((f) => active.has(f.id))
          .reduce((sum, f) => sum + f.count, 0);

  return (
    <div className="w-full max-w-sm space-y-3">
      <div className="flex items-center justify-between">
        <div className="flex items-center gap-1.5 text-muted-foreground text-sm">
          <SlidersHorizontalIcon className="size-3.5" />
          <span>Filter by role</span>
        </div>
        <div className="flex items-center gap-1.5">
          <span className="text-muted-foreground text-xs">
            {totalResults} results
          </span>
          {active.size > 0 && (
            <button
              className="text-muted-foreground text-xs underline-offset-2 hover:text-foreground hover:underline"
              onClick={() => setActive(new Set())}
              type="button"
            >
              Clear
            </button>
          )}
        </div>
      </div>

      <div className="flex flex-wrap gap-2">
        {filters.map((filter) => {
          const isActive = active.has(filter.id);
          return (
            <Toggle
              aria-label={`Filter by ${filter.label}`}
              className="gap-1.5 rounded-full"
              key={filter.id}
              onPressedChange={() => toggle(filter.id)}
              pressed={isActive}
              size="sm"
              variant="outline"
            >
              {filter.label}
              <Badge
                className={`transition-colors ${isActive ? "bg-primary-foreground/20 text-current" : ""}`}
                size="sm"
                variant={isActive ? "default" : "outline"}
              >
                {filter.count}
              </Badge>
            </Toggle>
          );
        })}
      </div>
    </div>
  );
}
```
