Skip to content

Instantly share code, notes, and snippets.

@brzezinskip
Created January 25, 2021 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brzezinskip/73464bfe3b9298671c47f11024db37e1 to your computer and use it in GitHub Desktop.
Save brzezinskip/73464bfe3b9298671c47f11024db37e1 to your computer and use it in GitHub Desktop.
(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