Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-shadow-root
Advanced tools
Lets you add a shadow root to React components allowing you to use the shadow DOM. This provides scoped CSS and includes support for constructable stylesheets.
npm install --save react-shadow-root
https://apearce.github.io/react-shadow-root/
import React form 'react';
import ReactShadowRoot from 'react-shadow-root';
class ShadowCounter extends React.Component {
state = { cnt: 0 };
increment = () => {
this.setState({
cnt: this.state.cnt + 1
});
}
render() {
const style = `span {
background-color: #333;
border-radius: 3px;
color: #fff;
padding: 1px 5px;
}
button {
background-color: #fff;
border: 1px solid currentColor;
border-radius: 3px;
color: #333;
cursor: pointer;
outline: 0;
}
button:active {
background-color: #333;
color: #fff;
}`;
return (
<div> {/* The shadow root will be attached to this DIV */}
<ReactShadowRoot>
<style>{style}</style>
<span>{this.state.cnt}</span> <button onClick={this.increment}>Click Me</button>
</ReactShadowRoot>
</div>
);
}
}
When the shadow root is created on its parent element, all children are copied into the shadow DOM. Styles in the shadow DOM are automatically scoped. You can inspect the element to confirm. Slots work as expected; just be sure to add {this.props.children}
after the closing ReactShadowRoot
tag.
Name | Description |
---|---|
constructableStylesheetsSupported | A boolean telling you if constructable stylesheets are supported by the browser. |
constructibleStylesheetsSupported | An alias of constructableStylesheetsSupported using the 'correct' spelling. |
shadowRootSupported | A boolean telling you if attaching a shadow root is supported by the browser, not the element. |
Prop | Type | Values | Default | Description |
---|---|---|---|---|
delegatesFocus | Boolean | true or false | false | Expands the focus behavior of elements within the shadow DOM. Click here for more information. |
mode | String | open or closed | open | Sets the mode of the shadow root. |
stylesheets | Array | arrayOf(CSSStyleSheet) | optional | Takes an array of CSSStyleSheet objects for constructable stylesheets. |
FAQs
Adds a shadow root to React components
The npm package react-shadow-root receives a total of 10,024 weekly downloads. As such, react-shadow-root popularity was classified as popular.
We found that react-shadow-root demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.