Skip to content

Commit 27c3b95

Browse files
committed
initial commit
1 parent ea68fd4 commit 27c3b95

File tree

8 files changed

+167
-0
lines changed

8 files changed

+167
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.cache/
2+
/.history/
3+
/.idea/
4+
/dist/
5+
/node_modules/

HelloWorld.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react';
2+
import {render, unmountComponentAtNode} from 'react-dom';
3+
4+
export default class HelloWorld extends React.Component<any, any> {
5+
render() {
6+
return <span>Hello {this.props.children}</span>
7+
}
8+
}
9+
10+
class CustomElement extends HTMLElement {
11+
mountPoint: any
12+
// componentAttributes = {}; // TODO: add example of usage
13+
// componentProperties = {}; // TODO: add example of usage
14+
15+
connectedCallback() {
16+
this.update();
17+
}
18+
disconnectedCallback() {
19+
unmountComponentAtNode(this.mountPoint);
20+
}
21+
update() {
22+
if (!this.mountPoint) {
23+
this.mountPoint = document.createElement('span');
24+
this.attachShadow({mode: 'open'}).appendChild(this.mountPoint);
25+
}
26+
render(<HelloWorld>{this.innerHTML}</HelloWorld>, this.mountPoint);
27+
}
28+
29+
}
30+
31+
customElements.define('hello-world', CustomElement);

index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* {
2+
color: blue;
3+
}
4+
5+
.hello {
6+
color: red;
7+
background-color: yellow;
8+
}

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<body>
3+
<div id="root"></div>
4+
<link rel="stylesheet" type="text/css" href="./index.css">
5+
<script src="./index.tsx"></script>
6+
</body>
7+
</html>
8+

index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from 'react'
2+
import HelloWorld from './HelloWorld'
3+
import {render} from 'react-dom';
4+
5+
render(
6+
<div>
7+
<div>Standard React component: <HelloWorld>React</HelloWorld></div>
8+
<div>React wrapped as Webcomponent: <hello-world class="hello">Webcomponent</hello-world></div>
9+
</div>,
10+
document.getElementById('root'),
11+
);
12+

package-lock.json

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

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "my-app",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"typescript": "^3.7.3"
14+
},
15+
"dependencies": {
16+
"react": "^16.12.0",
17+
"react-dom": "^16.12.0"
18+
}
19+
}

tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react",
4+
"target": "esnext"
5+
}
6+
}
7+

0 commit comments

Comments
 (0)