Skip to content

Multiple Build Types (commonjs, es, and UMD) and other build setup updates #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"presets": ["react", "es2015", "stage-2"]
}
"presets": ["react", "es2015", "stage-2"],
"env": {
"es": {
"comments": false
},
"commonjs": {
"comments": false
}
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
node_modules
example/bundle.js
dist
lib
es
*.log
.DS_Store
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Selectable items for React
[![NPM version][npm-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]

Allows individual or group selection of items using the mouse.

Expand All @@ -7,33 +9,38 @@ Allows individual or group selection of items using the mouse.

## Upgrading from 0.1 to 0.2
There have been significant changes in the 0.2 release. Please [read about them here](UPGRADING.md).

## Getting started

```
npm install react-selectable
npm install --save react-selectable
```
This assumes you are using [npm](https://www.npmjs.com/) as your package manager.

If you are not, you can access these files [through unpkg](https://unpkg.com/react-selectable), download them, or point your package manager to them. For more info on this in, visit [the builds section](#builds)

```js
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: []
};
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;
const selected = this.state.selectedKeys.indexOf(item.id) > -1;
return (
<SelectableComponent key={i} selected={selected} selectableKey={item.id}>
{item.title}
Expand All @@ -42,14 +49,10 @@ class App extends React.Component {
})}
</SelectableGroup>
);
},

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

}
```

## Configuration

The `<SelectableGroup />` component accepts a few optional props:
Expand All @@ -61,3 +64,15 @@ The `<SelectableGroup />` component accepts a few optional props:
* `selectOnMouseMove` (Boolean) Enable to fire the `onSelection` callback while the mouse is moving. Throttled to 50ms for performance in IE/Edge
* `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.

## Builds

Most commonly people consume `react-selectable` as a collection of [CommonJS](http://webpack.github.io/docs/commonjs.html) modules. These modules are what you get when you import `react-selectable` in a [Webpack](https://webpack.js.org/), [Browserify](http://browserify.org/), or a Node environment.

The `redux-selectable` source code is written in ES2015 but we precompile both CommonJS and UMD builds to ES5 so they work in [any modern browser](http://caniuse.com/#feat=es5).

If you don't use a module bundler, it's also fine. The `redux-selectable` npm package includes precompiled production and development [UMD](https://github.com/umdjs/umd) builds in the [`dist` folder](https://unpkg.com/react-selectable/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a [`<script>` tag](https://unpkg.com/redux/dist/redux.js) on the page, or [tell Bower to install it](https://github.com/reactjs/redux/pull/1181#issuecomment-167361975). The UMD builds make Redux available as a `window.ReactSelectable` global variable.

[npm-image]: https://img.shields.io/npm/v/react-selectable.svg?style=flat-square
[npm-downloads-image]: https://img.shields.io/npm/dm/react-selectable.svg?style=flat-square
[npm-url]: https://npmjs.org/package/react-selectable
Loading