Skip to content

Commit

Permalink
onMouseEnter and onMouseLeave navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
gerouvi committed Nov 20, 2024
1 parent fb63e7e commit 328959f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/components/Dashboard/Menu/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const DashboardMenuItem = ({
isOpen = false,
isActive = false,
onToggle,
onMouseEnter,
onMouseLeave,
hasChildren = false,
}: {
label: string
Expand All @@ -17,6 +19,8 @@ export const DashboardMenuItem = ({
isOpen?: boolean
isActive?: boolean
onToggle?: () => void
onMouseEnter?: () => void
onMouseLeave?: () => void
hasChildren?: boolean
}) => (
<Button
Expand All @@ -29,6 +33,8 @@ export const DashboardMenuItem = ({
w='full'
leftIcon={icon ? <Icon as={icon} /> : undefined}
rightIcon={hasChildren ? isOpen ? <ChevronUpIcon /> : <ChevronDownIcon /> : undefined}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{label}
</Button>
Expand Down
23 changes: 14 additions & 9 deletions src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useBreakpointValue,
useDisclosure,
} from '@chakra-ui/react'
import { useState } from 'react'
import { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { generatePath, Link as ReactRouterLink } from 'react-router-dom'
import { useAuth } from '~components/Auth/useAuth'
Expand Down Expand Up @@ -67,37 +67,40 @@ const NavbarMenu = ({ isOpen, onClose }: { isOpen: boolean; onClose: () => void

const NavbarMenuContent = () => {
const { t } = useTranslation()
const ref = useRef()
const useCasesItems = useCases()
const [openSection, setOpenSection] = useState<string | null>(null)
const isLargerThanXL = useBreakpointValue({ base: false, xl: true })

const handleToggle = (label: string) => {
setOpenSection((prev) => (prev === label ? null : label))
}

const menuItems: MenuItem[] = [
{
label: t('navbar.use_cases', { defaultValue: 'Use Cases' }),
route: Routes.useCases.root,
children: useCasesItems,
},
{
label: t('navbar.features', { defaultValue: 'Features' }),
route: '',
route: Routes.features,
},
{
label: t('navbar.pricing', { defaultValue: 'Pricing' }),
route: '',
route: Routes.pricing,
},
{
label: t('navbar.technolgy', { defaultValue: 'Technology' }),
route: '',
route: Routes.technology,
},
{
label: t('navbar.demos', { defaultValue: 'Demos' }),
route: '',
route: Routes.demos,
},
{
label: t('navbar.contact_us', { defaultValue: 'Contact Us' }),
route: '',
route: Routes.contactUs,
},
]

Expand All @@ -111,16 +114,18 @@ const NavbarMenuContent = () => {
label={item.label}
route={item.route}
isOpen={isLargerThanXL ? openSection === item.label : true}
onToggle={() => handleToggle(item.label)}
onMouseEnter={() => handleToggle(item.label)}
onMouseLeave={() => setOpenSection(null)}
hasChildren
/>
<Collapse in={isLargerThanXL ? openSection === item.label : true}>
<Collapse ref={ref} in={isLargerThanXL ? openSection === item.label : true}>
<List
onMouseEnter={() => handleToggle(item.label)}
onMouseLeave={() => setOpenSection(null)}
zIndex={20}
position={{ base: 'relative', xl: 'absolute' }}
gap={6}
px={6}
pt={{ base: 0, xl: 6 }}
bgColor={'navbar.bg_light'}
_dark={{ bgColor: 'navbar.bg_dark' }}
>
Expand Down
1 change: 1 addition & 0 deletions src/router/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Routes = {
web3: '/web3',
sportClubs: '/sport-clubs',
},
technology: '/technology',
terms: '/terms',
}

Expand Down

0 comments on commit 328959f

Please sign in to comment.