Btn can have an optional ID
This commit is contained in:
parent
5d9e3398fd
commit
c13c94f045
2 changed files with 27 additions and 8 deletions
|
@ -88,9 +88,11 @@
|
||||||
|
|
||||||
(in-package :cl-sbt/btn)
|
(in-package :cl-sbt/btn)
|
||||||
|
|
||||||
(defmacro btn ((&key (type "button") (color "primary") (size "")) &body body)
|
(defmacro btn ((&key (id nil) (type "button") (color "primary") (size "")) &body body)
|
||||||
"This macro generates a Bootstrap button.
|
"This macro generates a Bootstrap button.
|
||||||
|
|
||||||
|
ID: (optional) The HTML id attribute for the button.
|
||||||
|
|
||||||
COLOR: The color of the button (like 'primary', 'secondary', 'success', etc.).
|
COLOR: The color of the button (like 'primary', 'secondary', 'success', etc.).
|
||||||
|
|
||||||
SIZE: (optional) The size of the button ('lg' for large, 'sm' for small).
|
SIZE: (optional) The size of the button ('lg' for large, 'sm' for small).
|
||||||
|
@ -106,6 +108,7 @@ Example:
|
||||||
`(spinneret:with-html
|
`(spinneret:with-html
|
||||||
(:button :type ,type
|
(:button :type ,type
|
||||||
:class ,class-str
|
:class ,class-str
|
||||||
|
,@(when (stringp id) (list :id id))
|
||||||
,@body))))
|
,@body))))
|
||||||
|
|
||||||
(defmacro define-btn (color &optional (outline nil) (size nil))
|
(defmacro define-btn (color &optional (outline nil) (size nil))
|
||||||
|
@ -123,8 +126,8 @@ button of the specified type and size."
|
||||||
(outline-name (if (null outline) "" "outline-"))
|
(outline-name (if (null outline) "" "outline-"))
|
||||||
(color-name (concatenate 'string outline-name color))
|
(color-name (concatenate 'string outline-name color))
|
||||||
(macro-name (intern (string-upcase (concatenate 'string "BTN-" outline-name color size-name)))))
|
(macro-name (intern (string-upcase (concatenate 'string "BTN-" outline-name color size-name)))))
|
||||||
`(defmacro ,macro-name ((&key (type "button")) &body body)
|
`(defmacro ,macro-name ((&key (id nil) (type "button")) &body body)
|
||||||
`(btn (:type ,type :color ,,color-name :size ,,size-name) ,@body))))
|
`(btn (:id ,id :type ,type :color ,,color-name :size ,,size-name) ,@body))))
|
||||||
|
|
||||||
(defmacro define-btns (colors)
|
(defmacro define-btns (colors)
|
||||||
"This macro generates a suite of button-creating macros for each provided button type.
|
"This macro generates a suite of button-creating macros for each provided button type.
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
(deftest test-btn-macro
|
(deftest test-btn-macro
|
||||||
(testing "Testing btn macro"
|
(testing "Testing btn macro"
|
||||||
(let ((result (spinneret:with-html-string (btn (:color "primary") "foo"))))
|
(let ((result (spinneret:with-html-string (btn (:color "primary") "foo"))))
|
||||||
(ok (search "class=\"btn btn-primary\"" result)))))
|
(ok (search "class=\"btn btn-primary\"" result))
|
||||||
|
(ok (search "type=button" result)))))
|
||||||
|
|
||||||
(deftest test-btn-macro-with-type
|
(deftest test-btn-macro-with-type
|
||||||
(testing "Testing btn macro with type"
|
(testing "Testing btn macro with type"
|
||||||
|
@ -22,18 +23,33 @@
|
||||||
(ok (search "class=\"btn btn-primary\"" result))
|
(ok (search "class=\"btn btn-primary\"" result))
|
||||||
(ok (search "type=submit" result)))))
|
(ok (search "type=submit" result)))))
|
||||||
|
|
||||||
|
(deftest test-btn-macro-with-id
|
||||||
|
(testing "Testing btn macro with id"
|
||||||
|
(let ((result (spinneret:with-html-string (btn (:id "submit" :color "primary") "foo"))))
|
||||||
|
(ok (search "class=\"btn btn-primary\"" result))
|
||||||
|
(ok (search "id=submit" result)))))
|
||||||
|
|
||||||
(deftest test-btn-primary
|
(deftest test-btn-primary
|
||||||
(testing "Testing btn primary"
|
(testing "Testing btn primary"
|
||||||
(let ((result (spinneret:with-html-string (btn-primary () "foo"))))
|
(let ((result (spinneret:with-html-string (btn-primary nil "foo"))))
|
||||||
(ok (search "class=\"btn btn-primary\"" result)))))
|
(ok (search "class=\"btn btn-primary\"" result))
|
||||||
|
(ok (search "type=button" result)))))
|
||||||
|
|
||||||
(deftest test-btn-outline-primary
|
(deftest test-btn-outline-primary
|
||||||
(testing "Testing btn outline primary"
|
(testing "Testing btn outline primary without additional keywords"
|
||||||
(let ((result (spinneret:with-html-string (btn-outline-primary () "foo"))))
|
(let ((result (spinneret:with-html-string (btn-outline-primary () "foo"))))
|
||||||
(ok (search "class=\"btn btn-outline-primary\"" result)))))
|
(ok (search "class=\"btn btn-outline-primary\"" result))
|
||||||
|
(ok (search "type=button" result)))))
|
||||||
|
|
||||||
(deftest test-btn-outline-primary-with-type-submit
|
(deftest test-btn-outline-primary-with-type-submit
|
||||||
(testing "Testing btn outline primary with type submit"
|
(testing "Testing btn outline primary with type submit"
|
||||||
(let ((result (spinneret:with-html-string (btn-outline-primary (:type "submit") "foo"))))
|
(let ((result (spinneret:with-html-string (btn-outline-primary (:type "submit") "foo"))))
|
||||||
(ok (search "class=\"btn btn-outline-primary\"" result))
|
(ok (search "class=\"btn btn-outline-primary\"" result))
|
||||||
(ok (search "type=submit" result)))))
|
(ok (search "type=submit" result)))))
|
||||||
|
|
||||||
|
(deftest test-btn-outline-primary-with-id
|
||||||
|
(testing "Testing btn outline primary with id example"
|
||||||
|
(let ((result (spinneret:with-html-string (btn-outline-primary (:id "example") "foo"))))
|
||||||
|
(ok (search "class=\"btn btn-outline-primary\"" result))
|
||||||
|
(ok (search "type=button" result))
|
||||||
|
(ok (search "id=example" result)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue