https://github.com/kennethormandy/react-flipcard
A flippable card, with almost no opinions on styling.
https://github.com/kennethormandy/react-flipcard
react
Last synced: over 1 year ago
JSON representation
A flippable card, with almost no opinions on styling.
- Host: GitHub
- URL: https://github.com/kennethormandy/react-flipcard
- Owner: kennethormandy
- License: mit
- Created: 2018-02-14T06:29:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T17:01:59.000Z (about 4 years ago)
- Last Synced: 2025-03-25T02:40:17.544Z (over 1 year ago)
- Topics: react
- Language: JavaScript
- Homepage: http://react-flipcard.kennethormandy.com/
- Size: 343 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Flipcard
Another React Flipcard, based on [@mzabriskie](https://github.com/mzabriskie)’s [react-flipcard](https://github.com/mzabriskie/react-flipcard), but with support for React v16, and some other considerations for the [Mort Modern](http://mort-modern.losttype.com/) type specimen site.
## Installation
```sh
npm install --save @kennethormandy/react-flipcard
```
## Example
```jsx
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 (
this.setState({ flipped: !this.state.flipped })}>
Flip
One
Two
)
}
}
render(, document.getElementById('target'))
```
### Transition Type
#### Horizontal
```jsx
One
Two
```
#### Revolving Door
```jsx
One
Two
```
### Conditional two-column example

Like in the [Mort Modern](http://mort-modern.losttype.com/) 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).
```jsx
Column 1
The main column on small viewports.
Column 2
Flip to see me on smaller viewports.
```
Within your CSS, you might do something like this:
```css
/* 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`:
```js
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:
```js
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
* [react-flipcard](https://github.com/mzabriskie/react-flipcard) by [@mzabriskie](https://github.com/mzabriskie)
* [react-card-flip](https://github.com/AaronCCWong/react-card-flip) by [@AaronCCWong](https://github.com/AaronCCWong), for the revolving-door transition
* [Create a CSS Flipping Animation](https://davidwalsh.name/css-flip) by David Walsh
## License
[The MIT License (MIT)](LICENSE.md)
Copyright © 2017–2018 [Kenneth Ormandy Inc.](https://kennethormandy.com)