We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a5f7a6d commit ebd4619Copy full SHA for ebd4619
scope/Scope.jsx
@@ -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