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

rectangle-composer

v0.0.3

Published

A React component for visual editing rectangles in 2D plane

Downloads

11

Readme

Rectangle composer

Dependencies Status Dev Dependencies Status Peer Dependencies Status

Build Status codecov

A React component for visual editing rectangles in 2D plane

Installation

YARN:

yarn add rectangle-composer konva react-konva styled-components

NPM:

npm install rectangle-composer konva react-konva styled-components

konva, react-konva and styled-components are peer dependencies

Usage

Basic:

Import Composer component from rectangle-composer for basic usage

Pass initial array of rects and some styling:

import React from 'react';
import Composer from rectangle-composer;

export const MyComponent = () => {
  const containerStyles = 'display: flex;';
  const panelStyles = 'width: 30%; overflow: auto;';
  const wrapperStyles = 'background-color: #C0D6DF; width: 70%; height: 400px;';
  const gridStyles = 'background-color: #B8BBAA;';
  const [initialBlocks, setInitialBlocks] = useState([
    { top: 10, bottom: 50, left: 100, right: 200, fill: 'blue' },
    { top: 60, bottom: 120, left: 0, right: 390, fill: 'red' },
    { top: 150, bottom: 200, left: 100, right: 200, fill: 'green' },
  ]);

  return (
    <div className="container">
      <style>
        {`.container {${containerStyles}}`}
        {`.panel {${panelStyles}}`}
        {`.composer.composer {${wrapperStyles}}`}
        {`.composer .grid {${gridStyles}}`}
      </style>
      <div className="panel">
        * Click on empty space to create rectangle.
        <br />
        * Click on existing rectangle to edit.
        <br />
        * All relative units passed to Composer is recalculated responsively to grid size.
        <br />
        Boxes:
        <br />
        {initialBlocks.map(JSON.stringify)}
      </div>
      <Composer
        initialRectangles={initialBlocks}
        relativeWidth={400}
        relativeHeight={400}
        wrapperClassName="composer"
        gridClassName="grid"
        onChange={setInitialBlocks}
        newRectangleProps={{
          width:  50,
          height: 50,
          fill: '#000000',
        }}
      />
    </div>
  );
};

Advanced:

Composer component is basically wrapping some Field, Rectangle and EditedRectangle into single stateful component.

You can use any react-konva components in combination with Field, Rectangle, EditedRectangle to customize expected behavior or styles.

For intersection check you can import getBoundBoxFunc and getDragBoundFunc into your app.

See Storybook and source code for more info.

Issues, PR and discussions are welcome!

Demo & docs

Storybook with use cases and prop descriptions

Codesandbox with basic usage

Boilerplate used

React Rollup Boilerplate