Gradient Editor
Linear / radial / conic gradients with draggable stops, oklch-default interpolation, and color-picker stops via cross-registry composition.
Basic Usage
Type unset โ switcher visible โ onChange emits whichever type the user last selected.
linear-gradient(45deg, oklch(0.628 0.258 29.234), oklch(0.622 0.214 259.815))Type-Locked
Setting type hides the switcher and locks onChange to that gradient flavor.
linear-gradient(45deg, #ff0000, #0000ff)radial-gradient(circle at 50% 50%, #ff0000, #0000ff)conic-gradient(from 0deg at 50% 50%, #ff0000, #0000ff)Stops Control
The maxStops prop caps how many stops the editor will allow. Min 2 is always enforced.
linear-gradient(45deg, #ff0000 0%, #00ff00 50%, #0000ff 100%)linear-gradient(45deg, #ff0000, #ff8800, #ffff00, #88ff00, #00ff00, #00ff88, #00ffff, #0088ff, #0000ff)Interpolation Space
Same red โ blue stops, different interpolation spaces. in srgb goes through a muddy gray midpoint; in oklch stays perceptually vivid through the transition. This is the brand bias.
linear-gradient(90deg in srgb, #ff0000, #0000ff)linear-gradient(90deg in oklch, #ff0000, #0000ff)API
Public surface โ component props, runtime helpers, and the type exports.
ยง Component
<GradientEditor<TType extends GradientType | undefined>
value: GradientString | (string & {})
onChange: (next: TType extends GradientType ? GradientStringMap[TType] : GradientString) => void
type?: TType
maxStops?: number
className?: string
aria-label?: string
/>| Prop | Type | Description |
|---|---|---|
| value | GradientString | (string & {}) | Current gradient. Any string accepted; IntelliSense suggests literal shapes. |
| onChange | (next) => void | Emits next gradient. Return type discriminated by `type` prop. |
| type | GradientType | undefined | Lock gradient type. When unset, in-popover type switcher is shown. |
| maxStops | number (default 8) | Max number of stops the editor allows. Min (2) always enforced. |
| className | string | Applied to the trigger preview swatch. |
| aria-label | string | Trigger label. Defaults to "Edit gradient". |
ยง Runtime helpers
isGradientString(value: string): value is GradientString isGradientString<S extends string>(value: S): value is S & (LinearGradientString | RadialGradientString | ConicGradientString)
Runtime type guard. Narrows wide strings to GradientString.
ยง Types
- GradientString
- Union of all suggestion-string literal types. Default `onChange` return type.
- GradientStringMap
- { linear: LinearGradientString, radial: RadialGradientString, conic: ConicGradientString }
- GradientType
- "linear" | "radial" | "conic"
- GradientStop
- { color: ColorString, position: number }. Reuses ColorString from color-picker.
- InterpolationSpace
- "srgb" | "oklch" | "oklab" | "hsl" | "hwb"
- InterpolationHueMethod
- "shorter" | "longer"
- PolarSpace
- Subset of InterpolationSpace that supports hue methods: "oklch" | "hsl" | "hwb".
- GradientTypeOf<S>
- Extract the type from a gradient literal. GradientTypeOf<"linear-gradient(...)"> = "linear".
- InterpolationOf<S>
- Extract the interpolation space from a literal, if declared.
Drop it in
One command. Resolves color-picker + unit-input transitively.
$ pnpm dlx shadcn@latest add https://turtiesocks.github.io/ridiculous/r/gradient-editor.json