GithubHelp home page GithubHelp logo

mohsen77sk / angular-material-date-fns-adapter Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 0.0 3.26 MB

Angular material date-fns adapter (Support jalali)

License: MIT License

TypeScript 76.57% HTML 13.59% SCSS 9.84%
angular angular-material date-fns date-fns-jalali jalali shamsi

angular-material-date-fns-adapter's Introduction

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

Angular version 17.x.x

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

Angular version 16.x.x

Angular version 15.x.x or 14.x.x

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

Usage

  1. Provider the provideDateFnsAdapter in your app.config.ts.

    import { provideDateFnsAdapter } from 'ngx-material-date-fns-adapter';
    
    export const appConfig: ApplicationConfig = {
      providers: [..., provideDateFnsAdapter()],
    };
  2. Register custom locale token in providers if needed.

    import { MAT_DATE_LOCALE } from "@angular/material/core";
    import { fr } from 'date-fns/locale';
    
    export const appConfig: ApplicationConfig = {
      providers: [..., { provide: MAT_DATE_LOCALE, useValue: fr }],
    };

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;
    }
  }
}

Default locale

When MAT_DATE_LOCALE tokens are not provided, en-US locale is used by default.

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)

angular-material-date-fns-adapter's People

Contributors

mohsen77sk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

angular-material-date-fns-adapter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.