dev.metalisp.sbt/docs/component/accordion.org
2024-02-06 10:12:13 +01:00

111 lines
6.1 KiB
Org Mode

#+title: Using dev.metalisp.sbt/component/accordion Macros in a Web Application
#+author: Marcus Kammer
#+email: marcus.kammer@mailbox.org
#+date: 2024-02-06T10:12+01:00
* Introduction
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.
** Bootstrap Accordions
[[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 dev.metalisp.sbt/component/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:
#+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)
(:export :generate-accordion-page))
(in-package :my-web-accordion-app)
(defun generate-accordion-page ()
"Generates an HTML page with accordion using accordion macros."
(with-output-to-string (spinneret:*html*)
(with-page (:title "Accordion Example" :main-con t)
(accordion (:id "firstAccordion")
"What is the purpose of this website?"
"This website is designed to provide information and resources on various topics related to user experience, design thinking, and agile methodologies."
"How can I contact the support team?"
"You can reach our support team by sending an email to support@example.com. We'll be happy to assist you with any questions or issues you may have."
"Is there a mobile app available?"
"Yes, we have a mobile app available for both iOS and Android devices. You can download it from the App Store or Google Play Store."
"What payment methods do you accept?"
"We accept payments through credit cards, PayPal, and bank transfers. You can choose the payment method that suits you best during the checkout process."
"How do I reset my password?"
"To reset your password, go to the login page and click on the 'Forgot Password' link. Follow the instructions sent to your registered email address to create a new password."
"Can I contribute to your knowledge sharing initiatives?"
"Absolutely! We encourage contributions from our community. You can participate in our knowledge sharing initiatives by joining our forums and sharing your insights and experiences."
"What is the schedule for upcoming webinars and events?"
"You can find the schedule for upcoming webinars and events on our Events page. We regularly update it with details of upcoming sessions.")
(accordion (:id "secondAccordion")
"What is the purpose of this website?"
"This website is designed to provide information and resources on various topics related to user experience, design thinking, and agile methodologies."
"How can I contact the support team?"
"You can reach our support team by sending an email to support@example.com. We'll be happy to assist you with any questions or issues you may have."
"Is there a mobile app available?"
"Yes, we have a mobile app available for both iOS and Android devices. You can download it from the App Store or Google Play Store."
"What payment methods do you accept?"
"We accept payments through credit cards, PayPal, and bank transfers. You can choose the payment method that suits you best during the checkout process."
"How do I reset my password?"
"To reset your password, go to the login page and click on the 'Forgot Password' link. Follow the instructions sent to your registered email address to create a new password."
"Can I contribute to your knowledge sharing initiatives?"
"Absolutely! We encourage contributions from our community. You can participate in our knowledge sharing initiatives by joining our forums and sharing your insights and experiences."
"What is the schedule for upcoming webinars and events?"
"You can find the schedule for upcoming webinars and events on our Events page. We regularly update it with details of upcoming sessions."))))
(format t (generate-accordion-page))
#+end_src
#+RESULTS: accordion-page
[[file:accordion-page.html]]
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.