Skip to content

Instantly share code, notes, and snippets.

@shaharz
Last active September 15, 2016 08:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaharz/10740986 to your computer and use it in GitHub Desktop.
Save shaharz/10740986 to your computer and use it in GitHub Desktop.
React.js's CSSTransitionGroup in Om
(ns om-transition.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def ctg (aget js/React "addons" "CSSTransitionGroup"))
(def app-state (atom ["test"]))
(defn app [data owner]
(reify
om/IRender
(render [_]
(dom/div nil
(ctg (clj->js {:transitionName "example"
:children (map #(dom/h1 nil %) data)}))
(dom/button #js {:onClick #(om/transact! data (fn [v] (conj v "test")))} "+")
(dom/button #js {:onClick #(om/transact! data pop)} "-")))))
(om/root
app
app-state
{:target (. js/document (getElementById "app"))})
<html>
<head>
<style>
.example-enter {
opacity: 0.01;
transition: opacity .5s ease-in;
}
.example-enter.example-enter-active {
opacity: 1;
}
.example-leave {
opacity: 1;
transition: opacity .5s ease-in;
}
.example-leave.example-leave-active {
opacity: 0.01;
}
</style>
<body>
<div id="app"></div>
<script src="http://fb.me/react-with-addons-0.9.0.js"></script>
<script src="out/goog/base.js" type="text/javascript"></script>
<script src="om_transition.js" type="text/javascript"></script>
<script type="text/javascript">goog.require("om_transition.core");</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment