Skip to content

Commit 2838e4c

Browse files
authored
feat(web-components): add React wrapper (#4678)
Adds React wrapper generator (`createReactCustomElementType`), based on one in `carbon-web-components` to `@carbon/ibmdotcom-web-components` codebase. It helps our adoptors using React to use our components, with the following support that React itself lacks for non-intrinsic elements: * Element attributes mapping to non-string element property values (e.g. Boolean attributes) * React props mapping to element properties instead of element attributes * Event handlers Also adds a Babel plugin that automatically creates React wrappers of our components from our components' `@property()` annotations, as well as the corresponding build process that generates the React wrappers to `es/components-react` directory. So in the most typical scenario, our users can use components in `es/components-react` directory in the same manner as regular React components. Also adds React stories so we can demonstrate the React integration. Refs #4251.
1 parent 97f73f0 commit 2838e4c

File tree

141 files changed

+13928
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+13928
-405
lines changed
Binary file not shown.
Binary file not shown.
2.86 KB
Binary file not shown.
1.31 KB
Binary file not shown.
3.98 KB
Binary file not shown.
-19.7 KB
Binary file not shown.

.yarn/offline-mirror/react-17.0.1.tgz

74.7 KB
Binary file not shown.
728 KB
Binary file not shown.
22.9 KB
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"babel-eslint": "^10.1.0",
5454
"browserslist-config-carbon": "^10.3.0",
5555
"carbon-components": "10.17.0",
56-
"carbon-web-components": "1.9.0",
56+
"carbon-web-components": "1.10.0",
5757
"chalk": "^4.1.0",
5858
"commander": "^4.1.0",
5959
"cross-env": "^5.2.0",

packages/react/.storybook/Container.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import cx from 'classnames';
89
import React, { Component } from 'react';
910
import './_container.scss';
1011
import { settings } from 'carbon-components';
@@ -37,11 +38,14 @@ export default class Container extends Component {
3738
}
3839

3940
render() {
40-
const { story } = this.props;
41+
const { parameters, story } = this.props;
42+
const classes = cx({
43+
'storybook-proxy-story': parameters.proxy,
44+
});
4145

4246
return (
4347
<React.StrictMode>
44-
<div data-floating-menu-container="" role="main">
48+
<div data-floating-menu-container="" role="main" className={classes}>
4549
{story()}
4650
</div>
4751
<input

packages/react/.storybook/_container.scss

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ div[role='main'] {
6767
width: 100%;
6868
}
6969

70+
.storybook-proxy-story {
71+
padding: 1rem;
72+
}
73+
7074
// hide the cookie button
7175
#teconsent {
7276
visibility: hidden;

packages/react/.storybook/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ addDecorator((story, { parameters }) => {
9494
return story();
9595
});
9696

97-
addDecorator(story => <Container story={story} />);
97+
addDecorator((story, { parameters }) => (
98+
<Container story={story} parameters={parameters} />
99+
));
98100

99101
addons.getChannel().on(CURRENT_THEME, theme => {
100102
document.documentElement.setAttribute(

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"@percy/agent": "^0.26.0",
8787
"@percy/puppeteer": "^1.0.0",
8888
"@percy/storybook": "^3.3.0",
89+
"@rollup/plugin-node-resolve": "^8.4.0",
8990
"@storybook/addon-a11y": "^5.3.0",
9091
"@storybook/addon-actions": "^5.3.0",
9192
"@storybook/addon-docs": "^5.3.0",
@@ -176,7 +177,6 @@
176177
"rollup-plugin-commonjs": "^9.3.4",
177178
"rollup-plugin-json": "^4.0.0",
178179
"rollup-plugin-node-builtins": "^2.1.2",
179-
"rollup-plugin-node-resolve": "^4.2.3",
180180
"rollup-plugin-replace": "^2.2.0",
181181
"rollup-plugin-scss": "^2.5.0",
182182
"rollup-plugin-sizes": "^0.5.0",

packages/react/scripts/rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Table = require('cli-table');
1212
const gzip = require('gzip-size');
1313

1414
const commonjs = require('rollup-plugin-commonjs');
15-
const resolve = require('rollup-plugin-node-resolve');
15+
const { nodeResolve } = require('@rollup/plugin-node-resolve');
1616
const builtins = require('rollup-plugin-node-builtins');
1717
const babel = require('rollup-plugin-babel');
1818
const scss = require('rollup-plugin-scss');
@@ -73,7 +73,7 @@ process.env.BABEL_ENV = 'es';
7373
module.exports = {
7474
input: 'src/index.js',
7575
plugins: [
76-
resolve({
76+
nodeResolve({
7777
browser: true,
7878
mainFields: ['jsnext', 'module', 'main'],
7979
}),

0 commit comments

Comments
 (0)