Slider
basecn/sliderFreeComponent
An input where the user selects a value from within a given range.
Live preview
live · rendered by the registry
Rendered by basecn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://basecn.dev/r/slider.jsonSource
1"use client";23import * as React from "react";4import { Slider as SliderPrimitive } from "@base-ui/react/slider";56import { cn } from "@/lib/utils";78function Slider({9 className,10 defaultValue,11 value,12 min = 0,13 max = 100,14 ...props15}: SliderPrimitive.Root.Props) {16 const _values = React.useMemo(17 () =>18 Array.isArray(value)19 ? value20 : Array.isArray(defaultValue)21 ? defaultValue22 : [min, max],23 [value, defaultValue, min, max]24 );2526 return (27 <SliderPrimitive.Root28 data-slot="slider"29 defaultValue={defaultValue}30 value={value}31 min={min}32 max={max}33 className={cn(34 "relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",35 className36 )}37 {...props}38 >39 <SliderPrimitive.Control className="grid grow data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5">40 <SliderPrimitive.Track41 data-slot="slider-track"42 className={cn(43 "bg-muted relative overflow-hidden rounded-full data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"44 )}45 >46 <SliderPrimitive.Indicator47 data-slot="slider-range"48 className={cn(49 "bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"50 )}51 />52 </SliderPrimitive.Track>53 {Array.from({ length: _values.length }, (_, index) => (54 <SliderPrimitive.Thumb55 data-slot="slider-thumb"56 key={index}57 className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"58 />59 ))}60 </SliderPrimitive.Control>61 </SliderPrimitive.Root>62 );63}6465export { Slider };
What it pulls in
npm packages
Files it writes
More from basecn
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | basecn | Components | Free | 2 deps | |
| Alertalert | basecn | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | basecn | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | basecn | Components | Free | no deps | |
| Autocompleteautocomplete | basecn | Components | Free | 2 deps | |
| Avataravatar | basecn | Components | Free | 1 dep | |
| Badgebadge | basecn | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | basecn | Components | Free | 2 deps |
