From 59474d2d4eceea34a744a9c2034a0081bff260fb Mon Sep 17 00:00:00 2001 From: MarsiBarsi Date: Thu, 21 Jan 2021 18:55:04 +0300 Subject: [PATCH] feat(cdk, core): `TuiMonthPipe` move from cdk to core, add i18n BREAKING CHANGE: import it from @taiga-ui/core library and use with async pipe --- projects/cdk/date-time/test/time.spec.ts | 2 +- projects/cdk/date-time/time.ts | 2 +- projects/cdk/pipes/index.ts | 1 - projects/cdk/pipes/month/month.pipe.ts | 13 ------ projects/cdk/tokens/index.ts | 1 - projects/cdk/tokens/months.ts | 21 ---------- projects/cdk/tokens/test/tokens.spec.ts | 12 ------ projects/core/pipes/index.ts | 1 + projects/{cdk => core}/pipes/month/index.ts | 0 .../{cdk => core}/pipes/month/month.module.ts | 0 projects/core/pipes/month/month.pipe.ts | 15 +++++++ .../{cdk => core}/pipes/month/package.json | 2 +- projects/core/tokens/i18n.ts | 40 ++++++++----------- 13 files changed, 35 insertions(+), 75 deletions(-) delete mode 100644 projects/cdk/pipes/month/month.pipe.ts delete mode 100644 projects/cdk/tokens/months.ts delete mode 100644 projects/cdk/tokens/test/tokens.spec.ts rename projects/{cdk => core}/pipes/month/index.ts (100%) rename projects/{cdk => core}/pipes/month/month.module.ts (100%) create mode 100644 projects/core/pipes/month/month.pipe.ts rename projects/{cdk => core}/pipes/month/package.json (97%) diff --git a/projects/cdk/date-time/test/time.spec.ts b/projects/cdk/date-time/test/time.spec.ts index 3393db3fe4f3..91e362046b5e 100644 --- a/projects/cdk/date-time/test/time.spec.ts +++ b/projects/cdk/date-time/test/time.spec.ts @@ -349,6 +349,6 @@ describe('TuiTime', () => { it('stringify and fill zeros for seconds and ms', () => { const time = new TuiTime(6, 36, 0, 0); - expect(time.toString('HH:MM:SS.MS')).toBe('06:36:00.000'); + expect(time.toString('HH:MM:SS.MSS')).toBe('06:36:00.000'); }); }); diff --git a/projects/cdk/date-time/time.ts b/projects/cdk/date-time/time.ts index e0f86b1a33d7..5135357490f2 100644 --- a/projects/cdk/date-time/time.ts +++ b/projects/cdk/date-time/time.ts @@ -63,7 +63,7 @@ export class TuiTime implements TuiTimeLike { * Converts TuiTime to string */ toString(mode?: TuiTimeMode): string { - const needAddMs = mode === 'HH:MM:SS.MS' || (!mode && this.ms > 0); + const needAddMs = mode === 'HH:MM:SS.MSS' || (!mode && this.ms > 0); const needAddSeconds = needAddMs || mode === 'HH:MM:SS' || (!mode && this.seconds > 0); diff --git a/projects/cdk/pipes/index.ts b/projects/cdk/pipes/index.ts index 3f7a79b4250d..bb875260613c 100644 --- a/projects/cdk/pipes/index.ts +++ b/projects/cdk/pipes/index.ts @@ -1,3 +1,2 @@ export * from '@taiga-ui/cdk/pipes/filter'; export * from '@taiga-ui/cdk/pipes/mapper'; -export * from '@taiga-ui/cdk/pipes/month'; diff --git a/projects/cdk/pipes/month/month.pipe.ts b/projects/cdk/pipes/month/month.pipe.ts deleted file mode 100644 index b5aeb11bb8d7..000000000000 --- a/projects/cdk/pipes/month/month.pipe.ts +++ /dev/null @@ -1,13 +0,0 @@ -import {Inject, Pipe, PipeTransform} from '@angular/core'; -import {TuiMonth} from '@taiga-ui/cdk/date-time'; -import {TUI_MONTHS} from '@taiga-ui/cdk/tokens'; - -// @dynamic -@Pipe({name: 'tuiMonth'}) -export class TuiMonthPipe implements PipeTransform { - constructor(@Inject(TUI_MONTHS) private readonly months: readonly string[]) {} - - transform({month}: TuiMonth): string { - return this.months[month]; - } -} diff --git a/projects/cdk/tokens/index.ts b/projects/cdk/tokens/index.ts index 0698919ab74f..66d33357e9e4 100644 --- a/projects/cdk/tokens/index.ts +++ b/projects/cdk/tokens/index.ts @@ -4,5 +4,4 @@ export * from './focusable-item-accessor'; export * from './is-android'; export * from './is-ios'; export * from './is-mobile'; -export * from './months'; export * from './sanitizer'; diff --git a/projects/cdk/tokens/months.ts b/projects/cdk/tokens/months.ts deleted file mode 100644 index 83d5ed22bead..000000000000 --- a/projects/cdk/tokens/months.ts +++ /dev/null @@ -1,21 +0,0 @@ -import {InjectionToken} from '@angular/core'; - -// prettier-ignore -type MONTHS_ARRAY = [string, string, string, string, string, string, string, string, string, string, string, string]; - -export const TUI_MONTHS = new InjectionToken('Localized months names', { - factory: () => [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December', - ], -}); diff --git a/projects/cdk/tokens/test/tokens.spec.ts b/projects/cdk/tokens/test/tokens.spec.ts deleted file mode 100644 index c146d410cb6a..000000000000 --- a/projects/cdk/tokens/test/tokens.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {TestBed} from '@angular/core/testing'; -import {TUI_MONTHS} from '../months'; - -describe('Tokens', () => { - it('months token factory returns array of months', () => { - TestBed.configureTestingModule({}); - - const months = TestBed.inject(TUI_MONTHS); - - expect(Array.isArray(months)).toBeTruthy(); - }); -}); diff --git a/projects/core/pipes/index.ts b/projects/core/pipes/index.ts index 14d74d0b0ceb..a5ca5bf54121 100644 --- a/projects/core/pipes/index.ts +++ b/projects/core/pipes/index.ts @@ -1,3 +1,4 @@ export * from '@taiga-ui/core/pipes/format-number'; export * from '@taiga-ui/core/pipes/format-phone'; +export * from '@taiga-ui/core/pipes/month'; export * from '@taiga-ui/core/pipes/pluralize'; diff --git a/projects/cdk/pipes/month/index.ts b/projects/core/pipes/month/index.ts similarity index 100% rename from projects/cdk/pipes/month/index.ts rename to projects/core/pipes/month/index.ts diff --git a/projects/cdk/pipes/month/month.module.ts b/projects/core/pipes/month/month.module.ts similarity index 100% rename from projects/cdk/pipes/month/month.module.ts rename to projects/core/pipes/month/month.module.ts diff --git a/projects/core/pipes/month/month.pipe.ts b/projects/core/pipes/month/month.pipe.ts new file mode 100644 index 000000000000..9f6ec3543993 --- /dev/null +++ b/projects/core/pipes/month/month.pipe.ts @@ -0,0 +1,15 @@ +import {Inject, Pipe, PipeTransform} from '@angular/core'; +import {TuiMonth} from '@taiga-ui/cdk/date-time'; +import {TUI_MONTHS} from '@taiga-ui/core/tokens'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; + +// @dynamic +@Pipe({name: 'tuiMonth'}) +export class TuiMonthPipe implements PipeTransform { + constructor(@Inject(TUI_MONTHS) private readonly months$: Observable) {} + + transform({month}: TuiMonth): Observable { + return this.months$.pipe(map(months => months[month])); + } +} diff --git a/projects/cdk/pipes/month/package.json b/projects/core/pipes/month/package.json similarity index 97% rename from projects/cdk/pipes/month/package.json rename to projects/core/pipes/month/package.json index cdd9e35f1143..289d2d373a50 100644 --- a/projects/cdk/pipes/month/package.json +++ b/projects/core/pipes/month/package.json @@ -4,4 +4,4 @@ "entryFile": "index.ts" } } -} \ No newline at end of file +} diff --git a/projects/core/tokens/i18n.ts b/projects/core/tokens/i18n.ts index c903dae2fd88..3e2d4d025a13 100644 --- a/projects/core/tokens/i18n.ts +++ b/projects/core/tokens/i18n.ts @@ -1,37 +1,29 @@ import {InjectionToken} from '@angular/core'; +import {extractI18n} from '@taiga-ui/i18n'; -export const TUI_CLOSE_WORD = new InjectionToken(`i18n 'close' word`, { - factory: () => 'Close', +export const TUI_MONTHS = new InjectionToken('Localized months names', { + factory: extractI18n('months'), }); -export const TUI_NOTHING_FOUND_MESSAGE = new InjectionToken( +export const TUI_CLOSE_WORD = new InjectionToken(`i18n 'close' word`, { + factory: extractI18n('close'), +}); + +export const TUI_NOTHING_FOUND_MESSAGE = new InjectionToken( `i18n 'Nothing found' message`, { - factory: () => 'Nothing found', + factory: extractI18n('nothingFoundMessage'), }, ); -export const TUI_DEFAULT_ERROR_MESSAGE = new InjectionToken( - `i18n of error message`, - { - factory: () => 'Value is invalid', - }, -); +export const TUI_DEFAULT_ERROR_MESSAGE = new InjectionToken(`i18n of error message`, { + factory: extractI18n('defaultErrorMessage'), +}); -/** - * Works with a tuple - * [@string word 'previous', @string word 'next'] - */ -export const TUI_SPIN_TEXTS = new InjectionToken<[string, string]>('spin i18n texts', { - factory: () => ['Previous', 'Next'], +export const TUI_SPIN_TEXTS = new InjectionToken('spin i18n texts', { + factory: extractI18n('spinTexts'), }); -/** - * Tuple with short days of week - * starts with Mon (Monday) - */ -export const TUI_SHORT_WEEK_DAYS = new InjectionToken< - [string, string, string, string, string, string, string] ->('calendars i18n texts', { - factory: () => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], +export const TUI_SHORT_WEEK_DAYS = new InjectionToken('calendars i18n texts', { + factory: extractI18n('shortWeekDays'), });