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.jsonNo 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.tsxUsage
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
| Prop | Type | Default | What it does |
|---|---|---|---|
theme | "dark" | "light" | "dark" | Dark or light palette. |
stops | readonly GradientPickerStop[] | None | Stops when the picker is controlled. Pair with onChange. |
defaultStops | readonly GradientPickerStop[] | gradientPickerStops | Starting stops when it is not controlled. |
onChange | (stops: readonly GradientPickerStop[]) => void | None | Called with the new stops after one is edited, added or removed, or the gradient is reversed. |
angle | number | None | Angle in degrees when it is controlled. Pair with onAngleChange. |
defaultAngle | number | 90 | Starting angle in degrees when it is not controlled. |
onAngleChange | (angle: number) => void | None | Called with the new angle after the gradient is turned. |
defaultSelected | number | 2 | Index of the stop selected at first. |
labels | GradientPickerLabels | gradientPickerLabels | Text for the two source tabs, the gradient type and the stops heading. |
onClose | () => void | None | Called 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