1.0.2 • Published 2 years ago

simple-react-grid-board v1.0.2

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

API

Simple and easy!

Type Declaration

interface Item {
  id: string;
  x: number;
  y: number;
  w: number;
  h: number;
  render?: (item: IGridItem, placeholder: TPlaceholder) => React.ReactNode;
}

interface GBProps {
  col: number;
  row: number;
  width: number;
  height: number;
  items: Item[];
  boardClassName?: string;
  itemClassName?: string;
  phClassName?: string;
}

Board Props

propstypeexplain
colnumbercolumns of the board
rownumberrows of the board
widthnumberwidth of the board
heightnumberheight of the board
itemsItemthe items
boardClassName?stringboard class
itemClassName?stringitem class
phClassName?stringplaceholder class

Item Props

propstypeexplain
idstringkey of the item
xnumberX coordinate of the item, range 0 - col
ynumberY coordinate of the item range 0 - row
wnumberwidth of the item, range 1 - col
hnumberheight of the item ,range 1 - row
render?(item, placeholder) => ReactNodethe element children of the item

Demo

import React from 'react';
import GridBoard from 'simple-grid-board';

export default () => (
  <GridBoard
    col={6}
    row={6}
    width={600}
    height={500}
    items={[
      {
        id: 'a',
        x: 0,
        y: 0,
        w: 2,
        h: 1,
        render() {
          return <div>AAAA</div>;
        },
      },
      {
        id: 'b',
        x: 0,
        y: 1,
        w: 1,
        h: 1,
        render() {
          return <div>BBBB</div>;
        },
      },
      { id: 'd', x: 1, y: 1, w: 2, h: 2 },
      { id: 'c', x: 2, y: 0, w: 2, h: 1 },
      { id: 'e', x: 3, y: 3, w: 3, h: 3 },
      { id: 'f', x: 1, y: 3, w: 2, h: 1 },
      { id: 'h', x: 1, y: 5, w: 1, h: 1 },
      { id: 'i', x: 0, y: 2, w: 1, h: 1 },
      { id: 'j', x: 0, y: 3, w: 1, h: 1 },
      { id: 'k', x: 0, y: 4, w: 1, h: 1 },
      { id: 'z', x: 4, y: 0, w: 2, h: 2 },
      { id: 'y', x: 3, y: 1, w: 1, h: 2 },
    ]}
  />
);

for more demo: see DEMO