Code Monkey home page Code Monkey logo

ng-sidebar's Introduction

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'
  },
  // ...
};

Usage

Add SidebarModule to your app module:

import { SidebarModule } from 'ng-sidebar';

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

If you're using it in a feature module, you may need to add it as an import in that module as well.

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>
  `
})
export 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 [(opened)]="_opened">
  <a closeSidebar>Closes the sidebar</a>
</ng-sidebar>

<ng-sidebar-container> options

Inputs

Property name Type Default Description
backdropClass string Additional class name on the overlay element.

<ng-sidebar> options

Inputs

Property name Type Default Description
opened boolean false If the sidebar should be open. This should be two-way bound.
mode `'over' 'push'` 'over'
position `'left' 'right' 'top'
closeOnClickOutside boolean false Whether clicking outside of the open sidebar will close it.
showBackdrop boolean false If a translucent black backdrop overlay should appear over the page contents when the sidebar is open.
animate boolean true Whether the sidebar should animate when opening/closing.
trapFocus boolean true Keeps focus within the sidebar if it's open.
autoFocus boolean true Automatically focuses the first focusable element in the sidebar when opened.
sidebarClass string Additional class name on the sidebar element.
ariaLabel string String used for the sidebar's aria-label attribute.
keyClose boolean false Close the sidebar when a keyboard button is pressed.
keyCode number 27 The KeyCode for keyClose.

Outputs

Property name Callback arguments Description
onOpenStart Emitted when the sidebar is opening.
onOpened Emitted when the sidebar is opened.
onCloseStart Emitted when the sidebar is closing.
onClosed Emitted when the sidebar is closed.
onPositionChange position: string Emitted when position is changed.
onModeChange mode: string Emitted when mode is changed.

ng-sidebar's People

Contributors

arkon avatar pablodoble avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.