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(experimental): ThumbnailCard add DI options #8155

Merged
merged 1 commit into from
Jul 24, 2024
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
Expand Up @@ -2,6 +2,7 @@ import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce';
import {TuiDocExample} from '@taiga-ui/addon-doc';
import {ALWAYS_TRUE_HANDLER, TuiBooleanHandler} from '@taiga-ui/cdk';
import {TuiSizeL, TuiSizeS} from '@taiga-ui/core';

@Component({
Expand Down Expand Up @@ -52,5 +53,12 @@ export class ExampleTuiThumbnailCardComponent {
sizeVariants: ReadonlyArray<TuiSizeL | TuiSizeS> = ['s', 'm', 'l'];
size = this.sizeVariants[1];

monoHandlerVariants: ReadonlyArray<TuiBooleanHandler<TuiPaymentSystem>> = [
ps => ps === 'mir' || ps === 'visa' || ps === 'electron',
ALWAYS_TRUE_HANDLER,
];

monoHandler = this.monoHandlerVariants[0];

paymentSystem: TuiPaymentSystem | null = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<tui-thumbnail-card
[iconLeft]="iconLeft"
[iconRight]="iconRight"
[monoHandler]="monoHandler"
[paymentSystem]="paymentSystem"
[size]="size"
>
Expand All @@ -61,6 +62,15 @@
>
Icon on the right
</ng-template>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="monoHandler"
documentationPropertyType="TuiBooleanHandler<TuiPaymentSystem>"
[documentationPropertyValues]="monoHandlerVariants"
[(documentationPropertyValue)]="monoHandler"
>
Whether to use colored icon for particular payment system
</ng-template>
<ng-template
documentationPropertyMode="input"
documentationPropertyName="paymentSystem"
Expand Down
1 change: 1 addition & 0 deletions projects/experimental/components/thumbnail-card/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './thumbnail-card.component';
export * from './thumbnail-card.module';
export * from './thumbnail-card.options';
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
Inject,
Input,
} from '@angular/core';
import {
TUI_INPUT_CARD_OPTIONS,
TuiInputCardOptions,
TuiPaymentSystem,
} from '@taiga-ui/addon-commerce';
import {TuiStringHandler} from '@taiga-ui/cdk';
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce';
import {TuiBooleanHandler, TuiStringHandler} from '@taiga-ui/cdk';
import {TuiSizeL, TuiSizeS} from '@taiga-ui/core';
import {TUI_ICON_RESOLVER} from '@taiga-ui/experimental/tokens';

import {
TUI_THUMBNAIL_CARD_OPTIONS,
TuiThumbnailCardOptions,
} from './thumbnail-card.options';

@Component({
selector: 'tui-thumbnail-card',
templateUrl: './thumbnail-card.template.html',
Expand All @@ -23,7 +24,7 @@ import {TUI_ICON_RESOLVER} from '@taiga-ui/experimental/tokens';
export class TuiThumbnailCardComponent {
@Input()
@HostBinding('attr.data-size')
size: TuiSizeL | TuiSizeS = 'm';
size: TuiSizeL | TuiSizeS = this.options.size;

@Input()
paymentSystem: TuiPaymentSystem | null = null;
Expand All @@ -34,20 +35,11 @@ export class TuiThumbnailCardComponent {
@Input()
iconRight = '';

@Input()
monoHandler: TuiBooleanHandler<TuiPaymentSystem> = this.options.monoHandler;

constructor(
@Inject(TUI_ICON_RESOLVER) readonly resolver: TuiStringHandler<string>,
@Inject(TUI_INPUT_CARD_OPTIONS) readonly options: TuiInputCardOptions,
@Inject(TUI_THUMBNAIL_CARD_OPTIONS) readonly options: TuiThumbnailCardOptions,
) {}

// TODO: Revisit this approach in 4.0 when icons are moved away from InputCard options
get isMono(): boolean {
switch (this.paymentSystem) {
case 'mir':
case 'visa':
case 'electron':
return true;
default:
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {TUI_PAYMENT_SYSTEM_ICONS, TuiPaymentSystem} from '@taiga-ui/addon-commerce';
import {TuiBooleanHandler, tuiCreateToken} from '@taiga-ui/cdk';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core';

export interface TuiThumbnailCardOptions {
readonly size: TuiSizeL | TuiSizeS;
readonly icons: Record<TuiPaymentSystem, string>;
readonly monoHandler: TuiBooleanHandler<TuiPaymentSystem>;
}

export const TUI_THUMBNAIL_CARD_OPTIONS = tuiCreateToken<TuiThumbnailCardOptions>({
icons: TUI_PAYMENT_SYSTEM_ICONS,
size: 'm',
monoHandler: ps => ps === 'mir' || ps === 'visa' || ps === 'electron',
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ng-content></ng-content>
<ng-container *ngIf="paymentSystem">
<tui-icon
*ngIf="isMono; else colored"
*ngIf="monoHandler(paymentSystem); else colored"
class="t-logo"
[icon]="options.icons[paymentSystem]"
></tui-icon>
Expand Down
Loading