48 | react-selectable-fast
49 |
50 |
51 |
55 |
56 |
57 | 58 | 59 | 60 | 61 | Install 62 |
63 |npm i -S react-selectable-fast
65 |
67 |
68 |
72 |
73 |
76 | 77 | Demo 78 |
79 |80 | Draw a box with your mouse/touch to select items. Click on + icon of an individual item to 81 | select it. 82 |
83 | 84 | 85 |86 | JavaScript environment requirements 92 |
93 |94 | The React-Selectable-Fast package distributed on NPM use the widely-supported ES5 version of 95 | JavaScript to support as many browser environments as possible. 96 |
97 |
98 | However, this package expects modern JavaScript globals (Map, Set,
99 | Array.from, Array.isArray Object.assign) to be
100 | defined. If you support older browsers and devices which may not yet provide these natively,
101 | consider including a global polyfill in your bundled application, such as
102 | core-js or
103 | babel-polyfill.
104 |
106 | A polyfilled environment for React-Selectable-Fast using 107 | core-js to support older browsers might 108 | look like this: 109 |
110 | 111 |import 'core-js/fn/object/assign'
113 | import 'core-js/fn/array/from'
114 | import 'core-js/fn/array/is-array'
115 | import 'core-js/fn/map'
116 | import 'core-js/fn/set'
117 |
118 | import App from './myApp';
119 | 122 | Usage 124 |
125 |126 | Example 128 |
129 |
130 | Package exports 4 entities
131 | { SelectableGroup, createSelectable, SelectAll, DeselectAll }. To make other
132 | components selectable wrap them using HoC createSelectable, add passed
133 | selectableRef prop to the target node and put a list of seletable items under
134 | SelectableGroup.
135 |
import React, { Component } from 'react'
138 | import { SelectableGroup } from 'react-selectable-fast'
139 |
140 | class App extends Component {
141 | ...
142 |
143 | render() {
144 | return (
145 | <SelectableGroup
146 | className="main"
147 | clickClassName="tick"
148 | enableDeselect
149 | tolerance={this.state.tolerance}
150 | globalMouse={this.state.isGlobal}
151 | allowClickWithoutSelected={false}
152 | duringSelection={this.handleSelecting}
153 | onSelectionClear={this.handleSelectionClear}
154 | onSelectionFinish={this.handleSelectionFinish}
155 | ignoreList={['.not-selectable', '.item:nth-child(10)', '.item:nth-child(27)']}
156 | >
157 | <List items={this.props.items} />
158 | </SelectableGroup>
159 | )
160 | }
161 | }
162 | import React from 'react'
165 | import { createSelectable } from 'react-selectable-fast'
166 |
167 | const SomeComponent = ({ selectableRef, isSelected, isSelecting }) => (
168 | <div ref={selectableRef}>...</div>
169 | )
170 |
171 | export default createSelectable(SomeComponent)
172 | import React, { Component } from 'react'
176 | import { createSelectable, SelectAll, DeselectAll } from 'react-selectable-fast'
177 | import SomeComponent from './SomeComponent'
178 |
179 | const SelectableComponent = createSelectable(SomeComponent)
180 |
181 | class List extends Component {
182 | ...
183 |
184 | render() {
185 | return (
186 | <div>
187 | <SelectAll className="selectable-button">
188 | <button>Select all</button>
189 | </SelectAll>
190 | <DeselectAll className="selectable-button">
191 | <button>Clear selection</button>
192 | </DeselectAll>
193 | {this.props.items.map((item, i) => (
194 | <SelectableComponent
195 | key={i}
196 | player={item.player}
197 | year={item.year}
198 | />
199 | ))}
200 | </div>
201 | )
202 | }
203 | }
204 | 206 | Configuration 208 |
209 |-
210 |
-
211 |
duringSelection(Function) Callback fired rapidly during selection (while the 212 | selector is being dragged). Passes an array containing selectable items currently under 213 | the selector to the callback function. 214 |
215 | onSelectionFinish(Function) Callback.
216 | onSelectionClear(Function) Callback.
217 | enableDeselect(Boolean) Enables deselect with selectbox.
218 | -
219 |
mixedDeselect(Boolean) When enabled items can be selected and deselected 220 | with selectbox at the same time,enableDeselectshould be set to 221 |true. 222 |
223 | -
224 |
scrollContainer(String) Selector of scroll container which will be used to 225 | calculate selectbox position. If not specified SelectableGroup element will be used as 226 | scroll container. 227 |
228 | ignoreList(Array) Array of ignored selectors.
229 | -
230 |
clickableClassName(String) On element with specified selector click item 231 | cotaining this element will be selected. 232 |
233 | -
234 |
tolerance(Number) The amount of buffer to add around your 235 |<SelectableGroup />container, in pixels. 236 |
237 | className(String) Class of selectable group element.
238 | -
239 |
selectionModeClass(String) Class indicating that there are more than 1 240 | selected item. Defaults to 'in-selection-mode'. 241 |
242 | -
243 |
component(String) The component to render. Defaults todiv. 244 |
245 | -
246 |
allowClickWithoutSelected(Boolean) When disabled items can be selected by 247 | click only if there are more than 1 already selected item. 248 |
249 | -
250 |
fixedPosition(Boolean) Whether the 251 |<SelectableGroup />container is a fixed/absolute position element or 252 | the grandchild of one. 253 |
254 | -
255 |
resetOnStart(Boolean) Unselect all items when you start a new drag. Default 256 | value isfalse. 257 |
258 | -
259 |
disabled(Boolean) Enable or disable the selectable draggable, useful if you 260 | want to enable drag of sub-items. Default value isfalse. 261 |
262 | -
263 |
delta(Number) Value of the CSS transform property scaled list, useful if 264 | your list of items in<SelectableGroup />is wrapped by a scale css 265 | transform property. Default value is1. 266 |
267 | -
268 |
selectOnClick(Boolean) Allow selecting by clicking items. Default value is 269 |true270 |
271 | -
272 |
allowAltClick(Boolean) Perform select actions even though the 273 |altkey is down when clicking or dragging. Default value is 274 |false275 |
276 | -
277 |
allowCtrlClick(Boolean) Perform select actions even though the 278 |ctrlkey is down when clicking or dragging. Default value is 279 |false280 |
281 | -
282 |
allowMetaClick(Boolean) Perform select actions even though the 283 |metakey is down when clicking or dragging. Default value is 284 |false285 |
286 | -
287 |
allowShiftClick(Boolean) Perform select actions even though the 288 |shiftkey is down when clicking or dragging. Default value is 289 |false290 |
291 |
293 | Development 296 |
297 |
298 | Clean lib and dist folders
301 |
302 | npm run clean
304 |
306 | Watch src folder
309 |
310 | npm run watch
312 |
314 | Start example dev-server
317 |
318 | npm run watch:example
320 |
322 | Lint src folder
325 |
326 | npm run lint
328 | 330 | License 332 |
333 |See MIT
334 | 341 | 342 |