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.1
  • 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')
  }

  return (
    <virtualList
      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?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
directionStringvertical/horizontal, scroll directionvertical
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-
draggableFunction/StringSpecifies which items inside the element should be draggable, the function type must return a booleanundefined
draggingFunctionSpecifies the drag element, which must return an HTMLElement, such as (e) => e.targetundefined

Uncommonly used

PropTypeRequired?DescriptionDefault
disabledBooleanDisables the sortable if set to truefalse
delayNumberDelay time of debounce function0
headerJSX.Elementtop of list-
footerJSX.Elementbottom of list-
wrapTagStringLabel type for list wrap elementdiv
rootTagStringLabel type for root elementdiv
itemTagStringLabel type for list item elementdiv
headerTagStringLabel type for header slot elementdiv
footerTagStringLabel type for footer slot elementdiv
itemStyleObjectstyle for each line{}
itemClassStringclass for each line''
rootStyleObjectRoot element style{}
rootClassStringRoot element class''
wrapStyleObjectList wrapper element style{}
wrapClassStringList wrapper element class''
animationNumberDrag-and-drop's animation delay150
ghostStyleObjectThe style of the mask element when dragging{}
ghostClassStringThe class of the mask element when dragging''
chosenClassStringThe 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 26 May 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