# Beam Hero
*URL: https://www.grettech.com/components/beam-hero*

A centred hero on a diagonal lattice of dashed lines with glowing meteors travelling along it, a highlighted phrase and a screenshot in a layered frame.

- Dashed diagonal lattice with meteors, animated with Motion
- Highlight box with design-tool corner handles
- Three-layer glass frame that tilts upright on scroll
- Warm glow and film grain behind the title

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/beam-hero
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/beam-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/beam-hero.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import { motion, useScroll, useTransform } from "motion/react"
import * as React from "react"

export interface BeamHeroProps extends Omit<
  React.HTMLAttributes<HTMLElement>,
  "title"
> {
  /** Small label above the title */
  eyebrow?: string
  title: string
  /** Words after the title, drawn in a highlight box */
  highlight?: string
  description?: string
  /** Calls to action, under the description */
  children?: React.ReactNode
  /** Framed screenshot below the text */
  image?: { src: string; alt: string }
  /** How many meteors travel along the lattice */
  beams?: number
  /** Meteor colours: tail and head */
  beamColors?: [string, string]
  /** Tilt the screenshot back and straighten it as it scrolls into view */
  tilt?: boolean
}

// Lattice spacing in px; meteors run along these lines
const GAP = 96

const REDUCED = "(prefers-reduced-motion: reduce)"
function subscribeReduced(onChange: () => void) {
  const media = window.matchMedia(REDUCED)
  media.addEventListener("change", onChange)
  return () => media.removeEventListener("change", onChange)
}
/**
 * Reduced motion, read so that hydration matches the server (which can't
 * know): false at first, the visitor's setting right after
 */
function useReduced() {
  return React.useSyncExternalStore(
    subscribeReduced,
    () => window.matchMedia(REDUCED).matches,
    () => false
  )
}

/**
 * A meteor running down one lattice line: it travels for the first 70% of
 * its cycle and rests, hidden, for the rest. Transforms only.
 */
function Meteor({
  left,
  duration,
  delay,
  tail,
  head,
}: {
  left: string
  duration: number
  delay: number
  tail: string
  head: string
}) {
  // Hidden for reduced motion (rendered all the same, so the server and
  // the browser agree)
  const still = useReduced()
  return (
    <motion.span
      className="absolute top-[22%] h-28 w-px"
      style={{
        left,
        backgroundImage: `linear-gradient(to bottom, transparent, ${tail} 70%, ${head})`,
      }}
      initial={{ y: -160, opacity: 0 }}
      animate={
        still
          ? { y: -160, opacity: 0 }
          : { y: [-160, 1700, 1700], opacity: [0, 1, 1, 0, 0] }
      }
      transition={
        still
          ? { duration: 0 }
          : {
              y: {
                duration,
                times: [0, 0.7, 1],
                ease: "linear",
                repeat: Infinity,
                delay,
              },
              opacity: {
                duration,
                times: [0, 0.06, 0.64, 0.7, 1],
                ease: "linear",
                repeat: Infinity,
                delay,
              },
            }
      }
    >
      <span
        className="absolute -bottom-0.5 left-1/2 size-1 -translate-x-1/2 rounded-full"
        style={{
          backgroundColor: head,
          boxShadow: `0 0 10px 2px ${head}, 0 0 24px 6px ${tail}`,
        }}
      />
    </motion.span>
  )
}

/** The screenshot frame: tilted back, straightening as it scrolls in */
function TiltFrame({
  tilt,
  className,
  children,
}: {
  tilt: boolean
  className?: string
  children: React.ReactNode
}) {
  const ref = React.useRef<HTMLDivElement>(null)
  const still = useReduced()
  const { scrollYProgress } = useScroll({
    target: ref,
    offset: ["start end", "start 0.45"],
  })
  const rotateX = useTransform(scrollYProgress, [0, 1], [20, 0])
  const scale = useTransform(scrollYProgress, [0, 1], [0.94, 1])
  const on = tilt && !still
  return (
    <motion.div
      ref={ref}
      className={className}
      style={on ? { rotateX, scale, transformPerspective: 1400 } : undefined}
    >
      {children}
    </motion.div>
  )
}

const GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`

// Dashed lines, faded towards the edges: two masks intersected
const LATTICE: React.CSSProperties = {
  backgroundImage: `repeating-linear-gradient(to right, currentColor 0 1px, transparent 1px ${GAP}px)`,
  maskImage:
    "repeating-linear-gradient(to bottom, black 0 5px, transparent 5px 11px), radial-gradient(ellipse 45% 45% at 50% 50%, black 30%, transparent 100%)",
  WebkitMaskImage:
    "repeating-linear-gradient(to bottom, black 0 5px, transparent 5px 11px), radial-gradient(ellipse 45% 45% at 50% 50%, black 30%, transparent 100%)",
  maskComposite: "intersect",
  WebkitMaskComposite: "source-in",
}

/** A box with small squares on its corners, like a selection in a design tool */
function Highlight({ children }: { children: React.ReactNode }) {
  const corner =
    "absolute size-1.5 rounded-[1px] border border-foreground/60 bg-background"
  return (
    <span className="relative mx-1 inline-block bg-foreground/[0.04] px-2 text-foreground ring-1 ring-foreground/25 ring-inset">
      <span
        aria-hidden="true"
        className={cn(corner, "-top-[3px] -left-[3px]")}
      />
      <span
        aria-hidden="true"
        className={cn(corner, "-top-[3px] -right-[3px]")}
      />
      <span
        aria-hidden="true"
        className={cn(corner, "-bottom-[3px] -left-[3px]")}
      />
      <span
        aria-hidden="true"
        className={cn(corner, "-right-[3px] -bottom-[3px]")}
      />
      {children}
    </span>
  )
}

/**
 * A centred hero on a diagonal lattice of dashed lines, with meteors
 * travelling along it and a soft glow behind the title. One phrase sits in
 * a design-tool selection box, and an optional screenshot in a layered
 * frame tilts upright as it scrolls into view. Motion drives the meteors
 * and the scroll-linked tilt with transforms only; reduced motion holds
 * everything still.
 */
export const BeamHero = React.forwardRef<HTMLElement, BeamHeroProps>(
  (
    {
      eyebrow,
      title,
      highlight,
      description,
      children,
      image,
      beams = 8,
      beamColors = ["#f97316", "#fde047"],
      tilt = true,
      className,
      ...props
    },
    ref
  ) => {
    const [tail, head] = beamColors
    const count = Math.max(0, Math.min(16, beams))
    return (
      <section
        ref={ref}
        className={cn(
          "relative isolate w-full overflow-hidden bg-background px-6 pt-24 pb-16 text-foreground sm:pt-32",
          className
        )}
        {...props}
      >
        <div
          aria-hidden="true"
          className="pointer-events-none absolute inset-0 -z-10"
        >
          {/* Lattice and meteors share one rotated layer */}
          <div className="absolute -inset-1/2 -rotate-45">
            <div
              className="absolute inset-0 text-foreground/15"
              style={LATTICE}
            />
            {Array.from({ length: count }, (_, i) => {
              // Spread meteors over lines near the middle, where the title is
              const line = Math.round((i - count / 2) * 2.3)
              return (
                <Meteor
                  key={i}
                  left={`calc(50% + ${line * GAP}px)`}
                  duration={7 + (i % 4) * 1.6}
                  delay={i * -2.3}
                  tail={tail}
                  head={head}
                />
              )
            })}
          </div>

          {/* Soft glow behind the title, and grain */}
          <div
            className="absolute top-[8%] left-1/2 h-[420px] w-[720px] max-w-full -translate-x-1/2 rounded-full opacity-25 blur-3xl dark:opacity-20"
            style={{
              backgroundImage: `radial-gradient(closest-side, ${tail}, transparent)`,
            }}
          />
          <div
            className="absolute inset-0 opacity-[0.12] mix-blend-overlay dark:opacity-[0.08]"
            style={{ backgroundImage: GRAIN }}
          />
        </div>

        <div className="mx-auto flex max-w-3xl flex-col items-center text-center">
          {eyebrow && (
            <p className="mb-6 inline-flex items-center gap-2 rounded-full bg-background/80 px-3 py-1 text-xs font-medium text-muted-foreground ring-1 ring-foreground/10 backdrop-blur">
              <span
                className="size-1.5 rounded-full"
                style={{ backgroundColor: tail }}
              />
              {eyebrow}
            </p>
          )}
          <h1 className="text-4xl leading-[1.08] font-semibold tracking-[-0.03em] text-balance text-foreground/75 sm:text-6xl">
            {title}
            {highlight && <Highlight>{highlight}</Highlight>}
          </h1>
          {description && (
            <p className="mt-6 max-w-xl text-base text-pretty text-muted-foreground sm:text-lg">
              {description}
            </p>
          )}
          {children && (
            <div className="mt-9 flex flex-wrap items-center justify-center gap-3">
              {children}
            </div>
          )}
        </div>

        {image?.src && (
          <div className="relative mx-auto mt-16 max-w-5xl sm:mt-20">
            <div
              aria-hidden="true"
              className="absolute inset-x-[10%] -bottom-6 h-1/2 rounded-full opacity-30 blur-3xl"
              style={{ backgroundColor: tail }}
            />
            {/* Three layers: a glassy rim, an inner tray, then the image */}
            <TiltFrame
              tilt={tilt}
              className="relative rounded-[28px] bg-foreground/[0.04] p-2 ring-1 ring-foreground/10 backdrop-blur-md sm:p-3"
            >
              <div className="rounded-[20px] bg-background p-1.5 ring-1 ring-foreground/10">
                {/* eslint-disable-next-line @next/next/no-img-element */}
                <img
                  src={image.src}
                  alt={image.alt}
                  className="aspect-video w-full rounded-[14px] object-cover object-top"
                />
              </div>
            </TiltFrame>
          </div>
        )}
      </section>
    )
  }
)
BeamHero.displayName = "BeamHero"

```

**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` | `string` | - | Yes | The main headline. |
| `highlight` | `string` | - | No | Words after the title, drawn in a highlight box. |
| `eyebrow` | `string` | - | No | Small label above the title. |
| `description` | `string` | - | No | Supporting text under the title. |
| `children` | `React.ReactNode` | - | No | Calls to action, shown under the description. |
| `image` | `{ src: string; alt: string }` | - | No | Framed screenshot shown below the text. |
| `image.src` | `string` | - | Yes | - |
| `image.alt` | `string` | - | Yes | - |
| `beams` | `number` | `8` | No | How many meteors travel along the lattice. |
| `tilt` | `boolean` | `true` | No | Tilt the screenshot back and straighten it as it scrolls into view (where the browser supports scroll-driven animations). |
| `beamColors` | `[string, string]` | `["#f97316", "#fde047"]` | No | Meteor colours: tail and head. |
| `className` | `string` | - | No | Extra classes for the section. |

## Usage
```tsx
"use client"

import { BeamHero } from "@/components/ui/beam-hero"

export default function BeamHeroDemo() {
  return (
    <BeamHero
      eyebrow="Northwind Analytics"
      title="Know what's working"
      highlight="before Monday"
      description="Live dashboards from the tools you already use, with a plain-English summary in your inbox every morning."
      image={{
        src:
          "https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=800&q=75&auto=format",
        alt: "Northwind dashboard with revenue and traffic charts",
      }}
      className="rounded-3xl border bg-background"
    >
      <a
        href="#start"
        className="rounded-lg bg-foreground px-5 py-2.5 text-sm font-medium text-background transition-opacity hover:opacity-90"
      >
        Start free trial
      </a>
      <a
        href="#how"
        className="rounded-lg border bg-background px-5 py-2.5 text-sm font-medium text-foreground transition-colors hover:bg-muted"
      >
        Book a demo
      </a>
    </BeamHero>
  )
}

```
