Simple list picker component made with Vue.js

Here is the following steps to use a simple list picker component made with Vue.js

Simple list picker component made with Vue.js
list picker component

How to install

npm

$ npm install vue-list-picker --save

yarn

$ yarn add vue-list-picker

Quick start

Vue.js

You can import in your main.js file

import Vue from "vue";
import VueListPicker from "vue-list-picker";

Vue.use(VueListPicker);

Or locally in any component

import { VueListPicker } from "vue-list-picker";

export default {
  components: {
    VueListPicker,
  },
};

Nuxt.js

You can import as a Nuxt.js plugin

~/plugins/vue-list-picker.js

import Vue from "vue";
import VueListPicker from "vue-list-picker";

Vue.use(VueListPicker);

and then import it in your nuxt.config.js file

plugins: ["~/plugins/vue-list-picker.js"];

There’s a window mouseup event listener so you should use the <no-ssr> tag

Basic usage

<template>
  <vue-list-picker :left-items="leftItems" :right-items="rightItems" />
</template>

<script>
  export default {
    data() {
      const example1 = {
        key: 1,
        content: "Item 1",
      };
      const example2 = {
        key: 2,
        content: "Item 2",
      };
      const example3 = {
        key: 3,
        content: "Item 3",
      };
      const example4 = {
        key: 4,
        content: "Item 4",
      };

      const leftItems = [example1, example2];
      const rightItems = [example3, example4];

      return { leftItems, rightItems };
    },
  };
</script>

Props

Property nameTypeDefaultDescription
left-itemsArraynullArray of objects to be displayed in the left. Must have at least a key and content property
right-itemsArraynullArray of objects to be displayed in the right. Must have at least a key and content property
moved-item-locationString‘top’After move a item, if this is set to top will move the item to the top, otherwise to the bottom
title-leftString‘Items available’Title name of the left column
title-rightString‘Items selected’Title name of the right column
title-centeredBooleantrueCentralizes the title text
title-classStringIf you want to set a custom class to the columns title, set it here
title-substrString20Number of characters to display inside the columns title. Above this, will set a ‘…’ mask
button-classStringIf you want to set a custom class to all the buttons in between the columns, set it here
content-keyString‘key’Property name inside the objects inside each items array, that will be used to move the object
content-attrString‘content’Property name inside the objects inside each items array, that will set the text content
content-centeredBooleanfalseCentralizes all the text content
content-classStringIf you want to set a custom class to the each content item, set it here
content-substrString23Number of characters to display inside the content item. Above this, will set a ‘…’ mask
min-heightString‘450px’Min-height of each column
heightStringHeight of each column
min-widthString‘220px’Min-width of each column
widthStringWidth of each column
Props

Events (optional usage)

Event nameReturn typeDescription
move-all-rightArrayArray of items moved
move-rightObjectItem object moved
move-leftObjectItem object moved
move-all-leftArrayArray of items moved
unselect-allArrayEmpty array
Events (optional usage)

Slots (optional usage)

Slot nameDescription
moveAllRightUse this to change the icon (chevrons-right) inside the first action button
moveRightUse this to change the icon (chevron-right) inside the second action button
moveLeftUse this to change the icon (chevron-left) inside the third action button
moveAllLeftUse this to change the icon (chevrons-left) inside the fourth action button
unselectAllUse this to change the icon (x) inside the fifth action button
Slots (optional usage)

Instructions

Generics

  1. Right now there’s no draggable depency. But if you click and hold your mouse down and drag it into another itens in the same column, all of them it’ll selected.
  2. The title and content background are both blue (#0052c0), but you can change those using the content-class and title-class props.
  3. By default the height isn’t set, but it has an overflow-y CSS property, so if you use the height prop, you’ll have a vertical scroll inside each panel.
  4. If you pass anything other than top to movedItemLocation, the item after moved will go to the bottom.
  5. The content key should be an unique key inside each array of objects (left-items / right-items).

Actions

From top to bottom:

  1. The first button moves all the left items to the right.
  2. The second button moves all the selected left items to the right.
  3. The third button moves all the right items to the left.
  4. The fourth button moves all the selected right items to the left.
  5. The fifth button unselect all the selected items from all columns (left and right).

Leave a Comment