Cropper
weekendsuperhero-io-sistine/cropperUnverifiedComponent
An image cropper component with optional glass material.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/Weekendsuperhero-io/sistine/main/cropper.jsonSource
1"use client";23import * as React from "react";4import type { Area, Point } from "react-easy-crop";5import CropperLib from "react-easy-crop";6import { type MaterialAxisProps, materialSurface, splitAxisProps } from "@/lib/material";7import { cn } from "@/lib/utils";8import { Slider } from "./slider";910interface CropperProps extends MaterialAxisProps {11 image: string;12 onCropComplete: (croppedArea: Area, croppedAreaPixels: Area) => void;13 aspect?: number;14 variant?: "default" | "glass";15 className?: string;16}1718/* Role: bordered adaptive glass. */19const ROLE = {20 border: true,21};2223export function Cropper({ image, onCropComplete, aspect = 1, variant = "glass", className, ...props }: CropperProps) {24 /* This component never forwards unknown props to the DOM — only the axes are consumed. */25 const [axes] = splitAxisProps(props);26 const [crop, setCrop] = React.useState<Point>({27 x: 0,28 y: 0,29 });30 const [zoom, setZoom] = React.useState(1);31 const [_croppedAreaPixels, setCroppedAreaPixels] = React.useState<Area | null>(null);3233 const handleCropComplete = React.useCallback(34 (croppedArea: Area, croppedAreaPixels: Area) => {35 setCroppedAreaPixels(croppedAreaPixels);36 onCropComplete(croppedArea, croppedAreaPixels);37 },38 [39 onCropComplete,40 ],41 );4243 /* Variant classes carry BEHAVIOR only; the surface comes from materialSurface. */44 const m = materialSurface(variant === "default" ? null : ROLE, axes);4546 return (47 <div48 data-material={m?.["data-material"]}49 className={cn(m?.className, "relative w-full h-[400px]", variant === "glass" && "rounded-lg overflow-hidden", className)}50 >51 <CropperLib52 image={image}53 crop={crop}54 zoom={zoom}55 aspect={aspect}56 onCropChange={setCrop}57 onZoomChange={setZoom}58 onCropComplete={handleCropComplete}59 />60 <div className="absolute bottom-4 left-1/2 -translate-x-1/2 w-3/4">61 <Slider62 value={[63 zoom,64 ]}65 min={1}66 max={3}67 step={0.1}68 onValueChange={(value) => setZoom(value[0])}69 />70 </div>71 </div>72 );73}
What it pulls in
npm packages
Other registry items
Files it writes
More from weekendsuperhero-io/sistine
All 71 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | weekendsuperhero-io/sistine | Components | Unverified | 5 deps · 4 files | |
| Alertalert | weekendsuperhero-io/sistine | Components | Unverified | 3 deps · 4 files | |
| Alert Dialogalert-dialog | weekendsuperhero-io/sistine | Components | Unverified | 4 deps · 4 files | |
| Auto Foregroundauto-foreground | weekendsuperhero-io/sistine | Components | Unverified | no deps | |
| Avataravatar | weekendsuperhero-io/sistine | Components | Unverified | 4 deps · 4 files | |
| Badgebadge | weekendsuperhero-io/sistine | Components | Unverified | 4 deps · 4 files | |
| Breadcrumbbreadcrumb | weekendsuperhero-io/sistine | Components | Unverified | 5 deps · 4 files | |
| Buttonbutton | weekendsuperhero-io/sistine | Components | Unverified | 4 deps · 4 files |
