npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multi-drag-drop

v0.0.12

Published

A react npm package that can do table rows & cols drag & drop with and without MUI.

Downloads

400

Readme

react-multi-drag-drop

This package will do drag and drop of a table rows and columns both. Users can customize the table's CSS using the "custom-scrollbar" class. This package is compatible with or without MUI.

Installation

npm install react-multi-drag-drop OR npm react-multi-drag-drop  --legacy-peer-deps

OR

yarn add react-multi-drag-drop OR yarn add react-multi-drag-drop  --legacy-peer-deps

Usage

<!-- How to import package -->
import { TableDragAndDrop } from "react-multi-drag-drop";
<!-- How to define rows -->
const [tableRows, setTableRows] = useState([
    {
      name: "Design",
      id: "2f251f31-4d52-4c6d-b383-3e35b2257beb",
      message: "Npm",
      created_by: "Mohammad",
      file_count: 1,
      days: "Monday",
      date: "27-June-2024",
      status: "Complete",
    },
    {
      name: "Making",
      id: "149e7dd4-a537-452e-9346-ab19194ea96d",
      message: "Package",
      created_by: "Nadeem",
      file_count: 1,
      days: "Tuesday",
      date: "27-June-2024",
      status: "Ready",
    },
    {
      name: "CSS",
      id: "1",
      message: "Storybook",
      created_by: "Amans",
      file_count: 1,
      days: "Wednesday",
      date: "27-June-2024",
      status: "Review",
    },
    {
      name: "HTML",
      id: "2",
      message: "React.JS",
      created_by: "Maans",
      file_count: 1,
      days: "Thursday",
      date: "27-June-2024",
      status: "In_Progress",
    },
    {
      name: "New Folder",
      id: "2f251f31-4d52-4c6d-b383-3e35b2257beb",
      message: "Npm",
      created_by: "Mohammad",
      file_count: 1,
      days: "Monday",
      date: "27-June-2024",
      status: "Complete",
    },
    {
      name: "Storybook",
      id: "149e7dd4-a537-452e-9346-ab19194ea96d",
      message: "Package",
      created_by: "Nadeem",
      file_count: 1,
      days: "Tuesday",
      date: "27-June-2024",
      status: "Ready",
    },
    {
      name: "React Component",
      id: "1",
      message: "Storybook",
      created_by: "Amans",
      file_count: 1,
      days: "Wednesday",
      date: "27-June-2024",
      status: "Review",
    },
    {
      name: "Row and Col",
      id: "2",
      message: "React.JS",
      created_by: "Maans",
      file_count: 1,
      days: "Thursday",
      date: "27-June-2024",
      status: "In_Progress",
    },
  ]);

<!-- How to define columns -->
const [columns, setColumns] = useState([
    {
      name: "name",
      displayName: "Name",
      cellWidth: 200,
      render: (r) =>
        r && r?.name ? (
          <Box display={"flex"} flexDirection={"row"} alignItems={"center"}>
            <IconButton size="small">
              <FaFolder size={12} color="#F8D775" />
            </IconButton>
            <Text
              color="primary"
              semibold
              style={{
                width: "100%",
                overflow: "hidden",
                textOverflow: "ellipsis",
                whiteSpace: "nowrap",
              }}
            >
              {r?.name}
            </Text>
          </Box>
        ) : (
          "N/A"
        ),
    },
    {
      name: "created_by",
      displayName: "Created By",
      render: (r) =>
        r && r?.created_by ? <Text>{r?.created_by}</Text> : "N/A",
    },
    {
      name: "days",
      displayName: "Days",
      render: (r) => (r && r?.days ? <Text>{r?.days}</Text> : "N/A"),
    },
    {
      name: "date",
      displayName: "Date",
      cellWidth: 200,
      render: (r) => (r && r?.date ? <Text>{r?.date}</Text> : "N/A"),
    },
    {
      name: "status",
      displayName: "Progress Status",
      render: (r) => (r && r?.status ? <Text>{r?.status}</Text> : "N/A"),
    },
    {
      name: "message",
      displayName: "Message",
      render: (r) => (r && r?.message ? <Text>{r?.message}</Text> : "N/A"),
    },

    {
      name: "file_count",
      displayName: "Files Count",
      render: (r) =>
        r && r?.file_count ? <Text>{r?.file_count}</Text> : "N/A",
    },
    {
      name: "actions",
      displayName: "Actions",
      render: (r) =>
        r &&
        r?.id && (
          <OptionMenu
            options={[
              {
                icon: <FiTrash2 />,
                name: "delete",
                displayName: "Delete",
                onClick: () => {},
              },
            ]}
          />
        ),
    },
  ]);
<!-- How to define Row drop handler -->
const handleDropRow = (draggedId, targetIndex) => {
    const presentID = tableRows?.some((data) => data?.id === draggedId);
    if (presentID) {
      // Implement the logic and API call to update the database.
      // Example :- In this code, I'm only updating the local state without making an API call.
      //  setTableRows((prev) => {
      //   const draggedIndex = prev.findIndex((item) => item.id === draggedId);
      //   const updatedItems = [...prev];
      //   const [draggedItem] = updatedItems.splice(draggedIndex, 1);
      //   updatedItems.splice(targetIndex, 0, draggedItem);
      //   return updatedItems;
      // });
    }
  };
  <!-- How to define Column drop handler -->
const handleDropCol = (draggedColId, draggedColIndex, targetColIndex) => {
    const presentID = columns?.some((data) => data?.name === draggedColId);
    if (presentID) {
      // Implement the logic and API call to update the database.
    }
  };

<!-- How to use component -->
// Without MUI
  <TableDragAndDrop
      rows={tableRows}
      columns={columns}
      msg={"No results found"}
      cellHeight={"0.1rem"}
      setTableRows={setTableRows}
      setColumns={setColumns}
      handleDropCol={handleDropCol}
      handleDropRow={handleDropRow}
    />

OR
// With MUI
  <ThemeProvider theme={theme}>
      <CssBaseline />
      <Paper>
        <TableDragAndDrop
          rows={tableRows}
          columns={columns}
          msg={"No results found"}
          cellHeight={"0.1rem"}
          setTableRows={setTableRows}
          setColumns={setColumns}
          handleDropCol={handleDropCol}
          handleDropRow={handleDropRow}
        />
      </Paper>
    </ThemeProvider>

License

This project is licensed under the MIT License.

Author

  • Mohammad Nadeem
    • LinkedIn: (https://in.linkedin.com/in/mohammad-nadeem-044418136)