Giter VIP home page Giter VIP logo

react-dragline's Introduction

react-dragline

Guide lines and magnetic adsorption to better align draggable elements.

npm version npm downloads license

Examples available here: https://zcued.github.io/react-dragline/

Installation

npm

npm install react-dragline --save

yarn

yarn add install react-dragline

If you aren't using browserify/webpack, a UMD version of react-dragline is available. It expects external React and ReactDOM.

Example

import { DraggableContainer, DraggableChild } from 'react-dragline'


class Example extends React.Component {
  state = [
    { id: 1, position: {x: 100, y: 10} },
    { id: 2, position: {x: 400, y: 200} },
  ]

  render() {
    const containerStyle = {
      height: 600,
      position: 'relative',
    }

    return (
      <DraggableContainer style={containerStyle}>
        {
          this.state.children.map(({ id, position }, index) => {
            const style = {
              width: 100,
              height: 100,
              cursor: 'move',
              background: '#8ce8df',
            }

            return (
              <DraggableChild key={id} defaultPosition={position}>
                <div style={style} />
              </DraggableChild>
            )
          })
        }
      </DraggableContainer>
    )
  }
}

ReactDOM.render(<Example />, container)

Prop Types: DraggableContainer

Property Type Default Description
Container String/Element 'div' The DraggableContainer will be rendered as a HTML tag or the React Component you specify
threshold Number 5 The max distance of between others and the dragging element triggering magnetic adsorption
directions Array ['tt', 'bb', 'll', 'rr', 'tb', 'lr', 'rl', 'mh', 'mv'] The directions you want. tt indicate the guide line will show when a element aligned with the top of the dragging element.
activeClassName String 'active' if you want to add class name for the element aligned with one you drag, use it.
lineStyle Object {} You can customize the style of auxiliary line by this option
limit Boolean true Whether to restricts movement within the container
detectOverlap Boolean false If true, then you can't drag block throw other blocks

Prop Types: DraggableChild

Property Type Default Description
axis String both Determines which axis the draggable can move (both, x, y)
grid Array [1,1] Specifies the x and y that dragging should snap to

Contributing

  1. Fork, then clone the project.
  2. Run the project in development mode: $ yarn start.
  3. Make your changes.
  4. Lint the code: $ yarn lint
  5. Make sure that the tests still pass:$ yarn test
  6. Commit and PR.

react-dragline's People

Contributors

vq0599 avatar tothehit avatar zhlooking avatar

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.