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

A virtual scrolling list component that can be sorted by dragging

  • 2.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.2K
decreased by-25.71%
Maintainers
1
Weekly downloads
 
Created
Source

Downloads Version

A virtual scrolling list component that can be sorted by dragging

demo

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, _old, _new, changed) => {
    console.log(arr, _old, _new, changed, 'new state after drag end')
  }

  // you can use style and className as jsx used
  return (
    <VirtualList
      className="virtual-list"
      style={{ height: '500px' }}
      dataKey="id"
      dataSource={ list }
      draggable=".drag"
      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, dataKey) => {
          return (
            <div>
              <span class=".drag">{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </VirtualList>
  )
}

Props

Common used

PropTypeRequired?DefaultDescription
dataKeyString-The unique identifier of each piece of data, in the form of 'a.b.c'
dataSourceArray[]Data list
sizeNumber50Estimated height of each row
keepsNumber30The number of lines rendered by the virtual scroll
directionStringverticalvertical/horizontal, scroll direction
draggableFunction/String-Specifies which items inside the element should be draggable, the function type must return a boolean
v-topFunction-callback function that fires when scrolling to the top
v-bottomFunction-callback function that fires when scrolling to the bottom
v-dragendFunction-event when drag is complete
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollStepNumber5The distance to scroll each frame when autoscrolling
scrollThresholdNumber15Threshold to trigger autoscroll

Uncommonly used

PropTypeRequired?DefaultDescription
disabledBooleanfalseDisables the sortable if set to true
delayNumber0Delay time of debounce function
draggingFunctionundefinedSpecifies the drag element, which must return an HTMLElement, such as (e) => e.target
headerJSX.Element-Top of list
footerJSX.Element-Bottom of list
rootTagStringdivLabel type for root element
wrapTagStringdivLabel type for list wrap element
itemTagStringdivLabel type for list item element
headerTagStringdivLabel type for header slot element
footerTagStringdivLabel type for footer slot element
itemStyleObject{}Style for each line
itemClassString''Class for each line
wrapStyleObject{}List wrapper element style
wrapClassString''List wrapper element class
animationNumber150Drag-and-drop's animation delay
ghostStyleObject{}The style of the mask element when dragging
ghostClassString''The class of the mask element when dragging
chosenClassString''The class of the selected element when dragging

Methods

Use the methods exposed in the component by setting ref

...

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
getOffset()get the current scroll height
scrollToTop()scroll to the top of the list
scrollToBottom()scroll to the bottom of the list
scrollToIndex(index)scroll to the specified index value
scrollToOffset(offset)scroll to the specified height

Keywords

FAQs

Package last updated on 02 Jun 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