1.1.1 • Published 6 years ago

ngx-clarity-datetime v1.1.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Angular Date Time Picker

Angular date time picker - Angular reusable UI component This package supports Angular 4

Breaking Changes

  • This picker is complete changed in version 5.
  • This picker now is no longer as a directive added into a text input. Instead, it is a stand along component that includes a text input and a dropdown calendar-time picker. You could see more details down below.
  • This picker now does not use MomentJS. Instead, it is using date-fns. Here is why.

Latest Update

I am working on a way that the picker would add dynamically. In this way, the picker component would not have the input element and users could use their own input template (such as Angular Material, issue#161). In the next major update, the picker would use Javascript Intl to have better internationalization support.

Description

Simple Angular date time picker. Online demo is here. This picker is responsive design, so feel free to try it in your desktops, tablets and mobile devices. This picker uses date-fns.

How to Use

  1. Install with npm:npm install ng-pick-datetime --save
  2. Add <link rel="stylesheet" type="text/css" href="/node_modules/ng-pick-datetime/assets/style/picker.min.css" /> in your index.html.
  3. Add DateTimePickerModule import to your @NgModule like example below

       import { NgModule } from '@angular/core';
       import { BrowserModule } from '@angular/platform-browser';
       import { MyTestApp } from './my-test-app';
    
       import { DateTimePickerModule } from 'ng-pick-datetime';
    
       @NgModule({
           imports:      [ BrowserModule, DateTimePickerModule ],
           declarations: [ MyTestApp ],
           bootstrap:    [ MyTestApp ]
       })
       export class MyTestAppModule {}
  4. If you are using systemjs package loader add the following ng-pick-datetime properties to the System.config:

  (function (global) {
      System.config({
          paths: {
              'npm:': 'node_modules/'
          },
          map: {
              // Other components are here...

              'ng-pick-datetime': 'npm:ng-pick-datetime',
          },
          packages: {
              // Other components are here...

            // the picker
              'ng-pick-datetime': {
                  main: 'picker.bundle.js',
                  defaultExtension: 'js'
              },
          }
      });
  })(this);
  1. Add picker component to your component: <owl-date-time [(ngModel)]="moment" ></owl-date-time>

Animation

This picker uses angular animations to improve the user experience, starting with Angular 4 animations have their own module so you need to import BrowserAnimationsModule to your application. If you prefer to disable animation effect, use NoopAnimationsModule instead.

npm install @angular/animations --save

    import {BrowserModule} from '@angular/platform-browser';
    import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
    
    @NgModule({
        imports: [
            BrowserModule,
            BrowserAnimationsModule,
            //...
        ],
        //...
    })
    export class YourAppModule { }

Properties

NameTypeRequiredDefaultDescription
autoClosebooleanOptionalfalseWhen specified, the calendar would be close when selected a date
dataTypestringOptional'date'Type of the value to write back to ngModel. Default type is Javascript Date object. You could change it as string type
defaultMomentDate / stringOptionalnullSet the calendar's default month and year and timer picker's default value if the field is blank.
dateFormatstringOptionalYYYY/MM/DD HH:mmFormat of the date. You could find more in this.
disabledbooleanOptionalfalseWhen specified, disables the component.
disabledDatesArray-Date[]OptionalnullArray with dates that should be disabled (not selectable).
disabledDaysArray-number[]OptionalnullArray with weekday numbers that should be disabled (not selectable). Start from 0(Sunday) to 6(Saturday).
hideClearButtonbooleanOptionalfalseWhen specified to true, the picker's input clear icon would be hidden.
hourFormatstringOptional'24'Specify the hour format, valid values are '12' and '24'.
inlinebooleanOptionalfalseWhen enabled, displays the picker as inline. Default is false for popup mode.
inputIdstringOptionalnullIdentifier of the focus input to match a label defined for the component.
inputStyleObjectOptionalnullInline style of the picker text input.
inputStyleClassstringOptionalnullStyle class of the picker text input.
localeObjectOptionalnullAn object having regional configuration properties for the dateTimePicker. You could learn more in below.
maxDateCountnumberOptionalnullMaximum number of selectable dates in multiple mode.
maxDate / stringOptionalnullSet the maximum date/time that is selectable.
minDate / stringOptionalnullSet the minimum date/time that is selectable.
placeHolderstringOptional'yyyy/mm/dd hh:mm'Placeholder text for the input.
readonlyInputbooleanOptionaltrueWhen specified to false, allows to enter the date manually with keyboard.
requiredbooleanOptionalfalseWhen present, it specifies that an input field must be filled out before submitting the form.
showButtonsbooleanOptionalfalseWhen specified, the picker would have a confirm button and close button.
selectionModestringOptional'single'Defines the quantity of the selection, valid values are "single", "multiple" and "range".
showHeaderbooleanOptionalfalseDefines whether to show the picker dialog header.
showOtherMonthsbooleanOptionaltrueWhen it is set to false, it would only show current month's days in calendar.
showSecondsTimerbooleanOptionalfalseDefines whether to show a timer to control time's second value.
styleObjectOptionalnullInline style of the whole component.
styleClassstringOptionalnullStyle class of the whole component.
tabIndexnumberOptionalnullIndex of the element in tabbing order.
typestringOptional'both'Specify the type of the date-time picker, valid value are 'both', 'calendar' and 'timer'.

Events

EventsParameterDescription
onBlurevent: Blur eventCallback to invoke on blur of input field
onFocusevent: Focus eventCallback to invoke on focus of input field.
onInvalidoriginalEvent: event, value: invalid date-time valueCallback to invoke when a invalid date-time value is selected.
onSelectevent: event, value: selected date-time valueCallback to invoke when a picker's date-time value is changed.
onConfirmoriginalEvent: event, value: selected date-time valueCallback to invoke when a confirm button is clicked.
onClearoriginalEvent: event, value: nullCallback to invoke when a clear button is clicked.
onCloseevent: eventCallback to invoke when picker dialog is closed.

Styling

Following is the list of structural style classes.

NameElement
owl-dateTimeWrapper of the whole element
owl-dateTime-inputInput element
owl-dateTime-dialogWrapper of the dropdown dialog

DateFormat

Default date format is 'YYYY/MM/DD HH:mm', to customize this use dateFormat property. Following options can be a part of the format.

  • s - second of the time value (no leading zero 0, 1, ..., 59)
  • ss - second of the time value (two digits 00, 01, ..., 59)
  • m - minute of the time value (no leading zero 0, 1, ..., 59)
  • mm - minute of the time value (two digits 00, 01, ..., 59)
  • h - hour of the time value, 12 hour format (no leading zero 1, 2, ..., 12)
  • hh - hour of the time value, 12 hour format (two digits 01, 02, ..., 12)
  • H - hour of the time value, 24 hour format (no leading zero 0, 1, ..., 23)
  • HH - hour of the time value, 24 hour format (two digits 00, 01, ..., 23)
  • A - meridian of the time value (AM, PM)
  • a - meridian of the time value (am, pm)
  • D - day of the month (no leading zero 1, 2, ..., 31)
  • DD - day of the month (two digits 01, 02, ..., 31)
  • M - month of the year (no leading zero 1, 2, ..., 12)
  • MM - month of the year (two digits 01, 02, ..., 12)
  • MMM - month of the year (Jan, Feb, ..., Dec)
  • MMMM - month of the year (January, February, ..., December)
  • YYYY - year(2015, 2016, 2017 ...)

Your could learn more about this from here.

Localization

Localization for different languages and formats is defined by binding the locale settings object to the locale property. Following is the default values for English.

<owl-date-time [(ngModel)]="dateValue" [locale]="en"></owl-date-time>
export class MyModel {
    
    en: any;
    
    ngOnInit() {
        this.en = {
            firstDayOfWeek: 0,
            dayNames: ["Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"],
            dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
            monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
            monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
        };
    }
}

If you want the formatted date time to be localized as well, you need to npm install date-fns.

<owl-date-time [(ngModel)]="dateValue" [locale]="es"></owl-date-time>
export class MyModel {
    
    es: any;
    esLocale = require('date-fns/locale/es')
    
    ngOnInit() {
        this.es = {
			 firstDayOfWeek: 1,
		     dayNames:["domingo","lunes","martes","miércoles","jueves","viernes","sábado" ],
		     dayNamesShort: [ "dom","lun","mar","mié","jue","vie","sáb" ],
		     monthNames: [ "enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre" ],
		     monthNamesShort: [ "ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic" ],
		     dateFns: esLocale
        };
    }
}

Dependencies

date-fns

Theme

The picker now separate its styles into ./node_modules/ng-pick-datetime/assets/style/picker.min.css. You could inspect the picker's classes from your browser's dev tool and overwrite them in your project's css files.

Demo

Online demo is here

License

  • License: MIT

Author

Daniel YK Pan

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago