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 React from 'react';
import { JumboLayoutProvider, JumboLayout } from '@jumbo/components';
import { defaultLayoutConfig } from '@app/_config/layouts';
import {Header, Footer, Sidebar} from '@app/{...your-defined-components}';

const MyApp = () => (
  <JumboLayoutProvider layoutConfig={defaultLayoutConfig}>
    <JumboLayout
      header={<Header />}
      footer={<Footer />}
      sidebar={<Sidebar menus={menus} />}
    >
      {children}
    </JumboLayout>
  </JumboLayoutProvider>
);

export default MyApp;

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 customLayoutConfig = {
      sidebar: {
        open: true,
        hide: false,
        variant: 'PERSISTENT',
        style: 'FULL_HEIGHT',
        view: 'FULL',
        scrollType: 'FIXED',
        anchor: 'LEFT',
        width: 240,
        minWidth: 80,
      },
      header: {
        hide: false,
        fixed: true,
        height: 80,
        sx: {
          height: 80,
        },
      },
      footer: {
        hide: false,
        sx: {},
      },
      root: {},
      content: {
        sx: {},
      },
    };
  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 React from 'react';
    import { JumboLayoutProvider, JumboLayout } from '@jumbo/components';
    import {Header, Footer, Sidebar} from '@app/{...your-defined-components}';
    
    const MyCustomApp = ({ children }) => (
      <JumboLayoutProvider layoutConfig={customLayoutConfig}>
        <JumboLayout
          header={<Header />}
          footer={<Footer />}
          sidebar={<Sidebar menus={menus} />}
        >
          {children}
        </JumboLayout>
      </JumboLayoutProvider>
    );
    
    export default MyCustomApp;

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.

Last updated