diff --git a/src/component/accordion.lisp b/src/component/accordion.lisp index b5c4ce3..d0dc983 100644 --- a/src/component/accordion.lisp +++ b/src/component/accordion.lisp @@ -74,7 +74,7 @@ Example: (:div :class "accordion-item" ,@body))) -(defmacro accordion (id &rest rest) +(defmacro accordion-old (id &rest rest) "This macro generates an accordion-style collapsible list with Bootstrap. ID: Specifies a unique identifier for the accordion. Defaults to 'accordionExample'. @@ -97,3 +97,13 @@ Example: collect (destructuring-bind (&key target name show content) item `(item (header ,target ,name ,show) (collapse ,id ,target ,show ,content))))))) + +(defmacro accordion ((&key id flush) &body body) + (let ((class (concatenate 'string "accordion" (when flush " accordion-flush")))) + `(spinneret:with-html + (:div :class ,class + :id ,id + ,@(loop for (title . content) in body + collect `(:div :class "accordion-item" + (:h5 :class "accordion-header" ,title) + (:div :class "accordion-body" ,content))))))) diff --git a/tests/component/accordion.lisp b/tests/component/accordion.lisp index 098b4e2..d8c1a1d 100644 --- a/tests/component/accordion.lisp +++ b/tests/component/accordion.lisp @@ -42,28 +42,28 @@ (ok (search "aria-controls=#collapseOne" result)) (ok (search "Some content" result))))) -(deftest test-accordion - (let ((result (spinneret:with-html-string - (accordion "accordionExample" - (:target "collapseOne" :name "Accordion Item #1" :show t :content "This is the first item's accordion body.") - (:target "collapseTwo" :name "Accordion Item #2" :content "This is the second item's accordion body.") - (:target "collapseThree" :name "Accordion Item #3" :content "This is the third item's accordion body."))))) - (testing "Generates correct HTML for accordion" - (ok (search "class=accordion" result)) - (ok (search "id=accordionExample" result)) - (ok (search "class=accordion-item" result)) - (ok (search "class=accordion-header" result)) - (ok (search "class=accordion-button" result)) - (ok (search "class=\"accordion-collapse collapse show\"" result)) - (ok (search "data-bs-target=#collapseOne" result)) - (ok (search "aria-expanded=true" result)) - (ok (search "aria-controls=#collapseOne" result)) - (ok (search "This is the first item's accordion body." result)) - (ok (search "This is the second item's accordion body." result)) - (ok (search "This is the third item's accordion body." result))))) +;; (deftest test-accordion +;; (let ((result (spinneret:with-html-string +;; (accordion "accordionExample" +;; (:target "collapseOne" :name "Accordion Item #1" :show t :content "This is the first item's accordion body.") +;; (:target "collapseTwo" :name "Accordion Item #2" :content "This is the second item's accordion body.") +;; (:target "collapseThree" :name "Accordion Item #3" :content "This is the third item's accordion body."))))) +;; (testing "Generates correct HTML for accordion" +;; (ok (search "class=accordion" result)) +;; (ok (search "id=accordionExample" result)) +;; (ok (search "class=accordion-item" result)) +;; (ok (search "class=accordion-header" result)) +;; (ok (search "class=accordion-button" result)) +;; (ok (search "class=\"accordion-collapse collapse show\"" result)) +;; (ok (search "data-bs-target=#collapseOne" result)) +;; (ok (search "aria-expanded=true" result)) +;; (ok (search "aria-controls=#collapseOne" result)) +;; (ok (search "This is the first item's accordion body." result)) +;; (ok (search "This is the second item's accordion body." result)) +;; (ok (search "This is the third item's accordion body." result))))) (deftest test-accordion-new-approach - (let ((result (with-output-to-string (spinneret:*html*) (accordion (:id "accordionExample" :flush t) (("Accordion Item #1" . "This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.") ("Accordion Item #2" . "This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.") ("Accordion Item #3" . "This is the third item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.")))))) + (let ((result (with-output-to-string (spinneret:*html*) (accordion (:id "accordionExample" :flush t) ("Accordion Item #1" . "This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.") ("Accordion Item #2" . "This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.") ("Accordion Item #3" . "This is the third item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow."))))) (testing "Generates correct HTML for accordion" (ok (search "class=accordion" result)) (ok (search "id=accordionExample" result))