Update make-grid-class
This commit is contained in:
parent
39848853b8
commit
55253c35a7
1 changed files with 47 additions and 43 deletions
|
@ -564,9 +564,14 @@ Example 3:
|
|||
(defun combine-classes (&rest class-specs)
|
||||
(string-trim " " (format nil "~{~a ~}" (remove nil class-specs))))
|
||||
|
||||
(defun validate-col-value-p (value)
|
||||
"Validate column-related numeric values."
|
||||
(when (and (integerp value)
|
||||
(<= 0 value 12))
|
||||
t))
|
||||
|
||||
(defun make-grid-class (&key
|
||||
row
|
||||
cols
|
||||
col
|
||||
xs
|
||||
sm
|
||||
|
@ -583,6 +588,8 @@ Example 3:
|
|||
order)
|
||||
"Return a css class as string according to Bootstrap Grid System.
|
||||
|
||||
---
|
||||
|
||||
Bootstrap’s grid system can adapt across all six default breakpoints, and any
|
||||
breakpoints you customize. The six default grid tiers are as follows:
|
||||
|
||||
|
@ -593,56 +600,53 @@ breakpoints you customize. The six default grid tiers are as follows:
|
|||
- Extra large (xl) ≥1200px
|
||||
- Extra extra large (xxl) ≥1400px
|
||||
|
||||
All number values has to be >= 0 or <= 12
|
||||
except for gutters (:g :gx :gy) values has to be >= 0 or <= 5
|
||||
---
|
||||
|
||||
ALIGN-ITEMS: \"start\", \"center\", \"end\"
|
||||
ALIGN-SELF: \"start\", \"center\", \"end\"
|
||||
JUSTIFY-CONTENT: \"start\", \"center\", \"end\", \"around\", \"between\", \"evenly\"
|
||||
|
||||
Example:
|
||||
(make-grid-class :row t :cols 2 :sm 2) -> \"row row-cols-2 row-cols-sm-2\"
|
||||
(make-grid-class :cols 2) -> \"row row-cols-2\"
|
||||
(make-grid-class :col 5) -> \"col-5\"
|
||||
(make-grid-class :row t) -> \"row\"
|
||||
(make-grid-class :row 2) -> \"row row-cols-2\"
|
||||
(make-grid-class :row 2 :sm 2) -> \"row row-cols-2 row-cols-sm-2\"
|
||||
(make-grid-class :col 5) -> \"col col-5\"
|
||||
(make-grid-class :col t :xs 12 :sm 6 :md :auto) -> \"col col-xs-12 col-sm-6 col-md-auto\"
|
||||
(make-grid-class :col :auto :sm t) -> \"col-auto col-sm\"
|
||||
(make-grid-class :col :auto) -> \"col-auto\"
|
||||
(make-grid-class :col \"auto\" :sm t) -> \"col col-auto col-sm\"
|
||||
(make-grid-class :col \"auto\") -> \"col col-auto\"
|
||||
(make-grid-class :sm 2) -> \"col-sm-2\"
|
||||
(make-grid-class :row t :col t) -> error
|
||||
(make-grid-class :col -1) -> error
|
||||
(make-grid-class :col 13) -> error
|
||||
(make-grid-class :g 0) -> \"row g-0\""
|
||||
|
||||
;; First validate input
|
||||
(when (and row col)
|
||||
(cond ((and row col)
|
||||
(error "Cannot specify both :row and :col"))
|
||||
((and row align-self)
|
||||
(error "Cannot specify both :row and :align-self"))
|
||||
((and col (or g gx gy))
|
||||
(error "Cannot specify both :col and gutters (:g :gx :gy)"))
|
||||
((and col justify-content)
|
||||
(error "Cannot specify both :col and :justify-content"))
|
||||
((and col align-items)
|
||||
(error "Cannot specify both :col and :align-items"))
|
||||
((not (or row col))
|
||||
(error "Specify at least :row or :col")))
|
||||
|
||||
(let ((class-strings '())
|
||||
(breakpoints
|
||||
(loop :for (key value) :on `(:xs ,xs :sm ,sm :md ,md :lg ,lg :xl ,xl :xxl ,xxl)
|
||||
:by #'cddr
|
||||
:when value :nconc (list key value))))
|
||||
|
||||
(let ((classes '()))
|
||||
;; Handle row cases
|
||||
(when row
|
||||
(push "row" classes)
|
||||
(when cols
|
||||
(push (format nil "row-cols-~a" cols) classes)))
|
||||
(push "row" class-strings)
|
||||
(push (format nil "~{row-cols-~(~A~)-~A~^ ~}" breakpoints) class-strings)
|
||||
(when (or (stringp row) (validate-col-value-p row))
|
||||
(push (format nil "row-cols-~A" row) class-strings)))
|
||||
|
||||
;; Handle column cases
|
||||
(when (or col xs sm md lg xl xxl)
|
||||
;; Base col class
|
||||
(push (if (numberp col)
|
||||
(format nil "col-~a" col)
|
||||
(when col "col"))
|
||||
classes))
|
||||
(when col
|
||||
(push "col" class-strings)
|
||||
(push (format nil "~{col-~(~A~)-~A~^ ~}" breakpoints) class-strings)
|
||||
(when (or (stringp col) (validate-col-value-p col))
|
||||
(push (format nil "col-~A" col) class-strings)))
|
||||
|
||||
;; Handle breakpoint-specific classes
|
||||
(flet ((add-breakpoint (prefix value)
|
||||
(when value
|
||||
(push (format nil "col-~a-~a"
|
||||
prefix
|
||||
(if (eq value t) ""
|
||||
(if (eq value :auto) "auto" value)))
|
||||
classes))))
|
||||
(add-breakpoint "xs" xs)
|
||||
(add-breakpoint "sm" sm)
|
||||
(add-breakpoint "md" md)
|
||||
(add-breakpoint "lg" lg)
|
||||
(add-breakpoint "xl" xl)
|
||||
(add-breakpoint "xxl" xxl))
|
||||
|
||||
;; Combine all classes, removing nil values and reversing to maintain order
|
||||
(string-trim " " (format nil "~{~a~^ ~}"
|
||||
(remove nil (nreverse classes))))))
|
||||
(format nil "~{~A~^ ~}" class-strings)))
|
||||
|
|
Loading…
Add table
Reference in a new issue