Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Dropdown add appearance option #4795

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Directive, ElementRef, Inject, NgZone, Output} from '@angular/core';
import {WINDOW} from '@ng-web-apis/common';
import {tuiIfMap, tuiIsFalsy, tuiTypedFromEvent, tuiZonefull} from '@taiga-ui/cdk';
import {merge, Observable} from 'rxjs';
import {distinctUntilChanged, filter, startWith} from 'rxjs/operators';
import {TUI_ANIMATIONS_DURATION} from '@taiga-ui/core';
import {merge, Observable, timer} from 'rxjs';
import {distinctUntilChanged, filter, startWith, switchMap} from 'rxjs/operators';

import {TuiSheetComponent} from '../../components/sheet/sheet.component';
import {TUI_SHEET_CLOSE} from '../../components/sheet-heading/sheet-heading.component';
Expand All @@ -16,7 +17,8 @@ export class TuiSheetCloseDirective {
// eslint-disable-next-line @angular-eslint/no-output-native
readonly close: Observable<unknown> = merge(
tuiTypedFromEvent(this.el.nativeElement, TUI_SHEET_CLOSE),
this.dragged$.pipe(
timer(this.duration).pipe(
switchMap(() => this.dragged$),
startWith(false),
tuiIfMap(
() => this.scroll$.pipe(startWith(this.el.nativeElement.scrollTop)),
Expand All @@ -30,6 +32,7 @@ export class TuiSheetCloseDirective {

constructor(
@Inject(NgZone) private readonly ngZone: NgZone,
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Inject(TUI_SHEET_DRAGGED) private readonly dragged$: Observable<boolean>,
@Inject(TUI_SHEET_SCROLL) private readonly scroll$: Observable<number>,
@Inject(WINDOW) private readonly win: Window,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface TuiDropdownOptions {
readonly minHeight: number;
readonly maxHeight: number;
readonly offset: number;
readonly appearance: string;
}

/** Default values for dropdown options */
Expand All @@ -32,6 +33,7 @@ export const TUI_DROPDOWN_DEFAULT_OPTIONS: TuiDropdownOptions = {
maxHeight: 400,
minHeight: 80,
offset: 4,
appearance: '',
};

/**
Expand All @@ -57,7 +59,7 @@ export const tuiDropdownOptionsProvider: (

@Directive({
selector:
'[tuiDropdownAlign], [tuiDropdownDirection], [tuiDropdownLimitWidth], [tuiDropdownMinHeight], [tuiDropdownMaxHeight], [tuiDropdownOffset]',
'[tuiDropdownAlign], [tuiDropdownAppearance], [tuiDropdownDirection], [tuiDropdownLimitWidth], [tuiDropdownMinHeight], [tuiDropdownMaxHeight], [tuiDropdownOffset]',
providers: [
{
provide: TUI_DROPDOWN_OPTIONS,
Expand All @@ -69,6 +71,9 @@ export class TuiDropdownOptionsDirective implements TuiDropdownOptions {
@Input('tuiDropdownAlign')
align = this.options.align;

@Input('tuiDropdownAppearance')
appearance = this.options.appearance;

@Input('tuiDropdownDirection')
direction = this.options.direction;

Expand Down
15 changes: 11 additions & 4 deletions projects/core/directives/dropdown/dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {
tuiRectAccessorFor,
} from '@taiga-ui/core/abstract';
import {tuiDropdownAnimation} from '@taiga-ui/core/animations';
import {MODE_PROVIDER} from '@taiga-ui/core/providers';
import {TuiPositionService, TuiVisualViewportService} from '@taiga-ui/core/services';
import {TUI_ANIMATION_OPTIONS} from '@taiga-ui/core/tokens';
import {TuiPoint} from '@taiga-ui/core/types';
import {TUI_ANIMATION_OPTIONS, TUI_MODE} from '@taiga-ui/core/tokens';
import {TuiBrightness, TuiPoint} from '@taiga-ui/core/types';
import {Observable} from 'rxjs';
import {map, takeUntil} from 'rxjs/operators';

Expand All @@ -45,9 +46,14 @@ import {TUI_DROPDOWN_OPTIONS, TuiDropdownOptions} from './dropdown-options.direc
TuiPositionService,
tuiPositionAccessorFor('dropdown'),
tuiRectAccessorFor('dropdown', TuiDropdownDirective),
MODE_PROVIDER,
],
animations: [tuiDropdownAnimation],
host: {'[@tuiDropdownAnimation]': 'animation'},
host: {
'[@tuiDropdownAnimation]': 'animation',
'[attr.data-appearance]': 'options.appearance',
'($.data-mode.attr)': 'mode$',
},
// @bad TODO: OnPush
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
changeDetection: ChangeDetectionStrategy.Default,
Expand All @@ -64,7 +70,8 @@ export class TuiDropdownComponent implements OnDestroy {
private readonly host: AbstractTuiPortalHostComponent,
@Inject(TuiRectAccessor) private readonly accessor: TuiRectAccessor,
@Inject(WINDOW) private readonly win: Window,
@Inject(TUI_DROPDOWN_OPTIONS) private readonly options: TuiDropdownOptions,
@Inject(TUI_MODE) readonly mode$: Observable<TuiBrightness | null>,
@Inject(TUI_DROPDOWN_OPTIONS) readonly options: TuiDropdownOptions,
@Optional()
@Inject(TuiDropdownHoverDirective)
private readonly hoverDirective: TuiDropdownHoverDirective | null,
Expand Down
2 changes: 0 additions & 2 deletions projects/core/directives/dropdown/dropdown.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {NgModule} from '@angular/core';
import {TuiActiveZoneModule, TuiHoveredModule, TuiOverscrollModule} from '@taiga-ui/cdk';
import {TuiScrollbarModule} from '@taiga-ui/core/components/scrollbar';
import {TuiModeModule} from '@taiga-ui/core/directives/mode';
import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus';

import {TuiDropdownComponent} from './dropdown.component';
Expand All @@ -22,7 +21,6 @@ import {TuiDropdownSelectionDirective} from './dropdown-selection.directive';
TuiActiveZoneModule,
TuiOverscrollModule,
TuiScrollbarModule,
TuiModeModule,
TuiHoveredModule,
],
declarations: [
Expand Down
17 changes: 9 additions & 8 deletions projects/core/directives/dropdown/dropdown.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.shadow(2);
position: absolute;
display: flex;
background-color: var(--tui-elevation-01);
background: var(--tui-elevation-01);
border-radius: var(--tui-radius-m);
overflow: hidden;
border: 1px solid var(--tui-base-04);
Expand All @@ -20,17 +20,18 @@
&:not([style*='top']) {
visibility: hidden;
}
}

.t-wrapper {
flex-grow: 1;
max-width: 100%;
max-height: inherit;
overflow: visible;
&[data-mode='onDark'] {
--tui-text-01: var(--tui-text-01-night);
--tui-clear: var(--tui-clear-inverse);
background: #222;
border: 1px solid #808080;
}
}

.t-scroll {
height: 100%;
flex-grow: 1;
max-width: 100%;
}

.t-primitive {
Expand Down
37 changes: 17 additions & 20 deletions projects/core/directives/dropdown/dropdown.template.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<div
<tui-scrollbar
#activeZone="tuiActiveZone"
tuiActiveZone
tuiOverscroll="all"
class="t-wrapper"
[tuiMode]="null"
class="t-scroll"
(tuiHoveredChange)="onHoveredChange($event)"
>
<tui-scrollbar class="t-scroll">
<div
tabindex="0"
(focus)="onTopFocus()"
></div>
<div
*polymorpheusOutlet="directive.content as text; context: {$implicit: activeZone}"
class="t-primitive"
>
{{ text }}
</div>
<div
tabindex="0"
(focus)="onBottomFocus()"
></div>
</tui-scrollbar>
</div>
<div
tabindex="0"
(focus)="onTopFocus()"
></div>
<div
*polymorpheusOutlet="directive.content as text; context: {$implicit: activeZone}"
class="t-primitive"
>
{{ text }}
</div>
<div
tabindex="0"
(focus)="onBottomFocus()"
></div>
</tui-scrollbar>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {TuiDocExample} from '@taiga-ui/addon-doc';
changeDetection,
})
export class ExampleTuiTabsComponent {
buttons = ['button 1', 'button 2', 'button 3', 'button 4'];
buttons = ['Button 1', 'Button 2', 'Button 3', 'Button 4'];

readonly exampleModule = import('./examples/import/import-module.md?raw');
readonly exampleHtml = import('./examples/import/insert-template.md?raw');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class ExampleTuiDropdownComponent extends AbstractExampleTuiDropdown {
HTML: import('./examples/3/index.html?raw'),
};

readonly example4: TuiDocExample = {
TypeScript: import('./examples/4/index.ts?raw'),
HTML: import('./examples/4/index.html?raw'),
LESS: import('./examples/4/index.less?raw'),
};

open = false;

onClick(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {FormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
import {TuiActiveZoneModule, TuiObscuredModule} from '@taiga-ui/cdk';
import {TuiButtonModule, TuiDropdownModule, TuiLinkModule} from '@taiga-ui/core';
import {
TuiButtonModule,
TuiDropdownModule,
TuiLinkModule,
TuiNotificationModule,
} from '@taiga-ui/core';
import {
TuiAvatarModule,
TuiInputModule,
Expand All @@ -18,6 +23,7 @@ import {ExampleTuiDropdownComponent} from './dropdown.component';
import {TuiDropdownExample1} from './examples/1';
import {TuiDropdownExample2} from './examples/2';
import {TuiDropdownExample3} from './examples/3';
import {TuiDropdownExample4} from './examples/4';

@NgModule({
imports: [
Expand All @@ -33,15 +39,17 @@ import {TuiDropdownExample3} from './examples/3';
TuiActiveZoneModule,
TuiToggleModule,
TuiInputModule,
TuiNotificationModule,
TuiAddonDocModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiDropdownComponent)),
DropdownDocumentationModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiDropdownComponent)),
],
declarations: [
ExampleTuiDropdownComponent,
TuiDropdownExample1,
TuiDropdownExample2,
TuiDropdownExample3,
TuiDropdownExample4,
],
exports: [ExampleTuiDropdownComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
>
<tui-dropdown-example-3></tui-dropdown-example-3>
</tui-doc-example>

<tui-doc-example
id="appearance"
heading="Appearance"
[content]="example4"
>
<tui-notification class="tui-space_bottom-3">
Use unencapsulated styles to customize dropdown appearance
</tui-notification>
<tui-dropdown-example-4></tui-dropdown-example-4>
</tui-doc-example>
</ng-template>

<ng-template pageTab>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<span (tuiActiveZoneChange)="onActiveZone($event)">
<button
tuiButton
type="button"
iconRight="tuiIconChevronDown"
[tuiDropdown]="dropdownContent"
[tuiDropdownManual]="open"
(tuiObscured)="onObscured($event)"
(click)="onClick()"
>
Choose
</button>
<button
tuiButton
type="button"
iconRight="tuiIconChevronDown"
[tuiDropdown]="dropdownContent"
[tuiDropdownManual]="open"
(tuiObscured)="onObscured($event)"
(click)="onClick()"
(tuiActiveZoneChange)="onActiveZone($event)"
>
Choose
<ng-template #dropdownContent>
<div class="dropdown">But there is nothing to choose...</div>
</ng-template>
</span>
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<label
tuiDropdownDirection="top"
tuiDropdownAlign="center"
tuiDropdownAppearance="round"
[tuiDropdown]="content"
[tuiDropdownManual]="open"
>
<tui-toggle
size="l"
class="tui-space_right-2"
[(ngModel)]="open"
></tui-toggle>
Show dropdown
<ng-template #content>
<blockquote>I'm a customized dropdown!</blockquote>
</ng-template>
</label>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tui-dropdown[data-appearance='round'] {
border-radius: 10rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';

@Component({
selector: 'tui-dropdown-example-4',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation: ViewEncapsulation.None,
changeDetection,
})
export class TuiDropdownExample4 {
open = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
margin: 0 0.5rem;
border-radius: var(--tui-radius-s);
padding: 0 0.625rem;
color: var(--tui-text-02);
color: var(--tui-text-01);

&:before {
display: none;
Expand All @@ -74,7 +74,6 @@
&:focus,
&._active {
box-shadow: none;
color: var(--tui-base-08);
background: var(--tui-clear);
}
}
Expand Down