New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

selection-area

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selection-area

Simple JavaScript mouse & touch seletion area to any DOM container element.

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by58.33%
Maintainers
1
Weekly downloads
 
Created
Source

Selection Area

npm version documentation


Simple JavaScript mouse & touch seletion area to any DOM container element.


How to use | API Reference | Demo


How to use

Download

Install with npm
npm install selection-area
Install with yarn
yarn add selection-area
From Source Code

Clone or download zipped source code into node_modules project folder.

git clone https://github.com/lucasmenendez/selection-area.git <project>/node_modules/selection-area

Import

Local dist version

Import using script html tags with vendor path:

<script src="/node_modules/selection-area/dist/selection-area.js"></script>

Or import using ES6 import:

import { SelectionArea } from 'selection-area';
CDN version

Importing with unpkg.com:

<script src="https://unpkg.com/selection-area"></script>

Example

Define container for selection area and selectable childs.

<div class="parent">
    <div class="child">0</div>
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
    <div class="child">4</div>
    <div class="child">5</div>
    <div class="child">6</div>
    <div class="child">7</div>
    <div class="child">8</div>
    <div class="child">9</div>
</div>

Define SelectionArea behaviour with configuration object, check available parameters here.

let config = {
    container: document.querySelector('.parent'),
    area: {
        class: 'custom-area'
    },
    targets: '.child',
    touchable: true,
    autostart: true,
    callback: selection => {
        if (selection.length == 0) alert("empty selection");
        else alert(`${ selection.length } items selected`);
    }
}

let selectable = new SelectionArea(config);

Also you can stylize the selection area element adding style yo defined class.

.custom-area {
    background: rgba(52, 152, 219, 0.2);
    border: 2px dotted #2980b9;
}

Keywords

FAQs

Package last updated on 04 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc