Skip to content

Commit 09bc9e8

Browse files
committed
seperated compopnents into files, added button
1 parent 9cf7b04 commit 09bc9e8

File tree

5 files changed

+95
-47
lines changed

5 files changed

+95
-47
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch index.tsx",
9+
"type": "firefox",
10+
"request": "launch",
11+
"reAttach": true,
12+
"file": "${workspaceFolder}/index.tsx"
13+
}
14+
]
15+
}

src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import './App.css';
3-
import { MainForm } from './MainForm';
3+
import { MainForm } from './Components/MainForm';
44

55
const App = () => (
66
<MainForm message="Hello!"/>

src/MainForm.tsx src/Components/MainForm.tsx

+4-46
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
1-
import React, { createRef } from 'react';
1+
import React from 'react';
22
import Moment from 'react-moment';
3-
import './App.css';
3+
import TimeInput from './TimeInput';
4+
import Timer from './Timer';
45

56
type MainFormState = {
67
count: number,
78
currentDateTime: Date
89
}
910

10-
type TimeInputProps = {
11-
defaultTimerDuration: string
12-
}
13-
14-
type TimeInputState = {
15-
value: string,
16-
}
17-
18-
19-
export class TimeInput extends React.Component<TimeInputProps, TimeInputState>{
20-
private instanceRef = createRef<HTMLInputElement>();
21-
22-
constructor(props: TimeInputProps){
23-
super(props);
24-
this.state = { value: props.defaultTimerDuration }
25-
this.handleChange = this.handleChange.bind(this);
26-
}
27-
state: TimeInputState = {
28-
value: "time..."
29-
}
30-
31-
handleChange(e: React.ChangeEvent<HTMLInputElement>){
32-
this.setState({ value: e.target.value })
33-
}
34-
35-
handleClick(e: MouseEvent){
36-
this.setState({ value:""});
37-
}
38-
39-
render(){
40-
return(
41-
<div>
42-
<form>
43-
<input type="text" value={this.state.value} onChange={this.handleChange} ref={this.instanceRef} />
44-
</form>
45-
</div>
46-
)
47-
}
48-
}
49-
50-
export class Timer extends React.Component<{}, {}>{
51-
52-
}
53-
5411
export class MainForm extends React.Component<{ message: string}, MainFormState>{
5512
state: MainFormState = {
5613
count: 0,
@@ -64,6 +21,7 @@ export class MainForm extends React.Component<{ message: string}, MainFormState>
6421
<div onClick={() => this.increment(1)}>
6522
{this.props.message} {this.state.count}
6623
</div>
24+
<Timer buttonText="Button"></Timer>
6725
<TimeInput defaultTimerDuration="15" ></TimeInput>
6826
<Moment format="YYYY/MM/DD hh:mm:ss"></Moment>
6927
</div>

src/Components/TimeInput.tsx

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { createRef } from "react";
2+
3+
type TimeInputProps = {
4+
defaultTimerDuration: string
5+
}
6+
7+
type TimeInputState = {
8+
value: string,
9+
}
10+
11+
export default class TimeInput extends React.Component<TimeInputProps, TimeInputState>{
12+
private instanceRef = createRef<HTMLInputElement>();
13+
14+
constructor(props: TimeInputProps){
15+
super(props);
16+
this.state = { value: props.defaultTimerDuration }
17+
this.handleChange = this.handleChange.bind(this);
18+
this.handleClick = this.handleClick.bind(this);
19+
}
20+
state: TimeInputState = {
21+
value: "time..."
22+
}
23+
24+
handleChange(e: React.ChangeEvent<HTMLInputElement>){
25+
this.setState({ value: e.target.value })
26+
}
27+
28+
handleClick(e: React.MouseEvent<HTMLInputElement>){
29+
this.setState({ value: ""})
30+
}
31+
32+
render(){
33+
return(
34+
<div>
35+
<form>
36+
<input type="text" value={this.state.value}
37+
onChange={this.handleChange}
38+
onClick={this.handleClick}
39+
ref={this.instanceRef} />
40+
</form>
41+
</div>
42+
)
43+
}
44+
}

src/Components/Timer.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react";
2+
3+
type TimerProps = {
4+
buttonText: string
5+
}
6+
7+
type TimerState = {
8+
value: string,
9+
}
10+
11+
export default class Timer extends React.Component<TimerProps, TimerState>{
12+
constructor(props: TimerProps){
13+
super(props);
14+
this.state = {
15+
value:props.buttonText
16+
}
17+
this.handleClick = this.handleClick.bind(this);
18+
}
19+
20+
handleClick(event: React.MouseEvent){
21+
this.setState({ value:"Clicked"})
22+
}
23+
24+
render(){
25+
return(
26+
<div>
27+
<button onClick={this.handleClick}>{ this.state.value }</button>
28+
</div>
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)