Skip to content

Commit 9c82e47

Browse files
committed
feat/fix: fix typing issues, add typings for css modules
1 parent d051eed commit 9c82e47

File tree

16 files changed

+265
-15
lines changed

16 files changed

+265
-15
lines changed

website/next.config.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1+
2+
const withTypedCssModules = (nextConfig = {}) => ({
3+
...nextConfig,
4+
webpack (config) {
5+
const cssLoaderRegex = /(?<!post)css-loader/;
6+
const typingsForCssModulesLoader = {
7+
loader: "@teamsupercell/typings-for-css-modules-loader",
8+
options: {
9+
disableLocalsExport: true,
10+
verifyOnly: process.env.NODE_ENV === "production",
11+
banner: `// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY\n`,
12+
},
13+
};
14+
15+
// looking for the webpack rules where `css-loader` is specified
16+
const { oneOf } = config.module.rules.find((rule) => Array.isArray(rule.oneOf));
17+
const rules = oneOf.filter((rule) => Array.isArray(rule.use));
18+
19+
rules.forEach((rule) => {
20+
const cssLoaderIndex = rule.use.findIndex((loader) => cssLoaderRegex.test(loader.loader));
21+
// no `css-loader` here -> skip
22+
if (cssLoaderIndex === -1) { return; }
23+
// webpack loaders are executed in reverse order
24+
// we want to inject the typings loader after `css-loader`,
25+
// but before other loaders `style-loader` or `mini-css-extract`
26+
rule.use.splice(cssLoaderIndex, 0, { ...typingsForCssModulesLoader });
27+
})
28+
29+
return config;
30+
}
31+
})
32+
133
/** @type {import('next').NextConfig} */
2-
module.exports = {
34+
module.exports = withTypedCssModules({
335
reactStrictMode: true,
4-
}
36+
})

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
1213
"clsx": "^1.1.1",
1314
"copy-text-to-clipboard": "^3.0.1",
1415
"glob": "^7.2.0",

website/src/components/Navbar/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ const Navbar = (): JSX.Element => {
3636
<a className={s.navItem}>{label}</a>
3737
</Link>
3838
))}
39-
<Link href={"https://github.com/acmucsd/acm-ai-workshops"}>
40-
<a className={s.githubButton}>
41-
<img src="/static/github.svg" alt="GitHub" />
42-
</a>
43-
</Link>
39+
<Link href={"https://github.com/acmucsd/acm-ai-workshops"}><a>
40+
<img src="/static/github.svg" alt="GitHub" />
41+
</a></Link>
4442
</div>
4543

4644
{/* TODO - mobile nav links */}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesModuleScssNamespace {
4+
export interface IStylesModuleScss {
5+
hidden: string;
6+
left: string;
7+
logo: string;
8+
navItem: string;
9+
navbar: string;
10+
right: string;
11+
}
12+
}
13+
14+
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss;
15+
16+
export = StylesModuleScssModule;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesModuleScssNamespace {
4+
export interface IStylesModuleScss {
5+
active: string;
6+
arrow: string;
7+
category: string;
8+
collapsed: string;
9+
desktop: string;
10+
items: string;
11+
link: string;
12+
}
13+
}
14+
15+
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss;
16+
17+
export = StylesModuleScssModule;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesModuleScssNamespace {
4+
export interface IStylesModuleScss {
5+
active: string;
6+
arrow: string;
7+
category: string;
8+
collapsed: string;
9+
contentContainer: string;
10+
contentWrapper: string;
11+
desktop: string;
12+
hidden: string;
13+
items: string;
14+
left: string;
15+
link: string;
16+
logo: string;
17+
navItem: string;
18+
navbar: string;
19+
right: string;
20+
sidebarContainer: string;
21+
wrapper: string;
22+
}
23+
}
24+
25+
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss;
26+
27+
export = StylesModuleScssModule;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesModuleScssNamespace {
4+
export interface IStylesModuleScss {
5+
card: string;
6+
description: string;
7+
grid: string;
8+
title: string;
9+
truncate: string;
10+
}
11+
}
12+
13+
declare const StylesModuleScssModule: StylesModuleScssNamespace.IStylesModuleScss;
14+
15+
export = StylesModuleScssModule;

website/src/layouts/pages/types/index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ export interface WithBreadcrumbs {
2727
sidebar: SidebarItemType[];
2828
}
2929

30-
export interface DocPageProps extends WithSidebar, WithBreadcrumbs {
30+
export interface CommonPageProps extends WithSidebar, WithBreadcrumbs {
31+
32+
}
33+
34+
export interface DocPageProps extends CommonPageProps {
3135
type: Doc['type'];
3236
title: string;
3337
source: MDXRemoteSerializeResult<Record<string, unknown>>;
3438
}
3539

36-
export interface CategoryPageProps extends WithSidebar, WithBreadcrumbs {
40+
export interface CategoryPageProps extends CommonPageProps {
3741
type: 'category';
3842
items: Array<Item>
3943
}

website/src/mdx/CodeBlock/CopyButton.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ interface CopyButtonProps {
3333
type="button"
3434
aria-label={isCopied ? 'Copied' : 'Copy code to clipboard'}
3535
title="Copy"
36-
className={c(
37-
s.copyButton,
38-
s.cleanBtn,
39-
isCopied && s.copied,
40-
)}
36+
className={c(s.copyButton, isCopied && s.copied)}
4137
onClick={handleCopyCode}>
4238
<span className={s.icons} aria-hidden="true">
4339
<svg className={s.copyIcon} viewBox="0 0 24 24">
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
2+
3+
declare namespace StylesExportModuleScssNamespace {
4+
export interface IStylesExportModuleScss {
5+
codeBlock: string;
6+
codeBlockContainer: string;
7+
content: string;
8+
copied: string;
9+
copyButton: string;
10+
copyIcon: string;
11+
icons: string;
12+
line: string;
13+
lineContent: string;
14+
lineNumber: string;
15+
lines: string;
16+
numbered: string;
17+
prismBackgroundColor: string;
18+
prismColor: string;
19+
standalone: string;
20+
successIcon: string;
21+
title: string;
22+
}
23+
}
24+
25+
declare const StylesExportModuleScssModule: StylesExportModuleScssNamespace.IStylesExportModuleScss;
26+
27+
export = StylesExportModuleScssModule;

0 commit comments

Comments
 (0)