Git Product home page Git Product logo

react-selection's Introduction

version Build Status Coverage

React Selection

Like the normal OS selection, it builds in algorithm for detect two rectangles are overlap, so the performance is pretty fast.

Live Demo

https://rwu823.github.io/react-selection/demo

Usage

<link href="/dist/react-selection.css" rel="stylesheet" />
import Selection from 'react-selection'

afterSelect = (selectedTargets)=>{
  const hasSelected = selectedTargets.length
}

render() {  
  <Selection target=".target" afterSelect={this.afterSelect}>
    <ul>
      <li><span className="target">React</span>
        <ul>
          <li><span className="target">redux</span></li>
          <li><span className="target">react-redux</span></li>
          <li><span className="target">react-router</span></li>
          <li><span className="target">redux-thunk</span></li>
          <li><span className="target">redux-logger</span></li>
          <li><span className="target">redux-saga</span></li>
        </ul>
      </li>
    </ul>
  </Selection>
}

API

Props

static propTypes = {
  target: PropTypes.string.isRequired,
  selectedClass: PropTypes.string,
  afterSelect: PropTypes.func,
  isLimit: PropTypes.bool,
}

static defaultProps = {
  target: '.react-selection-target',
  selectedClass: 'react-selection-selected',
  isLimit: false,
  afterSelect() {

  }
}
name description
target [String] required, it should be a css select
selectedClass [String] add selected class
isLimit [Boolean] limit select range inside box
afterSelect Function([selectedTargets]) be triggered after select, the select targets are native DOMList

Customization

If you want to custom your rectangle selection, it just overwrites .react-selection-rectangle class

.react-selection-rectangle {
  pointer-events: none;
  transition: opacity .4s;
  position: absolute;
  background-color: rgba(204,204,204 .2);
  border: 1px solid #ccc;
}

react-selection's People

Contributors

rwu823 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  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

react-selection's Issues

Cannot resolve module 'react-selection'

Hi there,

I've been looking for exactly the lib you built, however somehow when I install it via NPM:

npm install -S react-selection

The installation works and the lib is added to my app's package.json but when I try to use it inside a file:

import Selection from "react-selection";

It isn't recognized:

Module not found: Error: Cannot resolve module 'react-selection'

My IDE (Webstorm) also says the module isn't installed... However the directory & files are available in node_modules. This has never happened to me before, any idea what the issue could be ?

Simple click doesn't select

A simple click, should probably toggle an item, or with ctrl toggle, and without select a single item... think similar to html <select> element here.

Just a bit of advice, as the dragging to select didn't make as much sense to me at first.

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.