Range Slider React Component

Range Slider Components

There are following components included:

  • Range

Range Props

NameTypeDefaultDescription
colorsobject

Object with Tailwind CSS colors classes

colors.thumbBgIosstring'range-thumb:bg-white'
colors.thumbBgMaterialstring'range-thumb:bg-md-light-primary dark:range-thumb:bg-md-dark-primary'
colors.valueBgIosstring'bg-primary'
colors.valueBgMaterialstring'bg-md-light-primary dark:bg-md-dark-primary'
componentstring'div'

Component's HTML Element

defaultValueany

Range value, in case of uncontrolled component

disabledbooleanfalse

Defines whether the range input is disabled

inputIdstring

Range input id attribute

maxnumber100

Range max value

minnumber0

Range min value

namestring

Range input name

readOnlybooleanfalse

Defines whether the range input is readonly

stepnumber1

Range step

valueany

Range value

onBlurfunction(e)

blur event handler

onChangefunction(e)

change event handler

onFocusfunction(e)

focus event handler

onInputfunction(e)

input event handler

Examples

RangeSlider.jsx
import React, { useState } from 'react';
import {
Page,
Navbar,
NavbarBackLink,
BlockTitle,
BlockHeader,
List,
ListItem,
Range,
} from 'konsta/react';
export default function RangeSliderPage() {
const [volume, setVolume] = useState(50);
const [price, setPrice] = useState(150);
const [red, setRed] = useState(100);
const [green, setGreen] = useState(50);
const [blue, setBlue] = useState(75);
return (
<Page>
<Navbar
title="Range Slider"
/>
<BlockTitle>Volume: {volume}</BlockTitle>
<BlockHeader>From 0 to 100 with step 10</BlockHeader>
<List strong insetMaterial outlineIos>
<ListItem
innerClassName="flex space-x-4 rtl:space-x-reverse"
innerChildren={
<>
<span>0</span>
<Range
value={volume}
step={10}
onChange={(e) => setVolume(e.target.value)}
/>
<span>100</span>
</>
}
/>
</List>
<BlockTitle>Price: ${price}</BlockTitle>
<BlockHeader>From 0 to 1000 with step 1</BlockHeader>
<List strong insetMaterial outlineIos>
<ListItem
innerClassName="flex space-x-4 rtl:space-x-reverse"
innerChildren={
<>
<span>$0</span>
<Range
value={price}
step={1}
min={0}
max={1000}
onChange={(e) => setPrice(e.target.value)}
/>
<span>$1000</span>
</>
}
/>
</List>
<BlockTitle>
Color: rgb({red}, {green}, {blue})
</BlockTitle>
<List strong insetMaterial outlineIos>
<ListItem
innerChildren={
<Range
className="k-color-brand-red"
value={red}
step={1}
min={0}
max={255}
onChange={(e) => setRed(e.target.value)}
/>
}
/>
<ListItem
innerChildren={
<Range
className="k-color-brand-green"
value={green}
step={1}
min={0}
max={255}
onChange={(e) => setGreen(e.target.value)}
/>
}
/>
<ListItem
innerChildren={
<Range
className="k-color-brand-blue"
value={blue}
step={1}
min={0}
max={255}
onChange={(e) => setBlue(e.target.value)}
/>
}
/>
</List>
</Page>
);
}
Code licensed under MIT.
2022 © Konsta UI by nolimits4web.