Update accordion

This commit is contained in:
Marcus Kammer 2023-07-08 22:09:06 +02:00
parent 9a21cc255a
commit 57a33029e3
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -2,17 +2,25 @@
(in-package :cl-sbt) (in-package :cl-sbt)
(defmacro accordion-header (target name) (defmacro accordion-header (target name show)
`(spinneret:with-html `(spinneret:with-html
(:h2 :class "accordion-header" (:h2 :class "accordion-header"
(:button :class "accordion-button" (:button :class "accordion-button"
:type "button" :type "button"
:data-bs-toggle "collapse" :data-bs-toggle "collapse"
:data-bs-target (format nil "#~a" ,target) :data-bs-target (format nil "#~a" ,target)
:aria-expanded "true" :aria-expanded ,(if show "true" "false")
:aria-controls "collapseOne" :aria-controls (format nil "#~a" ,target)
,name)))) ,name))))
(defmacro accordion-collapse (parent id show &body body)
`(spinneret:with-html
(:div :id ,id
:class ,(concatenate 'string "accordion-collapse collapse" (when show " show"))
:data-bs-parent (format nil "#~a" ,parent)
(:div :class "accordion-body"
,@body))))
(defmacro accordion-item (&body body) (defmacro accordion-item (&body body)
`(spinneret:with-html `(spinneret:with-html
(:div :class "accordion-item" (:div :class "accordion-item"
@ -23,5 +31,13 @@
(:div :class "accordion" (:div :class "accordion"
:id ,id :id ,id
,@(loop for item in rest ,@(loop for item in rest
collect (destructuring-bind (&key target name) item collect (destructuring-bind (&key target name show content) item
`(accordion-item (accordion-header ,target ,name))))))) `(accordion-item (accordion-header ,target ,name ,show)
(accordion-collapse ,id ,target ,show ,content)))))))
(defun show-accordion-example ()
"Show an generated accordion example"
(accordion (:id "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 second item's accordion body.")))