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

v0.1.3

Published

Relieving the pain of morphing UIs.

Downloads

3

Readme

react-morphine

Relieving the pain of morphing UIs in React.

Travis-CI

Contents

Summary

React-morphine uses React-motion and SVG to help you draw shapes which can morph. More precisely, it allows you to reposition points within the SVG Path definition.

Description

React-morpphine defines an SVGPath component class which has a series of required props to making a morphine UI. It's designed to be used to draw a shape using an SVG path. However, the trick is that instead of defining the path as a static string, we define it as a function that takes a parameter of the current spring state.

Think of it as React-motion's interpolatedValues but applied to a shape definition.

All you have to do create the states you want to animate between, define the shape using a function and the library does the rest.

See detailed Card example.

Guide

Just a quick guide for now. I'll write-up a better description soon. For now, follow the guide below and check out the example.

1. Installation

React-morphine is available on npm or bower:

npm install react-mophine --save
bower install react-mophine

2. Define your shape

Use whatever drawing package you want. I used Sketch.

Warning: it helps to tidy-up SVGs first so that you don't go insane later on.

Here's some great tips I found: Optimising SVGs for the Web – part 1 & part 2

The key is to note the d attribute of the path node. you're going to use this to describe how the path changes using React-motions spring mechanics.

3. Define your component

See example Card component but in summary:

class Card extends Component {

  constructor(props) {
    super(props);
    this.state = {
      isHovering: false
    };
  }

  onEnter() {
    this.setState({
      isHovering: true
    });
  }

  onLeave() {
    this.setState({
      isHovering: false
    });
  }

  render() {
    const {isHovering} = this.state;

    const destination = isHovering ? SECONDARY : DEFAULT;

    return (
      <div className="Card"
           onMouseEnter={this.onEnter.bind(this)}
           onMouseLeave={this.onLeave.bind(this)}>
        <SVGPath defaultStyle={ DEFAULT }
                 style={{
                   tr: spring(destination.tr, presets.wobbly),
                   tl: spring(destination.tl, presets.wobbly)
                 }}
                 width={500}
                 height={300}
                 path={(delta) => `M0,${delta.tl} L220,${delta.tr} L220,300 L0,300 Z`}/>
      </div>
    );
  }
}

See the path prop passed to the SVGPath component? It's a function that defines how the path changes based on the spring values by returning a string.

The path prop function is passed a single argument that describes the current state of all the springs. You can define as many parameters as you want off the back of it. I defined tr and tl to represent the rightmost and leftmost points of the SVG definition.

Tips

It's a pain getting the SVG path

Tell me about it. The SVG spec is pretty straightforward but just play around with your path prop until it draws what you're expecting.

I found it useful to return a constant string (ignoring the delta param) until I need which point I wanted to change.

Would be great to have tools to help us with this in the future. Bear with us.

It's still too low level

I know what you mean. I like the power we have with this API, but I'm thinking of ways which are slightly more how designers think.

Contributing