# Gallery Hero
*URL: https://www.grettech.com/components/gallery-hero*

A portfolio hero with copy beside a 3D marquee of work: tilted columns scroll in opposite directions over a dot field and warm glow, and pause on hover.

- 3D marquee tilt with all four edges faded
- Columns scroll in opposite directions with a seamless loop
- Dot field and warm colour glow behind the gallery
- Eases to a stop on hover; still for reduced motion

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/gallery-hero
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/gallery-hero-demo`

**Dependencies:** npm: motion, clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install motion clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/gallery-hero.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import {
  animate,
  motion,
  useAnimate,
  useReducedMotion,
  type AnimationPlaybackControls,
} from "motion/react"
import * as React from "react"

export type GalleryImage = { src: string; alt: string }

export interface GalleryHeroProps extends Omit<
  React.HTMLAttributes<HTMLElement>,
  "title"
> {
  eyebrow?: string
  title: React.ReactNode
  description?: string
  /** Calls to action */
  children?: React.ReactNode
  /** Small print or proof under the actions */
  note?: React.ReactNode
  /** Shared out across the columns, in order */
  images: GalleryImage[]
  /** Number of image columns (two on phones either way) */
  columns?: 2 | 3
  /** Seconds for a column to scroll through once */
  duration?: number
  /** Tilt the gallery back for depth */
  tilt?: boolean
  /** Two colours for the glow behind the gallery */
  glowColors?: [string, string]
}

/**
 * One column of the marquee: two copies of its images scrolling forever,
 * so -50% lands exactly on the start of the copy. It eases to a stop while
 * hovered and picks up again after.
 */
function MarqueeColumn({
  images,
  reverse,
  duration,
  paused,
  className,
}: {
  images: GalleryImage[]
  reverse: boolean
  duration: number
  paused: boolean
  className?: string
}) {
  const [scope] = useAnimate<HTMLDivElement>()
  const still = useReducedMotion() ?? false
  const run = React.useRef<AnimationPlaybackControls | null>(null)

  React.useEffect(() => {
    if (still || !scope.current) return
    run.current = animate(
      scope.current,
      { y: reverse ? ["-50%", "0%"] : ["0%", "-50%"] },
      { duration, ease: "linear", repeat: Infinity }
    )
    return () => run.current?.stop()
  }, [scope, reverse, duration, still])

  // Slow down to a stop rather than freezing mid-step
  React.useEffect(() => {
    const scroll = run.current
    if (!scroll) return
    const ease = animate(scroll.speed, paused ? 0 : 1, {
      duration: 0.6,
      ease: "easeOut",
      onUpdate: (v) => (scroll.speed = v),
    })
    return () => ease.stop()
  }, [paused])

  return (
    <div ref={scope} className={cn("flex flex-col", className)}>
      {[...images, ...images].map((image, i) => (
        // Each image is padded below rather than gapped, so the two
        // halves are exactly the same height
        <div key={i} className="pb-4">
          <motion.img
            src={image.src}
            alt={i < images.length ? image.alt : ""}
            aria-hidden={i >= images.length || undefined}
            loading={i < 2 ? "eager" : "lazy"}
            whileHover={{ scale: 1.04 }}
            transition={{ type: "spring", stiffness: 260, damping: 24 }}
            className="aspect-[4/5] w-full rounded-2xl bg-muted object-cover shadow-[0_18px_40px_-18px_rgba(0,0,0,0.45)] ring-1 ring-foreground/10"
          />
        </div>
      ))}
    </div>
  )
}

/** Deals the images out round-robin, repeating short columns to fill */
function toColumns(images: GalleryImage[], count: number) {
  return Array.from({ length: count }, (_, c) => {
    const own = images.filter((_, i) => i % count === c)
    const base = own.length ? own : images
    let column = [...base]
    while (column.length && column.length < 4) column = column.concat(base)
    return column
  })
}

/**
 * A portfolio-style hero: copy on one side, and columns of work scrolling
 * past in opposite directions on the other, tilted back for depth. Motion
 * scrolls the columns (transforms only), eases them to a stop on hover and
 * holds them still for reduced motion.
 */
export const GalleryHero = React.forwardRef<HTMLElement, GalleryHeroProps>(
  (
    {
      eyebrow,
      title,
      description,
      children,
      note,
      images,
      columns = 3,
      duration = 40,
      tilt = true,
      glowColors = ["#f59e0b", "#ec4899"],
      className,
      ...props
    },
    ref
  ) => {
    // Images without a source (say, a half-filled new item) are skipped
    const cols = toColumns(
      images.filter((image) => image.src),
      columns
    )
    const [hovered, setHovered] = React.useState(false)
    return (
      <section
        ref={ref}
        className={cn(
          "relative isolate w-full overflow-hidden bg-background px-6 py-16 sm:py-20",
          className
        )}
        {...props}
      >
        <div
          aria-hidden="true"
          className="pointer-events-none absolute inset-0 -z-10"
        >
          <div className="absolute inset-0 [background-image:radial-gradient(color-mix(in_oklab,currentColor_16%,transparent)_1px,transparent_1px)] [mask-image:radial-gradient(ellipse_60%_80%_at_75%_50%,black,transparent)] [background-size:22px_22px] text-foreground" />
          <div
            className="absolute top-[10%] right-[5%] h-[70%] w-[45%] rounded-full opacity-30 blur-3xl dark:opacity-20"
            style={{
              backgroundImage: `radial-gradient(closest-side at 35% 40%, ${glowColors[0]}, transparent), radial-gradient(closest-side at 65% 65%, ${glowColors[1]}, transparent)`,
            }}
          />
        </div>

        <div className="mx-auto grid max-w-6xl items-center gap-12 lg:grid-cols-[1fr_1.1fr]">
          <div>
            {eyebrow && (
              <p className="mb-5 text-sm font-medium text-muted-foreground">
                {eyebrow}
              </p>
            )}
            <h1 className="text-4xl leading-[1.05] font-semibold tracking-tight text-balance text-foreground sm:text-5xl lg:text-6xl">
              {title}
            </h1>
            {description && (
              <p className="mt-5 max-w-lg text-base text-pretty text-muted-foreground sm:text-lg">
                {description}
              </p>
            )}
            {children && (
              <div className="mt-8 flex flex-wrap items-center gap-3">
                {children}
              </div>
            )}
            {note && (
              <div className="mt-6 text-sm text-muted-foreground">{note}</div>
            )}
          </div>

          <div className="relative">
            <div
              aria-hidden="true"
              className="absolute inset-[10%] -z-10 rounded-full bg-foreground/5 blur-3xl"
            />
            <div
              className="h-[440px] overflow-hidden sm:h-[560px]"
              style={{
                // Fade all four edges: two masks intersected
                maskImage:
                  "linear-gradient(to bottom, transparent, black 12%, black 88%, transparent), linear-gradient(to right, transparent, black 10%, black 92%, transparent)",
                WebkitMaskImage:
                  "linear-gradient(to bottom, transparent, black 12%, black 88%, transparent), linear-gradient(to right, transparent, black 10%, black 92%, transparent)",
                maskComposite: "intersect",
                WebkitMaskComposite: "source-in",
              }}
            >
              <div
                onPointerEnter={() => setHovered(true)}
                onPointerLeave={() => setHovered(false)}
                className={cn(
                  // Tilt around the middle of the visible window, not the
                  // middle of the (much taller) columns
                  "grid origin-[50%_220px] items-start gap-4 sm:origin-[50%_280px]",
                  columns === 3 ? "grid-cols-2 sm:grid-cols-3" : "grid-cols-2"
                )}
                style={
                  tilt
                    ? {
                        transform:
                          "perspective(1200px) rotateX(26deg) rotateY(-10deg) rotateZ(-14deg) scale(1.3)",
                      }
                    : undefined
                }
              >
                {cols.map((column, c) => (
                  <MarqueeColumn
                    key={c}
                    images={column}
                    reverse={c % 2 === 1}
                    duration={duration * (1 + c * 0.15)}
                    paused={hovered}
                    className={c === 2 ? "hidden sm:flex" : undefined}
                  />
                ))}
              </div>
            </div>
          </div>
        </div>
      </section>
    )
  }
)
GalleryHero.displayName = "GalleryHero"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `title` | `React.ReactNode` | - | Yes | The main headline. |
| `images` | `GalleryImage[]` | - | Yes | Images shared out across the columns, in order. Short columns repeat to fill. |
| `images.src` | `string` | - | Yes | Image URL. |
| `images.alt` | `string` | - | Yes | Description of the image. |
| `eyebrow` | `string` | - | No | Small label above the title. |
| `description` | `string` | - | No | Supporting text under the title. |
| `children` | `React.ReactNode` | - | No | Calls to action. |
| `note` | `React.ReactNode` | - | No | Small print or proof under the actions. |
| `columns` | `2 \| 3` | `3` | No | Number of image columns (two on phones either way). |
| `duration` | `number` | `40` | No | Seconds for a column to scroll through once. |
| `tilt` | `boolean` | `true` | No | Tilt the gallery back for depth. |
| `glowColors` | `[string, string]` | `["#f59e0b", "#ec4899"]` | No | Two colours for the glow behind the gallery. |
| `className` | `string` | - | No | Extra classes for the section. |

## Usage
```tsx
"use client"

import { GalleryHero } from "@/components/ui/gallery-hero"

const WORK = [
  {
    src:
      "https://images.unsplash.com/photo-1559028012-481c04fa702d?w=600&h=750&fit=crop&q=75",
    alt: "Course website on a desktop monitor",
  },
  { src: "https://images.unsplash.com/photo-1551650975-87deedd944c3?w=600&h=750&fit=crop&q=75", alt: "Weather app open on a phone" },
  { src: "https://images.unsplash.com/photo-1522542550221-31fd19575a2d?w=600&h=750&fit=crop&q=75", alt: "Watercolour wireframe of a web page" },
  { src: "https://images.unsplash.com/photo-1467232004584-a241de8bcf5d?w=600&h=750&fit=crop&q=75", alt: "Designer's desk with two screens" },
  { src: "https://images.unsplash.com/photo-1586717791821-3f44a563fa4c?w=600&h=750&fit=crop&q=75", alt: "Wireframes sketched on a tablet" },
  { src: "https://images.unsplash.com/photo-1581291518857-4e27b48ff24e?w=600&h=750&fit=crop&q=75", alt: "Hand drawing a user flow" },
  { src: "https://images.unsplash.com/photo-1563986768609-322da13575f3?w=600&h=750&fit=crop&q=75", alt: "Chat app on a phone beside a laptop" },
  { src: "https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=800&q=75&auto=format", alt: "Analytics dashboard" },
]

export default function GalleryHeroDemo() {
  return (
    <GalleryHero
      eyebrow="Folio"
      title="Show the work that wins your next client"
      description="Folio turns your best projects into a portfolio site in an afternoon, with case studies, testimonials and a contact form built in."
      images={WORK}
      note="Used by 3,000+ designers and small studios."
      className="rounded-3xl border bg-background"
    >
      <a
        href="#start"
        className="rounded-full bg-foreground px-5 py-2.5 text-sm font-medium text-background transition-opacity hover:opacity-90"
      >
        Build your portfolio
      </a>
      <a
        href="#examples"
        className="rounded-full border px-5 py-2.5 text-sm font-medium text-foreground transition-colors hover:bg-muted"
      >
        Browse examples
      </a>
    </GalleryHero>
  )
}

```
