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.7.1
  • Source
  • npm
  • Socket score

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

react-virtual-drag-list

npm npm Software License

A virtual scrolling list component that can be sorted by dragging

Live Demo

Simple Usage

npm i react-virtual-drag-list

Root component:

import VirtualList from 'react-virtual-drag-list';

function Virtual() {

  const [list, setList] = useState([{id: '1', text: 'a'}, {id: '2', text: 'b'}, ...]);

  const onDrop = (event) => {
    // dnd complete
    setList(() => event.list);
  }

  // use style and className as jsx used
  return (
    <VirtualList
      className="virtual-list"
      style={{ height: '500px' }}
      dataKey="id"
      dataSource={ list }
      handle=".handle"
      header={ <div className="loading">top loading...</div> }
      footer={ <div className="loading">bottom loading...</div> }
      onDrop={ onDrop }
    >
      {
        (record, index, dataKey) => {
          return (
            <div>
              <span class=".handle">{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </VirtualList>
  )
}

Props

Callback

EmitTypeDefaultDescription
onTopFunction-Scrolling to the top of the scroller
onBottomFunction-Scrolling to the bottom of the scroller
onDragFunction-Drag is started
onDropFunction-Drag is complete

Required props

PropTypeDefaultDescription
dataKeyString-The unique identifier of each piece of data, in the form of 'a.b.c'
dataSourceArray[]The data that needs to be rendered

Common used

PropTypeDefaultDescription
headerJSX.Element-Top of list
footerJSX.Element-Bottom of list
sizeNumber-Estimated height of each row. You can choose to pass it or not, it will be automatically calculated
keepsNumber30The number of lines rendered by the virtual scroll
handleString-Drag handle selector within list items
groupObject/String-string: 'name' or object: { name: 'group', put: true/false, pull: true/false/'clone', revertDrag: true/false }
scrollerDocument | HTMLElement-Virtual list scrolling element
directionvertical | horizontalverticalScroll direction
debounceTimeNumber0debounce time on scroll
throttleTimeNumber0debounce time on scroll
tableModeBooleanfalsedisplay with table and tbody

Uncommonly used

PropTypeDefaultDescription
draggableString'.virutal-dnd-list-item'Specifies which items inside the element should be draggable
sortableBooleantrueWhether the current list can be sorted by dragging
lockAxisx | y-Axis on which dragging will be locked
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll
disabledBooleanfalseDisables the sortable if set to true
animationNumber150Drag-and-drop's animation delay
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollThresholdNumber55Threshold to trigger autoscroll
delayNumber0Time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseOnly delay on press if user is using touch
fallbackOnBodyBooleanfalseAppends the ghost element into the document's body
rootTagStringdivLabel type for root element
wrapTagStringdivLabel type for list wrap element
wrapStyleObject{}List wrapper element style
wrapClassString''List wrapper element class
itemClassString'virutal-dnd-list-item'List item element class
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
getSize(key)get the height of the specified item by key value
getOffset()get the current scroll top/left
getClientSize()Get wrapper element client viewport size (width or height)
getScrollSize()Get all scroll size (scrollHeight or scrollWidth)
scrollToTop()scroll to the top of the list
scrollToBottom()scroll to the bottom of the list
scrollToKey(key)scroll to the specified data-key
scrollToIndex(index)scroll to the specified index value
scrollToOffset(offset)scroll to the specified height

Keywords

FAQs

Package last updated on 11 Jun 2024

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