Giter Club home page Giter Club logo

vue-drag-select's Introduction

Screenshot

Vue Drag to Select Component

A Vue component for drag selecting elements. Inspired by react-drag-select.

Demo

  • Visit the demo here.

Usage

  • Add vue-drag-select to your project:
$ yarn add vue-drag-select # or npm i --save vue-drag-select
  • Import the component and add it to your template:
import DragSelect from 'vue-drag-select/src/DragSelect.vue'

export default {
  components: {
    'drag-select-container': DragSelect
  }
}
  • Wrap the items that you want to be selectable in the drag-select-container with a selectorClass property and a scoped slot:
<template>
  <drag-select-container selectorClass="itemToBeSelected">
    <template slot-scope="{ selectedItems }">
      <!-- Your items here -->
    </template>
  </drag-select-container>
</template>
  • Then write your own logic to make items look selected. For instance by applying a class.

License

MIT

vue-drag-select's People

Contributors

franciskong avatar irongollem avatar stephan281094 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  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

vue-drag-select's Issues

support click and multi selection

hi, i viewed your library and learned a lot. Would you plan to add click item to select and multi select when use enter ctrl or command ? i overwrite your code and do that on my way. the demo is here: demo
If you are interested in this, i hope i can pull request to your code.
best wishes.

'selectionEnd' event

I would appreciate something like 'selectionEnd' event to handle change after the user completed his selection, instead of during the selection. I believe this should behave like onMouseUp but fire only when the underlying selection was changed.

My use case is: I need to start resource-intensive computations after the selection is made. It does not make sense to start it after every change.

expand / reduce selction with strg - click

hi there, this is a very useful component,
is it possible to integrate a select/deselect function, so you can expand/reduce the selection with strg - mouseclick on items
if not planned can you give me a hint, how to start to implement it
thank you very much
marc

Make `selectorClass` accept function

If selectorClass accepts function as value, it could be used for more expressive checks, e.g.

<drag-select-container :selectorClass="vm => vm.$el.hasClass('item')">
	<template scope="{ selectedItems }">
		<!-- ... -->
	</template>
</drag-select-container>

But with this name selectorClass is not descriptive enough. Maybe rename it to something like selectableItem?

Not work properly with 'simplebar'

Not work properly with 'simplebar'

the drag area is not holded when scroll.
drag area work like 'fixed'. so it select new item without old item.

simplebar : https://github.com/Grsmto/simplebar

for test you should install simplebar

npm install --save simplebar-vue

and this is the code for testing

<template>
  <div class="app">
    <h1>Vue Drag Select Example</h1>
    <simple-bar>
        <drag-select-container selectorClass="item">
          <template slot-scope="{ selectedItems }">
            <div
              v-for="item in 50"
              :key="item"
              :class="getClasses(item, selectedItems)"
              :data-item="item"
            >
              Item {{ item }}
            </div>
          </template>
        </drag-select-container>
    </simple-bar>
  </div>
</template>

<script>
import DragSelect from "vue-drag-select";

import SimpleBar from 'simplebar-vue';
import 'simplebar/dist/simplebar.css';

export default {
  name: "home",

  components: {
    SimpleBar,
    "drag-select-container": DragSelect
  },

  methods: {
    getClasses(item, selectedItems) {
      const isActive = !!selectedItems.find(selectedItem => {
        return parseInt(selectedItem.dataset.item, 10) === item;
      });

      return {
        item: true,
        active: isActive
      };
    }
  }
};
</script>

<style>
/* skiped other css in example */
.simplebar-wrapper {
    max-height: 500px;
}
</style>

thanks...

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.