Skip to content

Commit 52cc1d2

Browse files
author
Christopher J Baker
committed
update deps
1 parent b304ebc commit 52cc1d2

File tree

6 files changed

+275
-24
lines changed

6 files changed

+275
-24
lines changed

.github/actions/publish-npm/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ runs:
3535
3636
- name: Increment Version
3737
shell: bash
38+
working-directory: ./packages/${{ inputs.directory }}
3839
run: |
3940
git config --local user.email "Workflow: ${{ inputs.package }}[bot]"
4041
git config --local user.name "${{ inputs.package }}[bot]@workflow"

README.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# React to Web Component
22

3-
`react-to-webcomponent` 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 mounted being 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.
3+
`@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 mounted being 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.
44

5-
`react-to-webcomponent`:
5+
`@r2wc/react-to-web-component`:
66

77
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
88
- Is `1.11KB` minified and gzipped.
@@ -16,8 +16,6 @@ This project is supported by [Bitovi, a React consultancy](https://www.bitovi.co
1616

1717
Or, you can hire us for training, consulting, or development. [Set up a free consultation.](https://www.bitovi.com/frontend-javascript-consulting/react-consulting)
1818

19-
> This is the documentation for the upcoming version 2 of react-to-webcomponent. It will have a very similar but backwards incompatible API. For production deployments, please see the [document for version 1](https://github.com/bitovi/react-to-webcomponent/tree/main).
20-
2119
## Basic Use
2220

2321
For basic usage, we will use this simple React component:
@@ -28,12 +26,12 @@ const Greeting = () => {
2826
}
2927
```
3028

31-
With our React component complete, all we have to do is call `reactToWebComponent` and [customElements.define](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) to create and define our custom element:
29+
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:
3230

3331
```js
34-
import reactToWebComponent from "react-to-webcomponent"
32+
import r2wc from "@r2wc/react-to-web-component"
3533

36-
const WebGreeting = reactToWebComponent(Greeting)
34+
const WebGreeting = r2wc(Greeting)
3735

3836
customElements.define("web-greeting", WebGreeting)
3937
```
@@ -48,27 +46,27 @@ Now we can use `<web-greeting>` like any other HTML element!
4846
</body>
4947
```
5048

51-
Note that by using React 18, `reactToWebComponent` will use the new root API. If your application needs the legacy API, please use React 17
49+
Note that by using React 18, `r2wc` will use the new root API. If your application needs the legacy API, please use React 17
5250

5351
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
5452

5553
## Working with Attributes
5654

57-
By default, custom elements created by `reactToWebComponent` only pass properties to the underlying React component. To make attributes work, you must specify your component's props.
55+
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.
5856

5957
```js
6058
const Greeting = ({ name }) => {
6159
return <h1>Hello, {name}!</h1>
6260
}
6361

64-
const WebGreeting = reactToWebComponent(Greeting, {
62+
const WebGreeting = r2wc(Greeting, {
6563
props: {
6664
name: "string",
6765
},
6866
})
6967
```
7068

71-
Now `reactToWebComponent` will know to look for `name` attributes
69+
Now `r2wc` will know to look for `name` attributes
7270
as follows:
7371

7472
```html
@@ -88,7 +86,7 @@ We also have a [complete example using a third party library](docs/complete-exam
8886
To install from npm:
8987

9088
```
91-
npm i react-to-webcomponent
89+
npm install @r2wc/react-to-web-component
9290
```
9391

9492
## External Examples
@@ -109,15 +107,11 @@ R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vit
109107

110108
R2WC with Create React App (CRA) [View Post](https://www.bitovi.com/blog/how-to-create-a-web-component-with-create-react-app)
111109

112-
## Bundled JS file available
113-
114-
[https://unpkg.com/react-to-webcomponent/dist/react-to-webcomponent.js](https://unpkg.com/react-to-webcomponent/dist/react-to-webcomponent.js)
115-
116110
## How it works
117111

118-
Check out our [full API documentation](docs/api.md).
112+
Check out our [full API documentation](../../docs/api.md).
119113

120-
`reactToWebComponent` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
114+
`r2wc` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
121115

122116
- re-renders the React component inside the custom element.
123117
- creates an enumerable getter / setter on the instance

package-lock.json

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@
2424
"semver": "^7.5.0",
2525
"ts-node": "^10.9.1",
2626
"typescript": "^4.9.5"
27-
},
28-
"version": "0.0.1-alpha.1"
27+
}
2928
}

packages/legacy/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# React to Web Component
2+
3+
`react-to-webcomponent` 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 mounted being 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.
4+
5+
`react-to-webcomponent`:
6+
7+
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
8+
- Is `1.11KB` minified and gzipped.
9+
10+
## Need help or have questions?
11+
12+
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:
13+
14+
- [Discord Community](https://discord.gg/J7ejFsZnJ4)
15+
- [Twitter](https://twitter.com/bitovi)
16+
17+
Or, you can hire us for training, consulting, or development. [Set up a free consultation.](https://www.bitovi.com/frontend-javascript-consulting/react-consulting)
18+
19+
## Basic Use
20+
21+
For basic usage, we will use this simple React component:
22+
23+
```js
24+
const Greeting = () => {
25+
return <h1>Hello, World!</h1>
26+
}
27+
```
28+
29+
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:
30+
31+
```js
32+
import React from "react"
33+
import * as ReactDOM from "react-dom/client" // if using React 18
34+
// import * as ReactDOM from "react-dom" // if using React 17
35+
import r2wc from "react-to-webcomponent"
36+
37+
const WebGreeting = r2wc(Greeting, React, ReactDOM)
38+
39+
customElements.define("web-greeting", WebGreeting)
40+
```
41+
42+
Now we can use `<web-greeting>` like any other HTML element!
43+
44+
```html
45+
<body>
46+
<h1>Greeting Demo</h1>
47+
48+
<web-greeting></web-greeting>
49+
</body>
50+
```
51+
52+
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
53+
54+
## Working with Attributes
55+
56+
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.
57+
58+
```js
59+
const Greeting = ({ name }) => {
60+
return <h1>Hello, {name}!</h1>
61+
}
62+
63+
const WebGreeting = r2wc(Greeting, React, ReactDOM, {
64+
props: {
65+
name: "string",
66+
},
67+
})
68+
```
69+
70+
Now `r2wc` will know to look for `name` attributes
71+
as follows:
72+
73+
```html
74+
<body>
75+
<h1>Greeting Demo</h1>
76+
77+
<web-greeting name="Justin"></web-greeting>
78+
</body>
79+
```
80+
81+
For projects needing more advanced usage of the web components, see our [programatic usage and declarative demos](docs/programatic-usage.md).
82+
83+
We also have a [complete example using a third party library](docs/complete-example.md).
84+
85+
## Setup
86+
87+
To install from npm:
88+
89+
```
90+
npm i react-to-webcomponent
91+
```
92+
93+
## External Examples
94+
95+
Greeting example in a [CodePen](https://codepen.io/bavinedwards/pen/jOveaGm)
96+
97+
Greeting example in [CodeSandbox](https://codesandbox.io/s/sample-greeting-app-ts-qwidh9)
98+
99+
Hello, world example (React17) in [CodeSandbox](https://codesandbox.io/s/hello-world-react17-u4l3x1)
100+
101+
Example with all prop types in [CodeSandbox](https://codesandbox.io/p/sandbox/vite-example-with-numerous-types-gjf87o)
102+
103+
R2WC With Vite Header Example in [CodeSandbox](https://codesandbox.io/p/sandbox/header-example-e4x25q)
104+
105+
## External Blog Posts
106+
107+
R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vite-and-react-to-webcomponent)
108+
109+
R2WC with Create React App (CRA) [View Post](https://www.bitovi.com/blog/how-to-create-a-web-component-with-create-react-app)
110+
111+
## How it works
112+
113+
Check out our [full API documentation](../../docs/api.md).
114+
115+
`r2wc` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
116+
117+
- re-renders the React component inside the custom element.
118+
- creates an enumerable getter / setter on the instance
119+
to save the set value and avoid hitting the proxy in the future.
120+
121+
Also:
122+
123+
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
124+
- The React component is not rendered until the custom element is inserted into the page.
125+
126+
# We want to hear from you.
127+
128+
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
129+
130+
See what we're up to by following us on [Twitter](https://twitter.com/bitovi).
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# React to Web Component
2+
3+
`@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 mounted being 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.
4+
5+
`@r2wc/react-to-web-component`:
6+
7+
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
8+
- Is `1.11KB` minified and gzipped.
9+
10+
## Need help or have questions?
11+
12+
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:
13+
14+
- [Discord Community](https://discord.gg/J7ejFsZnJ4)
15+
- [Twitter](https://twitter.com/bitovi)
16+
17+
Or, you can hire us for training, consulting, or development. [Set up a free consultation.](https://www.bitovi.com/frontend-javascript-consulting/react-consulting)
18+
19+
## Basic Use
20+
21+
For basic usage, we will use this simple React component:
22+
23+
```js
24+
const Greeting = () => {
25+
return <h1>Hello, World!</h1>
26+
}
27+
```
28+
29+
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:
30+
31+
```js
32+
import r2wc from "@r2wc/react-to-web-component"
33+
34+
const WebGreeting = r2wc(Greeting)
35+
36+
customElements.define("web-greeting", WebGreeting)
37+
```
38+
39+
Now we can use `<web-greeting>` like any other HTML element!
40+
41+
```html
42+
<body>
43+
<h1>Greeting Demo</h1>
44+
45+
<web-greeting></web-greeting>
46+
</body>
47+
```
48+
49+
Note that by using React 18, `r2wc` will use the new root API. If your application needs the legacy API, please use React 17
50+
51+
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
52+
53+
## Working with Attributes
54+
55+
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.
56+
57+
```js
58+
const Greeting = ({ name }) => {
59+
return <h1>Hello, {name}!</h1>
60+
}
61+
62+
const WebGreeting = r2wc(Greeting, {
63+
props: {
64+
name: "string",
65+
},
66+
})
67+
```
68+
69+
Now `r2wc` will know to look for `name` attributes
70+
as follows:
71+
72+
```html
73+
<body>
74+
<h1>Greeting Demo</h1>
75+
76+
<web-greeting name="Justin"></web-greeting>
77+
</body>
78+
```
79+
80+
For projects needing more advanced usage of the web components, see our [programatic usage and declarative demos](docs/programatic-usage.md).
81+
82+
We also have a [complete example using a third party library](docs/complete-example.md).
83+
84+
## Setup
85+
86+
To install from npm:
87+
88+
```
89+
npm install @r2wc/react-to-web-component
90+
```
91+
92+
## External Examples
93+
94+
Greeting example in a [CodePen](https://codepen.io/bavinedwards/pen/jOveaGm)
95+
96+
Greeting example in [CodeSandbox](https://codesandbox.io/s/sample-greeting-app-ts-qwidh9)
97+
98+
Hello, world example (React17) in [CodeSandbox](https://codesandbox.io/s/hello-world-react17-u4l3x1)
99+
100+
Example with all prop types in [CodeSandbox](https://codesandbox.io/p/sandbox/vite-example-with-numerous-types-gjf87o)
101+
102+
R2WC With Vite Header Example in [CodeSandbox](https://codesandbox.io/p/sandbox/header-example-e4x25q)
103+
104+
## External Blog Posts
105+
106+
R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vite-and-react-to-webcomponent)
107+
108+
R2WC with Create React App (CRA) [View Post](https://www.bitovi.com/blog/how-to-create-a-web-component-with-create-react-app)
109+
110+
## How it works
111+
112+
Check out our [full API documentation](../../docs/api.md).
113+
114+
`r2wc` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
115+
116+
- re-renders the React component inside the custom element.
117+
- creates an enumerable getter / setter on the instance
118+
to save the set value and avoid hitting the proxy in the future.
119+
120+
Also:
121+
122+
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
123+
- The React component is not rendered until the custom element is inserted into the page.
124+
125+
# We want to hear from you.
126+
127+
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
128+
129+
See what we're up to by following us on [Twitter](https://twitter.com/bitovi).

0 commit comments

Comments
 (0)