Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-konva-grid

Package Overview
Dependencies
Maintainers
1
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-konva-grid

Canvas grid to render large set of tabular data with virtualization.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
288
decreased by-53.32%
Maintainers
1
Weekly downloads
 
Created
Source

Declarative Canvas Grid with React Konva

Canvas grid to render large set of tabular data. Uses virtualization similar to react-window

Demo

Features

  • :electron: React powered declarative library
  • :100: Virtualized: Only visible cells are rendered
  • :bulb: Peformant: Canvas implementation with no DOM nodes
  • :scroll: Supports scrolling using native scrollbars
  • :computer: Supports both Fixed and Variable sized grids
  • :fire: Freeze rows and columns
  • :hand: Resizable headers
  • :hammer_and_wrench: Fully typed API written in TypeScript
  • :muscle: Highly customizable using react-konva

Why another canvas grid library

Born out of frustration at work, having to deal with complicated imperative canvas libraries, I wanted to create something easy to understand and declarative in nature. React-Konva uses React's custom renderer to expose konva components.

Installation

npm
yarn add react-konva-grid
yarn
npm install react-konva-grid --save

Compatiblity

Konva grid will work with any browser that supports react, konva and canvas element.

Usage

import { Grid } from 'react-konva-grid'
import { Group, Text, Rect } from 'react-konva'

const App = () => {
  const Cell = ({ rowIndex, columnIndex, x, y, width, height}) => {
    return (
      <Group>
        <Rect
          x={x}
          y={y}
          height={height}
          width={width}
          fill="white"
          stroke="grey"
        />
        <Text
          x={x}
          y={y}
          height={height}
          width={width}
          text={text}
          verticalAlign="middle"
          align="center"
        />
      </Group>
    )
  }

  return (
    <Grid
      rowCount={100}
      columnCount={100}
      width={800}
      height={800}
      rowHeight={(rowIndex) => 20}
      columnWidth={(columnIndex) => 100}
      itemRenderer={Cell}
    />
  )
}

Props

This is the list of props that are meant to be used to customise the konva-grid behavior.

NameRequiredTypeDescriptionDefault
widthtruenumberWidth of the grid container800
heighttruenumberHeight of the grid container800
columnCounttruenumberNo of columns in the grid200
rowCounttruenumberNo of rows in the grid200
rowHeighttruefunctionFunction that returns height of the row based on rowIndex(rowIndex) => 20
columnWidthtruefunctionFunction that returns width of the column based on columnIndex(columnIndex) => 100
itemRenderertrueFunctionReact component to render the cellnull
scrollbarSizefalsenumberSize of the scrollbar17
showScrollbarfalsebooleanAlways show scrollbartrue
selectionBackgroundColorfalsestringBackground color of selected cellsrgba(66, 133, 244, 0.3)
selectionBorderColorfalsestringBorder color of bounding box of selected cellsrgba(66, 133, 244, 1)
selectionsfalseArrayArray of selected cell areas[]
frozenRowsfalsenumberNo of frozen rows0
frozenColumnsfalsenumberNo of frozen columns0

Methods

scrollTo({ scrollLeft, scrollTop }

Scrolls the grid to a specified x,y position relative to the container

resetAfterIndices({ rowIndex, columnIndex })

Imperatively trigger re-render of the grid after specified rowIndex or columnIndex

Storybook

Examples can be found as stories in Grid.stories.tsx. To run storybook, enter the following commands

yarn
yarn run storybook

Screenshot

Contribution

Feel free to fork and submit pull requests

git clone https://github.com/rmdort/konva-grid.git
cd konva-grid
yarn
// Run storybook
yarn storybook 

FAQs

Package last updated on 25 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc