npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mydaterangepicker2

v1.0.14

Published

Angular2 date range picker

Downloads

3

Readme

mydaterangepicker

Angular 2 date range picker - Angular2 reusable UI component

Build Status codecov npm

Description

Simple Angular2 date range picker. Online demo is here

Installation

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

  1. npm install mydaterangepicker --save

  2. Add MyDateRangePickerModule import to your @NgModule like example below

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { MyTestApp } from './my-test-app';
    
    // If you are using webpack package loader import the MyDateRangePickerModule from here:
    import { MyDateRangePickerModule } from 'mydaterangepicker';
    
    // If you are using systemjs package loader import the MyDateRangePickerModule from here:
    import { MyDateRangePickerModule } from 'mydatepicker/dist/my-date-range-picker.module';
    
    @NgModule({
        imports:      [ BrowserModule, MyDateRangePickerModule ],
        declarations: [ MyTestApp ],
        bootstrap:    [ MyTestApp ]
    })
    export class MyTestAppModule {}
  3. Use the following snippet inside your template:

    <my-date-range-picker [options]="myDateRangePickerOptions"
                    (dateRangeChanged)="onDateRangeChanged($event)"></my-date-range-picker>
    • Mandatory attributes:

      • [options]="myDateRangePickerOptions"
      • (dateRangeChanged)="onDateRangeChanged($event)"
    • Optional attributes:

      • [selDateRange]="selectedDateRange"
      • (inputFieldChanged)="onInputFieldChanged($event)"
      • (calendarViewChanged)="onCalendarViewChanged($event)"
  4. If you are using systemjs package loader add the following mydaterangepicker properties to the System.config:

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

Usage

options attribute

| Option | Default | Description | | ------------- | ------------- | ----- | | 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. | | dateFormat | yyyy-mm-dd | Date format on the selection area and the callback. For example: dd.mm.yyyy, yyyy-mm-dd, dd mmm yyyy (mmm = Month as a text) | | showClearBtn | true | Show 'Clear' button on calendar. | | clearBtnTxt | Clear | Clear button text. Can be used if showClearBtn = true. | | beginDateBtnTxt | Begin Date | To begin date button text. | | endDateBtnTxt | End Date | To end date button text. | | acceptBtnTxt | OK | Accept date range button text. | | showSelectDateText | true | Show select date text. | | selectBeginDateTxt | Select Begin Date | Select begin date text. Can be used if showSelectDateText = true.| | selectEndDateTxt | Select End Date | Select end date text. Can be used if showSelectDateText = true. | | firstDayOfWeek | mo | First day of week on calendar. One of the following: mo, tu, we, th, fr, sa, su | | sunHighlight | true | Sunday red colored on calendar. | | markCurrentDay | true | Is current day (today) marked on calendar. | | editableMonthAndYear | true | Is month and year labels editable or not. | | minYear | 1000 | Minimum allowed year in calendar. Cannot be less than 1000. | | maxYear | 9999 | Maximum allowed year in calendar. Cannot be more than 9999. | | inline | false | Show mydaterangepicker in inline mode. | | height | 34px | mydatepicker height without selector. Can be used if inline = false. | | width | 100% | mydatepicker width. Can be used if inline = false. | | selectionTxtFontSize | 18px | Selection area font size. Can be used if inline = false. | | alignSelectorRight | false | Align selector right. Can be used if inline = false. | | indicateInvalidDateRange | true | If user typed date range is not same format as dateFormat, show red background in the selection area. Can be used if inline = false. | | showDateRangeFormatPlaceholder | false | Show value of dateFormat - dateFormat as placeholder in the selection area if it is empty. Can be used if inline = false. | | customPlaceholderTxt | empty string | Show custom string in the selection area if a date range is not selected. Can be used if showDateRangeFormatPlaceholder = false and inline = false. | | componentDisabled | false | Is selection area input field and buttons disabled or not (input disabled flag). Can be used if inline = false. | | editableDateRangeField | true | Is selection area input field editable or not (input readonly flag). Can be used if inline = false. | | inputValueRequired | false | Is selection area input field value required or not (input required flag). Can be used if inline = false. |

  • Example of the options data (not all properties listed):
    myDateRangePickerOptions = {
        clearBtnTxt: 'Clear',
        beginDateBtnTxt: 'Begin Date',
        endDateBtnTxt: 'End Date',
        acceptBtnTxt: 'OK',
        dateFormat: 'dd.mm.yyyy',
        firstDayOfWeek: 'mo',
        sunHighlight: true,
        height: '34px',
        width: '260px',
        inline: false,
        selectionTxtFontSize: '15px',
        alignSelectorRight: false,
        indicateInvalidDateRange: true,
        showDateRangeFormatPlaceholder: false
    };

selDateRange attribute

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

defaultMonth attribute

If selDateRange is not specified, when the daterangepicker 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] attribute.

Value of the [defaultMonth] attribute is a string which contain year number and month number separated by delimiter. The delimiter can be any special character. For example the value of the [defaultMonth] attribute can be: 2016.08, 08-2016, 08/2016.

dateRangeChanged callback:

  • called when the date range is selected, removed or input field typing is valid

  • event parameter:

    • event.beginDate: Date object in the following format: { day: 22, month: 11, year: 2016 }
    • event.endDate: Date object in the following format: { day: 23, month: 11, year: 2016 }
    • event.formatted: Date range string: '2016-11-22 - 2016-11-23'
    • event.beginEpoc: Epoc time stamp number: 1479765600
    • event.endEpoc: Epoc time stamp number: 1479852000
  • Example of the dateChanged callback:

    onDateRangeChanged(event:any) {
        console.log('onDateRangeChanged(): Begin date: ', event.beginDate, ' End date: ', event.endDate);
        console.log('onDateRangeChanged(): Formatted: ', event.formatted);
        console.log('onDateRangeChanged(): BeginEpoc timestamp: ', event.beginEpoc, ' - endEpoc timestamp: ', event.endEpoc);
    }

inputFieldChanged callback:

  • called when the value change in the input field, date range is selected or date range is cleared (can be used in validation, returns true or false indicating is date range valid or not in the input field)

  • event parameter:

    • event.value: Value of the input field. For example: '2016-11-22 - 2016-11-23'
    • event.dateRangeFormat: Date range format string. For example: 'yyyy-mm-dd - yyyy-mm-dd'
    • event.valid: Boolean value indicating is the typed value valid. For example: true
  • Example of the input field changed callback:

onInputFieldChanged(event:any) {
  console.log('onInputFieldChanged(): Value: ', event.value, ' - dateRangeFormat: ', event.dateRangeFormat, ' - valid: ', event.valid);
}

calendarViewChanged callback:

  • called when the calendar view change (year or month change)

  • event parameter:

    • event.year: Year number in calendar. For example: 2016
    • event.month: Month number in calendar. For example: 11
    • event.first: First day of selected month and year. Object which contain day number and weekday string. For example: {number: 1, weekday: "tu"}
    • event.last: Last day of selected month and year. Object which contain day number and weekday string. For example: {number: 30, weekday: "we"}
  • values of the weekday property are same as values of the firstDayOfWeek option

  • Example of the calendar view changed callback:

onCalendarViewChanged(event:any) {
  console.log('onCalendarViewChanged(): Year: ', event.year, ' - month: ', event.month, ' - first: ', event.first, ' - last: ', event.last);
}

Change styles of the component

The styles of the component can be changed by overriding the existing styles.

Create a separate stylesheet file which contain the changed styles. Then import the stylesheet file in the place which is after the place where the component is loaded.

The sampleapp of the component contain an example:

Development of this component

  • At first fork and clone this repo.

  • Install all dependencies:

    1. npm install
    2. npm install --global gulp-cli
  • Build dist and npmdist folders and execute tslint:

    1. gulp all
  • Execute unit tests and coverage (output is generated to the test-output folder):

    1. npm test
  • Run sample application:

    1. Open a terminal and type npm start
    2. Open http://localhost:5000 to browser
  • Build a local npm installation package:

    1. gulp all
    2. cd npmdist
    3. npm pack
    • local installation package is created to the npmdist folder. For example: mydaterangepicker-1.0.10.tgz
  • Install the local npm package to your project:

    1. npm install path_to_npmdist/mydaterangepicker-1.0.10.tgz

Demo

Online demo is here

Compatibility (tested with)

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

License

  • License: MIT

Author

  • Author: kekeh