Components (.cljc + .css + tests): - Alert (success/warning/danger/info variants) - Badge (primary/secondary/outline/success/warning/danger) - Card (card/card-header/card-body/card-footer) - Accordion (collapsible with open/closed state) - Table (headers/rows, striped/bordered variants) - Dialog (modal with header/body/footer sections) - Breadcrumb (nav with active item) - Pagination (current/total with prev/next) - Progress (value bar with color variants) - Spinner (sm/md/lg sizes) - Skeleton (line/box/circle/heading placeholders) - Switch (toggle with checked/disabled states) - Tooltip (hover text via data-tooltip attr) CSS-only additions: - Form elements (inputs, selects, checkboxes, radios, range, groups) - Grid (12-column system with offsets, responsive) - Utilities (flex, spacing, alignment, sr-only) Also adds warning/fg-on-warning tokens to light and dark themes. All 3 dev targets updated with full component showcase. 40 tests, 213 assertions, all passing.
66 lines
2.4 KiB
Clojure
66 lines
2.4 KiB
Clojure
(ns ui.switch
|
|
(:require [clojure.string :as str]))
|
|
|
|
(defn switch-class-list
|
|
"Generate a vector of CSS class strings for a switch."
|
|
[{:keys [disabled]}]
|
|
(cond-> ["switch"]
|
|
disabled (conj "switch--disabled")))
|
|
|
|
(defn switch-classes
|
|
"Generate CSS class string for a switch."
|
|
[opts]
|
|
(str/join " " (switch-class-list opts)))
|
|
|
|
(defn switch-toggle
|
|
"Render a toggle switch element.
|
|
|
|
Props:
|
|
:checked - boolean, whether the switch is on
|
|
:disabled - boolean
|
|
:on-change - change handler (ignored in :clj target)
|
|
:label - label text
|
|
:class - additional CSS classes
|
|
:attrs - additional HTML attributes"
|
|
[{:keys [checked disabled on-change label class attrs] :as _props}]
|
|
#?(:squint
|
|
(let [classes (cond-> (switch-classes {:disabled disabled})
|
|
class (str " " class))
|
|
track-cls (cond-> "switch-track"
|
|
checked (str " switch-track--checked"))]
|
|
[:label (merge {:class classes} attrs)
|
|
[:input {:class "switch-input" :type "checkbox"
|
|
:checked (boolean checked)
|
|
:disabled (boolean disabled)
|
|
:on-change on-change}]
|
|
[:span {:class track-cls}
|
|
[:span {:class "switch-thumb"}]]
|
|
(when label [:span label])])
|
|
|
|
:cljs
|
|
(let [cls (switch-class-list {:disabled disabled})
|
|
classes (cond-> cls class (conj class))
|
|
track-cls (cond-> ["switch-track"]
|
|
checked (conj "switch-track--checked"))]
|
|
[:label (merge {:class classes} attrs)
|
|
[:input (cond-> {:class ["switch-input"] :type "checkbox"
|
|
:checked (boolean checked)
|
|
:disabled (boolean disabled)}
|
|
on-change (assoc-in [:on :change] on-change))]
|
|
[:span {:class track-cls}
|
|
[:span {:class ["switch-thumb"]}]]
|
|
(when label [:span label])])
|
|
|
|
:clj
|
|
(let [classes (cond-> (switch-classes {:disabled disabled})
|
|
class (str " " class))
|
|
track-cls (cond-> "switch-track"
|
|
checked (str " switch-track--checked"))]
|
|
[:label (merge {:class classes} attrs)
|
|
[:input {:class "switch-input" :type "checkbox"
|
|
:checked (boolean checked)
|
|
:disabled (boolean disabled)}]
|
|
[:span {:class track-cls}
|
|
[:span {:class "switch-thumb"}]]
|
|
(when label [:span label])])))
|