From 8c1c9ed59aa58a849a3de0371787747967c18f88 Mon Sep 17 00:00:00 2001 From: Mutesa-Cedric Date: Tue, 26 Sep 2023 09:44:29 +0200 Subject: [PATCH] feat(animations) : jump animations --- src/HOC/wrapper.tsx | 2 +- src/animations/simple/Jump.ts | 38 +++++++++++++++++++++++++++++++++++ src/lib/defaultConfigs.ts | 7 ++++++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/animations/simple/Jump.ts diff --git a/src/HOC/wrapper.tsx b/src/HOC/wrapper.tsx index da95dfa..fe8b17d 100644 --- a/src/HOC/wrapper.tsx +++ b/src/HOC/wrapper.tsx @@ -13,7 +13,7 @@ import RevealBase from '../lib/Base.js' * @param {React.ReactNode} children * @returns {React.ReactNode} */ -export default function wrapper(props: { when: any; in: any }, inEffect: any, outEffect: any, children: string | number | boolean | +export default function wrapper(props: { when: any; in: any, }, inEffect: any, outEffect: any, children: string | number | boolean | React.ReactElement> | Iterable | null | undefined) { if ('in' in props) props.when = props.in diff --git a/src/animations/simple/Jump.ts b/src/animations/simple/Jump.ts new file mode 100644 index 0000000..20ed8c6 --- /dev/null +++ b/src/animations/simple/Jump.ts @@ -0,0 +1,38 @@ +import wrapper from '@/HOC/wrapper'; +import { animation, defaults } from '@/lib/defaultConfigs'; + + +const rule = ` + from, 20%, 53%, 80%, to { + animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000); + transform: translate3d(0,0,0); + } + + 40%, 43% { + animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); + transform: translate3d(0, -30px, 0); + } + + 70% { + animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060); + transform: translate3d(0, -15px, 0); + } + + 90% { + transform: translate3d(0, -4px, 0); +} +`; + +let name: string | undefined; +function make() { + return name || (name = animation(rule)); +} + + +function Jump({ 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', } }; + // @ts-expect-error(some props are not allowed, this will be fixed later) + return wrapper(props, effect, false, children); +} + +export default Jump; diff --git a/src/lib/defaultConfigs.ts b/src/lib/defaultConfigs.ts index cce9165..3a2719d 100644 --- a/src/lib/defaultConfigs.ts +++ b/src/lib/defaultConfigs.ts @@ -23,7 +23,12 @@ export const namespace = 'react-swiftreveal' // default values -export const defaults = { duration: 1000, delay: 0, count: 1 } +export const defaults: { + duration: number; + delay: number; + count: number; + [key: string]: any; +} = { duration: 1000, delay: 0, count: 1 } export let ssr = true export let observerMode = false export let raf: WindowRequestAnimationFrame = cb => setTimeout(cb, 66)