Skip to content
Browse components

GradientPicker

An editor for a linear gradient. Select, add, remove and reverse stops, and set each stop's position and colour.

Stops
%
100%

Installation

Run this in a project that has a components.json. It adds one file, components/tenor-ui/gradient-picker.tsx, and no packages.

pnpm dlx shadcn@latest add https://tenor.design/r/gradient-picker.json

No components.json? Fetch the file. It works in any React project.

curl --create-dirs -o src/components/tenor-ui/gradient-picker.tsx https://tenor.design/r/gradient-picker.tsx

Usage

Every prop is optional. With none, it renders the content you see above.

<GradientPicker />
"use client"; import * as React from "react"; import { GradientPicker, type GradientPickerStop } from "@/components/tenor-ui/gradient-picker"; export function BannerFill() { const [angle, setAngle] = React.useState(135); const [stops, setStops] = React.useState<readonly GradientPickerStop[]>([ { position: 0, color: "#0F172A" }, { position: 60, color: "#4338CA" }, { position: 100, color: "#F472B6" }, ]); const ordered = [...stops].sort((a, b) => a.position - b.position); const background = `linear-gradient(${angle}deg, ${ordered.map((stop) => `${stop.color} ${stop.position}%`).join(", ")})`; return ( <div style={{ display: "grid", gap: 16 }}> <div style={{ height: 120, borderRadius: 12, background }} /> <GradientPicker stops={stops} onChange={setStops} angle={angle} onAngleChange={setAngle} defaultSelected={1} /> </div> ); }

Props

PropTypeDefaultWhat it does
theme"dark" | "light""dark"Dark or light palette.
stopsreadonly GradientPickerStop[]NoneStops when the picker is controlled. Pair with onChange.
defaultStopsreadonly GradientPickerStop[]gradientPickerStopsStarting stops when it is not controlled.
onChange(stops: readonly GradientPickerStop[]) => voidNoneCalled with the new stops after one is edited, added or removed, or the gradient is reversed.
anglenumberNoneAngle in degrees when it is controlled. Pair with onAngleChange.
defaultAnglenumber90Starting angle in degrees when it is not controlled.
onAngleChange(angle: number) => voidNoneCalled with the new angle after the gradient is turned.
defaultSelectednumber2Index of the stop selected at first.
labelsGradientPickerLabelsgradientPickerLabelsText for the two source tabs, the gradient type and the stops heading.
onClose() => voidNoneCalled when the close button is pressed.

It also takes every attribute of its root element, such as className and style.

Theming

Set any of these CSS variables on the component or on an ancestor. Each falls back to the look shown here.

  • --tui-surface
  • --tui-stroke
  • --tui-text
  • --tui-muted
  • --tui-control
  • --tui-font-sans
  • --tui-font-mono