Skip to content

Commit ebd4619

Browse files
committed
Create Scope.jsx
1 parent a5f7a6d commit ebd4619

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scope/Scope.jsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Scoped CSS component
2+
// https://developer.mozilla.org/en-US/docs/Web/CSS/@scope
3+
// Influenced by https://x.com/dburles/status/1848236095173226873
4+
5+
/**
6+
* @param {string} [href] - Optional URL for stylesheet
7+
* @param {string} [css] - Optional CSS string for scoped styles
8+
* @param {import('react').ReactNode} children - Child elements
9+
* @returns {JSX.Element} Scoped component
10+
*/
11+
const Scope = (href, css, children) => {
12+
return (
13+
<ultra-scope>
14+
{href && <link rel="stylesheet" href={href} />}
15+
{css && (
16+
<style
17+
dangerouslySetInnerHTML={{
18+
__html: `@scope {
19+
${css}
20+
}`,
21+
}}
22+
/>
23+
)}
24+
{children}
25+
</ultra-scope>
26+
);
27+
};

0 commit comments

Comments
 (0)