Button: - :icon-left, :icon-right props for buttons with leading/trailing icons - :icon prop for icon-only buttons (square padding via .btn-icon class) - Icon size scales with button size (sm→sm, md/lg→sm/md) Alert: - Auto-assigns variant-specific icons (circle-check, alert-triangle, alert-circle, info) per variant - :icon-name prop to override default, false to suppress - Layout restructured with .alert-icon + .alert-content wrapper Badge: - :icon-name prop adds a leading icon before text - .badge-icon CSS scales icon to match badge font size Form input: - :icon-left and :icon-right props on form-input - Wraps input in .form-input-wrap with absolutely-positioned icon spans - Padding adjusts automatically via .form-input--icon-left/right All three dev targets (hiccup, replicant, squint) updated with demos.
44 lines
1.8 KiB
Clojure
44 lines
1.8 KiB
Clojure
(ns ui.badge-test
|
|
(:require [clojure.test :refer [deftest is testing]]
|
|
[ui.badge :as badge]
|
|
[ui.icon :as icon]))
|
|
|
|
(deftest badge-class-list-test
|
|
(testing "default variant (primary)"
|
|
(is (= ["badge"] (badge/badge-class-list {}))))
|
|
|
|
(testing "explicit variants"
|
|
(is (= ["badge"] (badge/badge-class-list {:variant :primary})))
|
|
(is (= ["badge" "badge-secondary"] (badge/badge-class-list {:variant :secondary})))
|
|
(is (= ["badge" "badge-outline"] (badge/badge-class-list {:variant :outline})))
|
|
(is (= ["badge" "badge-success"] (badge/badge-class-list {:variant :success})))
|
|
(is (= ["badge" "badge-warning"] (badge/badge-class-list {:variant :warning})))
|
|
(is (= ["badge" "badge-danger"] (badge/badge-class-list {:variant :danger})))))
|
|
|
|
(deftest badge-classes-test
|
|
(testing "space-joined output"
|
|
(is (= "badge" (badge/badge-classes {})))
|
|
(is (= "badge badge-danger" (badge/badge-classes {:variant :danger})))))
|
|
|
|
(deftest badge-component-test
|
|
(testing "renders a span"
|
|
(let [result (badge/badge {} "New")]
|
|
(is (= :span (first result)))
|
|
(is (= "badge" (get-in result [1 :class])))
|
|
(is (= "New" (nth result 2)))))
|
|
|
|
(testing "extra class gets appended"
|
|
(let [result (badge/badge {:class "extra"} "X")]
|
|
(is (= "badge extra" (get-in result [1 :class]))))))
|
|
|
|
(deftest badge-icon-test
|
|
(testing "badge with icon-name renders icon before text"
|
|
(let [result (badge/badge {:icon-name :check} "Done")]
|
|
(is (= :span (first result)))
|
|
(is (= :svg (first (nth result 2)))) ;; icon is first child
|
|
(is (= "Done" (nth result 3))))) ;; text is second child
|
|
|
|
(testing "badge without icon-name has no icon"
|
|
(let [result (badge/badge {} "Plain")]
|
|
(is (= "Plain" (nth result 2))))))
|