A customizable double-thumb range slider built for Svelte. This component allows users to select a range between a minimum and maximum value with two draggable thumbs.
Install the package via npm:
npm install svelte-5-range-slider
Import the RangeSlider
component into your Svelte file and bind it to two state variables:
<script lang="ts">
import RangeSlider from "svelte-5-range-slider/RangeSlider.svelte";
let thumb1 = $state(25);
let thumb2 = $state(50);
const trackOptions = {
height: 12,
color: "#323841",
radius: 10000,
connecting: {
color: "#ECF9FF",
padding: 4,
radius: 100000,
},
};
const thumbOptions = {
color: "#1D232A",
size: 16,
radius: 20,
};
const sliderOptions = {
min: 18,
max: 90,
step: 1,
};
</script>
<div class="slider-container">
<span>{thumb1} - {thumb2}</span>
<RangeSlider
bind:thumb1
bind:thumb2
{sliderOptions}
{trackOptions}
{thumbOptions}
/>
</div>
sliderOptions: SliderOptions
min
(number) - Minimum value of the slidermax
(number) - Maximum value of the sliderstep
(number) - Increment stepstrackOptions: TrackOptions
height
(number) - Height of the trackcolor
(string) - Color of the trackradius
(number) - Border radius of the trackconnecting.color
(string) - Color of the selected range sectionconnecting.padding
(number) - Padding around the selected rangeconnecting.radius
(number) - Border radius of the selected rangethumbOptions: ThumbOptions
color
(string) - Color of the thumbsize
(number) - Size of the thumbradius
(number) - Border radius of the thumbborder.size
(number) - Border width of the thumb (optional)border.color
(string) - Border color of the thumb (optional)interface TrackOptions {
height: number;
color: string;
radius: number;
class?: string;
connecting?: {
color: string;
padding: number;
radius: number;
class?: string;
} | null;
}
interface ThumbOptions {
color: string;
size: number;
radius: number;
class?: string;
border?: {
size: number;
color: string;
} | null;
}
interface SliderOptions {
min: number;
max: number;
step: number;
}
This component automatically updates thumb1
and thumb2
values when the user interacts with the slider.
The slider is styled via inline styles and can be customized using the provided options. If additional styling is needed, you can wrap it in a styled container and apply CSS classes accordingly.
This project is licensed under the MIT License.
Happy coding! 🎉