Created
March 4, 2020 21:51
-
-
Save acobster/70483f4624b6340ae24cdfef6206d761 to your computer and use it in GitHub Desktop.
Reagent animations with framer-motion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.motion | |
(:require | |
[framer-motion :refer (motion AnimatePresence useSpring useMotionValue useTransform useViewportScroll) :as motion] | |
[cljs-bean.core :refer [bean ->clj ->js]])) | |
(def div | |
(.-div motion)) | |
(def span | |
(.-span motion)) | |
(def li | |
(.-li motion)) | |
(def img | |
(.-img motion)) | |
(def button | |
(.-button motion)) | |
(def input | |
(.-input motion)) | |
(def textarea | |
(.-textarea motion)) | |
(def label | |
(.-label motion)) | |
(def transform #(motion/transform (->js %1) (->js %2) (->js %3))) | |
(def animate-presence AnimatePresence) | |
(def use-spring useSpring) | |
(def use-motion-value useMotionValue) | |
(def use-transform useTransform) | |
(def use-viewport-scroll useViewportScroll) | |
(def spring | |
{:type :spring | |
:damping 1000 | |
:stiffness 10700}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.core | |
(:require [cljs-bean.core :refer [bean ->clj ->js]] | |
[re-frame.core :refer [dispatch subscribe]] | |
[app.motion :as motion] | |
[herb.core :refer [<class]]) | |
(defn page | |
[id content] | |
[:> motion/div | |
{:key (str "page" id) ; IMPORTANT UNIQUE ID 8 | |
:class [:page (<class styles/page)] | |
:variants {:initial {:opacity 0} | |
:animate {:opacity 1} | |
:exit {:opacity 0}} | |
:initial :initial | |
:animate :animate | |
:exit :exit | |
content}]) | |
(defn pages | |
[] | |
(let [page @(subscribe [:page/current])] | |
[:> motion/animate-presence | |
(case page | |
:page-1 [page :page-1 [page1]] | |
:page-2 [page :page- ...] | |
...)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment