0.0.2 • Published 2 years ago

ngx-mat-smart-daterange-picker v0.0.2

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

NgxMatSmartDateTimePicker

This library add a component to select a date range à la Grafana. You can pick date with the picker, use pre-defined periods or select date manualy.

screenshot

Get started

Install the lib

npm install ngx-smart-daterange-picker

Then import the module somewhere in your application :

app.module.ts
NgxSmartDateRangePickerModule.forRoot({
  lang: 'en-US' // available locales are en-GB, en-US, fr-BE, fr-CA, fr-FR
});

And use it in your component :

app.component.ts
start = new Date(2020, 0, 1);
today = new Date();

maxRange = 10; // limit selection range to 10 days (0 for unlimited)
app.component.html
<ngx-mat-smart-daterange-picker [min]="start" [max]="today" [maxRange]="maxRange"> </ngx-mat-smart-daterange-picker>

Options

You can define relative time range periods globally when importing module

app.module.ts
const relativeTimeRanges: RelativeTimeRange[] = [
  { label: 'last5Minutes', from: 'now-5m', to: 'now' },
  { label: 'last15Minutes', from: 'now-15m', to: 'now' },
  { label: 'last30Minutes', from: 'now-30m', to: 'now' },
  { label: 'todaySoFar', from: 'now/d', to: 'now' }
];

NgxSmartDateRangePickerModule.forRoot({
  relativeTimeRanges,
  lang: 'en-US'
});

Or you can define it when using the component :

app.component.ts
// Overload default configuration
readonly relativeTimeRanges: RelativeTimeRange[] = [
  { label: 'last5Minutes', from: 'now-5m', to: 'now' },
  { label: 'last15Minutes', from: 'now-15m', to: 'now' },
  { label: 'last30Minutes', from: 'now-30m', to: 'now' },
  { label: 'todaySoFar', from: 'now/d', to: 'now' }
];

app.component.html

<ngx-mat-smart-daterange-picker
  [min]="start"
  [max]="today"
  [maxRange]="maxRange"
  [relativeTimeRanges]="relativeTimeRanges"
>
</ngx-mat-smart-daterange-picker>

API

NgxMatSmartDateRangePickerComponent

NameDescription
@Input() min: DateMinimum date that can be selected in picker (default: undefined)
@Input() max: DateMaximum date that can be selected in picker (default: undefined)
@Input() maxRange: numberNumber of day that user can select in picker (default: 0)
@Input() recentlyUsedTimeRangeCount: numberNumber of date the component keep in the recently used section (default: 4)
@Input() relativeTimeRanges: RelativeTimeRange[]Dates that can be shown in the relative time range section (default: lot's of dates
0.0.2

2 years ago

0.0.1

2 years ago