• Stars
    star
    142
  • Rank 250,268 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A component for react that allows mouse selection of child items

Selectable items for React

Allows individual or group selection of items using the mouse.

Demo

Try it out

Upgrading from 0.1 to 0.2

There have been significant changes in the 0.2 release. Please read about them here.

Getting started

npm install react-selectable
import React from 'react';
import { render } from 'react-dom';
import { SelectableGroup, createSelectable } from 'react-selectable';
import SomeComponent from './some-component';

const SelectableComponent = createSelectable(SomeComponent);

class App extends React.Component {

  constructor (props) {
  	super(props);
  	this.state = {
  		selectedKeys: []
  	};
  }

  handleSelection (selectedKeys) {
  	this.setState({ selectedKeys });
  }

  render () {
    return (
      <SelectableGroup onSelection={this.handleSelection}>
        {this.props.items.map((item, i) => {
          	let selected = this.state.selectedKeys.indexOf(item.id) > -1;
          	return (
          		<SelectableComponent key={i} selected={selected} selectableKey={item.id}>
          			{item.title}
          		</SelectableComponent>
          	);
        })}
      </SelectableGroup>
    );
  }

}

Configuration

The <SelectableGroup /> component accepts a few optional props:

  • onBeginSelection(event) (Function) Callback fired when the selection was started.
  • onSelection(items, event) (Function) Callback fired while the mouse is moving. Throttled to 50ms for performance in IE/Edge.
  • onEndSelection(items, event) (Function) Callback fired after user completes selection.
  • onNonItemClick(event) (Function) Callback fired when a click happens within the selectable group component, but not in a selectable item. Useful for clearing selection.
  • tolerance (Number) The amount of buffer to add around your <SelectableGroup /> container, in pixels.
  • component (String) The component to render. Defaults to div.
  • fixedPosition (Boolean) Whether the <SelectableGroup /> container is a fixed/absolute position element or the grandchild of one. Note: if you get an error that Value must be omitted for boolean attributes when you try <SelectableGroup fixedPosition={true} />, simply use Javascript's boolean object function: <SelectableGroup fixedPosition={Boolean(true)} />.
  • preventDefault (Boolean) Allows to enable/disable preventing the default action of the onmousedown event (with e.preventDefault). True by default. Disable if your app needs to capture this event for other functionalities.
  • enabled (Boolean) If false, all of the selectable features are disabled, and event handlers removed.
  • className (String) A CSS class to add to the containing element.
  • selectingClassName (String) A CSS class to add to the containing element when we select.

Decorators

Though they are optional, you can use decorators with this react-selectable.

A side by side comparison is the best way to illustrate the difference:

Without Decorators

class SomeComponent extends Component {

}
export default createSelectable(SomeComponent)

vs.

With Decorators

@createSelectable
export default class SomeComponent extends Component {

}

In order to enable this functionality, you will most likely need to install a plugin (depending on your build setup). For Babel, you will need to make sure you have installed and enabled babel-plugin-transform-decorators-legacy by doing the following:

  1. run npm i --save-dev babel-plugin-transform-decorators-legacy
  2. Add the following line to your .babelrc:
{
  "plugins": ["transform-decorators-legacy"]
}

More Repositories

1

silverstripe-gridfield-betterbuttons

Adds new form actions and buttons to the GridField detail form
PHP
80
star
2

DataObjectManager

DataObjectManager module for Silverstripe CMS
PHP
74
star
3

silverstripe-display-logic

The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior.
PHP
73
star
4

Uploadify

Uploadify module for SilverStripe CMS
PHP
62
star
5

silverstripe-bootstrap-forms

Allows the creation of forms compatible with the Twitter Bootstrap CSS framework in SilverStripe
JavaScript
56
star
6

silverstripe-kickassets

KickAssets module for asset management in SilverStripe 3
JavaScript
47
star
7

silverstripe-dropzone

JavaScript
46
star
8

silverstripe-dashboard

Dashboard module for SilverStripe 3
PHP
46
star
9

KickAssets

The KickAssets module for SilverStripe is an alternative to AssetAdmin
JavaScript
40
star
10

SilverSmith

The SilverSmith toolset for SilverStripe framework 3.0
PHP
34
star
11

silverstripe-event-calendar

The Event Calendar module for SilverStripe
PHP
31
star
12

silverstripe-zen-fields

Adds syntactic sugar to SilverStripe FieldLists
PHP
29
star
13

ImageGallery

Image Gallery module for SilverStripe CMS
JavaScript
29
star
14

silverstripe-page-gallery

Enhances the user experience of creating pages in the CMS by providing screenshots of templates
PHP
21
star
15

LangEditor

Lang Editor module for SilverStripe CMS
PHP
20
star
16

silverstripe-permamail

Adds several features to transactional emails including persisting sent emails, resending emails, and user-defined templates
PHP
20
star
17

silverstripe-mock-dataobjects

Allows DataObjects to self-populate intelligently with fake data
PHP
18
star
18

silverstripe-meta-languages

Allows the direct inclusion of meta languages such as SASS and CoffeeScript into a project with automatic runtime compiling
PHP
18
star
19

silverstripe-image-optionset

Allows use of images as selectable items in an OptionsetField
PHP
13
star
20

silverstripe-green

A micro-framework for SilverStripe that offers a design-driven approach to creating unique templates
PHP
11
star
21

TranslatableDataObject

Insanely simple translation for SilverStripe
PHP
11
star
22

Mappable

Mappable module for SilverStripe CMS
PHP
10
star
23

silverstripe-serialised-dbfields

Provides consumable serialised data in text fields for SilverStripe
PHP
10
star
24

Postale

Postale module for SilverStripe CMS
JavaScript
10
star
25

ContactForm

Contact form Module for SilverStripe
PHP
9
star
26

sublime-robotype

Automatically emulate typing text from your clipboard
Python
9
star
27

silverstripe-webpack-starter

Starter kit for Silverstripe, Bootstrap, and Webpack
CSS
8
star
28

Tabs

A module that allows for an alternative TabSet in SilverStripe.
PHP
6
star
29

silverstripe-bootstrap-tagfield

Allows you to create field that allows multiple selection of records, such as tags, compliant with Bootstrap 3
JavaScript
6
star
30

silverstripe-eager-loader

Eager loading for SilverStripe DataLists
PHP
6
star
31

ss-to-react

Convert .ss template files to React JSX
JavaScript
5
star
32

silverstripe-reflection-templates

Introspects SilverStripe templates, getting metadata about variables and blocks, much like PHP's ReflectionClass
PHP
5
star
33

silverstripe-docstation

Experimental userdocs thing
PHP
5
star
34

silverstripe-nextjs-tutorial-frontend

The frontend for the Silverstripe CMS / NextJS tutorials
TypeScript
5
star
35

silverstripe-intercom-userforms

Adds Intercom integration to userforms
PHP
5
star
36

silverstripe-blubber

Scans your theme CSS for unused selectors
PHP
5
star
37

silverstripe-db-surgeon

PHP
4
star
38

silverstripe-superquery

A tool to run queries in the CMS.
JavaScript
4
star
39

bedrock

Bedrock
PHP
4
star
40

silverstripe-sendgrid-mailer

Send all transactional email through Sendgrid with zero implementation.
PHP
3
star
41

silverstripe-blog-sortable-categories

Makes the categories in silverstripe/blog sortable
PHP
3
star
42

silverstripe-nextjs-tutorial-cms

The CMS instance for the Silverstripe CMS / NextJS tutorials
PHP
3
star
43

silverstripe-gatsby-helpers

A suite of functions to help with various tasks in SilverStripe + Gatsby integrations
TypeScript
3
star
44

experimental-horizontal-hierarchy

An experiment in horizontal hierarchical navigation in the SilverStripe 3
JavaScript
2
star
45

silverstripe-green-addons

An expansion pack for silverstripe-green that provides template parsing and code generation
PHP
2
star
46

dogapp-backend

The backend for the graphql dog app
PHP
2
star
47

dogapp-frontend

The frontend app for the graphql dog app
JavaScript
1
star
48

silverstripe-blog-featured-posts

Adds featured posts to the SilverStripe blog module
PHP
1
star
49

gouda

JavaScript
1
star
50

qwuzz

A Javascript library for generating quizzes from data structures
JavaScript
1
star
51

silverstripe-gatsby-elemental

Tools for building Silverstripe Elemental content blocks in Gatsby
JavaScript
1
star
52

nfl-fourth-down

NFL Fourth Down Simulator
JavaScript
1
star
53

gatsby-frontend-mega

Frontend for SS Gatsby POC with large volumes of content
SCSS
1
star