Update utility function color

This commit is contained in:
Marcus Kammer 2023-07-23 14:11:03 +02:00
parent d456370f50
commit f5d4ddec59
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -53,10 +53,12 @@
(in-package :cl-sbt/utility) (in-package :cl-sbt/utility)
(defparameter *colors* '(:primary :secondary :success :danger :warning :info :light :dark :body :muted :white :transparent))
(defun string-clean (str) (defun string-clean (str)
(string-trim " " (string-downcase str))) (string-trim " " (string-downcase str)))
(defun background (&key (color nil) (gradient nil)) (defun background (&key (color :primary) (gradient nil))
"Generates a Bootstrap background class. "Generates a Bootstrap background class.
COLOR: Specifies the color, should be :primary, :secondary, :success, COLOR: Specifies the color, should be :primary, :secondary, :success,
@ -81,20 +83,25 @@ Example 3:
Example 4: Example 4:
(background :color :dark :gradient :t) (background :color :dark :gradient :t)
; This will generate a string 'bg-dark bg-gradient'" ; This will generate a string 'bg-dark bg-gradient'"
(let ((color-str (if (null color) "" (format nil "bg-~a" color))) (assert (member color *colors*) nil "Color can't be nil")
(let ((color-str (format nil "bg-~a" color))
(gradient-str (if (eq gradient :t) " bg-gradient" ""))) (gradient-str (if (eq gradient :t) " bg-gradient" "")))
(string-clean (concatenate 'string color-str gradient-str)))) (string-clean (concatenate 'string color-str gradient-str))))
(defun color (&key (text nil) (background nil)) (defun color (&key (text nil) (background nil) (emphasis nil) (body nil))
"Generates a Bootstrap color class. "Generates a Bootstrap color class.
TEXT: Specifies the color of the text. Should be 'primary', 'secondary', TEXT: Specifies the color of the text. Should be :primary, :secondary,
'success', 'danger', 'warning', 'info', 'light', 'dark', 'white', 'body', :success, :danger, :warning, :info, :light, :dark, :white, :body,
'muted', 'black-50', 'white-50', 'reset'. :muted, :reset
BACKGROUND: Specifies the color of the background. Should be 'primary', BACKGROUND: Specifies the color of the background. Should be :primary,
'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'white', :secondary, :success, :danger, :warning, :info, :light, :dark, :white,
'transparent'. :transparent.
EMPHASIS: Specifies whether the color should be emphasized or not.
BODY: Specifies whether the color of the text should be body color.
Example 1: Example 1:
(color :text :primary) (color :text :primary)
@ -110,10 +117,31 @@ Example 3:
Example 4: Example 4:
(color :text :white :background '(:color :primary)) (color :text :white :background '(:color :primary))
; This will generate a string 'text-white bg-primary'" ; This will generate a string 'text-white bg-primary'
(string-clean (concatenate 'string
(if (null text) "" (format nil "text-~a " text)) Example 5:
(if (null background) "" (apply #'background background))))) (color :text :primary :emphasis t)
; This will generate a string 'text-primary-emphasis'
Example 6:
(color :body :secondary)
; This will generate a string 'text-body-secondary'
Example 7:
(color :body t :emphasis t)
; This will generate a string 'text-body-emphasis'"
(let* ((text-str (if (null text) "" (format nil "text-~a" text)))
(background-str (if (null background) "" (apply #'background background)))
(emphasis-str (if (null emphasis) "" "-emphasis"))
(body-str (if (null body) "" (if (keywordp body)
(format nil "text-body-~a" body)
(format nil "text-body" body)))))
(string-clean (concatenate 'string
body-str
text-str
emphasis-str
(when background " ")
background-str))))
(defun opacity (&key (level nil)) (defun opacity (&key (level nil))
"Generates a Bootstrap opacity class. "Generates a Bootstrap opacity class.