Skip to content

Commit

Permalink
Create Scope.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
mashaal committed Oct 28, 2024
1 parent a5f7a6d commit ebd4619
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scope/Scope.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Scoped CSS component
// https://developer.mozilla.org/en-US/docs/Web/CSS/@scope
// Influenced by https://x.com/dburles/status/1848236095173226873

/**
* @param {string} [href] - Optional URL for stylesheet
* @param {string} [css] - Optional CSS string for scoped styles
* @param {import('react').ReactNode} children - Child elements
* @returns {JSX.Element} Scoped component
*/
const Scope = (href, css, children) => {
return (
<ultra-scope>
{href && <link rel="stylesheet" href={href} />}
{css && (
<style
dangerouslySetInnerHTML={{
__html: `@scope {
${css}
}`,
}}
/>
)}
{children}
</ultra-scope>
);
};

0 comments on commit ebd4619

Please sign in to comment.