Gradient Editor
ridiculous/gradient-editorFreeComponent
Linear / radial / conic gradient editor with draggable stops, position picker, oklch-default interpolation, and reusable color-picker stops.
Install it
npx shadcn@latest add http://ridiculous.turtlesocks.dev/r/gradient-editor.jsonSource
1"use client"23import { useEffect, useMemo, useRef, useState } from "react"4import { Button } from "@/components/ui/button"5import { ColorPicker } from "@/components/ui/color-picker"6import {7 Popover,8 PopoverContent,9 PopoverTrigger,10} from "@/components/ui/popover"11import { UnitInput } from "@/components/ui/unit-input"12import { cn } from "@/lib/utils"13import {14 formatGradient,15 fromUnitString,16 GRADIENT_TYPES,17 INTERPOLATION_SPACES,18 type InternalState,19 nextStopId,20 POLAR_SPACES,21 parseGradient,22 toDeg,23 toPct,24} from "./gradient-editor.helpers"25import type {26 GradientString,27 GradientStringMap,28 GradientType,29 InternalStop,30 InterpolationHueMethod,31 InterpolationSpace,32 PolarSpace,33} from "./gradient-editor.types"3435// ---------------------------------------------------------------------------36// Component (top of file)37// ---------------------------------------------------------------------------3839export interface GradientEditorProps<40 TType extends GradientType | undefined = undefined,41> {42 value: GradientString | (string & {})43 onChange: (44 value: TType extends GradientType45 ? GradientStringMap[TType]46 : GradientString,47 ) => void48 type?: TType49 maxStops?: number50 className?: string51 "aria-label"?: string52}5354export function GradientEditor<TType extends GradientType | undefined>({55 value,56 onChange,57 type: typeProp,58 maxStops = 8,59 className,60 "aria-label": ariaLabel = "Edit gradient",61}: GradientEditorProps<TType>) {62 const parsed = useMemo(() => parseGradient(value), [value])63 if (!parsed) {64 return (65 <span66 aria-hidden="true"67 className={cn(68 "inline-block h-5 w-12 rounded border bg-muted",69 className,70 )}71 style={{ backgroundColor: value }}72 data-slot="gradient-editor-fallback"73 />74 )75 }76 return (77 <GradientEditorBody78 value={value}79 initial={parsed}80 onChange={onChange as (next: string) => void}81 typeProp={typeProp}82 maxStops={maxStops}83 className={className}84 ariaLabel={ariaLabel}85 />86 )87}8889interface GradientEditorBodyProps {90 value: string91 initial: InternalState92 onChange: (next: string) => void93 typeProp: GradientType | undefined94 maxStops: number95 className: string | undefined96 ariaLabel: string97}9899function GradientEditorBody({100 value,101 initial,102 onChange,103 typeProp,104 maxStops,105 className,106 ariaLabel,107}: GradientEditorBodyProps) {108// … truncated
What it pulls in
Other registry items
Files it writes
More from ridiculous
All 22 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| All ridiculous componentsall | ridiculous | Components | Free | no deps | |
| Anchor Position Editoranchor-position-editor | ridiculous | Components | Free | no deps · 9 files | |
| Background Editorbackground-editor | ridiculous | Components | Free | no deps · 9 files | |
| Box Shadow Editorbox-shadow-editor | ridiculous | Components | Free | no deps · 7 files | |
| Calc Editorcalc-editor | ridiculous | Components | Free | no deps · 4 files | |
| Clip Path Editorclip-path-editor | ridiculous | Components | Free | no deps · 20 files | |
| Color Functioncolor-function | ridiculous | Components | Free | no deps · 10 files | |
| Color Pickercolor-picker | ridiculous | Components | Free | no deps · 11 files |
