Slider
fluid-functionalism/sliderFreeComponent
Animated slider with spring-snapped thumb, step dots, range mode, and click-to-edit value display. Built on Radix UI Slider.
Install it
npx shadcn@latest add https://fluidfunctionalism.com/r/slider.jsonSource
1"use client";23import {4 forwardRef,5 useRef,6 useState,7 useEffect,8 useLayoutEffect,9 useCallback,10 useMemo,11 type CSSProperties,12 type HTMLAttributes,13} from "react";14import {15 motion,16 useMotionValue,17 useTransform,18 animate,19 AnimatePresence,20 type MotionValue,21} from "framer-motion";22import * as SliderPrimitive from "@radix-ui/react-slider";23import { cn } from "@/lib/utils";24import { spring } from "@/lib/springs";25import { fontWeights } from "@/lib/font-weight";26import { useShape } from "@/lib/shape-context";2728// ---------------------------------------------------------------------------29// Types30// ---------------------------------------------------------------------------3132type SliderValue = number | [number, number];33type ValuePosition = "left" | "right" | "top" | "bottom" | "tooltip";3435interface SliderProps36 extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> {37 value: SliderValue;38 onChange: (value: SliderValue) => void;39 min?: number;40 max?: number;41 step?: number;42 /**43 * Discrete list of allowed values, e.g. [0.1, 0.5, 0.7, 1.1, 1.3].44 *45 * When set, the thumb snaps only to these values (positioned proportionally46 * along the track) and arrow keys walk the list. `min`/`max` derive from the47 * list's extremes and `step` is ignored.48 */49 steps?: number[];50 showSteps?: boolean;51 showValue?: boolean;52 valuePosition?: ValuePosition;53 formatValue?: (v: number) => string;54 label?: string;55 disabled?: boolean;56 trackClassName?: string;57 trackStyle?: CSSProperties;58 fillClassName?: string;59 fillStyle?: CSSProperties;60 hideFill?: boolean;61 thumbColor?: string;62 thumbBorderColor?: string;63}6465// ---------------------------------------------------------------------------66// Constants67// ---------------------------------------------------------------------------6869const THUMB_SIZE = 20;70const THUMB_SIZE_REST = 16;71const TRACK_BG_HEIGHT = 18;72const DOT_SIZE = 4;73const PIP_SIZE = 5;74// Inset track BG so its rounded-end centers align with thumb centers at min/max75const TRACK_INSET = (THUMB_SIZE - TRACK_BG_HEIGHT) / 2;7677// ---------------------------------------------------------------------------78// Helpers79// ---------------------------------------------------------------------------8081function valueToPixel(82 v: number,83 min: number,84 max: number,85 trackWidth: number86): number {87 if (max === min) return 0;88 const usable = trackWidth - THUMB_SIZE;89// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fluid-functionalism
All 53 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | fluid-functionalism | Components | Free | 3 deps | |
| Accordion (Base UI)accordion-base | fluid-functionalism | Components | Free | 3 deps | |
| Ask User Questionsask-user-questions | fluid-functionalism | Components | Free | 2 deps | |
| Badgebadge | fluid-functionalism | Components | Free | 1 dep | |
| Buttonbutton | fluid-functionalism | Components | Free | 4 deps | |
| Button (Base UI)button-base | fluid-functionalism | Components | Free | 4 deps | |
| Cardcard | fluid-functionalism | Components | Free | 1 dep | |
| Chat Messagechat-message | fluid-functionalism | Components | Free | 1 dep |
