dev.metalisp.sbt/src/component/alert.lisp

106 lines
3.8 KiB
Common Lisp
Raw Normal View History

2023-07-09 09:03:27 +02:00
;; https://getbootstrap.com/docs/5.3/components/alerts/
2023-07-11 16:17:51 +02:00
;; The Bootstrap Alert component is a flexible, dismissible container for
;; displaying important, often short, messages to the user. It's primarily used
;; for system messaging.
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; The Alerts are available for various types and states. They can be of different
;; types such as success, info, warning, danger, primary, secondary, light, and
;; dark to indicate the nature of the alert. Each type is visually distinguished
;; by a different color.
;; The content inside an alert can be nearly any valid HTML, including headings,
;; paragraphs, and links.
;; By adding an optional .alert-dismissible class to the alert container, and a
;; close button, an alert can be made dismissible - it will disappear when the
;; user clicks the close button. This is especially useful for ephemeral messages
;; like form validation errors, where the message does not need to persist once
;; the user has seen it.
;; Here is a basic example of a Bootstrap Alert component:
;; <div class="alert alert-warning alert-dismissible fade show" role="alert">
;; <strong>Warning!</strong> You should check in on some of those fields below.
;; <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
;; </div>
(defpackage cl-sbt-alert
(:use :cl)
(:export
:btn
:alert))
(in-package :cl-sbt-alert)
(defmacro btn ()
"This macro generates the close button used in a Bootstrap alert when it is set to be dismissible."
2023-07-01 11:28:25 +02:00
2023-07-09 09:03:27 +02:00
`(spinneret:with-html
(:button :type "button"
:class "btn-close"
:data-bs-dismiss "alert"
:aria-label "Close")))
2023-07-11 16:31:35 +02:00
(defmacro alert ((&key (type "primary") (dismissible nil)) &body body)
2023-07-11 16:17:51 +02:00
"This macro generates a Bootstrap alert component.
Parameters:
2023-07-11 16:31:35 +02:00
- TYPE: Specifies the alert type. Can be 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', or 'dark'. Defaults to 'primary'.
2023-07-11 16:17:51 +02:00
- DISMISSIBLE: Specifies whether the alert is dismissible. If true, the alert includes a close button.
- BODY: Specifies the content of the alert."
2023-07-01 11:28:25 +02:00
`(spinneret:with-html
2023-07-08 22:25:20 +02:00
(:div :role "alert"
2023-07-11 16:17:51 +02:00
:class ,(concatenate 'string (format nil "alert alert-~a" type)
(if (null dismissible) nil " alert-dismissible"))
,(if (null dismissible) nil `(btn))
2023-07-08 22:25:20 +02:00
,@body)))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-primary (&body body)
;; `(alert (:type "primary") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-secondary (&body body)
;; `(alert (:type "secondary") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-success (&body body)
;; `(alert (:type "success") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-danger (&body body)
;; `(alert (:type "danger") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-warning (&body body)
;; `(alert (:type "warning") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-info (&body body)
;; `(alert (:type "info") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-light (&body body)
;; `(alert (:type "light") ,@body))
2023-07-01 13:16:55 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-dark (&body body)
;; `(alert (:type "dark") ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-primary-dismiss (&body body)
;; `(alert (:type "primary" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-secondary-dismiss (&body body)
;; `(alert (:type "secondary" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-success-dismiss (&body body)
;; `(alert (:type "success" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-danger-dismiss (&body body)
;; `(alert (:type "danger" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-warning-dismiss (&body body)
;; `(alert (:type "warning" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-info-dismiss (&body body)
;; `(alert (:type "info" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-light-dismiss (&body body)
;; `(alert (:type "light" :dismissible t) ,@body))
2023-07-09 09:03:27 +02:00
2023-07-11 16:17:51 +02:00
;; (defmacro alert-dark-dismiss (&body body)
;; `(alert (:type "dark" :dismissible t) ,@body))