@WidgetComponent
File
Metadata
changeDetection |
ChangeDetectionStrategy.OnPush |
selector |
nm-date-time-range-picker |
styleUrls |
date-time-range-picker.component.widget.scss |
templateUrl |
./date-time-range-picker.component.widget.html |
Index
Widget inputs
|
|
|
Widget outputs
|
|
|
Properties
|
|
Methods
|
|
Methods
Public
chosenDateRange
|
chosenDateRange(value: )
|
|
|
Protected
configureWidget
|
configureWidget(configuration: WidgetConfig)
|
Decorators : WidgetConfigure
|
|
|
Public
_id
|
_id:
|
Decorators : WidgetId
|
|
Public
autofocus
|
autofocus: boolean
|
Type : boolean
|
Default value : false
|
|
Public
initialDateRange
|
initialDateRange: literal type
|
Type : literal type
|
|
Public
initialSelectedDateRange
|
initialSelectedDateRange:
|
Default value : new Subject<{
startDate: moment_.Moment;
endDate: moment_.Moment;
}>()
|
Decorators : WidgetInput
|
|
|
Public
selectedDateRange
|
selectedDateRange:
|
Default value : new ReplaySubject<any>(1)
|
Decorators : WidgetOutput
|
|
Emits selected date range
|
Private
unsubscribe
|
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
|
import {
Component,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from "@angular/core";
import { getOrDefault, WidgetConfig } from "../widget.configuration";
import { Subject, ReplaySubject } from "rxjs";
import { takeUntil } from "rxjs/operators";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetId,
WidgetInput,
WidgetOutput,
} from "../widget.metadata";
import { NgUnsubscribe } from "../../ng-unsubscribe";
import * as moment_ from "moment";
import { BaseConfiguration } from "../widgetframe";
const moment = moment_;
export interface DateTimeRangePickerConfiguration extends BaseConfiguration {
/**
* Set focus on input. @default(false)
*/
autofocus?: boolean;
}
@WidgetComponent("nm-date-time-range-picker")
@Component({
selector: "nm-date-time-range-picker",
templateUrl: "./date-time-range-picker.component.widget.html",
styleUrls: ["./date-time-range-picker.component.widget.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DateTimeRangePickerWidgetComponent {
private unsubscribe = NgUnsubscribe.create();
@WidgetConfiguration()
public configuration: WidgetConfig<DateTimeRangePickerConfiguration>;
@WidgetId()
public _id;
/**
* Sets selected date range
*/
@WidgetInput()
public initialSelectedDateRange = new Subject<{
startDate: moment_.Moment;
endDate: moment_.Moment;
}>();
/**
* Emits selected date range
*/
@WidgetOutput()
public selectedDateRange = new ReplaySubject<any>(1);
public initialDateRange: {
startDate: moment_.Moment;
endDate: moment_.Moment;
};
public autofocus: boolean = false;
constructor(protected cdr: ChangeDetectorRef) {}
@WidgetConfigure()
protected configureWidget(
configuration: WidgetConfig<DateTimeRangePickerConfiguration>
) {
this.initialSelectedDateRange
.pipe(takeUntil(this.unsubscribe))
.subscribe((initialSelectedDateRange) => {
this.initialDateRange = initialSelectedDateRange;
this.cdr.detectChanges();
});
this.autofocus = getOrDefault(
this.configuration.configuration["autofocus"],
false
);
}
public chosenDateRange(value) {
this.selectedDateRange.next(value);
}
}
<nm-widgetframe [configuration]="configuration">
<div slot="content" class="nm-widgetframe__content nm-dtrp__container">
<nm-date-time-range-picker-component
[initialDateRange]="initialDateRange"
(valueChange)="chosenDateRange($event)"
[autofocus]="configuration.configuration.autofocus"
>
</nm-date-time-range-picker-component>
</div>
</nm-widgetframe>
Legend
Html element with directive