From 0d975434b5bc4f8b32212af892e46e958ddcb936 Mon Sep 17 00:00:00 2001 From: mdlufy Date: Wed, 25 Sep 2024 16:26:49 +0300 Subject: [PATCH] chore(demo): `Dropdown` add reuse component & migrate example to new approach --- .../demo/src/components/dropdown/index.html | 75 +++++++++++++++++++ .../demo/src/components/dropdown/index.ts | 44 +++++++++++ .../modules/directives/dropdown/index.html | 45 +++++------ .../src/modules/directives/dropdown/index.ts | 2 + 4 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 projects/demo/src/components/dropdown/index.html create mode 100644 projects/demo/src/components/dropdown/index.ts diff --git a/projects/demo/src/components/dropdown/index.html b/projects/demo/src/components/dropdown/index.html new file mode 100644 index 000000000000..82e50df9acb2 --- /dev/null +++ b/projects/demo/src/components/dropdown/index.html @@ -0,0 +1,75 @@ + + + + + Dropdown + + Applied as a host directive + + + + + Manual control/monitor for the dropdown being visible + + + Align of dropdown (does not work together with + limitWidth === 'fixed' + ) + + + Set a vertical direction of dropdown + + + Limit width of dropdown + + + Minimum height to calculate that dropdown fits to set + tuiDropdownDirection + + + Maximum height of dropdown + + + Dropdown offset + diff --git a/projects/demo/src/components/dropdown/index.ts b/projects/demo/src/components/dropdown/index.ts new file mode 100644 index 000000000000..3bd908e976a7 --- /dev/null +++ b/projects/demo/src/components/dropdown/index.ts @@ -0,0 +1,44 @@ +import {ChangeDetectionStrategy, Component, Input} from '@angular/core'; +import {RouterLink} from '@angular/router'; +import {DemoRoute} from '@demo/routes'; +import {TuiDocAPIItem} from '@taiga-ui/addon-doc'; +import { + TuiDropdown, + type TuiDropdownAlign, + type TuiDropdownWidth, + TuiLink, + TuiTitle, + type TuiVerticalDirection, +} from '@taiga-ui/core'; + +@Component({ + standalone: true, + selector: 'tbody[tuiDocDropdown]', + imports: [RouterLink, TuiDocAPIItem, TuiDropdown, TuiLink, TuiTitle], + templateUrl: './index.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class TuiDocDropdown { + protected readonly routes = DemoRoute; + + protected readonly aligns: readonly TuiDropdownAlign[] = ['left', 'right', 'center']; + protected readonly directions: TuiVerticalDirection[] = ['bottom', 'top']; + protected readonly limitWidths: readonly TuiDropdownWidth[] = [ + 'auto', + 'min', + 'fixed', + ]; + + @Input() + public tuiDocDropdown: readonly string[] | '' = ''; + + public open = false; + + public align: TuiDropdownAlign = 'left'; + public direction: TuiVerticalDirection | null = null; + public limitWidth: TuiDropdownWidth = 'fixed'; + public minHeight = 80; + public maxHeight = 400; + public offset = 4; + public appearance = ''; +} diff --git a/projects/demo/src/modules/directives/dropdown/index.html b/projects/demo/src/modules/directives/dropdown/index.html index 68a7c0ccc39c..aedba824643d 100644 --- a/projects/demo/src/modules/directives/dropdown/index.html +++ b/projects/demo/src/modules/directives/dropdown/index.html @@ -49,13 +49,13 @@ tuiButton type="button" [tuiDropdown]="dropdownContent" - [tuiDropdownAlign]="dropdownAlign" - [tuiDropdownDirection]="dropdownDirection" - [tuiDropdownLimitWidth]="dropdownLimitWidth" - [tuiDropdownManual]="open" - [tuiDropdownMaxHeight]="dropdownMaxHeight" - [tuiDropdownMinHeight]="dropdownMinHeight" - [tuiDropdownOffset]="dropdownOffset" + [tuiDropdownAlign]="dropdown.align" + [tuiDropdownDirection]="dropdown.direction" + [tuiDropdownLimitWidth]="dropdown.limitWidth" + [tuiDropdownManual]="dropdown.open" + [tuiDropdownMaxHeight]="dropdown.maxHeight" + [tuiDropdownMinHeight]="dropdown.minHeight" + [tuiDropdownOffset]="dropdown.offset" (click)="onClick()" (tuiObscured)="onObscured($event)" > @@ -78,24 +78,27 @@ - - + Show dropdown (basic manual implementation, see related pages for other options) - - + Content - - - + + + diff --git a/projects/demo/src/modules/directives/dropdown/index.ts b/projects/demo/src/modules/directives/dropdown/index.ts index 93c3354efc6a..92ad5694fff5 100644 --- a/projects/demo/src/modules/directives/dropdown/index.ts +++ b/projects/demo/src/modules/directives/dropdown/index.ts @@ -1,4 +1,5 @@ import {Component, forwardRef} from '@angular/core'; +import {TuiDocDropdown} from '@demo/components/dropdown'; import {changeDetection} from '@demo/emulate/change-detection'; import {DemoRoute} from '@demo/routes'; import {TuiDemo} from '@demo/utils'; @@ -16,6 +17,7 @@ import {DropdownDocumentation} from '../../components/abstract/dropdown-document TuiActiveZone, TuiButton, TuiDemo, + TuiDocDropdown, TuiDropdown, TuiObscured, ],