Rename select -> combo

This commit is contained in:
Marcus Kammer 2023-09-17 15:26:15 +02:00
parent 7fe512e3e5
commit ffee1dda67
Signed by: marcuskammer
GPG key ID: C374817BE285268F
3 changed files with 21 additions and 21 deletions

View file

@ -20,10 +20,10 @@
:cl-sbt/utility :cl-sbt/utility
:spacing) :spacing)
(:export (:export
:select :combo
:select-lg :combo-lg
:select-sm :combo-sm
:select-multiple :combo-multiple
:checkable :checkable
:checkable-radio :checkable-radio
:checkable-checkbox :checkable-checkbox
@ -170,7 +170,7 @@ LABEL: The label to display next to the control."
:type type :type type
:name name-str))))) :name name-str)))))
(defmacro select ((&key size multiple) &body body) (defmacro combo ((&key size multiple) &body body)
"This macro generates a Bootstrap select dropdown menu. "This macro generates a Bootstrap select dropdown menu.
SIZE: Specifies the size of the select menu. It can be a string indicating the SIZE: Specifies the size of the select menu. It can be a string indicating the
@ -183,10 +183,10 @@ the list that should be visible at one time.
REST: The contents of the select menu, typically options. REST: The contents of the select menu, typically options.
Example 1: Example 1:
(select (:size \"sm\") \"Red\" \"Green\" \"Blue\" (combo (:size \"sm\") \"Red\" \"Green\" \"Blue\"
Example 2: Example 2:
(select (:multiple 3) \"Red\" \"Green\" \"Blue\"" (combo (:multiple 3) \"Red\" \"Green\" \"Blue\""
(let ((class-attr (cond ((stringp size) (let ((class-attr (cond ((stringp size)
(format nil "form-select form-select-~a" size)) (format nil "form-select form-select-~a" size))
(t "form-select")))) (t "form-select"))))
@ -201,27 +201,27 @@ Example 2:
(let ((value-prop-str (build-value-prop-str item))) (let ((value-prop-str (build-value-prop-str item)))
`(:option :value ,value-prop-str ,item))))))) `(:option :value ,value-prop-str ,item)))))))
(defmacro select-multiple (rows &body body) (defmacro combo-multiple (rows &body body)
`(select (:multiple ,rows) ,@body)) `(combo (:multiple ,rows) ,@body))
(defmacro define-select (size) (defmacro define-combo (size)
"Defines a new select macro tailored for a given size. "Defines a new select macro tailored for a given size.
SIZE: A string that specifies the size ('lg' for large, 'sm' for small)." SIZE: A string that specifies the size ('lg' for large, 'sm' for small)."
(let ((macro-name (intern (string-upcase (concatenate 'string "SELECT-" size))))) (let ((macro-name (intern (string-upcase (concatenate 'string "COMBO-" size)))))
`(defmacro ,macro-name (&body body) `(defmacro ,macro-name (&body body)
`(select (:size ,,size) ,@body)))) `(combo (:size ,,size) ,@body))))
(defmacro define-selects (sizes) (defmacro define-combos (sizes)
"Generates multiple select macros based on the provided list of sizes. "Generates multiple select macros based on the provided list of sizes.
SIZES: A list of strings that specifies the sizes for which to generate select SIZES: A list of strings that specifies the sizes for which to generate select
macros." macros."
`(progn `(progn
,@(loop for size in sizes ,@(loop for size in sizes
collect `(define-select ,size)))) collect `(define-combo ,size))))
(define-selects ("lg" "sm")) (define-combos ("lg" "sm"))
(defun search-form () (defun search-form ()
"This function generates a general-purpose search form. "This function generates a general-purpose search form.

View file

@ -23,7 +23,7 @@
:cl-sbt/form :cl-sbt/form
:checkable :checkable
:ctrl :ctrl
:select) :combo)
(:export (:export
:question :question
:questionnaire)) :questionnaire))
@ -95,7 +95,7 @@ Returns:
(resolve-input-and-choices choice) (resolve-input-and-choices choice)
(if (string= type "combo") (if (string= type "combo")
`(spinneret:with-html `(spinneret:with-html
(:li (select () ,@inputs))) (:li (combo () ,@inputs)))
`(spinneret:with-html `(spinneret:with-html
,@(loop for input in inputs ,@(loop for input in inputs
collect collect

View file

@ -6,16 +6,16 @@
(:import-from (:import-from
:cl-sbt/form :cl-sbt/form
:ctrl :ctrl
:select :combo
:select-sm :combo-sm
:select-lg :combo-lg
:search-form :search-form
:checkable)) :checkable))
(in-package :cl-sbt/tests/form) (in-package :cl-sbt/tests/form)
(deftest test-select-default (deftest test-select-default
(let ((result (spinneret:with-html-string (select () "Red" "Green" "Blue")))) (let ((result (spinneret:with-html-string (combo () "Red" "Green" "Blue"))))
(testing "Generates correct HTML for select element" (testing "Generates correct HTML for select element"
(ok (search "class=form-select" result)) (ok (search "class=form-select" result))
(ok (search "option value=red" result)) (ok (search "option value=red" result))