1.1.0 • Published 4 years ago

flip-card-react v1.1.0

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

flip-card-react

A react component to card flip

Install

npm install flip-card-react

Examples

To try the examples locally:

cd examples/
npm install
npm start

Usage

import React, { useState } from 'react';
import FlipCard from 'flip-card-react';

const cardStyle = {
    padding: 25,
    border: "solid 1px",
    borderRadius: 5,
    color: "#fff",
    width: 150
};

const App = () => {
    const [isFlipped, setFlipped] = useState(false);

    const front = (
        <div onClick={() => setFlipped(x => !x)} style={{ ...cardStyle, background: "#999" }}>
            Click to see the back
        </div>
    );

    const back = (
        <div onClick={() => setFlipped(x => !x)} style={{ ...cardStyle, background: "#444" }}>
            Click to see the front
        </div>
    );

    return (
        <div style={{padding: 5, border: "solid", position: "absolute"}}>
            <FlipCard isFlipped={isFlipped} front={front} back={back}/>
        </div>
    );
}

export default App;

Properties

PropsTypeDescriptionDefault
frontReactNodeFront face of the cardrequired
backReactNodeBack face of the cardrequired
isFlippedboolfalse: show the front of the card, true: show the back of the cardfalse
speednumberThe speed of the flip animation, the higher the slower0.6
onFlipfunctionFunction to be triggered when the card flipsundefined
verticalboolIf it exists, the card flips on vertical direction (otherwise horizontal)undefined
perspectiveboolIf it exists, the card flips with 3D animation (otherwise flat)undefined
infiniteboolIf it exists, the card always flips to right/up (otherwise toggles between directions)undefined

License

MIT