1.0.2 • Published 7 months ago

@ngx-smart/ngx-smart-sidebar v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

🌟 ngx-smart-sidebar

A customizable, collapsible, responsive, feature-rich sidebar component for Angular apps.

NPM Version

npm.io

✨ Features

  • 🌈 Fully customizable styling with background/hover colors
  • šŸ“ Multiple size options (small, medium, large)
  • šŸ”€ Flexible positioning (left or right)
  • šŸ“Š Multi-level nested navigation support
  • šŸ“± Responsive design with collapsible functionality
  • šŸ”„ Angular Router integration
  • šŸ‘† Click-outside closing capability
  • šŸ’¾ State persistence between sessions

šŸš€ Installation

npm i @ngx-smart/ngx-smart-sidebar --save

āš™ļø Basic Implementation

  1. Import the SidebarComponent in your Angular Component / Module:
  2. Define your sidebar items
  3. Use the sidebar component in your template
import { Component } from "@angular/core";
import { SidebarComponent, SidebarSection } from "@ngx-smart/ngx-smart-sidebar";

@Component({
  selector: "app-root",
  standalone: true,
  imports: [SidebarComponent],
  template: `
    <lib-sidebar [items]="sidebarItems" [title]="'Navigation'" [activeItemPath]="'/dashboard'" [sidebarId]="'main-sidebar'"> </lib-sidebar>

    <div class="content">
      <!-- Your page content here -->
    </div>
  `,
})
export class AppComponent {
  sidebarItems: SidebarSection[] = [
    {
      header: "Main",
      labels: [
        { label: "Dashboard", path: "/dashboard" },
        { label: "Analytics", path: "/analytics" },
        {
          label: "User Management",
          children: [
            { label: "User List", path: "/users" },
            { label: "Add User", path: "/users/add" },
          ],
        },
      ],
    },
    {
      header: "Settings",
      labels: [
        { label: "Profile", path: "/profile" },
        { label: "Preferences", path: "/settings" },
      ],
    },
  ];
}

šŸŽØ Custom Styling & Content

<lib-sidebar [position]="'left'" [width]="'medium'" [title]="'My App'" [items]="sidebarItems" [activeItemPath]="activePath" [sidebarId]="'main-sidebar'" [collapsible]="true" [sidebarBackgroundColor]="'#f5f5f5'" [backgroundHighlightColor]="'#e0f7fa'">
  <!-- Custom header content -->
  <div sidebarHeaderContent>
    <img src="assets/logo.png" alt="Logo" width="120" />
  </div>

  <!-- Custom footer content -->
  <div sidebarFooterContent>
    <p>Ā© 2025 My App</p>
  </div>
</lib-sidebar>

šŸ› ļø Configuration Options

Input Properties

InputTypeDefaultDescription
positionSidebarPosition'left'Position of the sidebar. Options are 'left' or 'right'.
widthSidebarWidth'medium'Width of the sidebar. Options are 'small' (150px), 'medium' (250px), or 'large' (300px).
titlestring''Title displayed at the top of the sidebar.
backgroundHighlightColorstring'#f5f7fa'Background color for highlighting when hovering over items.
itemsSidebarSection[][]Array of sidebar section objects defining the navigation structure.
activeItemPathstring''Path of the currently active item, should match the router path.
sidebarIdstring''Unique identifier for the sidebar, useful when using multiple sidebars.
collapsiblebooleantrueWhether the sidebar can be collapsed.
hideSidebarOnPathChangebooleanfalseWhether to automatically collapse the sidebar when the route changes.
closeOnClickOutsidebooleanfalseWhether to close the sidebar when clicking outside of it.
sidebarBackgroundColorstring'#ffffff'Background color of the sidebar.

Types

export type SidebarPosition = "left" | "right";
export type SidebarWidth = "small" | "medium" | "large";

export interface SidebarLabel {
  label: string;
  path?: string;
  children?: SidebarLabel[];
  isExpanded?: boolean;
}

export interface SidebarSection {
  header: string;
  labels: SidebarLabel[];
}

šŸ“ø Visual Examples

Default Sidebar

Sidebar Image

Custom Hover Background

Sidebar Custom Hover Backaground Image

Custom Sidebar Background

Sidebar Custom Sidebar Background

Custom Header and Footer Content Projection

The sidebar provides two content projection slots:

  • sidebarHeaderContent: Custom content for sidebar header area
  • sidebarFooterContent: Custom content for sidebar footer area

You can add custom content to the header and footer of the sidebar:

<lib-sidebar [items]="sidebarItems">
  <div sidebarHeaderContent>
    <img src="assets/logo.png" alt="Logo" width="120" />
  </div>

  <div sidebarFooterContent>
    <p>Ā© 2025 My App</p>
  </div>
</lib-sidebar>

šŸ¤ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

šŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago