Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element/breadcrumbs #20

Open
wants to merge 43 commits into
base: refactor/architecture
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
98b6f2a
Merge pull request #10 from bdo-labs/fix/chooser
kleinrein Jan 23, 2018
70719b9
Fix weak contrast between cells
andreasreinbdo Feb 13, 2018
4fa2d71
Merge pull request #12 from bdo-labs/fix/contrast-non-editable-cell
hkjels Feb 26, 2018
7232ecb
Merge branch 'master' into perf/sheet
hkjels Mar 19, 2018
e20d377
Update core.cljs
hkjels Mar 19, 2018
1ba5a51
numberfield added
Mar 19, 2018
f75d0f2
connect with REPL
Mar 19, 2018
5b0191f
thoughts on form + error
Mar 19, 2018
3abf402
Merge pull request #13 from bdo-labs/perf/sheet
hkjels Mar 20, 2018
4aa3c0d
Merge branch 'master' into wire/form
emil0r Mar 20, 2018
1f46aef
Weasel REPL re-added, but with try/catch clause
Mar 20, 2018
ca47b26
first draft of form.
Mar 20, 2018
b5bacb0
split up form into sub-components
Mar 21, 2018
ebae9dd
moved from ui.element.form to ui.wire.form
Mar 21, 2018
69b422b
notification(s) element added
Mar 21, 2018
e359d5b
plumbing for form validation handling done
Mar 21, 2018
277f3ad
added i18n support for error messages in validation
Mar 22, 2018
ee1f950
added wiring as a wire. simple helper namespace for transversing the
Mar 22, 2018
5af567b
wiring added as an option to as-table
Mar 22, 2018
08aa358
as-list added
Mar 22, 2018
88f98ec
as-paragraph added
Mar 22, 2018
3c4c87d
bugfix: wiring can now replace a material with nil
emil0r Mar 28, 2018
296a616
bugfix: :wiring and :template caused an infinite loop when rendering …
emil0r Mar 28, 2018
84bf989
as-template added
emil0r Mar 28, 2018
6a53fd5
renamed material(s) to marker(s) in wiring
emil0r Mar 28, 2018
ca3a41e
tidied up docs for form a bit. added CSS error class
emil0r Mar 28, 2018
db09957
Merge branch 'refactor/architecture' into wire/form
emil0r Apr 17, 2018
ab48a03
form has added support for textfield and chooser
emil0r Apr 18, 2018
ca08293
checkbox working with new spec
emil0r Apr 19, 2018
5184f38
fix checkbox spec
emil0r Apr 19, 2018
65e8367
form now accepts an additional content field which holds a valid reac…
emil0r Apr 19, 2018
cb4a946
wizard done
emil0r Apr 20, 2018
2a3c58e
styling of numberfield
emil0r Apr 24, 2018
ebbb449
documentation for notification
emil0r Apr 25, 2018
eecf4da
removed some features for numberfield which caused too many constrains
emil0r Apr 25, 2018
3f99142
added tabs
emil0r Apr 25, 2018
0de6d43
default styling done for tabs
emil0r Apr 26, 2018
25359e3
documentation for tabs done
emil0r Apr 26, 2018
cc4de05
radio buttons added + styling + documentation
emil0r Apr 26, 2018
654b3bf
bugfix: radio button now is properly checked when selected
emil0r Apr 27, 2018
091f3f0
moved model back up to initilization of radio button
emil0r Apr 27, 2018
88aa578
paginator added. styling, documentation and code
emil0r Apr 27, 2018
6ac6b0e
added breadcrumbs including functionality, styling and documentation
emil0r Apr 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
form has added support for textfield and chooser
checkbox almost there
  • Loading branch information
emil0r committed Apr 18, 2018
commit ab48a0304aa0dd2a5e8b059ec0845d9ac27759d2
15 changes: 14 additions & 1 deletion src/cljc/ui/docs/form.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
{:on-valid (fn [data _] #?(:cljs (js/alert (pr-str data))))}
[{:type ::element/numberfield
:name :number1
:label "Number (1)"
:help "My help text"
:text [:span {:style {:font-weight "bold"}} "My info text"]
:wiring [:tr :$key
Expand All @@ -40,8 +41,20 @@
:spec ::number1-valid}
{:type element/numberfield
:name :number2
:label "Number (2)"
:spec ::number2-valid
:error-element :dispatch}])
:error-element :dispatch}
{:type ::element/textfield
:name :text1
:label "Text"}
{:type ::element/chooser
:name :chooser1
:label "Chooser"
:items [{:id 1 :value "Test 1"}
{:id 2 :value "Test 2"}]}
{:type ::element/checkbox
:name :checkbox1
:label "Checkbox"}])

(defn- notification-args [model]
{:model model
Expand Down
13 changes: 6 additions & 7 deletions src/cljc/ui/docs/inputs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@
toggle-email #(re-frame/dispatch [::toggle-email])]
[layout/horizontally
[layout/vertically
[element/checkbox {:checked bacon
[element/checkbox {:model bacon
:on-change toggle-bacon} "Bacon"]
[element/checkbox {:checked cheese
[element/checkbox {:model cheese
:on-change toggle-cheese} "Cheese"]
[element/checkbox {:checked ketchup
[element/checkbox {:model ketchup
:on-change toggle-ketchup} "Ketchup"]]
[layout/vertically
[element/toggle {:checked email
[element/toggle {:model email
:on-change toggle-email} "Eat here?"]]]))

(defn smart-case-includes? [s substr]
Expand All @@ -175,9 +175,9 @@
sep-filtered-items @(re-frame/subscribe [::sep-filtered-items])]
[layout/horizontally
[layout/vertically
[element/checkbox {:checked multiple
[element/checkbox {:model multiple
:on-change #(re-frame/dispatch [::toggle-multiple])} "Multiple"]
[element/checkbox {:checked disabled
[element/checkbox {:model disabled
:on-change #(re-frame/dispatch [::toggle-disabled])} "Disabled"]
[element/chooser {:style {:width "420px"}
:label "Name a Character from Game of Thrones"
Expand All @@ -200,4 +200,3 @@
"
[check-toggle]
[completion]])

37 changes: 22 additions & 15 deletions src/cljc/ui/element/checkbox/spec.cljc
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
(ns ui.element.checkbox.spec
(:require [clojure.spec.alpha :as spec]
[clojure.test.check.generators :as gen]))
[clojure.test.check.generators :as gen]
[ui.specs :as common]))

(spec/def ::maybe-fn
(spec/with-gen fn?
(gen/return (constantly nil))))

(spec/def ::id (spec/or :numeric int? :textual (spec/and string? not-empty)))
(spec/def ::checked? boolean?)
(spec/def ::label string?)
(spec/def ::value string?)
(spec/def ::model
(spec/nonconforming
(spec/or :deref (spec/and ::common/ratom #(let [v (deref %)]
(#{:checked :indeterminate :not-checked} v)))
:boolean boolean?
:nil nil?
:keywords #{:checked :indeterminate :not-checked})))

(spec/def ::on-change ::maybe-fn)
(spec/def ::on-change ::common/maybe-fn)

(spec/def ::checkbox-params
(spec/def ::params
(spec/keys
:opt-un [::id ::checked? ::value ::on-change]))
:opt-un [::common/id
::on-change]))

(spec/def ::--params
(spec/merge
::params
(spec/keys :opt-un [::model])))

(spec/def ::checkbox-args
(spec/cat :params ::checkbox-params :label ::label))
(spec/def ::args
(spec/or :arg2 (spec/cat :params ::--params :label ::label)
:arg1 (spec/cat :params ::--params)))

(spec/fdef checkbox
:args ::checkbox-args
:args ::args
:ret vector?)

66 changes: 42 additions & 24 deletions src/cljc/ui/element/checkbox/views.cljc
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
(ns ui.element.checkbox.views
(:require [ui.util :as util]
(:require [#?(:clj clojure.core :cljs reagent.core) :refer [atom]]
[ui.util :as util]
[ui.element.checkbox.spec :as spec]))

(defn checkbox
[& args]
(let [{:keys [params label]
:or {label ""}} (util/conform! ::spec/checkbox-args args)
{:keys [checked on-click id]
:or {id (util/gen-id)}} params]
[:label {:for id
:class (->> (util/names->str [(case checked
(true :checked) :Checked
:indeterminate :Indeterminate
:Not-Checked)
(:class params)])
(str (when-not (some #(= :Toggle %) (:class params)) " Checkbox ")))}
[:div.Shape
[:i (when-not (some #(= :Toggle %) (:class params))
(case checked
(true :checked) {:class :ion-ios-checkmark-empty}
:indeterminate {:class :ion-ios-minus-empty}
{}))]
[:input (merge (dissoc params :checked :id :class)
{:id id
:type :checkbox
:checked checked})]] label]))
(defn checkbox [& args]
(let [{:keys [params]} (util/conform! ::spec/args args)
{:keys [model on-change id]
:or {id (util/gen-id)}} params
initial-value (util/deref-or-value model)
model (if (util/deref? model)
model
(atom (cond (keyword? initial-value) initial-value
(true? initial-value) :checked
:else :not-checked)))
--on-change #(let [model-value @model]
(when (= model-value :checked)
(reset! model :not-checked))
(when (not= model-value :checked)
(reset! model :checked))
(when (ifn? on-change) (on-change model-value %)))]

;;#?(:cljs (js/alert (pr-str {:model model :params-model (:model params)})))
(fn [& args]
(let [{:keys [params label]
:or {label ""}} (util/conform! ::spec/args args)
checked @model]
[:label {:for id
:class (->> (util/names->str [(case checked
:checked :Checked
:indeterminate :Indeterminate
:Not-Checked)
(:class params)])
(str (when-not (some #(= :Toggle %) (:class params)) " Checkbox ")))}
[:div.Shape
[:i (when-not (some #(= :Toggle %) (:class params))
(case checked
:checked {:class :ion-ios-checkmark-empty}
:indeterminate {:class :ion-ios-minus-empty}
{}))]
[:input (merge (dissoc params :model :id :class)
{:id id
:type :checkbox
:on-change --on-change
:checked checked})]] label]))))
11 changes: 7 additions & 4 deletions src/cljc/ui/element/chooser/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
(spec/def ::searchable boolean?)
(spec/def ::deletable boolean?)
(spec/def ::predicate? ::common/maybe-fn)
(spec/def ::model
(spec/nonconforming
(spec/or :deref (spec/and ::common/ratom #(set? (deref %)))
:set set?
:nil nil?)))

(spec/def ::params
(spec/merge ::collection/params
Expand All @@ -18,10 +23,8 @@
::deletable
::searchable
::labels
::predicate?])))

(spec/exercise ::params)
::predicate?
::model])))

(spec/def ::args
(spec/cat :params ::params))

35 changes: 18 additions & 17 deletions src/cljc/ui/element/chooser/views.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
(defn chooser
[& args]
(let [{:keys [params]} (util/conform! ::spec/args args)
{:keys [id selected deletable items
{:keys [id model deletable items
on-key-up on-change on-focus on-blur on-select]
:or {id (util/gen-id)
selected #{}}} params
id (util/slug id)
query* ^{:doc "Query to use for filtering and emphasizing the resultset"} (atom (if deletable (str/join ", " (map :value selected)) ""))
model #{}}} params
id (util/slug "chooser" id)
query* ^{:doc "Query to use for filtering and emphasizing the resultset"} (atom (if deletable (str/join ", " (map :value model)) ""))
show* ^{:doc "Show or hide the collection-dropdown"} (atom false)
selected* ^{:doc "Keep track of all selected items"} (atom selected)]

model ^{:doc "Keep track of all selected items"} (cond (util/deref? model) model
(set? model) (atom model)
:else (atom #{}))]
(fn [& args]
(let [{:keys [params]} (util/conform! ::spec/args args)
{:keys [multiple
Expand Down Expand Up @@ -61,9 +62,9 @@
;; Remove incomplete items
:on-key-up (fn [key value event]
(let [candidates (->> (str/split value ",") (mapv str/trim) (set))
valid-ones (remove (fn [x] (not (contains? candidates (str (:value x))))) @selected*)]
(when (not= @selected* valid-ones)
(reset! selected* (set valid-ones))))
valid-ones (remove (fn [x] (not (contains? candidates (str (:value x))))) @model)]
(when (not= @model valid-ones)
(reset! model (set valid-ones))))
(when (fn? on-key-up) (on-key-up key value event)))
:on-focus (fn [value event]
(do (reset! show* true)
Expand All @@ -82,17 +83,17 @@
:read-only true})
(when (and (not deletable)
(false? multiple)
(not-empty @selected*))
{:placeholder (-> (first @selected*) :value)})
(not-empty @model))
{:placeholder (-> (first @model) :value)})
(when (and (not deletable)
multiple
(false? labels)
(not (empty? @selected*)))
{:placeholder (str (str/join ", " (map :value @selected*)))}))
(not (empty? @model)))
{:placeholder (str (str/join ", " (map :value @model)))}))
collection-params (merge params
{:id (util/slug id "collection")
:emphasize current-query
:model selected*
:model model
:keyboard keyboard
:selectable selectable
:searchable searchable
Expand All @@ -101,7 +102,7 @@
(if deletable
(reset! query* (str (str/join ", " (map :value items)) (when multiple ", ")))
(reset! query* ""))
(reset! selected* items)
(reset! model items)
(when (fn? on-select) (on-select items)))})]

[:div.Chooser {:id id
Expand All @@ -114,12 +115,12 @@

(when (and multiple
(false? labels))
[badge {:show-content? true} (count @selected*)])
[badge {:show-content? true} (count @model)])

(when (and multiple labels)
[:div.Labels
(doall
(for [label-params @selected*]
(for [label-params model]
(let [label-params (merge label-params
{:key (util/slug (:id label-params) "a-label")
:on-key-down #(let [key (util/code->key (.-which %))]
Expand Down
7 changes: 4 additions & 3 deletions src/cljc/ui/element/collection/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
(spec/def ::keyboard boolean?) ;; Enable keyboard-support
(spec/def ::params
(spec/keys :opt-un [::common/id
::model
::max-selected
::emphasize
::collapsable
Expand All @@ -45,6 +44,9 @@
::on-click
::on-select
::on-mouse-enter]))
(spec/def ::--params
(spec/merge ::params
(spec/keys :opt-un [::model])))

(spec/def ::id (spec/nonconforming (spec/or :str :ui.specs/qualified-string? :num nat-int?)))
(spec/def ::value :ui.specs/qualified-string?)
Expand All @@ -56,6 +58,5 @@
#(gen/fmap set (spec/gen (spec/coll-of ::item)))))

(spec/def ::args
(spec/cat :params ::params
(spec/cat :params ::--params
:items ::items))

46 changes: 24 additions & 22 deletions src/cljc/ui/element/collection/views.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
(remove-item! [item]
(swap! model disj item))
(add-item! [item]
(when (seq item)
(when (seq item)
(if (contains? @model item)
(when deselectable
(if (= 1 (count @model))
Expand Down Expand Up @@ -130,28 +130,30 @@
[:ul.Collection {:key (util/slug "collection" id)
:class (str (util/params->classes ui-params) " " class)}
(when (seq items)
(for [{:keys [id value label class] :as item} items]
(let [label (or label value)]
(into
[:li {:key (util/slug "collection" "item" id)
:class (str/join " " [(when (= (:id item) (:id intended)) "intended")
(when (and (util/deref? model)
(contains? @model item)) "selected")
(str class)])
:on-mouse-enter (partial --on-mouse-enter item)
:on-click (partial --on-click item)}]
(if (and collapsable
(= (:id (first items)) id))
[[:div.item-area
(if (string? label)
;; force evaluation. React doesn't like a LazySeq here
(doall
(for [{:keys [id value label class] :as item} items]
(let [label (or label value)]
(into
[:li {:key (util/slug "collection" "item" id)
:class (str/join " " [(when (= (:id item) (:id intended)) "intended")
(when (and (util/deref? model)
(contains? @model item)) "selected")
(str class)])
:on-mouse-enter (partial --on-mouse-enter item)
:on-click (partial --on-click item)}]
(if (and collapsable
(= (:id (first items)) id))
[[:div.item-area
(if (string? label)
(emphasize-match label emphasize)
label)]
[:div.collapse-area
[button {:on-click toggle-expanded}
[icon {:size 2} (str "chevron-" (if expanded? "up" "down"))]]]]
[(if (string? label)
(emphasize-match label emphasize)
label)]
[:div.collapse-area
[button {:on-click toggle-expanded}
[icon {:size 2} (str "chevron-" (if expanded? "up" "down"))]]]]
[(if (string? label)
(emphasize-match label emphasize)
label)])))))]))]
label)]))))))]))]
#?(:clj render-fn
:cljs
(reagent/create-class
Expand Down
1 change: 0 additions & 1 deletion src/cljc/ui/element/notification/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[ui.specs :as common]
[ui.util :as util]))

(spec/def ::id (spec/and string? #(re-find #"(?i)(\w+)" %)))
(spec/def ::value string?)
(spec/def ::model util/deref?)
(spec/def ::class (spec/coll-of string?))
Expand Down
Loading