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-kinetic

v0.3.0

Published

Using KineticJS library with React

Downloads

38

Readme

react-kinetic

Build status

KineticJS canvas library using React components.

Click on rectangles at http://freiksenet.github.io/react-kinetic/. A more elaborate example at https://github.com/freiksenet/react-kinetic-asteroids.

An attempt to make React work with the KineticJS HTML5 canvas library. The goal is to have similar declarative markup as normal React and to have similar data-flow model.

Currently you can use all Kinetic components as React components and all Kinetic events are supported on them in same way as normal browser events are supported.

You can even inspect the components in React dev tools.

Installation

If you use browserify or webpack

npm install react kinetic react-kinetic

Then just require it

require('react-kinetic');

If you use require.js or want to use it standalone, then standalone version is available in Releases.

If you want to build from source

git clone https://github.com/freiksenet/react-kinetic.git
cd react-kinetic
npm run umd

build/react-kinetic.js will be a standalone dist, you can require react and react-kinetic from there. ReactKinetic Note that in all cases you need to have react and kinetic available, so have them included in <script> tag (or available to RequireJS if you use AMD).

User guide

Minimal example:

/** @jsx React.DOM */

var React = require('react');
var ReactKinetic = require('react-kinetic');

var TestingComponent = React.createClass({
  render: function () {
    return (
      <ReactKinetic.Stage height={300} width={300}>
        <ReactKinetic.Layer>
          <ReactKinetic.Rect x={100} y={100} width={50} height={50} fill="black" />
        </ReactKinetic.Layer>
      </ReactKinetic.Stage>
    );
  }
});

React.renderComponent(
  <TestingComponent />,
  document.body
);

All react-kinetic components correspond to KineticJS components of the same name. All the parameters available for Kinetic objects are valid props for corresponding react-kinetic components, unless otherwise noted.

Every react-kinetic component (or components that use react-kinetic components) must be wrappe in Stage. Stage is the only react-kinetic element that has actual DOM representation. Unlike Kinetic.Stage, Stage will ignore container passed to it, because it constructs container by itself.

Stage's only valid children are Layer components. Layers are currently only components that handle redrawing and currently they redraw on all changes of props or children.

Layers can have all the other react-kinetic components inside. The supported elements are: Container, Layer, Group, Label, Shape, Rect, Circle, Ellipse, Ring, Wedge, Arc, Image, Text, Line, Sprite, Path, TextPath, RegularPolygon, Star and Tag. See KineticJS API docs for valid props.

Currently there is no API to add react-kinetic components for custom KineticJS nodes, but I'm planning to add it in the future. See KineticComponent.js and KineticFactory.js.

Events

react-kinetic supports all KineticJS events. The names are done 'react-style', so onCamelCased. Full mapping:

var KineticEvents = {
  onMouseOver: "mouseover",
  onMouseOut: "mouseout",
  onMouseEnter: "mouseenter",
  onMouseLeave: "mouseleave",
  onMouseMove: "mousemove",
  onMouseDown: "mousedown",
  onMouseUp: "mouseup",
  onClick: "click",
  onDblClick: "dblclick",
  onDragStar: "dragstart",
  onDragEnd: "dragend",
  onTouchStart: "touchstart",
  onTouchMove: "touchmove",
  onTouchEnd: "touchend",
  onTap: "tap",
  onDblTap: "dbltap",
  onDragMove: "dragmove"
};

Events work in similar way as they work in normal React. See demo/rectangles.js for examples.

Internally, events use the .react namespace for Kinetic events, so this namespace shouldn't be used if you manually bind events, e.g. in componentDidMount.

Some internals

To get raw Kinetic node object, use the getKineticNode method which all react-kinetic components have.