Code Monkey home page Code Monkey logo

vue-muuri's Introduction

vue-muuri

npm vue2

A vue plugin using Muuri's responsive, sortable, filterable and draggable grid layouts.

Vue-muuri was created to provide an alternative option for creating a responsive dashboard in Vue. It is essentially a vue wrapper for Muuri. Using Vue's modular component system, vue-muuri allows us to drop in any number of tile components to quickly create our dashboard.

Installation

npm install --save vue-muuri

Bundler (Webpack)

import Vue from 'vue'
import VueMuuri from 'vue-muuri'
// You need a specific loader for CSS files like https://github.com/webpack/css-loader
import 'vue-muuri/dist/vue-muuri.css'

Vue.use(VueMuuri)

How to Use

Vue-muuri consists of a base muuri-grid component that implements the Muuri plugin. Using this component, we will be able to insert any number of item components through its slot.

Example:

    <muuri-grid id="example-grid">
      <!-- slot content -->
    </muuri-grid>

Out-of-the-box, vue-muuri comes with a few item components to get you started.

    import { ItemLink, ItemSm, ItemMd, ItemLg } from 'vue-muuri'
    <muuri-grid id="example-grid">
      <item-link id="link" text="Example Link" route="/"></item-link>
      
      <item-sm id="item-sm">
        <p>Small item.</p>
      </item-sm>
      
      <item-md id="item-md">
        <p>Medium item.</p>
      </item-md>
      
      <item-lg id="item-lg">
        <p>Large item.</p>
      </item-lg>
    </muuri-grid>

Events

Vue-muuri also allows you to listen to events on the grid object created by Muuri. Please refer to the docs for a complete list of events.

Example:

    <muuri-grid id="example-grid" @layoutEnd="updateOrder">
      <item-sm :id="'item-sm-' + index" v-for="num, index in [1,2,3,4]">
        <p>Item {{ num }}</p>
      </item-sm>
    </muuri-grid>
    // ...
    methods: {
        updateOrder (items) {
            console.log(items)
        }
    }

License

MIT

vue-muuri's People

Contributors

jocodev1 avatar rbrnx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-muuri's Issues

Incorrect self reference in recursive grid

Issue: When create recursive grid (grid inside another grid), the global variable self is override by the last grid created, and all event emits are messed up due to the incorrect reference.

Is there any particular reason you assigned this to self, instead of using arrow function in all events? Assuming you were trying to avoid this from Vue to be confused by this in the functions.

I was able to resolve this issue by removing the self assignment and use arrow functions as below.
this.grid.on('synchronize', ()=> { this.$emit('synchronize') });

How to remove elements?

Can you give an example where I can utilize the remove event to remove elements from the list and the DOM?

Add `ItemFluid` component

Usually grid item's width and height depends on content width and height. Therefore it would be great to have a fluid item

<template>
  <div :id="id" class="item">
    <div class="item-content item-fluid">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'item-fluid',
    props: {
      id: {
        type: [Number, String],
        default: 'item-sm'
      },
      onClick: {
        type: Function,
        default (id) {
          return null
        }
      }
    }
  }
</script>

<style scoped></style>

To make it work we should set default .item to have fluid width and height:

.item {
  ...
  width: auto;
  max-width: 100%;
  height: auto;
  ...
}

Oversized bundle

The JS files in the /dist folder appear to include muuri itself as well as all other dependencies, creating a huge javascript file of ~800KB. You could add another option for people that only includes your vue components, and allows muuri and other dependencies to be installed via npm.

Muuri is not defined

main.js
import VueMuuri from 'vue-muuri'
import 'vue-muuri/dist/vue-muuri.css'
Vue.use(VueMuuri)
but still Muuri is not defined

Many errors when running lint:staged

Like these:

dist/vue-muuri.css
   8:1  ×  Expected no more than 1 empty line   max-empty-lines
  11:1  ×  Expected empty line before rule      rule-empty-line-before
  21:1  ×  Expected empty line before rule      rule-empty-line-before
  24:1  ×  Expected empty line before rule      rule-empty-line-before
  27:1  ×  Expected empty line before rule      rule-empty-line-before
  30:1  ×  Expected empty line before rule      rule-empty-line-before
  39:1  ×  Expected empty line before rule      rule-empty-line-before

Resize item and add new item

Hi sorry if this question sounds too stupid .
Im a beginner i just need to know how to create function to resize the item and add new item

image

image

Working example

Is this library stil up to date, anyone have a working example ?

Thanks

Use this.$el to initialize grid

Currently Muurri initializes like this:

createGrid () {
  this.grid = new Muuri('#' + this.id, this.options)
  ...
}

It forces user to set id for each component (in case if there are many instances).

Instead we can refer to root element using this.$el (https://vuejs.org/v2/api/?#mounted):

createGrid () {
  this.grid = new Muuri(this.$el, this.options)
  ...
}

Do not set id by default

In Vue environment it's rarely necessary to assign id attribute to an element. Now user have to set an unique id otherwise there will be elements with the same id (e.g. grid).
To make id optional:

id: {
        type: String,
        default: null
      },

Unable to run tests

After calling npm run dev I got:

ERROR in ./test/visual.js
Module not found: Error: Can't resolve './specs' in 'E:\experiments\vue-muuri\test'
 @ ./test/visual.js 71:19-51
 @ multi (webpack)-dev-server/client?http://localhost:8081 ./test/visual.js

OS: Windows 8.1
node: 8.7.0
npm: 5.5.1

v-for

How would 'v-for' be used with this to display items within the grid dynamically from a database? I'm having trouble getting this to work. Any advice?

Override styles

Is it really necessary to add default visual styles like this?

  .item {
    // display: block;
    // position: absolute;
    margin: 5px;
    // z-index: 1;
    background: #333;
    border: 2px solid black;
    border-radius: 5px;
    padding: 15px;
    color: #fff;
    opacity: 0.9;
  }

The only way to override .item padding is

.item[data-v-6ac0860c] {
  padding: 0;
}

I think we only need styles that are required for muuri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.