feat : add types for all props components , add scroll css styles

This commit is contained in:
Ali Josheghani
2024-05-20 22:25:03 +03:30
parent fd7bc724f9
commit 6e52e2634f
15 changed files with 116 additions and 14 deletions

View File

@@ -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 (
<div
@@ -59,7 +69,7 @@ const Alert = ({ children, type, message }) => {
>
<path d={iconPath} />
</svg>
<span className="sr-only">Info</span>
<span className="sr-only">{children}</span>
<div>
<span className="font-medium">{children}</span> {message}
</div>

View File

@@ -1,4 +1,6 @@
function Button({ children, onClick, extra }) {
import { ButtonProps } from "../../types/buttonProps";
function Button({ children, onClick, extra }: ButtonProps) {
return (
<button
className={`px-4 py-1 md:px-5 md:py-2 rounded-md transition duration-300 ease-in-out transform bg-white text-[#333] hover:bg-gray-600 hover:text-white ${extra}`}

View File

@@ -1,6 +1,7 @@
// src/components/Header/Navbar/MobileMenu.tsx
import { MobileMenuProps } from "../../../../types/mobileMenu";
import NavbarLink from "./NavbarLink";
const MobileMenu = ({ isOpen, toggleMenu, routes }) => {
const MobileMenu = ({ isOpen, toggleMenu, routes }: MobileMenuProps) => {
return (
<>
<div

View File

@@ -1,4 +1,6 @@
const MobileMenuButton = ({ isOpen, onClick }) => {
import { MobileMenuButtonProps } from "../../../../types/mobileMenuButton";
const MobileMenuButton = ({ isOpen, onClick }: MobileMenuButtonProps) => {
return (
<button
onClick={onClick}

View File

@@ -1,16 +1,17 @@
// src/components/Header/Navbar/Navbar.tsx
import React, { useState, useEffect } from "react";
import { useState, useEffect } from "react";
import MobileMenuButton from "./MobileMenuButton";
import MobileMenu from "./MobileMenu";
import NavbarLink from "./NavbarLink";
import router from "../../../../routes/routes";
import Button from "../../../../assets/button";
import Button from "../../../button";
import { Link } from "react-router-dom";
import { Route } from "../../../../types/routes";
const Navbar = () => {
const [isOpen, setIsOpen] = useState(false);
const [isOpen, setIsOpen] = useState<boolean>(false);
const [routes, setRoutes] = useState(router);
const [routes] = useState<Route[]>(router);
const toggleMenu = () => {
setIsOpen(!isOpen);

View File

@@ -1,10 +1,11 @@
import { NavLink } from "react-router-dom";
import { NavbarLinkProps, NavData } from "../../../../types/navbarLink";
const NavbarLink = ({ to, children, onClick }) => {
const NavbarLink = ({ to, children, onClick }: NavbarLinkProps) => {
return (
<NavLink
to={to}
className={(navData) =>
className={(navData: NavData) =>
navData.isActive
? "block px-2 mx-3 py-2 text-base font-medium text-yellow-600 border-b-2 border-yellow-600"
: "block px-2 mx-3 py-2 rounded-md text-base font-medium text-white"

View File

@@ -32,4 +32,41 @@
@apply backdrop-blur-[19px] backdrop-saturate-[200%] bg-[rgba(17,25,40,0.25)] rounded-xl;
-webkit-backdrop-filter: blur(19px) saturate(200%);
}
/* برای مرورگرهای WebKit (مثل Chrome و Safari) */
::-webkit-scrollbar {
width: 12px; /* عرض نوار اسکرول */
}
::-webkit-scrollbar-track {
background: transparent; /* پس‌زمینه نوار اسکرول */
}
::-webkit-scrollbar-thumb {
@apply bg-yellow-600; /* رنگ نوار اسکرول */
border-radius: 20px; /* گرد کردن نوار اسکرول */
border: 3px solid transparent; /* ایجاد فضای خالی در اطراف نوار اسکرول */
background-clip: content-box; /* اطمینان از حفظ فضای خالی */
}
/* برای مرورگر Firefox */
* {
scrollbar-width: thin; /* عرض نوار اسکرول */
scrollbar-color: #ca8a04 transparent; /* رنگ نوار اسکرول و پس‌زمینه */
}
/* برای مرورگرهای مبتنی بر Blink (مثل Edge) */
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background-color: #ca8a04;
border-radius: 20px;
border: 3px solid transparent;
background-clip: content-box;
}
}

7
src/types/alertProps.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
export type MessageType = "info" | "danger" | "success" | "warning" | "dark";
export interface AlertProps {
children: React.ReactNode;
type?: "info" | "danger" | "success" | "warning" | "dark";
message: string;
}

5
src/types/buttonProps.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export interface ButtonProps {
children: React.ReactNode;
onClick?: () => void;
extra?: React.CSSProperties;
}

7
src/types/mobileMenu.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
import { Route } from "./routes";
export interface MobileMenuProps {
isOpen: boolean;
toggleMenu: () => void;
routes: Route[];
}

4
src/types/mobileMenuButton.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
export interface MobileMenuButtonProps {
isOpen: boolean;
onClick: () => void;
}

12
src/types/navbarLink.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
import { NavLinkProps } from "react-router-dom";
export interface NavbarLinkProps {
to: string;
children: React.ReactNode;
onClick?: () => void;
}
export interface NavData {
isActive: boolean;
isPending: boolean;
}

5
src/types/routes.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export interface Route {
id: number;
path: string;
name: string;
}