@kennethormandy/react-flipcard

0.4.3 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @kennethormandy/react-flipcard

Weekly Downloads

90

Version

0.4.3

License

none

Unpacked Size

1.09 MB

Total Files

16

Last publish

Collaborators

  • kennethormandy