1.0.11 • Published 5 years ago

react-box-selection v1.0.11

Weekly downloads
43
License
MIT
Repository
github
Last release
5 years ago

React Box Selection

npm.io npm.io

React component for making box selections on elements.

Gif

npm.io

npm.io

npm.io

Installation

npm install || yarn 

Usage

import Selection from 'react-box-selection'

const content = [...Array(7)].map((item, row) => {
  return [...Array(14)].map((item, col) => {
    const data = Math.floor(Math.random() * 100 + 1)
    const tmp = <h3 key={`${row}-${col}`}>{data}</h3>
    return tmp
  })
})

class App extends React.Component {
  state = {}

  componentWillUnmount () {
    this.setState = () => { }
  }

  mounted = all => { //all items(dom)
    console.log(all)
  }
  selected = (positions, items, all) => { //data-position(array of string),selected items(array of dom)
    console.log(positions)
  }
  singleSelected = (position, item, all) => { //data-position(string),selected items(dom)
    console.log(position)
  }
  hovered = (position, item) => {
    console.log(position)
  }
  leaved = (position, item) => {
    console.log(position)
  }

  render () {

    return (
      <div>
        <Selection
          cols={24} 
          rows={48} 
          width={30} 
          height={50} 
          gap={10} 
          wrapperScroll={undefined}
          onMounted={this.mounted}
          onHovered={this.hovered}
          onLeaved={this.leaved}
          onSelected={this.selected}
          onSingleSelected={this.singleSelected}
          itemClass='selection_item'
          extraClass={['extra_1', 'extra_2']}
          activeClass='selection_item_active'
        >
          {content}
        </Selection>
      </div>
    )
  }
}
 

params

namedefaultValuemustEffect
cols24×columns
rows7×rows
height50px×item's height
width30px×item's width
gap0×item's spacing
wrapperScrollwindow scrollTop & scrollLeft×outer dom scrollTop & scrollLeft
Children-×item's dom or text
onMounted-×mounted callback
onHovered-×overed callback
onLeaved-×leaved callback
onSelected-×selected callback
onSingleSelected-×select or click on a single callback
itemClassselection_item×items' class
extraClass[]×items' extra class
activeClassselection_item_active×items' active class
1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago