Generate alert macros

This commit is contained in:
Marcus Kammer 2023-07-13 12:57:05 +02:00
parent 25ad37aade
commit e6e6eeb0bb

View file

@ -28,7 +28,23 @@
(:use :cl) (:use :cl)
(:export (:export
:btn :btn
:alert)) :alert
:alert-primary
:alert-secondary
:alert-success
:alert-danger
:alert-warning
:alert-info
:alert-light
:alert-dark
:alert-dismiss-primary
:alert-dismiss-secondary
:alert-dismiss-success
:alert-dismiss-danger
:alert-dismiss-warning
:alert-dismiss-info
:alert-dismiss-light
:alert-dismiss-dark))
(in-package :cl-sbt-alert) (in-package :cl-sbt-alert)
@ -44,10 +60,9 @@
(defmacro alert ((&key (type "primary") (dismissible nil)) &body body) (defmacro alert ((&key (type "primary") (dismissible nil)) &body body)
"This macro generates a Bootstrap alert component. "This macro generates a Bootstrap alert component.
Parameters: TYPE: Specifies the alert type. Can be 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', or 'dark'. Defaults to 'primary'.
- TYPE: Specifies the alert type. Can be 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', or 'dark'. Defaults to 'primary'. DISMISSIBLE: Specifies whether the alert is dismissible. If true, the alert includes a close button.
- DISMISSIBLE: Specifies whether the alert is dismissible. If true, the alert includes a close button. BODY: Specifies the content of the alert."
- BODY: Specifies the content of the alert."
`(spinneret:with-html `(spinneret:with-html
(:div :role "alert" (:div :role "alert"
@ -56,50 +71,31 @@
,(if (null dismissible) nil `(btn)) ,(if (null dismissible) nil `(btn))
,@body))) ,@body)))
;; (defmacro alert-primary (&body body) (defmacro define-alert (type &optional (dismissible nil))
;; `(alert (:type "primary") ,@body)) "This macro defines a new macro for creating a Bootstrap alert of a specific type.
;; (defmacro alert-secondary (&body body) TYPE: The type of the alert (like 'primary', 'secondary', 'success', etc.).
;; `(alert (:type "secondary") ,@body)) DISMISSIBLE: (optional) Whether the alert should be dismissible.
;; (defmacro alert-success (&body body) The newly defined macro, when called, will generate HTML for a Bootstrap
;; `(alert (:type "success") ,@body)) alert of the specified type and dismissibility."
;; (defmacro alert-danger (&body body) (let* ((macro-name (intern (string-upcase (concatenate 'string "ALERT-" (if (null dismissible) "" "DISMISS-") type)))))
;; `(alert (:type "danger") ,@body)) `(defmacro ,macro-name (&body body)
`(alert (:type ,,type :dismissible ,,dismissible) ,@body))))
;; (defmacro alert-warning (&body body) (defmacro define-alerts (names)
;; `(alert (:type "warning") ,@body)) "This macro generates specific alert macros based on the provided names.
;; (defmacro alert-info (&body body) NAMES: A list of alert type names. For each name in this list, a macro will
;; `(alert (:type "info") ,@body)) be generated: a non-dismissible alert and a dismissible alert of the
specified type."
;; (defmacro alert-light (&body body) `(progn
;; `(alert (:type "light") ,@body)) ,@(loop for item in names
for type-name = (string-downcase (string item))
collect `(progn
(define-alert ,type-name)
(define-alert ,type-name t)))))
;; (defmacro alert-dark (&body body) (define-alerts (primary secondary success danger warning info light dark))
;; `(alert (:type "dark") ,@body))
;; (defmacro alert-primary-dismiss (&body body)
;; `(alert (:type "primary" :dismissible t) ,@body))
;; (defmacro alert-secondary-dismiss (&body body)
;; `(alert (:type "secondary" :dismissible t) ,@body))
;; (defmacro alert-success-dismiss (&body body)
;; `(alert (:type "success" :dismissible t) ,@body))
;; (defmacro alert-danger-dismiss (&body body)
;; `(alert (:type "danger" :dismissible t) ,@body))
;; (defmacro alert-warning-dismiss (&body body)
;; `(alert (:type "warning" :dismissible t) ,@body))
;; (defmacro alert-info-dismiss (&body body)
;; `(alert (:type "info" :dismissible t) ,@body))
;; (defmacro alert-light-dismiss (&body body)
;; `(alert (:type "light" :dismissible t) ,@body))
;; (defmacro alert-dark-dismiss (&body body)
;; `(alert (:type "dark" :dismissible t) ,@body))