-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes a fully functional vote component for Angular 2. Features: - Content projections for up- and downvote button - Config option to allow or disallow editing - Config option for disabling voting functionality - Extend main container with own css class
- Loading branch information
0 parents
commit 46b9b4c
Showing
23 changed files
with
4,923 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Node | ||
node_modules/* | ||
npm-debug.log | ||
|
||
# TypeScript | ||
src/*.js | ||
src/*.map | ||
src/*.d.ts | ||
|
||
# JetBrains | ||
.idea | ||
.project | ||
.settings | ||
.idea/* | ||
*.iml | ||
|
||
# VS Code | ||
.vscode/* | ||
|
||
# Windows | ||
Thumbs.db | ||
Desktop.ini | ||
|
||
# Mac | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Ngc generated files | ||
**/*.ngfactory.ts | ||
|
||
# Build files | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Node | ||
node_modules/* | ||
npm-debug.log | ||
docs/* | ||
# DO NOT IGNORE TYPESCRIPT FILES FOR NPM | ||
# TypeScript | ||
# *.js | ||
# *.map | ||
# *.d.ts | ||
|
||
# JetBrains | ||
.idea | ||
.project | ||
.settings | ||
.idea/* | ||
*.iml | ||
|
||
# VS Code | ||
.vscode/* | ||
|
||
# Windows | ||
Thumbs.db | ||
Desktop.ini | ||
|
||
# Mac | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Ngc generated files | ||
**/*.ngfactory.ts | ||
|
||
# Library files | ||
src/* | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- '6' | ||
|
||
script: | ||
- npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"generator-angular2-library": { | ||
"promptValues": { | ||
"gitRepositoryUrl": "http://github.com/patrickvaler/ng-vote" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
[![Build Status](https://travis-ci.org/patrickvaler/ng-vote.svg?branch=master)](https://travis-ci.org/patrickvaler/ng-vote) [![Dependency Status](https://david-dm.org/patrickvaler/ng-vote/status.svg?style=flat)](https://david-dm.org/patrickvaler/ng-vote) [![npm version](https://badge.fury.io/js/ng-vote.svg)](http://badge.fury.io/js/ng-vote) | ||
|
||
# ng-vote | ||
|
||
Simple & lightweight Angular 2 vote component. | ||
|
||
![ng-vote demo][demo] | ||
|
||
## Installation | ||
|
||
To install ng-vote, run: | ||
|
||
```bash | ||
$ npm install ng-vote --save | ||
``` | ||
|
||
## Usage | ||
Import `NgVoteModule` into your Angular application: | ||
|
||
```typescript | ||
|
||
// 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: | ||
|
||
```typescript | ||
|
||
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) | ||
} | ||
} | ||
``` | ||
|
||
```html | ||
<!-- 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> | ||
``` | ||
|
||
## Bindings | ||
### ng-vote component | ||
|
||
`<ng-vote>` | ||
```typescript | ||
|
||
// Input | ||
totalVotes: number | ||
selectedVote: number // one of -1 (downVote), 0 (not voted), 1 (upVote) | ||
config: { | ||
allowEdit: boolean, // defines if user is allowed to change selection | ||
disabled: boolean // disables vote functionality | ||
cssClass: string // Sets custom css class to override styles | ||
|
||
} | ||
|
||
// Output | ||
(vote): { | ||
selectedVote:number, | ||
totalVotes:number | ||
} | ||
|
||
``` | ||
|
||
### ng-vote-up / ng-vote-down component | ||
No bindings available for `<ng-vote-up>` / `<ng-vote-down>`. Content will be projected to the `<button>`. | ||
|
||
## 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]("http://www.patrickvaler.ch") (<hello@patrickvaler.ch>) | ||
|
||
|
||
[demo]: https://image.ibb.co/niY4kv/ng_vote_demo.gif "ng-vote demo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* eslint-disable */ | ||
var gulp = require('gulp'), | ||
path = require('path'), | ||
ngc = require('@angular/compiler-cli/src/main').main, | ||
rollup = require('gulp-rollup'), | ||
del = require('del'), | ||
runSequence = require('run-sequence'), | ||
inlineResources = require('./tools/gulp/inline-resources'); | ||
|
||
const rootFolder = path.join(__dirname); | ||
const srcFolder = path.join(rootFolder, 'src'); | ||
const tmpFolder = path.join(rootFolder, '.tmp'); | ||
const buildFolder = path.join(rootFolder, 'build'); | ||
const distFolder = path.join(rootFolder, 'dist'); | ||
|
||
/** | ||
* 1. Delete /dist folder | ||
*/ | ||
gulp.task('clean:dist', function () { | ||
return deleteFolders([distFolder]); | ||
}); | ||
|
||
/** | ||
* 2. Clone the /src folder into /.tmp. If an npm link inside /src has been made, | ||
* then it's likely that a node_modules folder exists. Ignore this folder | ||
* when copying to /.tmp. | ||
*/ | ||
gulp.task('copy:source', function () { | ||
return gulp.src([`${srcFolder}/**/*`, `!${srcFolder}/node_modules`]) | ||
.pipe(gulp.dest(tmpFolder)); | ||
}); | ||
|
||
/** | ||
* 3. Inline template (.html) and style (.css) files into the the component .ts files. | ||
* We do this on the /.tmp folder to avoid editing the original /src files | ||
*/ | ||
gulp.task('inline-resources', function () { | ||
return Promise.resolve() | ||
.then(() => inlineResources(tmpFolder)); | ||
}); | ||
|
||
|
||
/** | ||
* 4. Run the Angular compiler, ngc, on the /.tmp folder. This will output all | ||
* compiled modules to the /build folder. | ||
*/ | ||
gulp.task('ngc', function () { | ||
return ngc({ | ||
project: `${tmpFolder}/tsconfig.es5.json` | ||
}) | ||
.then((exitCode) => { | ||
if (exitCode === 1) { | ||
// This error is caught in the 'compile' task by the runSequence method callback | ||
// so that when ngc fails to compile, the whole compile process stops running | ||
throw new Error('ngc compilation failed'); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* 5. Run rollup inside the /build folder to generate our Flat ES module and place the | ||
* generated file into the /dist folder | ||
*/ | ||
gulp.task('rollup', function () { | ||
return gulp.src(`${buildFolder}/**/*.js`) | ||
// transform the files here. | ||
.pipe(rollup({ | ||
// any option supported by Rollup can be set here. | ||
entry: `${buildFolder}/index.js`, | ||
external: [ | ||
'@angular/core', | ||
'@angular/common' | ||
], | ||
format: 'es' | ||
})) | ||
.pipe(gulp.dest(distFolder)); | ||
}); | ||
|
||
/** | ||
* 6. Copy all the files from /build to /dist, except .js files. We ignore all .js from /build | ||
* because with don't need individual modules anymore, just the Flat ES module generated | ||
* on step 5. | ||
*/ | ||
gulp.task('copy:build', function () { | ||
return gulp.src([`${buildFolder}/**/*`, `!${buildFolder}/**/*.js`]) | ||
.pipe(gulp.dest(distFolder)); | ||
}); | ||
|
||
/** | ||
* 7. Copy package.json from /src to /dist | ||
*/ | ||
gulp.task('copy:manifest', function () { | ||
return gulp.src([`${srcFolder}/package.json`]) | ||
.pipe(gulp.dest(distFolder)); | ||
}); | ||
|
||
/** | ||
* 8. Delete /.tmp folder | ||
*/ | ||
gulp.task('clean:tmp', function () { | ||
return deleteFolders([tmpFolder]); | ||
}); | ||
|
||
/** | ||
* 9. Delete /build folder | ||
*/ | ||
gulp.task('clean:build', function () { | ||
return deleteFolders([buildFolder]); | ||
}); | ||
|
||
gulp.task('compile', function () { | ||
runSequence( | ||
'clean:dist', | ||
'copy:source', | ||
'inline-resources', | ||
'ngc', | ||
'rollup', | ||
'copy:build', | ||
'copy:manifest', | ||
'clean:build', | ||
'clean:tmp', | ||
function (err) { | ||
if (err) { | ||
console.log('ERROR:', err.message); | ||
deleteFolders([distFolder, tmpFolder, buildFolder]); | ||
} else { | ||
console.log('Compilation finished succesfully'); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* Watch for any change in the /src folder and compile files | ||
*/ | ||
gulp.task('watch', function () { | ||
gulp.watch(`${srcFolder}/**/*`, ['compile']); | ||
}); | ||
|
||
gulp.task('clean', ['clean:dist', 'clean:tmp', 'clean:build']); | ||
|
||
gulp.task('build', ['clean', 'compile']); | ||
gulp.task('build:watch', ['build', 'watch']); | ||
gulp.task('default', ['build:watch']); | ||
|
||
/** | ||
* Deletes the specified folder | ||
*/ | ||
function deleteFolders(folders) { | ||
return del(folders); | ||
} |
Oops, something went wrong.