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-layout-grid-generator

v1.0.0

Published

React drag & drop components based on react-grid-layout

Downloads

11

Readme

react-layout-grid-generator

npm package npm downloads

this component is created using react-grid-layout to create dashboard by drag & drop. you can access to the demo.

install it with,

yarn add react-layout-grid-generator

or

npm install react-layout-grid-generator

Options

| prop | type | default | description | | --------------------- | ------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | isEditable | bool | false | allow the end-user to change the position and size of the grid items. | | renderEdit | func | - | grid item to render when edit mode is turned on, use it as a method. see below for usage | | renderView | func | - | the render of grid item when edit mode is off, use it as a method | | onChange? | func | - | the function will be raised if the layout changes in edit mode | | initialLayouts? | object | null | the initial state of layout | | renderDraggableItems? | func | - | to enable drag & drop components into, use it as a method. * each draggable item 'onDragStart' should be binded to 'handleDragStart' | | children? | node | null | children will be rendered inside the LayoutGrid | | gridItemMargin? | number | 10 | margin between each grid item | | editingGridColor? | string | #cccccc80 | background color in edit mode | | breakpointRules? | object | - | min width to apply each layout size e.g. lg, sm, lg and etc. | | colRules? | object | - | maximum number of column in width for each layout size e.g. lg, sm, lg and etc. |

renderEdit and RenderView

in rendering the grid item you can access to the following properties:

| prop | type | description | | ------------ | ------ | ----------------------------------------------------------------------------------------- | | id | string | the id of grid item | | type | string | it can be used as a key for rendering decision | | option | object | it can be used as a place for storing additional data | | x | number | row position of the grid item | | y | number | column position of the grid item | | w | number | width of each grid item | | h | number | height of each grid item | | onUpdateById | func | * only in edit mode. it will update the option property. the inputs are (id, key, value) | | onDeleteById | func | * only in edit mode. it will delete the grid item by id |

EXAMPLES

import { LayoutGrid } from "react-layout-grid-generator";

const widgetItems = [
  { option: { data: "b" }, type: "CHART_A", w: 1, h: 1 },
  { option: { res: "b" }, type: "CHART_B", w: 2, h: 2 },
  { option: {}, type: "WIDGET", w: 1, h: 1 },
];
const [isEditable, setIsEditable] = useState(true);

const [initialLayouts, setInitialLayouts] = useState({});
const [tempLayouts, setTempLayouts] = useState({});

const onLayoutChanged = (newLayouts) => {
  setTempLayouts(newLayouts);
};

const onSave = () => {
  localStorage.setItem("layouts", JSON.stringify({ layouts: tempLayouts }));
};

const onLoad = () => {
  const newLayouts = JSON.parse(localStorage.getItem("layouts")).layouts;
  setInitialLayouts(newLayouts);
};

<LayoutGrid
  isEditable={isEditable}
  renderEdit={({ type, onUpdateById, onDeleteById, id, option }) => (
    <div>
      {type}
      {option?.data ?? ""}
      <button onClick={() => onUpdateById(id, "option", { data: "me" })}>
        Edit
      </button>
      <button onClick={() => onDeleteById(id)}>DELETE</button>
    </div>
  )}
  renderView={({ type, option }) => {
    switch (type) {
      case "CHART_A":
        return <div className="chart-a">CHART_A</div>;
      case "CHART_B":
        return <div className="chart-b">CHART_B</div>;
      case "WIDGET":
        return <div className="chart-c">WIDGETTTTT</div>;

      default:
        return <div className="chart-none">NO TYPE PROVIDED</div>;
    }
  }}
  renderDraggableItems={(handleDragStart) => (
    <div className="layout-grid__widget-items">
      {widgetItems.map((item) => (
        <div
          draggable={true}
          className="widget-item"
          key={item.type}
          onDragStart={(e) => handleDragStart(item, e)}
        >
          {type}
        </div>
      ))}
    </div>
  )}
  onChange={onLayoutChanged}
  initialLayouts={initialLayouts}
>
  <span>Will be added here</span>
</LayoutGrid>;