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(kit): default options configuration for arrow #1251

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 24 additions & 0 deletions projects/kit/components/arrow/arrow-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {InjectionToken} from '@angular/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

export interface TuiArrowOptions {
readonly iconSmall: PolymorpheusContent;
readonly iconLarge: PolymorpheusContent;
}

// TODO: remove in ivy compilation
export const TUI_ARROW_ICON_SMALL = 'tuiIconChevronDown';
export const TUI_ARROW_ICON_LARGE = 'tuiIconChevronDownLarge';

/** Default values for arrow options */
export const TUI_ARROW_DEFAULT_OPTIONS: TuiArrowOptions = {
iconSmall: TUI_ARROW_ICON_SMALL,
iconLarge: TUI_ARROW_ICON_LARGE,
};

export const TUI_ARROW_OPTIONS = new InjectionToken<TuiArrowOptions>(
'Default parameters for arrow component',
{
factory: () => TUI_ARROW_DEFAULT_OPTIONS,
},
);
11 changes: 7 additions & 4 deletions projects/kit/components/arrow/arrow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
TuiHostedDropdownComponent,
TuiTextfieldSizeDirective,
} from '@taiga-ui/core';
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus';
import {PolymorpheusComponent, PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

import {TUI_ARROW_OPTIONS, TuiArrowOptions} from './arrow-options';

@Component({
selector: 'tui-arrow',
Expand All @@ -19,12 +21,13 @@ export class TuiArrowComponent {
readonly dropdown: TuiHostedDropdownComponent,
@Inject(TUI_TEXTFIELD_SIZE)
private readonly textfieldSize: TuiTextfieldSizeDirective,
@Inject(TUI_ARROW_OPTIONS) private readonly options: TuiArrowOptions,
) {}

get arrowIcon(): string {
get arrowIcon(): PolymorpheusContent {
return sizeBigger(this.textfieldSize.size)
? 'tuiIconChevronDownLarge'
: 'tuiIconChevronDown';
? this.options.iconLarge
: this.options.iconSmall;
}
}

Expand Down
3 changes: 2 additions & 1 deletion projects/kit/components/arrow/arrow.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {TuiSvgModule} from '@taiga-ui/core';
import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus';

import {TuiArrowComponent} from './arrow.component';

@NgModule({
imports: [CommonModule, TuiSvgModule],
imports: [CommonModule, TuiSvgModule, PolymorpheusModule],
declarations: [TuiArrowComponent],
exports: [TuiArrowComponent],
entryComponents: [TuiArrowComponent],
Expand Down
7 changes: 5 additions & 2 deletions projects/kit/components/arrow/arrow.style.less
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
@import 'taiga-ui-local';

.icon {
.transition(transform);
cursor: pointer;
pointer-events: none;

&_rotated {
> * {
GinMitch marked this conversation as resolved.
Show resolved Hide resolved
.transition(transform);
}

&_rotated > * {
transform: rotate(180deg);
}
}
11 changes: 8 additions & 3 deletions projects/kit/components/arrow/arrow.template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<tui-svg
<span
polymorpheus-outlet
class="icon"
[class.icon_rotated]="dropdown.openChange | async"
[src]="arrowIcon"
></tui-svg>
[content]="arrowIcon"
>
<ng-template let-icon>
<tui-svg [src]="icon"></tui-svg>
</ng-template>
</span>
1 change: 1 addition & 0 deletions projects/kit/components/arrow/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './arrow.component';
export * from './arrow.module';
export * from './arrow-options';