Slider
An input where the user selects a value from within a given range.
import Slider from '@dinui/react/slider'import { cn } from '@dinui/react/utils'
type SliderProps = React.ComponentProps<typeof Slider>
export default function SliderDemo({ className, ...props }: SliderProps) { return ( <Slider defaultValue={[50]} max={100} step={1} className={cn('w-[60%]', className)} {...props} /> )}Installation
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Run the following command in your project
Terminal window npx @dinui/cli@latest add sliderTerminal window yarn dlx @dinui/cli@latest add sliderTerminal window pnpm dlx @dinui/cli@latest add sliderTerminal window bunx @dinui/cli@latest add slider -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Install dependencies
Terminal window npm install @radix-ui/react-slider tailwind-variants type-festTerminal window yarn add @radix-ui/react-slider tailwind-variants type-festTerminal window pnpm add @radix-ui/react-slider tailwind-variants type-festTerminal window bun add @radix-ui/react-slider tailwind-variants type-fest -
Copy and paste the following code into your project
'use client'import * as SliderPrimitive from '@radix-ui/react-slider'import { forwardRef } from 'react'import { tv } from 'tailwind-variants'import type { Merge } from 'type-fest'const slider = tv({slots: {root: 'relative flex w-full touch-none select-none items-center',track: 'relative h-1.5 w-full grow overflow-hidden rounded-full bg-bg--muted',range: 'absolute h-full bg-fg-brand',thumb:'block h-4 w-4 rounded-full border border-fg/70 bg-bg--contrast shadow transition-colors disabled:pointer-events-none disabled:opacity-50',},})const Slider = forwardRef<React.ElementRef<typeof SliderPrimitive.Root>,Merge<React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>,{trackProps?: React.ComponentProps<typeof SliderPrimitive.Track>rangeProps?: React.ComponentProps<typeof SliderPrimitive.Range>thumbProps?: React.ComponentProps<typeof SliderPrimitive.Thumb>}>>(({ trackProps, rangeProps, thumbProps, ...props }, ref) => {const { root, range, thumb, track } = slider()return (<SliderPrimitive.Root {...props} ref={ref} className={root({ className: props.className })}><SliderPrimitive.Track{...trackProps}className={track({ className: trackProps?.className })}><SliderPrimitive.Range{...rangeProps}className={range({ className: rangeProps?.className })}/></SliderPrimitive.Track><SliderPrimitive.Thumb{...thumbProps}className={thumb({ className: thumbProps?.className })}/></SliderPrimitive.Root>)})Slider.displayName = SliderPrimitive.Root.displayNameexport default Sliderexport { slider, SliderPrimitive } -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.