Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-virtual-drag-list

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-virtual-drag-list

支持拖拽排序的虚拟列表组件

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
increased by28.52%
Maintainers
1
Weekly downloads
 
Created
Source

Downloads Version

A virtual scrolling list component that can be sorted by dragging

Simple usage

npm i react-virtual-drag-list -D

or

yarn add react-virtual-drag-list -D

Root component:

import virtualList from 'react-virtual-drag-list'

function Virtual() {

  const list = [{id: '1', text: 'asd'}, {id: '2', text: 'fgh'}, ...]


  const handleToTop = () => {
    console.log('istop')
  }
  const handleToBottom = () => {
    console.log('isbottom')
  }
  const handleDragEnd = (arr) => {
    console.log(arr, 'new arr after drag end')
  }

  return (
    <virtualList
      dataKey="id"
      dataSource={ list }
      header={ <div className="loading">top loading...</div> }
      footer={ <div className="loading">bottom loading...</div> }
      v-top={ handleToTop }
      v-bottom={ handleToBottom }
      v-dragend={ handleDragEnd }
    >
      {
        (record, index, uniqueKey) => {
          return (
            <div>
              <span draggable>{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </virtualList>
  )
}

Props

PropTypeRequired?DescriptionDefault
dataKeyStringthe unique identifier of each piece of data, in the form of 'a.b.c'-
dataSourceArraydata list[]
sizeNumberestimated height of each row50
keepsNumberthe number of lines rendered by the virtual scroll30
delayNumberDelay time of debounce function10
draggableBooleanwhether to support drag and drop. You need to specify a draggable element and set the draggable attribute for ittrue
dragElementFunctionThe function that selects the dragged element, must have a return value with a dom node, has two parameters: e(the currently selected element), parent(the parent node of the list)-
headerJSX.Elementtop of list-
footerJSX.Elementbottom of list-
v-topFunctioncallback function that fires when scrolling to the top-
v-bottomFunctioncallback function that fires when scrolling to the bottom-
v-dragendFunctionevent when drag is complete-
dragStyleObjectmask style while dragging-
itemStyleObjectstyle for each line-
itemClassStringclass for each line-

Methods

Use the methods exposed in the component by setting ref, like this:

...

const virtualRef = useRef()

const scrollToBottom = () => {
  virtualRef.current.scrollToBottom()
}

return (
  <button onClick={ scrollToBottom }></button>
  <virtualList
    ref={ virtualRef }
    ...
  >
    {
      (record) => <div>{ record.text }</div>
    }
  </virtualList>
)
PropDescription
reset()reset to initial
getSize(key)get the height of the specified item by key value
getScrollTop()get the current scroll height
scrollToBottom()scroll to the bottom of the list
scrollToTop()scroll to the top of the list
scrollToOffset(offset)scroll to the specified height
scrollToIndex(index)scroll to the specified index value

Keywords

FAQs

Package last updated on 02 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc