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-mmm-grid

v1.0.11

Published

Desktop like grid component for React

Downloads

25

Readme

react-mmm-grid

npm version types npm bundle size License: MIT

react-mmm-grid is a highly customizable and performant grid component for React, designed to provide a desktop-like experience. It supports features like custom rendering, keyboard navigation and multiple column types.

react-mmm-grid

Live Demo : https://react-mmm-grid.netlify.app/

Features

  • Customizable Columns: Easily configure the columns to display.
  • Responsive Design: Adapts to different screen sizes.
  • Keyboard Navigation: Navigate through the grid using keyboard shortcuts.
  • Theming: Customize the look and feel with theming support.

Installation

Install the package via npm:

npm install react-mmm-grid

Or via yarn:

yarn add react-mmm-grid

Usage

import { useState } from "react";
import MyGrid, { MMMGridColumnProps } from "react-mmm-grid";


function App() {
  const columns: MMMGridColumnProps[] = [
    {
      name: "name",
      title: "First Name",
      minWidth: 150,
    },
    {
      name: "lastName",
      title: "Last Name",
      minWidth: 150,
    },
    {
      name: "age",
      title: "Age",
      columnType: "numeric",
      minWidth: 80,
      decimals: 1,
    },
    {
      name: "gender",
      title: "Gender",
      type: "select",
      minWidth: 100,
      selectOptions: () => [
        { label: "Male", value: "male" },
        { label: "Female", value: "female" },
      ],
    },
    {
      name: "email",
      title: "Email",
      minWidth: 120,
    },
    {
      name: "city",
      title: "City",
      minWidth: 120,
      type: "select",
      selectType: "async",
      selectOptions: () => [
        { label: "Banglore", value: "Banglore" },
        { label: "Mumbai", value: "Mumbai" },
        { label: "Nasik", value: "Nasik" },
        { label: "Pune", value: "Pune" },
        { label: "Delhi", value: "Delhi" },
        { label: "Chennai", value: "Chennai" },
        { label: "Hyderabad", value: "Hyderabad" },
        { label: "Kolkata", value: "Kolkata" },
      ],
    },
  {
      name: "avatar",
      title: "Avatar",
      minWidth: 150,
      render: (row: any, rowIndex: number) => {

        return (
          <div>
            <div
              style={{
                display: row.name ? "flex" : "none",
                width: 35,
                height: 35,
                borderRadius: 25,
                backgroundColor: "blue",
                justifyContent: "center",
                alignItems: "center",
                margin: "auto",
                fontSize: 16,
                color: "white",
              }}
            >
              {row.name?.charAt(0).toUpperCase()}
              {row.lastName?.charAt(0).toUpperCase()}
            </div>
          </div>
        );
      },
    },
  ];


  const [rows, setRows] = useState([{},{}]);
  const [activeGridRow, setActiveGridRow] = useState<any>();

  const handleGridChange = async (
    rowIndex: number,
    name: string,
    value: any,
    inputType?: "select" | "text"
  ) => {
    const temp: any = structuredClone(rows);

    let val = value;
    if (inputType === "select") {
      val = value?.label;
    }
    temp[rowIndex] = { ...temp[rowIndex], [name]: val };

    if (rowIndex >= temp.length - 2) {
      temp.push({});
    }

    setRows(temp);
  };

  const handleRowsDelete = (indexes: number[]) => {
    let temp = structuredClone(rows);
    for (let i = 0; i < indexes.length; i++) {
      temp[indexes[i]] = {};
    }
    temp = temp.filter((x: any) => x.name);
    temp.push({});
    temp.push({});

    setRows(temp);
  };



  return (
    <div>
      <h1 style={{ textAlign: "center", color: "gray" }}>
        <u>MMM Grid Demo</u>
      </h1>

      <h2 style={{ color: "gray" }}>Grid 1</h2>
      <MyGrid
        columns={columns}
        rows={rows}
        height={200}
        handleChange={handleGridChange}
        deleteRows
        handleDelete={handleRowsDelete}
        setActiveGridRow={setActiveGridRow}
        idPrefix="grid1" // should be unique for each grid in the same page
      />
      <div style={{ marginTop: 7, textAlign: "center", color: "blue" }}>
        <b>Active row first name : {activeGridRow?.name}</b>
      </div>
      <br />
    </div>
  );
}

export default App;

Props

| Name | Type | Default | Description | | --- | --- | --- | --- | | columns | MMMGridColumnProps[] | [] | The columns to display in the grid. | | rows | any[] | [] | The rows to display in the grid. | | height | number | 300 | The height of the grid. | | handleChange | (rowIndex: number, name: string, value: any, inputType?: "select" | "text") => void | () => {} | The function to call when a cell value changes. | | deleteRows | boolean | false | Whether to show the delete rows button. | | handleDelete | (indexes: number[]) => void | () => {} | The function to call when the delete rows button is clicked. | | setActiveGridRow | (row: any) => void | () => {} | The function to call when a row is clicked. | | idPrefix | string | "" | A unique prefix for the grid's IDs. |

License

MIT

Author

Mehlam Hamid