05 plugin.js (3/5)
function control(f) {
const attrs = `data-k="${f.key}" id="${api.name}-${f.key}"`;
if (f.type === 'select') {
return `<select ${attrs}>${f.options.map(([v, t]) => `<option value="${esc(v)}">${esc(t)}</option>`).join('')}</select>`;
}
if (f.type === 'checkbox') {
return `<label class="toggle-switch"><input type="checkbox" ${attrs}><span class="toggle-slider"></span></label>`;
}
const type = f.type === 'url' ? 'text' : f.type;
const extra = [
f.placeholder ? `placeholder="${esc(f.placeholder)}"` : '',
f.min != null ? `min="${f.min}"` : '',
f.max != null ? `max="${f.max}"` : '',
f.type === 'password' ? 'autocomplete="new-password"' : 'autocomplete="off"',
].join(' ');
return `<input type="${type}" ${attrs} ${extra}>`;
}