drag-selectjs
TypeScript icon, indicating that this package has built-in type declarations

0.0.16Β β€’Β PublicΒ β€’Β Published

drag-selectjs ⚑️

Make any element selectable with just a few lines of code πŸ‘Š

  • Lightweight ☁️
  • Easy to use 🌞
  • Compatible with any frontend framework πŸ”₯

CodePen Demo

Installation

CLI

npm i drag-selectjs

or...

yarn add drag-selectjs

CDN

<script src="https://unpkg.com/drag-selectjs"></script>

Usage

First, add the data-dragselect attribute to any element you want to make selectable:

<div data-dragselect>SELECT ME!</div>

Then, add any styling for the drag-box and selected elements:

/* Class-names can be changed with `init('box-class', 'selected-class')` */
.__dragselect--box {
    background-color: rgba(0, 0, 0, 0.5);
}
.__dragselect--selected {
    border: 3px solid #808080;
}

Now, all you need to do is initialise drag-selectjs:

CLI

import { init, onSelected } from 'drag-selectjs'

init('drag-box-class', 'selected-element-class') // Arguments are optional

onSelected(selected => {
    console.log(selected) // [div.selected-element-class, ...]
})

CDN

DragSelect.init()

DragSelect.onSelected(selected => {
    console.log(selected)
})

Contributions welcome!

Package Sidebar

Install

npm i drag-selectjs

Weekly Downloads

30

Version

0.0.16

License

MIT

Unpacked Size

9.78 kB

Total Files

6

Last publish

Collaborators

  • daniel_knights