1import {2 Slider,3 SliderFill,4 SliderLabel,5 SliderThumb,6 SliderTrack,7 SliderValueLabel,8} from "~/components/ui/slider";9
10export default function SliderDemo() {11 return (12 <Slider13 minValue={10}14 maxValue={2000}15 defaultValue={[20, 500]}16 getValueLabel={(params) => `$${params.values[0]} - $${params.values[1]}`}17 class="w-[300px] space-y-3"18 >19 <div class="flex w-full justify-between">20 <SliderLabel>Money</SliderLabel>21 <SliderValueLabel />22 </div>23 <SliderTrack>24 <SliderFill />25 <SliderThumb />26 <SliderThumb />27 </SliderTrack>28 </Slider>29 );30}
npx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/slider.json
yarn shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/slider.json
pnpm dlx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/slider.json
bunx --bun shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/slider.json
Install the following dependencies
npm install @kobalte/core
yarn add @kobalte/core
pnpm add @kobalte/core
bun add @kobalte/core
Install the following component dependencies
Copy and paste the following code into your project
1import type { PolymorphicProps } from "@kobalte/core/polymorphic";2import type { JSX, ValidComponent } from "solid-js";3
4import { splitProps } from "solid-js";5import * as SliderPrimitive from "@kobalte/core/slider";6
7import { Label } from "~/components/ui/label";8import { cn } from "~/lib/utils";9
10type SliderRootProps<T extends ValidComponent = "div"> =11 SliderPrimitive.SliderRootProps<T> & {12 class?: string | undefined;13 };14
15const Slider = <T extends ValidComponent = "div">(16 props: PolymorphicProps<T, SliderRootProps<T>>,17) => {18 const [local, others] = splitProps(props as SliderRootProps, ["class"]);19 return (20 <SliderPrimitive.Root21 data-slot="slider"22 class={cn(23 "relative flex w-full touch-none flex-col items-center select-none",24 local.class,25 )}26 {...others}27 />28 );29};30
31type SliderTrackProps<T extends ValidComponent = "div"> =32 SliderPrimitive.SliderTrackProps<T> & {33 class?: string | undefined;34 };35
36const SliderTrack = <T extends ValidComponent = "div">(37 props: PolymorphicProps<T, SliderTrackProps<T>>,38) => {39 const [local, others] = splitProps(props as SliderTrackProps, ["class"]);40 return (41 <SliderPrimitive.Track42 data-slot="slider-track"43 class={cn(44 "relative h-3 w-full grow rounded-base border-2 border-border bg-secondary-background",45 local.class,46 )}47 {...others}48 />49 );50};51
52type SliderFillProps<T extends ValidComponent = "div"> =53 SliderPrimitive.SliderFillProps<T> & {54 class?: string | undefined;55 };56
57const SliderFill = <T extends ValidComponent = "div">(58 props: PolymorphicProps<T, SliderFillProps<T>>,59) => {60 const [local, others] = splitProps(props as SliderFillProps, ["class"]);61 return (62 <SliderPrimitive.Fill63 data-slot="slider-fill"64 class={cn("absolute h-full rounded-base bg-primary", local.class)}65 {...others}66 />67 );68};69
70type SliderThumbProps<T extends ValidComponent = "span"> =71 SliderPrimitive.SliderThumbProps<T> & {72 class?: string | undefined;73 children?: JSX.Element;74 };75
76const SliderThumb = <T extends ValidComponent = "span">(77 props: PolymorphicProps<T, SliderThumbProps<T>>,78) => {79 const [local, others] = splitProps(props as SliderThumbProps, [80 "class",81 "children",82 ]);83 return (84 <SliderPrimitive.Thumb85 data-slot="slider-thumb"86 class={cn(87 "-top-1.5 block size-5 rounded-full border-2 border-border bg-white ring-offset-white transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",88 local.class,89 )}90 {...others}91 >92 <SliderPrimitive.Input />93 </SliderPrimitive.Thumb>94 );95};96
97const SliderLabel = <T extends ValidComponent = "label">(98 props: PolymorphicProps<T, SliderPrimitive.SliderLabelProps<T>>,99) => {100 return (101 <SliderPrimitive.Label data-slot="slider-label" as={Label} {...props} />102 );103};104
105const SliderValueLabel = <T extends ValidComponent = "label">(106 props: PolymorphicProps<T, SliderPrimitive.SliderValueLabelProps<T>>,107) => {108 return (109 <SliderPrimitive.ValueLabel110 data-slot="slider-value-label"111 as={Label}112 {...props}113 />114 );115};116
117export {118 Slider,119 SliderTrack,120 SliderFill,121 SliderThumb,122 SliderLabel,123 SliderValueLabel,124};
Update the import paths to match your project setup.
1import {2 Slider,3 SliderFill,4 SliderLabel,5 SliderThumb,6 SliderTrack,7 SliderValueLabel,8} from "~/components/ui/slider";
1<Slider>2 <SliderTrack>3 <SliderFill />4 <SliderThumb />5 </SliderTrack>6</Slider>
1import {2 Slider,3 SliderFill,4 SliderLabel,5 SliderThumb,6 SliderTrack,7 SliderValueLabel,8} from "~/components/ui/slider";9
10export default function SliderDemo() {11 return (12 <Slider13 minValue={10}14 maxValue={2000}15 defaultValue={[500]}16 getValueLabel={(params) => `$${params.values[0]}`}17 class="w-[300px] space-y-3"18 >19 <div class="flex w-full justify-between">20 <SliderLabel>Money</SliderLabel>21 <SliderValueLabel />22 </div>23 <SliderTrack>24 <SliderFill />25 <SliderThumb />26 </SliderTrack>27 </Slider>28 );29}