Skip to content

Commit

Permalink
chore(demo): Dropdown add reuse component & migrate example to new …
Browse files Browse the repository at this point in the history
…approach
  • Loading branch information
mdlufy committed Sep 25, 2024
1 parent 61170a6 commit 0d97543
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 21 deletions.
75 changes: 75 additions & 0 deletions projects/demo/src/components/dropdown/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<tr>
<td colspan="3">
<span tuiTitle>
<a
tuiLink
[routerLink]="routes.Dropdown"
>
<strong>Dropdown</strong>
</a>
<span tuiSubtitle>Applied as a host directive</span>
</span>
</td>
</tr>
<tr
name="[(tuiDropdownOpen)]"
tuiDocAPIItem
type="boolean"
[(value)]="open"
>
Manual control/monitor for the dropdown being visible
</tr>
<tr
name="[tuiDropdownAlign]"
tuiDocAPIItem
type="tuiDropdownAlign"
[items]="aligns"
[(value)]="align"
>
Align of dropdown (does not work together with
<code>limitWidth === 'fixed'</code>
)
</tr>
<tr
name="[tuiDropdownDirection]"
tuiDocAPIItem
type="TuiVerticalDirection | null"
[items]="directions"
[(value)]="direction"
>
Set a vertical direction of dropdown
</tr>
<tr
name="[tuiDropdownLimitWidth]"
tuiDocAPIItem
type="TuiDropdownWidth"
[items]="limitWidths"
[(value)]="limitWidth"
>
Limit width of dropdown
</tr>
<tr
name="[tuiDropdownMinHeight]"
tuiDocAPIItem
type="number"
[(value)]="minHeight"
>
Minimum height to calculate that dropdown fits to set
<code>tuiDropdownDirection</code>
</tr>
<tr
name="[tuiDropdownMaxHeight]"
tuiDocAPIItem
type="number"
[(value)]="maxHeight"
>
Maximum height of dropdown
</tr>
<tr
name="[tuiDropdownOffset]"
tuiDocAPIItem
type="number"
[(value)]="offset"
>
Dropdown offset
</tr>
44 changes: 44 additions & 0 deletions projects/demo/src/components/dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -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 = '';
}
45 changes: 24 additions & 21 deletions projects/demo/src/modules/directives/dropdown/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
>
Expand All @@ -78,24 +78,27 @@
</ng-template>
</span>
</tui-doc-demo>
<tui-doc-documentation>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="tuiDropdownManual"
documentationPropertyType="boolean"
[(documentationPropertyValue)]="open"
<table tuiDocAPI>
<tr
name="[tuiDropdownManual]"
tuiDocAPIItem
type="boolean"
[(value)]="open"
>
Show dropdown (basic manual implementation, see related pages for other options)
</ng-template>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="tuiDropdown"
documentationPropertyType="PolymorpheusContent"
</tr>
<tr
name="[tuiDropdown]"
tuiDocAPIItem
type="PolymorpheusContent"
>
Content
</ng-template>
<dropdown-documentation />
</tui-doc-documentation>
</tr>
<tbody
#dropdown
tuiDocDropdown
></tbody>
</table>
</ng-template>

<tui-setup *pageTab />
Expand Down
2 changes: 2 additions & 0 deletions projects/demo/src/modules/directives/dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,6 +17,7 @@ import {DropdownDocumentation} from '../../components/abstract/dropdown-document
TuiActiveZone,
TuiButton,
TuiDemo,
TuiDocDropdown,
TuiDropdown,
TuiObscured,
],
Expand Down

0 comments on commit 0d97543

Please sign in to comment.