Categories
Top Vue Packages

Top Vue Packages for Adding a Time Selector, Context Menu, and Scrollbar

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps. In this article, we’ll look at how the best packages for adding a time selector, context menu, and more.

Vue-timeselector

vue-timeselector lets us add a time picker into our Vue app.

To install it, we can run:

npm i vue-timeselector

Then we can use it by writing:

App.vue

<template>
  <div>
    <timeselector v-model="time"></timeselector>
    <p>{{time}}</p>
  </div>
</template>

<script>
import Timeselector from "vue-timeselector";

export default {
  components: {
    Timeselector
  },
  data() {
    return {
      time: undefined
    };
  }
};
</script>

Now we get an input element where we can set the time. It emits the input event which is emitted with the inputted value. name sets the name attribute of the input. We can also set the input to required or disable the input. Also, we can set a placeholder like any other input. Optionally, we can add a second picker to let us pick the seconds. The interval can be changed with the interval prop.

We can add the second’s picker and change the interval of the pickers by writing:

<template>
  <div>
    <timeselector v-model="time" :interval="{h:2, m:1, s:10}" displaySeconds></timeselector>
    <p>{{time}}</p>
  </div>
</template>

<script>
import Timeselector from "vue-timeselector";

export default {
  components: {
    Timeselector
  },
  data() {
    return {
      time: undefined
    };
  }
};
</script>

vue-simple-context-menu

The vue-simple-context-menu lets us add a context menu to our app.

To install it, we can run:

npm i vue-simple-context-menu

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import "vue-simple-context-menu/dist/vue-simple-context-menu.css";

import VueSimpleContextMenu from "vue-simple-context-menu";
Vue.component("vue-simple-context-menu", VueSimpleContextMenu);

Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <div class="item-wrapper">
      <div
        v-for="item in items"
        :key="item"
        [@click](http://twitter.com/click "Twitter profile for @click").prevent.stop="handleClick($event, item)"
      >{{item}}</div>
    </div>

<vue-simple-context-menu
      :elementId="'myUniqueId'"
      :options="options"
      :ref="'vueSimpleContextMenu'"
      [@option](http://twitter.com/option "Twitter profile for @option")-clicked="optionClicked"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: ["foo", "bar"],
      options: [
        {
          name: "foo"
        },
        {
          name: "bar"
        }
      ]
    };
  },
  methods: {
    handleClick(event, item) {
      this.$refs.vueSimpleContextMenu.showMenu(event, item);
    },

    optionClicked(event) {
      window.alert(JSON.stringify(event));
    }
  }
};
</script>

We register the plugin and import the CSS for the menu from the package in main.js . Then we add the vue-simple-context-menu to add the menu to our component. It can be styled with the vue-simple-context-menu class.

vue2-perfect-scrollbar

The vue2-perfect-scrollbar package lets us add a scrollbar to our app into any element.

We can install it by running:

npm i vue2-perfect-scrollbar

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import PerfectScrollbar from "vue2-perfect-scrollbar";
import "vue2-perfect-scrollbar/dist/vue2-perfect-scrollbar.css";

Vue.use(PerfectScrollbar);

Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <perfect-scrollbar>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ultricies, odio vitae cursus placerat, felis nibh consectetur arcu, vel consectetur enim enim in purus. Cras non viverra arcu, ac semper mi. Sed vehicula porttitor malesuada. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas id libero eleifend, bibendum odio a, efficitur neque. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum hendrerit tellus posuere massa rutrum, eu congue nisi ornare.</p>

      <p>Vestibulum sed dapibus eros. Quisque semper quam non laoreet rutrum. Vestibulum efficitur dictum sem eget ornare. Nullam egestas arcu erat, quis elementum felis venenatis ac. In commodo, lacus at vestibulum viverra, ante ante tristique metus, id tempus augue erat sed ipsum. Nullam ut nibh non augue mattis porta. Curabitur consectetur tellus eu tellus eleifend, ut ornare urna suscipit. Ut pharetra nulla fringilla, ultrices arcu ac, ullamcorper leo. In ultricies erat ac semper laoreet. Ut tristique condimentum dui eget tempus. Sed sed placerat nulla. Ut at blandit neque, vitae sodales urna. Vestibulum id ultrices ante, eget blandit ex.</p>
    </perfect-scrollbar>
  </div>
</template>

<script>
export default {};
</script>

<style>
.ps {
  height: 400px;
}
</style>

Because we have the perfect-scrollbar component, we’ll see a scrollbar generated by it displayed instead of the browser’s native scrollbar.

We can style the element rendered by perfect-scrollbar with the .ps class.

Conclusion

vue-timeselector lets us add a time picker to our Vue app. vue-simple-context-menu lets us add a context menu to our app. vue2-perfect-scrollbar replaces the native scrollbar with its own. Thanks for reading my article, I hope you found it helpful!

Categories
Top Vue Packages

Top Vue Packages for Adding Text Editor, Spinner, Progress Bar, and File Upload

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at how the best packages for adding a rich text editor, file upload control, spinner, and progress bar.

Vue2Editor

Vue2Editor is an easy to use rich text editor component based on Quill.

To install it, we can run:

npm i vue2-editor

Then we can use it by writing:

<template>
  <div id="app">
    <vue-editor v-model="content"></vue-editor>
    <p v-html="content"></p>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  components: {
    VueEditor
  },

  data() {
    return {
      content: "<h1>hello</h1>"
    };
  }
};
</script>

We have the vue-editor component which binds to the content state with v-model .

It comes with common features like bold, italic, underline, different style text, lists, images, videos, links, and more.

There are many other customizations like placeholders.

It also emits events for blur, focus, adding images, changing selection, and more.

We can also change how images are uploaded.

vue-spinner

vue-spinner is a spinner component so that we display something when our data is loading.

To use it, we first install it by running:

npm i vue-spinner

Then we can use it by writing:

<template>
  <div id="app">
    <pulse-loader loading :color="color"></pulse-loader>
  </div>
</template>

<script>
import PulseLoader from "vue-spinner/src/PulseLoader.vue";

export default {
  components: {
    PulseLoader
  },
  data() {
    return {
      color: "green"
    };
  }
};
</script>

We set the loading prop to indicate that it’s loading.

color sets the color.

It comes with many other styles like grid-loader , clip-loader , and much more.

vue2-dropzone

vue2-dropzone is a dropzone component that we can use to add a file upload input to our Vue app.

To use it, we run:

npm i vue2-dropzone

Then we can use it by writing:

<template>
  <div id="app">
    <vue-dropzone ref="dropzone" id="dropzone" :options="dropzoneOptions"></vue-dropzone>
  </div>
</template>

<script>
import vue2Dropzone from "vue2-dropzone";
import "vue2-dropzone/dist/vue2Dropzone.min.css";
export default {
  name: "app",
  components: {
    vueDropzone: vue2Dropzone
  },
  data() {
    return {
      dropzoneOptions: {
        url: "https://example.com",
        thumbnailWidth: 150,
        maxFilesize: 0.5,
        headers: { "Header": "header value" }
      }
    };
  }
};
</script>

We use the vue-dropzone component with some options.

url is the URL to upload to.

thumbnailwidth is the width of the thumbnail.

maxFilesize is the maximum file size of the file selected,.

headers is the headers we send with the request.

vue-count-to

vue-count-to is a component that lets us add animation to count up or down to a specific number.

To install it, we run:

npm i vue-count-to

Then we can use it by writing:

<template>
  <countTo :startVal="startVal" :endVal="endVal" :duration="3000"></countTo>
</template>

<script>
import countTo from "vue-count-to";
export default {
  components: { countTo },
  data() {
    return {
      startVal: 0,
      endVal: 2020
    };
  }
};
</script>

We just set the startVal prop to set the starting value of the animation.

endVal sets the end value of the animation.

duration is the animation duration.

vue-progressbar

vue-progressbar is a progress bar component.

To use it, first we install it by running:

npm i vue-progressbar

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueProgressBar from "vue-progressbar";

const options = {
  color: "green",
  failedColor: "red",
  thickness: "5px",
  transition: {
    speed: "1.2s",
    opacity: "1.6s",
    termination: 300
  },
  autoRevert: true,
  location: "top",
  inverse: false
};

Vue.use(VueProgressBar, options);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div id="app">
    <vue-progress-bar></vue-progress-bar>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$Progress.finish();
  },
  created() {
    this.$Progress.start();
  }
};
</script>

We have the options object with the options that we set for the progress bar.

color is the bar color.

failedColor is the color when loading fails.

thickness is the thickness of the bar.

transition is the speed of the animation.

opacity is the opacity of the bar.

termination is when it terminates.

autoRevert means that it reverses automatically when loading fails.

location is the location of the bar.

inverse is inverting the direction.

Conclusion

Vue2Editor is the rich text editor.

vue2-dropzone is a file upload widget.

vue-count-to provides us with a way to animate number displays.

vue-progressbar lets us display a progress bar.

vue-spinner is a spinner we can add.

Categories
Top Vue Packages

Top Vue Packages for Adding Croppers, Calendars, and Lodash

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at how the best packages to add a cropper, calendar, full-year date picker, and Lodash.

vue-cropperjs

We can use the vue-cropperjs package to add an image cropper to our Vue app.

To use it, first we install it by running:

npm i vue-cropperjs

Then we can use it by writing:

<template>
  <div>
    <vue-cropper ref="cropper" src="https://placekitten.com/200/200" alt="Source Image"></vue-cropper>
  </div>
</template>

<script>
import VueCropper from "vue-cropperjs";
import "cropperjs/dist/cropper.css";

export default {
  components: { VueCropper }
};
</script>

We just have to import and register the VueCropper component.

Then we set the image with the src prop.

It emits the ready , cropstart , cropmove , cropend , crop , and zoom events.

So we can do anything we want.

Also, we can use it programmatically by calling methods from the ref.

For instance, we can write:

this.$refs.cropper.zoom(1.5);

to zoom in.

vue-lodash

vue-lodash is a wrapper for Lodash that we can use in our Vue apps.

To install it, we run:

npm i vue-lodash lodash

Lodash is a required dependency.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueLodash from "vue-lodash";
import lodash from "lodash";

Vue.use(VueLodash, { name: "custom", lodash });
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

We registered the VueLodash plugin. The name is the property name that we can invoke Lodash with.

lodash is the library itself.

Then in our component, we can write:

<template>
  <div></div>
</template>

<script>
export default {
  mounted() {
    console.log(this.lodash.random(20));
    console.log(this._.random(20));
    console.log(this.custom.random(20));
  }
};
</script>

We can invoke Lodash with the lodash , _ , or custom property as we defined in the name property of the object we passed into Vue.use .

vue-material-year-calendar

vue-material-year-calendar is a useful package for letting us add a full year calendar.

It displays all months on the screen instead of one like most date pickers.

To install it, we run:

npm i vue-material-year-calendar

Then we can use it by writing:

<template>
  <YearCalendar
    v-model="year"
    :activeDates.sync="activeDates"
    [@toggleDate](http://twitter.com/toggleDate "Twitter profile for @toggleDate")="toggleDate"
    prefixClass="prefix"
    :activeClass="activeClass"
  ></YearCalendar>
</template>

<script>
import YearCalendar from "vue-material-year-calendar";

export default {
  components: { YearCalendar },
  data() {
    return {
      year: 2020,
      activeDates: [
        { date: "2020-02-13" },
        { date: "2020-02-14", className: "red" },
        { date: "2020-02-15", className: "blue" },
        { date: "2020-02-16" }
      ],
      activeClass: "active"
    };
  },
  methods: {
    toggleDate(dateInfo) {
      console.log(dateInfo);
    }
  }
};
</script>

<style>
.red {
  color: red;
}

.blue {
  color: blue;
}

.active {
  background: yellow;
}
</style>

We use the YearCalendar component.

The toggleDate event is set to the toggleDate method to log the date.

prefixClass lets us add a prefix to the wrapper class.

activeDates has sets the days to be highlighted. We make the highlight with our own class.

v-model binds to year to set the initial year.

vue-full-calendar

vue-full-calendar is a calendar widget that we can add to a Vue app.

To install it, we run:

npm i vue-full-calendar moment jquery

Moment and jQuery are a required dependencies

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import FullCalendar from "vue-full-calendar";
import "fullcalendar/dist/fullcalendar.css";

Vue.use(FullCalendar);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

We register the plugin and import the CSS.

App.vue

<template>
  <full-calendar :events="events"></full-calendar>
</template>

<script>
import { FullCalendar } from "vue-full-calendar";
export default {
  components: {
    FullCalendar
  },
  data() {
    return {
      events: [
        {
          title: "eat",
          start: "2020-01-01"
        },
        {
          title: "drink",
          start: "2020-01-05",
          end: "2020-01-07"
        },
        {
          title: "sleep",
          start: "2020-01-09T12:30:00",
          allDay: false
        }
      ]
    };
  }
};
</script>

We use the full-calendar component.

We pass in an array of events with the title, start, and end dates in each entry.

Also, we can set the allDay property to add a full-day event.

Conclusion

vue-cropperjs lets us add an image cropped to our Vue app.

The vue-full-calendar package is a calendar widget we can use to display events

The vue-material-year-calendar is a unique date picker in that it displays the whole year.

vue-lodash is a Vue wrapper for Lodash.

Categories
Top Vue Packages

Top Vue Packages for Adding Code Editors, Notifications, and Watch Element Resizing

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at how the best packages for adding code editors, notifications, and watching element resizing.

vue-codemirror

vue-codemirror provides us with a box to display code.

To use it, we install it by running:

npm i vue-codemirror

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueCodemirror from "vue-codemirror";
import "codemirror/lib/codemirror.css";

Vue.use(VueCodemirror);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <codemirror v-model="code" :options="cmOptions"></codemirror>
  </div>
</template>

<script>
import "codemirror/mode/javascript/javascript.js";
import "codemirror/theme/base16-dark.css";

export default {
  data() {
    return {
      code: "const a = 1",
      cmOptions: {
        tabSize: 4,
        mode: "text/javascript",
        theme: "base16-dark",
        lineNumbers: true,
        line: true
      }
    };
  },
  methods: {
    onCmReady(cm) {
      console.log("the editor is readied!", cm);
    },
    onCmFocus(cm) {
      console.log("the editor is focus!", cm);
    },
    onCmCodeChange(newCode) {
      console.log("this is new code", newCode);
      this.code = newCode;
    }
  }
};
</script>

We have the codemirror component.

The code is bound with v-model to code .

We can also add some options like tabSize for size of tabs.

mode for the language we’re displaying.

theme for the display theme.

lineNumber to indicate whether we show line numbers.

It also comes with a merge mode, which lets us compare code side by side.

To use that, we can write:

<template>
  <div>
    <codemirror merge :options="cmOption" @scroll="onCmScroll"></codemirror>
  </div>
</template>

<script>
import "codemirror/addon/merge/merge.js";
import "codemirror/addon/merge/merge.css";
import DiffMatchPatch from "diff-match-patch";
window.diff_match_patch = DiffMatchPatch;
window.DIFF_DELETE = -1;
window.DIFF_INSERT = 1;
window.DIFF_EQUAL = 0;
export default {
  data() {
    return {
      cmOption: {
        value: "<p>james</p>",
        origLeft: null,
        orig: "<p>james smith</p>",
        connect: "align",
        mode: "text/html",
        lineNumbers: true,
        collapseIdentical: false,
        highlightDifferences: true
      }
    };
  },
  methods: {
    onCmScroll() {
      console.log("onCmScroll");
    }
  }
};
</script>

value has the new code.

orig has the original code.

collapseIdentical lets us collapse identical code by default.

highlightDifference lets us highlight any code differences between the original and the current code.

vue-notification

vue-notification is a library that lets us display notifications.

To install it, we run:

npm i vue-notification

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Notifications from "vue-notification";

Vue.use(Notifications);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <notifications group="foo"/>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$notify({
      group: "foo",
      title: "title",
      text: "Hello"
    });
  }
};
</script>

We add the notification component with the group prop.

Then we use the same group value when we call this.$notify to display notifications.

title is the title and text is the content.

We can style it with the generated classes.

We can also create custom notification by populating the slots that it comes with:

<template>
  <div>
    <notifications group="foo" position="top left">
      <template slot="body" slot-scope="props">
        <div>
          <a class="title">{{props.item.title}}</a>
          <a class="close" @click="props.close">close</a>
          <div v-html="props.item.text"></div>
        </div>
      </template>
    </notifications>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$notify({
      group: "foo",
      title: "title",
      text: "Hello"
    });
  }
};
</script>

We populated the body slot with our own content.

It comes with a props.close to close the notification.

The width and velocity can be changed.

vue-resize

vue-resize lets us watch for elements being resized.

To install it, we run:

npm i vue-resize

Then we can use it by using:

main.js

import Vue from "vue";
import App from "./App.vue";
import { ResizeObserver } from "vue-resize";

Vue.component("resize-observer", ResizeObserver);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <resize-observer @notify="handleResize"/>
  </div>
</template>

<script>
export default {
  methods: {
    handleResize({ width, height }) {
      console.log(width, height);
    }
  }
};
</script>

 <style scoped>
div {
  position: relative;
  width: 100vw;
}
</style>

We listen to elements being resized with the resize-observer component.

Conclusion

vue-codemirror lets us add a code editor that supports diffing.

vue-notification lets us add notifications of any variety.

vue-resize lets us watch for elements being resized.

Categories
Top Vue Packages

Top Vue Packages for Infinite Scrolling, Displaying Toasts, and Add a Flexbox Grid

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at how the best packages for adding infinite scrolling, displaying toasts, and adding a flexbox grid.

vue-infinite-loading

We can add infinite scrolling to our app with the vue-infinite-loading package.

To add it, we run the following to install the package:

npm i vue-infinite-loading

Then we can use it by writing:

<template>
  <div>
    <div v-for="n in num" :key="n">{{n}}</div>
    <infinite-loading @infinite="infiniteHandler"></infinite-loading>
  </div>
</template>

<script>
import InfiniteLoading from "vue-infinite-loading";

export default {
  components: {
    InfiniteLoading
  },
  data() {
    return { num: 50 };
  },
  methods: {
    infiniteHandler($state) {
      this.num += 50;
      $state.loaded();
    }
  }
};
</script>

We add register and use the infinite-loading component to load more data.

It emits the infinite event which we listen to with the infiniteHandler .

It has a $state parameter, which we call loaded to indicate that we loaded what we want to display as we scroll.

We just loop through some numbers from 0 to num , which is updated by the infiniteHandler method.

If we don’t want to load more items, we can call $state.complete .

So we can write:

<template>
  <div>
    <div v-for="n in num" :key="n">{{n}}</div>
    <infinite-loading @infinite="infiniteHandler"></infinite-loading>
  </div>
</template>

<script>
import InfiniteLoading from "vue-infinite-loading";

export default {
  components: {
    InfiniteLoading
  },
  data() {
    return { num: 50 };
  },
  methods: {
    infiniteHandler($state) {
      if (this.num === 200) {
        $state.complete();
        return;
      }
      this.num += 50;
      $state.loaded();
    }
  }
};
</script>

Now we stop updating when this.num is 200.

This means there’s no more infinite scrolling with this.num is 200.

vue-grd

If we’re having trouble with flexbox, we can use vue-grd to make flexible work with our Vue app.

To install it, we run:

npm i vue-grd

Then we can write:

<template>
  <div>
    <vue-grid align="stretch" justify="start">
      <vue-cell width="fill">fill</vue-cell>
      <vue-cell width="5of12">5of12</vue-cell>
      <vue-cell width="3of12">3of12</vue-cell>
    </vue-grid>
  </div>
</template>

<script>
import { VueGrid, VueCell } from "vue-grd";

export default {
  components: {
    VueGrid,
    VueCell
  }
};
</script>

to create a flexbox container with vue-grid .

Then we have vue-cell to add the contents into the flexbox container.

The container has 12 columns, so we can change the width with strings like 5of12 or 3of12 to fill 5 of the 12 columns and 3 respectively.

fill fills the remaining space with the content in the vue-cell .

justify works the same way as the justify in CSS.

We can layout our time at the ends, with space in between, etc.

vue-material-checkbox

vue-material-checkbox lets us add a Material design style checkbox easily.

To install it, we write:

npm i vue-material-checkbox

Then we can use it by writing:

<template>
  <div>
    <Checkbox v-model="val" :value="42">My Checkbox</Checkbox>
    <p>{{val}}</p>
  </div>
</template>

<script>
import Checkbox from "vue-material-checkbox";

export default {
  components: { Checkbox },
  data() {
    return { val: undefined };
  }
};
</script>

The Checkbox component binds to the val state.

It’s set to true if it’s checked and false otherwise.

We can set the color, disabled, required attribute, size, font size, and more options.

vue-toasted

We can display toasts with the vue-toasted plugin.

To install it, we run:

npm i vue-toasted

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Toasted from "vue-toasted";

Vue.use(Toasted);

Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div></div>
</template>

<script>
export default {
  mounted() {
    this.$toasted.show("hello");
  }
};
</script>

We register the plugin and then display a toast.

We can add actions to toasts.

For instance, we can write:

<template>
  <div></div>
</template>

<script>
export default {
  mounted() {
    this.$toasted.show("hello", {
      action: [
        {
          text: "Cancel",
          onClick: (e, toastObject) => {
            toastObject.goAway(0);
          }
        },
        {
          text: "Undo",
          push: {
            name: "/",
            dontClose: true
          }
        }
      ]
    });
  }
};
</script>

We pass in an object that lets us add some links to the toast.

The first is a cancel button.

We call goAway to make it go away. The argument is the delay in milliseconds.

The 2nd one is one that lets us navigate to a route.

name has the route path from Vue Router.

Conclusion

vue-infinite-loading is an easy to use package to let us add infinite scrolling to our app.

vue-toasted lets us display toasts in our app.

vue-material-checkbox lets us display a checkbox.

vue-grd lets us create a flexbox grid without our own CSS.