6
6
ViewEncapsulation ,
7
7
ChangeDetectorRef ,
8
8
EventEmitter ,
9
- ViewChild ,
10
- AfterViewInit
9
+ ViewChild
11
10
} from '@angular/core' ;
12
11
import { Ng2Datetime } from './ng2-datetime' ;
13
12
@@ -24,7 +23,8 @@ declare var moment: any;
24
23
selector : 'ng2-datetime-picker' ,
25
24
template : `
26
25
<div class="ng2-datetime-picker">
27
-
26
+ <div class="close-button" *ngIf="showCloseButton" (click)="close()">X</div>
27
+
28
28
<!-- Month - Year -->
29
29
<div class="month" *ngIf="!timeOnly">
30
30
<b class="prev_next prev" (click)="updateMonthData(-12)">«</b>
@@ -119,35 +119,43 @@ declare var moment: any;
119
119
}
120
120
121
121
.ng2-datetime-picker {
122
- color: #333;
123
- outline-width: 0;
124
- font: normal 14px sans-serif;
125
- border: 1px solid #ddd;
126
- display: inline-block;
127
- background: #fff;
128
- animation: slideDown 0.1s ease-in-out;
129
- animation-fill-mode: both;
122
+ color: #333;
123
+ outline-width: 0;
124
+ font: normal 14px sans-serif;
125
+ border: 1px solid #ddd;
126
+ display: inline-block;
127
+ background: #fff;
128
+ animation: slideDown 0.1s ease-in-out;
129
+ animation-fill-mode: both;
130
+ }
131
+ .ng2-datetime-picker .close-button {
132
+ position: absolute;
133
+ padding: 0 5px;
134
+ cursor: pointer;
135
+ color: #ff0000;
136
+ right: 0;
137
+ z-index: 1;
130
138
}
131
139
.ng2-datetime-picker > .month {
132
- text-align: center;
133
- line-height: 22px;
134
- padding: 10px;
135
- background: #fcfcfc;
136
- text-transform: uppercase;
137
- font-weight: bold;
138
- border-bottom: 1px solid #ddd;
139
- position: relative;
140
+ text-align: center;
141
+ line-height: 22px;
142
+ padding: 10px;
143
+ background: #fcfcfc;
144
+ text-transform: uppercase;
145
+ font-weight: bold;
146
+ border-bottom: 1px solid #ddd;
147
+ position: relative;
140
148
}
141
149
.ng2-datetime-picker > .month > .prev_next {
142
- color: #555;
143
- display: block;
144
- font: normal 24px sans-serif;
145
- outline: none;
146
- background: transparent;
147
- border: none;
148
- cursor: pointer;
149
- width: 15px;
150
- text-align: center;
150
+ color: #555;
151
+ display: block;
152
+ font: normal 24px sans-serif;
153
+ outline: none;
154
+ background: transparent;
155
+ border: none;
156
+ cursor: pointer;
157
+ width: 15px;
158
+ text-align: center;
151
159
}
152
160
.ng2-datetime-picker > .month > .prev_next:hover {
153
161
background-color: #333;
@@ -160,64 +168,64 @@ declare var moment: any;
160
168
float: right;
161
169
}
162
170
.ng2-datetime-picker > .days {
163
- width: 210px; /* 30 x 7 */
164
- margin: 10px;
165
- text-align: center;
171
+ width: 210px; /* 30 x 7 */
172
+ margin: 10px;
173
+ text-align: center;
166
174
}
167
175
.ng2-datetime-picker > .days .day-of-week,
168
176
.ng2-datetime-picker > .days .day {
169
- box-sizing: border-box;
170
- -moz-box-sizing: border-box;
171
- border: 1px solid transparent;
172
- width: 30px;
173
- line-height: 28px;
174
- float: left;
177
+ box-sizing: border-box;
178
+ -moz-box-sizing: border-box;
179
+ border: 1px solid transparent;
180
+ width: 30px;
181
+ line-height: 28px;
182
+ float: left;
175
183
}
176
184
.ng2-datetime-picker > .days .day-of-week {
177
- font-weight: bold;
185
+ font-weight: bold;
178
186
}
179
187
.ng2-datetime-picker > .days .day-of-week.weekend {
180
- color: #ccc;
181
- background-color: inherit;
188
+ color: #ccc;
189
+ background-color: inherit;
182
190
}
183
191
.ng2-datetime-picker > .days .day:not(.selectable) {
184
- color: #ccc;
185
- cursor: default;
192
+ color: #ccc;
193
+ cursor: default;
186
194
}
187
195
.ng2-datetime-picker > .days .weekend {
188
- color: #ccc;
189
- background-color: #eee;
196
+ color: #ccc;
197
+ background-color: #eee;
190
198
}
191
199
.ng2-datetime-picker > .days .day.selectable {
192
- cursor: pointer;
200
+ cursor: pointer;
193
201
}
194
202
.ng2-datetime-picker > .days .day.selected {
195
- background: gray;
196
- color: #fff;
203
+ background: gray;
204
+ color: #fff;
197
205
}
198
206
.ng2-datetime-picker > .days .day:not(.selected).selectable:hover {
199
- background: #eee;
207
+ background: #eee;
200
208
}
201
209
.ng2-datetime-picker > .days:after {
202
- content: '';
203
- display: block;
204
- clear: left;
205
- height: 0;
210
+ content: '';
211
+ display: block;
212
+ clear: left;
213
+ height: 0;
206
214
}
207
215
.ng2-datetime-picker .hourLabel,
208
216
.ng2-datetime-picker .minutesLabel {
209
- display: inline-block;
210
- width: 40px;
211
- text-align: right;
217
+ display: inline-block;
218
+ width: 40px;
219
+ text-align: right;
212
220
}
213
221
.ng2-datetime-picker input[type=range] {
214
- width: 200px;
222
+ width: 200px;
215
223
}
216
224
`
217
225
] ,
218
226
encapsulation : ViewEncapsulation . None
219
227
} )
220
- export class Ng2DatetimePickerComponent implements AfterViewInit {
228
+ export class Ng2DatetimePickerComponent {
221
229
@Input ( 'date-format' ) dateFormat : string ;
222
230
@Input ( 'date-only' ) dateOnly : boolean ;
223
231
@Input ( 'time-only' ) timeOnly : boolean ;
@@ -231,6 +239,7 @@ export class Ng2DatetimePickerComponent implements AfterViewInit {
231
239
@Input ( 'min-hour' ) minHour : number ;
232
240
@Input ( 'max-hour' ) maxHour : number ;
233
241
@Input ( 'disabled-dates' ) disabledDates : Date [ ] ;
242
+ @Input ( 'show-close-button' ) showCloseButton : boolean ;
234
243
235
244
@Output ( 'selected$' ) selected$ :EventEmitter < any > = new EventEmitter ( ) ;
236
245
@Output ( 'closing$' ) closing$ :EventEmitter < any > = new EventEmitter ( ) ;
@@ -250,15 +259,15 @@ export class Ng2DatetimePickerComponent implements AfterViewInit {
250
259
this . el = elementRef . nativeElement ;
251
260
}
252
261
253
- public ngAfterViewInit ( ) :void {
254
- let stopPropagation = ( e : Event ) => e . stopPropagation ( ) ;
255
- if ( ! this . dateOnly ) {
256
- this . hours . nativeElement . addEventListener ( 'keyup' , stopPropagation ) ;
257
- this . hours . nativeElement . addEventListener ( 'mousedown' , stopPropagation ) ;
258
- this . minutes . nativeElement . addEventListener ( 'keyup' , stopPropagation ) ;
259
- this . minutes . nativeElement . addEventListener ( 'mousedown' , stopPropagation ) ;
260
- }
261
- }
262
+ // public ngAfterViewInit ():void {
263
+ // let stopPropagation = (e: Event) => e.stopPropagation();
264
+ // if (!this.dateOnly) {
265
+ // this.hours.nativeElement.addEventListener('keyup', stopPropagation);
266
+ // this.hours.nativeElement.addEventListener('mousedown', stopPropagation);
267
+ // this.minutes.nativeElement.addEventListener('keyup', stopPropagation);
268
+ // this.minutes.nativeElement.addEventListener('mousedown', stopPropagation);
269
+ // }
270
+ // }
262
271
263
272
public get year ( ) :number {
264
273
return this . selectedDate . getFullYear ( ) ;
@@ -353,7 +362,6 @@ export class Ng2DatetimePickerComponent implements AfterViewInit {
353
362
return Ng2Datetime . formatDate ( this . selectedDate , this . dateFormat , this . dateOnly ) ;
354
363
} ;
355
364
this . selected$ . emit ( this . selectedDate ) ;
356
- this . closing$ . emit ( true ) ;
357
365
} ;
358
366
359
367
/**
@@ -379,4 +387,7 @@ export class Ng2DatetimePickerComponent implements AfterViewInit {
379
387
return false ;
380
388
}
381
389
390
+ public close ( ) {
391
+ this . closing$ . emit ( true ) ;
392
+ }
382
393
}
0 commit comments