-
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.
- Loading branch information
Showing
8 changed files
with
270 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
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()} | ||
> | ||
<MobileNavigationMenu className="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> | ||
<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
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,115 @@ | ||
import * as NavigationMenuPrimitive from '@radix-ui/react-navigation-menu'; | ||
import {cn} from 'app/lib/utils'; | ||
import {forwardRef} from 'react'; | ||
|
||
import {IconChevron} from '../icons/IconChevron'; | ||
|
||
const MobileNavigationMenu = forwardRef< | ||
React.ElementRef<typeof NavigationMenuPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root> | ||
>(({children, className, ...props}, ref) => ( | ||
<NavigationMenuPrimitive.Root | ||
className={cn('container relative py-14', className)} | ||
ref={ref} | ||
{...props} | ||
> | ||
{children} | ||
<MobileNavigationMenuViewport /> | ||
</NavigationMenuPrimitive.Root> | ||
)); | ||
MobileNavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName; | ||
|
||
const MobileNavigationMenuList = forwardRef< | ||
React.ElementRef<typeof NavigationMenuPrimitive.List>, | ||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List> | ||
>(({className, ...props}, ref) => ( | ||
<NavigationMenuPrimitive.List | ||
className={cn('flex flex-col gap-4', className)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
)); | ||
MobileNavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName; | ||
|
||
const MobileNavigationMenuItem = NavigationMenuPrimitive.Item; | ||
|
||
const MobileNavigationMenuTrigger = forwardRef< | ||
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>, | ||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger> | ||
>(({children, className, ...props}, ref) => ( | ||
<NavigationMenuPrimitive.Trigger | ||
className={cn( | ||
'group data-[state=open]:fixed data-[state=open]:top-4 data-[state=open]:z-[9999] data-[state=open]:duration-300 data-[state=open]:animate-in data-[state=open]:fade-in', | ||
className, | ||
)} | ||
ref={ref} | ||
{...props} | ||
> | ||
<span className="flex items-center gap-2"> | ||
<span className="group-data-[state=open]:hidden">{children}</span> | ||
<IconChevron | ||
className="group-data-[state=open]:rotate-180" | ||
direction="right" | ||
/> | ||
</span> | ||
</NavigationMenuPrimitive.Trigger> | ||
)); | ||
MobileNavigationMenuTrigger.displayName = | ||
NavigationMenuPrimitive.Trigger.displayName; | ||
|
||
const MobileNavigationMenuContent = forwardRef< | ||
React.ElementRef<typeof NavigationMenuPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content> | ||
>(({className, ...props}, ref) => ( | ||
<NavigationMenuPrimitive.Content | ||
className={cn( | ||
[ | ||
'h-screen w-screen transition ease-in-out', | ||
'group-data-[state=open]:duration-500', | ||
'group-data-[state=open]:animate-in', | ||
'group-data-[state=open]:fade-in', | ||
], | ||
className, | ||
)} | ||
onInteractOutside={(e) => e.preventDefault()} | ||
ref={ref} | ||
{...props} | ||
> | ||
<div className="container flex flex-col gap-3 pt-4">{props.children}</div> | ||
</NavigationMenuPrimitive.Content> | ||
)); | ||
MobileNavigationMenuContent.displayName = | ||
NavigationMenuPrimitive.Content.displayName; | ||
|
||
const MobileNavigationMenuLink = NavigationMenuPrimitive.Link; | ||
|
||
const MobileNavigationMenuViewport = forwardRef< | ||
React.ElementRef<typeof NavigationMenuPrimitive.Viewport>, | ||
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport> | ||
>(({className, ...props}, ref) => ( | ||
<NavigationMenuPrimitive.Viewport | ||
className={cn([ | ||
'group absolute left-0 top-14 z-50', | ||
'h-[var(--radix-navigation-menu-viewport-height)] w-[var(--radix-navigation-menu-viewport-width)]', | ||
'bg-background text-foreground transition ease-in-out', | ||
'data-[state=closed]:duration-300', | ||
'data-[state=closed]:animate-out', | ||
'data-[state=closed]:fade-out', | ||
className, | ||
])} | ||
ref={ref} | ||
{...props} | ||
/> | ||
)); | ||
MobileNavigationMenuViewport.displayName = | ||
NavigationMenuPrimitive.Viewport.displayName; | ||
|
||
export { | ||
MobileNavigationMenu, | ||
MobileNavigationMenuContent, | ||
MobileNavigationMenuItem, | ||
MobileNavigationMenuLink, | ||
MobileNavigationMenuList, | ||
MobileNavigationMenuTrigger, | ||
MobileNavigationMenuViewport, | ||
}; |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ export default { | |
theme: { | ||
container: { | ||
center: true, | ||
padding: '1rem', | ||
}, | ||
extend: { | ||
colors: { | ||
|