feat: show error when has styles & not using shadow roots
This commit is contained in:
parent
114ce87a41
commit
20c716d78d
2 changed files with 17 additions and 5 deletions
|
@ -78,7 +78,7 @@
|
||||||
"size-limit": [
|
"size-limit": [
|
||||||
{
|
{
|
||||||
"path": "./dist/WebComponent.js",
|
"path": "./dist/WebComponent.js",
|
||||||
"limit": "1.1 KB"
|
"limit": "1.2 KB"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "./dist/html.js",
|
"path": "./dist/html.js",
|
||||||
|
|
|
@ -28,6 +28,7 @@ export class WebComponent extends HTMLElement {
|
||||||
*/
|
*/
|
||||||
static props
|
static props
|
||||||
|
|
||||||
|
// TODO: support array of styles
|
||||||
static styles
|
static styles
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,9 +204,20 @@ export class WebComponent extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
#applyStyles() {
|
#applyStyles() {
|
||||||
const styleObj = new CSSStyleSheet()
|
if (this.constructor.styles !== undefined)
|
||||||
styleObj.replaceSync(this.constructor.styles)
|
try {
|
||||||
console.log(this.constructor.styles, this.constructor.props)
|
const styleObj = new CSSStyleSheet()
|
||||||
this.#host.adoptedStyleSheets = [...this.#host.adoptedStyleSheets, styleObj]
|
styleObj.replaceSync(this.constructor.styles)
|
||||||
|
console.log(this.constructor.styles, this.constructor.props)
|
||||||
|
this.#host.adoptedStyleSheets = [
|
||||||
|
...this.#host.adoptedStyleSheets,
|
||||||
|
styleObj,
|
||||||
|
]
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
'ERR: Constructable stylesheets are only supported in shadow roots',
|
||||||
|
e
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue