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-konva-portal

v1.0.10

Published

Portal API support for react-konva

Downloads

24

Readme

react-konva-portal

Portals support for react-konva

Teleport your canvas components across groups, layers and canvas elements regardless your component hierarchy. This library provides portals support for react-konva components and may facilitate in a complex canvas scene compositions.

Example projects link1, link2.

Install

yarn add react-konva-portal

IMPORTANT: Please note, this package depends on konva and react-konva packages.

Usage

Replace react-konva root component with Stage from react-konva-portal. Please use it as a drop-in replacement of the original one. It is required in order for portals to work.

Any React content inside <Portal /> will be rendered outside of its tree hierarchy.

Example

import React, { Component } from 'react';
import { Rect, Text, Layer } from 'react-konva';
import { Stage, Portal } from 'react-konva-portal';

class PortalExample extends Component {
  render() {
    return (
      <Stage width={400} height={400}>
        <Layer id="example-layer">
          <Portal>
            <Text text="This content will be rendered in a Portal (above overlay-layer)." width={400} height={400} />
          </Portal>
        </Layer>
        <Layer id="overlay-layer">
          <Rect fill="#c1f7ff" width={400} height={400} />
        </Layer>
      </Stage>
    );
  }
}

Optionally, You may refine desired render destination with containerId and zIndex.

With containerId pointing to Layer/Group component from react-konva-portal in your app tree.

You may also provide stacking order in container with zIndex property.

import React, { Component } from 'react';
import { Rect, Text } from 'react-konva';
import { Group, Stage, Portal, Layer } from 'react-konva-portal';

function Content({ text }) {
  return <Text text={text} width={400} height={400} />;
}

class TeleportExample extends Component {
  render() {
    return (
      <Stage width={400} height={400}>
        <Layer id="content-layer">
          <Portal containerId="another-layer">
            <Content text="Will be rendered as a children of <Layer id={'another-layer'} />" />
          </Portal>
          <Portal>
            <Content text="Will be rendered as a children of default portals layer in `Stage`" />
          </Portal>
          <Portal containerId="some-group" zIndex={100}>
            <Content text="Will be rendered as a children of <Group id={'some-group'} /> with specified stacking order" />
          </Portal>
          <Portal containerId="some-group">
            <Content text="Will be rendered as a children of <Group id={'some-group'} />" />
          </Portal>
        </Layer>
        <Layer id="another-layer">
          <Group id="some-group" />
        </Layer>
      </Stage>
    );
  }
}

API

This package exposes Stage, Portal, Layer and Group React components.

import { Group, Stage, Portal, Layer } from 'react-konva-portal';

Stage

Root component for working with canvas scene composition. It accepts all Konva.Stage props and forwards the original ref.

| Prop | Note | | :----------------- | :---------------------------------------------------------------------------------------------------------------------------------- | | portalLayerProps | Optional. Accepts Konva.LayerConfig and forwards it to portals containing Layer instance from react-konva. |

Portal

Special, own children teleporting component.

| Prop | Note | | :------------ | :--------------------------------------------------------------------------------------------------------------------- | | containerId | Optional. Accepts string value and should match id prop of Group or Layer in order for content to be rendered. | | zIndex | Optional. Specifies stacking order in container. | | children | Required. This property holds "travelling" content. |

Layer

Container component with portals' content hosting capabilities. It accepts all Konva.Layer props and forwards the original ref.

| Prop | Note | | :--- | :----------------------------------------------------- | | id | Required. Accepts string value and should be unique. |

Group

Container component with portals' content hosting capabilities. It accept all Konva.Node props and forwards the original ref.

| Prop | Note | | :--- | :----------------------------------------------------- | | id | Required. Accepts string value and should be unique. |

Contribute

Use the issue tracker and/or open pull requests.

License

MIT © papahigh