Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-sidebar

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-sidebar

Angular 2+ sidebar component.

  • 3.4.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ng-sidebar

NPM

Demo

Formally called ng2-sidebar

An Angular 2+ sidebar component.

Installation

npm install --save ng-sidebar

SystemJS configuration

If you're using SystemJS, be sure to add the appropriate settings to your SystemJS config:

var map = {
  // ...
  'ng-sidebar': 'node_modules/ng-sidebar',
  // ...
};

var packages = {
  // ...
  'ng-sidebar': {
    main: 'lib/index',
    defaultExtension: 'js'
  },
  // ...
};

Changelog

See the releases page in the GitHub repo.

Usage

Add SidebarModule to your app module:

import { SidebarModule } from 'ng-sidebar';

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

In your app component, simply use add a <ng-sidebar-container> wrapper, then place your <ng-sidebar>(s) and content within it:

@Component({
  selector: 'app',
  template: `
    <!-- Container for sidebar(s) + page content -->
    <ng-sidebar-container>

      <!-- A sidebar -->
      <ng-sidebar [(opened)]="_opened">
        <p>Sidebar contents</p>
      </ng-sidebar>

      <!-- Page content -->
      <button (click)="_toggleSidebar()">Toggle sidebar</button>

    </ng-sidebar-container>
  `
})
class AppComponent {
  private _opened: boolean = false;

  private _toggleSidebar() {
    this._opened = !this._opened;
  }
}

A directive is also provided to easily close the sidebar by clicking something inside it:

<ng-sidebar>
  <a closeSidebar>Closes the sidebar</a>
</ng-sidebar>

You can also use the open() and close() functions:

<ng-sidebar #sidebar>
  <button (click)="sidebar.close()">Close sidebar</button>
</ng-sidebar>

<button (click)="sidebar.open()">Open sidebar</button>

Styling

Various class names are attached to the sidebar and container for easier styling.

If you are using Angular 2's default emulated view encapsulation, you may have to use the /deep/ selector to target the sidebar's classes. Check out Angular's documentation for more details.

Sidebar

Class nameDescription
ng-sidebarAlways on the sidebar element.
ng-sidebar--openedWhen opened is true.
ng-sidebar--closedWhen opened is false.
ng-sidebar--leftWhen position is 'left' (or the 'start'/'end' aliases are equivalent to 'left').
ng-sidebar--rightWhen position is 'right' (or the 'start'/'end' aliases are equivalent to 'right').
ng-sidebar--topWhen position is 'top'.
ng-sidebar--bottomWhen position is 'bottom'.
ng-sidebar--overWhen mode is 'over'.
ng-sidebar--pushWhen mode is 'push'.
ng-sidebar--dockWhen mode is 'dock'.
ng-sidebar--inertIgnores pointer clicks. Class is applied when the sidebar is closed.
ng-sidebar--animateWhen animate is true.

Backdrop

Class nameDescription
ng-sidebar__backdropClass of the backdrop div. Note that the div is only in the DOM when the backdrop is shown.

Page content

Class nameDescription
ng-sidebar__contentClass of the wrapper div for the page content.

Options

<ng-sidebar-container>

Inputs

Property nameTypeDefaultDescription
backdropClassstringAdditional class name on the overlay element.
showBackdropbooleanfalseControls the backdrop state of the sidebar container. This should be two-way bound.
allowSidebarBackdropControlbooleantrueDetermines if the container component respects the sidebar's showBackdrop input option.
Outputs
Property nameCallback argumentsDescription
showBackdropChangeshowBackdrop: booleanEmitted when showBackdrop is modified. This allows for you to do "two-way binding" (i.e. [(showBackdrop)]).

<ng-sidebar>

Inputs
Property nameTypeDefaultDescription
openedbooleanfalseControls the opened state of the sidebar. This should be two-way bound.
mode`'over''push''dock'`
dockedSizestring'0px'When mode is set to 'dock', this value indicates how much of the sidebar is still visible when "closed".
position`'left''right''top'
autoCollapseHeightnumberWindow height in pixels in which to automatically close the sidebar.
autoCollapseWidthnumberWindow width in pixels in which to automatically close the sidebar.
animatebooleantrueAnimate the opening/closing of the sidebar.
sidebarClassstringAdditional class name on the sidebar element.
ariaLabelstringValue for the sidebar's aria-label attribute.
trapFocusbooleantrueKeeps focus within the sidebar when open.
autoFocusbooleantrueAutomatically focus the first focusable element in the sidebar when opened.
showBackdropbooleanfalseIf a translucent black backdrop overlay should appear over the page contents when the sidebar is opened. This is ignored if the sidebar's parent container has its allowSidebarBackdropControl property set to true.
closeOnClickOutsidebooleanfalseWhether clicking outside of the open sidebar will close it.
keyClosebooleanfalseClose the sidebar when a keyboard button is pressed.
keyCodenumber27The key code for keyClose.
Outputs
Property nameCallback argumentsDescription
openedChangeopened: booleanEmitted when opened is modified. This allows for you to do "two-way binding" (i.e. [(opened)]).
onOpenStartEmitted when the sidebar is opening.
onOpenedEmitted when the sidebar is opened.
onCloseStartEmitted when the sidebar is closing.
onClosedEmitted when the sidebar is closed.
onModeChangemode: stringEmitted when mode is changed.
onPositionChangeposition: stringEmitted when position is changed.

Keywords

FAQs

Package last updated on 22 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc