-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
87 lines (75 loc) · 2.23 KB
/
demo.html
File metadata and controls
87 lines (75 loc) · 2.23 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React Runtime</title>
<script src="js/react-runtime.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Calibri;
}
.app-container {
display: flex;
flex-direction: column;
gap: 5px;
padding: 5px;
margin: 5px;
}
.counter-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 5px;
padding: 5px;
margin: 5px;
border-radius: 5px;
}
.counter-container .title {
display: flex;
flex: 1;
}
.counter-container button {
width: 50px;
aspect-ratio: 1;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
// Class Component
class App extends React.Component {
render() {
return (
<div className="app-container">
<h1>React Runtime</h1>
<p>Developer: Mehdi-RaTo</p>
<Counter title="Num1" />
<Counter title="Num2" backgroundColor="#f001" />
<Counter title="Num3" backgroundColor="#00f1" />
</div>
);
}
}
// Functional Component
function Counter(props) {
const [number, setNumber] = React.useState(0);
return (
<div className="counter-container" style={{ backgroundColor: props.backgroundColor || "#0001" }}>
<p className="title">{props.title}: {number}</p>
<button onClick={() => setNumber(number + 1)}>➕</button>
<button onClick={() => setNumber(number - 1)}>➖</button>
</div>
);
}
// Render
ReactDOM.render(<App />, document.getElementById("root"));
</script>
</body>
</html>