SHARE
TWEET

table

alanforrester Apr 1st, 2017 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns taskmaster.core
  2.   (:require [reagent.core :as r]))
  3.  
  4. (def heading-list
  5.     ["a" "b" "c" "d"])
  6.  
  7. (def headings
  8.     {:type :h3
  9.     :id (random-uuid)
  10.     :content (map (fn [h] {:id (random-uuid) :content h}) heading-list)})
  11.  
  12. (defn make-row [elinfo]
  13.   (for [ei (:content elinfo)]
  14.     ^{:key (str (:id ei))}
  15.     [:td [(:type elinfo) (:content ei)]]))
  16.  
  17. (defn new-blank-row [n type]
  18.     {:type type
  19.     :id (random-uuid)
  20.      :content (map (fn [r] {:id (random-uuid) :content ""}) (range n))})
  21.  
  22. (def taskmaster-app
  23.   (r/atom {:rows [headings]}))
  24.  
  25. (defn add-row-button []
  26.   (let [nc (count (:content headings))]
  27.     [:input {:type "button" :value "Add row"
  28.              :on-click (fn [] (swap! taskmaster-app
  29.                                 #(update-in % [:rows] conj
  30.                                   (new-blank-row nc :textarea))))}]))
  31.  
  32. (defn Table [state]
  33.   [:div [:div [add-row-button]]
  34.     [:div [:table [:tbody
  35.         (for [row (:rows @state)]
  36.             (into
  37.                 ^{:key (str (:id row))} [:tr]
  38.                 (make-row row)))]]]])
  39.  
  40. (defn ^:export run []
  41.   (r/render
  42.     [Table taskmaster-app]
  43.     (js/document.getElementById "app")))
RAW Paste Data
Top