Jumbo React
V7.0 - NextJS
V7.0 - NextJS
  • About Jumbo NextJS
  • Get Started
    • Get Access to Jumbo
    • Package Content
    • Project Setup
  • Structure
    • Folder Structure
    • Layout
  • Settings
    • Authentication & Authorization
    • Customize Theme
    • Manage Sidebar Menus
  • Components
    • JumboBackdrop
    • JumboCard
    • JumboCardFeatured
    • JumboConfigProvider
    • JumboDdMenu
    • JumboDdPopover
    • JumboIconButton
    • JumboLayout
    • JumboLayoutProvider
    • JumboNavbar
    • JumboOverlay
    • JumboRTL
    • JumboScrollbar
    • JumboTabs
    • JumboTheme
Powered by GitBook
On this page
  • Using Pre-built Layouts
  • Creating a Custom Layout
  • Using Multipel Demo Layouts
  1. Structure

Layout

Use pre-defined layouts in Jumbo or create your own customised one

Using Pre-built Layouts

Jumbo comes with several pre-built layouts that you can use out of the box. These layouts are designed to cater to common use cases and provide a quick way to get started with your project. To use a pre-built layout, simply import it into your component and wrap your content with the layout component.

Here's an example of using a pre-built layout:

import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter';
import type { Metadata } from 'next';

import { AppSnackbar } from '@/components/AppSnackbar';
import { CONFIG } from '@/config';
import '@/styles/style.css';
import { Params } from '@/types/paramsType';
import { ASSET_IMAGES } from '@/utilities/constants/paths';
import '@assets/fonts/noir-pro/styles.css';
import {
  JumboConfigProvider,
  JumboDialog,
  JumboDialogProvider,
  JumboTheme,
} from '@jumbo/components';
import { CssBaseline } from '@mui/material';
import Link from 'next/link';

declare module '@mui/material/styles' {
  interface Theme {
    type: 'light' | 'semi-dark' | 'dark';
    sidebar: {
      bgimage: string;
      overlay: {
        bgcolor: string;
        bgimage: string;
        opacity: number;
      };
    };
    jumboComponents: {
      JumboNavbar: {
        nav: {
          action: {
            active: string;
            hover: string;
          };
          background: {
            active: string;
            hover: string;
          };
          tick: {
            active: string;
            hover: string;
          };
        };
      };
    };
  }
  // allow configuration using `createTheme`
  interface ThemeOptions {
    type?: 'light' | 'semi-dark' | 'dark';
    sidebar?: {
      bgimage?: string;
      overlay?: {
        bgcolor?: string;
        bgimage?: string;
        opacity?: number;
      };
    };
    jumboComponents?: {
      JumboNavbar?: {
        nav?: {
          action?: {
            active?: string;
            hover?: string;
          };
          background?: {
            active?: string;
            hover?: string;
          };
          tick?: {
            active?: string;
            hover?: string;
          };
        };
      };
    };
  }
}

export async function generateStaticParams() {
  return [{ lang: 'en-US' }];
}
export const metadata: Metadata = {
  title: 'Jumbo - Admin Dashboard',
  icons: `${ASSET_IMAGES}/favicon.ico`,
};

export default async function RootLayout(
  props: {
    children: React.ReactNode;
  } & Params
) {
  const params = await props.params;

  const { children } = props;

  const { lang } = params;
  return (
    <html lang={lang} data-lt-installed='true'>
      <body cz-shortcut-listen='true'>
        <div id='root'>
          <AppRouterCacheProvider>
            <JumboConfigProvider LinkComponent={Link}>
              <JumboTheme init={CONFIG.THEME}>
                <CssBaseline />
                <JumboDialogProvider>
                  <JumboDialog />
                  <AppSnackbar>{children}</AppSnackbar>
                </JumboDialogProvider>
              </JumboTheme>
            </JumboConfigProvider>
          </AppRouterCacheProvider>
        </div>
      </body>
    </html>
  );
}

In this example, preBuiltLayoutConfig is an object containing the configuration for a pre-built layout. You can customize this object to fit your needs or choose a different pre-built layout configuration from the provided ones.

Creating a Custom Layout

If the pre-built layouts do not meet your requirements, you can create a custom layout by providing your own layout configuration. The layout configuration allows you to customize various aspects of the layout, such as the sidebar, header, and footer.

Here’s how you can create a custom layout:

  1. Define the Layout Configuration

    Create a layout configuration object that specifies how you want your layout to behave. Below is an example of a layout configuration object:

    const defaultLayoutConfig: LayoutOptions = {
      sidebar: {
        open: true,
        hide: false,
        variant: SIDEBAR_VARIANTS.PERSISTENT,
        style: SIDEBAR_STYLES.FULL_HEIGHT,
        view: SIDEBAR_VIEWS.FULL,
        scrollType: SIDEBAR_SCROLL_TYPES.FIXED,
        anchor: SIDEBAR_ANCHOR_POSITIONS.LEFT,
        width: 240,
        minWidth: 80,
        drawer: true,
        drawerBreakpoint: 'xl',
      },
      header: {
        hide: false,
        fixed: true,
        sx: {
          height: 80,
        },
        drawerBreakpoint: 'xl',
      },
      footer: {
        hide: false,
      },
      root: {},
      content: {
        sx: {
          py: 4,
        },
      },
      wrapper: {},
      main: {},
    };
    
  2. Wrap Your Content with Jumbo Layout Components

    Use the JumboLayoutProvider and JumboLayout components to apply your custom layout configuration. Here’s an example:

    import { Footer } from '@/components/Footer';
    import { Header } from '@/components/Header';
    import { Sidebar } from '@/components/Sidebar';
    import { defaultLayoutConfig } from '@/config/layouts';
    import { getMenus } from '@/services';
    import { Params } from '@/types/paramsType';
    import { JumboLayout, JumboLayoutProvider } from '@jumbo/components';
    import { MenuItems } from '@jumbo/types';
    import React from 'react';
    
    export default async function CommonLayout(
      props: {
        children: React.ReactNode;
      } & Params
    ) {
      const params = await props.params;
    
      const { children } = props;
    
      const { lang } = params;
      const menus: MenuItems = await getMenus(lang);
      return (
        <JumboLayoutProvider layoutConfig={defaultLayoutConfig}>
          <JumboLayout
            header={<Header />}
            footer={<Footer lang={lang} />}
            sidebar={<Sidebar menus={menus} />}
          >
            {children}
          </JumboLayout>
        </JumboLayoutProvider>
      );
    }
    

Using Multipel Demo Layouts

Jumbo supports defining multiple custom layouts for different use cases such as demos, themes, or application variants. If your project includes multiple demo layouts (e.g., Demo1Layout, Demo2Layout, etc.), you can organize them in a modular way using the same base structure, while providing distinct configurations and UI components for each.

  • Each demo layout typically includes:

    • A custom layout configuration (e.g., demoConfig1, demoConfig2, etc).

    • Custom header and footer components (e.g., Header1, Footer1, etc).

    • Optionally, dynamic content such as menus based on language or user

    Here's an example of using a demo-layouts:

import { Header1 } from '@/components/Demo1Layout/Header1';
import { Footer1 } from '@/components/Demo1Layout/Footer1';
import { demoConfig1 } from '@/config/layouts/demo1';
import { getDemoMenus } from '@/utilities/constants/demo1-menus';
import { JumboLayout, JumboLayoutProvider } from '@jumbo/components';

export default async function Demo1Layout({ children, params }) {
  const { lang } = await params;
  const menus = await getDemoMenus(lang);

  return (
    <JumboLayoutProvider layoutConfig={demoConfig1}>
      <JumboLayout
        header={<Header1 menus={menus} />}
        footer={<Footer1 />}
      >
        {children}
      </JumboLayout>
    </JumboLayoutProvider>
  );
}

Each layout can reuse the same logic but import its own Header, Footer, layoutConfig, and menu-fetching function.

Layout Configuration Options

Below are the configuration options available for customizing your layout:

  • Sidebar

    • open: Boolean to control the open or close state of the sidebar.

    • hide: Boolean to hide or show the sidebar.

    • variant: Variant of the sidebar, either PERSISTENT, PERMANENT, or TEMPORARY.

    • style: Style of the sidebar, either FULL_HEIGHT or CLIPPED_UNDER_HEADER.

    • view: View of the sidebar, either FULL or MINI.

    • scrollType: Scroll type of the sidebar, either FIXED or DEFAULT.

    • anchor: Anchor position of the sidebar, either LEFT, RIGHT, TOP, or BOTTOM.

    • width: Width of the sidebar.

    • minWidth: Minimum width of the sidebar in collapsed state.

  • Header

    • hide: Boolean to show or hide the header.

    • fixed: Boolean to keep the header fixed or move with scroll.

    • height: Height of the header.

    • sx: Style object to set additional styling.

  • Footer

    • hide: Boolean to show or hide the footer.

    • sx: Style object to set additional styling.

  • Root and Content

    • sx: Style object to set additional styling for root and content.

By customizing these options, you can create a layout that perfectly fits your application's needs.

PreviousFolder StructureNextAuthentication & Authorization

Last updated 4 days ago