合并组件
This commit is contained in:
parent
9b23a7d18b
commit
ff2f6c7e3c
@ -1,5 +1,5 @@
|
|||||||
export function List({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
|
export function createElement({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }, tagName) {
|
||||||
const element = document.createElement('ul')
|
const element = document.createElement(tagName)
|
||||||
for (const key in attributes) {
|
for (const key in attributes) {
|
||||||
element.setAttribute(key, attributes[key])
|
element.setAttribute(key, attributes[key])
|
||||||
}
|
}
|
||||||
@ -12,44 +12,18 @@ export function List({ innerText, textContent, onclick, children = [], dataset,
|
|||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ListItem({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
|
export function List(options) {
|
||||||
const element = document.createElement('li')
|
return createElement(options, '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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Span({ innerText, textContent, onclick, children = [], dataset, classList = [], ...attributes }) {
|
export function ListItem(options) {
|
||||||
const element = document.createElement('span')
|
return createElement(options, 'li')
|
||||||
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 }) {
|
export function Span(options) {
|
||||||
const element = document.createElement('button')
|
return createElement(options, 'span')
|
||||||
for (const key in attributes) {
|
}
|
||||||
element.setAttribute(key, attributes[key])
|
|
||||||
}
|
export function Button(options) {
|
||||||
element.classList.add(...classList)
|
return createElement(options, 'button')
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user