乱了, 懒得说是什么
This commit is contained in:
24
client/ui/InnerTextContainerElement.ts
Normal file
24
client/ui/InnerTextContainerElement.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export default class InnerTextContainerElement extends HTMLElement {
|
||||
static observedAttributes = ['text']
|
||||
declare textContainer: HTMLDivElement
|
||||
declare slotContainer: HTMLSlotElement
|
||||
declare text?: string
|
||||
constructor() {
|
||||
super()
|
||||
this.attachShadow({ mode: 'open' })
|
||||
}
|
||||
connectedCallback() {
|
||||
this.shadowRoot!.appendChild(document.createElement('slot'))
|
||||
}
|
||||
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
||||
if (this.textContainer == null) {
|
||||
this.textContainer = document.createElement('div')
|
||||
// 注意这里不能加到 shadow
|
||||
this.appendChild(this.textContainer)
|
||||
this.textContainer.style.display = 'none'
|
||||
}
|
||||
this.textContainer.innerText = newValue || ''
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('inner-text-container', InnerTextContainerElement)
|
||||
Reference in New Issue
Block a user