ng-vote
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

npm version Build Status Dependency Status

ng-vote

Simple & lightweight Angular 2/4 voting component. Demo is available on Plunker.

ng-vote demo

Installation

To install ng-vote, run:

$ npm install ng-vote --save

Usage

Import NgVoteModule into your Angular application:

 
// Import ng-vote
import { NgVoteModule } from 'ng-vote';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    // Specify ng-vote as an import
    NgVoteModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once ng-vote is imported, you can use it in your Angular application:

 
import { Component } from '@angular/core';
 
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
    voteConfig: {
      cssClass: 'my-class',
      allowEdit: true, 
      disabled: false
    }
    votes: 123, // total amount of votes
    selectedVote: 0 // not voted yet
 
  onVote(vote) {
    console.log('onVote response: ', vote)
  }
}
<!-- You can now use ng-vote component in your application -->
<ng-vote 
  (vote)="onVote($event)" 
  [totalVotes]="votes" 
  [selectedVote]="selectedVote" 
  [config]="voteConfig">
    <!-- Define Up Vote Button -->
    <ng-vote-up>
      <!-- Content will be projected -->
      <i class="my-up-icon"></i>Up
    </ng-vote-up>
    <!-- Add Down Vote Button -->
    <ng-vote-down>Down</ng-vote-down>
</ng-vote> 
 
<!-- Minimal setup would be -->
<ng-vote (vote)="onVote($event)">
    <ng-vote-up>Up</ng-vote-up>
    <ng-vote-down>Down</ng-vote-down>
</ng-vote>

Bindings

ng-vote

@Input

  • [totalVotes]: number Default: 0
  • [selectedVote]: number Default: 0 One of -1 (downVote), 0 (not voted), 1 (upVote)
  • [config]: Object
    • allowEdit: boolean Default: true Defines if user is allowed to change his the selection.
    • disabled: boolean Default: false Disables vote functionality.
    • cssClass: string Default: '' Sets custom css class to override styles.

@Output

  • (vote): Object
    • selectedVote: number
    • totalVotes: number

ng-vote-up / ng-vote-down

No bindings available for <ng-vote-up> / <ng-vote-down>. Content will be projected to the <button>.

Demo

Demo of the Angular 2/4 voting component is available on Plunker.

License

The MIT License (MIT)

Copyright (c) 2017 Patrick Valer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Made with ♥ by Patrick Valer (hello@patrickvaler.ch)

Readme

Keywords

Package Sidebar

Install

npm i ng-vote

Weekly Downloads

1

Version

0.1.5

License

MIT

Last publish

Collaborators

  • patrickvaler