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

angular-fk-datepicker

v2.0.0

Published

Angular 2 datepicker

Downloads

8

Readme

NPM Version

angular-fk-datepicker

This library is a fully Angular 2 datepicker.

Click here for a demo.

Install

npm install angular-fk-datepicker

Usage

The library has two main component, the main one is obviously the datepicker itself. The second one is the input of the datepicker. By separating the two, you are able to use the datepicker in any way you want. It's not dependant on the input text.

The input can take a DateFormatter, it's an interface that has format function which takes a Date and returns a string. By default, the formatter used does Date#toLocaleString. For example, you can pass your own formatter which uses moment for advanced formatting.

A word on styling

By default the style uses Bootstrap 3. It supports basic custom classes to apply custom styles. See DatePickerCustomClasses.

import { NgModule } from '@angular/core';
import { FkDatePickerModule } from 'angular-fk-datepicker';

@NgModule({
    imports: [FkDatePickerModule]
})
export class ModuleWithoutConfig {}

@NgModule({
    imports: [
        FkDatePickerModule.withConfig({
            initialDate: new Date(2016, 08, 27)
        });
    ]
})
export class ModuleWithConfig {}

In one of your component:


<fk-datepicker-input [formatter]="customFormatter">
    <fk-datepicker 
        [initialDate]="initialDate"
        [minDate]="minDate"
        [maxDate]="maxDate"
        firstDayOfWeek="mo">
    </fk-datepicker>
</fk-datepicker-input>

Documentation

DatePickerComponent

Properties

  • initialDate (Date): The initial date selected by the datepicker. Default value is new Date().
  • minDate (Date): The minimum date that the datepicker can select. No default value.
  • maxDate (Date): The maximum date that the datepicker can select. No default value.
  • firstDayOfWeek (string): The initial date selected by the datepicker. Default value is su (sunday).
  • monthLabels (MonthLabels): The labels for the months. Default values are the english months.
  • dayLabels (DayLabels): The labels for the days. Default values are the english days.
  • customClasses (DatePickerCustomClasses): Custom classes for the datepicker elements. See defaults below.
  • closeOnClickAway (boolean): Close the datepicker when clicking away. Default is true.
  • useConfig (boolean): Since 1.2.0, you can set it to false to ignore global configuration object.

Events

  • selection (Date): Event fired when a new date is selected. The event is fired a first time when the datepicker is created.
  • toggle (boolean): Event fired when the datepicker is opened or closed. True if open, false if closed.

FormControlName

The datepicker supports the formControlName directive. Just set formControlName with the name of your control like any other control. If a value is already present in the control, it will set it as initial value. When the value is updated the control is also updated and set to dirty. It is set to touched as soon as the datepicker is closed.

NgModel

The datepicker also supports NgModel, which is the alternative to FormControlName.

DatePickerCustomClasses

The interface for the custom classes is:

export interface DatePickerCustomClasses {
    mergeWithDefaults?: boolean;
    table?: string;
    headerRow?: string;
    dayLabelsRow?: string;
    month?: string;
    year?: string;
    previousIcon?: string;
    nextIcon?: string;
}

The defaults are:

export const defaultClasses: DatePickerCustomClasses = {
    table: 'calendar',
    previousIcon: 'glyphicon glyphicon-chevron-left',
    nextIcon: 'glyphicon glyphicon-chevron-right',
    headerRow: 'months-header',
    dayLabelsRow: 'days-header',
    month: 'month',
    year: 'year'
};

If you set mergeWithDefaults to true, it will override the defaults, otherwise it will not take any default values. If you change the table class, don't forget to add the styles for the selected day, etc. See the default styles in the datepicker.component.ts file.

DatePickerInputComponent

Properties

  • formatter (DateFormatter): The date formatter that transforms the date to a custom format for the input.
  • customClasses (string): Custom classes for the input. Default is form-control

DateFormatter

Implement this interface to create your custom formatter;

export interface DateFormatter {
    format (date: Date): string;
}

MonthLabels

Create an object that implements this interface to pass your custom label names.

import { MonthLabels } from 'angular-fk-datepicker';
export interface MonthLabels {
    ['1']: string;
    ['2']: string;
    ['3']: string;
    ['4']: string;
    ['5']: string;
    ['6']: string;
    ['7']: string;
    ['8']: string;
    ['9']: string;
    ['10']: string;
    ['11']: string;
    ['12']: string;
}

DayLabels

Create an object that implements this interface to pass your custom label names.

import { DayLabels } from 'angular-fk-datepicker';
export interface DayLabels {
    su: string;
    mo: string;
    tu: string;
    we: string;
    th: string;
    fr: string;
    sa: string;
}

Global configuration object

It's possible since 1.2.0 to configure the datepicker with a global configuration object.

The configuration interface is FkDatePickerConfig:

export interface FkDatePickerConfig {
    minDate?: Date;
    maxDate?: Date;
    initialDate?: Date;
    monthLabels?: MonthLabels;
    dayLabels?: DayLabels;
    firstDayOfWeek?: FirstDayOfWeek;
    formatter: DateFormatter; // Since 1.3.2
}

How this works:

  • If the value is passed by data-binding, it will override the configuration.
  • If useConfig is set to true (which is the default), the datepicker will look for the value in the configuration object.
  • If the value is absent, it will set the default, for example, date of day for initialDate.

License

The MIT License (MIT)

Copyright (c) 2016 Florian Knop