The Slider component extends Base UI's Slider. It provides a user control for selecting a value or a range of values from a specified range.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/slider
// https://base-ui.com/react/components/slider
import { Slider as BaseSlider } from "@base-ui/react/slider";
import clsx from "clsx";
import styles from "./Slider.module.scss";
function Root({ className, ...props }: BaseSlider.Root.Props) {
return (
<BaseSlider.Root className={clsx(styles.root, className)} {...props} />
);
}
function Control({ className, ...props }: BaseSlider.Control.Props) {
return (
<BaseSlider.Control
className={clsx(styles.control, className)}
{...props}
/>
);
}
function Track({ className, ...props }: BaseSlider.Track.Props) {
return (
<BaseSlider.Track className={clsx(styles.track, className)} {...props} />
);
}
function Indicator({ className, ...props }: BaseSlider.Indicator.Props) {
return (
<BaseSlider.Indicator
className={clsx(styles.indicator, className)}
{...props}
/>
);
}
function Thumb({ className, ...props }: BaseSlider.Thumb.Props) {
return (
<BaseSlider.Thumb className={clsx(styles.thumb, className)} {...props} />
);
}
function Value({ className, ...props }: BaseSlider.Value.Props) {
return (
<BaseSlider.Value className={clsx(styles.value, className)} {...props} />
);
}
const Slider = {
Root,
Control,
Track,
Indicator,
Thumb,
Value,
};
namespace Slider {
export namespace Root {
export type Props = BaseSlider.Root.Props;
export type State = BaseSlider.Root.State;
export type ChangeEventDetails = BaseSlider.Root.ChangeEventDetails;
}
export namespace Control {
export type Props = BaseSlider.Control.Props;
}
export namespace Track {
export type Props = BaseSlider.Track.Props;
}
export namespace Indicator {
export type Props = BaseSlider.Indicator.Props;
}
export namespace Thumb {
export type Props = BaseSlider.Thumb.Props;
export type State = BaseSlider.Thumb.State;
}
export namespace Value {
export type Props = BaseSlider.Value.Props;
}
}
export default Slider;A basic slider with a single thumb. Use the defaultValue prop for uncontrolled usage, or value with onValueChange for controlled state management.
For range selection, pass an array to defaultValue and render multiple Slider.Thumb components with the index prop.
Use the Slider.Value component to display the current slider value. It automatically updates as the slider is moved.
Set the orientation prop to "vertical" for a vertical slider layout.
Sliders can be disabled using the disabled prop. When disabled, the slider is not interactive and shows a reduced visual state.