A library to easily render react compatible shadow DOMs for web components with individual styling for inside and outside.
npm install @depay/react-shadow-dom```
yarn add @depay/react-shadow-dom
``
import { ReactShadowDOM } from '@depay/react-shadow-dom';
``
ReactShadowDOM({
document,
element,
content,
outsideStyle: outsideStyle,
insideStyle: insideStyle
})
The function ReactShadowDOM renders a react compontent (content) into an insideContainer that lives inside a shadowRoot of the outsideContainerelement
target element () within a given document (document) while also applying insideStyle to the insideContainer and outsideStyle to the outsideContainer.
You can either pas a ReactElement to content or a function. In case of a function that function will be call with the insideContainer as an argument and it's expected to return a ReactElement.
While outsideStyle is applied to the outside container directly:`
outsideStyle:
border: 1px solid red;
color: black;```
insideStyle is wrapped in a style tag and prepend to the shadowRoot:`
insideStyle:
.ReactShadowDOMInsideContainer {
background: blue;
color: white;
}```
#shadow-root
I'm in a ShadowDOM
wich allows you to style all elements and classes within the shadowRoot.
insideClasses sets classes on inside container:``
insideClasses: ['contained', 'another-class']``
#shadow-root
I'm in a ShadowDOM
In order to completly unmount everything (removing containers and unmounting React components),
the ReactShadowDOM function returns an object containing an unmount function:
`javascript
let { unmount } = ReactShadowDOM(...)
unmount()
`
``
yarn install
yarn demo
``
yarn test:integration
``
yarn test:cypress:debug 'cypress/integration/ReactShadowDOM.js'
```
npm publish