Skip to Content
zjkm-ui
Components

Gradient Slider

A slider over a colour gradient track.

21°C
Props
30
<GradientSlider label="Temperature" colors={["#3b82f6", "#ef4444"]} min={16} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/gradient-slider.json
import { GradientSlider } from "@/components/gradient-slider"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A slider over a colour gradient, for settings that are a scale rather than a number: temperature, warmth, intensity.

import { GradientSlider } from "@/components/gradient-slider";

export function Thermostat() {
  return <GradientSlider label="Temperature" colors={["#3b82f6", "#ef4444"]} min={16} max={30} format={(v) => `${v}°C`} />;
}

Props

PropTypeDefaultDescription
labelstringThe label.
colorsstring[]blue, purple, redThe track's colours, left to right.
defaultValuenumber50Starting value.
minnumber0Lowest value.
maxnumber100Highest value.
stepnumber1Step between values.
format(value: number) => stringStringTurns the value into the text shown and read out, e.g. v => `${v}%`.
onChange(value: number) => voidCalled as the value changes.
classNamestringClasses for the wrapper.

It has no animation, so reduced motion changes nothing.

On this page