-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
4246bbe
commit f747d98
Showing
7 changed files
with
117 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
web/apps/app/components/navigation/FloatingNavContainer.tsx
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,15 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { cx } from 'classix'; | ||
|
||
export function FloatingNavContainer({ children }: PropsWithChildren) { | ||
return ( | ||
<div className={cx( | ||
'absolute inset-x-0 top-0 p-1 md:inset-y-0 md:left-0 md:right-auto md:p-2', | ||
'animate-in slide-in-from-top-16 md:slide-in-from-top-0 md:slide-in-from-left-20' | ||
)}> | ||
<div className="h-full rounded-2xl border border-neutral-300 shadow-md"> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
} |
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,27 @@ | ||
import { cx } from 'classix'; | ||
import { Stack } from '@signalco/ui/dist/Stack'; | ||
import useLocale from '../../src/hooks/useLocale'; | ||
import { NavItem } from './NavProfile'; | ||
import NavLink from './NavLink'; | ||
|
||
export function MobileMenu({ open, items, active, onClose }: { open: boolean; items: NavItem[]; active?: NavItem; onClose: () => void; }) { | ||
const { t } = useLocale('App', 'Nav'); | ||
|
||
return ( | ||
<div className={cx( | ||
'fixed inset-0 top-[60px] z-50 bg-white', | ||
!open && 'hidden' | ||
)}> | ||
<Stack> | ||
{items.map((ni, index) => ( | ||
<NavLink | ||
key={index + 1} | ||
path={ni.path} | ||
Icon={ni.icon} | ||
active={ni === active} | ||
label={t(ni.label)} | ||
onClick={onClose} />))} | ||
</Stack> | ||
</div> | ||
); | ||
} |
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,70 @@ | ||
'use client'; | ||
|
||
import React, { useState } from 'react'; | ||
import { usePathname } from 'next/navigation'; | ||
import { Channel, Close, Dashboard, Device, Menu as MenuIcon, Settings } from '@signalco/ui-icons'; | ||
import { Stack } from '@signalco/ui/dist/Stack'; | ||
import { IconButton } from '@signalco/ui/dist/IconButton'; | ||
import { orderBy } from '@signalco/js'; | ||
import { UserProfileAvatar } from '../users/UserProfileAvatar'; | ||
import { KnownPages } from '../../src/knownPages'; | ||
import useLocale from '../../src/hooks/useLocale'; | ||
import NavLink from './NavLink'; | ||
import { MobileMenu } from './MobileMenu'; | ||
import { FloatingNavContainer } from './FloatingNavContainer'; | ||
|
||
export type NavItem = { | ||
label: string, | ||
path: string, | ||
icon: React.FunctionComponent, | ||
hidden?: boolean | undefined; | ||
} | ||
|
||
const navItems: NavItem[] = [ | ||
{ label: 'Channels', path: KnownPages.Channels, icon: Channel, hidden: true }, | ||
{ label: 'Settings', path: KnownPages.Settings, icon: Settings, hidden: true }, | ||
{ label: 'Dashboards', path: KnownPages.Root, icon: Dashboard }, | ||
{ label: 'Entities', path: KnownPages.Entities, icon: Device } | ||
]; | ||
|
||
export default function NavProfile() { | ||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false); | ||
const pathname = usePathname(); | ||
const activeNavItem: NavItem | undefined = orderBy(navItems.filter(ni => pathname?.startsWith(ni.path)), (a, b) => b.path.length - a.path.length).at(0); | ||
const visibleNavItems = navItems.filter(ni => ni === activeNavItem || !ni.hidden); | ||
const { t } = useLocale('App', 'Nav'); | ||
|
||
return ( | ||
<FloatingNavContainer> | ||
<div className="flex h-full min-h-[60px] flex-row items-center justify-between gap-1 sm:flex-col sm:justify-start md:pl-0 md:pt-2"> | ||
<UserProfileAvatar /> | ||
<div className="hidden w-full sm:block"> | ||
<Stack> | ||
{visibleNavItems | ||
.map((ni, index) => ( | ||
<NavLink | ||
key={index + 1} | ||
path={ni.path} | ||
Icon={ni.icon} | ||
active={ni === activeNavItem} | ||
label={t(ni.label)} /> | ||
))} | ||
</Stack> | ||
</div> | ||
<div className="sm:hidden"> | ||
<IconButton | ||
variant="plain" | ||
onClick={() => setMobileMenuOpen((curr) => !curr)} | ||
aria-label="Toggle menu"> | ||
{mobileMenuOpen ? <Close /> : <MenuIcon />} | ||
</IconButton> | ||
<MobileMenu | ||
open={mobileMenuOpen} | ||
items={visibleNavItems} | ||
active={activeNavItem} | ||
onClose={() => setMobileMenuOpen(false)} /> | ||
</div> | ||
</div> | ||
</FloatingNavContainer> | ||
); | ||
} |
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