Socket
Socket
Sign inDemoInstall

mygrsdatepicker

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mygrsdatepicker

Angular2 date picker


Version published
Weekly downloads
10
increased by100%
Maintainers
1
Install size
124 kB
Created
Weekly downloads
 

Readme

Source

mygrsdatepicker

Angular 2 date picker - Angular2 reusable UI component

Build Status codecov npm

Description

Simple Angular2 date picker. Online demo is here

Installation

To install this component to an external project, follow the procedure:

  1. npm install mygrsdatepicker --save

  2. Add mygrsdatepickerModule 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 { mygrsdatepickerModule } from 'mygrsdatepicker';
    
    @NgModule({
        imports:      [ BrowserModule, mygrsdatepickerModule ],
        declarations: [ MyTestApp ],
        bootstrap:    [ MyTestApp ]
    })
    export class MyTestAppModule {}
    
  3. Use the following snippet inside your template:

    <my-date-picker [options]="mygrsdatepickerOptions"
                    (dateChanged)="onDateChanged($event)"></my-date-picker>
    
    • Mandatory attributes:

      • [options]="mygrsdatepickerOptions"
      • (dateChanged)="onDateChanged($event)"
    • Optional attributes:

      • [selDate]="selectedDate" || [defaultMonth]="defaultMonth"
      • [locale]="locale"
    • Example of the options data (not all properties listed):

        mygrsdatepickerOptions = {
            todayBtnTxt: 'Today',
            dateFormat: 'yyyy-mm-dd',
            firstDayOfWeek: 'mo',
            sunHighlight: true,
            height: '34px',
            width: '260px',
            inline: false,
            disableUntil: {year: 2016, month: 8, day: 10},
            selectionTxtFontSize: '16px'
        };
    
    • Example of the date changed callback:
        onDateChanged(event:any) {
            console.log('onDateChanged(): ', event.date, ' - formatted: ', event.formatted, ' - epoc timestamp: ', event.epoc);
        }
    
  4. If you are using systemjs package loader add the following mygrsdatepicker properties to the System.config:

    (function (global) {
        System.config({
            paths: {
                'npm:': 'node_modules/'
            },
            map: {
                // Other components are here...
    
                'mygrsdatepicker': 'npm:mygrsdatepicker',
            },
            packages: {
                // Other components are here...
    
                mygrsdatepicker: {
                    main: './index.js',
                    defaultExtension: 'js'
                }
            }
        });
    })(this);
    

Usage

options attribute

Value of the options attribute is a javascript object. It can contain the following properties.

OptionDefaultDescription
dayLabels{su: 'Sun', mo: 'Mon', tu: 'Tue', we: 'Wed', th: 'Thu', fr: 'Fri', sa: 'Sat'}Day labels visible on the selector.
monthLabels{ 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }Month labels visible on the selector.
dateFormatyyyy-mm-ddDate format on selection area and callback.
todayBtnTxtTodayToday button text.
firstDayOfWeekmoFirst day of week on calendar. One of the following: mo, tu, we, th, fr, sa, su
sunHighlighttrueSunday red colored on calendar.
editableMonthAndYeartrueIs month and year labels editable or not.
minYear1000Minimum allowed year in calendar. Cannot be less than 1000.
maxYear9999Maximum allowed year in calendar. Cannot be more than 9999.
disableUntilno default valueDisable dates backward starting from the given date. For example: {year: 2016, month: 6, day: 26}
disableSinceno default valueDisable dates forward starting from the given date. For example: {year: 2016, month: 7, day: 22}
disableWeekendsfalseDisable weekends (Saturday and Sunday).
inlinefalseShow mygrsdatepicker in inline mode.
height34pxmygrsdatepicker height without selector. Can be used if inline = false.
width100%mygrsdatepicker width. Can be used if inline = false.
selectionTxtFontSize18pxSelection area font size. Can be used if inline = false.
alignSelectorRightfalseAlign selector right. Can be used if inline = false.
indicateInvalidDatetrueIf user typed date is not same format as dateFormat, show red background in the selection area. Can be used if inline = false.
showDateFormatPlaceholderfalseShow value of dateFormat as placeholder in the selection area if it is empty. Can be used if inline = false.

locale attribute

A two-letter ISO 639-1 language code can be provided as shorthand for several of the options listed above. Currently supported languages: en, fr, ja, fi and es. If the locale attribute is used it overrides dayLabels, monthLabels, dateFormat, todayBtnTxt, firstDayOfWeek and sunHighlight properties from the options.

  • new locale data can be added to this file.

selDate attribute

Provide the initially chosen date that will display both in the text input field and provide the default for the popped-up selector.

defaultMonth attribute

If selDate is not specified, when the datepicker is opened, it will ordinarily default to selecting the current date. If you would prefer a different year and month to be the default for a freshly chosen date picking operation, specify a [defaultMonth] in the same format as that for the datepicker options (yyyy.mm if not otherwise specified).

Development of this component

At first fork and clone this repo.

Install all dependencies:

  1. npm install
  2. npm install --global gulp-cli

Run sample application:

  1. Open a terminal and type npm start
  2. Open http://localhost:5000 to browser

Build dist folder (javascript version of the component):

  • gulp all

Execute unit tests and coverage (output is generated to the test-output folder):

  • npm test

Demo

Online demo is here

Compatibility (tested with)

  • Firefox (latest)
  • Chromium (latest)
  • Edge
  • IE11

License

  • License: MIT

Author

  • Author: kekeh

Keywords

FAQs

Last updated on 07 Nov 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc