Skip to content

Commit

Permalink
feat(app): Navbar restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarDev committed Oct 3, 2023
1 parent 4246bbe commit f747d98
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 89 deletions.
84 changes: 0 additions & 84 deletions web/apps/app/components/NavProfile.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions web/apps/app/components/layouts/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Minimize } from '@signalco/ui-icons';
import { IconButton } from '@signalco/ui/dist/IconButton';
import { useSearchParam } from '@signalco/hooks/dist/useSearchParam';
import NavProfile from '../NavProfile';
import NavProfile from '../navigation/NavProfile';
import RealtimeService from '../../src/realtime/realtimeService';
import { AuthWrapper } from './AuthWrapper';

Expand All @@ -27,7 +27,7 @@ export function AppLayout(props: React.PropsWithChildren) {
{isFullScreen !== 'true' && (
<NavProfile />
)}
<div className="relative w-full grow overflow-hidden">
<div className="relative mt-[72px] w-full grow overflow-hidden md:ml-[90px] md:mt-0">
{children}
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions web/apps/app/components/navigation/FloatingNavContainer.tsx
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>
);
}
27 changes: 27 additions & 0 deletions web/apps/app/components/navigation/MobileMenu.tsx
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>
);
}
2 changes: 1 addition & 1 deletion web/apps/app/components/navigation/NavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function NavLink({ path, Icon, active, label, onClick }: NavLinkP
<Tooltip title={label}>
<Link href={path}>
<IconButton
className={cx(styles.root, active && styles.active)}
className={cx(styles.root, 'relative', active && styles.active)}
aria-label={label}
title={label}
variant="plain"
Expand Down
70 changes: 70 additions & 0 deletions web/apps/app/components/navigation/NavProfile.tsx
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>
);
}
4 changes: 2 additions & 2 deletions web/packages/data/src/KnownSecureHeadersExternalUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const knownSecureHeadersExternalUrls: KnownSecureHeadersExternalUrlsObjec
connectSrc: ['https://*.clarity.ms']
},
vercel: {
scriptSrc: ['https://vercel.live', 'https://vitals.vercel-insights.com'],
connectSrc: ['https://vercel.live', 'https://vitals.vercel-insights.com']
scriptSrc: ['https://vercel.live', 'https://vitals.vercel-insights.com', 'https://*.vercel-scripts.com'],
connectSrc: ['https://vercel.live', 'https://vitals.vercel-insights.com', 'https://*.vercel-scripts.com']
},
azureSignalR: {
connectSrc: ['https://*.service.signalr.net', 'wss://*.service.signalr.net']
Expand Down

0 comments on commit f747d98

Please sign in to comment.