// NOTE: API calls must start with 'api/' in order to serve the app at any URI 'use strict'; import { h, render, useState, useEffect, useRef, html, Router } from './bundle.js'; const Icons = { cog: props => html` `, info: props => html` `, bolt: props => html` `, home: props => html` `, save: props => html` `, bars3: props => html` `, }; function TextValue({value, setfn, disabled, placeholder, type, addonRight, addonLeft, attr, min, max, step, mult}) { const [bg, setBg] = useState('bg-white'); useEffect(() => { if (type == 'number') checkval(+min, +max, +value); }, []); step ||= '1', mult ||= 1; const checkval = function(min, max, v) { setBg('bg-white'); if (min && v < min) setBg('bg-red-100 border-red-200'); if (max && v > max) setBg('bg-red-100 border-red-200'); }; const m = step.match(/^.+\.(.+)/); const digits = m ? m[1].length : 0; const onchange = ev => { let v = ev.target.value; if (type == 'number') { checkval(+min, +max, +v); v = +(parseFloat(v) / mult).toFixed(digits); } setfn(v); }; if (type == 'number') value = +(value * mult).toFixed(digits); return html`
${addonLeft && html`${addonLeft}` } ${addonRight && html`${addonRight}` } `; }; function SelectValue({value, setfn, options, disabled}) { const toInt = x => x == parseInt(x) ? parseInt(x) : x; const onchange = ev => setfn(toInt(ev.target.value)); return html`