Adaptive Slider Free React component
A range slider whose track gradient, thumb and number shift colour as the value climbs, with the number rolling to every new value.
Original component by Watermelon UI · MIT licence
Get the code
npx shadcn@latest add https://registry.watermelon.sh/r/adaptive-slider.jsonInstalls from the Watermelon UI registry through the shadcn CLI. Needs Tailwind CSS and the motion package, which the command adds for you.
import { AdaptiveSlider } from '../adaptive-slider'
function AdaptiveSliderDemo() {
return (
<div className="flex justify-center items-center">
<AdaptiveSlider
min={100}
max={800}
step={50}
defaultValue={300}
/>
</div>
)
}
export default AdaptiveSliderDemo// adaptive-slider, from Watermelon UI: https://ui.watermelon.sh/animated-components/adaptive-slider
// MIT License. Copyright (c) 2025-present Watermelon Contributors.
"use client";
import { useState, useMemo, type FC, type ChangeEvent } from "react";
import { AnimatePresence, motion } from "motion/react";
import { cn } from "@/lib/utils";
interface AdaptiveSliderProps {
value?: number;
min?: number;
max?: number;
step?: number;
defaultValue?: number;
onChange?: (value: number) => void;
}
interface ColorSettings {
text: string;
gradient: string;
thumbBorder: string;
}
const DEFAULT_MIN = 50;
const DEFAULT_MAX = 350;
const DEFAULT_STEP = 25;
const DEFAULT_VALUE = 200;
const getColorSettings = (
value: number,
min: number,
max: number
): ColorSettings => {
const percentage = (value - min) / (max - min);
if (percentage < 0.5) {
return {
text: "#10B981",
gradient: "linear-gradient(to right, #FEB101, #FE7C09)",
thumbBorder: "#10B981",
};
} else if (percentage < 0.7) {
return {
text: "#FE55B7",
gradient: "linear-gradient(to right, #FE55B74D, #FE55B7)",
thumbBorder: "#F97316",
};
} else {
return {
text: "#D946EF",
gradient: "linear-gradient(to right, #DAB0FE, #4946FF)",
thumbBorder: "#D946EF",
};
}
};
export const AdaptiveSlider: FC<AdaptiveSliderProps> = ({
value,
min = DEFAULT_MIN,
max = DEFAULT_MAX,
step = DEFAULT_STEP,
defaultValue = DEFAULT_VALUE,
onChange,
}) => {
const [internalValue, setInternalValue] = useState<number>(defaultValue);
const calories = value ?? internalValue;
const colorSettings = useMemo(
() => getColorSettings(calories, min, max),
[calories, min, max]
);
const percentage = ((calories - min) / (max - min)) * 100;
const dots = useMemo(
() =>
Array.from({ length: 6 }).map((_, i) => (
<div
key={i}
className="z-30 h-1.5 w-1.5 rounded-full bg-[#C4B9FA] transition-colors dark:bg-neutral-600"
style={{ opacity: 0.8 }}
/>
)),
[]
);
const handleSliderChange = (e: ChangeEvent<HTMLInputElement>) => {
const val = Number(e.target.value);
setInternalValue(val);
onChange?.(val);
};
return (
<motion.div className="flex h-[60vh] w-xs flex-col items-center justify-center rounded-[36px] bg-[#FEFEFE] p-6 shadow-2xl shadow-black/5 transition-colors select-none sm:w-sm sm:p-12 dark:bg-neutral-900 dark:shadow-none">
<span className="mb-2 text-xl font-bold text-[#878787] sm:text-2xl dark:text-neutral-500">
Calories
</span>
<div className="mb-8 flex items-baseline gap-2">
<AnimatedText
value={calories.toString()}
className="overflow-hidden text-5xl font-extrabold tracking-tight sm:text-6xl"
/>
<motion.span
layout
className="text-4xl font-extrabold text-[#010101] transition-colors sm:text-5xl dark:text-neutral-100"
>
kCal
</motion.span>
</div>
<div className="group relative flex h-13 w-full items-center overflow-hidden rounded-full bg-[#f1f3f5] transition-colors dark:bg-neutral-800">
<div className="pointer-events-none absolute inset-0 flex items-center justify-between px-4 transition-colors sm:px-8">
{dots}
</div>
<motion.div
className="pointer-events-none absolute top-0 left-0 h-full rounded-full"
animate={{
width: `calc((${percentage} / 100) * (100% - 52px) + 52px)`,
background: colorSettings.gradient,
}}
transition={{ type: "spring", stiffness: 300, damping: 30 }}
/>
<input
title="range"
type="range"
min={min}
max={max}
step={step}
value={calories}
onChange={handleSliderChange}
className="absolute inset-0 z-50 h-13 w-full cursor-pointer opacity-0"
/>
<motion.div
className="pointer-events-none absolute top-0 z-40 flex size-13 items-center justify-center rounded-full border-none"
animate={{
left: `calc((${percentage} / 100) * (100% - 52px))`,
}}
transition={{ type: "spring", stiffness: 300, damping: 30 }}
>
<div className="size-10 rounded-full bg-white shadow-[inset_0_2px_4px_rgba(0,0,0,0.06)]" />
</motion.div>
</div>
</motion.div>
);
};
const AnimatedText = ({
value,
className,
}: {
value: string;
className?: string;
}) => {
return (
<div
className={cn(
"flex text-lg tracking-tight will-change-transform",
className
)}
>
<AnimatePresence mode="popLayout" initial={false}>
{value.split("").map((char, index) => {
const displayChar = char === " " ? "\u00A0" : char;
return (
<motion.span
key={char + index}
initial={{ opacity: 1, y: 0, scale: 1 }}
animate={{
opacity: 1,
y: 0,
scale: 1,
transition: {
type: "spring",
stiffness: 200,
damping: 20,
// delay: 0.03 * index,
},
}}
exit={{ opacity: 0, y: 0, scale: 1, transition: { duration: 0 } }}
>
{displayChar}
</motion.span>
);
})}
</AnimatePresence>
</div>
);
};
Paste this into Claude, ChatGPT, Cursor, Lovable or v0 to build it from scratch.
Build a React component called "Adaptive Slider" with Tailwind CSS and Motion (motion/react). A range slider whose track gradient, thumb and number shift colour as the value climbs, with the number rolling to every new value. Use spring transitions, keep it accessible with keyboard focus and aria labels, respect prefers-reduced-motion, and make it work on touch screens. Export it as a single .tsx file with sensible default props so it renders a complete demo on its own.How the adaptive slider works
A range slider whose track gradient, thumb and number shift colour as the value climbs, with the number rolling to every new value. The component is a single TypeScript file built with React, Tailwind CSS and Motion, so the animation runs on springs and shared layouts instead of hand-written keyframes.
It comes from Watermelon UI, an open-source component library released under the MIT licence. Install it with the shadcn command above, or copy the source from the code tab into your project.
Frequently asked questions
Want motion like this on your website?
We design and build custom websites with motion, 3D and SEO built in. Websites from $500.