UNPKG

react-reveal

Version:

Really simple way to add reveal on scroll animation to your React app.

63 lines (49 loc) 1.37 kB
/* * HeadShake React Component * * Copyright © Roman Nosov 2017 * Original CSS Effect - Copyright (c) 2016 Daniel Eden * * This source code is licensed under the MIT license found in the * LICENSE.txt file in the root directory of this source tree. */ import { bool, number } from 'prop-types'; import wrap from '../lib/wrap'; import { animation, defaults } from '../lib/globals'; const propTypes = { duration: number, timeout: number, delay: number, count: number, forever: bool, }; const rule = ` 0% { transform: translateX(0); } 6.5% { transform: translateX(-6px) rotateY(-9deg); } 18.5% { transform: translateX(5px) rotateY(7deg); } 31.5% { transform: translateX(-3px) rotateY(-5deg); } 43.5% { transform: translateX(2px) rotateY(3deg); } 50% { transform: translateX(0); } `; let name = false; function make() { return name || (name = animation(rule)); } function HeadShake({ children, out, timeout, duration = defaults.duration, delay = defaults.delay, count = defaults.count, forever, ...props } = defaults) { const effect = { make, duration: timeout === undefined ? duration : timeout, delay, forever, count, style: { animationFillMode: 'both', } }; return wrap(props, effect, false, children, true); } HeadShake.propTypes = propTypes; export default HeadShake;