feat: add 13 components adapted from Oat UI

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.
This commit is contained in:
Florian Schroedl
2026-03-03 11:37:05 +01:00
parent d55e3d3a90
commit 18043cb150
47 changed files with 2556 additions and 106 deletions

70
src/ui/pagination.cljc Normal file
View File

@@ -0,0 +1,70 @@
(ns ui.pagination
(:require [clojure.string :as str]))
(defn pagination-item-class-list
"Generate a vector of CSS class strings for a pagination item."
[{:keys [active disabled]}]
(cond-> ["pagination-item"]
active (conj "pagination-item--active")
disabled (conj "pagination-item--disabled")))
(defn pagination-item-classes
"Generate CSS class string for a pagination item."
[opts]
(str/join " " (pagination-item-class-list opts)))
(defn pagination
"Render a pagination nav.
Props:
:current - current page number (1-based)
:total - total number of pages
:href-fn - fn of page number → URL string (for :clj)
:on-click - fn of page number → handler (for :cljs/:squint)
:class - additional CSS classes
:attrs - additional HTML attributes"
[{:keys [current total href-fn on-click class attrs] :as _props}]
(let [pages (range 1 (inc total))
prev-disabled (= current 1)
next-disabled (= current total)]
#?(:squint
(let [classes (cond-> "pagination" class (str " " class))
make-item (fn [page label active disabled]
[:li {:class (pagination-item-classes {:active active :disabled disabled})}
[:a (cond-> {:href (if href-fn (href-fn page) "#")}
(and on-click (not disabled))
(assoc :on-click (fn [e] (.preventDefault e) (on-click page))))
label]])]
[:nav {:aria-label "Pagination"}
(into [:ol (merge {:class classes} attrs)]
(concat
[(make-item (dec current) "← Previous" false prev-disabled)]
(map (fn [p] (make-item p (str p) (= p current) false)) pages)
[(make-item (inc current) "Next →" false next-disabled)]))])
:cljs
(let [cls (cond-> ["pagination"] class (conj class))
make-item (fn [page label active disabled]
[:li {:class (pagination-item-class-list {:active active :disabled disabled})}
[:a (cond-> {:href (if href-fn (href-fn page) "#")}
(and on-click (not disabled))
(assoc-in [:on :click] (fn [e] (.preventDefault e) (on-click page))))
label]])]
[:nav {:aria-label "Pagination"}
(into [:ol (merge {:class cls} attrs)]
(concat
[(make-item (dec current) "← Previous" false prev-disabled)]
(map (fn [p] (make-item p (str p) (= p current) false)) pages)
[(make-item (inc current) "Next →" false next-disabled)]))])
:clj
(let [classes (cond-> "pagination" class (str " " class))
make-item (fn [page label active disabled]
[:li {:class (pagination-item-classes {:active active :disabled disabled})}
[:a {:href (if href-fn (href-fn page) "#")} label]])]
[:nav {:aria-label "Pagination"}
(into [:ol (merge {:class classes} attrs)]
(concat
[(make-item (dec current) "← Previous" false prev-disabled)]
(map (fn [p] (make-item p (str p) (= p current) false)) pages)
[(make-item (inc current) "Next →" false next-disabled)]))]))))