Skip to content

Commit 090cc94

Browse files
committed
[fabric] add example for spin button component
1 parent 5a7763f commit 090cc94

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

apps/demo/src/app/app.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ <h2>Getting up and running...</h2>
1212
<fab-icon iconName="Add" (onClick)="onClickEventHandler($event)" (onMouseOver)="onMouseOverEventHandler($event)">
1313
</fab-icon>
1414

15+
<fab-spin-button
16+
label="my label"
17+
[value]="7 + ' cm'"
18+
[validate]="onValidate"
19+
[increment]="onIncrement"
20+
[decrement]="onDecrement"
21+
></fab-spin-button>
22+
1523
<div>
1624
<fab-pivot>
1725
<fab-pivot-item headerText="Tab 1"> <div>Tab 1's content</div> </fab-pivot-item>

apps/demo/src/app/app.component.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ChangeDetectorRef, Component, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
22
import { ICalendarStrings, IContextualMenuProps, ISelection, Selection } from 'office-ui-fabric-react';
33

4+
const suffix = ' cm';
5+
46
@Component({
57
selector: 'app-root',
68
templateUrl: './app.component.html',
@@ -13,6 +15,8 @@ export class AppComponent {
1315
dismissMenu: (ev?: any, dismissAll?: boolean) => void;
1416
}>;
1517

18+
textFieldValue = 'Hello';
19+
1620
onClickEventHandler(ev) {
1721
console.log('onClick', { ev });
1822
}
@@ -92,8 +96,53 @@ export class AppComponent {
9296
console.log('Column header clicked', event);
9397
}
9498

99+
onIncrement(value: string): string | void {
100+
value = this._removeSuffix(value, suffix);
101+
102+
if (+value >= 13) {
103+
return value + suffix;
104+
}
105+
106+
return String(+value + 2) + suffix;
107+
}
108+
109+
onDecrement(value: string): string | void {
110+
value = this._removeSuffix(value, suffix);
111+
112+
if (+value <= 3) {
113+
return value + suffix;
114+
}
115+
return String(+value - 2) + suffix;
116+
}
117+
118+
onValidate(value: string, event: Event): string | void {
119+
value = this._removeSuffix(value, suffix);
120+
if (value.trim().length === 0 || isNaN(+value)) {
121+
return '0' + suffix;
122+
}
123+
124+
return String(value) + suffix;
125+
}
126+
127+
private _hasSuffix(value: string, suffix: string): Boolean {
128+
const subString = value.substr(value.length - suffix.length);
129+
return subString === suffix;
130+
}
131+
132+
private _removeSuffix(value: string, suffix: string): string {
133+
if (!this._hasSuffix(value, suffix)) {
134+
return value;
135+
}
136+
137+
return value.substr(0, value.length - suffix.length);
138+
}
139+
95140
constructor(private readonly cd: ChangeDetectorRef) {
96141
this.selection = new Selection();
142+
143+
this.onValidate = this.onValidate.bind(this);
144+
this.onIncrement = this.onIncrement.bind(this);
145+
this.onDecrement = this.onDecrement.bind(this);
97146
}
98147

99148
customItemCount = 1;

apps/demo/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
FabSpinnerModule,
3232
FabToggleModule,
3333
FabTooltipModule,
34+
FabSpinButtonModule,
3435
} from '@angular-react/fabric';
3536
import { NgModule } from '@angular/core';
3637
import { NxModule } from '@nrwl/nx';
@@ -73,6 +74,7 @@ import { CounterComponent } from './counter/counter.component';
7374
FabDetailsListModule,
7475
FabGroupModule,
7576
FabMarqueeSelectionModule,
77+
FabSpinButtonModule,
7678
],
7779
declarations: [AppComponent, CounterComponent],
7880
bootstrap: [AppComponent],

0 commit comments

Comments
 (0)