dev.metalisp.sbt/docs/component/accordion.org

69 lines
3.9 KiB
Org Mode
Raw Normal View History

2023-09-01 12:42:01 +02:00
#+title: Using cl-sbt/accordion Macros in a Web Application
2023-09-01 13:44:50 +02:00
#+author: Marcus Kammer
#+email: marcus.kammer@mailbox.org
2024-02-04 15:13:35 +01:00
#+date: 2024-02-04T13:09+01:00
2023-09-01 13:44:50 +02:00
* Introduction
2023-09-01 12:42:01 +02:00
2023-09-01 13:44:50 +02:00
The accordion component is a popular UI element that helps to organize and
present content in a space-efficient manner. Accordions consist of a list of
headers that users can click on to toggle the visibility of associated content.
This is particularly useful for presenting large amounts of information in a
confined space while keeping the interface clean and uncluttered. The Accordion
component is perfect for FAQ sections, multi-part forms, or any situation where
you need to present the user with a range of options or information, but you
want to keep the interface uncluttered by hiding content that isn't immediately
necessary.
2023-09-01 12:42:01 +02:00
2023-09-01 13:44:50 +02:00
** Bootstrap Accordions
2023-09-01 12:42:01 +02:00
2023-09-01 13:44:50 +02:00
[[https://getbootstrap.com/docs/][Bootstrap]] is a popular front-end framework that provides ready-to-use
components for building responsive and modern web applications. One of its
components is the [[https://getbootstrap.com/docs/5.3/components/accordion/][accordion]], which enhances the user experience by providing a
user-friendly way to display and interact with content.
*** How Bootstrap Accordions Work
Bootstrap accordions are created using HTML, CSS, and JavaScript. The Bootstrap
JavaScript library adds the necessary interactivity to the accordion. Here's
how it works:
- Each accordion item consists of a header and content section.
- Clicking on an accordion item's header toggles the visibility of its content.
- By default, only one item's content is visible at a time. Clicking on a
header closes any open content before opening the clicked item's content.
- Bootstrap's JavaScript library manages the animations and transitions for
smooth content expansion and collapse.
* Integrating cl-sbt/accordion Macros
To create Bootstrap-style accordions in your Common Lisp web application, you
can use the cl-sbt/accordion macros. These macros provide a convenient way to
generate the necessary HTML structure for accordion components. Here's how you
can integrate them into your project:
2024-02-04 15:13:35 +01:00
#+name: accordion-page
#+begin_src lisp :results output file :file-ext html
(defpackage my-web-accordion-app
(:use :cl)
(:import-from :dev.metalisp.sbt :with-page)
(:import-from :dev.metalisp.sbt/component/accordion :accordion)
2023-09-01 13:44:50 +02:00
(:export :generate-accordion-page))
2024-02-04 15:13:35 +01:00
(in-package :my-web-accordion-app)
2023-09-01 13:44:50 +02:00
(defun generate-accordion-page ()
2024-02-04 15:13:35 +01:00
"Generates an HTML page with accordion using accordion macros."
(with-output-to-string (spinneret:*html*)
(with-page (:title "Accordion Example" :main-con t)
(accordion ()
("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.")))))
2023-09-01 13:44:50 +02:00
2024-02-04 15:13:35 +01:00
(format t (generate-accordion-page))
2023-09-01 12:42:01 +02:00
#+end_src
This example demonstrates how to integrate the cl-sbt/accordion macros into a
web application to create an interactive accordion component. The macros help
generate the necessary HTML structure for the accordion, which allows users to
navigate through content conveniently.