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

ngx-gaewynn-datepicker

v2.1.0

Published

A simple wrapper around the Material Angular Datepicker allowing to update the date format at runtime

Downloads

4

Readme

An Angular Material Component wrapping the Angular Material Datepicker and allowing

  • to update the date formats at runtime and instantly (see this issue and this issue)
  • to use different formats for each DatePicker

Support - Angular 15+ (Reactive Forms) Request - on github

Disclaimer

This component relies on a hack consisting of the modification of a private field within the Angular Material DatePicker component. Be aware that a breaking change could happen on any future update from the Angular Material team

Table of contents

Browser support

| IE / Edge| Firefox| Chrome | Safari| Opera| |--|--|--|--|--| |IE11, Edge|latest|latest|latest|latest|

Features

Now:

  • Angular 15 Support
  • All features from the native Angular Material DatePicker.....and one more
  • Update your DatePicker date formats at runtime (including the calendar popup labels)
  • Support only MomentDateAdapter
  • Support DateRangePicker

What's next?

Demo

NgxGaewynnDatePicker demo

Installation

ngx-gaewynn-datepicker is available via npm and yarn

Using npm:

$ npm install ngx-gaewynn-datepicker --save

Using yarn:

$ yarn add ngx-gaewynn-datepicker

Using angular-cli:

$ ng add ngx-gaewynn-datepicker

What's in?

|Member|Description| |--|--| |NgxGaewynnDatePickerModule|The module handling DatePickers. To import in each module using the component| |NgxGaewynnDateRangePickerModule|The module handling DateRangePickers. To import in each module using the component| |NgxGaewynnDatePickerService|A service allowing to manage the date pickers formats and the configuration| |NGX_GAEWYNN_DATEPICKER_CONFIGURATION|A token providing your formats configuration|

NGX_GAEWYNN_DATEPICKER_CONFIGURATION consists of two properties:

  • initials: represents a collection of links between a datepicker (or date range picker) and the locale it will use
[
	// All components with a group binding set to "group1" will be initialized using the format name "format-1" defined in the NGX_GAEWYNN_DATEPICKER_CONFIGURATION
	{ group: "group1", format: "format-1" },

	// All components with a group binding set to "group2" will be initialized using the format name "format-2" defined in the NGX_GAEWYNN_DATEPICKER_CONFIGURATION
	{ group: "group2", format: "format-2" }
]
  • formats: represents the formats to use for each locale of your application
[
	// Formats that will be used when updating to "format-1"
	{
		format: "format-1",
		locale: "fr",
		momentDateFormats: {
			parse: {
				dateInput: "DD.MM.YYYY",
			},
			display: {
				dateInput: "DD.MM.YYYY",
				monthYearLabel: "MMM.YYYY",
				dateA11yLabel: "DD.MM.YYYY",
				monthYearA11yLabel: "MMM.YYYY",
			}
		}
	}, 
	// Formats that will be used when updating to "format-2"
	{
		format: "format-2",
		locale: "en",
		momentDateFormats: {
			parse: {
				dateInput: "YYYY-MM-DD",
			},
			display: {
				dateInput: "YYYY-MM-DD",
				monthYearLabel: "MMM/YYYY",
				dateA11yLabel: "YYYY-MM-DD",
				monthYearA11yLabel: "MMM/YYYY",
			}
		}
	}
]

An example of a whole configuration will then be as follow:

export  const  GaewynnDatePickerConfiguration: NgxGaewynnDatePickerConfiguration= {
	initials: [{ group: "group1", format: "format-1" }, { group: "group2", format: "format-2" }],
	formats: [{
		format: "format-1",
		locale: "fr",
		momentDateFormats: {
			parse: {
				dateInput: "DD.MM.YYYY",
			},
			display: {
				dateInput: "DD.MM.YYYY",
				monthYearLabel: "MMM.YYYY",
				dateA11yLabel: "DD.MM.YYYY",
				monthYearA11yLabel: "MMM.YYYY",
			}
		}
	}, {
		format: "format-2",
		locale: "en",
		momentDateFormats: {
			parse: {
				dateInput: "YYYY-MM-DD",
			},
			display: {
				dateInput: "YYYY-MM-DD",
				monthYearLabel: "MMM/YYYY",
				dateA11yLabel: "YYYY-MM-DD",
				monthYearA11yLabel: "MMM/YYYY",
			}
		}
	}]
};

Usage

NgxGaewynnDatePicker is only a wrapper around the Angular Material Datepicker, so just wrap your Angular Material Datepicker inside the <ngx-gaewynn-datepicker> or the <ngx-gaewynn-date-range-picker>.

It relies on ReactiveForms, so needs to be included in a FormGroup

Basic usage

  1. Inject the NgxGaewynnDatePickerModule (and/or the NgxGaewynnDateRangePickerModule) in each modules using the component and define a configuration for your datepickers (see What's in?). This configuration will be provided using the NGX_GAEWYNN_DATEPICKER_CONFIGURATION token in your AppModule
// ...  
import { NgxGaewynnDatePickerModule, NgxGaewynnDateRangePickerModule, NGX_GAEWYNN_DATEPICKER_CONFIGURATION } from  'NgxGaewynnDatePicker';
        
@NgModule({      
	imports: [
		// ...     		
		NgxGaewynnDatePickerModule,
		NgxGaewynnDateRangePickerModule
	],
	providers: [
		// ...
		// GaewynnDatePickerConfiguration is the configuration as described
		// You can use "useFactory" or "useClass" to provide the configuration
		{ provide: NGX_GAEWYNN_DATEPICKER_CONFIGURATION, useValue: GaewynnDatePickerConfiguration}
	]
})
export class AppModule { }
  1. Add the <ngx-gaewynn-datepicker> and/or the <ngx-gaewynn-date-range-picker> to your template
<div [formGroup]="ngxGaewynnDatePickerForm">
	<!-- the [group] binding indicate which format will be used for this datepicker (see "What's in?" -->
	<ngx-gaewynn-datepicker [group]="'group1'">
		<mat-form-field appearance="fill">
			<mat-label>{{ Your hint }}</mat-label>
			<input  matInput [formControl]="customDateFormControl" [matDatepicker]="picker">
			<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
			<mat-datepicker #picker></mat-datepicker>
		</mat-form-field>
	</ngx-gaewynn-datepicker>

	<!-- For a DateRangePicker -->
	<ngx-gaewynn-date-range-picker  [group]="'group1'">
		<mat-form-field  appearance="fill">
			<mat-label>{{ mockService.getRangePlaceholder(1) }}</mat-label>
			<mat-date-range-input  [rangePicker]="rangePicker1">
				<input  matStartDate  [formControl]="customRangeDateFromFormControl1"  placeholder="Start date">
				<input  matEndDate  [formControl]="customRangeDateToFormControl1"  placeholder="End date">
			</mat-date-range-input>
			<mat-hint>{{ mockService.hintGroup1 }} – {{ mockService.hintGroup1 }}</mat-hint>
			<mat-datepicker-toggle  matIconSuffix  [for]="rangePicker1"></mat-datepicker-toggle>
			<mat-date-range-picker  #rangePicker1></mat-date-range-picker>
		</mat-form-field>
	</ngx-gaewynn-date-range-picker>
</div>
  1. Inject the NgxGaewynnDatePickerService in each component using the <ngx-gaewynn-datepicker> (or the <ngx-gaewynn-date-range-picker>) component and call the function "init()" to initialize all datepickers with their initials formats
@Component({
	selector: 'app-root',
	templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {

	constructor(private readonly _ngxGaewynnDatePickerService: NgxGaewynnDatePickerService) { }

	public ngOnInit(): void {
		this._ngxGaewynnDatePickerService.init();
	}
}
  1. Trigger the update of your format whenever you want
@Component({
	selector: 'app-root',
	templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {

	constructor(private readonly _ngxGaewynnDatePickerService: NgxGaewynnDatePickerService) { }

	public ngOnInit(): void {
		this._ngxGaewynnDatePickerService.init();
	}

	public updateFormats(): void {

		// This will apply the format named "format-2" in your 
		// NGX_GAEWYNN_DATEPICKER_CONFIGURATION on all datepickers binded to "group1"
		this._ngxGaewynnDatePickerService.updateFormats("format-2", "group1");
	}
}

Advanced usage

In more complex scenarios, it could happen that using the NGX_GAEWYNN_DATEPICKER_CONFIGURATION at the application startup as a provider is not a solution. In such cases, you can initialize the configuration programmatically using the NgxGaewynnDatePickerService and the functions "initConfiguration()" and "addFormat()".

Versioning

ngx-gaewynn-datepicker will be maintained under the Semantic Versioning guidelines. Releases will be numbered with the following format:

<major>.<minor>.<patch>

For more information on SemVer, please visit http://semver.org.

Creator

Arnaud Fischer

Credits

License

ngx-gaewynn-datepicker is MIT licensed.