(define-module (calp html components) :use-module (hnh util) :use-module (ice-9 curried-definitions) :use-module (ice-9 match) :export (xhtml-doc) ) ;; Wraps a number of sxml forms into a valid sxhtml-tree. (define-syntax xhtml-doc (syntax-rules (@) ((_ (@ attr ...) body ...) `(*TOP* (*PI* xml "version=\"1.0\" encoding=\"utf-8\"") (html (@ (xmlns "http://www.w3.org/1999/xhtml") attr ...) body ...))) ((_ body ...) (xhtml-doc (@) body ...)))) ;; Add a slider with an associated number input. Keeps the two in check. ;; Uses the js function setVar (which must be provided elsewhere) ;; set the the value of @var{variable}. (define*-public (slider-input key: variable (min 0) (max 10) (step 1) (value 1) (unit "")) (let ((groupname (symbol->string (gensym "slider")))) `(div (@ (class "input-group")) (script "function " ,groupname "fn (value) {" "setVar('" ,variable "', value + '" ,unit "');" "for (let el of document.getElementsByClassName('" ,groupname "')) {" " el.value = value;" "}}") (input (@ (type "range") (class ,groupname) (min ,min) (max ,max) (step ,step) (value ,value) (oninput ,groupname "fn(this.value)") )) (input (@ (type "number") (class ,groupname) (min ,min) (max ,max) (step ,step) (value ,value) (oninput ,groupname "fn(this.value)")) )))) ;; Generates a button or button-like link. ;; TODO
inside