From f0de26b5131a69ab31236c26cc75bb5b195ddfd9 Mon Sep 17 00:00:00 2001 From: mdlufy Date: Fri, 27 Sep 2024 12:53:16 +0300 Subject: [PATCH] chore(demo): `Textfield` add reuse component & migrate `TextfieldController` to new approach --- .../demo/src/components/textfield/index.html | 57 +++++++++++++++++++ .../demo/src/components/textfield/index.ts | 41 +++++++++++++ .../textfield-controller/index.html | 55 ++++-------------- .../directives/textfield-controller/index.ts | 30 +--------- 4 files changed, 110 insertions(+), 73 deletions(-) create mode 100644 projects/demo/src/components/textfield/index.html create mode 100644 projects/demo/src/components/textfield/index.ts diff --git a/projects/demo/src/components/textfield/index.html b/projects/demo/src/components/textfield/index.html new file mode 100644 index 000000000000..6158dc2c1dfb --- /dev/null +++ b/projects/demo/src/components/textfield/index.html @@ -0,0 +1,57 @@ + + + + + Textfield + + Applied as a host directive + + + + + Shows a cross to reset a value + + + Right content (e.g. avatar with maximum size 32x32px) + + + Label is outside a component and made with + + Label + + + + Size + diff --git a/projects/demo/src/components/textfield/index.ts b/projects/demo/src/components/textfield/index.ts new file mode 100644 index 000000000000..8b51c9155aca --- /dev/null +++ b/projects/demo/src/components/textfield/index.ts @@ -0,0 +1,41 @@ +import {NgIf} from '@angular/common'; +import {ChangeDetectionStrategy, Component, inject, Input} from '@angular/core'; +import {RouterLink} from '@angular/router'; +import {DemoRoute} from '@demo/routes'; +import {TuiDocAPIItem} from '@taiga-ui/addon-doc'; +import type {TuiLooseUnion} from '@taiga-ui/cdk'; +import { + TUI_TEXTFIELD_OPTIONS, + TuiLink, + type TuiSizeL, + type TuiSizeS, + type TuiTextfieldOptions, + TuiTitle, +} from '@taiga-ui/core'; + +@Component({ + standalone: true, + selector: 'tbody[tuiDocTextfield]', + imports: [NgIf, RouterLink, TuiDocAPIItem, TuiLink, TuiTitle], + templateUrl: './index.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class TuiDocTextfield { + private readonly options = inject(TUI_TEXTFIELD_OPTIONS); + + protected readonly routes = DemoRoute; + + protected readonly sizeVariants: ReadonlyArray = ['s', 'm', 'l']; + protected readonly customContentVariants = ['', '@tui.bell']; + + @Input() + public tuiDocTextfield: readonly string[] | '' = ''; + + @Input() + public hiddenOptions: Array> = []; + + public cleaner: boolean = this.options.cleaner(); + public size: TuiSizeL | TuiSizeS = this.options.size(); + public labelOutside = false; + public customContent = this.customContentVariants[0]; +} diff --git a/projects/demo/src/modules/directives/textfield-controller/index.html b/projects/demo/src/modules/directives/textfield-controller/index.html index 088fa2eb3010..2e03a9135000 100644 --- a/projects/demo/src/modules/directives/textfield-controller/index.html +++ b/projects/demo/src/modules/directives/textfield-controller/index.html @@ -47,56 +47,21 @@ Hello - - - Shows a cross to reset a value - - - Right content (e.g. avatar with maximum size 32x32px) - - - Label is outside a component and made with - - Label - - - - Size - - + + +
diff --git a/projects/demo/src/modules/directives/textfield-controller/index.ts b/projects/demo/src/modules/directives/textfield-controller/index.ts index 851c2b125875..61610789c490 100644 --- a/projects/demo/src/modules/directives/textfield-controller/index.ts +++ b/projects/demo/src/modules/directives/textfield-controller/index.ts @@ -1,9 +1,9 @@ import {Component} from '@angular/core'; import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms'; +import {TuiDocTextfield} from '@demo/components/textfield'; import {changeDetection} from '@demo/emulate/change-detection'; import {DemoRoute} from '@demo/routes'; import {TuiDemo} from '@demo/utils'; -import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core'; import {TuiTextfield} from '@taiga-ui/core'; import {TuiInputModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy'; @@ -12,6 +12,7 @@ import {TuiInputModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy'; imports: [ ReactiveFormsModule, TuiDemo, + TuiDocTextfield, TuiInputModule, TuiTextfield, TuiTextfieldControllerModule, @@ -20,33 +21,6 @@ import {TuiInputModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy'; changeDetection, }) export default class Page { - protected readonly sizeVariants: ReadonlyArray = ['s', 'm', 'l']; - - protected readonly inputModeVariants: readonly string[] = ['text', 'numeric']; - - protected readonly maxLengthVariants: readonly number[] = [10]; - - protected readonly typeVariants: readonly string[] = [ - 'text', - 'email', - 'password', - 'tel', - 'url', - ]; - - protected type = this.typeVariants[0]!; - - protected readonly customContentVariants = ['', 'Bell']; - - protected customContentSelected = this.customContentVariants[0]!; - - protected cleaner = false; - protected exampleText = ''; - protected labelOutside = false; - protected size = this.sizeVariants[2]!; - protected inputMode = this.inputModeVariants[0]!; - protected maxLength: number | null = null; - protected readonly control = new FormControl('111', Validators.required); protected readonly routes = DemoRoute; }