Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
 - Addressed the choices-with-group-headings issue of pull request #8.
 - Removed the dropdown demo for `:id-fn` (but left the code in for testing purposes).
 - Changed function specs in (component)-args-desc to new Haskell type notation.
  • Loading branch information
Gregg8 committed May 7, 2015
1 parent 1299678 commit ecc55f3
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/re_com/alert.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{:name :body :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "displayed within the body of the alert"}
{:name :padding :required false :default "15px" :type "string" :validate-fn string? :description "padding surounding the alert"}
{:name :closeable? :required false :default false :type "boolean" :description [:span "if true, render a close button. " [:code ":on-close"] " should be supplied"]}
{:name :on-close :required false :type "(:id) -> nil" :validate-fn fn? :description [:span "called when the user clicks the close 'X' button. Passed the " [:code ":id"] " of the alert to close"]}
{:name :on-close :required false :type ":id -> nil" :validate-fn fn? :description [:span "called when the user clicks the close 'X' button. Passed the " [:code ":id"] " of the alert to close"]}
{:name :class :required false :type "string" :validate-fn string? :description "CSS classes (whitespace separated). Applied to outer container"}
{:name :style :required false :type "CSS style map" :validate-fn css-style? :description "CSS styles. Applied to outer container"}
{:name :attr :required false :type "HTML attr map" :validate-fn html-attr? :description [:span "HTML attributes, like " [:code ":on-mouse-move"] [:br] "No " [:code ":class"] " or " [:code ":style"] "allowed. Applied to outer container"]}])
Expand Down Expand Up @@ -66,7 +66,7 @@

(def alert-list-args-desc
[{:name :alerts :required true :type "vector of maps | atom" :validate-fn vector-of-maps? :description "alerts to render (in the order supplied). Can also be a list of maps"}
{:name :on-close :required true :type "(:id) -> nil" :validate-fn fn? :description [:span "called when the user clicks the close 'X' button. Passed the alert's " [:code ":id"]]}
{:name :on-close :required true :type ":id -> nil" :validate-fn fn? :description [:span "called when the user clicks the close 'X' button. Passed the alert's " [:code ":id"]]}
{:name :max-height :required false :type "string" :validate-fn string? :description "CSS style for maximum list height. By default, it grows forever"}
{:name :padding :required false :default "4px" :type "string" :validate-fn string? :description "CSS padding within the alert"}
{:name :border-style :required false :default "1px solid lightgrey" :type "string" :validate-fn string? :description "CSS border style surrounding the list"}
Expand Down
10 changes: 5 additions & 5 deletions src/re_com/buttons.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(def button-args-desc
[{:name :label :required true :type "string | hiccup" :validate-fn string-or-hiccup? :description "label for the button"}
{:name :class :required false :type "string" :validate-fn string? :description "CSS class names, space separated"}
{:name :on-click :required false :type "( ) -> nil" :validate-fn fn? :description "called when the button is clicked"}
{:name :on-click :required false :type "-> nil" :validate-fn fn? :description "a function which takes no params and returns nothing. Called when the button is clicked"}
{:name :tooltip :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "what to show in the tooltip"}
{:name :tooltip-position :required false :default :below-center :type "keyword" :validate-fn position? :description [:span "relative to this anchor. One of " position-options-list]}
{:name :disabled? :required false :default false :type "boolean | atom" :description "if true, the user can't click the button"}
Expand Down Expand Up @@ -64,7 +64,7 @@

(def md-circle-icon-button-args-desc
[{:name :md-icon-name :required true :default "md-add" :type "string" :validate-fn string? :description [:span "the name of the icon." [:br] "For example, " [:code "\"md-add\""] " or " [:code "\"md-undo\""]] }
{:name :on-click :required false :type "( ) -> nil" :validate-fn fn? :description "called when the button is clicked"}
{:name :on-click :required false :type "-> nil" :validate-fn fn? :description "a function which takes no params and returns nothing. Called when the button is clicked"}
{:name :size :required false :default :regular :type "keyword" :validate-fn button-size? :description [:span "one of " button-sizes-list]}
{:name :tooltip :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "what to show in the tooltip"}
{:name :tooltip-position :required false :default :below-center :type "keyword" :validate-fn position? :description [:span "relative to this anchor. One of " position-options-list]}
Expand Down Expand Up @@ -120,7 +120,7 @@

(def md-icon-button-args-desc
[{:name :md-icon-name :required true :default "md-add" :type "string" :validate-fn string? :description [:span "the name of the icon." [:br] "For example, " [:code "\"md-add\""] " or " [:code "\"md-undo\""]]}
{:name :on-click :required false :type "( ) -> nil" :validate-fn fn? :description "called when the button is clicked"}
{:name :on-click :required false :type "-> nil" :validate-fn fn? :description "a function which takes no params and returns nothing. Called when the button is clicked"}
{:name :size :required false :default :regular :type "keyword" :validate-fn button-size? :description [:span "one of " button-sizes-list]}
{:name :tooltip :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "what to show in the tooltip"}
{:name :tooltip-position :required false :default :below-center :type "keyword" :validate-fn position? :description [:span "relative to this anchor. One of " position-options-list]}
Expand Down Expand Up @@ -218,7 +218,7 @@

(def row-button-args-desc
[{:name :md-icon-name :required true :default "md-add" :type "string" :validate-fn string? :description [:span "the name of the icon." [:br] "For example, " [:code "\"md-add\""] " or " [:code "\"md-undo\""]]}
{:name :on-click :required false :type "( ) -> nil" :validate-fn fn? :description "called when the button is clicked"}
{:name :on-click :required false :type "-> nil" :validate-fn fn? :description "a function which takes no params and returns nothing. Called when the button is clicked"}
{:name :mouse-over-row? :required false :default false :type "boolean" :description "true if the mouse is hovering over the row"}
{:name :tooltip :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "what to show in the tooltip"}
{:name :tooltip-position :required false :default :below-center :type "keyword" :validate-fn position? :description [:span "relative to this anchor. One of " position-options-list]}
Expand Down Expand Up @@ -267,7 +267,7 @@

(def hyperlink-args-desc
[{:name :label :required true :type "string | hiccup | atom" :validate-fn string-or-hiccup? :description "label/hiccup for the button"}
{:name :on-click :required false :type "( ) -> nil" :validate-fn fn? :description "called when the button is clicked"}
{:name :on-click :required false :type "-> nil" :validate-fn fn? :description "a function which takes no params and returns nothing. Called when the button is clicked"}
{:name :tooltip :required false :type "string | hiccup" :validate-fn string-or-hiccup? :description "what to show in the tooltip"}
{:name :tooltip-position :required false :default :below-center :type "keyword" :validate-fn position? :description [:span "relative to this anchor. One of " position-options-list]}
{:name :disabled? :required false :default false :type "boolean | atom" :description "if true, the user can't click the button"}
Expand Down
2 changes: 1 addition & 1 deletion src/re_com/datepicker.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@

(def datepicker-args-desc
[{:name :model :required true :type "goog.date.UtcDateTime | atom" :validate-fn goog-date? :description "the selected date. Should match :enabled-days"}
{:name :on-change :required true :type "(goog.date.UtcDateTime) -> nil" :validate-fn fn? :description "called when a new selection is made"}
{:name :on-change :required true :type "goog.date.UtcDateTime -> nil" :validate-fn fn? :description "called when a new selection is made"}
{:name :disabled? :required false :default false :type "boolean | atom" :description "when true, the can't select dates but can navigate"}
{:name :enabled-days :required false :type "set" :validate-fn set? :description "a subset of #{:Su :Mo :Tu :We :Th :Fr :Sa}. Only dates falling on these days will be user-selectable. Default is all 7 days"}
{:name :show-weeks? :required false :default false :type "boolean" :description "when true, week numbers are shown to the left"}
Expand Down
53 changes: 30 additions & 23 deletions src/re_com/dropdown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@

(defn- choices-with-group-headings
"If necessary, inserts group headings entries into the choices"
[opts]
(let [groups (partition-by :group opts)
[opts group-fn]
(let [groups (partition-by group-fn opts)
group-headers (->> groups
(map first)
(map :group)
(map #(hash-map :id % :group % :group-header? true)))]
;(if (= 1 (count groups))
; opts
; (flatten (interleave group-headers groups)))
(flatten (interleave group-headers groups))))
(map group-fn)
(map #(hash-map :id (gensym) :group %)))]
[group-headers groups]))


(defn- filter-choices
Expand Down Expand Up @@ -85,11 +82,11 @@
(when new-scroll-top (set! (.-scrollTop parent) new-scroll-top))))


(defn- choice-group-heading
(defn- make-group-heading
"Render a group heading"
[group]
[:li.group-result
group])
[m]
^{:key (:id m)} [:li.group-result
(:group m)])


(defn- choice-item
Expand Down Expand Up @@ -124,6 +121,13 @@
label]))})))


(defn make-choice-item
[id-fn label-fn callback internal-model opt]
(let [id (id-fn opt)
label (label-fn opt)]
^{:key (str id)} [choice-item id label callback internal-model]))


(defn- filter-text-box-base
"Base function (before lifecycle metadata) to render a filter text box"
[]
Expand Down Expand Up @@ -188,17 +192,17 @@
(def single-dropdown-args-desc
[{:name :choices :required true :type "vector of maps | atom" :validate-fn vector-of-maps? :description "each has an :id, a :label and, optionally, a :group (list of maps also allowed)"}
{:name :model :required true :type "an :id within :choices | atom" :description "the :id of the selected choice. If nil, :placeholder text is shown"}
{:name :on-change :required true :type "(:id) -> nil" :validate-fn fn? :description [:span "called when a new selection is made. Passed the " [:code ":id"] " of new selection"] }
{:name :on-change :required true :type ":id -> nil" :validate-fn fn? :description [:span "called when a new selection is made. Passed the " [:code ":id"] " of new selection"] }
{:name :disabled? :required false :default false :type "boolean | atom" :description "if true, no user selection is allowed"}
{:name :filter-box? :required false :default false :type "boolean" :description "if true, a filter text field is placed at the top of the dropdown"}
{:name :regex-filter? :required false :default false :type "boolean | atom" :description "if true, the filter text field will support JavaScript regular expressions. If false, just plain text"}
{:name :placeholder :required false :type "string" :validate-fn string? :description "background text when no selection"}
{:name :width :required false :default "100%" :type "string" :validate-fn string? :description "the CSS width. e.g.: \"500px\" or \"20em\""}
{:name :max-height :required false :default "240px" :type "string" :validate-fn string? :description "the maximum height of the dropdown part"}
{:name :tab-index :required false :type "integer | string" :validate-fn number-or-string? :description "component's tabindex. A value of -1 removes from order"}
{:name :id-fn :required false :default :id :type "(map) -> anything" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns the unique identifier for this dropdown entry"]}
{:name :label-fn :required false :default :label :type "(map) -> string | hiccup" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns what should be displayed in this dropdown entry"]}
{:name :group-fn :required false :default :group :type "(map) -> anything" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns the group identifier for this dropdown entry"]}
{:name :id-fn :required false :default :id :type "map -> anything" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns the unique identifier for this dropdown entry"]}
{:name :label-fn :required false :default :label :type "map -> string | hiccup" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns what should be displayed in this dropdown entry"]}
{:name :group-fn :required false :default :group :type "map -> anything" :validate-fn ifn? :description [:span "given an element of " [:code ":choices"] ", returns the group identifier for this dropdown entry"]}
{:name :class :required false :type "string" :validate-fn string? :description "CSS class names, space separated"}
{:name :style :required false :type "CSS style map" :validate-fn css-style? :description "CSS styles to add or override"}
{:name :attr :required false :type "HTML attr map" :validate-fn html-attr? :description [:span "HTML attributes, like " [:code ":on-mouse-move"] [:br] "No " [:code ":class"] " or " [:code ":style"] "allowed"]}])
Expand Down Expand Up @@ -300,11 +304,14 @@
[:ul.chosen-results
(when max-height {:style {:max-height max-height}})
(if (-> filtered-choices count pos?)
(for [opt (choices-with-group-headings filtered-choices)]
(let [id (id-fn opt)
label (label-fn opt)
group (group-fn opt)]
(if (:group-header? opt)
^{:key (str id)} [choice-group-heading group]
^{:key (str id)} [choice-item id label callback internal-model])))
(let [[group-names group-opt-lists] (choices-with-group-headings filtered-choices group-fn)
make-a-choice (partial make-choice-item id-fn label-fn callback internal-model)
make-choices #(map make-a-choice %1)
make-h-then-choices (fn [h opts]
(cons (make-group-heading h)
(make-choices opts)))
has-no-group-names? (nil? (:group (first group-names)))]
(if (and (= 1 (count group-opt-lists)) has-no-group-names?)
(make-choices (first group-opt-lists)) ;; one group means no headings
(apply concat (map make-h-then-choices group-names group-opt-lists))))
[:li.no-results (str "No results match \"" @filter-text "\"")])]])]))))
2 changes: 1 addition & 1 deletion src/re_com/input_time.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

(def input-time-args-desc
[{:name :model :required true :type "integer | string | atom" :validate-fn number-or-string? :description "a time in integer form. e.g. '09:30am' is 930"}
{:name :on-change :required true :type "(integer) -> nil" :validate-fn fn? :description "called when user entry completes and value is new. Passed new value as integer"}
{:name :on-change :required true :type "integer -> nil" :validate-fn fn? :description "called when user entry completes and value is new. Passed new value as integer"}
{:name :minimum :required false :default 0 :type "integer | string" :validate-fn number-or-string? :description "user can't enter a time less than this value"}
{:name :maximum :required false :default 2359 :type "integer | string" :validate-fn number-or-string? :description "user can't enter a time more than this value"}
{:name :disabled? :required false :default false :type "boolean | atom" :description "when true, user input is disabled"}
Expand Down
Loading

0 comments on commit ecc55f3

Please sign in to comment.