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

@osx11/react-simple-dnd-table

v1.0.13

Published

A simple Drag-To-Reorder table for React

Downloads

4

Readme

React Simple DND (Drag to Reorder) Table

demo gif

Installation

With npm:

npm install @osx11/react-simple-dnd-table

With yarn:

yarn add @osx11/react-simple-dnd-table

Usage

Applicable for both high-level and low-level api:

You should provide the following css variables:

:root {
  --dnd-table-odd-row-background: #F5F5F5; /* background for odd rows */
  --dnd-table-even-row-background: none; /* background for even rows */
  --dnd-table-row-highlight-border: #5388F1; /* border color for element before of after which the dragging row will be inserted */
  --dnd-table-borders: #cfd9e1; /* general table borders */
}

Please note that you should provide icons for expand button and drag-and-drop icon manually. It should be located somewhere in the assets folder (or any) and imported like that:

import dragHandleIcon from './assets/drag-handle.svg';
import expandArrowIcon from './assets/expand-arrow.svg';

Then you can pass it to dragHandleIcon and expandArrowIcon props of SimpleDNDTable or as url prop for DNDTableHandle.

Note that there may be a typescript error when importing images, including .svg. To avoid it, create global.d.ts (or any .d.ts) file in the root dir of project and put the following content:

declare module "*.svg";

Example of usage with a high-level API

import {useState} from 'react';
import dragHandleIcon from './assets/drag-handle.svg';
import expandArrowIcon from './assets/expand-arrow.svg';
import {SimpleDNDTable, SimpleDNDTableData} from '@osx11/react-simple-dnd-table';

function App() {
  const [data, setData] = useState<SimpleDNDTableData[]>([
    {key: '1', values: ['1', '2', '3']},
    {
      key: '2',
      values: ['4', '5', '6'],
      inner: [
        {key: '4', values: ['10', '11', '12']},
        {key: '5', values: ['13', '14', '15']}
      ]
    },
    {key: '3', values: ['7', '8', '9']},
  ]);

  return (
    <SimpleDNDTable 
      data={data} 
      onOrderUpdate={setData}
      headers={['Column 1', 'Column 2', 'Column 3']} 
      dragHandleIcon={dragHandleIcon} 
      expandArrowIcon={expandArrowIcon}
    />
  )
}

export default App;

All the props listed in the above example are mandatory, but there also is an optional prop:

  • gridColumnSettings: string - via this prop you can manage width of your columns. The default value is 30px repeat(1fr, N), where 30px is responsive for the handle width

The example of high-level API using SimpleDNDTable is ready to use and located at src/example.

To run dev server with example, type:

cd src/example
yarn
yarn dev

Example of usage with a low-level API

Please, see the implementation of SimpleDNDTable (located at src/components/simple_dnd_table/SimpleDNDTable.tsx) as an example of low-level API usage. Low-level API provides full control over the table, including micro-components like Table, TableRow, TableData etc.

Customization

You can customize the entire table by overriding the following css clases:

  • .dnd__table-data-element
  • .dnd__table-data
  • .dnd__table-row
  • .dnd__table-head
  • .dnd__table-header-element
  • .dnd__table-header
  • .dnd__table
  • .dnd__handle
  • .dnd__handle-disabled