react-sortable-dashboard
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

React sortable dashboard · npm

React library for building modern dashboards with drag-n-drop sorting

Links

Usage

import { Dashboard, DashboardWidget } from "react-sortable-dashboard";

const handleWidgetsReorder = (source: number, target: number) => {
  // ... do some stuff with source and target index
};

function App() {
  const widgets = ...; // Array of some widget objects

  return (
    <Dashboard rows={5} columns={5} onWidgetsReorder={handleWidgetsReorder}>
      { widgets.map((widget) => (
        <DashboardWidget
              columns={widget.columns}
              rows={widget.rows}
              key={widget.id}
              dragRef={dragTriggerRef}>
              <SomeWidgetComponent />
        </DashboardWidget>
      ))}
    </Dashboard>
  );
}

API Reference

Dashboard

Parameter Type Description
rows number Required. Total number of rows available for widgets on this dashboard
columns number Required. Total number of columns available for widgets on this dashboard
verticalSpacing number Space in pixels, that will be added between columns
horizontalSpacing number Space in pixels, that will be added between rows
onWidgetsReorder (source: number, target: number) => void handler for event that fires when order of widgets was changed via drag and drop

DashboardWidget

Parameter Type Description
rows number Required. Number of rows occupied by widget
columns number Required. Number of columns occupied by widget
dragRef RefObject<HTMLElement> Ref to widget child, that triggers drag and drop interaction

Package Sidebar

Install

npm i react-sortable-dashboard

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

58.7 kB

Total Files

30

Last publish

Collaborators

  • dkonasov