GitRead 中文社区
首页趋势排行榜原创文章严选周刊
更多资源
新手训练营
精选专题热门话题GitHub 文档资源精选实战指南

ReactShadow

:beginner: Utilise Shadow DOM in React with all the benefits of style encapsulation.

  • 语言JavaScript
  • 默认分支master
  • 大小6.2 MB
  • 更新2025年1月10日
  • Issues27
在 GitHub 打开
avatarWildhoney

项目介绍

Wildhoney/ReactShadow 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 MIT License 许可证,目前获得 1.4k 个 Star、80 次 Fork。

仓库全名
Wildhoney/ReactShadow

README 摘要

Utilise Shadow DOM in React with all the benefits of style encapsulation.       npm: npm i react-shadow yarn: yarn add react-shadow Heroku: https://react-shadow.herokuapp.com/ (alternative) Getting Started Creating the shadow root is as simple as using the default export to construct a shadow root using the node name provided – for example root.div would create a div as the host element, and a…

完整内容见 GitHub 原始 README 或本页 。

常见问题

ReactShadow 用什么语言开发?

主要使用 JavaScript 编写,采用 MIT License 许可证,目前有 1.4k 个 Star。

ReactShadow 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 ReactShadow 的源码?

可以直接克隆仓库:git clone https://github.com/Wildhoney/ReactShadow.git,默认分支为 master;安装与运行步骤见仓库 README。

ReactShadow 最近还在维护吗?

仓库最近一次更新为 2025年1月10日,当前有 27 个未关闭 Issue;Star 数为 1.4k,可作为社区活跃度的参考。

本页面展示项目元数据与原始 README,GitRead 中文社区 编辑团队负责选题收录。

相关仓库

affaan-m/ECC avatar
ECCaffaan-m
1 天前
300.6k
44.4k
248

代理框架性能优化系统。为 Claude Code、Codex、Opencode、Cursor 及其他工具提供技能、本能、记忆、安全性和研究优先的开发支持。

ai-agentsanthropicclaude+5
JavaScript
61.3 MB
2
详情
react/react avatar
reactreact
2 小时前
252.5k
52.2k
1.5k

用于 Web 和原生用户界面的库。

declarativefrontendjavascript+3
JavaScript
1.1 GB
0
详情
trekhleb/javascript-algorithms avatar
javascript-algorithmstrekhleb
7月26日
196.7k
31.0k
437

用 JavaScript 实现的算法与数据结构,并附有讲解和延伸阅读链接

algorithmalgorithmscomputer-science+5
JavaScript
14.6 MB
0
详情
DietrichGebert/ponytail avatar
ponytailDietrichGebert
1 周前
188.2k
10.4k
80

让你的 AI 代理像房间里最懒的资深开发者一样思考。最好的代码是你从未写过的代码。

agent-skillsai-agentsclaude+7
JavaScript
12.8 MB
0
详情
Snailclimb/JavaGuide avatar
JavaGuideSnailclimb
2 周前
159.5k
44.9k
17

Java 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发

agentaicontext-engineering+10
JavaScript
179.2 MB
1
详情
airbnb/javascript avatar
javascriptairbnb
4月17日
148.0k
24.2k
99

JavaScript 风格指南

arrow-functionses2015es2016+11
JavaScript
3.7 MB
0
详情
vercel/next.js avatar
next.jsvercel
1 小时前
143.4k
32.4k
1.1k

React 框架

blogbrowsercompiler+11
JavaScript
2.5 GB
0
详情
Chalarangelo/30-seconds-of-code avatar
30-seconds-of-codeChalarangelo
1 天前
129.5k
12.1k
0

助你提升开发技能的编程文章

astroawesome-listcss+10
JavaScript
725.2 MB
0
详情

关于

componentscsscss-documentcss-isolationcustom-elementsencapsulationfrontendhooksjavascriptreactreactjsscoped-stylesshadow-boundaryshadow-domstyle-encapsulationtypescriptwebcomponents
  • MIT License
  • 1.4k Stars
  • 80 Forks
  • 14 Watching

简要分析

热度分
1554
价值分
852
活跃状态
活跃
GitHub

语言占比

CSS
JavaScript

贡献者

WildhoneyWildhoneydependabot[bot]dependabot[bot]mrspencemrspenceziahamzaziahamzadarthtrevinodarthtrevinomeetwudimeetwudifrontendphilfrontendphilshvaikaleshshvaikaleshBossElijahBossElijaharizonatribearizonatribegeorgeclaghorngeorgeclaghornlazarljubenoviclazarljubenovic

ReactShadow

Utilise Shadow DOM in React with all the benefits of style encapsulation.

Travis   Coveralls   npm   License MIT

  • npm: npm i react-shadow
  • yarn: yarn add react-shadow
  • Heroku: https://react-shadow.herokuapp.com/ (alternative)

Screenshot


Getting Started

Creating the shadow root is as simple as using the default export to construct a shadow root using the node name provided – for example root.div would create a div as the host element, and a shadow root as its immediate descendant — all of the child elements would then be descendants of the shadow boundary.

import root from 'react-shadow';
import styles from './styles.css';

export default function Quote() {
    return (
        <root.div className="quote">
            <q>There is strong shadow where there is much light.</q>
            <span className="author">― Johann Wolfgang von Goethe.</span>
            <style type="text/css">{styles}</style>
        </root.div>
    );
}

Edit react-shadow

Applying styles requires either applying the styles directly to the component as a string, or importing the CSS documents as a string as part of your build process. You can then append the style component directly to your shadow boundary via your component’s tree. In the example we use the following Webpack configuration to import CSS documents as strings.

{
    test: /\.css$/,
    loader: ['to-string-loader', 'css-loader']
}

Alternatively you can use styled-components normally, as each time a shadow boundary is created, a new StyleSheetManager context is also created which will encapsulate all related styles in their corresponding shadow root — to use this import react-shadow/styled-components instead of import react-shadow, likewise if you’d like to use emotion you can import react-shadow/emotion.

import root from 'react-shadow/styled-components';
import root from 'react-shadow/emotion';

// ...

<root.section />;

You may pass any props you like to the root.* component which will be applied directly to the host element, including event handlers and class names. There are also a handful of options that are used for the attachShadow invocation.

ShadowRoot.propTypes = {
    mode: PropTypes.oneOf(['open', 'closed']),
    delegatesFocus: PropTypes.bool,
    styleSheets: PropTypes.arrayOf(
        PropTypes.instanceOf(globalThis.CSSStyleSheet),
    ),
    children: PropTypes.node,
};

ShadowRoot.defaultProps = {
    mode: 'open',
    delegatesFocus: false,
    styleSheets: [],
    children: null,
};

In cases where you need the underlying element and its associated shadow boundary, you can use a standard ref which will be invoked with the host element – from that you can use shadowRoot to access its shadow root if the mode has been set to the default open value.

const node = useRef(null);

// ...

<root.section ref={node} />;

Recently and at long last there has been some movement in introducing a declarative shadow DOM which react-shadow tentatively supports – as it’s experimental, open to sudden spec changes, and React finds it difficult to rehydrate – by using the ssr prop.

const node = useRef(null);

// ...

<root.section ssr />;

评论

登录 后发表评论
暂无评论
GitRead 中文社区
深度解读 · 趋势洞察 · 价值精选

关于

关于我们联系我们编辑准则收录标准赞赏人员

发现

技术趋势新手训练营资源精选实战指南精选专题热门话题GitHub 文档

条款

隐私政策服务条款网站地图
26.9万收录项目
5.8万中文话题
155精选专题
发现技术价值,连接开源智慧
© 2026 GitRead · GitHub 中文社区 本站与 GitHub, Inc. 无隶属关系;GitHub 是 GitHub, Inc. 的商标。