Git Product home page Git Product logo

react-flipcard's Introduction

Flipcard

Another React Flipcard, based on @mzabriskie’s react-flipcard, but with support for React v16, and some other considerations for the Mort Modern type specimen site.

Installation

npm install --save @kennethormandy/react-flipcard

Example

import React from 'react'
import { render } from 'react-dom'
import Flipcard from '@kennethormandy/react-flipcard'

// Import minimal required styles however you’d like
import '@kennethormandy/react-flipcard/dist/Flipcard.css'

class App extends React.Component {
  constructor() {
    super()

    this.state = {
      flipped: false,
    }
  }

  render() {
    return (
      <div>
        <button onClick={e => this.setState({ flipped: !this.state.flipped })}>
          Flip
        </button>
        <Flipcard flipped={this.state.flipped}>
          <h1>One</h1>
          <h1>Two</h1>
        </Flipcard>
      </div>
    )
  }
}

render(<App />, document.getElementById('target'))

Transition Type

Horizontal

<Flipcard type="horizontal">
  <h1>One</h1>
  <h1>Two</h1>
</Flipcard>

Revolving Door

<Flipcard type="revolving-door">
  <h1>One</h1>
  <h1>Two</h1>
</Flipcard>

Conditional two-column example

Gif showing the two-column layout turning into a Flipcard below a certain breakpoint.

Like in the Mort Modern type specimen site, it’s possible to change or disable the minimal Flipcard styles at certain breakpoints. This can be done entirely through CSS, but you might also want to use matchMedia to change some other part of your user interface (ex. disabling the button).

<Flipcard>
  <Card>
    <div>
      <h2>Column 1</h2>
      <p>The main column on small viewports.</p>
    </div>
  </Card>
  <Card>
    <div>
      <h2>Column 2</h2>
      <p>Flip to see me on smaller viewports.</p>
    </div>
  </Card>
</Flipcard>

Within your CSS, you might do something like this:

/* If the viewport is wide enough: */
@media (min-width: 750px) {

  /* Use the flipper as a Flexbox container: */
  .Flipcard-flipper {
    display: flex;
    transform: none !important;
  }

  /* Show both cards and remove the transitions: */
  .Flipcard-front, 
  .Flipcard-back {
    position: relative;
    transform: none !important;
    opacity: 1 !important;
  }
}

Importing styles

People have a lot of different opinions about how to manage styles alongside React. The guideline I have decided to follow is that my approach should work with a fresh Create React App setup, and not impose another dependency.

If you’d like the styles already minified and autoprefixed, import the CSS from dist:

import '@kennethormandy/react-flipcard/dist/Flipcard.css'

If you’re already running things through your own CSS build process that’s going to do those things anyway, you might want to import the styles from src instead. Then, the source maps will map back to your CSS before minification, too:

import '@kennethormandy/react-flipcard/src/Flipcard.css'

You can also path to these files from Sass, PostCSS, or another CSS build process. The styles are also quite minimal and you might want to change them, so there’s nothing wrong with copying and building on the CSS partial yourself rather than using the provided styles directly.

Credits

License

The MIT License (MIT)

Copyright © 2017–2018 Kenneth Ormandy Inc.

react-flipcard's People

Contributors

kennethormandy avatar

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.