Skip to content

Commit

Permalink
add config input and refactor demos page
Browse files Browse the repository at this point in the history
  • Loading branch information
tb committed Apr 24, 2016
1 parent 6beab97 commit a04308d
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Angular2 nouislider directive

See [demo](http://tb.github.io/ng2-nouislider/)
See [demos](http://tb.github.io/ng2-nouislider/)

## Install

Expand Down
31 changes: 28 additions & 3 deletions demo/app.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="page-header">
<h3>Example 1</h3>
<h3>Single value</h3>
</div>

<pre>&lt;div nouislider [min]=&quot;0&quot; [max]=&quot;10&quot; [step]=&quot;0.05&quot; [(ngModel)]=&quot;someValue&quot;&gt;&lt;/div&gt;</pre>
Expand All @@ -14,7 +14,7 @@ <h3>Example 1</h3>
</div>

<div class="page-header">
<h3>Example 2</h3>
<h3>Range</h3>
</div>

<pre>&lt;div nouislider [connect]=&quot;true&quot; [min]=&quot;0&quot; [max]=&quot;15&quot; [step]=&quot;1&quot; [(ngModel)]=&quot;someRange&quot;&gt;&lt;/div&gt;</pre>
Expand All @@ -31,4 +31,29 @@ <h3>Example 2</h3>
<div class="btn-group">
<button type="button" class="btn btn-primary" (click)="changeSomeRange(1,-1)">-</button>
<button type="button" class="btn btn-primary" (click)="changeSomeRange(1,1)">+</button>
</div>
</div>

<div class="page-header">
<h3>Range with config</h3>
</div>

<pre>someRange2config: any = {
behaviour: 'drag',
connect: true,
margin: 1,
limit: 5, // NOTE: overwritten by [limit]="10"
range: {
min: 0,
max: 20
},
pips: {
mode: 'steps',
density: 5
}
};</pre>

<pre>&lt;div nouislider [config]=&quot;someRange2config&quot; [limit]=&quot;10&quot; [(ngModel)]=&quot;someRange2&quot;&gt;&lt;/div&gt;</pre>

<code>someRange2: {{ someRange2 | json }}</code>

<div nouislider [config]="someRange2config" [limit]="10" [(ngModel)]="someRange2"></div>
15 changes: 15 additions & 0 deletions demo/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ import {Nouislider} from 'ng2nouislider';
export class App {
public someValue: any = 5;
public someRange: any = [3,7];
public someRange2: any = [10,15];
public someRange2config: any = {
behaviour: 'drag',
connect: true,
margin: 1,
limit: 5,
range: {
min: 0,
max: 20
},
pips: {
mode: 'steps',
density: 5
}
};

changeSomeValue(value: number) {
this.someValue = this.someValue + value;
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<body>
<div class="jumbotron">
<div class="container">
<h1>ng2-nouislider</h1>
<p>Angular2 nouislider directive</p>
<h2>ng2-nouislider demos</h2>
<a href="https://github.com/tb/ng2-nouislider" class="btn btn-default">Back to GitHub</a>
</div>
</div>
<div class="container">
Expand Down
5 changes: 4 additions & 1 deletion nouislider.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OnInit, ElementRef, EventEmitter } from 'angular2/core';
import { ElementRef, EventEmitter, OnInit } from 'angular2/core';
import { ControlValueAccessor } from 'angular2/common';
export declare function toValue(value: string[]): number | number[];
export declare class Nouislider implements ControlValueAccessor, OnInit {
Expand All @@ -7,10 +7,13 @@ export declare class Nouislider implements ControlValueAccessor, OnInit {
value: any;
onChange: any;
onTouched: any;
behaviour: string;
connect: boolean;
limit: number;
min: number;
max: number;
step: number;
config: any;
ngModelChange: EventEmitter<any>;
constructor(el: ElementRef);
ngOnInit(): void;
Expand Down
36 changes: 22 additions & 14 deletions nouislider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nouislider.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 29 additions & 13 deletions nouislider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import * as noUiSlider from 'nouislider';
import {Directive, OnInit, ElementRef, forwardRef, Provider, Input, Output, EventEmitter} from 'angular2/core';
import {
Directive,
ElementRef,
EventEmitter,
forwardRef,
Input,
OnInit,
Output,
Provider
} from 'angular2/core';
import {ControlValueAccessor} from 'angular2/common';

import {NG_VALUE_ACCESSOR} from 'angular2/src/common/forms/directives/control_value_accessor';
Expand Down Expand Up @@ -31,26 +40,33 @@ export class Nouislider implements ControlValueAccessor, OnInit {
public onChange: any = Function.prototype;
public onTouched: any = Function.prototype;

@Input() connect: boolean = false;
@Input() min: number = 0;
@Input() max: number = 10;
@Input() step: number = 1;
@Input() behaviour: string;
@Input() connect: boolean;
@Input() limit: number;
@Input() min: number;
@Input() max: number;
@Input() step: number;
@Input() config: any = {};
@Output() ngModelChange: EventEmitter<any> = new EventEmitter();

public constructor(el:ElementRef) {
this.el = el;
}

ngOnInit(): void {
this.slider = noUiSlider.create(this.el.nativeElement, {
start: this.value || 0,
step: this.step,
let inputsConfig = JSON.parse(JSON.stringify({
behaviour: this.behaviour,
connect: this.connect,
range: {
min: this.min,
max: this.max
}
});
limit: this.limit,
start: this.value,
step: this.step,
range: this.config.range || {min: this.min, max: this.max}
}));

this.slider = noUiSlider.create(
this.el.nativeElement,
Object.assign(this.config, inputsConfig)
);

this.slider.on('set', (value) => {
this.writeValue(toValue(value));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-nouislider",
"version": "0.2.1",
"version": "0.3.0",
"description": "Angular2 noUiSlider directive",
"main": "nouislider.js",
"typings": "nouislider.d.ts",
Expand Down

0 comments on commit a04308d

Please sign in to comment.