add dropdown component

This commit is contained in:
2023-03-31 17:35:36 +08:00
parent b9447997fe
commit 41b1bbd7d6
20 changed files with 575 additions and 74 deletions

View File

@ -5,7 +5,9 @@ function fillCheckbox(container, type, label) {
layer.className = 'check-box-inner';
layer.appendChild(createIcon(type, 'check'));
container.appendChild(layer);
if (label != null && label.length > 0) {
if (label instanceof HTMLElement) {
container.appendChild(label);
} else if (label != null && label.length > 0) {
const span = document.createElement('span');
span.innerText = label;
container.appendChild(span);
@ -21,6 +23,11 @@ function createCheckbox(opts) {
if (opts.checked === true) {
input.checked = true;
}
if (opts.customerAttributes != null) {
for (let entry of Object.entries(opts.customerAttributes)) {
input.setAttribute(entry[0], entry[1]);
}
}
if (typeof opts.onchange === 'function') {
input.addEventListener('change', opts.onchange);
}
@ -50,9 +57,7 @@ function createCheckbox(opts) {
}
function resolveCheckbox(container, legacy) {
if (container == null) {
container = document.body;
}
container ??= document.body;
if (legacy) {
const checks = container.querySelectorAll('input[type="checkbox"]');
for (let chk of checks) {