|
1 | 1 | # react-card-flipper |
2 | | -A React card flipper component. |
| 2 | +[](https://travis-ci.org/factor1/react-card-flipper) |
| 3 | +[](https://badge.fury.io/js/react-card-flipper) |
| 4 | + |
| 5 | + |
3 | 6 |
|
4 | | -## Installation |
| 7 | + |
| 8 | +A React card flipper component (built with React `16.2.0`) that can be triggered by hover or click. Inspired |
| 9 | +from [David Walsh's great tutorial](https://davidwalsh.name/css-flip). |
| 10 | + |
| 11 | +## Installation |
| 12 | +### Yarn: |
5 | 13 | `yarn add react-card-flipper` |
| 14 | + |
| 15 | +### npm: |
| 16 | +`npm install react-card-flipper --save` |
| 17 | + |
| 18 | +## Current Browser Support |
| 19 | +Initial testing via BrowserStack of a React app that simply renders the card |
| 20 | +component. |
| 21 | + |
| 22 | +| Browser | Support | Notes | |
| 23 | +| ---------------- |:--:| ------ | |
| 24 | +| Chrome >= 38 | ✅ | | |
| 25 | +| Edge >= 14 | ✅ | | |
| 26 | +| Firefox >= 16 | ✅ | | |
| 27 | +| IE 11-10 | ⚠️ | Card flips have no animation | |
| 28 | +| IE 9.0 | ❌ | No toggling of cards | |
| 29 | +| Opera >= 30 | ✅ | | |
| 30 | +| Safari >= 6.2.8 | ✅ | | |
| 31 | +| Safari 6.0.5 | ⚠️ | Card flips have no animation | |
| 32 | + |
| 33 | + |
| 34 | +## Getting Started |
| 35 | +You can import react-card-flipper into your React app. The following is a bare |
| 36 | +bones example. |
| 37 | + |
| 38 | +> **Important:** The `<ReactCardFlipper>` component must have two `<div>` elements, one for the front and one for the back. |
| 39 | +
|
| 40 | +```js |
| 41 | +import React from 'react'; |
| 42 | +import ReactDOM from 'react-dom'; |
| 43 | +import ReactCardFlipper from 'react-card-flipper'; |
| 44 | + |
| 45 | +ReactDOM.render( |
| 46 | + <div> |
| 47 | + <ReactCardFlipper> |
| 48 | + <div> |
| 49 | + The cards front content goes here. |
| 50 | + </div> |
| 51 | + <div> |
| 52 | + The cards back content goes here. |
| 53 | + </div> |
| 54 | + </ReactCardFlipper> |
| 55 | + </div>, |
| 56 | + document.getElementById('root') |
| 57 | +); |
| 58 | +``` |
| 59 | + |
| 60 | +## Props and Options |
| 61 | +The `ReactCardFlipper` component has 4 props it accepts that you can use to adjust |
| 62 | +how your card behaves. |
| 63 | + |
| 64 | +| Prop / Option | Accepted Prop(s) | Default | Description | |
| 65 | +| ------------- |:---------------------------:|:-------:| ----------- | |
| 66 | +| `width` | String (ex: `300px`) | `auto` | Card width. | |
| 67 | +| `height` | String (ex: `600px`) | `auto` | Card height. | |
| 68 | +| `behavior` | String (`click` or `hover`) | `click` | If the card should click to flip, or hover to flip. | |
| 69 | +| `levitate` | Boolean | `false` | If the card should "levitate" up on hover. Only applied when `behavior` is `click`. | |
| 70 | + |
| 71 | +#### Example: |
| 72 | +```js |
| 73 | +render() { |
| 74 | + return( |
| 75 | + <div> |
| 76 | + <ReactCardFlipper width="300px" height="550px" behavior="click" levitate={true}> |
| 77 | + <div> |
| 78 | + <h3>Click me to learn more</h3> |
| 79 | + </div> |
| 80 | + <div> |
| 81 | + <p>You Clicked!</p> |
| 82 | + </div> |
| 83 | + </ReactCardFlipper> |
| 84 | + </div> |
| 85 | + ) |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## Styling |
| 90 | +Out of the box we provide very little styling aside from core styles like transitions |
| 91 | +to let you shape the design as you see fit. All of the css classes provided for are |
| 92 | +prefixed with `rcf-` to avoid any conflicts with existing classes. In most cases you'll |
| 93 | +only be adding styles to `.rcf-front` & `.rcf-back`. All classes available for styling are: |
| 94 | + |
| 95 | +- `rcf-container` - main container for the component |
| 96 | +- `rcf-front` - front card styling |
| 97 | +- `rcf-back` - back card styling |
| 98 | +- `rcf-flipper` - "flipper" container, controls animation speed, etc. |
| 99 | + |
| 100 | +## Development |
| 101 | +To get started developing on this project, fork or clone the repo. Then run `yarn install` |
| 102 | + |
| 103 | +#### Start the development server |
| 104 | +##### `yarn start` |
| 105 | +Starts the development/test server and polls for changes. |
| 106 | + |
| 107 | +#### Running EsLint |
| 108 | +##### `yarn lint` |
| 109 | +Lints `ReactCardFlipper.js` and outputs any warnings or errors. |
| 110 | + |
| 111 | +#### Running Tests |
| 112 | +##### `yarn test` |
| 113 | +Runs EsLint, and builds the test output. |
| 114 | + |
| 115 | +#### Running Test Build |
| 116 | +##### `yarn build` |
| 117 | +Compiles a new test build. |
0 commit comments