Here are my new components: (ns blueridge.ui.new (:require [ui.components :as…
- User
Here are my new components:
(ns blueridge.ui.new (:require [ui.components :as components] [cljs.pprint :refer [cl-format]] [clojure.string :as string] [reagent.core :as ra] [“reactstrap” :as rs])) (defn dropdown-item [config] (let [label (:label config)] [components/dropdown-item config label]))
(def default-styles-dropdown-button {:title "Actions" :dropdown-button {:key (str "dropdown-" (rand-int 100)) ;; If there are multiple dropdowns with the same title this leads to problems. ;; You should set this manually, but this is a small failsafe. :direction "down" :class {} :style {:height "3rem"}} :dropdown-toggle {:key "dropdown-toggle" :style {:width "8rem"} :color "primary" :caret true} :dropdown-menu {:key "dropdown-menu" :class "dropdown-menu-right"} :items [[dropdown-item {:key "item-1" :disabled false :label "Clickable item"}] [dropdown-item {:key "item-2" :disabled true :label [:div.d-flex "Disabled item " [:i.fas.fa-question-circle.fa-md.ml-2]]}]]})
(defn dropdown-button "Standard dropdown menu button for Gojee. Takes a config map. See default-styles-dropdown-menu-button for an example list of things that can be changed if desired. Required:
:items[list of dropdown items] Recommended::titlestring:dropdown-button{:key string} (unique, prevents duplicate menus) Optional::dropdown-toggle{}:dropdown-menu{}" [config] (ra/with-let [is-open (ra/atom false) merged-config
button-options (:dropdown-button merged-config) toggle-options (:dropdown-toggle merged-config) menu-options (:dropdown-menu merged-config) items (:items merged-config)] [components/dropdown-button (merge button-options {:is-open @is-open :toggle #(reset! is-open (not @is-open))}) [components/dropdown-toggle toggle-options (:title merged-config)] [components/dropdown-menu menu-options (map dropdown-item items)]]))I want the options and items to update on hotreload, so I don't think I can use with-let. How should I structure the code instead?
- Assistant
- User
Is there a problem with building it like this?
[{:keys [title dropdown-button dropdown-toggle dropdown-menu items] :as config}] (ra/with-let [is-open (ra/atom false) default default-styles-dropdown-button] [components/dropdown-button (merge (:dropdown-button default) dropdown-button {:is-open @is-open :toggle #(reset! is-open (not @is-open))}) [components/dropdown-toggle (merge (:dropdown-toggle default) dropdown-toggle) (when-not title (:title default))] [components/dropdown-menu (merge (:dropdown-menu default) dropdown-menu) (map dropdown-item items)]]))
- Assistant
- User
- Assistant