@mish-tv/sortable-list
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@mish-tv/sortable-list
npm license

`@mish-tv/sortable-list` is a React component for creating a vertical list UI that can be sorted by drag and drop.

Usage

import React from "react";
import { RowCreator, SortableList } from "@mish-tv/sortable-list";

type Item = { id: number; body: string };

export const Component = (props: { initialIds: number[]; items: Record<number, Item> }) => {
  const [ids, setIds] = React.useState(props.initialIds);

  const row: RowCreator<HTMLLIElement, number> = React.useCallback(
    (id, rowAttributes, handleAttributes, options) => {
      const item = props.items[id];
      let className = "row";
      if (options.isDraggingThis) className += " draggingThis";
      if (options.isDraggingOthers) className += " draggingOthers";

      return (
        <li className={className} {...rowAttributes}>
          <button type="button" {...handleAttributes}></button>
          <span>{item.body}</span>
        </li>
      );
    },
    [props.items],
  );

  return (
    <ul className="list">
      <SortableList ids={ids} setIds={setIds} row={row} />
    </ul>
  );
};

Installation

npm install --save @mish-tv/sortable-list

Readme

Keywords

none

Package Sidebar

Install

npm i @mish-tv/sortable-list

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

132 kB

Total Files

71

Last publish

Collaborators

  • malt03