1.0.4 • Published 1 year ago

ngx-sticky-sidebar v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Sticky-Sidebar

NPM

Status

npm version NPM Unpacked Size NPM License NPM Downloads

DEMO

REPOSITORY

A Customizable Sidebar Angular Component

Installation

npm install --save ngx-sticky-sidebar

Usage

Add NgxStickySidebarModule to your project:

app module:

import { NgxStickySidebarModule } from 'ngx-sticky-sidebar';

@NgModule({
  declarations: [ AppComponent ],
  imports: [ BrowserModule, NgxStickySidebarModule ],
  bootstrap: [ AppComponent ],
})
class AppModule {}

or layout component:

import { NgxStickySidebarModule } from 'ngx-sticky-sidebar';

@Component({
  selector: 'app-layout',
  standalone: true,
  imports: [
    NgxStickySidebarModule
  ],
  template: '',
  styles: []
})
export class LayoutComponent {}

Add <ngx-sticky-sidebar> to your layout template:

<ngx-sticky-sidebar [items]="items" [backgroundColor]="backgroundColor" [color]="color">
    <div id="sidebar-header" style="text-align: center;">
        <span> Sticky Sidebar </span>
    </div>
    <div id="sidebar-content">
        <span>Page Content</span>
        <router-outlet></router-outlet>
    </div>
</ngx-sticky-sidebar>

Inputs

PropertyTypeDefaultDescription
itemsStickySidebarItems[][]Elements for sidebar list.
backgroundColorstringblackSidebar background color.
colorstringwhiteSidebar font color.
widthstring220pxSidebar width size.
paddingstring1remSidebar padding.
backdropColorstring#00000054Backdrop color.
transitionDelaystring0.5sTime (in sec) for each transition.
overWidthnumber992If the screen width is equal to or less than that value, the sidebar should disappear.
dropWidthnumber992If the screen width is equal to or less than that value, the sidebar should appear.
closeBtnSizenumber15Close button size for small screen widths.
autoRoutebooleantrue(Items with children) Determine the default route when clicking on the item without specifying a child.

State

Add NgxStickySidebarService where you want get or set sidebar state:

import { NgxStickySidebarService } from 'ngx-sticky-sidebar';

@Component({
  selector: 'app-layout',
  templateUrl: './layout.component.html',
  styleUrls: ['./layout.component.scss']
})
export class LayoutComponent {
    state: boolean;

    constructor( private sidebar: NgxStickySidebarService ) {
        this.sidebar.stateAsObs.subscribe((state: boolean) => {
            this.state = state;
        })
    }

    toogle(): void {
        this.sidebar.toggle();
    }

    set_value(value: boolean): void {
        this.sidebar.set_state = value;
    }
}

Items

Declare your sidebar items.

E.g:

items: StickySidebarItems[] = [
    {
      label: 'Home',
      route: '/',
      childs: []
    },
    {
      label: 'Apps',
      route: '/apps',
      collapse: true,
      iconClass: 'bi bi-window-plus', // <-- using Boostrap Icons
      childs: [
        {
          label: 'One',
          route: '/one'
        },
        {
          label: 'Two',
          route: '/two'
        }
      ]
    }
]

Properties

PropertyTypeDescription
labelstringText of item to display on sidebar list
routestringRoute to navigate upon clicking
childs{ label: string, route: string }[]Text and routes for item's children
collapsebooleanDefault value for collapse item if have children
iconClassstringClass name for <i> element to display custom icon
1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

0.0.1

6 years ago