-
Notifications
You must be signed in to change notification settings - Fork 3
/
simple.tsx
56 lines (49 loc) · 1.47 KB
/
simple.tsx
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
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import useTextWidth from '../useTextWidth';
const App = () => {
const [text, setText] = useState('Hello World!');
const [fontType, setFontType] = useState('Times');
const [fontSize, setFontSize] = useState('16px');
const font = `${fontSize} ${fontType}`;
const width = useTextWidth({ text, font });
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
setText(event.currentTarget.value);
};
const onFontTypeChange = (event: React.FormEvent<HTMLSelectElement>) => {
setFontType(event.currentTarget.value);
};
const onFontSizeChange = (event: React.FormEvent<HTMLInputElement>) => {
setFontSize(event.currentTarget.value);
};
return (
<div>
<div>
<label>
Your text:
<input type="text" value={text} onChange={onChange} />
</label>
</div>
<div>
<label>
Font type:
<select onChange={onFontTypeChange}>
<option value="Times">Times</option>
<option value="Helvetica">Helvetica</option>
</select>
</label>
<label>
Font size:
<input type="text" value={fontSize} onChange={onFontSizeChange} />
</label>
</div>
<div>
<p>
"{text}" text width is {width}px
</p>
</div>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('root'));