-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
151 lines (124 loc) · 4 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Creating the Project#
// About this task#
// You can create a React Web Component widget. The following instruction provides an example of creating a my-web-comp widget.
// NOTE
// If you use VS code, ensure that your typescript coming with VS code is v4.0.2 or higher.
// Procedure#
// Create project structure running the following command in your terminal ⁄ console:
// npx create-react-app {{app-name}}
// Navigate to the src directory in the project folder.
// In the src directory, create a new empty .tsx component file. For testing purposes, you can create Welcome.tsx.
// Add the following code to the Welcome.tsx file:
import React from "react";
class Welcome extends React.Component {
render() {
return (
<div className="neo-widget__content">
<div className="neo-widget__header">
<div className="neo-widget__header-left">
<span className="neo-icon-agents"></span>
<p>React</p>
</div>
</div>
<div className="neo-widget__body">
<div className="container">
<h3>
<b>React Web Component</b>
</h3>
</div>
</div>
</div>
);
}
}
export default Welcome;
// In the same directory, create a new .tsx file. For the purpose of this demo, you can create a MyWebComp.tsx file.
// Import your Welcome React component into MyWebComp.tsx file and transform it into a customElement as follows:
import { createElement } from "react";
import { render, unmountComponentAtNode } from "react-dom";
import Welcome from "./Welcome";
class MyWebComp extends HTMLElement {
connectedCallback() {
render(createElement(Welcome), this);
}
disconnectedCallback() {
unmountComponentAtNode(Welcome);
}
}
customElements.define("my-web-comp", MyWebComp);
// Next step#
// When your project is ready as a Web Component, you must build it for later use.
// Building the Project#
// About this task#
// You must build the project to use your widget in Avaya Workspaces.
// Procedure#
// In the root project folder, create the webpack.config.js file with the following contents:
const path = require("path");
module.exports = {
entry: path.resolve(__dirname, "src", "MyWebComp.tsx"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "my-web-comp.js",
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
compilerOptions: {
noEmit: false,
},
},
exclude: /node_modules/,
include: path.resolve(__dirname, "src"),
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
};
// Add build scripts to the package.json file:
// "build": "npm run build:react && npm run build:bundle",
// "build:react": "react-scripts build",
// "build:bundle": "webpack --config webpack.config.js"
// Add tsconfig file with the following contents:
// {
// "compilerOptions": {
// "target": "es2015",
// "lib": [
// "dom",
// "dom.iterable",
// "esnext"
// ],
// "allowJs": true,
// "skipLibCheck": true,
// "esModuleInterop": true,
// "allowSyntheticDefaultImports": true,
// "strict": true,
// "forceConsistentCasingInFileNames": true,
// "noFallthroughCasesInSwitch": true,
// "module": "esnext",
// "moduleResolution": "node",
// "resolveJsonModule": true,
// "isolatedModules": true,
// "noEmit": true,
// "noImplicitAny": false,
// "jsx": "react"
// },
// "include": [
// "src"
// ]
// }
// Run the following command to install necessary packages:
// npm i typescript ts-loader webpack-cli
// Build your project running the following command:
// npm run build
// The bundled file my-web-comp.js is in the dist folder. Host this folder using HTTP-server.
// Next step#
// When your project is bundled and built, continue configuring the widget JSON file that you can import in the Widget Manager.