# Icon category bar

> Categories shown as icons with labels, and an underline that slides across to the one you pick.

- Category: [Navigation](https://library.aimran.es/components/navigation)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/icon-category-bar
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Rental and marketplace sites use this pattern to let people browse by type before they search: cabins, beach houses, city breaks, design stays. It also works for a shop with product families or a recipe site sorted by meal. The sliding underline makes the choice clear, and the icon category bar reads well even at a glance.

Choose icons that really match each label, and keep the labels to one word. With more than six or seven categories, let the bar scroll sideways on mobile instead of squeezing everything into one line.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { motion } from "framer-motion";
import { Calendar, Compass, Home, Layers } from "lucide-react";

const spring = { type: "spring" as const, stiffness: 300, damping: 30 };

const ITEMS = [
  { icon: Home, label: "Homes" },
  { icon: Compass, label: "Nature" },
  { icon: Calendar, label: "Getaways" },
  { icon: Layers, label: "Design" },
];

interface CategoryBarProps {
  color?: string;
}

export default function CategoryBar({ color = "#0071e3" }: CategoryBarProps) {
  const [active, setActive] = useState(0);

  return (
    <div className="flex gap-7 border-b border-black/10 dark:border-white/10">
      {ITEMS.map(({ icon: Icon, label }, i) => (
        <button
          key={label}
          type="button"
          aria-pressed={active === i}
          onClick={() => setActive(i)}
          className="relative flex flex-col items-center gap-1.5 pb-3 text-xs text-[#86868b]"
        >
          <Icon className="h-5 w-5" style={{ color: active === i ? color : undefined }} />
          <span>{label}</span>
          {active === i && (
            <motion.i
              layoutId="cat-line"
              className="absolute inset-x-0 -bottom-px h-0.5"
              style={{ backgroundColor: color }}
              transition={spring}
            />
          )}
        </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 “Icon category bar” block (Navigation) from AIMRAN Library to my project.

## What it is
Categories shown as icons with labels, and an underline that slides across to the one you pick.

## Chosen settings
- Accent: #0071e3

## 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 { motion } from "framer-motion";
import { Calendar, Compass, Home, Layers } from "lucide-react";

const spring = { type: "spring" as const, stiffness: 300, damping: 30 };

const ITEMS = [
  { icon: Home, label: "Homes" },
  { icon: Compass, label: "Nature" },
  { icon: Calendar, label: "Getaways" },
  { icon: Layers, label: "Design" },
];

interface CategoryBarProps {
  color?: string;
}

export default function CategoryBar({ color = "#0071e3" }: CategoryBarProps) {
  const [active, setActive] = useState(0);

  return (
    <div className="flex gap-7 border-b border-black/10 dark:border-white/10">
      {ITEMS.map(({ icon: Icon, label }, i) => (
        <button
          key={label}
          type="button"
          aria-pressed={active === i}
          onClick={() => setActive(i)}
          className="relative flex flex-col items-center gap-1.5 pb-3 text-xs text-[#86868b]"
        >
          <Icon className="h-5 w-5" style={{ color: active === i ? color : undefined }} />
          <span>{label}</span>
          {active === i && (
            <motion.i
              layoutId="cat-line"
              className="absolute inset-x-0 -bottom-px h-0.5"
              style={{ backgroundColor: color }}
              transition={spring}
            />
          )}
        </button>
      ))}
    </div>
  );
}
```

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