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 ( + + + {text} + + + {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 + */} + + )} diff --git a/src/components/common/Button/Buttons.module.scss b/src/components/common/Button/Buttons.module.scss index 598883d..311a9ae 100644 --- a/src/components/common/Button/Buttons.module.scss +++ b/src/components/common/Button/Buttons.module.scss @@ -1,3 +1,5 @@ +@import '../../../variables.scss'; + // Tayttopaikka specific $primaryBlue: #0d4d7b; $primaryBlueHover: #1971b1; @@ -10,7 +12,7 @@ $transparent: rgba(0, 0, 0, 0); $grey: #c7c7cd; $white: #ffffff; -#commonButton { +.commonButton { align-items: center; border-radius: 8px; border: none; diff --git a/src/components/common/Button/Buttons.tsx b/src/components/common/Button/Buttons.tsx index 556cc44..f13d564 100644 --- a/src/components/common/Button/Buttons.tsx +++ b/src/components/common/Button/Buttons.tsx @@ -12,6 +12,7 @@ export type CommonButtonProps = { className?: string; disabled?: boolean; key?: string; + id?: string; onClick?: React.MouseEventHandler; type?: ButtonType; }; @@ -29,6 +30,7 @@ export const ElementButton: React.FC = ({ disabled, key, element, + id, onClick, tooltip, type = ButtonType.button, @@ -41,11 +43,11 @@ export const ElementButton: React.FC = ({ return ( <> = ({ disabled, key, onClick, + id, text, type = ButtonType.button, }) => ( = ({ disabled, key, onClick, + id, text, type = ButtonType.button, }) => ( = ({ disabled, key, onClick, + id, text, type = ButtonType.button, }) => (