Skip to content

Commit

Permalink
feat(cdk, core): TuiMonthPipe move from cdk to core, add i18n
Browse files Browse the repository at this point in the history
BREAKING CHANGE: import it from @taiga-ui/core library and use with async pipe
  • Loading branch information
MarsiBarsi committed Jan 21, 2021
1 parent 4e75649 commit 59474d2
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 75 deletions.
2 changes: 1 addition & 1 deletion projects/cdk/date-time/test/time.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion projects/cdk/date-time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion projects/cdk/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -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';
13 changes: 0 additions & 13 deletions projects/cdk/pipes/month/month.pipe.ts

This file was deleted.

1 change: 0 additions & 1 deletion projects/cdk/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
21 changes: 0 additions & 21 deletions projects/cdk/tokens/months.ts

This file was deleted.

12 changes: 0 additions & 12 deletions projects/cdk/tokens/test/tokens.spec.ts

This file was deleted.

1 change: 1 addition & 0 deletions projects/core/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -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';
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions projects/core/pipes/month/month.pipe.ts
Original file line number Diff line number Diff line change
@@ -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<string[]>) {}

transform({month}: TuiMonth): Observable<string> {
return this.months$.pipe(map(months => months[month]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"entryFile": "index.ts"
}
}
}
}
40 changes: 16 additions & 24 deletions projects/core/tokens/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
import {InjectionToken} from '@angular/core';
import {extractI18n} from '@taiga-ui/i18n';

export const TUI_CLOSE_WORD = new InjectionToken<string>(`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<string>(
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<string>(
`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'),
});

0 comments on commit 59474d2

Please sign in to comment.