webrtc/public/weigets.js

56 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-10-02 22:24:38 +08:00
export function List({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
const element = document.createElement('ul')
for (const key in attributes) {
element.setAttribute(key, attributes[key])
}
element.classList.add(...classList)
if (innerText) element.innerText = innerText
if (textContent) element.textContent = textContent
if (onclick) element.onclick = onclick
if (dataset) Object.keys(dataset).forEach(key => element.dataset[key] = dataset[key])
if (children) children.forEach(child => element.appendChild(child))
return element
2023-09-28 15:20:02 +08:00
}
2023-10-02 22:24:38 +08:00
export function ListItem({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
2023-10-02 21:59:43 +08:00
const element = document.createElement('li')
for (const key in attributes) {
element.setAttribute(key, attributes[key])
}
2023-10-02 22:24:38 +08:00
element.classList.add(...classList)
2023-10-02 21:59:43 +08:00
if (innerText) element.innerText = innerText
2023-10-02 22:24:38 +08:00
if (textContent) element.textContent = textContent
2023-10-02 21:59:43 +08:00
if (onclick) element.onclick = onclick
if (dataset) Object.keys(dataset).forEach(key => element.dataset[key] = dataset[key])
if (children) children.forEach(child => element.appendChild(child))
return element
2023-09-28 15:20:02 +08:00
}
2023-10-02 08:11:28 +08:00
2023-10-02 22:24:38 +08:00
export function Span({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
2023-10-02 21:59:43 +08:00
const element = document.createElement('span')
2023-10-02 22:24:38 +08:00
for (const key in attributes) {
element.setAttribute(key, attributes[key])
}
element.classList.add(...classList)
if (innerText) element.innerText = innerText
if (textContent) element.textContent = textContent
if (onclick) element.onclick = onclick
if (dataset) Object.keys(dataset).forEach(key => element.dataset[key] = dataset[key])
if (children) children.forEach(child => element.appendChild(child))
return element
}
export function Button({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
const element = document.createElement('button')
for (const key in attributes) {
element.setAttribute(key, attributes[key])
}
element.classList.add(...classList)
2023-10-02 21:59:43 +08:00
if (innerText) element.innerText = innerText
2023-10-02 22:24:38 +08:00
if (textContent) element.textContent = textContent
2023-10-02 21:59:43 +08:00
if (onclick) element.onclick = onclick
if (dataset) Object.keys(dataset).forEach(key => element.dataset[key] = dataset[key])
if (children) children.forEach(child => element.appendChild(child))
return element
2023-10-02 08:11:28 +08:00
}