1.1.0 • Published 2 months ago

@tenqube/react-grid v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@tenqube/react-grid

logo

Introduction

React Grid is a tabular View library used within the Tenqube company.
It is composed of React components and can be implemented easily and intuitively by passing the data constituting the table as Props.

It is still an early version, so there may be unstable parts. Please register the problematic part as an issue on GitHub.

Version

v1.1.0

Features

Change and remember column width.

You can change the size of each column in the table by enabling the scalable setting in options, and the changes will be saved and persisted in web storage.

Fixed column not working to scroll.

If you enter a size in the fixedSize setting in options, the column is fixed by that size. (default 0)

Other basic features..

  • Provided as a sorting status callback by column.
  • Specifying per-row classes for styling.
  • Provides column types such as checkbox and toggle.

Installation

$ npm install @tenqube/react-grid

Quick Start

React Grid makes it simple to construct a table view by passing the promised columns and rows as Props.
and below is a simple configuration example.

// GridComponent.tsx
import React from "react";
import Grid, { GridType, IPropsColumn, RowType } from "@tenqube/react-grid";
// import style what you want
import "@tenqube/react-grid/dist/esm/index.css";
import "@tenqube/react-grid/dist/cjs/index.css";

const GridComponent = () => {
  const columns: Array<IPropsColumn> = [
    {
      id: "week",
      name: "THIS WEEK",
      type: GridType.String,
    },
    {
      id: "title",
      name: "TITLE",
      type: GridType.String,
    },
    {
      id: "artist",
      name: "ARTIST",
      type: GridType.String,
    },
    {
      id: "award",
      name: "AWARD",
      type: GridType.String,
    },
  ];

  const rows: Array<Array<RowType>> = [
    ["1", "Last Night", "Morgan Wallen", "★"],
    ["2", "Flowers", "Miley Cyrus", ""],
    ["3", "Kill Bill", "SZA", ""],
    ["4", "Calm Down", "Rema & Selena Gomez", "★"],
    ["5", "Favorite Song", "Toosii", "★"],
  ];

  return <Grid id={"billboard"} columns={columns} rows={rows} />;
};

export default GridComponent;

Props

React Grid provides props of id, columns, rows, options and addClassNameByRows.

Grid Props

interface IProps {
  id: string;
  rows: RowType[][];
  columns: IPropsColumn[];
  options?: IPropsOptions;
  addClassNameByRows?: IClassNameByRow[];
}

Row Type

type string | number | boolean | ILinkRows | Array<string | number> | null | Function | ReactNode

Link Rows

interface ILinkRows {
  name: string;
  target: string;
  url: string;
}

Link Rows

interface IClassNameByRow {
  index: number;
  className: string;
}

GridType

enum GridType {
  Hidden,
  Checkbox,
  String,
  Toggle,
  Image,
  Link,
  Button,
  Items,
  InputText,
  InputNumber,
  Array,
  Component,
}

Columns

  • Hidden type
interface IPropsColumn {
  id: string;
  type: GridType.Hidden;
}
  • Checkbox type
interface IPropsColumn {
  id: string;
  type: GridType.Checkbox;
  callback: (isAll: boolean, rowIdx?: number, columnIdx?: number) => void;
  width?: number;
  className?: string;
}
  • Toggle type
interface IPropsColumn {
  id: string;
  type: GridType.Toggle;
  callback: (rowIdx: number, columnIdx: number) => void;
  width?: number;
  name?: string;
  className?: string;
}
  • String type
interface IPropsColumn {
  id: string;
  type: GridType.String;
  width?: number;
  name?: string;
  className?: string;
  isSorting?: boolean;
  callback?: (columnId: string, orderType: OrderType) => void; // callback by sorting
}
  • Image type
interface IPropsColumn {
  id: string;
  type: GridType.Image;
  width?: number;
  name?: string;
  className?: string;
}
  • Link type
interface IPropsColumn {
  id: string;
  type: GridType.Link;
  width?: number;
  name?: string;
  className?: string;
  isSorting?: boolean;
  callback?: (columnId: string, orderType: OrderType) => void; // callback by sorting
}
  • Button type
interface IPropsColumn {
  id: string;
  type: GridType.Button;
  callback: (rowIdx: number, columnIdx: number) => void;
  width?: number;
  name?: string;
  className?: string;
}
  • Items type
interface IPropsColumn {
  id: string;
  type: GridType.Items;
  items: Array<FC<{ rowIdx: number; columnIdx: number }> | ReactNode>;
  width?: number;
  name?: string;
  className?: string;
  isSorting?: boolean;
  callback?: (columnId: string, orderType: OrderType) => void; // callback by sorting
}
  • Input type
interface IPropsColumn {
  id: string;
  type: GridType.InputText | GridType.InputNumber;
  callback: (rowIdx: number, columnIdx: number, value: string | number) => void;
  width?: number;
  name?: string;
  className?: string;
}
  • Array type
interface IPropsColumn {
  id: string;
  type: GridType.Array;
  width?: number;
  name?: string;
  className?: string;
}
  • Component type
interface IPropsColumn {
  id: string;
  type: GridType.Component;
  width?: number;
  name?: string;
  className?: string;
  isSorting?: boolean;
  callback?: (columnId: string, orderType: OrderType) => void; // callback by sorting
}

OrderType

enum OrderType {
  Default,
  ASC,
  DESC,
}

Options

interface IPropsOptions {
  scalable?: boolean | IPropsScalableOption;
  fixedSize?: number;
  scroll?: IPropsScrollOption;
}
interface IPropsScalableOption {
  enable: boolean;
  storage?: boolean | IPropsStorageOption;
}
interface IPropsStorageOption {
  enable: boolean;
  target?: "local" | "session";
}
export interface IPropsScrollOption {
  enable: boolean;
  type?: "inner" | "outer";
  height?: number;
}

Example

String type and Sorting

import React, { useState } from "react";
import Grid, { GridType, IPropsColumn, RowType } from "@tenqube/react-grid";
// import style what you want
import "@tenqube/react-grid/dist/esm/index.css";
import "@tenqube/react-grid/dist/cjs/index.css";

const StringTypeComponent = () => {
  const ascRows = [["aaa"], ["bbb"], ["ccc"]];
  const descRows = [["ccc"], ["bbb"], ["aaa"]];

  const [rows, setRows] = useState<Array<Array<RowType>>>(ascRows);

  const handleSorting = (columnId: string, orderType: OrderType) => {
    setRows(orderType === OrderType.ASC ? ascRows : descRows);
  };

  const columns: Array<IPropsColumn> = [
    {
      id: "string",
      name: "Text",
      type: GridType.String,
      isSorting: true,
      callback: handleSorting,
    },
  ];

  return <Grid id={"string"} columns={columns} rows={rows} />;
};

export default StringTypeComponent;

Toggle type

import React, { useState } from "react";
import Grid, { GridType, IPropsColumn, RowType } from "@tenqube/react-grid";
// import style what you want
import "@tenqube/react-grid/dist/esm/index.css";
import "@tenqube/react-grid/dist/cjs/index.css";

const ToggleTypeComponent = () => {
  const [rows, setRows] = useState<Array<Array<RowType>>>([[true], [false]]);

  const handleToggle = (rowIdx: number, columnIdx: number) => {
    const cloneRows = rows.map((row) => [...row]);
    cloneRows[rowIdx][columnIdx] = !cloneRows[rowIdx][columnIdx];
    setRows(cloneRows);
  };

  const columns: Array<IPropsColumn> = [
    {
      id: "toggle",
      name: "Toggle",
      type: GridType.Toggle,
      callback: handleToggle,
    },
  ];

  return <Grid id={"toggle"} columns={columns} rows={rows} />;
};

export default ToggleTypeComponent;

License

MIT

1.1.0

2 months ago

1.0.15

2 months ago

1.0.9

9 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.14

7 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

0.0.84

11 months ago

0.0.83

11 months ago

0.0.80

11 months ago

0.0.82

11 months ago

0.0.76

11 months ago

0.0.77

11 months ago

0.0.78

11 months ago

0.0.79

11 months ago

0.0.74

11 months ago

0.0.75

11 months ago

0.0.70

11 months ago

0.0.71

11 months ago

0.0.72

11 months ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.47

1 year ago

0.0.62

12 months ago

0.0.63

12 months ago

0.0.64

12 months ago

0.0.65

12 months ago

0.0.66

12 months ago

0.0.67

12 months ago

0.0.68

12 months ago

0.0.69

12 months ago

0.0.60

12 months ago

0.0.61

12 months ago

0.0.59

12 months ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

12 months ago

0.0.56

12 months ago

0.0.57

12 months ago

0.0.58

12 months ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.40

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago