No need for a special select-option function
This commit is contained in:
parent
6713c7b76e
commit
1874907734
1 changed files with 6 additions and 20 deletions
|
@ -84,21 +84,7 @@ Example:
|
||||||
:id ,id
|
:id ,id
|
||||||
:placeholder ,placeholder)))))))
|
:placeholder ,placeholder)))))))
|
||||||
|
|
||||||
(defmacro select-option (&rest rest)
|
(defmacro select ((&key size) &rest rest)
|
||||||
"This macro generates option elements for a select dropdown.
|
|
||||||
|
|
||||||
CONTENT: The text content displayed for the option.
|
|
||||||
|
|
||||||
VALUE: The value of the option that gets sent when the form is submitted.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
(select-option (:content \"Option 1\" :value \"opt1\"))"
|
|
||||||
`(spinneret:with-html
|
|
||||||
,@(loop for item in rest
|
|
||||||
collect (destructuring-bind (&key content value) item
|
|
||||||
`(:option :value ,value ,content)))))
|
|
||||||
|
|
||||||
(defmacro select ((&key size) &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 number specifying the
|
SIZE: Specifies the size of the select menu. It can be a number specifying the
|
||||||
|
@ -111,20 +97,20 @@ BODY: The contents of the select menu, typically options.
|
||||||
Example:
|
Example:
|
||||||
(select (:size \"sm\")
|
(select (:size \"sm\")
|
||||||
(:content \"Option 1\" :value \"opt1\"))"
|
(:content \"Option 1\" :value \"opt1\"))"
|
||||||
(let ((class-attr (cond ((null size) "form-select")
|
(let ((class-attr (cond ((and (stringp size)
|
||||||
((numberp size) "form-select")
|
|
||||||
((and (stringp size)
|
|
||||||
(string= size "multiple")) "form-select")
|
(string= size "multiple")) "form-select")
|
||||||
((stringp size)
|
((stringp size)
|
||||||
(format nil "form-select form-select-~a" size))
|
(format nil "form-select form-select-~a" size))
|
||||||
(t (error "Invalid size specification: ~a" size)))))
|
(t "form-select"))))
|
||||||
`(spinneret:with-html
|
`(spinneret:with-html
|
||||||
(:select :class ,class-attr
|
(:select :class ,class-attr
|
||||||
,@(when (numberp size) `(:size ,size))
|
,@(when (numberp size) `(:size ,size))
|
||||||
,@(when (and (stringp size) (string= size "multiple")) (list :multiple t))
|
,@(when (and (stringp size) (string= size "multiple")) (list :multiple t))
|
||||||
:aria-label "Default select example"
|
:aria-label "Default select example"
|
||||||
(:option :selected t "Open this selected menu")
|
(:option :selected t "Open this selected menu")
|
||||||
(select-option ,@body)))))
|
,@(loop for item in rest
|
||||||
|
collect (destructuring-bind (&key content value) item
|
||||||
|
`(:option :value ,value ,content)))))))
|
||||||
|
|
||||||
(defun choice (text name type)
|
(defun choice (text name type)
|
||||||
"This macro generates a list item for an answer option in a question.
|
"This macro generates a list item for an answer option in a question.
|
||||||
|
|
Loading…
Add table
Reference in a new issue