Skip to content

Commit

Permalink
refactor(kit): new version of InputNumber (#10031)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov authored Dec 24, 2024
1 parent 99cb0bc commit a1b748c
Show file tree
Hide file tree
Showing 42 changed files with 1,704 additions and 600 deletions.
12 changes: 12 additions & 0 deletions projects/cdk/classes/value-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import type {FactoryProvider, ProviderToken} from '@angular/core';
import {inject} from '@angular/core';

export abstract class TuiValueTransformer<From, To = unknown> {
public abstract toControlValue(componentValue: From): To;
public abstract fromControlValue(controlValue: To): From;
}

export function tuiValueTransformerFrom<
T extends {valueTransformer: TuiValueTransformer<unknown>},
>(token: ProviderToken<T>): FactoryProvider {
return {
provide: TuiValueTransformer,
useFactory: () => inject(token).valueTransformer,
};
}
33 changes: 15 additions & 18 deletions projects/demo-cypress/src/tests/input-number/dynamic-postfix.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,40 @@ import '@angular/common/locales/global/ru';
import {I18nPluralPipe} from '@angular/common';
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TuiRoot} from '@taiga-ui/core';
import {TuiInputNumberModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy';
import {TuiRoot, TuiTextfield} from '@taiga-ui/core';
import {TuiInputNumber} from '@taiga-ui/kit';

@Component({
standalone: true,
imports: [
FormsModule,
I18nPluralPipe,
TuiInputNumberModule,
TuiRoot,
TuiTextfieldControllerModule,
],
imports: [FormsModule, I18nPluralPipe, TuiInputNumber, TuiRoot, TuiTextfield],
template: `
<tui-root>
<tui-input-number
[tuiTextfieldPostfix]="value | i18nPlural: pluralMap : 'ru-RU'"
[(ngModel)]="value"
></tui-input-number>
<tui-textfield>
<input
tuiInputNumber
[postfix]="value | i18nPlural: pluralMap : 'ru-RU'"
[(ngModel)]="value"
/>
</tui-textfield>
</tui-root>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TestInputNumberWithPostfix {
protected value: number | null = null;
protected pluralMap = {
one: 'секунда',
few: 'секунды',
many: 'секунд',
other: 'секунды',
one: ' секунда',
few: ' секунды',
many: ' секунд',
other: ' секунды',
};
}

describe('InputNumber with dynamic postfix', () => {
describe('Plural forms of seconds (locale ru-RU)', () => {
beforeEach(() => {
cy.mount(TestInputNumberWithPostfix);
cy.get('tui-input-number input').as('textfield');
cy.get('[tuiInputNumber]').as('textfield');
});

const withPostfix = (
Expand Down
Loading

0 comments on commit a1b748c

Please sign in to comment.