Skip to content

NewMCP server for your coding agent. Set it up ›

Nexus UI
Get Pro

Aspect Crop, animated React component

  • Pro
  • Inputs & Controls
  • Spring

An aspect-ratio picker whose crop frame keeps the same area at every ratio, so switching reads as re-cropping the same photo. The frame springs to its new shape and rule-of-thirds lines flash while it moves.

Props

PropTypeDefaultWhat it does
ratiosDEFAULT_ASPECT_RATIOSRatios to offer, each { id, w, h } (4:3, 1:1, 3:4 and 9:16 by default).
src—Photo to crop. Without it a drawn sunset illustration is shown.
alt""Alt text for src.
onChange—Called with the ratio id when the user picks one.
autoplayfalseCycles through the ratios until someone touches it.
size220Side of the square whose area every crop keeps, in px (100 to 280). A bigger number gives a bigger frame at every ratio.
radius18Corner radius of the frame, in px (0 to 60).
guides"flash"When the thirds grid shows: flash while the frame moves, always, or off.
speed1How quickly the frame springs to its new shape (0.3 to 3). Higher is snappier.
bounce1How much the frame overshoots before it settles (0.4 to 2.5). Higher bounces more, lower settles dead.

Add it to your project

  1. 1

    Set up your project once

    You need a Next.js project with Tailwind CSS and the @/ import alias. In its root folder, run this once. It creates components.json and the cn() helper in src/lib/utils.ts:

    npx shadcn@latest init -d

    Starting from nothing? The Quick Start walks through the whole thing.

  2. 2

    Connect the registry with your API key

    Aspect Crop is a Pro item, so the CLI has to send your API key. Do this once per project:

    1. Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with nxs_ and is shown only once.
    2. In your project root, next to package.json, create a file named .env.local with this line, using your own key:
      NEXUS_API_KEY=nxs_your_key_here
    3. Open components.json and add this entry inside the outermost braces, next to "aliases". Leave {name} and ${NEXUS_API_KEY} exactly as written; the CLI fills them in:
      "registries": {
        "@nexus-labs": {
          "url": "https://www.nexus-ui.com/api/registry/{name}",
          "headers": {
            "Authorization": "Bearer ${NEXUS_API_KEY}"
          }
        }
      }

How Aspect Crop works

Crop control that keeps the picture's area constant, so switching ratio reads as re-cropping the same photo rather than resizing it. The frame springs to its new shape, the photo stays put underneath, and thirds grid lines flash while it moves.

The source, the install command and the build prompt come with Pro.