You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
24. node-fetch version 2.7.0 (https://github.com/bitinn/node-fetch)
30
+
25. os-browserify version 0.3.0 (https://github.com/CoderPuppy/os-browserify)
31
+
26. path-browserify version 1.0.1 (https://github.com/browserify/path-browserify)
32
+
27. react-dom version 19.0.0 (https://github.com/facebook/react)
33
+
28. react version 19.0.0 (https://github.com/facebook/react)
34
+
29. signal-utils version 0.21.1 (https://github.com/proposal-signals/signal-utils)
35
+
30. slug version 10.0.0 (https://github.com/Trott/slug)
36
+
31. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)
36
37
37
38
%% @gk-nzaytsev/fast-string-truncated-width NOTICES AND INFORMATION BEGIN HERE
38
39
=========================================
@@ -1324,6 +1325,136 @@ END OF @opentelemetry/sdk-trace-base NOTICES AND INFORMATION
1324
1325
=========================================
1325
1326
END OF @opentelemetry/semantic-conventions NOTICES AND INFORMATION
1326
1327
1328
+
%% @r2wc/react-to-web-component NOTICES AND INFORMATION BEGIN HERE
1329
+
=========================================
1330
+
# React to Web Component
1331
+
1332
+
`@r2wc/react-to-web-component` converts [React](https://reactjs.org/) components to [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)! It lets you share React components as native elements that **don't** require being mounted through React. The custom element acts as a wrapper for the underlying React component. Use these custom elements with any project that uses HTML even in any framework (vue, svelte, angular, ember, canjs) the same way you would use standard HTML elements.
1333
+
1334
+
> Note: The latest version of this package only works with the React 18. If you are using React 16 or 17, please use version 1.
1335
+
1336
+
`@r2wc/react-to-web-component`:
1337
+
1338
+
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
1339
+
- Is `1.26KB` minified and gzipped.
1340
+
1341
+
## Setup
1342
+
1343
+
To install from npm:
1344
+
1345
+
```
1346
+
npm install @r2wc/react-to-web-component
1347
+
```
1348
+
1349
+
## Need help or have questions?
1350
+
1351
+
This project is supported by [Bitovi, a React consultancy](https://www.bitovi.com/frontend-javascript-consulting/react-consulting). You can get help or ask questions on our:
Or, you can hire us for training, consulting, or development. [Set up a free consultation.](https://www.bitovi.com/frontend-javascript-consulting/react-consulting)
1357
+
1358
+
## Basic Use
1359
+
1360
+
For basic usage, we will use this simple React component:
1361
+
1362
+
```js
1363
+
const Greeting = () => {
1364
+
return <h1>Hello, World!</h1>
1365
+
}
1366
+
```
1367
+
1368
+
With our React component complete, all we have to do is call `r2wc` and [customElements.define](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) to create and define our custom element:
Now we can use `<web-greeting>` like any other HTML element!
1379
+
1380
+
```html
1381
+
<body>
1382
+
<h1>Greeting Demo</h1>
1383
+
1384
+
<web-greeting></web-greeting>
1385
+
</body>
1386
+
```
1387
+
1388
+
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
1389
+
1390
+
## Working with Attributes
1391
+
1392
+
By default, custom elements created by `r2wc` only pass properties to the underlying React component. To make attributes work, you must specify your component's props.
1393
+
1394
+
```js
1395
+
const Greeting = ({ name }) => {
1396
+
return <h1>Hello, {name}!</h1>
1397
+
}
1398
+
1399
+
const WebGreeting = r2wc(Greeting, {
1400
+
props: {
1401
+
name: "string",
1402
+
},
1403
+
})
1404
+
```
1405
+
1406
+
Now `r2wc` will know to look for `name` attributes
1407
+
as follows:
1408
+
1409
+
```html
1410
+
<body>
1411
+
<h1>Greeting Demo</h1>
1412
+
1413
+
<web-greeting name="Justin"></web-greeting>
1414
+
</body>
1415
+
```
1416
+
1417
+
For projects needing more advanced usage of the web components, see our [programatic usage and declarative demos](docs/programatic-usage.md).
1418
+
1419
+
We also have a [complete example using a third party library](docs/complete-example.md).
1420
+
1421
+
## Examples
1422
+
1423
+
- [Hello World](https://codesandbox.io/s/hello-world-md5oih) - The quintessential software demo!
1424
+
- [All the Props](https://codesandbox.io/s/all-the-props-n8z5hv) - A demo of all the prop transform types that R2WC supports.
1425
+
- [Header Example](https://codesandbox.io/s/example-header-blog-7k313l) - An example reusable Header component.
1426
+
- [MUI Button](https://codesandbox.io/s/example-mui-button-qwidh9) - An example application using an MUI button with theme customization.
1427
+
- [Checklist Demo](https://codesandbox.io/s/example-checklist-blog-y3nqwx) - An example Checklist application.
1428
+
1429
+
## Blog Posts
1430
+
1431
+
R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vite-and-react-to-webcomponent)
1432
+
1433
+
R2WC with Create React App (CRA) [View Post](https://www.bitovi.com/blog/how-to-create-a-web-component-with-create-react-app)
1434
+
1435
+
## How it works
1436
+
1437
+
Check out our [full API documentation](https://github.com/bitovi/react-to-web-component/blob/main/docs/api.md).
1438
+
1439
+
Under the hood, `r2wc` creates a `CustomElementConstructor` with custom getters/setters and life cycle methods that keep track of the props that you have defined. When a property is set, its custom setter:
1440
+
1441
+
- re-renders the React component inside the custom element.
1442
+
- creates an enumerable getter / setter on the instance to save the set value and avoid hitting the proxy in the future.
1443
+
1444
+
Also:
1445
+
1446
+
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
1447
+
- The React component is not rendered until the custom element is inserted into the page.
1448
+
1449
+
# We want to hear from you.
1450
+
1451
+
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
1452
+
1453
+
See what we're up to by following us on [Twitter](https://twitter.com/bitovi).
1454
+
1455
+
=========================================
1456
+
END OF @r2wc/react-to-web-component NOTICES AND INFORMATION
1457
+
1327
1458
%% @shoelace-style/shoelace NOTICES AND INFORMATION BEGIN HERE
0 commit comments