Giter VIP home page Giter VIP logo

ngx-stepper's Introduction

ngx-stepper

Angular Steppers directive for Angular Material

Based on Material Steppers: https://www.google.com/design/spec/components/steppers.html#steppers-types-of-steppers

Plunker Demo

http://embed.plnkr.co/n1Ye3pQY6dlMSoJizO6Y/

Run Demo App

You can try out the Angular Steppers in the demo app built with Angular-CLI.

#1 To start the demo app clone or download the repo.

#2 Install the latest version of Angular-CLI

npm install -g angular-cli@latest

#3 Install npm packages

npm install

#4 Run the app

ng serve

#5 Open the app

http://localhost:4200/

Installation in package.json

npm i -S ngx-stepper

note: works with angular 2 & 4

Import to app module

import { NgxStepperModule } from 'ngx-stepper';

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

Write your html

<ngx-stepper #stepperDemo="stepper" [options]="options">
  <ngx-step [label]="'Select a campaign'">
    <ngx-step-body>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur nobis saepe facere suscipit atque,
        sapiente, natus mollitia ipsum odit accusamus repellendus deserunt. Odio sit similique, labore maxime
        voluptatibus, eaque autem!</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur nobis saepe facere suscipit atque,
        sapiente, natus mollitia ipsum odit accusamus repellendus deserunt. Odio sit similique, labore maxime
        voluptatibus, eaque autem!</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur nobis saepe facere suscipit atque,
        sapiente, natus mollitia ipsum odit accusamus repellendus deserunt. Odio sit similique, labore maxime
        voluptatibus, eaque autem!</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur nobis saepe facere suscipit atque,
        sapiente, natus mollitia ipsum odit accusamus repellendus deserunt. Odio sit similique, labore maxime
        voluptatibus, eaque autem!</p>
    </ngx-step-body>
    <ngx-step-actions>
      <button mat-button class="mat-primary mat-raised" (click)="selectCampaign()">Continue</button>
      <button mat-button class="mat-primary" (click)="stepperDemo.back()">Cancel</button>
    </ngx-step-actions>
  </ngx-step>
  <ngx-step [label]="'Publish the ad'">
    <ngx-step-body>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur nobis saepe facere suscipit atque,
        sapiente, natus mollitia ipsum odit accusamus repellendus deserunt. Odio sit similique, labore maxime
        voluptatibus, eaque autem!</p>
    </ngx-step-body>
    <ngx-step-actions>
      <button mat-button class="mat-primary mat-raised" (click)="stepperDemo.next()">Complete</button>
      <button mat-button class="mat-primary" (click)="stepperDemo.back()">Back</button>
    </ngx-step-actions>
  </ngx-step>

Stepper Options

options attribute

Value of the options attribute is a type of StepperOptions. It can contain the following properties.

Detailed property bellow:

Options Default Type Description
vertical false boolean
linear true boolean
alternative true boolean
mobileStepText true boolean
labelStep 'Step' string
labelOf 'Of' string
enableSvgIcon false boolean

Stepper Service

Used to control a stepper by it's id. Example:

@ViewChild('stepperDemo')
public steppers: NgxStepperComponent;

public selectCampaign(): void {
  this.steppers.showFeedback('Checking, please wait ...');
  this.steppers.next();
}

Detailed service operations bellow:

Method Description Returns
next() Complete the current step and move one to the next. Using this method on editable steps (in linear stepper) it will search by the next step without "completed" state to move. When invoked it dispatch the event onstepcomplete to the step element. boolean - True if move and false if not move (e.g. On the last step)
back() Move to the previous step without change the state of current step. Using this method in linear stepper it will check if previous step is editable to move. boolean - True if move and false if not move (e.g. On the first step)
skip() Move to the next step without change the state of current step. This method works only in optional steps. boolean - True if move and false if not move (e.g. On non-optional step)
goto(stepNumber: number) Move "active" to specified step id parameter. The id used as reference is the integer number shown on the label of each step (e.g. 2). boolean - True if move and false if not move (e.g. On id not found)
error(message: string) Defines the current step state to "error" and shows the message parameter on title message element.When invoked it dispatch the event onsteperror to the step element. {string} message The error message
clearError() Defines the current step state to "normal" and removes the message parameter on title message element. void
showFeedback(message?: string) Shows a feedback message and a loading indicador. void
clearFeedback() Removes the feedback. void

Embed SVG Icon assets

  • Supported Namespace: 'step-done', 'step-warning'
import {DomSanitizer} from '@angular/platform-browser';
import {MatIconRegistry} from '@angular/material';

public options: StepperOptions = {
  enableSvgIcon: true
};

constructor(private _iconRegistry: MatIconRegistry,private _sanitizer: DomSanitizer) {}

public ngOnInit(): void {
  this._iconRegistry
    .addSvgIcon('step-done', this._sanitizer.bypassSecurityTrustResourceUrl('YOUR_ICON_URL'));
  this._iconRegistry
    .addSvgIcon('step-warning', this._sanitizer.bypassSecurityTrustResourceUrl('YOUR_ICON_URL'));
}
  • EX: 'YOUR_ICON_URL' = 'assets/icon/warning.svg'

TODO

  • Horizontal steppers
  • Vertical steppers
  • Linear steppers
  • Non-linear steppers
  • Alternative labels
  • Optional steps
  • Editable steps
  • Stepper feedback
  • Mobile steppers
    • Mobile step text
    • Mobile step dots
    • Mobile step progress bar
  • Correct apply styles (css) of the material design
  • Embed SVG Icon assets
  • Create a better demo page with all options.

Remarks

ngx-stepper's People

Contributors

hvqthong avatar hl2308 avatar

Watchers

James Cloos avatar Reiosantos  avatar  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.