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-flop-card

v0.3.2

Published

Card component with flip animation implement in React Motion

Downloads

11

Readme

React Flop Card

Yet another React flip card component. Animation was done with React-Motion instead of CSS transition.

import { FlipCard } from 'react-flop-card';
// in your render
<FlipCard
  flipped={ true } onClick={ onClick }
  onMouseOut={ onMouseOut } onMouseOver={ onMouseOver }
  frontChild={ frontChild } backChild={ backChild }
  width={ 100 } height={ 100 }
  style={ { frontStyle, backStyle, wrapperStyle } }/>

Install

npm install --save react-flop-card

Demo

http://pckhoi.github.io/react-flop-card-demo.html

Code from the above demo:

import React, { Component } from 'react';

import { FlipCard } from 'react-flop-card';


export default class Demo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      flippedKey: null
    };
    this.cards = Array.apply(null, {length: 64}).map((val, ind) => ({
      key: String(ind),
      style: {
        front: this.getFrontStyle(ind),
        back: backStyle,
        wrapper: wrapperStyle
      },
      frontChild: (<noscript/>),
      backChild: (<p style={ letterStyle }>{ randomLetter() }</p>),
      onMouseOver: () => { this.setState({ flippedKey: String(ind) }); },
      onMouseOut: () => { this.setState({ flippedKey: null }); }
    }));
  }

  getFrontStyle(ind) {
    const y = (ind - ind % 8) / 8 * -104;
    const x = ind % 8 * -104 -300;
    const backgroundStyle = `url("img/food-dinner-lemon-rice.jpg") ${x}px ${y}px/auto`;
    return {
      background: backgroundStyle,
      borderRadius: '20px'
    };
  }

  render() {
    return (
      <div style={ containerStyle }>
        { this.cards.map(({
          key, frontChild, backChild, onMouseOver, onMouseOut, style
        }) => (

          <FlipCard
            key={ key }
            flipped={ this.state.flippedKey === key }
            onMouseOut={ onMouseOut } onMouseOver={ onMouseOver }
            frontChild={ frontChild } backChild={ backChild }
            width={ 100 } height={ 100 } style={ style }/>

        )) }
      </div>
    );
  }
}

const backStyle = {
  backgroundColor: 'green',
  borderRadius: '20px'
};

const letterStyle = {
  color: 'white',
  fontSize: '40px',
  margin: '28px 0',
  textAlign: 'center',
  fontFamily: 'sans-serif'
};

const containerStyle = {
  fontSize: 0,
  width: '832px',
  margin: '0 auto'
};

const wrapperStyle = {
  display: 'inline-block',
  margin: '2px'
};

function randomLetter() {
  const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return possible.charAt(
    Math.floor(Math.random() * possible.length)
  );
}

API

exports

  • FlipCard
  • RotateCard

<FlipCard/>

Usage

<FlipCard
  flipped={ true } onClick={ onClick }
  onMouseOut={ onMouseOut } onMouseOver={ onMouseOver }
  frontChild={ frontChild } backChild={ backChild }
  width={ 100 } height={ 100 }
  style={ { front, back, wrapper } }/>

Props

All props are optional.

  • flipped: boolean

Control whether the card will show (or animate toward) front side or back side.

  • onClick: function

Trigger when clicked on.

  • onMouseOut: function

Trigger when no longer hovered.

  • onMouseOver: function

Trigger when hovered.

  • frontChild: React element

The element to display in the front of card.

  • backChild: React element

The element to display in the back of card.

  • width: number or string

If width is given as number, it will be automatically converted to px. If you want to use units other than px, supply a string instead. If not given then width will not be set (no default value).

  • height: number

Same as width.

  • style: object
    • style.front: object - style that apply to wrapper of frontChild.
    • style.back: object - style that apply to wrapper of backChild.
    • style.wrapper: object - style that apply to outer wrapper.

<RotateCard/>

This is a low level component with no animation. The plus side is that you can easily control it's rotate angle with degree prop.

Usage

<RotateCard
  degree={ 180 } onClick={ onClick }
  onMouseOut={ onMouseOut } onMouseOver={ onMouseOver }
  frontChild={ frontChild } backChild={ backChild }
  width={ 100 } height={ 100 }
  style={ { front, back, wrapper } }/>

Props

Same as FlipCard except it doesn't have flipped prop. Instead it has degree prop.

  • degree: number
    • degree={ 0 } is the same as flipped={ false } whereas degree={ 180 } is the same as flipped={ true }.

License

MIT