Range Slider Svelte 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'

Range thumb bg color in iOS theme

colors.thumbBgMaterialstring'range-thumb:bg-primary'

Range thumb bg color in Material theme

colors.valueBgstring'bg-primary'

Range bg color

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.svelte
<script>
import {
Page,
Navbar,
NavbarBackLink,
BlockTitle,
BlockHeader,
List,
ListItem,
Range,
} from 'konsta/svelte';
let volume = 50;
let price = 150;
let red = 100;
let green = 50;
let blue = 75;
</script>
<Page>
<Navbar title="Range Slider" />
<BlockTitle>Volume: {volume}</BlockTitle>
<BlockHeader>From 0 to 100 with step 10</BlockHeader>
<List>
<ListItem innerClass="flex space-x-4">
<svelte:fragment slot="inner">
<span>0</span>
<Range
value={volume}
step={10}
onInput={(e) => (volume = e.target.value)}
/>
<span>100</span>
</svelte:fragment>
</ListItem>
</List>
<BlockTitle>Price: ${price}</BlockTitle>
<BlockHeader>From 0 to 1000 with step 1</BlockHeader>
<List>
<ListItem innerClass="flex space-x-4">
<svelte:fragment slot="inner">
<span>$0</span>
<Range
value={price}
step={1}
min={0}
max={1000}
onInput={(e) => (price = e.target.value)}
/>
<span>$1000</span>
</svelte:fragment>
</ListItem>
</List>
<BlockTitle>
Color: rgb({red}, {green}, {blue})
</BlockTitle>
<List>
<ListItem>
<Range
slot="inner"
colors={{
valueBg: 'bg-red-500',
thumbBgMaterial: 'range-thumb:bg-red-500',
}}
value={red}
step={1}
min={0}
max={255}
onInput={(e) => (red = e.target.value)}
/></ListItem
>
<ListItem>
<Range
slot="inner"
colors={{
valueBg: 'bg-green-500',
thumbBgMaterial: 'range-thumb:bg-green-500',
}}
value={green}
step={1}
min={0}
max={255}
onInput={(e) => (green = e.target.value)}
/></ListItem
>
<ListItem>
<Range
slot="inner"
colors={{
valueBg: 'bg-blue-500',
thumbBgMaterial: 'range-thumb:bg-blue-500',
}}
value={blue}
step={1}
min={0}
max={255}
onInput={(e) => (blue = e.target.value)}
/></ListItem
>
</List>
</Page>
Code licensed under MIT.
2021 © Konsta UI by nolimits4web.