Skip to content

Commit 3bcf1ba

Browse files
committed
Improve support for styleSheets.
1 parent f562ddb commit 3bcf1ba

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.changeset/thirty-clocks-hear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pionjs/pion": minor
3+
---
4+
5+
Improve `styleSheets` support.

src/component.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Atts<P> = readonly KebabCase<keyof P>[];
1919
interface Renderer<P extends object> extends GenericRenderer<HTMLElement, P> {
2020
(this: Component<P>, host: Component<P>): unknown | void;
2121
observedAttributes?: Atts<P>;
22+
styleSheets?: (CSSStyleSheet | string)[];
2223
}
2324

2425
type Component<P extends object> = HTMLElement & P;
@@ -98,9 +99,9 @@ function makeComponent(render: RenderFunction): Creator {
9899
observedAttributes = [],
99100
useShadowDOM = true,
100101
shadowRootInit = {},
101-
styleSheets,
102+
styleSheets: _styleSheets,
102103
} = options || (baseElementOrOptions as Options<P>) || {};
103-
104+
const styleSheets = sheets(renderer.styleSheets || _styleSheets);
104105
class Element extends BaseElement {
105106
_scheduler: Scheduler<P>;
106107

@@ -117,7 +118,7 @@ function makeComponent(render: RenderFunction): Creator {
117118
mode: "open",
118119
...shadowRootInit,
119120
});
120-
if (styleSheets) shadowRoot.adoptedStyleSheets = sheets(styleSheets);
121+
if (styleSheets) shadowRoot.adoptedStyleSheets = styleSheets;
121122
this._scheduler = new Scheduler(renderer, shadowRoot, this);
122123
}
123124
}

src/util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export const sheet = (...styles: string[]) => {
44
return cs;
55
};
66

7-
export const sheets = (styleSheets: (string | CSSStyleSheet)[]) =>
8-
styleSheets.map((style) => {
7+
export const sheets = (styleSheets?: (string | CSSStyleSheet)[]) =>
8+
styleSheets?.map((style) => {
99
if (typeof style === "string") return sheet(style);
1010
return style;
1111
});

0 commit comments

Comments
 (0)