Code Monkey home page Code Monkey logo

react-flipcard's Introduction

#react-flipcard

React flip card component

Installing

$ npm install react-flipcard
# or
$ bower install react-flipcard

Demo

http://mzabriskie.github.io/react-flipcard/basic

Example

import React from 'react';
import FlipCard from 'react-flipcard';

var App = React.createClass({
  getInitialState() {
    return {
      isFlipped: false
    };
  },

  showBack() {
    this.setState({
      isFlipped: true
    });
  },

  showFront() {
    this.setState({
      isFlipped: false
    });
  },

  handleOnFlip(flipped) {
    if (flipped) {
      this.refs.backButton.getDOMNode().focus();
    }
  },

  handleKeyDown(e) {
    if (this.state.isFlipped && e.keyCode === 27) {
      this.showFront();
    }
  },

  render() {
    return (
      <div>
        {/* Default behavior is horizontal flip on hover, or focus */}
        <FlipCard>
          {/* The first child is used as the front of the card */}
          <div>
            <div>Front</div>
            <div><small>(horizontal flip)</small></div>
          </div>
          {/* The second child is used as the back of the card */}
          <div>Back</div>
        </FlipCard>

        {/* The `type` attribute allows using a vertical flip */}
        <FlipCard type="vertical">
          <div>
            <div>Front</div>
            <div><small>(vertical flip)</small></div>
          </div>
          <div>Back</div>
        </FlipCard>

        {/*
          The `disabled` attribute allows turning off the auto-flip
          on hover, or focus. This allows manual control over flipping.

          The `flipped` attribute indicates whether to show the front,
          or the back, with `true` meaning show the back.
        */}
        <FlipCard
          disabled={true}
          flipped={this.state.isFlipped}
          onFlip={this.handleOnFlip}
          onKeyDown={this.handleKeyDown}
        >
          <div>
            <div>Front</div>
            <button type="button" onClick={this.showBack}>Show back</button>
            <div><small>(manual flip)</small></div>
          </div>
          <div>
            <div>Back</div>
            <button type="button" ref="backButton" onClick={this.showFront}>Show front</button>
          </div>
        </FlipCard>
      </div>
    );
  }
});

React.render(<App/>, document.getElementById('container'));

Credits

This component is largely a React wrapper for CSS created by David Walsh.

License

MIT

react-flipcard's People

Contributors

mzabriskie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-flipcard's Issues

Add option to not focus after flip

Hi, I was glad to find this component, it's pretty sweet - thanks!
I'd like to add the option to avoid focusing after flipping.
I will gladly work on a PR for this if this is something you may be interested in merging.

P.S.
Here's my use case:
I'm using the flip card show a placeholder image until all my data is ready. When the data is ready, I flip the card to reveal the final image. So focusing on the image is not a desired effect here.

Modify the styling

Hi Matt,
Thanks for making this component. I would like to change the card styling, to make it look like Google's Material Design. I went through the code but could not find the css that directed the background color/shadow/etc... Could you point me in the right direction please?
Cheers,
Nico

Possible offset option

In our legacy code we have a flipper that I wrote but it uses an offset.

Here is an example of what it looks like.

When the card the card still flips 108 deg but it starts and ends with a set offset. I am not sure what the best solution might be as this rotation deg amount is in your styles.

Let me know your thoughts.

React 16 compatibility issues

When i import FlipCard component, it gives the following warning:-

TypeError: Cannot read property 'string' of undefined


  64010 | displayName: 'ReactFlipCard',
  64011 | 
  64012 | propTypes: {
> 64013 |   type: _react.PropTypes.string,
        |                          ^  64014 |   flipped: _react.PropTypes.bool,
  64015 |   disabled: _react.PropTypes.bool,
  64016 |   onFlip: _react.PropTypes.func,

DOMNode changes in react v.0.14.0

Hey,

In the new beta of react v.0.14.0 ReactDOM needs to be included separately. It would be awesome if you could include this too in your Flipcards.

Nice demo, but would like documentation

I really like the module, and the readme is very sharp, but reading through the examples I keep thinking "there are a lot of cool options, I want to read all about them, and make sure I dont miss any in the docs" only to find out there aren't any!

I know its nitpicking, but I think it will really help.

React 16 compatibility issues

When i import FlipCard component, it gives the following warning:-

TypeError: Cannot read property 'string' of undefined


  64010 | displayName: 'ReactFlipCard',
  64011 | 
  64012 | propTypes: {
> 64013 |   type: _react.PropTypes.string,
        |                          ^  64014 |   flipped: _react.PropTypes.bool,
  64015 |   disabled: _react.PropTypes.bool,
  64016 |   onFlip: _react.PropTypes.func,

Positioning Issues

I'm attempting to use react-flipcard using bootstrap rows and cols. Unfortunately the cards all stack on top of one another rather than the intended effect. Any insights on how I can fix this?

Updating state on unmounted component warning using React 14.6

With React version 0.14.6

I get the following warnings.

warning.js?8a56*******:45 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the ReactFlipCard component.

FlipCard.js:198 Uncaught TypeError: Cannot read property 'style' of undefined

Flip per element

Is there a way to flip a single element on a page full of flippable elements using a function?

Currently its based on the component state, I've tried adding a ref and changing the isFlipped to False, but with no luck.

Unmet peer dependency when using react 16

Hello,

I am trying to use the lib with react 16, I saw that there is a https://github.com/Dash-OS/react-flipcard-2 that should work with react 16. The thing is that it still has the same unmet peer dependency issue.

I looked at the package.json is it possible to add this or statement?

the way it is atm:
"peerDependencies": {
"react": "^0.14.0 || ^0.15.0 || ^0.16.0",
"react-dom": "^0.14.0 || ^0.15.0 || ^0.16.0"
}

Is it possible to become:
"peerDependencies": {
"react": "^0.14.0 || ^0.15.0 || ^0.16.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
"react-dom": "^0.14.0 || ^0.15.0 || ^0.16.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
}

Also are you planning to update it in the near future, so I know if I should wait for it?

React 15

I was looking through the project and didn't notice anything offhand that prevents you from bumping it to support react 15 in another release. Could always just make it a major version if needed. If you need help, I, or someone from my work team, would be happy to do the footwork.

Let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.