From 6e52e2634fe6bb3253b3c848b8977acbd1244ef0 Mon Sep 17 00:00:00 2001 From: Ali Josheghani Date: Mon, 20 May 2024 22:25:03 +0330 Subject: [PATCH] feat : add types for all props components , add scroll css styles --- package-lock.json | 7 ++++ package.json | 1 + src/components/alert/Alert.tsx | 20 +++++++--- src/{assets => components}/button/index.tsx | 4 +- .../header/components/navbar/MobileMenu.tsx | 3 +- .../components/navbar/MobileMenuButton.tsx | 4 +- .../header/components/navbar/Navbar.tsx | 9 +++-- .../header/components/navbar/NavbarLink.tsx | 5 ++- src/index.css | 37 +++++++++++++++++++ src/types/alertProps.d.ts | 7 ++++ src/types/buttonProps.d.ts | 5 +++ src/types/mobileMenu.d.ts | 7 ++++ src/types/mobileMenuButton.d.ts | 4 ++ src/types/navbarLink.d.ts | 12 ++++++ src/types/routes.d.ts | 5 +++ 15 files changed, 116 insertions(+), 14 deletions(-) rename src/{assets => components}/button/index.tsx (70%) create mode 100644 src/types/alertProps.d.ts create mode 100644 src/types/buttonProps.d.ts create mode 100644 src/types/mobileMenu.d.ts create mode 100644 src/types/mobileMenuButton.d.ts create mode 100644 src/types/navbarLink.d.ts create mode 100644 src/types/routes.d.ts diff --git a/package-lock.json b/package-lock.json index 64f83b0..9035eb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "react-router-dom": "^6.23.1" }, "devDependencies": { + "@types/nprogress": "^0.2.3", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", @@ -1317,6 +1318,12 @@ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "dev": true }, + "node_modules/@types/nprogress": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@types/nprogress/-/nprogress-0.2.3.tgz", + "integrity": "sha512-k7kRA033QNtC+gLc4VPlfnue58CM1iQLgn1IMAU8VPHGOj7oIHPp9UlhedEnD/Gl8evoCjwkZjlBORtZ3JByUA==", + "dev": true + }, "node_modules/@types/prop-types": { "version": "15.7.12", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", diff --git a/package.json b/package.json index eb27ea8..3101b22 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "react-router-dom": "^6.23.1" }, "devDependencies": { + "@types/nprogress": "^0.2.3", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", diff --git a/src/components/alert/Alert.tsx b/src/components/alert/Alert.tsx index a366b20..5123bd5 100644 --- a/src/components/alert/Alert.tsx +++ b/src/components/alert/Alert.tsx @@ -1,5 +1,16 @@ -const Alert = ({ children, type, message }) => { - const types = { +import { AlertProps, MessageType } from "../../types/alertProps"; + +const Alert = ({ children, type = "info", message }: AlertProps) => { + const types: Record< + MessageType, + { + text: string; + bg: string; + darkText: string; + darkBg: string; + iconPath: string; + } + > = { info: { text: "text-blue-800", bg: "bg-blue-50", @@ -42,8 +53,7 @@ const Alert = ({ children, type, message }) => { }, }; - const { text, bg, darkText, darkBg, iconPath, title } = - types[type] || types.info; + const { text, bg, darkText, darkBg, iconPath } = types[type]; return (
{ > - Info + {children}
{children} {message}
diff --git a/src/assets/button/index.tsx b/src/components/button/index.tsx similarity index 70% rename from src/assets/button/index.tsx rename to src/components/button/index.tsx index f0d005a..4b7d807 100644 --- a/src/assets/button/index.tsx +++ b/src/components/button/index.tsx @@ -1,4 +1,6 @@ -function Button({ children, onClick, extra }) { +import { ButtonProps } from "../../types/buttonProps"; + +function Button({ children, onClick, extra }: ButtonProps) { return (