Egret Admin Dashboard

Egret Documentation

Layout
Layout Overview

Egret provides a flexible layout system that can be easily configured to meet your application's needs. The layout system is built around the LayoutService which manages the layout configuration and provides reactive updates to all components.

Available Layout Types

Egret offers several layout types that can be configured through the layout service:

  • Vertical Layout: Traditional sidebar navigation with header on the side (default)
  • Horizontal Layout: Top navigation with header at the top
  • Auth Layout: Special layout for authentication pages
  • Admin Layout: Base layout for admin pages with customizable components
Layout Service

The LayoutService is the core service that manages the layout configuration in Egret. It provides a reactive way to change layout settings and applies them throughout the application.

Set Default Layout Configuration

You can set the default layout by modifying the setAppLayout method in layout.service.ts:

// layout.service.ts
setAppLayout() {
  // ********** SET DEFAULT LAYOUT **********
  let defaultLayout: ILayoutConf = {
    navigationPos: 'side', // side, top
    sidebarStyle: 'full', // full, compact, closed
    sidebarCompactToggle: false, // if "sidebarStyle" is "compact" make it true
    dir: 'ltr', // ltr, rtl
    useBreadcrumb: true, 
    topbarFixed: false,
    sidebarColor: 'sidebar-dark', // sidebar-dark, sidebar-light
    matTheme: 'egret-navy', // egret-navy, egret-navy-dark
    breadcrumb: 'simple', // simple, title
  };
}
Set Layout during Runtime

Here's how to inject and use the layout service in a component:

import { Component, OnInit } from '@angular/core';
import { LayoutService } from 'app/shared/services/layout.service';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.html'
})
export class MyComponent implements OnInit {
  constructor(private layoutService: LayoutService) {}

  ngOnInit() {
    // Subscribe to layout changes
    this.layoutService.layoutConf$.subscribe(layoutConf => {
      console.log('Current layout config:', layoutConf);
    });
  }

  // Change to compact sidebar
  setCompactSidebar() {
    this.layoutService.publishLayoutChange({
      sidebarStyle: 'compact'
    });
  }

  // Change to horizontal navigation
  setHorizontalLayout() {
    this.layoutService.publishLayoutChange({
      navigationPos: 'top'
    });
  }

  // Toggle RTL mode
  toggleRTL() {
    this.layoutService.publishLayoutChange({
      dir: 'rtl'
    });
  }
}
Common Layout Configurations

Here are some common layout configurations you might want to use:

1. Changing Sidebar Style
// Full sidebar (default)
layoutService.publishLayoutChange({
  sidebarStyle: 'full'
});

// Compact sidebar (icons only, expands on hover if sidebarCompactToggle is true)
layoutService.publishLayoutChange({
  sidebarStyle: 'compact',
  sidebarCompactToggle: true
});

// Closed sidebar (completely hidden)
layoutService.publishLayoutChange({
  sidebarStyle: 'closed'
});
2. Changing Navigation Position
// Side navigation (default)
layoutService.publishLayoutChange({
  navigationPos: 'side'
});

// Top navigation (horizontal menu)
layoutService.publishLayoutChange({
  navigationPos: 'top'
});
3. Changing Theme and Colors
// Change material theme
layoutService.publishLayoutChange({
  matTheme: 'egret-navy-dark'
});

// Change sidebar color
layoutService.publishLayoutChange({
  sidebarColor: 'sidebar-light'
});

4. Toggling Fixed Elements
// Fixed topbar
layoutService.publishLayoutChange({
  topbarFixed: true
});

// Fixed footer
layoutService.publishLayoutChange({
  footerFixed: true
});