Skip to content

Commit

Permalink
chore: 🔖 Bump version to 11.1.0. Update root README
Browse files Browse the repository at this point in the history
Update version to 11.1.0 from 11.1.0-beta.0 Update README.md in root directory with the latest changes.

#4
  • Loading branch information
sapozhnikovay committed Apr 6, 2021
1 parent 943f325 commit 2c31890
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
export class AppModule {}
```

2. Register custom locale token in providers if needed.
> `providers: [{ provide: MAT_DATE_LOCALE, useValue: 'ja' }],`
2. Register custom locale token in providers if needed. Also register required locales in NGX_MAT_DATEFNS_LOCALES array.
> `providers: [`
> `{ provide: MAT_DATE_LOCALE, useValue: 'ja' },`
> `{ provide: NGX_MAT_DATEFNS_LOCALES, useValue: [ja] }`
> `],`
```typescript
import { NgModule } from "@angular/core";
Expand All @@ -77,6 +80,7 @@ import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
import { da, ja } from 'date-fns/esm/locale'

@NgModule({
declarations: [AppComponent],
Expand All @@ -95,12 +99,53 @@ import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
provide: MAT_DATE_LOCALE,
useValue: "ja",
},
{
provide: NGX_MAT_DATEFNS_LOCALES,
useValue: [da, ja]
}
],
bootstrap: [AppComponent],
})
export class AppModule {}
```

## Default locale

When MAT_DATE_LOCALE and NGX_MAT_DATEFNS_LOCALES tokens are not provided, `en-US` locale is used by default. When empty or null value is provided to the MAT_DATE_LOCALE token, `en-US` locale is also used.

## Change locale dynamically

Use `setLocale()` method of the `DateAdapter`.
In case of using `setLocale` with a string argument, target locale should be imported into NGX_MAT_DATEFNS_LOCALES array.

```typescript
import { Component } from '@angular/core';
import { DateAdapter } from '@angular/material/core';
import { fr } from 'date-fns/esm/locale';

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

constructor(private readonly dateAdapter: DateAdapter<any>) {}

setLocaleWithString(): void {
this.dateAdapter.setLocale('fr');
}

setLocaleWithLocaleObject(): void {
this.dateAdapter.setLocale(fr);
}
}
```

## ES modules and Tree-shaking

Import date-fns locales from 'date-fns/esm/locale' entrypoint. This enables tree-shaking by the Angular builder.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-datefns-date-adapter",
"version": "11.0.3",
"version": "11.1.0",
"scripts": {
"start": "ng serve",
"build": "ng-packagr -p ./projects/ngx-mat-datefns-date-adapter/ng-package.json",
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mat-datefns-date-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mat-datefns-date-adapter",
"version": "11.1.0-beta.0",
"version": "11.1.0",
"description": "",
"author": "Alexey Sapozhnikov",
"license": "MIT",
Expand Down

0 comments on commit 2c31890

Please sign in to comment.