Skip to content

Commit 417a4d6

Browse files
authored
Typescript (#118)
* ts files extension * type code * eslint errors * typscript configurations and eslint updates * clean after typescript migration * code review
1 parent 325a96f commit 417a4d6

30 files changed

+953
-11062
lines changed

.babelrc

-3
This file was deleted.

.eslintrc

-17
This file was deleted.

demo/App.js demo/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export default function App() {
5656
<Header>
5757
<H1>react-timer-hook</H1>
5858
<div>
59-
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160" height="30" title="GitHub" />
60-
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=fork&count=true&size=large" frameborder="0" scrolling="0" width="126" height="30" title="GitHub" />
59+
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=star&count=true&size=large" frameBorder="0" scrolling="0" width="160" height="30" title="GitHub" />
60+
<iframe src="https://ghbtns.com/github-btn.html?user=amrlabib&repo=react-timer-hook&type=fork&count=true&size=large" frameBorder="0" scrolling="0" width="126" height="30" title="GitHub" />
6161
</div>
6262
</Header>
6363
</Container>

demo/components/Button.js demo/components/Button.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import styled from 'styled-components';
32

43
const ButtonStyled = styled.button`
@@ -16,8 +15,4 @@ const ButtonStyled = styled.button`
1615
}
1716
`;
1817

19-
export default function Button(props) {
20-
return (
21-
<ButtonStyled {...props} />
22-
);
23-
}
18+
export default ButtonStyled;

demo/components/Digit.js demo/components/Digit.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ const SingleDigit = styled.span`
4949
}
5050
`;
5151

52-
export default function Digit({ value, title, isMIlliseconds }) {
52+
type DigitType = {
53+
value: number,
54+
title: string,
55+
isMIlliseconds?: boolean;
56+
};
57+
58+
export default function Digit({ value, title, isMIlliseconds }: DigitType) {
5359
const digits = value.toString().padStart(4, '0');
5460
return (
5561
<Container>

demo/components/TimerStyled.js demo/components/TimerStyled.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ const Separtor = styled.span`
2626
margin: 5px 0px;
2727
`;
2828

29-
export default function TimerStyled({ milliseconds, seconds, minutes, hours, days, enableMilliseconds }) {
29+
type TimerType = {
30+
milliseconds: number,
31+
seconds: number,
32+
minutes: number,
33+
hours: number,
34+
days?: number,
35+
enableMilliseconds: boolean;
36+
};
37+
38+
export default function TimerStyled({ milliseconds, seconds, minutes, hours, days, enableMilliseconds }: TimerType) {
3039
return (
3140
<TimerContainer>
32-
{days !== undefined ? <Digit value={days} title="DAYS" addSeparator /> : null}
41+
{days !== undefined ? <Digit value={days} title="DAYS" /> : null}
3342
{days !== undefined ? (<SepartorContainer><Separtor /><Separtor /></SepartorContainer>): null}
34-
<Digit value={hours} title="HOURS" addSeparator />
43+
<Digit value={hours} title="HOURS" />
3544
<SepartorContainer><Separtor /><Separtor /></SepartorContainer>
36-
<Digit value={minutes} title="MINUTES" addSeparator />
45+
<Digit value={minutes} title="MINUTES" />
3746
<SepartorContainer><Separtor /><Separtor /></SepartorContainer>
3847
<Digit value={seconds} title="SECONDS" />
3948
{enableMilliseconds ?

demo/components/UseStopwatchDemo.js demo/components/UseStopwatchDemo.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { useStopwatch } from '../../src/index';
33
import Button from './Button';
44
import TimerStyled from './TimerStyled';
55

6-
export default function UseStopwatchDemo({ interval }) {
7-
const time = new Date();
8-
time.setMilliseconds(time.getMilliseconds() + 10000);
6+
export default function UseStopwatchDemo({ interval }: { interval: number}) {
97
const {
108
milliseconds,
119
seconds,
@@ -15,7 +13,7 @@ export default function UseStopwatchDemo({ interval }) {
1513
start,
1614
pause,
1715
reset,
18-
} = useStopwatch({ autoStart: true, interval, offsetTimestamp: 0 });
16+
} = useStopwatch({ interval });
1917

2018

2119
return (
@@ -24,7 +22,7 @@ export default function UseStopwatchDemo({ interval }) {
2422
<TimerStyled milliseconds={milliseconds} seconds={seconds} minutes={minutes} hours={hours} days={days} enableMilliseconds={interval < 1000} />
2523
<Button onClick={start}>Start</Button>
2624
<Button onClick={pause}>Pause</Button>
27-
<Button onClick={reset}>Reset</Button>
25+
<Button onClick={() => reset()}>Reset</Button>
2826
</div>
2927
);
3028
}

demo/components/UseTimeDemo.js demo/components/UseTimeDemo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { useTime } from '../../src/index';
33
import TimerStyled from './TimerStyled';
44

5-
export default function UseTimeDemo({ interval }) {
5+
export default function UseTimeDemo({ interval }: { interval: number}) {
66
const {
77
milliseconds,
88
seconds,

demo/components/UseTimerDemo.js demo/components/UseTimerDemo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTimer } from '../../src/index';
33
import TimerStyled from './TimerStyled';
44
import Button from './Button';
55

6-
export default function UseTimerDemo({ expiryTimestamp, interval }) {
6+
export default function UseTimerDemo({ expiryTimestamp, interval }: { expiryTimestamp: Date, interval: number}) {
77
const {
88
milliseconds,
99
seconds,

demo/index.js demo/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react';
21
import ReactDOM from 'react-dom';
32
import App from './App';
43

4+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5+
//@ts-expect-error
56
ReactDOM.render(<App />, document.getElementById('app'));

0 commit comments

Comments
 (0)