Skip to content

Commit a6d96cb

Browse files
authored
Add type check to pre commit hook (#25)
1 parent 80d36d4 commit a6d96cb

File tree

7 files changed

+110
-93
lines changed

7 files changed

+110
-93
lines changed

.storybook/preview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import React from "react";
12
import { Story as StoryType } from "@storybook/react";
23
import { ThemeProvider } from "styled-components";
3-
import { GlobalStyle } from "../styles/GlobalStyle";
4+
import { GlobalStyle } from "../styles/global-style";
45
import { theme } from "../styles/theme";
56
import { NavigationProvider } from "../features/ui";
67
import { decorator as mockRouterDecorator } from "../__mocks__/next/router";

features/ui/sidebar-navigation/sidebar-navigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const Logo = styled.img`
7272
width: 7.375rem;
7373
7474
@media (min-width: ${breakpoint("desktop")}) {
75-
margin: ${space(0, 3)};
75+
margin: ${space(0, 4)};
7676
}
7777
`;
7878

package-lock.json

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

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"build-storybook": "build-storybook",
1515
"prepare": "husky install"
1616
},
17+
"lint-staged": {
18+
"*.{js,jsx,ts,tsx}": "eslint --cache --fix",
19+
"*.{ts,tsx}": "tsc-files --noEmit --incremental false",
20+
"*.{js,jsx,ts,tsx,css,md}": "prettier --write"
21+
},
1722
"dependencies": {
1823
"@fontsource/inter": "^4.5.7",
1924
"@types/lodash": "^4.14.181",
@@ -51,10 +56,7 @@
5156
"lint-staged": "^12.3.5",
5257
"lodash": "^4.17.21",
5358
"prettier": "^2.3.0",
59+
"tsc-files": "^1.1.3",
5460
"typescript": "4.6.2"
55-
},
56-
"lint-staged": {
57-
"*.{js,jsx,ts,tsx}": "eslint --cache --fix",
58-
"*.{js,jsx,ts,tsx,css,md}": "prettier --write"
5961
}
6062
}

styled.d.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

styles/global-style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createGlobalStyle } from "styled-components";
22
import { normalize } from "styled-normalize";
3-
import { color } from "./theme";
3+
import { color, Theme } from "./theme";
44

5-
export const GlobalStyle = createGlobalStyle`
5+
export const GlobalStyle = createGlobalStyle<{ theme: Theme }>`
66
${normalize}
77
88
body {

styles/theme.ts

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,67 @@
1-
import { DefaultTheme } from "styled-components";
1+
type Color = {
2+
25: string;
3+
50: string;
4+
100: string;
5+
200: string;
6+
300: string;
7+
400: string;
8+
500: string;
9+
600: string;
10+
700: string;
11+
800: string;
12+
900: string;
13+
};
14+
15+
type Font = {
16+
regular: string;
17+
medium: string;
18+
semibold: string;
19+
};
20+
21+
export type Theme = {
22+
color: {
23+
gray: Color;
24+
primary: Color;
25+
error: Color;
26+
warning: Color;
27+
success: Color;
28+
};
29+
space: {
30+
0: string;
31+
1: string;
32+
2: string;
33+
3: string;
34+
4: string;
35+
5: string;
36+
6: string;
37+
8: string;
38+
10: string;
39+
12: string;
40+
16: string;
41+
20: string;
42+
24: string;
43+
};
44+
size: {
45+
headerHeight: string;
46+
};
47+
breakpoint: {
48+
desktop: string;
49+
};
50+
zIndex: {
51+
header: number;
52+
};
53+
font: {
54+
text: {
55+
xs: Font;
56+
sm: Font;
57+
md: Font;
58+
};
59+
display: {
60+
sm: Font;
61+
md: Font;
62+
};
63+
};
64+
};
265

366
export const theme = {
467
color: {
@@ -186,38 +249,37 @@ export const theme = {
186249
};
187250

188251
export function color(
189-
name: keyof DefaultTheme["color"],
190-
shade: keyof DefaultTheme["color"]["gray"]
252+
name: keyof Theme["color"],
253+
shade: keyof Theme["color"]["gray"]
191254
) {
192-
return ({ theme }: { theme: DefaultTheme }) => theme.color[name][shade];
255+
return ({ theme }: { theme: Theme }) => theme.color[name][shade];
193256
}
194257

195-
export function space(...names: Array<keyof DefaultTheme["space"]>) {
196-
return ({ theme }: { theme: DefaultTheme }) => {
258+
export function space(...names: Array<keyof Theme["space"]>) {
259+
return ({ theme }: { theme: Theme }) => {
197260
const spaces = names.map((name) => theme.space[name]);
198261
return spaces.join(" ");
199262
};
200263
}
201264

202-
export function breakpoint(name: keyof DefaultTheme["breakpoint"]) {
203-
return ({ theme }: { theme: DefaultTheme }) => theme.breakpoint[name];
265+
export function breakpoint(name: keyof Theme["breakpoint"]) {
266+
return ({ theme }: { theme: Theme }) => theme.breakpoint[name];
204267
}
205268

206-
export function zIndex(name: keyof DefaultTheme["zIndex"]) {
207-
return ({ theme }: { theme: DefaultTheme }) => theme.zIndex[name];
269+
export function zIndex(name: keyof Theme["zIndex"]) {
270+
return ({ theme }: { theme: Theme }) => theme.zIndex[name];
208271
}
209272

210273
export function textFont(
211-
size: keyof DefaultTheme["font"]["text"],
212-
weight: keyof DefaultTheme["font"]["text"]["sm"]
274+
size: keyof Theme["font"]["text"],
275+
weight: keyof Theme["font"]["text"]["sm"]
213276
) {
214-
return ({ theme }: { theme: DefaultTheme }) => theme.font.text[size][weight];
277+
return ({ theme }: { theme: Theme }) => theme.font.text[size][weight];
215278
}
216279

217280
export function displayFont(
218-
size: keyof DefaultTheme["font"]["display"],
219-
weight: keyof DefaultTheme["font"]["display"]["sm"]
281+
size: keyof Theme["font"]["display"],
282+
weight: keyof Theme["font"]["display"]["sm"]
220283
) {
221-
return ({ theme }: { theme: DefaultTheme }) =>
222-
theme.font.display[size][weight];
284+
return ({ theme }: { theme: Theme }) => theme.font.display[size][weight];
223285
}

0 commit comments

Comments
 (0)