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

Version published
Weekly downloads
6.4K
increased by28.52%
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 handleToTop = () => {
    // to top
  }
  const handleToBottom = () => {
    // to bottom
  }
  const handleDrop = (params) => {
    // dnd complete
  }

  // 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> }
      v-top={ handleToTop }
      v-bottom={ handleToBottom }
      v-drop={ handleDrop }
    >
      {
        (record, index, dataKey) => {
          return (
            <div>
              <span class=".handle">{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </VirtualList>
  )
}

Props

Callback

EmitTypeRequired?DefaultDescription
v-topFunction-Scrolling to the top of the scroller
v-bottomFunction-Scrolling to the bottom of the scroller
v-dragFunction-Drag is started
v-dropFunction-Drag is complete
v-addFunction-Element is dropped into the list from another
v-removeFunction-Element is removed from the list into another

Common used

PropTypeRequired?DefaultDescription
dataKeyString-The unique identifier of each piece of data, in the form of 'a.b.c'
dataSourceArray[]The data that needs to be rendered
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
handleFunction/String-Drag handle selector within list items
groupObject/String-string: 'name' or object: { name: 'group', put: true/false, pull: true/false/'clone', revertDrag: true/false }
scrollerHTMLElement | Window | Document-Virtual list scrolling element
directionStringverticalvertical/horizontal, scroll direction
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll
debounceTimeNumber0debounce time on scroll
throttleTimeNumber0debounce time on scroll
headerJSX.Element-Top of list
footerJSX.Element-Bottom of list

Uncommonly used

PropTypeRequired?DefaultDescription
draggableString-Specifies which items inside the element should be draggable. If does not set a value, the default list element can be dragged
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
itemTagStringdivLabel type for list item element
itemStyleObject{}List item element style
itemClassString''List item element class
headerTagStringdivLabel type for header slot element
headerStyleObject{}header slot style
headerClassString''header slot class
footerTagStringdivLabel type for footer slot element
footerStyleObject{}footer slot style
footerClassString''footer slot 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 07 Mar 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