Layout

Use pre-defined layouts in Wieldy or create your own customized one

Using Pre-built Layouts

Wieldy 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 { Footer } from "@/_components/Footer";
import { Header1 } from "@/_components/Header1";
import { Sidebar } from "@/_components/Sidebar1";
import { WieldyLayout } from "@wieldy/components";
import { WieldyContainer } from "@wieldy/components/WieldyContainer";
import React from "react";
import { layoutConfig } from "./_config";

const DefaultLayout = ({ children }: { children: React.ReactNode }) => {
  return (
    <WieldyLayout
      header={<Header1 />}
      sidebar={<Sidebar />}
      footer={<Footer />}
      styles={layoutConfig.styles}
      classes={layoutConfig.classes}
      layoutOptions={layoutConfig.layoutOptions}
    >
      <WieldyContainer>{children}</WieldyContainer>
    </WieldyLayout>
  );
};

export default DefaultLayout;

```

In this example, layoutConfig 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:

    import { WieldyLayoutConfig } from "@wieldy/components/WieldyLayout/types";
    
    export const layoutConfig: WieldyLayoutConfig = {
      classes: {
        root: "wieldy-layout min-h-screen",
        header: "wieldy-layout-header shadow-md py-4 px-8 leading-[unset] h-[72px]",
        content: "wieldy-layout-content py-8",
        sidebar: "wieldy-layout-sidebar",
        rightSidebar: "wieldy-layout-right-sidebar",
        footer: "wieldy-layout-footer shadow-md py-4 px-8 min-h-12",
      },
    
      layoutOptions: {
        header: {
          fixed: true,
          hidden: false,
          spreadOut: false,
        },
        sidebar: {
          width: 280,
          collapsible: false,
          collapsedWidth: 80,
          fixed: true,
          breakpoint: "lg",
        },
        footer: {
          fixed: true,
        },
      },
    };
  2. Wrap Your Content with Wieldy Layout Components

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

import React from 'react';
import { WieldyLayout } from '@wieldy/components';
import {Header, Footer, Sidebar} from '@app/{...your-defined-components}';

const MyCustomApp = ({ children }) => (
   <WieldyLayout
      header={<Header />}
      footer={<Footer />}
      sidebar={<Sidebar />}
      styles={customLayoutConfig.styles}
      classes={customLayoutConfig.classes}
      layoutOptions={customLayoutConfig}
    >
      {children}
    </WieldyLayout>
);

export default MyCustomApp;

Layout Configuration Options

Below are the configuration options available for customizing your layout:

  • Sidebar

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

    • breakpoint: Show or hide sidebar of specific breakpoint.

    • fixed: Boolean to keep the sidebar fixed.

    • width: Width of the sidebar.

    • collapsedWidth: Width of the sidebar in collapsed state.

  • Header

    • hidden: Boolean to show or hide the header.

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

    • spreadOut: Height of the header.

  • Footer

    • hidden: Boolean to show or hide the footer.

    • fixed: Boolean to keep the footer fixed.

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

Last updated