# iOS segmented tabs

> A soft grey track where a white pill with a light shadow glides to the section you choose.

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

## Where to use it

Picture the top of a booking site that splits its offer into “Stays”, “Experiences” and “Services”. That is where these iOS-style segmented tabs feel right: a neutral switch between two or three big sections, not a colorful filter. The white pill slides with a gentle spring, much like the one in iPhone apps.

Because it has no accent color, it sits well on busy pages without fighting your main buttons. Keep it to three options at most and use nouns people would type into a search, not clever internal names.

## Code

### React (Motion)

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

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

const OPTIONS = ["Stays", "Experiences", "Services"];

interface SegmentedControlProps {
  count?: number;
}

export default function SegmentedControl({ count = 3 }: SegmentedControlProps) {
  const options = OPTIONS.slice(0, count);
  const [active, setActive] = useState(0);

  return (
    <div className="flex rounded-full bg-black/5 p-1 text-[#1d1d1f] dark:text-[#f5f5f7] dark:bg-white/10">
      {options.map((option, i) => (
        <button
          key={option}
          type="button"
          aria-pressed={active === i}
          onClick={() => setActive(i)}
          className="relative rounded-full px-4 py-2 text-sm"
        >
          <AnimatePresence>
            {active === i && (
              <motion.span
                layoutId="segmented-pill"
                className="absolute inset-0 rounded-full bg-white dark:bg-[#1c1c1e] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
                transition={spring}
              />
            )}
          </AnimatePresence>
          <span className="relative">{option}</span>
        </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 “iOS segmented tabs” block (Navigation) from AIMRAN Library to my project.

## What it is
A soft grey track where a white pill with a light shadow glides to the section you choose.

## Chosen settings
- Options: 3 (from 2 to 3)

## 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";

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

const OPTIONS = ["Stays", "Experiences", "Services"];

interface SegmentedControlProps {
  count?: number;
}

export default function SegmentedControl({ count = 3 }: SegmentedControlProps) {
  const options = OPTIONS.slice(0, count);
  const [active, setActive] = useState(0);

  return (
    <div className="flex rounded-full bg-black/5 p-1 text-[#1d1d1f] dark:text-[#f5f5f7] dark:bg-white/10">
      {options.map((option, i) => (
        <button
          key={option}
          type="button"
          aria-pressed={active === i}
          onClick={() => setActive(i)}
          className="relative rounded-full px-4 py-2 text-sm"
        >
          <AnimatePresence>
            {active === i && (
              <motion.span
                layoutId="segmented-pill"
                className="absolute inset-0 rounded-full bg-white dark:bg-[#1c1c1e] shadow-[0_1px_2px_rgba(0,0,0,0.03),0_8px_28px_rgba(0,0,0,0.05)]"
                transition={spring}
              />
            )}
          </AnimatePresence>
          <span className="relative">{option}</span>
        </button>
      ))}
    </div>
  );
}
```

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