diff --git a/src/App.tsx b/src/App.tsx index b800ead..6a89018 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -87,7 +87,7 @@ const Content: React.FC = () => { {/* Admin only views */} - }> + }> } /> diff --git a/src/components/Navbar/AdminDropdown.tsx b/src/components/Navbar/AdminDropdown.tsx new file mode 100644 index 0000000..71e0abf --- /dev/null +++ b/src/components/Navbar/AdminDropdown.tsx @@ -0,0 +1,57 @@ +import { useCallback, useRef, useState, type PropsWithChildren } from 'react'; +import { ButtonType } from '../common/Button/Buttons'; +import styles from './Navbar.module.scss'; +import { useMatch, useResolvedPath } from 'react-router-dom'; + +type AdminDropdownButtonProps = PropsWithChildren & { + disabled?: boolean; + key?: string; + text: string; +}; + +export const AdminDropdown: React.FC = ({ + children, + disabled, + key, + text, +}) => { + const resolvedPath = useResolvedPath('/admin/*'); + + const [isOpen, setIsOpen] = useState(false); + const isActive = !!useMatch({ path: resolvedPath.pathname }); + + const onDropdownButtonClick = useCallback(() => { + setIsOpen(!isOpen); + }, [isOpen]); + + const dropdownRef = useRef(null); + + const handleMouseLeave = useCallback(() => { + setIsOpen(false); + }, []); + + return ( +
+ + + {isOpen &&
{children}
} +
+ ); +}; diff --git a/src/components/Navbar/CustomLink.tsx b/src/components/Navbar/CustomLink.tsx index 2e65067..5af2cd2 100644 --- a/src/components/Navbar/CustomLink.tsx +++ b/src/components/Navbar/CustomLink.tsx @@ -2,10 +2,12 @@ import { Link, useMatch, useResolvedPath } from 'react-router-dom'; import styles from './Navbar.module.scss'; export const CustomLink = ({ + className, to, children, ...props }: { + className?: string; to: string; children: string | JSX.Element; }): JSX.Element => { @@ -13,7 +15,7 @@ export const CustomLink = ({ const isActive = useMatch({ path: resolvedPath.pathname, end: true }); return ( -
  • +
  • {children} diff --git a/src/components/Navbar/Navbar.module.scss b/src/components/Navbar/Navbar.module.scss index 739e9e3..f9b67c7 100644 --- a/src/components/Navbar/Navbar.module.scss +++ b/src/components/Navbar/Navbar.module.scss @@ -52,8 +52,8 @@ nav { } .active { - background: $white-smoke; - color: $black; + background: $white-smoke !important; + color: $black !important; :hover { color: $black; @@ -78,6 +78,67 @@ nav { align-self: center; } +.dropdownButton { + align-items: center; + background-color: $blue; + border-radius: 0; + border: none; + color: $white; + display: flex; + position: relative; + flex-direction: row; + font-weight: 500; + font-family: roboto; + justify-content: center; + padding: 0.5rem 1rem; + height: 100%; + + &:disabled { + background-color: $grey; + } + + &:hover:not(.active) { + background-color: $blue-hover; + color: $white; + } + + &.open { + background-color: $blue-hover; + } +} + +.dropdownMenu { + background: $white-smoke; + border: 1px solid $grey; + border-top: none; + border-radius: 0 0 8px 8px; + color: $grey; + position: absolute; + + li { + color: $black; + } + + li:last-child { + border-radius: 0 0 8px 8px; + } + + li:hover:not(.active) { + background-color: $blue-hover; + color: $white; + + a { + color: inherit; + } + } +} + +.dropdownLink { + &.active { + background-color: $timberwolf !important; + } +} + @media (max-width: 780px) { nav { a { diff --git a/src/components/Navbar/Navbar.tsx b/src/components/Navbar/Navbar.tsx index 91d537d..90408b6 100644 --- a/src/components/Navbar/Navbar.tsx +++ b/src/components/Navbar/Navbar.tsx @@ -7,6 +7,7 @@ import { getUserRoles } from '../../lib/utils'; import styles from './Navbar.module.scss'; import { Navbar as BootNavbar, Container, Nav } from 'react-bootstrap'; import { CustomLink } from './CustomLink'; +import { AdminDropdown } from './AdminDropdown'; export const Navbar: React.FC = () => { const navigate = useNavigate(); @@ -44,7 +45,25 @@ export const Navbar: React.FC = () => { Täyttöhistoria - {isAdmin && Laskutus} + {isAdmin && ( + + + Laskutus + + {/* + Käyttäjät + + + Täyttöhistoria + */} + + )}