Skip to content

Commit bcf6767

Browse files
committed
refactor(docusaurus): refactor to TS - shared/{navcard,card,ga}
#254
1 parent 45cdafd commit bcf6767

11 files changed

+53
-20
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/**
44
.github
55
public/
66
.workflows
7+
/**/*.d.ts

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
"import/no-unresolved": [
2727
2,
2828
{
29-
ignore: ["^@theme-original"],
29+
ignore: ["^@theme-original", "./styles.module.scss"],
3030
},
3131
],
3232
},

declaration.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.scss' {
2+
const content: Record<string, string>;
3+
export default content;
4+
};

global.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare global {
2+
interface Window {
3+
essss: string;
4+
ga: (eventType: string, options: {
5+
hitType: string,
6+
eventCategory: string,
7+
eventAction: string,
8+
eventLabel: string,
9+
eventValue: number,
10+
}) => void;
11+
}
12+
}
13+
14+
export {};

src/shared/lib/ga/ga.js src/shared/lib/ga/ga.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export const sendEvent = ({ category, action, label, value }) => {
1+
type EventOptions = {
2+
category: string;
3+
action: string;
4+
label: string;
5+
value?: number;
6+
};
7+
8+
export const sendEvent = ({ category, action, label, value }: EventOptions) => {
29
if (typeof window === undefined) return;
310
if (!window.ga) return;
411

File renamed without changes.

src/shared/ui/card/index.jsx src/shared/ui/card/index.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import React from "react";
22
import clsx from "clsx";
33
import styles from "./styles.module.scss";
4+
import type { AntdIconProps } from "@ant-design/icons/lib/components/AntdIcon";
45

5-
export function Card({ Icon, title, description, size }) {
6+
type Props = {
7+
Icon: React.FC<AntdIconProps>;
8+
title: string;
9+
description: React.ReactNode;
10+
size: number;
11+
};
12+
13+
export const Card: React.FC<Props> = ({ Icon, title, description, size }) => {
614
return (
715
<div className={clsx("col", `col--${size}`)}>
816
<div className="text--center">
@@ -14,4 +22,4 @@ export function Card({ Icon, title, description, size }) {
1422
</div>
1523
</div>
1624
);
17-
}
25+
};

src/shared/ui/nav-card/index.jsx src/shared/ui/nav-card/index.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import Link from "@docusaurus/Link";
55
import { ga } from "@site/src/shared/lib/ga";
66
import styles from "./styles.module.scss";
77

8+
type Props = {
9+
title: React.ReactNode;
10+
description: React.ReactNode;
11+
to: string;
12+
Icon: string | any;
13+
tags?: string[];
14+
className?: string;
15+
disabled?: boolean;
16+
theme?: "default" | "mini" | "primary";
17+
};
18+
819
/**
920
* NavCard for linking
1021
* @see https://docusaurus.io/docs/next/markdown-features/react#importing-markdown
11-
* @param {import('./types').Props} props
1222
*/
13-
export const NavCard = (props) => {
23+
export const NavCard: React.FC<Props> = (props) => {
1424
const { title, description, to, Icon, tags, className, disabled, theme = "default" } = props;
1525
const handleClick = useCallback(() => {
1626
ga.sendEvent({

src/shared/ui/nav-card/tmpl.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import NavCard from "./index.jsx";
1+
import NavCard from "./index.tsx";
22

33
<NavCard {...props} />

src/shared/ui/nav-card/types.d.ts

-12
This file was deleted.

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@tsconfig/docusaurus/tsconfig.json",
33
"compilerOptions": {
4-
"baseUrl": "."
4+
"baseUrl": ".",
5+
"typeRoots": ["declaration.d.ts", "global.d.ts", "./node_modules/@types"]
56
}
67
}

0 commit comments

Comments
 (0)