Skip to content

Commit

Permalink
Merge pull request #7 from danielmoncada/UpdateFeatures
Browse files Browse the repository at this point in the history
Update features
  • Loading branch information
danielmoncada committed Feb 12, 2020
2 parents d23729a + d2dd992 commit dba887d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export interface OwlMomentDateTimeAdapterOptions {
* {@default false}
*/
useUtc: boolean;

/**
* Turns the use of strict string parsing in moment.
* Changing this will change how the DateTimePicker interprets input.
* {@default false}
*/
parseStrict: boolean;
}

/** InjectionToken for moment date adapter to configure options. */
Expand All @@ -29,7 +36,8 @@ export const OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS = new InjectionToken<OwlMoment
/** @docs-private */
export function OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS_FACTORY(): OwlMomentDateTimeAdapterOptions {
return {
useUtc: false
useUtc: false,
parseStrict: false
};
}

Expand Down Expand Up @@ -246,11 +254,15 @@ export class MomentDateTimeAdapter extends DateTimeAdapter<Moment> {

public parse( value: any, parseFormat: any ): Moment | null {
if (value && typeof value === 'string') {
return this.createMoment(value, parseFormat, this.locale);
return this.createMoment(value, parseFormat, this.locale, this.parseStrict);
}
return value ? this.createMoment(value).locale(this.locale) : null;
}

get parseStrict() {
return this.options && this.options.parseStrict;
}

/**
* Returns the given value if given a valid Moment or null. Deserializes valid ISO 8601 strings
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid Moments and empty
Expand All @@ -265,7 +277,7 @@ export class MomentDateTimeAdapter extends DateTimeAdapter<Moment> {
if (!value) {
return null;
}
date = this.createMoment(value, moment.ISO_8601).locale(this.locale);
date = this.createMoment(value, moment.ISO_8601, this.parseStrict).locale(this.locale);
}
if (date && this.isValid(date)) {
return date;
Expand Down
2 changes: 2 additions & 0 deletions projects/picker/src/lib/date-time/timer-box.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<label class="owl-dt-timer-content">
<input class="owl-dt-timer-input" maxlength="2"
[value]="displayValue | numberFixedLen : 2"
(keydown.arrowup)="!upBtnDisabled && upBtnClicked()"
(keydown.arrowdown)="!downBtnDisabled && downBtnClicked()"
(input)="handleInputChange(valueInput.value)" #valueInput>
<span class="owl-hidden-accessible">{{inputLabel}}</span>
</label>
Expand Down
35 changes: 34 additions & 1 deletion projects/picker/src/lib/date-time/timer-box.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ChangeDetectionStrategy,
Component,
EventEmitter,
ElementRef,
ViewChild,
Input,
OnDestroy,
OnInit,
Expand Down Expand Up @@ -71,6 +73,10 @@ export class OwlTimerBoxComponent implements OnInit, OnDestroy {
return true;
}

@ViewChild('valueInput', { static: true })
private valueInput: ElementRef;
private onValueInputMouseWheelBind = this.onValueInputMouseWheel.bind(this);

constructor() {
}

Expand All @@ -83,10 +89,12 @@ export class OwlTimerBoxComponent implements OnInit, OnDestroy {
const inputValue = coerceNumberProperty(val, 0);
this.updateValueViaInput(inputValue);
}
})
});
this.bindValueInputMouseWheel();
}

public ngOnDestroy(): void {
this.unbindValueInputMouseWheel();
this.inputStreamSub.unsubscribe();
}

Expand All @@ -112,4 +120,29 @@ export class OwlTimerBoxComponent implements OnInit, OnDestroy {
}
this.inputChange.emit(value);
}

private onValueInputMouseWheel( event: any ): void {
event = event || window.event;
var delta = event.wheelDelta || -event.deltaY || -event.detail;

if (delta > 0){
!this.upBtnDisabled && this.upBtnClicked();
} else if (delta < 0){
!this.downBtnDisabled && this.downBtnClicked();
}

event.preventDefault ? event.preventDefault() : (event.returnValue = false);
}

private bindValueInputMouseWheel(): void {
this.valueInput.nativeElement.addEventListener(
'onwheel' in document ? "wheel" : "mousewheel",
this.onValueInputMouseWheelBind);
}

private unbindValueInputMouseWheel(): void {
this.valueInput.nativeElement.removeEventListener(
'onwheel' in document ? "wheel" : "mousewheel",
this.onValueInputMouseWheelBind);
}
}
16 changes: 15 additions & 1 deletion projects/picker/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@
*/

export { OwlDateTimeModule } from './lib/date-time/date-time.module';

export { OwlDateTimeIntl } from './lib/date-time/date-time-picker-intl.service';

export { OwlNativeDateTimeModule } from './lib/date-time/adapter/native-date-time.module';

export {
OWL_DATE_TIME_LOCALE_PROVIDER,
OWL_DATE_TIME_LOCALE,
DateTimeAdapter
DateTimeAdapter,

} from './lib/date-time/adapter/date-time-adapter.class';

export {
MomentDateTimeAdapter,
OwlMomentDateTimeAdapterOptions,
OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS
} from './lib/date-time/adapter/moment-adapter/moment-date-time-adapter.class';

export { OWL_DATE_TIME_FORMATS, OwlDateTimeFormats } from './lib/date-time/adapter/date-time-format.class';

export { OwlDateTimeInlineComponent } from './lib/date-time/date-time-inline.component';

export { OwlDateTimeComponent } from './lib/date-time/date-time-picker.component';

export { OwlMomentDateTimeModule } from './lib/date-time/adapter/moment-adapter/moment-date-time.module';

export * from './lib/date-time/calendar-body.component';
Expand Down

0 comments on commit dba887d

Please sign in to comment.