-
-
Save brzezinskip/73464bfe3b9298671c47f11024db37e1 to your computer and use it in GitHub Desktop.
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
(defn counter-row [{desc :desc timer :timer active :active bg-color :bg-color}] | |
(r/with-let [seconds-elapsed (r/atom 0) | |
running (r/atom false) | |
timer-fn (atom nil)] | |
(fn [] | |
[:div {:class (str "h-full flex flex-col flex-1 " bg-color " bg-opacity-75 items-center justify-evenly") | |
:on-click (fn [] | |
(if @running (js/clearInterval timer-fn) | |
(reset! timer-fn (js/setInterval #(swap! seconds-elapsed inc) 1000))) | |
(reset! running (not @running)) | |
)} | |
[:p {:class "w-full text-9xl text-center text-gray-50"} desc] | |
[:p {:class "w-full text-9xl text-center text-gray-50"} @seconds-elapsed]]) | |
(finally (js/clearInterval timer-fn)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment