Giter VIP home page Giter VIP logo

drag-sort-react's Introduction

基于React的简单排序组件

使用
npm install drag-sort-react
    import DragSort from 'drag-sort-react'

    const DragSortItem=DragSort.Item
    const handleChange=(r)=>{
      console.log('输出新的排序结果:',r)
    }

    return (<DragSort className="demo-1" onChange={handleChange}>
      {
        testData.map(item=>(<DragSortItem 
          className="drag-item"
          tag='div'
          key={item.id} 
          id={item.id}>{item.name}</DragSortItem>))
      }
    </DragSort>)

onChange排序改变后触发的事件

配置

DragSort

DragSort.defaultProps = {
    tag: "div",
    className: "",
    options: {
        draggable: true
    },
    onChange: noop
}

DragSort.propTypes = {
    // 元素将要渲染的Dom,默认div
    tag: PropTypes.string,
    // 元素的样式名 方便自定义样式
    className: PropTypes.string,
    // 元素开始拖放
    onStart: PropTypes.func,
    // 元素顺序改变后的回调事件
    onChange: PropTypes.func,
    // 配置
    options: PropTypes.shape({
        // 是否禁止拖放
        draggable: PropTypes.bool
    })
}

DragSortItem

DragSortItem.defaultProps = {
    tag: "div",
    className: "",
    draggable: true
}

DragSortItem.propTypes = {
    // 标记元素tag
    tag: PropTypes.string,
    // 类名字
    className: PropTypes.string,
    //当前item的id
    id: PropTypes.string.isRequired,
    // 当前元素是否支持拖拽
    draggable: PropTypes.bool
}

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.