11import { ChangeDetectorRef , Component , TemplateRef , ViewChild , ViewEncapsulation } from '@angular/core' ;
22import { 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 ;
0 commit comments