Sortable Grid Layout Builder With Vue And Sortable.js – Grid Designer

Description:

Grid Designer is a Vue.js component to build a customizable, sortable, draggable grid system using the sortable.js library.

Basic usage:

1. Import the Grid Designer into your Vue project.

import Vue from 'vue';
import VueGridDesigner from '@thefootonline/vue-grid-designer';

2. Register the component.

// global component
Vue.component('vue-grid-designer', VueGridDesigner);

// locally
export default {
  ...
  components: { VueGridDesigner }
  ...
};

3. Add the Grid Designer to the template.

<template>
  <div>
     <vue-grid-designer v-model="grid"></vue-grid-designer>
  </div>
</template>
export default { 
  components: { VueGridDesigner },
  data () {
    return {
      grid: [{
        blocks: [{ 
          span: 1,
          content: '<p>1</p>'
        },{ 
          span: 2,
          content: '<p>2</p>'
        },{ 
          span: 3,
          content: '<p>3</p>'
        }]
      }]
    };
  }   
};

4. Available props.

// The v-model grid data; rows and blocks
value: {
  type   : Array,
  default: () => []
},
// Component mode - edit or view
mode: {
  type     : String,
  default  : 'edit',
  validator: ( prop ) => [ 'edit', 'view' ].includes ( prop )
},
// Logical blocks per row
blocksPerRow: {
  type   : Number,
  default: 4
},
// Maximum number of rows
maxRows: {
  type   : Number,
  default: 0
},
// CSS row class
rowClass: {
  type   : String,
  default: ''
},
// CSS block class
blockClass: {
  type   : String,
  default: ''
},
// Minimum block height - in pixels
minBlockHeight: {
  type   : Number,
  default: 100
},
// Block margin - in pixels
blockMargin: {
  type   : Number,
  default: 6
},
// Allow blocks to be moved between rows
enableMoveBlocksBetweenRows: {
  type   : Boolean,
  default: true
},
// New row callback - allows decoration of the new row object (async)
onNewRow: {
  type   : Function
},
// New block callback - allows decoration of the new block object (async)
onNewBlock: {
  type   : Function
},
/*
SortableJS Props with local defaults and managed locally
*/
// CSS Class for the ghost position indicator element
sortableGhostClass: {
  type   : String,
  default: 'vgd__block--ghost'
},
// CSS Class for the selected element
sortableChosenClass: {
  type   : String,
  default: 'vgd__block--chosen'
},
// CSS Class for the element when dragged
sortableDragClass: {
  type   : String,
  default: 'vgd__block--drag'
},
// Animation speed. 0 for no animation
sortableAnimation: {
  type   : Number,
  default: 50
},
// Pass-thru remaining SortableJS options
sortableOptions: {
  type   : Object,
  default: () => {
  }
}

Preview:

Sortable Grid Layout Builder With Vue And Sortable.js - Grid Designer

Changelog:

v2.24.3 (10/24/2020)

  • Update/Define sortable.js compatible version

Download Details:

Author: TheFoot

Live Demo: https://thefoot.github.io/vue-grid-designer/

Download Link: https://github.com/SortableJS/Sortable/archive/master.zip

Official Website: https://github.com/SortableJS/Sortable

Install & Download:

# NPM
$ npm i @thefootonline/vue-grid-designer --save

You Might Be Interested In:

Add Comment