Range Slider Vue 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

componentstring'div'

Component's HTML Element

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

Range Events

NameTypeDescription
blurfunction(e)

blur event handler

changefunction(e)

change event handler

focusfunction(e)

focus event handler

inputfunction(e)

input event handler

Examples

RangeSlider.vue
<template>
<twm-page>
<twm-navbar title="Range Slider" />
<twm-block-title>Volume: {{ volume }}</twm-block-title>
<twm-block-header>From 0 to 100 with step 10</twm-block-header>
<twm-list>
<twm-list-item inner-class="flex space-x-4">
<template #inner>
<span>0</span>
<twm-range
:value="volume"
:step="10"
@input="(e) => (volume = parseInt(e.target.value, 10))"
/>
<span>100</span>
</template>
</twm-list-item>
</twm-list>
<twm-block-title>Price: ${{ price }}</twm-block-title>
<twm-block-header>From 0 to 1000 with step 1</twm-block-header>
<twm-list>
<twm-list-item inner-class="flex space-x-4">
<template #inner>
<span>$0</span>
<twm-range
:value="price"
:step="1"
:min="0"
:max="1000"
@input="(e) => (price = parseInt(e.target.value, 10))"
/>
<span>$1000</span>
</template>
</twm-list-item>
</twm-list>
<twm-block-title>
Color: rgb({{ red }}, {{ green }}, {{ blue }})
</twm-block-title>
<twm-list>
<twm-list-item>
<template #inner>
<twm-range
:colors="{
valueBg: 'bg-red-500',
thumbBgMaterial: 'range-thumb:bg-red-500',
}"
:value="red"
:step="1"
:min="0"
:max="255"
@input="(e) => (red = parseInt(e.target.value, 10))"
/>
</template>
</twm-list-item>
<twm-list-item>
<template #inner>
<twm-range
:colors="{
valueBg: 'bg-green-500',
thumbBgMaterial: 'range-thumb:bg-green-500',
}"
:value="green"
:step="1"
:min="0"
:max="255"
@input="(e) => (green = parseInt(e.target.value, 10))"
/>
</template>
</twm-list-item>
<twm-list-item>
<template #inner>
<twm-range
:colors="{
valueBg: 'bg-blue-500',
thumbBgMaterial: 'range-thumb:bg-blue-500',
}"
:value="blue"
:step="1"
:min="0"
:max="255"
@input="(e) => (blue = parseInt(e.target.value, 10))"
/>
</template>
</twm-list-item>
</twm-list>
</twm-page>
</template>
<script>
import { ref } from 'vue';
import {
twmPage,
twmNavbar,
twmNavbarBackLink,
twmBlockTitle,
twmBlockHeader,
twmList,
twmListItem,
twmRange,
} from 'tailwind-mobile/vue';
export default {
components: {
twmPage,
twmNavbar,
twmNavbarBackLink,
twmBlockTitle,
twmBlockHeader,
twmList,
twmListItem,
twmRange,
},
setup() {
const volume = ref(50);
const price = ref(150);
const red = ref(100);
const green = ref(50);
const blue = ref(75);
return {
volume,
price,
red,
green,
blue,
};
},
};
</script>
Code licensed under MIT.
2021 © Tailwind Mobile by nolimits4web.