>) =>
+ lang.pipe(
+ switchMap(lang => lang),
+ map(({name}) => ({
+ ...TUI_DEFAULT_DATE_FORMAT,
+ mode: name === 'english' ? 'MDY' : 'DMY',
+ separator: name === 'english' ? '/' : '.',
+ })),
+ ),
+ },
+ ],
+})
+export default class ExampleComponent {
+ protected readonly testForm = new FormGroup({
+ testValue: new FormControl(new TuiDay(2017, 0, 15)),
+ });
+}
diff --git a/projects/demo/src/modules/components/input-date/examples/import/declare-form.md b/projects/demo/src/modules/components/input-date/examples/import/declare-form.md
deleted file mode 100644
index f301bf2024e9..000000000000
--- a/projects/demo/src/modules/components/input-date/examples/import/declare-form.md
+++ /dev/null
@@ -1,12 +0,0 @@
-```ts
-import {FormControl, FormGroup} from '@angular/forms';
-
-@Component({
- // ...
-})
-export class MyComponent {
- testForm = new FormGroup({
- testValue: new FormControl(),
- });
-}
-```
diff --git a/projects/demo/src/modules/components/input-date/examples/import/import-module.md b/projects/demo/src/modules/components/input-date/examples/import/import.md
similarity index 76%
rename from projects/demo/src/modules/components/input-date/examples/import/import-module.md
rename to projects/demo/src/modules/components/input-date/examples/import/import.md
index 8cdbc4a3936f..2cbf17d0193d 100644
--- a/projects/demo/src/modules/components/input-date/examples/import/import-module.md
+++ b/projects/demo/src/modules/components/input-date/examples/import/import.md
@@ -2,7 +2,8 @@
import {ReactiveFormsModule} from '@angular/forms';
import {TuiInputDateModule} from '@taiga-ui/kit';
-@NgModule({
+@Component({
+ standalone: true,
imports: [
// ...
ReactiveFormsModule,
@@ -10,5 +11,5 @@ import {TuiInputDateModule} from '@taiga-ui/kit';
],
// ...
})
-export class MyModule {}
+export class MyComponent {}
```
diff --git a/projects/demo/src/modules/components/input-date/examples/import/insert-template.md b/projects/demo/src/modules/components/input-date/examples/import/template.md
similarity index 100%
rename from projects/demo/src/modules/components/input-date/examples/import/insert-template.md
rename to projects/demo/src/modules/components/input-date/examples/import/template.md
diff --git a/projects/demo/src/modules/components/input-date/input-date.template.html b/projects/demo/src/modules/components/input-date/index.html
similarity index 77%
rename from projects/demo/src/modules/components/input-date/input-date.template.html
rename to projects/demo/src/modules/components/input-date/index.html
index a546a932f730..58a6f655641c 100644
--- a/projects/demo/src/modules/components/input-date/input-date.template.html
+++ b/projects/demo/src/modules/components/input-date/index.html
@@ -9,21 +9,18 @@
– input with a calendar.
- DI-tokens for date localization:
-
- -
-
TUI_DATE_FORMAT
-
- -
- active date format (
-
'DMY' | 'MDY' | 'YMD'
- ).
-
- -
-
TUI_DATE_SEPARATOR
-
- - single-character date's separator (dot, slash etc.).
-
+
+ Date formatting can be customized with
+
+ TUI_DATE_FORMAT
+
+ token.
+
+
DI-tokens for input-configurations:
-
-
+ [component]="1 | tuiComponent"
+ [content]="1 | tuiExample: 'html,ts'"
+ />
-
-
+ [component]="2 | tuiComponent"
+ [content]="2 | tuiExample: 'html,ts'"
+ />
-
-
+ [component]="3 | tuiComponent"
+ [content]="3 | tuiExample: 'html,ts'"
+ />
-
-
+ [component]="4 | tuiComponent"
+ [content]="4 | tuiExample: 'html,ts'"
+ />
-
-
+ />
-
-
+ [component]="6 | tuiComponent"
+ [content]="6 | tuiExample: 'html,ts'"
+ />
+
+
@@ -246,46 +244,6 @@ DI-tokens for input-configurations:
tui-root
-
-
- -
-
- Import an Angular module for forms and
- TuiInputDateModule
- in the same module where you want to use our component:
-
-
-
-
-
- -
-
- Declare a form (
- FormGroup
- ) or a control (
- FormControl
- ) in your component:
-
-
-
-
-
- -
- Use
-
TuiInputDate
- in template:
-
-
-
-
+
diff --git a/projects/demo/src/modules/components/input-date/input-date.component.ts b/projects/demo/src/modules/components/input-date/index.ts
similarity index 60%
rename from projects/demo/src/modules/components/input-date/input-date.component.ts
rename to projects/demo/src/modules/components/input-date/index.ts
index cbc575f79db0..d7c50126e254 100644
--- a/projects/demo/src/modules/components/input-date/input-date.component.ts
+++ b/projects/demo/src/modules/components/input-date/index.ts
@@ -1,61 +1,57 @@
import {Component, forwardRef} from '@angular/core';
-import {FormControl, Validators} from '@angular/forms';
+import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms';
+import {RouterLink} from '@angular/router';
import {changeDetection} from '@demo/emulate/change-detection';
+import {TuiDemoModule} from '@demo/utils';
import type {TuiDocExample} from '@taiga-ui/addon-doc';
+import {TuiMobileCalendarDialogModule} from '@taiga-ui/addon-mobile';
import type {TuiBooleanHandler} from '@taiga-ui/cdk';
import {TUI_FALSE_HANDLER, TUI_FIRST_DAY, TUI_LAST_DAY, TuiDay} from '@taiga-ui/cdk';
import type {TuiMarkerHandler} from '@taiga-ui/core';
-import {TUI_DEFAULT_MARKER_HANDLER} from '@taiga-ui/core';
-import {TuiNamedDay} from '@taiga-ui/kit';
+import {
+ TUI_DEFAULT_MARKER_HANDLER,
+ TuiDropdownModule,
+ TuiHintModule,
+ TuiLinkModule,
+ TuiTextfieldControllerModule,
+} from '@taiga-ui/core';
+import {TuiInputDateModule, TuiNamedDay} from '@taiga-ui/kit';
import {AbstractExampleTuiControl} from '../abstract/control';
import {ABSTRACT_PROPS_ACCESSOR} from '../abstract/inherited-documentation/abstract-props-accessor';
+import {InheritedDocumentationModule} from '../abstract/inherited-documentation/inherited-documentation.module';
const TWO_DOTS: [string, string] = ['var(--tui-primary)', 'var(--tui-info-fill)'];
const ONE_DOT: [string] = ['var(--tui-success-fill)'];
@Component({
- selector: 'example-tui-input-date',
- templateUrl: './input-date.template.html',
+ standalone: true,
+ imports: [
+ TuiDemoModule,
+ TuiInputDateModule,
+ TuiTextfieldControllerModule,
+ TuiMobileCalendarDialogModule,
+ TuiDropdownModule,
+ TuiHintModule,
+ TuiLinkModule,
+ ReactiveFormsModule,
+ InheritedDocumentationModule,
+ RouterLink,
+ ],
+ templateUrl: './index.html',
changeDetection,
providers: [
{
provide: ABSTRACT_PROPS_ACCESSOR,
- useExisting: forwardRef(() => ExampleTuiInputDateComponent),
+ useExisting: forwardRef(() => ExampleComponent),
},
],
})
-export class ExampleTuiInputDateComponent extends AbstractExampleTuiControl {
+export default class ExampleComponent extends AbstractExampleTuiControl {
public override cleaner = false;
public control = new FormControl(null, Validators.required);
- protected readonly exampleForm = import('./examples/import/declare-form.md?raw');
-
- protected readonly exampleModule = import('./examples/import/import-module.md?raw');
-
- protected readonly exampleHtml = import('./examples/import/insert-template.md?raw');
-
- protected readonly example1: TuiDocExample = {
- TypeScript: import('./examples/1/index.ts?raw'),
- HTML: import('./examples/1/index.html?raw'),
- };
-
- protected readonly example2: TuiDocExample = {
- TypeScript: import('./examples/2/index.ts?raw'),
- HTML: import('./examples/2/index.html?raw'),
- };
-
- protected readonly example3: TuiDocExample = {
- TypeScript: import('./examples/3/index.ts?raw'),
- HTML: import('./examples/3/index.html?raw'),
- };
-
- protected readonly example4: TuiDocExample = {
- TypeScript: import('./examples/4/index.ts?raw'),
- HTML: import('./examples/4/index.html?raw'),
- };
-
protected readonly example5: TuiDocExample = {
TypeScript: import('./examples/5/index.ts?raw'),
HTML: import('./examples/5/index.html?raw'),
@@ -64,11 +60,6 @@ export class ExampleTuiInputDateComponent extends AbstractExampleTuiControl {
),
};
- protected readonly example6: TuiDocExample = {
- TypeScript: import('./examples/6/index.ts?raw'),
- HTML: import('./examples/6/index.html?raw'),
- };
-
protected minVariants = [
TUI_FIRST_DAY,
new TuiDay(2017, 2, 5),
diff --git a/projects/demo/src/modules/components/input-date/input-date.module.ts b/projects/demo/src/modules/components/input-date/input-date.module.ts
deleted file mode 100644
index a9fc4e7278f1..000000000000
--- a/projects/demo/src/modules/components/input-date/input-date.module.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import {CommonModule} from '@angular/common';
-import {NgModule} from '@angular/core';
-import {FormsModule, ReactiveFormsModule} from '@angular/forms';
-import {RouterModule} from '@angular/router';
-import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
-import {TuiMobileCalendarDialogModule} from '@taiga-ui/addon-mobile';
-import {
- TuiButtonModule,
- TuiDropdownModule,
- TuiErrorModule,
- TuiHintModule,
- TuiLinkModule,
- TuiNotificationModule,
- TuiTextfieldControllerModule,
-} from '@taiga-ui/core';
-import {
- TuiFieldErrorPipeModule,
- TuiInputDateModule,
- TuiRadioListModule,
- TuiUnfinishedValidatorModule,
-} from '@taiga-ui/kit';
-
-import {InheritedDocumentationModule} from '../abstract/inherited-documentation/inherited-documentation.module';
-import {TuiInputDateExample1} from './examples/1';
-import {TuiInputDateExample2} from './examples/2';
-import {TuiInputDateExample3} from './examples/3';
-import {TuiInputDateExample4} from './examples/4';
-import {TuiInputDateExample5} from './examples/5';
-import {ExampleNativeDateTransformerDirective} from './examples/5/native-date-transformer.directive';
-import {TuiInputDateExample6} from './examples/6';
-import {ExampleTuiInputDateComponent} from './input-date.component';
-
-@NgModule({
- imports: [
- TuiAddonDocModule,
- InheritedDocumentationModule,
- ReactiveFormsModule,
- FormsModule,
- CommonModule,
- TuiLinkModule,
- TuiRadioListModule,
- TuiButtonModule,
- TuiInputDateModule,
- TuiMobileCalendarDialogModule,
- TuiUnfinishedValidatorModule,
- TuiTextfieldControllerModule,
- TuiHintModule,
- TuiErrorModule,
- TuiFieldErrorPipeModule,
- TuiNotificationModule,
- RouterModule.forChild(tuiGenerateRoutes(ExampleTuiInputDateComponent)),
- TuiDropdownModule,
- ],
- declarations: [
- ExampleTuiInputDateComponent,
- TuiInputDateExample1,
- TuiInputDateExample2,
- TuiInputDateExample3,
- TuiInputDateExample4,
- TuiInputDateExample5,
- TuiInputDateExample6,
- ExampleNativeDateTransformerDirective,
- ],
- exports: [ExampleTuiInputDateComponent],
-})
-export class ExampleTuiInputDateModule {}
diff --git a/projects/demo/src/modules/components/input-number/input-number.module.ts b/projects/demo/src/modules/components/input-number/input-number.module.ts
index d93bb682e731..63bc686d8372 100644
--- a/projects/demo/src/modules/components/input-number/input-number.module.ts
+++ b/projects/demo/src/modules/components/input-number/input-number.module.ts
@@ -9,7 +9,7 @@ import {
TuiHintModule,
TuiLinkModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiSvgModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
@@ -42,7 +42,7 @@ import {ExampleTuiInputNumberComponent} from './input-number.component';
InheritedDocumentationModule,
TuiHintModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiInputNumberComponent)),
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
],
declarations: [
ExampleTuiInputNumberComponent,
diff --git a/projects/demo/src/modules/components/input-range/input-range.module.ts b/projects/demo/src/modules/components/input-range/input-range.module.ts
index 542c8d4c568b..da60cdf113cd 100644
--- a/projects/demo/src/modules/components/input-range/input-range.module.ts
+++ b/projects/demo/src/modules/components/input-range/input-range.module.ts
@@ -7,7 +7,7 @@ import {
TuiButtonModule,
TuiLinkModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiSvgModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
@@ -43,7 +43,7 @@ import {ExampleTuiInputRangeComponent} from './input-range.component';
TuiTextfieldControllerModule,
TuiSvgModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiInputRangeComponent)),
NumberFormatDocumentationModule,
],
diff --git a/projects/demo/src/modules/components/input-slider/input-slider.module.ts b/projects/demo/src/modules/components/input-slider/input-slider.module.ts
index ff7c6b4d641f..79048177c2ee 100644
--- a/projects/demo/src/modules/components/input-slider/input-slider.module.ts
+++ b/projects/demo/src/modules/components/input-slider/input-slider.module.ts
@@ -8,7 +8,7 @@ import {
TuiHintModule,
TuiLinkModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiSvgModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
@@ -42,7 +42,7 @@ import {ExampleTuiInputSliderComponent} from './input-slider.component';
TuiSvgModule,
TuiNotificationModule,
TuiTextfieldControllerModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiInputSliderComponent)),
],
declarations: [
diff --git a/projects/demo/src/modules/components/select/select.module.ts b/projects/demo/src/modules/components/select/select.module.ts
index d1cff1c58721..5fea1287435f 100644
--- a/projects/demo/src/modules/components/select/select.module.ts
+++ b/projects/demo/src/modules/components/select/select.module.ts
@@ -16,7 +16,7 @@ import {
TuiLinkModule,
TuiLoaderModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiScrollableDirective,
TuiScrollbarComponent,
TuiSvgModule,
@@ -81,7 +81,7 @@ import {ExampleTuiSelectComponent} from './select.component';
TuiMapperPipeModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiSelectComponent)),
TuiAmountPipe,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiScrollableDirective,
TuiInitialsPipe,
],
diff --git a/projects/demo/src/modules/directives/date-format/examples/1/index.html b/projects/demo/src/modules/directives/date-format/examples/1/index.html
new file mode 100644
index 000000000000..19e9d85e494c
--- /dev/null
+++ b/projects/demo/src/modules/directives/date-format/examples/1/index.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Cool
+
+
+
diff --git a/projects/demo/src/modules/directives/date-format/examples/1/index.ts b/projects/demo/src/modules/directives/date-format/examples/1/index.ts
new file mode 100644
index 000000000000..5709c170ca43
--- /dev/null
+++ b/projects/demo/src/modules/directives/date-format/examples/1/index.ts
@@ -0,0 +1,17 @@
+import {Component} from '@angular/core';
+import {FormControl, ReactiveFormsModule} from '@angular/forms';
+import {changeDetection} from '@demo/emulate/change-detection';
+import {encapsulation} from '@demo/emulate/encapsulation';
+import {TuiDateFormatDirective} from '@taiga-ui/core';
+import {TuiInputDateModule} from '@taiga-ui/kit';
+
+@Component({
+ standalone: true,
+ imports: [TuiInputDateModule, TuiDateFormatDirective, ReactiveFormsModule],
+ templateUrl: './index.html',
+ encapsulation,
+ changeDetection,
+})
+export default class ExampleComponent {
+ protected readonly control = new FormControl();
+}
diff --git a/projects/demo/src/modules/directives/number-format/examples/import/import-module.md b/projects/demo/src/modules/directives/date-format/examples/import/import.md
similarity index 59%
rename from projects/demo/src/modules/directives/number-format/examples/import/import-module.md
rename to projects/demo/src/modules/directives/date-format/examples/import/import.md
index 45dfb4c1ab6e..2a73056a38a0 100644
--- a/projects/demo/src/modules/directives/number-format/examples/import/import-module.md
+++ b/projects/demo/src/modules/directives/date-format/examples/import/import.md
@@ -1,5 +1,5 @@
```ts
-import {TuiNumberFormatModule} from '@taiga-ui/core';
+import {TuiDateFormatDirective} from '@taiga-ui/core';
// ...
@@ -7,7 +7,7 @@ import {TuiNumberFormatModule} from '@taiga-ui/core';
standalone: true,
imports: [
// ...
- TuiNumberFormatModule,
+ TuiDateFormatDirective,
],
// ...
})
diff --git a/projects/demo/src/modules/directives/date-format/examples/import/template.md b/projects/demo/src/modules/directives/date-format/examples/import/template.md
new file mode 100644
index 000000000000..e3c65e954b5b
--- /dev/null
+++ b/projects/demo/src/modules/directives/date-format/examples/import/template.md
@@ -0,0 +1,3 @@
+```html
+
+```
diff --git a/projects/demo/src/modules/directives/date-format/index.html b/projects/demo/src/modules/directives/date-format/index.html
new file mode 100644
index 000000000000..c005c3436b73
--- /dev/null
+++ b/projects/demo/src/modules/directives/date-format/index.html
@@ -0,0 +1,28 @@
+
+
+
+ Directive allows to customize
+ TuiInputDate
+ ,
+ TuiInputDateRange
+ ,
+ TuiInputDateMulti
+ and
+ TuiInputDateTime
+ date format.
+
+
+
+
+
+
+
diff --git a/projects/demo/src/modules/directives/date-format/index.ts b/projects/demo/src/modules/directives/date-format/index.ts
new file mode 100644
index 000000000000..be9fca414f6c
--- /dev/null
+++ b/projects/demo/src/modules/directives/date-format/index.ts
@@ -0,0 +1,11 @@
+import {Component} from '@angular/core';
+import {changeDetection} from '@demo/emulate/change-detection';
+import {TuiDemoModule} from '@demo/utils';
+
+@Component({
+ standalone: true,
+ imports: [TuiDemoModule],
+ templateUrl: './index.html',
+ changeDetection,
+})
+export default class ExampleComponent {}
diff --git a/projects/demo/src/modules/directives/number-format/examples/1/index.ts b/projects/demo/src/modules/directives/number-format/examples/1/index.ts
index ae874db0e282..5c57bfaaa274 100644
--- a/projects/demo/src/modules/directives/number-format/examples/1/index.ts
+++ b/projects/demo/src/modules/directives/number-format/examples/1/index.ts
@@ -2,13 +2,13 @@ import {Component} from '@angular/core';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
-import {TuiNumberFormatModule} from '@taiga-ui/core';
+import {TuiNumberFormatDirective} from '@taiga-ui/core';
import {TuiInputNumberModule} from '@taiga-ui/kit';
@Component({
standalone: true,
selector: 'tui-number-format-example-1',
- imports: [TuiInputNumberModule, TuiNumberFormatModule, ReactiveFormsModule],
+ imports: [TuiInputNumberModule, TuiNumberFormatDirective, ReactiveFormsModule],
templateUrl: './index.html',
encapsulation,
changeDetection,
diff --git a/projects/demo/src/modules/directives/number-format/examples/import/import.md b/projects/demo/src/modules/directives/number-format/examples/import/import.md
new file mode 100644
index 000000000000..f7fd0b0d77de
--- /dev/null
+++ b/projects/demo/src/modules/directives/number-format/examples/import/import.md
@@ -0,0 +1,15 @@
+```ts
+import {TuiNumberFormatDirective} from '@taiga-ui/core';
+
+// ...
+
+@Component({
+ standalone: true,
+ imports: [
+ // ...
+ TuiNumberFormatDirective,
+ ],
+ // ...
+})
+export class MyComponent {}
+```
diff --git a/projects/demo/src/modules/directives/number-format/examples/import/insert-template.md b/projects/demo/src/modules/directives/number-format/examples/import/template.md
similarity index 100%
rename from projects/demo/src/modules/directives/number-format/examples/import/insert-template.md
rename to projects/demo/src/modules/directives/number-format/examples/import/template.md
diff --git a/projects/demo/src/modules/directives/number-format/number-format.template.html b/projects/demo/src/modules/directives/number-format/index.html
similarity index 84%
rename from projects/demo/src/modules/directives/number-format/number-format.template.html
rename to projects/demo/src/modules/directives/number-format/index.html
index de92feb73bdb..d1523bf5b8ca 100644
--- a/projects/demo/src/modules/directives/number-format/number-format.template.html
+++ b/projects/demo/src/modules/directives/number-format/index.html
@@ -23,9 +23,5 @@
-
+
diff --git a/projects/demo/src/modules/directives/number-format/number-format.component.ts b/projects/demo/src/modules/directives/number-format/index.ts
similarity index 67%
rename from projects/demo/src/modules/directives/number-format/number-format.component.ts
rename to projects/demo/src/modules/directives/number-format/index.ts
index a8a583758dbe..1d4f4801026d 100644
--- a/projects/demo/src/modules/directives/number-format/number-format.component.ts
+++ b/projects/demo/src/modules/directives/number-format/index.ts
@@ -16,10 +16,7 @@ import {TuiNumberFormatExample1} from './examples/1';
TuiAddonDocModule,
TuiNumberFormatExample1,
],
- templateUrl: './number-format.template.html',
+ templateUrl: './index.html',
changeDetection,
})
-export default class ExampleTuiNumberFormatComponent {
- protected readonly import = import('./examples/import/import-module.md?raw');
- protected readonly template = import('./examples/import/insert-template.md?raw');
-}
+export default class ExampleTuiNumberFormatComponent {}
diff --git a/projects/demo/src/modules/pipes/amount/amount.module.ts b/projects/demo/src/modules/pipes/amount/amount.module.ts
index 8a9ff572d2a2..db5e0109ac0e 100644
--- a/projects/demo/src/modules/pipes/amount/amount.module.ts
+++ b/projects/demo/src/modules/pipes/amount/amount.module.ts
@@ -5,7 +5,7 @@ import {tuiGetDocModules} from '@taiga-ui/addon-doc';
import {
TuiLinkModule,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
} from '@taiga-ui/core';
import {ExampleTuiAmountComponent} from './amount.component';
@@ -18,7 +18,7 @@ import {TuiAmountExample3} from './examples/3';
CommonModule,
TuiAmountPipe,
TuiNotificationModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
tuiGetDocModules(ExampleTuiAmountComponent),
TuiLinkModule,
],
diff --git a/projects/demo/src/modules/utils/math/math.module.ts b/projects/demo/src/modules/utils/math/math.module.ts
index 447d65d1fbd7..d5f0163ff6e7 100644
--- a/projects/demo/src/modules/utils/math/math.module.ts
+++ b/projects/demo/src/modules/utils/math/math.module.ts
@@ -3,7 +3,7 @@ import {NgModule} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
-import {TuiNumberFormatModule} from '@taiga-ui/core';
+import {TuiNumberFormatDirective} from '@taiga-ui/core';
import {TuiInputNumberModule} from '@taiga-ui/kit';
import {TuiMathExample1} from './examples/1';
@@ -21,7 +21,7 @@ import {ExampleMathComponent} from './math.component';
ReactiveFormsModule,
TuiAddonDocModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleMathComponent)),
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
],
declarations: [
ExampleMathComponent,
diff --git a/projects/demo/src/modules/utils/tokens/examples/10/index.html b/projects/demo/src/modules/utils/tokens/examples/10/index.html
new file mode 100644
index 000000000000..41b3855958bb
--- /dev/null
+++ b/projects/demo/src/modules/utils/tokens/examples/10/index.html
@@ -0,0 +1,25 @@
+
+ Use
+ TUI_FIRST_DAY_OF_WEEK
+ injection token to change start day of the week (Monday by default).
+
+
+
+
+
+ This token can customize the following components:
+
+
diff --git a/projects/demo/src/modules/utils/tokens/examples/10/index.ts b/projects/demo/src/modules/utils/tokens/examples/10/index.ts
new file mode 100644
index 000000000000..5243aa4f1aa6
--- /dev/null
+++ b/projects/demo/src/modules/utils/tokens/examples/10/index.ts
@@ -0,0 +1,37 @@
+import {Component} from '@angular/core';
+import {changeDetection} from '@demo/emulate/change-detection';
+import {encapsulation} from '@demo/emulate/encapsulation';
+import {TuiDayOfWeek} from '@taiga-ui/cdk';
+import {TUI_FIRST_DAY_OF_WEEK} from '@taiga-ui/core';
+
+@Component({
+ selector: 'tui-token-example-10',
+ templateUrl: './index.html',
+ encapsulation,
+ changeDetection,
+ providers: [
+ {
+ provide: TUI_FIRST_DAY_OF_WEEK,
+ useValue: TuiDayOfWeek.Sunday,
+ },
+ ],
+})
+export class TuiTokensExample10 {
+ protected readonly provideFirstDayOfWeekToken = import(
+ './provide-first-day-of-week-token.md?raw'
+ );
+
+ protected readonly customizableComponentsViaThisToken = [
+ {name: 'Calendar', link: '/components/calendar', fragment: 'localization'},
+ {
+ name: 'CalendarRange',
+ link: '/components/calendar-range',
+ fragment: 'localization',
+ },
+ {
+ name: 'MobileCalendar',
+ link: '/components/mobile-calendar',
+ fragment: 'localization',
+ },
+ ] as const;
+}
diff --git a/projects/demo/src/modules/utils/tokens/examples/9/provide-first-day-of-week-token.md b/projects/demo/src/modules/utils/tokens/examples/10/provide-first-day-of-week-token.md
similarity index 100%
rename from projects/demo/src/modules/utils/tokens/examples/9/provide-first-day-of-week-token.md
rename to projects/demo/src/modules/utils/tokens/examples/10/provide-first-day-of-week-token.md
diff --git a/projects/demo/src/modules/utils/tokens/examples/9/index.html b/projects/demo/src/modules/utils/tokens/examples/9/index.html
index 41b3855958bb..7f698979852c 100644
--- a/projects/demo/src/modules/utils/tokens/examples/9/index.html
+++ b/projects/demo/src/modules/utils/tokens/examples/9/index.html
@@ -1,25 +1,79 @@
-
- Use
- TUI_FIRST_DAY_OF_WEEK
- injection token to change start day of the week (Monday by default).
-
+
+
+ Using
+ TUI_DATE_FORMAT
+ injection token you can customize numbers formatting.
+
+
For example: 10.01.2024
+
Can be customized as: 2024/01/10
-
+
+ Description:
+
+ -
+
mode
+
+ -
+ active date format (
+
'DMY' | 'MDY' | 'YMD'
+ )
+
+ -
+
separator
+
+ - single-character date's separator (dot, slash etc.)
+
+
-
- This token can customize the following components:
-
-
+
+ Defaults:
+
+ -
+ mode =
+
DMY
+
+ -
+ separator =
+
.
+
+
+
+
+
+ Components that are customizable:
+
+
+
diff --git a/projects/demo/src/modules/utils/tokens/examples/9/index.ts b/projects/demo/src/modules/utils/tokens/examples/9/index.ts
index 62b101e669af..23a793166373 100644
--- a/projects/demo/src/modules/utils/tokens/examples/9/index.ts
+++ b/projects/demo/src/modules/utils/tokens/examples/9/index.ts
@@ -1,37 +1,14 @@
-import {Component} from '@angular/core';
+import {Component, inject} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
-import {TuiDayOfWeek} from '@taiga-ui/cdk';
-import {TUI_FIRST_DAY_OF_WEEK} from '@taiga-ui/core';
+import {TUI_DATE_FORMAT} from '@taiga-ui/core';
@Component({
selector: 'tui-token-example-9',
templateUrl: './index.html',
encapsulation,
changeDetection,
- providers: [
- {
- provide: TUI_FIRST_DAY_OF_WEEK,
- useValue: TuiDayOfWeek.Sunday,
- },
- ],
})
export class TuiTokensExample9 {
- protected readonly provideFirstDayOfWeekToken = import(
- './provide-first-day-of-week-token.md?raw'
- );
-
- protected readonly customizableComponentsViaThisToken = [
- {name: 'Calendar', link: '/components/calendar', fragment: 'localization'},
- {
- name: 'CalendarRange',
- link: '/components/calendar-range',
- fragment: 'localization',
- },
- {
- name: 'MobileCalendar',
- link: '/components/mobile-calendar',
- fragment: 'localization',
- },
- ] as const;
+ protected readonly TuiDateFormatSettings = inject(TUI_DATE_FORMAT);
}
diff --git a/projects/demo/src/modules/utils/tokens/tokens.component.ts b/projects/demo/src/modules/utils/tokens/tokens.component.ts
index 55781db87bfe..395f78aefd8f 100644
--- a/projects/demo/src/modules/utils/tokens/tokens.component.ts
+++ b/projects/demo/src/modules/utils/tokens/tokens.component.ts
@@ -46,4 +46,8 @@ export class ExampleTokensComponent {
protected readonly example8: TuiDocExample = {
TypeScript: import('./examples/8/index.ts?raw'),
};
+
+ protected readonly example9: TuiDocExample = {
+ TypeScript: import('./examples/9/index.ts?raw'),
+ };
}
diff --git a/projects/demo/src/modules/utils/tokens/tokens.module.ts b/projects/demo/src/modules/utils/tokens/tokens.module.ts
index 10e0a023cb07..e6105f8b2c5e 100644
--- a/projects/demo/src/modules/utils/tokens/tokens.module.ts
+++ b/projects/demo/src/modules/utils/tokens/tokens.module.ts
@@ -13,6 +13,7 @@ import {TuiTokensExample6} from './examples/6';
import {TuiTokensExample7} from './examples/7';
import {TuiTokensExample8} from './examples/8';
import {TuiTokensExample9} from './examples/9';
+import {TuiTokensExample10} from './examples/10';
import {ExampleTokensComponent} from './tokens.component';
@NgModule({
@@ -33,6 +34,7 @@ import {ExampleTokensComponent} from './tokens.component';
TuiTokensExample7,
TuiTokensExample8,
TuiTokensExample9,
+ TuiTokensExample10,
],
exports: [ExampleTokensComponent],
})
diff --git a/projects/demo/src/modules/utils/tokens/tokens.template.html b/projects/demo/src/modules/utils/tokens/tokens.template.html
index b2733453d464..d4dd842f8dd9 100644
--- a/projects/demo/src/modules/utils/tokens/tokens.template.html
+++ b/projects/demo/src/modules/utils/tokens/tokens.template.html
@@ -76,12 +76,21 @@
+
+
+
+
-
+
diff --git a/projects/kit/components/input-date-multi/input-date-multi.component.ts b/projects/kit/components/input-date-multi/input-date-multi.component.ts
index 55f370ad1278..3d59d3d7d531 100644
--- a/projects/kit/components/input-date-multi/input-date-multi.component.ts
+++ b/projects/kit/components/input-date-multi/input-date-multi.component.ts
@@ -8,6 +8,7 @@ import {
Input,
ViewChild,
} from '@angular/core';
+import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import type {MaskitoOptions} from '@maskito/core';
import {maskitoDateOptionsGenerator} from '@maskito/kit';
import type {
@@ -20,8 +21,6 @@ import type {
import {
AbstractTuiMultipleControl,
changeDateSeparator,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_FALSE_HANDLER,
TUI_IS_MOBILE,
tuiAsControl,
@@ -30,6 +29,7 @@ import {
TuiDay,
tuiIsString,
TuiMonth,
+ tuiWatch,
} from '@taiga-ui/cdk';
import type {
TuiMarkerHandler,
@@ -38,6 +38,8 @@ import type {
TuiWithOptionalMinMax,
} from '@taiga-ui/core';
import {
+ TUI_DATE_FORMAT,
+ TUI_DEFAULT_DATE_FORMAT,
TUI_DEFAULT_MARKER_HANDLER,
TUI_TEXTFIELD_SIZE,
TuiDialogService,
@@ -57,7 +59,7 @@ import {
import {tuiImmutableUpdateInputDateMulti} from '@taiga-ui/kit/utils';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';
import type {Observable} from 'rxjs';
-import {map, takeUntil} from 'rxjs';
+import {map} from 'rxjs';
@Component({
selector: 'tui-input-date[multiple]',
@@ -132,16 +134,24 @@ export class TuiInputDateMultiComponent
protected open = false;
- protected readonly dateFormat = inject(TUI_DATE_FORMAT);
- protected readonly dateSeparator = inject(TUI_DATE_SEPARATOR);
+ protected dateFormat = TUI_DEFAULT_DATE_FORMAT;
protected readonly isMobile = inject(TUI_IS_MOBILE);
protected readonly doneWord$ = inject(TUI_DONE_WORD);
protected readonly filler$: Observable = this.dateTexts$.pipe(
map(dateTexts =>
- changeDateSeparator(dateTexts[this.dateFormat], this.dateSeparator),
+ changeDateSeparator(
+ dateTexts[this.dateFormat.mode],
+ this.dateFormat.separator,
+ ),
),
);
+ protected readonly dateFormat$ = inject(TUI_DATE_FORMAT)
+ .pipe(tuiWatch(this.cdr), takeUntilDestroyed())
+ .subscribe(format => {
+ this.dateFormat = format;
+ });
+
public get nativeFocusableElement(): HTMLInputElement | null {
return this.textfield?.nativeFocusableElement || null;
}
@@ -233,7 +243,7 @@ export class TuiInputDateMultiComponent
},
},
)
- .pipe(takeUntil(this.destroy$))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => {
this.value = value;
});
diff --git a/projects/kit/components/input-date-range/input-date-range.component.ts b/projects/kit/components/input-date-range/input-date-range.component.ts
index a71cfc59550a..c856add1ec6f 100644
--- a/projects/kit/components/input-date-range/input-date-range.component.ts
+++ b/projects/kit/components/input-date-range/input-date-range.component.ts
@@ -8,6 +8,7 @@ import {
Input,
ViewChild,
} from '@angular/core';
+import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import type {MaskitoOptions} from '@maskito/core';
import {MASKITO_DEFAULT_OPTIONS} from '@maskito/core';
import {maskitoDateRangeOptionsGenerator} from '@maskito/kit';
@@ -25,8 +26,6 @@ import {
DATE_FILLER_LENGTH,
DATE_RANGE_FILLER_LENGTH,
RANGE_SEPARATOR_CHAR,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_FALSE_HANDLER,
TUI_FIRST_DAY,
TUI_IS_MOBILE,
@@ -38,6 +37,7 @@ import {
TuiMonth,
tuiNullableSame,
tuiPure,
+ tuiWatch,
} from '@taiga-ui/cdk';
import type {
TuiMarkerHandler,
@@ -46,6 +46,8 @@ import type {
TuiWithOptionalMinMax,
} from '@taiga-ui/core';
import {
+ TUI_DATE_FORMAT,
+ TUI_DEFAULT_DATE_FORMAT,
TUI_DEFAULT_MARKER_HANDLER,
TUI_TEXTFIELD_SIZE,
TuiDialogService,
@@ -66,7 +68,7 @@ import {
} from '@taiga-ui/kit/tokens';
import type {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';
-import {map, takeUntil} from 'rxjs';
+import {map} from 'rxjs';
@Component({
selector: 'tui-input-date-range',
@@ -132,12 +134,19 @@ export class TuiInputDateRangeComponent
protected readonly dateFiller$ = this.dateTexts$.pipe(
map(dateTexts =>
- changeDateSeparator(dateTexts[this.dateFormat], this.dateSeparator),
+ changeDateSeparator(
+ dateTexts[this.dateFormat.mode],
+ this.dateFormat.separator,
+ ),
),
);
- protected readonly dateFormat = inject(TUI_DATE_FORMAT);
- protected readonly dateSeparator = inject(TUI_DATE_SEPARATOR);
+ protected dateFormat = TUI_DEFAULT_DATE_FORMAT;
+ protected readonly dateFormat$ = inject(TUI_DATE_FORMAT)
+ .pipe(tuiWatch(this.cdr), takeUntilDestroyed())
+ .subscribe(format => {
+ this.dateFormat = format;
+ });
public get nativeFocusableElement(): HTMLInputElement | null {
return this.textfield?.nativeFocusableElement ?? null;
@@ -161,7 +170,7 @@ export class TuiInputDateRangeComponent
}
return value
- ? value.getFormattedDayRange(this.dateFormat, this.dateSeparator)
+ ? value.getFormattedDayRange(this.dateFormat.mode, this.dateFormat.separator)
: nativeValue;
}
@@ -183,7 +192,7 @@ export class TuiInputDateRangeComponent
this.value =
value.length === DATE_RANGE_FILLER_LENGTH
- ? TuiDayRange.normalizeParse(value, this.dateFormat)
+ ? TuiDayRange.normalizeParse(value, this.dateFormat.mode)
: null;
}
@@ -232,8 +241,8 @@ export class TuiInputDateRangeComponent
return this.activePeriod
? MASKITO_DEFAULT_OPTIONS
: this.calculateMask(
- this.dateFormat,
- this.dateSeparator,
+ this.dateFormat.mode,
+ this.dateFormat.separator,
this.computedMin,
this.computedMax,
this.minLength,
@@ -317,7 +326,7 @@ export class TuiInputDateRangeComponent
},
},
)
- .pipe(takeUntil(this.destroy$))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => {
this.value = value;
});
@@ -356,7 +365,10 @@ export class TuiInputDateRangeComponent
this.nativeValue.length ===
DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length)
) {
- this.value = TuiDayRange.normalizeParse(this.nativeValue, this.dateFormat);
+ this.value = TuiDayRange.normalizeParse(
+ this.nativeValue,
+ this.dateFormat.mode,
+ );
}
}
diff --git a/projects/kit/components/input-date-range/test/input-date-range.component.spec.ts b/projects/kit/components/input-date-range/test/input-date-range.component.spec.ts
index bb2b8d9ad8a1..2682597cf0dc 100644
--- a/projects/kit/components/input-date-range/test/input-date-range.component.spec.ts
+++ b/projects/kit/components/input-date-range/test/input-date-range.component.spec.ts
@@ -7,13 +7,15 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {
AbstractTuiValueTransformer,
RANGE_SEPARATOR_CHAR,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_LAST_DAY,
TuiDay,
TuiDayRange,
} from '@taiga-ui/cdk';
-import {TuiRootModule, TuiTextfieldControllerModule} from '@taiga-ui/core';
+import {
+ TUI_DATE_FORMAT,
+ TuiRootModule,
+ TuiTextfieldControllerModule,
+} from '@taiga-ui/core';
import type {TuiDayRangePeriod} from '@taiga-ui/kit';
import {
TUI_DATE_RANGE_VALUE_TRANSFORMER,
@@ -22,6 +24,7 @@ import {
TuiInputDateRangeModule,
} from '@taiga-ui/kit';
import {TuiNativeInputPO, TuiPageObject} from '@taiga-ui/testing';
+import {of} from 'rxjs';
describe('InputDateRangeComponent', () => {
@Component({
@@ -185,8 +188,10 @@ describe('InputDateRangeComponent', () => {
TestBed.configureTestingModule({
...defaultTestingModuleMeta,
providers: [
- {provide: TUI_DATE_FORMAT, useValue: 'MDY'},
- {provide: TUI_DATE_SEPARATOR, useValue: '/'},
+ {
+ provide: TUI_DATE_FORMAT,
+ useValue: of({mode: 'MDY', separator: '/'}),
+ },
],
});
await TestBed.compileComponents();
@@ -224,8 +229,10 @@ describe('InputDateRangeComponent', () => {
TestBed.configureTestingModule({
...defaultTestingModuleMeta,
providers: [
- {provide: TUI_DATE_FORMAT, useValue: 'YMD'},
- {provide: TUI_DATE_SEPARATOR, useValue: '-'},
+ {
+ provide: TUI_DATE_FORMAT,
+ useValue: of({mode: 'YMD', separator: '-'}),
+ },
],
});
await TestBed.compileComponents();
diff --git a/projects/kit/components/input-date-time/input-date-time.component.ts b/projects/kit/components/input-date-time/input-date-time.component.ts
index e9b40db3860a..d766b56f13ea 100644
--- a/projects/kit/components/input-date-time/input-date-time.component.ts
+++ b/projects/kit/components/input-date-time/input-date-time.component.ts
@@ -7,6 +7,7 @@ import {
Input,
ViewChild,
} from '@angular/core';
+import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import type {MaskitoOptions} from '@maskito/core';
import {maskitoDateTimeOptionsGenerator} from '@maskito/kit';
import type {
@@ -21,10 +22,7 @@ import {
AbstractTuiControl,
changeDateSeparator,
DATE_FILLER_LENGTH,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_FALSE_HANDLER,
- TUI_IS_IOS,
TUI_IS_MOBILE,
tuiAsControl,
tuiAsFocusableItemAccessor,
@@ -35,9 +33,15 @@ import {
tuiNullableSame,
tuiPure,
TuiTime,
+ tuiWatch,
} from '@taiga-ui/cdk';
import type {TuiSizeL, TuiSizeS, TuiWithOptionalMinMax} from '@taiga-ui/core';
-import {TUI_TEXTFIELD_SIZE, TuiPrimitiveTextfieldComponent} from '@taiga-ui/core';
+import {
+ TUI_DATE_FORMAT,
+ TUI_DEFAULT_DATE_FORMAT,
+ TUI_TEXTFIELD_SIZE,
+ TuiPrimitiveTextfieldComponent,
+} from '@taiga-ui/core';
import {
DATE_TIME_SEPARATOR,
TUI_DATE_MODE_MASKITO_ADAPTER,
@@ -51,7 +55,7 @@ import {
tuiDateStreamWithTransformer,
} from '@taiga-ui/kit/tokens';
import type {Observable} from 'rxjs';
-import {BehaviorSubject, combineLatest, map, takeUntil, timer} from 'rxjs';
+import {BehaviorSubject, combineLatest, map, timer} from 'rxjs';
@Component({
selector: 'tui-input-date-time',
@@ -104,7 +108,10 @@ export class TuiInputDateTimeComponent
protected readonly filler$: Observable = combineLatest([
this.dateTexts$.pipe(
map(dateTexts =>
- changeDateSeparator(dateTexts[this.dateFormat], this.dateSeparator),
+ changeDateSeparator(
+ dateTexts[this.dateFormat.mode],
+ this.dateFormat.separator,
+ ),
),
),
this.timeTexts$,
@@ -115,10 +122,13 @@ export class TuiInputDateTimeComponent
),
);
- protected readonly dateFormat = inject(TUI_DATE_FORMAT);
- protected readonly dateSeparator = inject(TUI_DATE_SEPARATOR);
+ protected dateFormat = TUI_DEFAULT_DATE_FORMAT;
protected readonly isMobile = inject(TUI_IS_MOBILE);
- protected readonly isIos = inject(TUI_IS_IOS);
+ protected readonly dateFormat$ = inject(TUI_DATE_FORMAT)
+ .pipe(tuiWatch(this.cdr), takeUntilDestroyed())
+ .subscribe(format => {
+ this.dateFormat = format;
+ });
@Input()
public set timeMode(value: TuiTimeMode) {
@@ -173,7 +183,7 @@ export class TuiInputDateTimeComponent
}
const [date, time] = value.split(DATE_TIME_SEPARATOR);
- const parsedDate = TuiDay.normalizeParse(date, this.dateFormat);
+ const parsedDate = TuiDay.normalizeParse(date, this.dateFormat.mode);
const parsedTime =
time && time.length === this.timeMode.length
? TuiTime.fromString(time)
@@ -205,8 +215,8 @@ export class TuiInputDateTimeComponent
this.computedMin,
this.computedMax,
this.timeMode,
- this.dateFormat,
- this.dateSeparator,
+ this.dateFormat.mode,
+ this.dateFormat.separator,
);
}
@@ -291,7 +301,7 @@ export class TuiInputDateTimeComponent
}
timer(0)
- .pipe(takeUntil(this.destroy$))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.nativeValue = this.trimTrailingSeparator(this.nativeValue);
});
@@ -359,7 +369,7 @@ export class TuiInputDateTimeComponent
): string {
const dateString =
date instanceof TuiDay
- ? date.toString(this.dateFormat, this.dateSeparator)
+ ? date.toString(this.dateFormat.mode, this.dateFormat.separator)
: date;
const timeString = time instanceof TuiTime ? time.toString(timeMode) : time || '';
@@ -392,7 +402,7 @@ export class TuiInputDateTimeComponent
private trimTrailingSeparator(value: string): string {
return value.replace(
- new RegExp(`(\\${this.dateSeparator}|${DATE_TIME_SEPARATOR}|\\.)$`),
+ new RegExp(`(\\${this.dateFormat.separator}|${DATE_TIME_SEPARATOR}|\\.)$`),
'',
);
}
diff --git a/projects/kit/components/input-date-time/test/input-date-time.component.spec.ts b/projects/kit/components/input-date-time/test/input-date-time.component.spec.ts
index 96eeb7801af9..269467a55603 100644
--- a/projects/kit/components/input-date-time/test/input-date-time.component.spec.ts
+++ b/projects/kit/components/input-date-time/test/input-date-time.component.spec.ts
@@ -6,20 +6,19 @@ import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {
AbstractTuiValueTransformer,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_FIRST_DAY,
TUI_LAST_DAY,
TuiDay,
TuiTime,
} from '@taiga-ui/cdk';
-import {TuiRootModule} from '@taiga-ui/core';
+import {TUI_DATE_FORMAT, TuiRootModule} from '@taiga-ui/core';
import {TUI_DATE_TIME_VALUE_TRANSFORMER} from '@taiga-ui/kit';
import {
TuiInputDateTimeComponent,
TuiInputDateTimeModule,
} from '@taiga-ui/kit/components';
import {TuiNativeInputPO, TuiPageObject} from '@taiga-ui/testing';
+import {of} from 'rxjs';
describe('InputDateTime', () => {
@Component({
@@ -242,8 +241,10 @@ describe('InputDateTime', () => {
TestBed.configureTestingModule({
...defaultTestingModuleMeta,
providers: [
- {provide: TUI_DATE_FORMAT, useValue: 'MDY'},
- {provide: TUI_DATE_SEPARATOR, useValue: '/'},
+ {
+ provide: TUI_DATE_FORMAT,
+ useValue: of({mode: 'MDY', separator: '/'}),
+ },
],
});
await TestBed.compileComponents();
@@ -280,8 +281,10 @@ describe('InputDateTime', () => {
TestBed.configureTestingModule({
...defaultTestingModuleMeta,
providers: [
- {provide: TUI_DATE_FORMAT, useValue: 'YMD'},
- {provide: TUI_DATE_SEPARATOR, useValue: '-'},
+ {
+ provide: TUI_DATE_FORMAT,
+ useValue: of({mode: 'YMD', separator: '-'}),
+ },
],
});
await TestBed.compileComponents();
diff --git a/projects/kit/components/input-date/input-date.component.ts b/projects/kit/components/input-date/input-date.component.ts
index 8443826a8068..6006cf285c6c 100644
--- a/projects/kit/components/input-date/input-date.component.ts
+++ b/projects/kit/components/input-date/input-date.component.ts
@@ -8,6 +8,7 @@ import {
Input,
ViewChild,
} from '@angular/core';
+import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import type {MaskitoOptions} from '@maskito/core';
import {MASKITO_DEFAULT_OPTIONS} from '@maskito/core';
import {maskitoDateOptionsGenerator} from '@maskito/kit';
@@ -22,8 +23,6 @@ import {
AbstractTuiNullableControl,
changeDateSeparator,
DATE_FILLER_LENGTH,
- TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
TUI_FALSE_HANDLER,
TUI_IS_MOBILE,
tuiAsControl,
@@ -33,6 +32,7 @@ import {
TuiMonth,
tuiNullableSame,
tuiPure,
+ tuiWatch,
} from '@taiga-ui/cdk';
import type {
TuiMarkerHandler,
@@ -41,6 +41,8 @@ import type {
TuiWithOptionalMinMax,
} from '@taiga-ui/core';
import {
+ TUI_DATE_FORMAT,
+ TUI_DEFAULT_DATE_FORMAT,
TUI_DEFAULT_MARKER_HANDLER,
TUI_TEXTFIELD_SIZE,
TuiDialogService,
@@ -58,7 +60,7 @@ import {
} from '@taiga-ui/kit/tokens';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';
import type {Observable} from 'rxjs';
-import {map, takeUntil} from 'rxjs';
+import {map} from 'rxjs';
@Component({
selector: 'tui-input-date',
@@ -103,6 +105,7 @@ export class TuiInputDateComponent
@Input()
public defaultActiveYearMonth = TuiMonth.currentLocal();
+ public dateFormat = TUI_DEFAULT_DATE_FORMAT;
protected open = false;
protected readonly dateTexts$ = inject(TUI_DATE_TEXTS);
protected override readonly valueTransformer = inject(TUI_DATE_VALUE_TRANSFORMER, {
@@ -110,15 +113,22 @@ export class TuiInputDateComponent
});
protected readonly isMobile = inject(TUI_IS_MOBILE);
- protected readonly dateFormat = inject(TUI_DATE_FORMAT);
- protected readonly dateSeparator = inject(TUI_DATE_SEPARATOR);
protected readonly type!: TuiContext;
protected readonly filler$: Observable = this.dateTexts$.pipe(
map(dateTexts =>
- changeDateSeparator(dateTexts[this.dateFormat], this.dateSeparator),
+ changeDateSeparator(
+ dateTexts[this.dateFormat.mode],
+ this.dateFormat.separator,
+ ),
),
);
+ protected readonly dateFormat$ = inject(TUI_DATE_FORMAT)
+ .pipe(tuiWatch(this.cdr), takeUntilDestroyed())
+ .subscribe(format => {
+ this.dateFormat = format;
+ });
+
public get computedMin(): TuiDay {
return this.min ?? this.options.min;
}
@@ -154,7 +164,9 @@ export class TuiInputDateComponent
return String(activeItem);
}
- return value ? value.toString(this.dateFormat, this.dateSeparator) : nativeValue;
+ return value
+ ? value.toString(this.dateFormat.mode, this.dateFormat.separator)
+ : nativeValue;
}
public onValueChange(value: string): void {
@@ -169,7 +181,7 @@ export class TuiInputDateComponent
this.value =
value.length !== DATE_FILLER_LENGTH
? null
- : TuiDay.normalizeParse(value, this.dateFormat);
+ : TuiDay.normalizeParse(value, this.dateFormat.mode);
}
public override setDisabledState(): void {
@@ -219,8 +231,8 @@ export class TuiInputDateComponent
return this.activeItem
? MASKITO_DEFAULT_OPTIONS
: this.computeMaskOptions(
- this.dateFormat,
- this.dateSeparator,
+ this.dateFormat.mode,
+ this.dateFormat.separator,
this.computedMin,
this.computedMax,
);
@@ -268,7 +280,7 @@ export class TuiInputDateComponent
disabledItemHandler: this.disabledItemHandler,
},
})
- .pipe(takeUntil(this.destroy$))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => {
this.value = value;
});
diff --git a/projects/kit/components/input-date/input-date.directive.ts b/projects/kit/components/input-date/input-date.directive.ts
index 3d8e776387c0..604e81685880 100644
--- a/projects/kit/components/input-date/input-date.directive.ts
+++ b/projects/kit/components/input-date/input-date.directive.ts
@@ -1,5 +1,6 @@
import {Directive} from '@angular/core';
import type {TuiDay} from '@taiga-ui/cdk';
+import type {TuiDateFormatSettings} from '@taiga-ui/core';
import {AbstractTuiTextfieldHost, tuiAsTextfieldHost} from '@taiga-ui/core';
import type {TuiInputDateComponent} from './input-date.component';
@@ -21,6 +22,10 @@ export class TuiInputDateDirective extends AbstractTuiTextfieldHost(TUI_TEXTFIELD_HOST);
protected get value(): string {
return this.host.value.length === DATE_FILLER_LENGTH
- ? TuiDay.normalizeParse(this.host.value, this.dateFormat).toString('YMD', '-')
+ ? TuiDay.normalizeParse(this.host.value, this.host.format.mode).toString(
+ 'YMD',
+ '-',
+ )
: '';
}
@@ -38,7 +40,9 @@ export class TuiNativeDateDirective {
protected onChange(value: string): void {
this.host.onValueChange(
- value ? TuiDay.normalizeParse(value, 'YMD').toString(this.dateFormat) : '',
+ value
+ ? TuiDay.normalizeParse(value, 'YMD').toString(this.host.format.mode)
+ : '',
);
}
}
diff --git a/projects/kit/components/input-date/test/input-date.component.spec.ts b/projects/kit/components/input-date/test/input-date.component.spec.ts
index 4422696b8192..f05db180abbb 100644
--- a/projects/kit/components/input-date/test/input-date.component.spec.ts
+++ b/projects/kit/components/input-date/test/input-date.component.spec.ts
@@ -4,17 +4,18 @@ import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
+import {AbstractTuiValueTransformer, TuiDay} from '@taiga-ui/cdk';
+import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core';
import {
- AbstractTuiValueTransformer,
TUI_DATE_FORMAT,
- TUI_DATE_SEPARATOR,
- TuiDay,
-} from '@taiga-ui/cdk';
-import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core';
-import {TuiHintModule, TuiRootModule, TuiTextfieldControllerModule} from '@taiga-ui/core';
+ TuiHintModule,
+ TuiRootModule,
+ TuiTextfieldControllerModule,
+} from '@taiga-ui/core';
import {TuiInputDateComponent, TuiInputDateModule} from '@taiga-ui/kit';
import {TUI_DATE_VALUE_TRANSFORMER} from '@taiga-ui/kit/tokens';
import {TuiNativeInputPO, TuiPageObject} from '@taiga-ui/testing';
+import {of} from 'rxjs';
describe('InputDate', () => {
@Component({
@@ -186,7 +187,7 @@ describe('InputDate', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
...meta,
- providers: [{provide: TUI_DATE_FORMAT, useValue: 'YMD'}],
+ providers: [{provide: TUI_DATE_FORMAT, useValue: of({mode: 'YMD'})}],
});
await TestBed.compileComponents();
await initializeEnvironment();
@@ -233,7 +234,7 @@ describe('InputDate', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
...meta,
- providers: [{provide: TUI_DATE_FORMAT, useValue: 'MDY'}],
+ providers: [{provide: TUI_DATE_FORMAT, useValue: of({mode: 'MDY'})}],
});
await TestBed.compileComponents();
await initializeEnvironment();
@@ -281,8 +282,10 @@ describe('InputDate', () => {
TestBed.configureTestingModule({
...meta,
providers: [
- {provide: TUI_DATE_FORMAT, useValue: 'MDY'},
- {provide: TUI_DATE_SEPARATOR, useValue: '/'},
+ {
+ provide: TUI_DATE_FORMAT,
+ useValue: of({mode: 'MDY', separator: '/'}),
+ },
],
});
await TestBed.compileComponents();
diff --git a/projects/kit/components/input-number/test/input-number-format.spec.ts b/projects/kit/components/input-number/test/input-number-format.spec.ts
index d3c41f5e0f5f..73251afb7a76 100644
--- a/projects/kit/components/input-number/test/input-number-format.spec.ts
+++ b/projects/kit/components/input-number/test/input-number-format.spec.ts
@@ -5,7 +5,7 @@ import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {CHAR_NO_BREAK_SPACE} from '@taiga-ui/cdk';
import type {TuiDecimalMode} from '@taiga-ui/core';
-import {TuiNumberFormatModule, tuiNumberFormatProvider} from '@taiga-ui/core';
+import {TuiNumberFormatDirective, tuiNumberFormatProvider} from '@taiga-ui/core';
import {TuiInputNumberComponent, TuiInputNumberModule} from '@taiga-ui/kit';
import {TuiNativeInputPO} from '@taiga-ui/testing';
@@ -41,7 +41,7 @@ describe('InputNumber - backward compatibility for separators', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiInputNumberModule,
ReactiveFormsModule,
],
@@ -81,7 +81,7 @@ describe('InputNumber - backward compatibility for separators', () => {
imports: [
NoopAnimationsModule,
TuiInputNumberModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
ReactiveFormsModule,
],
declarations: [TestComponent],
diff --git a/projects/kit/components/input-number/test/input-number.component.spec.ts b/projects/kit/components/input-number/test/input-number.component.spec.ts
index 580e2dc3cfaa..5980f5b0e1c3 100644
--- a/projects/kit/components/input-number/test/input-number.component.spec.ts
+++ b/projects/kit/components/input-number/test/input-number.component.spec.ts
@@ -8,7 +8,7 @@ import {CHAR_MINUS, CHAR_NO_BREAK_SPACE} from '@taiga-ui/cdk';
import type {TuiDecimalMode, TuiSizeL, TuiSizeS} from '@taiga-ui/core';
import {
TuiHintModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
import {TuiInputNumberComponent, TuiInputNumberModule} from '@taiga-ui/kit';
@@ -65,7 +65,7 @@ describe('InputNumber', () => {
imports: [
NoopAnimationsModule,
TuiInputNumberModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
ReactiveFormsModule,
TuiTextfieldControllerModule,
TuiHintModule,
diff --git a/projects/kit/components/input-range/input-range.module.ts b/projects/kit/components/input-range/input-range.module.ts
index cc15b283a322..bfe7bb74c37d 100644
--- a/projects/kit/components/input-range/input-range.module.ts
+++ b/projects/kit/components/input-range/input-range.module.ts
@@ -3,7 +3,7 @@ import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TuiActiveZoneDirective, TuiPressedModule} from '@taiga-ui/cdk';
import {
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiTextfieldControllerModule,
TuiWrapperModule,
} from '@taiga-ui/core';
@@ -24,7 +24,7 @@ import {TuiInputRangeComponent} from './input-range.component';
TuiRangeModule,
TuiWrapperModule,
TuiTextfieldControllerModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
],
declarations: [TuiInputRangeComponent],
exports: [TuiInputRangeComponent],
diff --git a/projects/kit/components/input-slider/input-slider.module.ts b/projects/kit/components/input-slider/input-slider.module.ts
index 5a0912fb9a2a..ef08ac2d0473 100644
--- a/projects/kit/components/input-slider/input-slider.module.ts
+++ b/projects/kit/components/input-slider/input-slider.module.ts
@@ -2,7 +2,7 @@ import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TuiFocusableModule} from '@taiga-ui/cdk';
-import {TuiNumberFormatModule, TuiTextfieldControllerModule} from '@taiga-ui/core';
+import {TuiNumberFormatDirective, TuiTextfieldControllerModule} from '@taiga-ui/core';
import {TuiInputNumberModule} from '@taiga-ui/kit/components/input-number';
import {TuiSliderModule} from '@taiga-ui/kit/components/slider';
import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus';
@@ -16,7 +16,7 @@ import {TuiInputSliderComponent} from './input-slider.component';
PolymorpheusModule,
TuiFocusableModule,
TuiInputNumberModule,
- TuiNumberFormatModule,
+ TuiNumberFormatDirective,
TuiSliderModule,
TuiTextfieldControllerModule,
],