Define first version of make-grid-class
This commit is contained in:
parent
92474c6755
commit
150a73752a
1 changed files with 83 additions and 0 deletions
|
@ -563,3 +563,86 @@ Example 3:
|
|||
|
||||
(defun combine-classes (&rest class-specs)
|
||||
(string-trim " " (format nil "~{~a ~}" (remove nil class-specs))))
|
||||
|
||||
(defun make-grid-class (&key
|
||||
row
|
||||
cols
|
||||
col
|
||||
xs
|
||||
sm
|
||||
md
|
||||
lg
|
||||
xl
|
||||
xxl
|
||||
g
|
||||
gx
|
||||
gy
|
||||
align-items
|
||||
align-self
|
||||
justify-content
|
||||
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:
|
||||
|
||||
- Extra small (xs) <576px
|
||||
- Small (sm) ≥576px
|
||||
- Medium (md) ≥768px
|
||||
- Large (lg) ≥992px
|
||||
- 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
|
||||
|
||||
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 :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 :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)
|
||||
(error "Cannot specify both :row and :col"))
|
||||
|
||||
(let ((classes '()))
|
||||
;; Handle row cases
|
||||
(when row
|
||||
(push "row" classes)
|
||||
(when cols
|
||||
(push (format nil "row-cols-~a" cols) classes)))
|
||||
|
||||
;; 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))
|
||||
|
||||
;; 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))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue