# M text highlight 3

> Direction picker — buttons call ref to demonstrate all four sweep directions

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/m-text-highlight-3).

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

## Install

```bash
npx shadcn@latest add https://ui.cnippet.dev/r/m-text-highlight-3.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/text-highlight`

## Files

### `registry/default/motion-variants/m-text-highlight-3.tsx`

```tsx
"use client";

import { useRef, useState } from "react";
import {
  TextHighlight,
  type TextHighlightRef,
} from "@/registry/default/motion/text-highlight";

const directions = ["ltr", "rtl", "ttb", "btt"] as const;

export default function TextHighlightDirections() {
  const ref = useRef<TextHighlightRef>(null);
  const [dir, setDir] = useState<(typeof directions)[number]>("ltr");

  return (
    <div className="flex min-h-50 flex-col items-center justify-center gap-6 px-6">
      <p className="font-bold text-2xl text-foreground">
        <TextHighlight
          direction={dir}
          highlightColor="hsl(155, 70%, 75%)"
          ref={ref}
          transition={{ bounce: 0, duration: 0.7, type: "spring" }}
          triggerType="ref"
        >
          Highlight direction
        </TextHighlight>
      </p>
      <div className="flex flex-wrap justify-center gap-2">
        {directions.map((d) => (
          <button
            className={`rounded-md px-3 py-1.5 font-medium text-xs transition-colors ${
              d === dir
                ? "bg-foreground text-background"
                : "bg-accent text-muted-foreground hover:text-foreground"
            }`}
            key={d}
            onClick={() => {
              setDir(d);
              ref.current?.reset();
              setTimeout(() => ref.current?.animate(d), 50);
            }}
            type="button"
          >
            {d.toUpperCase()}
          </button>
        ))}
      </div>
    </div>
  );
}
```
