-
Notifications
You must be signed in to change notification settings - Fork 25
HelixUI with React
React can consume Web Components with some known workarounds.
Please read "React: Web Components" for more information.
- Latest stable NodeJS (for the
npm
andnpx
command-line utilities) -
helix-ui
v0.18.0 or later
(all paths are relative to the root of the project directory)
- Your app was bootstrapped via
create-react-app
- Your app is a greenfield app (brand new codebase)
- Vendor assets live in
public/vendor/
(coded by 3rd party)
npm install helix-ui vendor-copy
-
vendor-copy
allows you to automatically copy bundled assets to your project afternpm install
.
Include the following configurations:
{
"scripts": {
"postinstall": "vendor-copy"
},
"vendorCopy": [
{
"from": "node_modules/helix-ui/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js",
"to": "public/vendor/webcomponents-loader.js"
},
{
"from": "node_modules/helix-ui/node_modules/@webcomponents/webcomponentsjs/bundles",
"to": "public/vendor/bundles"
}
]
}
Run the following to copy files configured via the vendorCopy
configuration, above.
npx vendor-copy
NOTE: You may also want to verify that your postinstall
script is working as expected, by running npm install
.
Add the following to the bottom of the <head>
element:
<!-- Required for HelixUI to function in older browsers -->
<script src="%PUBLIC_URL%/vendor/webcomponents-loader.js"></script>
/* ... */
import 'helix-ui/dist/css/helix-ui.min.css';
import HelixUI from 'helix-ui';
/* ... */
HelixUI.initialize().then(() => {
ReactDOM.render(/* ... */);
});
/* ... */
-
TODO: Using
ref
to attach event listeners -
Warning: React's synthetic events violate non-bubbling specifications.
- It is a "known and intentional deviation".
- See facebook/react#12786 and facebook/react#6410 for information.
All HTMLElement
(custom element) lifecycle methods are executed in render()
-
React.Component
- constructor -
React.Component
- componentWillMount() -
React.Component
- render()-
HTMLElement
- create/connect- constructor
- attributeChangedCallback()
- connectedCallback()
-
-
React.Component
- componentDidMount()
-
React.Component
- componentWillUnmount() -
React.Component
- render()-
HTMLElement
- disconnect- disconnectedCallback()
-
-
React.Component
- componentWillUpdate() -
React.Component
- render()-
HTMLElement
- disconnect- disconnectedCallback()
-
HTMLElement
- create/connect- constructor
- attributeChangedCallback()
- connectedCallback()
-
React 15 is not supported by HelixUI.
It lacks support for the slot
attribute, which is required in order to take advantage of Light DOM redistribution into Shadow DOM slots. For this redistribution to happen, the slot
attribute needs to be present in the rendered markup.
React 15 ignores unknown attributes and slot
isn't a known attribute, so it's missing from the rendered markup. This results in Light DOM elements being redistributed into the wrong Shadow DOM slots.
Assume the following React/JSX Template:
<hx-custom-element>
<p id="first">
I will be redistributed into the default, unnamed slot in Shadow DOM.
</p>
<p id="second" slot="extra">
I should be redistributed into the "extra" slot in Shadow DOM.
React 15 doesn't include [slot="extra"], so I get redistributed
into the default, unnamed slot instead.
</p>
</hx-custom-element>
React 15 Renders the following: (notice how slot
is missing from <p id="second">
)
<hx-custom-element>
<p id="first">...</p>
<p id="second">...</p>
</hx-custom-element>
React 16+ Renders the following: (the slot
attribute is still present)
<hx-custom-element>
<p id="first">...</p>
<p id="second" slot="extra">...</p>
</hx-custom-element>
- Bypass synthetic event system for Web Component events (React) (facebook/react#7901)