# Compare

> Before/after image comparison slider split by a blade of light: a white-hot seam with a chromatic fringe, pulses running along it and a trail that stretches with the speed of the gesture.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Media
- Tags: media, image, slider, comparison, before-after, interactive
- Types: `CompareProps`, `StarFieldProps`
- Docs: https://fancy-ui.rama.app/docs/components/compare
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/compare

## Import

```tsx
import { Compare } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `firstImage` | `string` | `""` | URL of the first (left) image |
| `secondImage` | `string` | `""` | URL of the second (right) image |
| `firstImageAlt` | `string` | `"First image"` | Alt text for the first image |
| `secondImageAlt` | `string` | `"Second image"` | Alt text for the second image |
| `firstContentClass` | `string` | `""` | CSS classes for the first content container |
| `secondContentClass` | `string` | `""` | CSS classes for the second content container |
| `initialSliderPercentage` | `number` | `50` | Initial slider position (0-100) |
| `slideMode` | `"hover" \| "drag"` | `"hover"` | How the slider is controlled |
| `showHandlebar` | `boolean` | `true` | Show the drag handle bar |
| `autoplay` | `boolean` | `false` | Automatically animate the slider back and forth |
| `autoplayDuration` | `number` | `5000` | Duration of one autoplay cycle in ms |
| `beamColors` | `string[]` | `["#22d3ee", "#818cf8", "#f472b6"]` | Beam colours: left fringe, centre, right fringe (one or more colours) |
| `label` | `string` | `"Comparison slider"` | Accessible name of the slider |
| `className` (Svelte `class`) | `string` | `""` | Additional CSS classes for the root element |
| `onpercentagechange` | `(percentage: number) => void` | — | Called with the slider position (0-100) whenever it changes |
| `ondragstart` | `() => void` | — | Called when a drag on the slider begins |
| `ondragend` | `() => void` | — | Called when the drag ends |
| `onhoverenter` | `() => void` | — | Called when the pointer enters the comparison area |
| `onhoverleave` | `() => void` | — | Called when the pointer leaves the comparison area |

## Node props

| Prop | Description |
| --- | --- |
| `firstContent` | Custom content to render in the first (left) panel instead of an image |
| `secondContent` | Custom content to render in the second (right) panel instead of an image |
| `handle` | Custom drag handle element |

## Example

No React example is published for this component yet: start from the import above and the props table. The full examples are Svelte-only, on https://fancy-ui.rama.app/docs/components/compare.md.
