Skip to content

Commit 0cf6f8f

Browse files
committed
demo components
1 parent 312003e commit 0cf6f8f

File tree

5 files changed

+134
-43
lines changed

5 files changed

+134
-43
lines changed

demo/App.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
11
import React from 'react';
2-
import { useTimer } from '../src/index';
2+
import UseTimerDemo from './components/UseTimerDemo';
3+
import UseStopwatchDemo from './components/UseStopwatchDemo';
4+
import UseTimeDemo from './components/UseTimeDemo';
35

46

5-
function MyTimer({ expiryTimestamp }) {
6-
const {
7-
seconds,
8-
minutes,
9-
hours,
10-
days,
11-
isRunning,
12-
start,
13-
pause,
14-
resume,
15-
restart,
16-
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });
17-
18-
19-
return (
20-
<div style={{ textAlign: 'center' }}>
21-
<h1>react-timer-hook </h1>
22-
<p>Timer Demo</p>
23-
<div style={{ fontSize: '100px' }}>
24-
<span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
25-
</div>
26-
<p>{isRunning ? 'Running' : 'Not running'}</p>
27-
<button type="button" onClick={start}>Start</button>
28-
<button type="button" onClick={pause}>Pause</button>
29-
<button type="button" onClick={resume}>Resume</button>
30-
<button
31-
type="button"
32-
onClick={() => {
33-
// Restarts to 5 minutes timer
34-
const time = new Date();
35-
time.setSeconds(time.getSeconds() + 300);
36-
restart(time);
37-
}}
38-
>
39-
Restart
40-
</button>
41-
</div>
42-
);
43-
}
44-
457
export default function App() {
468
const time = new Date();
479
// time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
4810
time.setMilliseconds(time.getMilliseconds() + 100); // 6.5 seconds timer
4911
return (
5012
<div>
51-
<MyTimer expiryTimestamp={time} />
13+
<UseTimerDemo expiryTimestamp={time} />
14+
<UseStopwatchDemo />
15+
<UseTimeDemo />
5216
</div>
5317
);
5418
}

demo/components/UseStopwatchDemo.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { useStopwatch } from '../../src/index';
3+
4+
export default function UseStopwatchDemo() {
5+
const {
6+
seconds,
7+
minutes,
8+
hours,
9+
days,
10+
isRunning,
11+
start,
12+
pause,
13+
reset,
14+
} = useStopwatch({ autoStart: true });
15+
16+
17+
return (
18+
<div style={{textAlign: 'center'}}>
19+
<p>Stopwatch Demo</p>
20+
<div style={{fontSize: '100px'}}>
21+
<span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
22+
</div>
23+
<p>{isRunning ? 'Running' : 'Not running'}</p>
24+
<button onClick={start}>Start</button>
25+
<button onClick={pause}>Pause</button>
26+
<button onClick={reset}>Reset</button>
27+
</div>
28+
);
29+
}

demo/components/UseTimeDemo.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { useTime } from '../../src/index';
3+
4+
export default function UseTimeDemo() {
5+
const {
6+
seconds,
7+
minutes,
8+
hours,
9+
ampm,
10+
} = useTime({ format: '12-hour'});
11+
12+
return (
13+
<div style={{textAlign: 'center'}}>
14+
<p>Current Time Demo</p>
15+
<div style={{fontSize: '100px'}}>
16+
<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span><span>{ampm}</span>
17+
</div>
18+
</div>
19+
);
20+
}

demo/components/UseTimerDemo.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { useTimer } from '../../src/index';
3+
4+
export default function UseTimerDemo({ expiryTimestamp }) {
5+
const {
6+
seconds,
7+
minutes,
8+
hours,
9+
days,
10+
isRunning,
11+
start,
12+
pause,
13+
resume,
14+
restart,
15+
} = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });
16+
17+
18+
return (
19+
<div style={{ textAlign: 'center' }}>
20+
<h1>react-timer-hook </h1>
21+
<p>Timer Demo</p>
22+
<div style={{ fontSize: '100px' }}>
23+
<span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
24+
</div>
25+
<p>{isRunning ? 'Running' : 'Not running'}</p>
26+
<button type="button" onClick={start}>Start</button>
27+
<button type="button" onClick={pause}>Pause</button>
28+
<button type="button" onClick={resume}>Resume</button>
29+
<button
30+
type="button"
31+
onClick={() => {
32+
// Restarts to 5 minutes timer
33+
const time = new Date();
34+
time.setSeconds(time.getSeconds() + 300);
35+
restart(time);
36+
}}
37+
>
38+
Restart
39+
</button>
40+
</div>
41+
);
42+
}

docs/index.js

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)