Vue Slide Bar Component

1.2.0 · active · verified Tue Apr 21

vue-slide-bar is a lightweight and straightforward slider component designed for Vue 2 applications. Currently stable at version 1.2.0, this package provides a customizable UI element for selecting values within a range or from a predefined dataset. While a specific release cadence isn't published, updates appear to be driven by bug fixes or minor feature additions. Its key differentiators include simple integration, support for both continuous numeric ranges and discrete data points with custom labels, and extensive styling options for the slider bar, labels, and tooltips. It allows for flexible configuration of minimum/maximum values, custom line height, and a callback function for range value changes. The component focuses on ease of use within existing Vue 2 projects, offering both global and local component registration methods.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Vue Slide Bar with v-model binding, and a more advanced setup with custom data points, labels, and styling, including event handling.

<template>
  <div id="app">
    <h1>Vue Slide Bar Demo</h1>
    <div style="width: 80%; margin: 50px auto;">
      <h2>Simple Slider</h2>
      <VueSlideBar v-model="simpleValue"/>
      <p>Value: {{ simpleValue }}</p>

      <h2>Slider with Custom Range and Labels</h2>
      <VueSlideBar
        v-model="rangeSlider.value"
        :data="rangeSlider.data"
        :range="rangeSlider.range"
        :labelStyles="{ color: '#fff', backgroundColor: '#337ab7' }"
        :processStyle="{ backgroundColor: '#337ab7' }"
        @callbackRange="handleRangeCallback">
        <template slot="tooltip" slot-scope="tooltip">
          <span>{{ tooltip.label || tooltip.value }}</span>
        </template>
      </VueSlideBar>
      <p>Value: {{ rangeSlider.value }} (Label: {{ rangeLabel }})</p>
    </div>
  </div>
</template>

<script>
import VueSlideBar from 'vue-slide-bar';

export default {
  name: 'App',
  components: {
    VueSlideBar,
  },
  data() {
    return {
      simpleValue: 50,
      rangeLabel: '',
      rangeSlider: {
        value: 45,
        data: [15, 30, 45, 60, 75, 90, 120],
        range: [
          { label: '15 mins' },
          { label: '30 mins', isHide: true },
          { label: '45 mins' },
          { label: '1 hr', isHide: true },
          { label: '1 hr 15 mins' },
          { label: '1 hr 30 mins', isHide: true },
          { label: '2 hrs' }
        ]
      }
    };
  },
  methods: {
    handleRangeCallback(val) {
      this.rangeLabel = val.label;
    },
  },
  mounted() {
      const initialRangeItem = this.rangeSlider.range.find(
          (item, index) => this.rangeSlider.data[index] === this.rangeSlider.value
      );
      if (initialRangeItem) {
          this.rangeLabel = initialRangeItem.label;
      }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

view raw JSON →