# Spice Slider

> A range slider that heats up from green to red, with a value bubble.

- Category: Inputs & forms
- Tier: Free (MIT)
- Page: https://bowls.dev/components/spice-slider
- Requires: React 18+, Tailwind CSS 4

## Install

Copy the source below into `components/bowls/spice-slider.tsx`.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | — | Visible label. |
| `min / max` | `number` | `0 / 100` | Range. |
| `defaultValue` | `number` | `40` | Starting value. |
| `levels` | `[string, string, string]` | `["Mild","Medium","Hot"]` | Words for each third. |
| `onChange` | `(value: number) => void` | — | Called as it moves. |

## Usage

```tsx
"use client";

import { SpiceSlider } from "@/components/bowls/spice-slider";

export default function Demo() {
  return (
    <div className="flex h-full w-full items-center justify-center px-8">
      <SpiceSlider label="Spice level" defaultValue={62} />
    </div>
  );
}
```

## Source

`components/bowls/spice-slider.tsx`

```tsx
"use client";

import { useId, useState } from "react";

export type SpiceSliderProps = {
  label: string;
  min?: number;
  max?: number;
  defaultValue?: number;
  /** Words shown for the low, middle and high thirds. */
  levels?: [string, string, string];
  onChange?: (value: number) => void;
};

/** A slider whose colour heats up from green to red, with a value bubble. */
export function SpiceSlider({ label, min = 0, max = 100, defaultValue = 40, levels = ["Mild", "Medium", "Hot"], onChange }: SpiceSliderProps) {
  const [value, setValue] = useState(defaultValue);
  const id = useId();
  const pct = (value - min) / (max - min);
  const hue = 130 - pct * 130; // green → red
  const color = `hsl(${hue} 85% 48%)`;
  const level = levels[Math.min(2, Math.floor(pct * 3))];

  return (
    <div className="w-full max-w-[280px]" style={{ ["--c" as string]: color }}>
      <div className="mb-8 flex items-baseline justify-between">
        <label htmlFor={id} className="text-[15px] font-semibold">{label}</label>
        <span className="font-mono text-xs font-semibold" style={{ color }}>{level}</span>
      </div>
      <div className="relative">
        <span
          aria-hidden="true"
          className="absolute -top-8 -translate-x-1/2 rounded-lg px-2 py-1 font-mono text-xs font-bold text-white transition-colors"
          style={{ left: `calc(${pct * 100}% + ${(0.5 - pct) * 22}px)`, background: color }}
        >
          {value}
        </span>
        <input
          id={id}
          type="range"
          min={min}
          max={max}
          value={value}
          onChange={(e) => {
            setValue(Number(e.target.value));
            onChange?.(Number(e.target.value));
          }}
          className="h-3 w-full cursor-pointer appearance-none rounded-full bg-[#e5e5e5] dark:bg-[#2a2a2a] [&::-moz-range-thumb]:size-[22px] [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-4 [&::-moz-range-thumb]:border-white [&::-moz-range-thumb]:bg-[var(--c)] [&::-webkit-slider-thumb]:size-[22px] [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-4 [&::-webkit-slider-thumb]:border-white [&::-webkit-slider-thumb]:bg-[var(--c)] [&::-webkit-slider-thumb]:shadow-[0_2px_8px_rgba(0,0,0,.3)]"
          style={{ backgroundImage: `linear-gradient(90deg, hsl(130 85% 48%), ${color})`, backgroundSize: `${pct * 100}% 100%`, backgroundRepeat: "no-repeat" }}
        />
      </div>
    </div>
  );
}
```
