-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from thomasKn/thomas/fv-227-mobile-header-menu
Add mobile nav
- Loading branch information
Showing
14 changed files
with
341 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type {IconProps} from './Icon'; | ||
|
||
import {Icon} from './Icon'; | ||
|
||
export function IconMenu(props: IconProps) { | ||
return ( | ||
<Icon {...props} stroke={props.stroke || 'currentColor'}> | ||
<title>Menu</title> | ||
<line strokeWidth="1.25" x1="3" x2="17" y1="6.375" y2="6.375" /> | ||
<line strokeWidth="1.25" x1="3" x2="17" y1="10.375" y2="10.375" /> | ||
<line strokeWidth="1.25" x1="3" x2="17" y1="14.375" y2="14.375" /> | ||
</Icon> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import {useCallback, useState} from 'react'; | ||
|
||
import type {NavigationProps} from './DesktopNavigation'; | ||
import type {SanityNestedNavigationProps} from './NestedNavigation'; | ||
|
||
import {IconMenu} from '../icons/IconMenu'; | ||
import {SanityExternalLink} from '../sanity/link/SanityExternalLink'; | ||
import {SanityInternalLink} from '../sanity/link/SanityInternalLink'; | ||
import { | ||
MobileNavigationMenu, | ||
MobileNavigationMenuContent, | ||
MobileNavigationMenuItem, | ||
MobileNavigationMenuLink, | ||
MobileNavigationMenuList, | ||
MobileNavigationMenuTrigger, | ||
} from '../ui/MobileNavigationMenu'; | ||
import {Sheet, SheetContent, SheetTrigger} from '../ui/Sheet'; | ||
|
||
export function MobileNavigation(props: {data?: NavigationProps}) { | ||
const [open, setOpen] = useState(false); | ||
const handleClose = useCallback(() => setOpen(false), []); | ||
|
||
if (!props.data) return null; | ||
|
||
// Todo => Add <Navlink /> support | ||
return ( | ||
<div className="md:hidden"> | ||
<Sheet onOpenChange={setOpen} open={open}> | ||
<SheetTrigger className="flex items-center justify-center p-2 pr-[var(--mobileHeaderXPadding)] md:pr-0"> | ||
<IconMenu className="size-7" strokeWidth={1.5} /> | ||
</SheetTrigger> | ||
<SheetContent | ||
className="flex max-h-screen min-h-full w-screen flex-col gap-0 bg-background p-0 text-foreground sm:max-w-lg" | ||
onCloseAutoFocus={(e) => e.preventDefault()} | ||
onOpenAutoFocus={(e) => e.preventDefault()} | ||
> | ||
<MobileNavigationMenu className="flex-1 overflow-y-scroll text-xl font-medium"> | ||
<MobileNavigationMenuList> | ||
{props.data && | ||
props.data?.length > 0 && | ||
props.data?.map((item) => ( | ||
<MobileNavigationMenuItem key={item._key}> | ||
{item._type === 'internalLink' && ( | ||
<MobileNavigationMenuLink asChild onClick={handleClose}> | ||
<div> | ||
<SanityInternalLink data={item} /> | ||
</div> | ||
</MobileNavigationMenuLink> | ||
)} | ||
{item._type === 'externalLink' && ( | ||
<MobileNavigationMenuLink asChild onClick={handleClose}> | ||
<div> | ||
<SanityExternalLink data={item} /> | ||
</div> | ||
</MobileNavigationMenuLink> | ||
)} | ||
{item._type === 'nestedNavigation' && ( | ||
<NestedMobileNavigation | ||
data={item} | ||
onClose={handleClose} | ||
/> | ||
)} | ||
</MobileNavigationMenuItem> | ||
))} | ||
</MobileNavigationMenuList> | ||
</MobileNavigationMenu> | ||
</SheetContent> | ||
</Sheet> | ||
</div> | ||
); | ||
} | ||
|
||
function NestedMobileNavigation(props: { | ||
data?: SanityNestedNavigationProps; | ||
onClose: () => void; | ||
}) { | ||
const {data} = props; | ||
|
||
if (!data) return null; | ||
|
||
const {childLinks} = data; | ||
|
||
return data.name && childLinks && childLinks.length > 0 ? ( | ||
<> | ||
<MobileNavigationMenuTrigger>{data.name}</MobileNavigationMenuTrigger> | ||
<MobileNavigationMenuContent className="flex-1 overflow-y-scroll"> | ||
<MobileNavigationMenuList> | ||
{childLinks && | ||
childLinks.length > 0 && | ||
childLinks.map((child) => ( | ||
<MobileNavigationMenuLink | ||
asChild | ||
key={child._key} | ||
onClick={props.onClose} | ||
> | ||
<div> | ||
{child._type === 'internalLink' ? ( | ||
<SanityInternalLink data={child} /> | ||
) : child._type === 'externalLink' ? ( | ||
<SanityExternalLink data={child} /> | ||
) : null} | ||
</div> | ||
</MobileNavigationMenuLink> | ||
))} | ||
</MobileNavigationMenuList> | ||
</MobileNavigationMenuContent> | ||
</> | ||
) : data.link && data.name && (!childLinks || childLinks.length === 0) ? ( | ||
// Render internal link if no child links | ||
<SanityInternalLink | ||
data={{ | ||
_key: data._key, | ||
_type: 'internalLink', | ||
anchor: null, | ||
link: data.link, | ||
name: data.name, | ||
}} | ||
> | ||
{data.name} | ||
</SanityInternalLink> | ||
) : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.