Skip to content

Commit d3cde56

Browse files
committed
Added a Simple Graph
1 parent 93aea70 commit d3cde56

File tree

9 files changed

+594
-24
lines changed

9 files changed

+594
-24
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"dependencies": {
4444
"@tweenjs/tween.js": "^18.6.4",
4545
"gsap": "^3.11.1",
46-
"react": "^17.0.2",
47-
"react-dom": "^17.0.2",
46+
"react": "^18.2.0",
47+
"react-dom": "^18.2.0",
4848
"two.js": "^0.8.10"
4949
}
5050
}

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Wiremarks</title>
66
<link rel="preconnect" href="https://fonts.googleapis.com">
77
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
8-
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;700&display=swap" rel="stylesheet">
8+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Space+Mono&display=swap" rel="stylesheet">
99
<link rel="stylesheet" type="text/css" href="./main.css" />
1010
<link rel="icon" href="./images/label.png" />
1111
</head>

public/main.css

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

src/editor.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useRef, useState } from 'react';
2+
import { Component as Wiremark } from './wiremark.js';
3+
4+
export default function Editor(props) {
5+
6+
const domElement = useRef();
7+
8+
const [text, setText] = useState('');
9+
const [width, setWidth] = useState(window.innerWidth);
10+
const [height, setHeight] = useState(window.innerHeight);
11+
const [isOpen, setIsOpen] = useState(false);
12+
13+
function update(e) {
14+
const value = e.target.value;
15+
setText(value);
16+
}
17+
18+
function open() {
19+
setIsOpen(true);
20+
requestAnimationFrame(select);
21+
}
22+
function close() {
23+
setIsOpen(false);
24+
}
25+
function select() {
26+
const selector = 'div.panel textarea';
27+
const textarea = domElement.current.querySelector(selector);
28+
textarea.focus();
29+
}
30+
31+
return (
32+
<div ref={ domElement } className={ ['editor', isOpen ? 'writing' : ''].join(' ') }>
33+
<div className="stage">
34+
<Wiremark instructions={ text } width={ width } height={ height } />
35+
</div>
36+
<div className="ui">
37+
<div className="open button" onClick={ open }>
38+
Open Instructions
39+
</div>
40+
<div className="panel">
41+
<div className="close button" onClick={ close }>✖️</div>
42+
<textarea onChange={ update } />
43+
</div>
44+
</div>
45+
</div>
46+
);
47+
48+
}

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
import { Wiremarks } from './wiremarks.js';
1+
import React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import Editor from './editor.js';
4+
5+
const domElement = document.createElement('div');
6+
const root = createRoot(domElement);
7+
8+
domElement.id = 'react';
9+
document.body.appendChild(domElement);
10+
11+
root.render(<Editor />);

src/main.less

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,100 @@
11
* {
22
margin: 0;
33
padding: 0;
4+
}
5+
6+
@font-size: 17px;
7+
@line-height: 20px;
8+
9+
div#react {
10+
div.editor {
11+
12+
position: fixed;
13+
overflow: hidden;
14+
top: 0;
15+
left: 0;
16+
right: 0;
17+
bottom: 0;
18+
19+
font-family: 'Inter', sans-serif;
20+
font-size: @font-size;
21+
font-weight: 400;
22+
line-height: @line-height;
23+
24+
div.stage {
25+
position: absolute;
26+
top: 0;
27+
left: 0;
28+
width: 100%;
29+
height: 100%;
30+
}
31+
32+
div.ui {
33+
position: absolute;
34+
top: 0;
35+
left: 0;
36+
width: 100%;
37+
height: 100%;
38+
pointer-events: none;
39+
box-sizing: border-box;
40+
padding: @line-height;
41+
42+
.open.button,
43+
.panel {
44+
pointer-events: all;
45+
}
46+
47+
.open.button {
48+
margin: @line-height;
49+
}
50+
.panel {
51+
52+
position: absolute;
53+
display: none;
54+
top: 0;
55+
left: 0;
56+
width: 100%;
57+
height: 100%;
58+
background: rgba(0, 0, 0, 0.3);
59+
box-sizing: border-box;
60+
padding: @line-height;
61+
62+
textarea {
63+
font-family: 'Space Mono', monospace;
64+
font-size: @font-size;
65+
font-weight: 400;
66+
line-height: @line-height;
67+
background: transparent;
68+
border: none;
69+
outline: none;
70+
width: 100%;
71+
height: 100%;
72+
margin: @line-height;
73+
74+
}
75+
.close {
76+
position: absolute;
77+
display: block;
78+
top: @line-height;
79+
right: @line-height;
80+
font-size: 200%;
81+
line-height: 100%;
82+
}
83+
}
84+
}
85+
.button {
86+
cursor: pointer;
87+
}
88+
89+
&.writing {
90+
div.ui {
91+
.open.button {
92+
display: none;
93+
}
94+
.panel {
95+
display: block;
96+
}
97+
}
98+
}
99+
}
4100
}

src/utils/function.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function debounce(func, timeout) {
2+
3+
var timer;
4+
5+
return function() {
6+
7+
if (timer) {
8+
clearTimeout(timer);
9+
}
10+
11+
var scope = this;
12+
var args = arguments;
13+
14+
timer = setTimeout(function() {
15+
timer = null;
16+
func.apply(scope, args);
17+
}, timeout);
18+
19+
};
20+
21+
}
22+
23+
export { debounce };

0 commit comments

Comments
 (0)