Fix radio-card to pass through HTMX attributes for $/% toggle

The radio-card component was ignoring HTMX attributes (:hx-post, :hx-target,
etc.) passed to it. Modified the component to extract these attributes and
merge them into each radio input element, so the $/% toggle now properly
triggers HTMX requests when changed.
This commit is contained in:
2026-05-20 23:23:19 -07:00
parent 351659f8eb
commit 535ef4d113

View File

@@ -2,7 +2,8 @@
(:require [auto-ap.ssr.hiccup-helper :as hh] (:require [auto-ap.ssr.hiccup-helper :as hh]
[auto-ap.ssr.hx :as hx])) [auto-ap.ssr.hx :as hx]))
(defn radio-card- [{:keys [options name title size orientation width] :or {size :medium width "w-48"} selected-value :value}] (defn radio-card- [{:keys [options name title size orientation width] :or {size :medium width "w-48"} selected-value :value :as attrs}]
(let [htmx-attrs (select-keys attrs [:hx-post :hx-target :hx-swap :hx-include :hx-trigger])]
[:h3 {:class "mb-4 font-semibold text-gray-900 dark:text-white"} title] [:h3 {:class "mb-4 font-semibold text-gray-900 dark:text-white"} title]
[:ul {:class (cond-> " text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white" [:ul {:class (cond-> " text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white"
(= orientation :horizontal) (-> (hh/add-class "flex gap-2 flex-wrap") (= orientation :horizontal) (-> (hh/add-class "flex gap-2 flex-wrap")
@@ -14,7 +15,7 @@
(hh/add-class "w-auto shrink-0 block rounded-lg border border-gray-200 dark:border-gray-600 px-3")))} (hh/add-class "w-auto shrink-0 block rounded-lg border border-gray-200 dark:border-gray-600 px-3")))}
[:div {:class (cond-> "flex items-center" [:div {:class (cond-> "flex items-center"
(not= orientation :horizontal) (hh/add-class "pl-3"))} (not= orientation :horizontal) (hh/add-class "pl-3"))}
[:input (cond-> {:id (str "list-" name "-" value) [:input (cond-> (merge {:id (str "list-" name "-" value)
:type "radio", :type "radio",
:value value :value value
:name name :name name
@@ -25,6 +26,7 @@
(= size :medium) (= size :medium)
(str " " "text-sm"))} (str " " "text-sm"))}
htmx-attrs)
(= (cond-> selected-value (keyword? selected-value) clojure.core/name) value) (assoc :checked true))] (= (cond-> selected-value (keyword? selected-value) clojure.core/name) value) (assoc :checked true))]
[:label {:for (str "list-" name "-" value) [:label {:for (str "list-" name "-" value)
:class :class
@@ -36,7 +38,7 @@
(str " " "text-sm py-3") (str " " "text-sm py-3")
(= orientation :horizontal) (= orientation :horizontal)
(hh/remove-class "w-full"))} content]]])]) (hh/remove-class "w-full"))} content]]])]))
(defn radio-list- [{:keys [options name x-model title size orientation] :or {size :medium} selected-value :value}] (defn radio-list- [{:keys [options name x-model title size orientation] :or {size :medium} selected-value :value}]
[:h3 {:class "mb-4 font-semibold text-gray-900 dark:text-white"} title] [:h3 {:class "mb-4 font-semibold text-gray-900 dark:text-white"} title]