In this clojurescript code, what is the react class I need to have the edit button on…
- User
In this clojurescript code, what is the react class I need to have the edit button on the left and the other buttons on the right?
[:div.d-flex [:div [:button.btn.btn-danger {:on-click #(ui.new/close-popover! popover-state-atom)} "Edit"]] [:div.align-items-right [:button.btn.btn-primary ;; on-close will be called and handle transfering the local values into re-frame {:on-click #(ui.new/close-popover! popover-state-atom)} "Save"] [:button.btn.btn-link {:on-click #(do (reset! name-atom original-name) (reset! desc-atom original-desc) (ui.new/close-popover! popover-state-atom))} "Cancel"]]]
- Assistant
- User
Is there a function to convert a map of elements to hiccup syntax?
- Assistant
In ClojureScript and Clojure web development, Hiccup syntax is a convenient way to represent HTML or XML elements using Clojure's native data structures (vectors for elements and maps for attributes). However, when you have a Clojure map and you want to convert it to Hiccup syntax, there's no built-in function specifically designed for this conversion because Hiccup is already designed to work closely with Clojure's data structures.
- User
How about elements like [:hr]?
- Assistant
Handling self-closing tags (such as , , , etc.) in a conversion function from a map to Hiccup syntax requires you to account for tags that do not wrap any content or children. These elements might still have attributes, so your conversion function needs to be flexible enough to handle both self-closing tags with attributes and those without any content or children.
- User
Here's what I'm trying to feed through it: ... (when-not sales-contractor? {:element :hr}) (when-not sales-contractor? {:key "delete" :on-click #(dispatch [::events/api-delete-quote id]) :label "Delete"})]}]))
And here's the code I'm using so far:
(defn map-to-hiccup "Converts a nested map representing elements to hiccup syntax." [hiccup-map] (let [self-closing #{:hr :br :img :input}] (mapv (fn [[tag value]] (cond (self-closing tag) (if (map? value) [(keyword tag) value] [tag]) (map? value) [(keyword tag) (:attrs value) (:body value)] :else [tag value])) hiccup-map)))
(defn dropdown-item-interpreter [config] (let [label (:label config)] (if (:elements config) [map-to-hiccup (:elements config)]) [components/dropdown-item config label]))
- Assistant