0.6.4 • Published 4 years ago

ng2-date-picker-raul-solution v0.6.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Build Status

Date Picker

This is a configurable date-picker build for Angular2 applications and uses MomentJS as its dependency.
DEMO

Installation:

  1. Download from npm: npm install ng2-date-picker --save
  2. import the DpDatePickerModule module:
    import {DpDatePickerModule} from 'ng2-date-picker';
  3. Add DpDatePickerModule to your module imports:
 @NgModule({
   ...
   imports: [
     ...
     DpDatePickerModule
   ]
 })

Usage

Put the dp-date-picker component wherever you need it.

Attributes:

NameTypeDefaultdescription
disabledBooleanfalseIf set to true the input would be disabled
placeholderString""The date-picker input placeholder
requiredBooleanundefinedThis is a validation rule, if there won't be any selected date then the containing form will be invalid.
minDateMoment|StringundefinedThis is a validation rule, if the selected date will be before minDate the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object.
maxDateMoment|StringundefinedThis is a validation rule, if the selected date will be after maxDate the containing form will be invalid. Note: if provided as string format configuration should be provided in the config object.
themestring''Theme is a class added to the popup container - this will allow styling of the calendar when it's appended to outer element (for example - body). There is a built in theme named dp-material, you can find it in the demo.
configIDayPickerConfigSee BelowConfiguration object - see description below.

Configuration:

In order to provide configurations to the date-picker you need to pass it to the dp-date-picker component:

<dp-day-picker [(ngModel)]="selectedDate" [config]="datePickerConfig"></dp-day-picker>

Here are the available configurations:

NameTypeDefaultdescription
firstDayOfWeekString"su"The first day of the calendar's week. Should be one of: "su", "mo", "tu", "we", "th", "fr", "sa"
calendarsAmountNumber1The amount of calenders shown when the date-picker open
formatString"DD-MM-YYYY"If ngModel provided as String the format is required, this format also will be used as the input format style.
monthFormatString"MMM-YYYY"The date format of the month calendar, the one that seen above the calendar days. Will be overwritten if monthFormatter provided.
monthFormatter(Moment) => StringundefinedThe date formatter (callback function) of the month calendar, the one that seen above the calendar days.
allowMultiSelectBooleanundefinedIf set to true will allow for choosing multiple dates. false will force a single selection. If undefined, the picker will attempt to guess based on the type of the input value.
closeOnSelectBooleantrueIf set to true will close the date-picker after choosing a date from the calender, otherwise, won't.
closeOnSelectDelayNumber100The delay (in ms) between the date selection and the date-picker collapse
onOpenDelayNumber0The delay (in ms) between the date picker focusing and the date-picker popup apparel
weekdayNamesObject{su: 'sun',mo: 'mon',tu: 'tue',we: 'wed',th: 'thu',fr: 'fri',sa: 'sat'}The weekday names as they are shown above the calendar days. The keys should be the same as seen in the default example.
disableKeypressBooleanfalseDisables the possibility to change the date value by typing it - changing the date would be possible only from the picker
minMoment|StringundefinedDisables all dates (on the date-picker) that are set to before the min, note that if invalid date would be set by the input then the date picker value would be the min date but the input will show the user typed date.
maxMoment|StringundefinedDisables all dates (on the date-picker) that are set to after the max, note that if invalid date would be set by the input then the date picker value would be the max date but the input will show the user typed date.
userValueTypeStringundefinedThe type of the value being passed out in ngModelChange. "string" passes values back as string or string[]. "object" passes values back as Moment or Moment[]. If undefined, the picker will attempt to guess based on the type of the input value.
appendToString|HTMLElementundefinedThe selector/element to which the calendar popup will append to (this is useful for overflow: hidden container issues). Please note that the appendTo element will be set with position absolute if it has position static (the default position).
drops'up'|'down'downWhether the picker appears below or above the input element.
opens'right'|'left'rightWhether the picker appears aligned to the left or to the right the input element.
showNearMonthDaysBooleantrueWhether to show/hide next and previous month days.
showWeekNumbersBooleanfalseWhether to show/hide the week number of each week (iso week number).

API:

In order to use the date-picker api user the @ViewChild annotation in the date-picker containing component class, take at the example bellow:
Container component:

import {Component, ViewChild} from '@angular/core';
import {DpDayPickerComponent} from 'ng2-date-picker';

@Component({
selector: 'my-container',
template: `
<div>
    <h1>Container</h1>
    <dp-day-picker #dayPicker></dp-day-picker>
    <button (click)="open()"></button>
    <button (click)="close()"></button>
</div>
`
});
class MyContainer {
    @ViewChild('dayPicker') dayPicker: DpDayPickerComponent;
    
    open() {
        this.dayPicker.api.open();
    }
     
    close() {
         this.dayPicker.api.close();
    } 
}  

Here is the list of APIs:

NameSignatureDescription
open() => voidOpens the date picker
close() => voidCloses the date picker

Inline

You can use the <dp-calendar> component to display the calendar widget without an associated input box.

i.e.

<dp-calendar [(selected)]="dates" [config]="calendarConfig"></dp-calendar>

Inputs

NameTypeDescription
selectedMoment[]Opens the date picker
themestringSame as putting a class on the element
configICalendarConfigA subset of the IDayPickerConfig.Properties include: firstDayOfWeek, calendarsAmount, min, max, allowMultiSelect, format, monthFormat, and monthFormatter.These properties behave as described in the Configuration section above.

Outputs

NameTypeDescription
selectedChangeEventEmitter<Moment[]>Emits the currently selected days every time the selection changes
dayClickEventEmitter<IDayEvent>Emits every time a day is clicked on the calendar
dayContextMenuEventEmitter<IDayEvent>Emits every time a day is right-clicked on the calendar
calendarMoveEventEmitter<Moment>Emits every time the calendar moves to a different set of months. The date emitted is the first month displayed.