19.0.0 • Published 8 months ago

ngx-material-date-fns-adapter v19.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Angular material date-fns adapter (Support jalali)

MIT licensed npm version Build Status

What is this?

This library provides a custom DateAdapter for the Angular Material Datepicker component using the date-fns library.

  • Includes all locales provided by date-fns.
  • Supported Jalali calendar for fa-IR locale.

Demo

https://mohsen77sk.github.io/angular-material-date-fns-adapter/

Installing

Install ngx-material-date-fns-adapter

npm install date-fns date-fns-jalali ngx-material-date-fns-adapter

Both date-fns and date-fns-jalali libraries are peer dependencies, but required for the compilation.

Angular Versiondate-fns Versiondate-fns-jalali Versionngx-material-date-fns-adapter Version
^19.0.0>=2.22.0 <5.0>=2.22.0-0 <=5.0.0-0latest
^18.0.0>=2.22.0 <4.0>=2.22.0-0 <=3.6.0-018.0.0
^17.0.0>=2.22.0 <4.0>=2.22.0-0 <=3.6.0-017.0.3
^16.0.0>=2.22.0 <3.0>=2.22.0-0 <=2.30.0-016.0.0
^15.0.0>=2.22.0 <3.0>=2.22.0-0 <=2.30.0-01.0.3
^14.0.0>=2.22.0 <3.0>=2.22.0-0 <=2.30.0-01.0.3

Usage

Provider the provideDateFnsAdapter and Register locale token in providers in your app.config.ts.

import { MAT_DATE_LOCALE } from '@angular/material/core';
import { provideDateFnsAdapter } from 'ngx-material-date-fns-adapter';
import { enUS } from 'date-fns/locale';

export const appConfig: ApplicationConfig = {
  providers: [
    ...,
    provideDateFnsAdapter(),
    { provide: MAT_DATE_LOCALE, useValue: enUS }
  ],
};

Change locale dynamically

Use setLocale() method of the DateAdapter. In case of using setLocale with a Locale argument

import { Component } from '@angular/core';
import { DateAdapter } from '@angular/material/core';
import { enUS, faIR } from 'date-fns/locale';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {

  constructor(private _adapter: DateAdapter<any>) {}

  changeLocale(value: any): void {
    switch (value) {
      case 'en-US':
        this._adapter.setLocale(enUS);
        break;
      case 'fa-IR':
        this._adapter.setLocale(faIR);
        break;
    }
  }
}

Supported locales

See project for details

Development

The most useful commands for development are:

  • npm run start to start a development server
  • npm run build-demo to build the demo locally (it will be published automatically by GitHub Actions)

License

The MIT License (MIT)

19.0.0

8 months ago

18.0.0

1 year ago

17.0.3

1 year ago

17.0.2

1 year ago

17.0.1

1 year ago

17.0.0

1 year ago

16.0.0

1 year ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago