Skip to content

Commit

Permalink
develop - changeset - added layout context, prime react, interfaces a…
Browse files Browse the repository at this point in the history
…nd appbar and footer - v4
  • Loading branch information
Umer Farooq committed Jul 30, 2024
1 parent 86f4ce3 commit 7505dd6
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 143 deletions.
14 changes: 14 additions & 0 deletions app/(protected)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Button } from 'primereact/button';
import { Card } from 'primereact/card';

export default function Dashboard() {
return (
<div className="card flex justify-content-center">
<Button>Add</Button>

<Card>
<p>Some text</p>
</Card>
</div>
);
}
10 changes: 10 additions & 0 deletions app/(protected)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Styles
import MainLayout from '@/lib/ui/layouts/main';

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <MainLayout>{children}</MainLayout>;
}
20 changes: 1 addition & 19 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-start-rgb: 255, 255, 255;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
Expand All @@ -25,9 +13,3 @@ body {
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}
15 changes: 12 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { PrimeReactProvider } from 'primereact/api';
import 'primereact/resources/primereact.min.css';
import 'primereact/resources/themes/saga-green/theme.css';

import { LayoutProvider } from '@/lib/context/layout-context';
import './globals.css';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
title: 'Enatega Customer',
description: 'Generated by Ninjas Code',
};

export default function RootLayout({
Expand All @@ -16,7 +21,11 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<PrimeReactProvider>
<LayoutProvider>{children}</LayoutProvider>
</PrimeReactProvider>
</body>
</html>
);
}
113 changes: 0 additions & 113 deletions app/page.tsx

This file was deleted.

78 changes: 78 additions & 0 deletions lib/context/layout-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use client';
import { ILayoutProvider } from '@/lib/utils/interfaces';
import {
LayoutConfig,
LayoutContextProps,
LayoutState,
} from '@/lib/utils/types';
import { createContext, useState } from 'react';
export const LayoutContext = createContext({} as LayoutContextProps);

export const LayoutProvider = ({ children }: ILayoutProvider) => {
const [layoutConfig, setLayoutConfig] = useState<LayoutConfig>({
ripple: false,
inputStyle: 'outlined',
menuMode: 'static',
colorScheme: 'light',
theme: 'lara-light-indigo',
scale: 14,
});

const [layoutState, setLayoutState] = useState<LayoutState>({
staticMenuDesktopInactive: false,
overlayMenuActive: false,
profileSidebarVisible: false,
configSidebarVisible: false,
staticMenuMobileActive: false,
menuHoverActive: false,
});

const onMenuToggle = () => {
if (isOverlay()) {
setLayoutState((prevLayoutState) => ({
...prevLayoutState,
overlayMenuActive: !prevLayoutState.overlayMenuActive,
}));
}

if (isDesktop()) {
setLayoutState((prevLayoutState) => ({
...prevLayoutState,
staticMenuDesktopInactive: !prevLayoutState.staticMenuDesktopInactive,
}));
} else {
setLayoutState((prevLayoutState) => ({
...prevLayoutState,
staticMenuMobileActive: !prevLayoutState.staticMenuMobileActive,
}));
}
};

const showProfileSidebar = () => {
setLayoutState((prevLayoutState) => ({
...prevLayoutState,
profileSidebarVisible: !prevLayoutState.profileSidebarVisible,
}));
};

const isOverlay = () => {
return layoutConfig.menuMode === 'overlay';
};

const isDesktop = () => {
return window.innerWidth > 991;
};

const value: LayoutContextProps = {
layoutConfig,
setLayoutConfig,
layoutState,
setLayoutState,
onMenuToggle,
showProfileSidebar,
};

return (
<LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>
);
};
File renamed without changes.
79 changes: 79 additions & 0 deletions lib/ui/components/app-bar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable @next/next/no-img-element */

import { LayoutContext } from '@/lib/context/layout-context';
import { AppTopbarRef } from '@/lib/utils/types';
import Link from 'next/link';
import { classNames } from 'primereact/utils';
import { forwardRef, useContext, useImperativeHandle, useRef } from 'react';

const AppTopbar = forwardRef<AppTopbarRef>((props, ref) => {
const { layoutConfig, layoutState, onMenuToggle, showProfileSidebar } =
useContext(LayoutContext);
const menubuttonRef = useRef(null);
const topbarmenuRef = useRef(null);
const topbarmenubuttonRef = useRef(null);

useImperativeHandle(ref, () => ({
menubutton: menubuttonRef.current,
topbarmenu: topbarmenuRef.current,
topbarmenubutton: topbarmenubuttonRef.current,
}));

return (
<div className="layout-topbar">
<Link href="/" className="layout-topbar-logo">
<img
src={`/layout/images/logo-${layoutConfig.colorScheme !== 'light' ? 'white' : 'dark'}.svg`}
width="47.22px"
height={'35px'}
alt="logo"
/>
<span>SAKAI</span>
</Link>

<button
ref={menubuttonRef}
type="button"
className="p-link layout-menu-button layout-topbar-button"
onClick={onMenuToggle}
>
<i className="pi pi-bars" />
</button>

<button
ref={topbarmenubuttonRef}
type="button"
className="p-link layout-topbar-menu-button layout-topbar-button"
onClick={showProfileSidebar}
>
<i className="pi pi-ellipsis-v" />
</button>

<div
ref={topbarmenuRef}
className={classNames('layout-topbar-menu', {
'layout-topbar-menu-mobile-active': layoutState.profileSidebarVisible,
})}
>
<button type="button" className="p-link layout-topbar-button">
<i className="pi pi-calendar"></i>
<span>Calendar</span>
</button>
<button type="button" className="p-link layout-topbar-button">
<i className="pi pi-user"></i>
<span>Profile</span>
</button>
<Link href="/documentation">
<button type="button" className="p-link layout-topbar-button">
<i className="pi pi-cog"></i>
<span>Settings</span>
</button>
</Link>
</div>
</div>
);
});

AppTopbar.displayName = 'AppTopbar';

export default AppTopbar;
Empty file.
10 changes: 10 additions & 0 deletions lib/ui/components/app-footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable @next/next/no-img-element */
'use client';

const AppFooter = () => {
return <div>Footer</div>;
};

AppFooter.displayName = 'AppFooter';

export default AppFooter;
Loading

0 comments on commit 7505dd6

Please sign in to comment.