Skip to content

Commit

Permalink
feat(timepicker): allow hiding the spinners
Browse files Browse the repository at this point in the history
fix #510

Closes #519
  • Loading branch information
jnizet authored and pkozlowski-opensource committed Jul 29, 2016
1 parent e9fe7e0 commit dc4962d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion demo/src/app/components/timepicker/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {NgbdTimepickerMeridian} from './meridian/timepicker-meridian';
import {NgbdTimepickerSeconds} from './seconds/timepicker-seconds';
import {NgbdTimepickerSteps} from './steps/timepicker-steps';
import {NgbdTimepickerValidation} from './validation/timepicker-validation';
import {NgbdTimepickerSpinners} from './spinners/timepicker-spinners';

export const DEMO_DIRECTIVES = [NgbdTimepickerBasic, NgbdTimepickerMeridian, NgbdTimepickerSeconds,
NgbdTimepickerSteps, NgbdTimepickerValidation];
NgbdTimepickerSpinners, NgbdTimepickerSteps, NgbdTimepickerValidation];

export const DEMO_SNIPPETS = {
basic: {
Expand All @@ -17,6 +18,9 @@ export const DEMO_SNIPPETS = {
seconds: {
code: require('!!prismjs?lang=typescript!./seconds/timepicker-seconds'),
markup: require('!!prismjs?lang=markup!./seconds/timepicker-seconds.html')},
spinners: {
code: require('!!prismjs?lang=typescript!./spinners/timepicker-spinners'),
markup: require('!!prismjs?lang=markup!./spinners/timepicker-spinners.html')},
steps: {
code: require('!!prismjs?lang=typescript!./steps/timepicker-steps'),
markup: require('!!prismjs?lang=markup!./steps/timepicker-steps.html')},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ngb-timepicker [(ngModel)]="time" [spinners]="spinners"></ngb-timepicker>

<button class="m-t-1 btn btn-sm btn-outline-{{spinners ? 'success' : 'danger'}}" (click)="toggleSpinners()">
Spinners - {{spinners ? "ON" : "OFF"}}
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Component} from '@angular/core';
import {NGB_TIMEPICKER_DIRECTIVES} from '@ng-bootstrap/ng-bootstrap';

@Component({
selector: 'ngbd-timepicker-spinners',
templateUrl: './timepicker-spinners.html',
directives: [NGB_TIMEPICKER_DIRECTIVES]
})
export class NgbdTimepickerSpinners {
time = {hour: 13, minute: 30};
spinners = true;

toggleSpinners() {
this.spinners = !this.spinners;
}
}
3 changes: 3 additions & 0 deletions demo/src/app/components/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {DEMO_DIRECTIVES, DEMO_SNIPPETS} from './demos';
<ngbd-example-box demoTitle="Seconds" [htmlSnippet]="snippets.seconds.markup" [tsSnippet]="snippets.seconds.code">
<ngbd-timepicker-seconds></ngbd-timepicker-seconds>
</ngbd-example-box>
<ngbd-example-box demoTitle="Spinners" [htmlSnippet]="snippets.spinners.markup" [tsSnippet]="snippets.spinners.code">
<ngbd-timepicker-spinners></ngbd-timepicker-spinners>
</ngbd-example-box>
<ngbd-example-box demoTitle="Custom steps" [htmlSnippet]="snippets.steps.markup" [tsSnippet]="snippets.steps.code">
<ngbd-timepicker-steps></ngbd-timepicker-steps>
</ngbd-example-box>
Expand Down
12 changes: 12 additions & 0 deletions src/timepicker/timepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,18 @@ describe('ngb-timepicker', () => {
});
})));
});

describe('spinners', () => {

it('should not have spinners if configured so', async(inject([TestComponentBuilder], (tcb) => {
const html = `<ngb-timepicker [(ngModel)]="model" [seconds]="true" [spinners]="false"></ngb-timepicker>`;

tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
const buttons = getButtons(fixture.nativeElement);
expect(buttons.length).toBe(0);
});
})));
});
});


Expand Down
9 changes: 7 additions & 2 deletions src/timepicker/timepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
template: `
<fieldset [disabled]="disabled" [class.disabled]="disabled">
<table>
<tr>
<tr *ngIf="spinners">
<td class="text-xs-center">
<button class="btn-link" (click)="changeHour(hourStep)"
[class.disabled]="disabled">
Expand Down Expand Up @@ -100,7 +100,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
</td>
</template>
</tr>
<tr>
<tr *ngIf="spinners">
<td class="text-xs-center">
<button class="btn-link" (click)="changeHour(-hourStep)"
[class.disabled]="disabled">
Expand Down Expand Up @@ -141,6 +141,11 @@ export class NgbTimepicker implements ControlValueAccessor {
*/
@Input() meridian = false;

/**
* Whether to display the spinners above and below the inputs.
*/
@Input() spinners = true;

/**
* Whether to display seconds input.
*/
Expand Down

0 comments on commit dc4962d

Please sign in to comment.