Socket
Socket
Sign inDemoInstall

generic-dnd-list

Package Overview
Dependencies
24
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    generic-dnd-list

A DnD list with a custom renderer for its items.


Version published
Maintainers
1
Install size
4.01 MB
Created

Readme

Source

generic-dnd-list Weekly downloads

A DnD list with a custom renderer for its items.


Demo

You can access the storybook for this component here.

Props

The component accepts the props defined bellow in the table.

Props accepted by GenericDndList

NameTypeRequiredDefaultDescription
getId(item: unknown) => stringyes-It returns a unique ID for each item
getItemClassName(isDragging: boolean) => stringnoundefinedIt returns the className for an item in the list
getItemStyle((isDragging: boolean) => CSSProperties) | nullnointernal*It returns the style for an item in the list
getListClassName(isDraggingOver: boolean) => stringnoundefinedIt returns the className for the list
getListStyle((isDraggingOver: boolean) => CSSProperties) | nullnointernal*It returns the style for the list
itemsunknown[]yes-The items rendered
lockAxisbooleannofalseThe dragged item keeps the direction
propsDragDropContextDragDropContextPropsno-Props passed to react-beautiful-dnd component
propsDraggableDraggableProps except draggableId, indexno-Props passed to react-beautiful-dnd component
propsDroppableDroppableProps except directionno-Props passed to react-beautiful-dnd component
onReorder(items: unknown[]) => voidno-It is called when the items are reordered
renderItem(item: unknown, index: number, context: Context) => JSX.Elementyes-Render an item

An undefined item can be used to signal the add new item. There should be at most one undefined item.

Context contains:

internal* - an internal style is used by default

Notes

Do not forget to provide null or a function returning an empty object for removing the default styling. The provided styles overwrite any internal styling.


Versions

GenericDndList usesreact-beautiful-dndReact
1.0.x11.0.516.8.5
1.1.x12.2.016.9.0
1.2.x13.0.016.9.0
2.0.x13.0.016.9.0
2.1.x13.0.016.9.0 or 17.0.0
2.2.x13.1.016.9.0 or 17.0.0
2.3.x13.1.016.9.0 or 17.0.0
3.0.x13.1.118.0.0

About versioning schema used for GenericDndList

  • Major - it will be increased if the major version of the dependat package changes or there are breaking changes in the code of GenericDndList
  • Minor - it will be increased if no major version of the dependat package changes, but there are changes of the minor or patch versions of it
  • Patch - it will be increased if there are no changes of the dependat packages, but there are non breaking changes in the code of GenericDndList

Example

Displaying a list with add item at the bottom:

import * as React from "react";
import GenericDndList from "generic-dnd-list";

interface ListItem {
  id: string;
  text: string;
}

const items: (ListItem | undefined)[] = [ {
    id: 'fruit-1',
    text: 'Apple'
  }, {
    id: 'fruit-2',
    text: 'Orange'
  }, {
    id: 'fruit-3',
    text: 'Banana'
  }, undefined];

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <GenericDndList
          items={items as unknown[]}
          getId={this.getId}
          renderItem={this.renderItem}
          onReorder={this.handleReorder}
        />
      </div>
    );
  }

  private getId = (item: unknown) => (item ? item.id : 'new-fruit');

  private renderItem = (item?: unknown) => (item ? <div>{item.text}</div> : <div>Use this to add a new fruit</div>);

  private handleReorder = (items: unknown[]) => {}
}

export default App;

Changelog

1.0.0

  • generic-dnd-list is made publicly available

1.1.0

  • Updated packages

1.1.1

  • Updated packages
  • Moved from npm to yarn

1.2.0

  • Updated packages

1.2.1

  • Updated packages

1.2.2

  • Fixed crash produced by "export * from"

1.2.3

  • Added two new props: getItemClassName and getListClassName

1.2.4

  • Made GenericDndList generic

1.2.5

  • Fixed GenericDndList definition in index.d.ts

1.2.6

  • Improved the definition of GenericDndList in index.d.ts

2.0.0

  • The default style is no longe applied (except user-select:none for items) if a getStyle function is provided.

2.1.0

  • Accepting React 17 as peerDependencies

2.1.1

  • Fixed security warnings

2.2.0

  • Added the possibility to lock the moved item on the vertical axis
  • Added the possibility to pass props to react-beautiful-dnd components

2.3.0

  • Added a context argument to render item function

2.3.1

  • Improved the documentation

2.3.2

  • Fixed the broken typedef in 2.3.0

2.3.3

  • Fixed the broken typedef in 2.3.0

2.3.4

  • Updated the packages

3.0.0

  • onResize prop is no longer required
  • Updated the packages
  • Supports minimum React 18

3.0.1

  • Updated the packages

3.0.2

  • Fixed bundled lib

Keywords

FAQs

Last updated on 10 Dec 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc