# Filter chips

> Pill-shaped filters you can switch on and off, each one showing a small check mark as it activates.

- Category: [Filters](https://library.aimran.es/components/filters)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/filter-chips
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Chips are the quickest way to let people narrow a list without opening a menu: cuisine types on a recipe site, sizes in a clothing shop, topics on a blog or skills on a job board. These filter chips allow several choices at once, and the check mark makes it obvious what is switched on.

They work best with up to eight short labels, one or two words each. If you have dozens of options, move them into a dropdown with search instead. Use the small size inside cards and the large one on mobile, where fingers need room.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Check } from "lucide-react";

const sizeMap = {
  sm: { pad: "px-3 py-1.5", text: "text-xs" },
  md: { pad: "px-4 py-2", text: "text-sm" },
  lg: { pad: "px-5 py-2.5", text: "text-base" },
} as const;

interface FilterChipsProps {
  accent?: string;
  size?: keyof typeof sizeMap;
  options?: string[];
  value?: string[];
  onChange?: (value: string[]) => void;
}

export default function FilterChips({
  accent = "#0071e3",
  size = "md",
  options = ["Design", "Code", "Audio", "Video", "3D"],
  value,
  onChange,
}: FilterChipsProps) {
  const [internal, setInternal] = useState<string[]>(options.slice(0, 1));
  const active = value ?? internal;
  const s = sizeMap[size];

  const toggle = (o: string) => {
    const next = active.includes(o) ? active.filter((x) => x !== o) : [...active, o];
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="flex w-full max-w-md flex-wrap justify-center gap-2">
      {options.map((o) => {
        const on = active.includes(o);
        return (
          <motion.button
            key={o}
            type="button"
            aria-pressed={on}
            whileTap={{ scale: 0.94 }}
            onClick={() => toggle(o)}
            className={`flex items-center gap-1.5 rounded-full border font-medium transition-colors ${s.pad} ${s.text}`}
            style={{
              borderColor: on ? accent : "oklch(1 0 0 / 14%)",
              backgroundColor: on ? `${accent}22` : "transparent",
              color: on ? accent : undefined,
            }}
          >
            <AnimatePresence initial={false}>
              {on && (
                <motion.span
                  initial={{ width: 0, opacity: 0 }}
                  animate={{ width: "auto", opacity: 1 }}
                  exit={{ width: 0, opacity: 0 }}
                  className="overflow-hidden"
                >
                  <Check className="h-3.5 w-3.5" />
                </motion.span>
              )}
            </AnimatePresence>
            {o}
          </motion.button>
        );
      })}
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Filter chips” block (Filters) from AIMRAN Library to my project.

## What it is
Pill-shaped filters you can switch on and off, each one showing a small check mark as it activates.

## Chosen settings
- Accent color: #0071e3
- Number of options: 5 (from 2 to 8)
- Size: Medium (other options: Small, Large)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { Check } from "lucide-react";

const sizeMap = {
  sm: { pad: "px-3 py-1.5", text: "text-xs" },
  md: { pad: "px-4 py-2", text: "text-sm" },
  lg: { pad: "px-5 py-2.5", text: "text-base" },
} as const;

interface FilterChipsProps {
  accent?: string;
  size?: keyof typeof sizeMap;
  options?: string[];
  value?: string[];
  onChange?: (value: string[]) => void;
}

export default function FilterChips({
  accent = "#0071e3",
  size = "md",
  options = ["Design", "Code", "Audio", "Video", "3D"],
  value,
  onChange,
}: FilterChipsProps) {
  const [internal, setInternal] = useState<string[]>(options.slice(0, 1));
  const active = value ?? internal;
  const s = sizeMap[size];

  const toggle = (o: string) => {
    const next = active.includes(o) ? active.filter((x) => x !== o) : [...active, o];
    if (value === undefined) setInternal(next);
    onChange?.(next);
  };

  return (
    <div className="flex w-full max-w-md flex-wrap justify-center gap-2">
      {options.map((o) => {
        const on = active.includes(o);
        return (
          <motion.button
            key={o}
            type="button"
            aria-pressed={on}
            whileTap={{ scale: 0.94 }}
            onClick={() => toggle(o)}
            className={`flex items-center gap-1.5 rounded-full border font-medium transition-colors ${s.pad} ${s.text}`}
            style={{
              borderColor: on ? accent : "oklch(1 0 0 / 14%)",
              backgroundColor: on ? `${accent}22` : "transparent",
              color: on ? accent : undefined,
            }}
          >
            <AnimatePresence initial={false}>
              {on && (
                <motion.span
                  initial={{ width: 0, opacity: 0 }}
                  animate={{ width: "auto", opacity: 1 }}
                  exit={{ width: 0, opacity: 0 }}
                  className="overflow-hidden"
                >
                  <Check className="h-3.5 w-3.5" />
                </motion.span>
              )}
            </AnimatePresence>
            {o}
          </motion.button>
        );
      })}
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
