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-data-matrix

v0.4.2

Published

View structured data in a matrix table (data grid), showing a value located at an X and Y coordinate.

Downloads

17

Readme

React Matrix

React Matrix Demo

React Matrix table shows relationships between two or more variables in a data set in grid format.

The most common usage for a table like React Matrix, is to display the likelihood and consequence "scores" of risks/hazards, this can be for anything from Corporate, Work Health Safety and Environment risks, and more.

PR's

  • Have a look at the PR template doc for best approach to getting your pr merged.

Usage

import ReactMatrix from "react-data-matrix";

const App: FC = () => {
  ...

  return (
    <ReactMatrix
      {...{
        matrixName: "",
        matrixDescription: "",
        hasTableBorder: true,
        rowPrimaryUpper: true,
        hasInlineStyles: true,
        matrixSizeSelected: 5,
        headerPrimaryUpper: true,
        hasContainerStyles: true,
        reverseMatrixValues: true,

        tableContainerStyles: {},
        tableStyles: {},

        thRowStyles: {},
        thTitleStyles: {},
        thSubTitleStyles: {},
        thPrimaryTitleStyles: {},

        trRowStyles: {},
        trTitleStyles: {},
        trSubTitleStyles: {},
        trPrimaryTitleStyles: {},

        tdStyles: {},

        customHeaderRowIdValue: "",
        customRowDynamicIdValue: "",
        customTableDataDynamicIdValue: "",
        customRowHeaderDynamicIdValue: "",
        customDynamicHeaderTitleIdValue: "",
        customDynamicSubHeaderTitleIdValue: "",
        data,
      }}
    />
  )
}

Expected Data Structure

  • See ./src/lib/utils/data.ts for an example of the data, this can be used for testing if needed, or an example of how to construct/deconstruct your data objects from your api.
import { MatrixData } from "react-data-matrix";

export const data: MatrixData = {
  id: 1,
  matrix_size: 5,
  matrix_name: "React Matrix",
  primary_header_title: "Consequence",
  primary_row_header_title: "Likelihood",
  matrix_description: "Risk Matrix Template",

  matrix_details: [
    {
      id: 1,
      likelihood: "E",
      consequence: 1,
      position: 5,
      matrix_type: "Risk",
      header_title: "Minor",
      header_sub_title: "Header sub-title/description.",
      row_header_title: "Rare",
      row_header_sub_title: "Row Header sub-title/description.",
    },
    ...
  ],

  matrix_values: [
    {
      id: 26,
      matrix_id: 1,
      description: "low",
      score_value: 1,
      colour: "green",
      position: 1,
      likelihood_descriptor: "E",
      consequence_descriptor: 1,
      response: "Business as usual",
    },
    ...
  ],
};

PropTypes

export interface MatrixDetail {
  id: number;
  position: number;
  matrix_type: string;
  likelihood: string;
  consequence: number;
  header_title: string;
  header_sub_title: string;
  row_header_title: string;
  row_header_sub_title: string;
}

export interface MatrixValue {
  id: number;
  matrix_id: number;
  description: string;
  score_value: number;
  colour: string;
  position: number;
  likelihood_descriptor: string;
  consequence_descriptor: number;
  response: string;
}

export interface MatrixData {
  id: number;
  matrix_size: number;
  matrix_name: string;
  primary_header_title: string;
  primary_row_header_title: string;
  matrix_description: string;
  matrix_details: MatrixDetail[];
  matrix_values: MatrixValue[];
}

export interface ReactMatrixProps {
  data: MatrixData;
  hasTableBorder?: boolean;
  hasInlineStyles?: boolean | undefined;
  hasContainerStyles?: boolean | undefined;
  reverseMatrixValues?: boolean;
  matrixSizeSelected?: number;
  rowPrimaryUpper?: boolean;
  headerPrimaryUpper?: boolean;
  tableContainerStyles?: React.CSSProperties;
  tableStyles?: React.CSSProperties;
  thRowStyles?: React.CSSProperties;
  thTitleStyles?: React.CSSProperties;
  thSubTitleStyles?: React.CSSProperties;
  thPrimaryTitleStyles?: React.CSSProperties;
  trRowStyles?: React.CSSProperties;
  trTitleStyles?: React.CSSProperties;
  trSubTitleStyles?: React.CSSProperties;
  trPrimaryTitleStyles?: React.CSSProperties;
  tdStyles?: React.CSSProperties;
  customHeaderRowIdValue?: string;
  customDynamicHeaderTitleIdValue?: string;
  customDynamicSubHeaderTitleIdValue?: string;
  customRowDynamicIdValue?: string;
  customRowHeaderDynamicIdValue?: string;
  customTableDataDynamicIdValue?: string;
}

export interface MatrixHeaderProps {
  data: MatrixData;
  hasInlineStyles?: boolean | undefined;
  headerPrimaryUpper?: boolean;
  thRowStyles?: React.CSSProperties;
  thTitleStyles?: React.CSSProperties;
  thSubTitleStyles?: React.CSSProperties;
  thPrimaryTitleStyles?: React.CSSProperties;
  customHeaderRowIdValue?: string;
  customDynamicHeaderTitleIdValue?: string;
  customDynamicSubHeaderTitleIdValue?: string;
}

export interface MatrixRowsProps {
  data: MatrixData;
  rowPrimaryUpper?: boolean;
  hasInlineStyles?: boolean | undefined;
  reverseMatrixValues?: boolean;
  trRowStyles?: React.CSSProperties;
  trTitleStyles?: React.CSSProperties;
  trSubTitleStyles?: React.CSSProperties;
  trPrimaryTitleStyles?: React.CSSProperties;
  tdStyles?: React.CSSProperties;
  customRowDynamicIdValue?: string;
  customRowHeaderDynamicIdValue?: string;
  customTableDataDynamicIdValue?: string;
}

export interface TableDataProps {
  data: {
    id: number;
    colour: string;
    position: number;
    matrix_id: number;
    score_value: number;
    description: string;
    response: string;
    likelihood_descriptor: string;
    consequence_descriptor: number;
  };
  tdStyles?: React.CSSProperties;
  hasInlineStyles?: boolean;
  customTableDataDynamicIdValue?: string;
}
defaultProps = {
  hasTableBorder: true,
  rowPrimaryUpper: true,
  hasInlineStyles: true,
  matrixSizeSelected: 5,
  headerPrimaryUpper: true,
  hasContainerStyles: true,
  reverseMatrixValues: true,

  tableContainerStyles: {},
  tableStyles: {},

  thRowStyles: {},
  thTitleStyles: {},
  thSubTitleStyles: {},
  thPrimaryTitleStyles: {},

  trRowStyles: {},
  trTitleStyles: {},
  trSubTitleStyles: {},
  trPrimaryTitleStyles: {},

  tdStyles: {},

  customHeaderRowIdValue: "",
  customRowDynamicIdValue: "",
  customTableDataDynamicIdValue: "",
  customRowHeaderDynamicIdValue: "",
  customDynamicHeaderTitleIdValue: "",
  customDynamicSubHeaderTitleIdValue: "",
};

Available Properties

  • hasInlineStyles
    • Default is true.
    • If false all inline styles are removed.

  • hasTableBorder
    • Default is true.
    • If false the most outer border is removed.

  • hasContainerStyles
    • Default is true.
    • This will center the matrix in the middle of the page.

  • reverseMatrixValues
    • Default is true.
    • When true the lowest value will be in the bottom left and the highest value will be in the top right, with all sequential values in-between.
    • When false the values will be reversed, lowest value top left highest value bottom right.

  • rowPrimaryUpper
    • Default is true.
    • If false string formatting will be removed.

  • headerPrimaryUpper
    • Default is true.
    • If false string formatting will be removed.

  • customHeaderRowIdValue
    • Default is empty string.
    • can be used to target element through id prop.

  • customDynamicHeaderTitleIdValue
    • Default is empty string.
    • can be used to target element through id prop.

  • customDynamicSubHeaderTitleIdValue
    • Default is empty string.
    • can be used to target element through id prop.

  • customRowDynamicIdValue
    • Default is empty string.
    • can be used to target element through id prop.

  • customRowHeaderDynamicIdValue
    • Default is empty string.
    • can be used to target element through id prop.

  • customTableDataDynamicIdValue
    • Default is empty string.
    • can be used to target element through id prop.

Styling Properties

Inline

These styles can be added to the current styles or, if you make hasInlineStyles = false, then add these values with your own styles, you can have full control over styling inline.

ReactMatrix

  • tableContainerStyles={{}}
  • tableStyles={{}}

MatrixHeaders

  • thRowStyles={{}}
  • thTitleStyles={{}}
  • thSubTitleStyles={{}}
  • thPrimaryTitleStyles={{}}

MatrixRows

  • trRowStyles={{}},
  • trTitleStyles={{}},
  • trSubTitleStyles={{}},
  • trPrimaryTitleStyles={{}},

TableData

  • tdStyles={{}},

React + TypeScript + Vite