Skip to content

Commit

Permalink
feat(icons): make the rest of components icons customizable (#5046)
Browse files Browse the repository at this point in the history
Co-authored-by: tinkoff-bot <[email protected]>
Co-authored-by: Nikita Barsukov <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2023
1 parent aa2f133 commit cc0828e
Show file tree
Hide file tree
Showing 116 changed files with 463 additions and 183 deletions.
26 changes: 16 additions & 10 deletions projects/addon-commerce/components/card/card.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {ChangeDetectionStrategy, Component, HostBinding, Input} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
HostBinding,
Inject,
Input,
} from '@angular/core';
import {
TUI_INPUT_CARD_OPTIONS,
TuiInputCardOptions,
} from '@taiga-ui/addon-commerce/components/input-card';
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce/types';
import {TUI_PAYMENT_SYSTEM_ICONS} from '@taiga-ui/addon-commerce/utils';
import {TuiSizeS} from '@taiga-ui/core';

const icons: Record<TuiPaymentSystem, string> = {
...TUI_PAYMENT_SYSTEM_ICONS,
mir: 'tuiIconMirMono',
visa: 'tuiIconVisaMono',
electron: 'tuiIconElectronMono',
};

@Component({
selector: 'tui-card',
templateUrl: './card.template.html',
Expand All @@ -34,11 +36,15 @@ export class TuiCardComponent {
@HostBinding('attr.data-size')
size: TuiSizeS = 'm';

constructor(
@Inject(TUI_INPUT_CARD_OPTIONS) private readonly options: TuiInputCardOptions,
) {}

get hasBrandLogo(): boolean {
return !!this.brandLogo && this.size === 'm';
}

get paymentSystemLogo(): string {
return this.paymentSystem ? icons[this.paymentSystem] : '';
return this.paymentSystem ? this.options.icons[this.paymentSystem] : '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ import {
import {
MODE_PROVIDER,
TEXTFIELD_CONTROLLER_PROVIDER,
TUI_COMMON_ICONS,
TUI_DIGIT_REGEXP,
TUI_MODE,
TUI_NON_DIGIT_REGEXP,
TUI_TEXTFIELD_WATCHED_CONTROLLER,
tuiAsDataListHost,
TuiBrightness,
TuiCommonIcons,
TuiDataListComponent,
TuiDataListDirective,
TuiDataListHost,
TuiTextfieldController,
} from '@taiga-ui/core';
import {TUI_ARROW_OPTIONS, TuiArrowOptions} from '@taiga-ui/kit';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {Observable} from 'rxjs';

Expand Down Expand Up @@ -154,6 +157,8 @@ export class TuiInputCardGroupedComponent
readonly cardGroupedTexts$: Observable<TuiCardGroupedTexts>,
@Inject(TUI_TEXTFIELD_WATCHED_CONTROLLER)
readonly controller: TuiTextfieldController,
@Inject(TUI_COMMON_ICONS) readonly icons: TuiCommonIcons,
@Inject(TUI_ARROW_OPTIONS) readonly arrowOptions: TuiArrowOptions,
@Inject(TUI_INPUT_CARD_GROUPED_OPTIONS) options: TuiInputCardGroupedOptions,
) {
super(control, cdr, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
width: 2rem;
height: 2rem;
margin-right: 0.5rem;
// Visa logo color
color: #1434cb;
}

.t-collapsed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@
*ngIf="hasCleaner"
tuiWrapper
appearance="icon"
src="tuiIconCloseLarge"
class="t-icon"
[src]="icons.close"
(click)="clear()"
></tui-svg>
<tui-svg
*ngIf="hasDropdown"
tuiWrapper
appearance="icon"
src="tuiIconChevronDownLarge"
class="t-icon"
[class.t-icon_rotated]="open"
[src]="arrowOptions.iconLarge"
(click)="toggle()"
></tui-svg>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ describe(`InputCardGrouped`, () => {

it(`input-card-grouped have a default icon`, () => {
expect(testComponent.control.valid).toEqual(true);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisa`);
expect(testComponent.component.icon).toEqual(`tuiIconVisa`);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisaMono`);
expect(testComponent.component.icon).toEqual(`tuiIconVisaMono`);
expect(testComponent.control.value).toEqual({card: `4111 1111 1111 1111`});

expect(expectCardOutlet()).toBeFalsy();
Expand All @@ -226,7 +226,7 @@ describe(`InputCardGrouped`, () => {
testComponent.component.cardSrc = `tuiIconMastercard`;

expect(testComponent.control.valid).toEqual(true);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisa`);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisaMono`);
expect(testComponent.component.icon).toEqual(`tuiIconMastercard`);
expect(testComponent.control.value).toEqual({card: `4111 1111 1111 1111`});

Expand All @@ -240,7 +240,7 @@ describe(`InputCardGrouped`, () => {
fixture.componentInstance.customIconTemplate;

expect(testComponent.control.valid).toEqual(true);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisa`);
expect(testComponent.component.defaultIcon).toEqual(`tuiIconVisaMono`);
expect(testComponent.component.icon).toBeInstanceOf(TemplateRef);
expect(testComponent.control.value).toEqual({card: `4111 1111 1111 1111`});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export abstract class AbstractTuiInputCard<
return this.getPaymentSystem(this.card);
}

/** @deprecated remove in 4.0 */
get icon(): PolymorpheusContent {
return this.cardSrc || this.defaultIcon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core';
import {MaskitoModule} from '@maskito/angular';
import {
TuiPrimitiveTextfieldModule,
TuiSvgModule,
TuiTextfieldComponent,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
Expand All @@ -16,6 +17,7 @@ import {TuiInputCardDirective} from './input-card.directive';
TuiPrimitiveTextfieldModule,
TuiTextfieldControllerModule,
TuiValueAccessorModule,
TuiSvgModule,
],
declarations: [TuiInputCardComponent, TuiInputCardDirective],
exports: [TuiInputCardComponent, TuiInputCardDirective, TuiTextfieldComponent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TuiInputCardOptions {
>;
}

// TODO: Move payment system icons into its own token in 4.0
export const TUI_INPUT_CARD_DEFAULT_OPTIONS: TuiInputCardOptions = {
icons: TUI_PAYMENT_SYSTEM_ICONS,
cardSrc: ``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
border-radius: inherit;
text-align: inherit;
}

.t-payment-system {
width: 2rem;
height: 2rem;
// Visa logo color
color: #1434cb;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tui-primitive-textfield
tuiValueAccessor
class="t-input"
[tuiTextfieldCustomContent]="icon"
[tuiTextfieldCustomContent]="cardSrc || (defaultIcon && logo)"
[readOnly]="readOnly"
[disabled]="disabled"
[focusable]="focusable"
Expand All @@ -21,3 +21,9 @@
ngProjectAs="input"
></ng-content>
</tui-primitive-textfield>
<ng-template #logo>
<tui-svg
class="t-payment-system"
[src]="defaultIcon"
></tui-svg>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe(`InputCard`, () => {

it(`input-card component has a default icon`, () => {
expect(testComponent.control.valid).toEqual(true);
expect(testComponent.component.icon).toEqual(`tuiIconVisa`);
expect(testComponent.component.icon).toEqual(`tuiIconVisaMono`);
expect(testComponent.control.value).toEqual(`4111 1111 1111 1111`);
});

Expand Down
1 change: 1 addition & 0 deletions projects/addon-commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@taiga-ui/cdk": ">=3.39.1",
"@taiga-ui/core": ">=3.39.1",
"@taiga-ui/i18n": ">=3.39.1",
"@taiga-ui/kit": ">=3.39.1",
"@tinkoff/ng-polymorpheus": ">=4.0.0",
"rxjs": ">=6.0.0",
"tslib": ">=2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions projects/addon-commerce/utils/payment-system-icons.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce/types';

// TODO: Make it a token in 4.0, think about mono icons for card component
export const TUI_PAYMENT_SYSTEM_ICONS: Record<TuiPaymentSystem, string> = {
mir: `tuiIconMir`,
visa: `tuiIconVisa`,
electron: `tuiIconElectron`,
visa: `tuiIconVisaMono`,
electron: `tuiIconElectronMono`,
mastercard: `tuiIconMastercard`,
maestro: `tuiIconMaestro`,
amex: `tuiIconAmex`,
Expand Down
2 changes: 2 additions & 0 deletions projects/addon-doc/components/demo/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
tuiToInteger,
} from '@taiga-ui/cdk';
import {TuiBrightness, TuiModeDirective} from '@taiga-ui/core';
import {TUI_ARROW_OPTIONS, TuiArrowOptions} from '@taiga-ui/kit';
import {Subject} from 'rxjs';

const MIN_WIDTH = 160;
Expand Down Expand Up @@ -83,6 +84,7 @@ export class TuiDocDemoComponent implements OnInit {
readonly items: readonly TuiBrightness[] = ['onLight', 'onDark'];

constructor(
@Inject(TUI_ARROW_OPTIONS) readonly options: TuiArrowOptions,
@Inject(TUI_IS_MOBILE) readonly isMobile: boolean,
@Inject(ElementRef) private readonly el: ElementRef<HTMLElement>,
@Inject(Location) private readonly locationRef: Location,
Expand Down
2 changes: 1 addition & 1 deletion projects/addon-doc/components/demo/demo.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
</button>
<ng-template #icon>
<tui-svg
src="tuiIconChevronDown"
class="t-icon"
[class.t-icon_rotated]="expanded"
[src]="options.iconSmall"
></tui-svg>
</ng-template>
<tui-expand
Expand Down
2 changes: 1 addition & 1 deletion projects/addon-doc/components/example/example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class TuiDocExampleComponent {
@Inject(Router) private readonly router: Router,
@Inject(ActivatedRoute) private readonly route: ActivatedRoute,
@Inject(NgLocation) private readonly ngLocation: NgLocation,
@Inject(TUI_DOC_EXAMPLE_OPTIONS) private readonly options: TuiDocExampleOptions,
@Inject(TUI_DOC_EXAMPLE_OPTIONS) readonly options: TuiDocExampleOptions,
) {}

readonly visible = (files: Record<string, string>): boolean =>
Expand Down
2 changes: 2 additions & 0 deletions projects/addon-doc/components/example/example.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface TuiDocExampleOptions {
codeEditorVisibilityHandler: TuiBooleanHandler<Record<string, string>>;
tabTitles: Map<unknown, PolymorpheusContent>;
fullsize: boolean;
linkIcon: string;
}

export const TUI_DOC_EXAMPLE_DEFAULT_OPTIONS: TuiDocExampleOptions = {
Expand All @@ -17,6 +18,7 @@ export const TUI_DOC_EXAMPLE_DEFAULT_OPTIONS: TuiDocExampleOptions = {
),
tabTitles: new Map(),
fullsize: true,
linkIcon: `tuiIconLink`,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
tuiIconButton
type="button"
size="xs"
icon="tuiIconLink"
appearance="icon"
class="t-link-icon"
[icon]="options.linkIcon"
[title]="copy$ | async"
(click)="copyExampleLink()"
></button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {ChangeDetectionStrategy, Component, Inject} from '@angular/core';
import {Router} from '@angular/router';
import {TUI_DOC_LOGO, TUI_DOC_MENU_TEXT} from '@taiga-ui/addon-doc/tokens';
import {
TUI_DOC_ICONS,
TUI_DOC_LOGO,
TUI_DOC_MENU_TEXT,
TuiDocIcons,
} from '@taiga-ui/addon-doc/tokens';
import {ALWAYS_FALSE_HANDLER, TuiSwipeService} from '@taiga-ui/cdk';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {merge, Subject} from 'rxjs';
Expand All @@ -25,6 +30,7 @@ export class TuiDocHeaderComponent {
).pipe(startWith(false), distinctUntilChanged());

constructor(
@Inject(TUI_DOC_ICONS) readonly icons: TuiDocIcons,
@Inject(TUI_DOC_LOGO) readonly logo: PolymorpheusContent,
@Inject(TUI_DOC_MENU_TEXT) readonly menu: string,
@Inject(Router) private readonly router: Router,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<button
tuiIconButton
icon="tuiIconMenuLarge"
appearance="icon"
type="button"
class="t-menu"
[icon]="icons.menu"
[title]="menu"
(click)="onClick()"
(tuiActiveZoneChange)="onActiveZone($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {ChangeDetectionStrategy, Component, Inject, Input} from '@angular/core';
import {TuiDocSourceCodePathOptions} from '@taiga-ui/addon-doc/interfaces';
import {TUI_DOC_SOURCE_CODE, TUI_DOC_SOURCE_CODE_TEXT} from '@taiga-ui/addon-doc/tokens';
import {
TUI_DOC_ICONS,
TUI_DOC_SOURCE_CODE,
TUI_DOC_SOURCE_CODE_TEXT,
TuiDocIcons,
} from '@taiga-ui/addon-doc/tokens';
import {tuiPure} from '@taiga-ui/cdk';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

Expand All @@ -23,6 +28,7 @@ export class TuiDocSourceCodeComponent {
path = '';

constructor(
@Inject(TUI_DOC_ICONS) readonly icons: TuiDocIcons,
@Inject(TUI_DOC_SOURCE_CODE)
readonly sourceCode: PolymorpheusContent<TuiDocSourceCodePathOptions>,
@Inject(TUI_DOC_SOURCE_CODE_TEXT) readonly text: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
*polymorpheusOutlet="sourceCode as link; context: pathOptions"
tuiIconButton
type="button"
icon="tuiIconCode"
appearance="icon"
target="_blank"
size="s"
[icon]="icons.code"
[title]="text"
[href]="link"
></a>
6 changes: 6 additions & 0 deletions projects/addon-doc/components/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ViewEncapsulation,
} from '@angular/core';
import {TuiThemeNightService, TuiThemeService} from '@taiga-ui/addon-doc/services';
import {TUI_DOC_ICONS, TuiDocIcons} from '@taiga-ui/addon-doc/tokens';
import {TuiSwipeService} from '@taiga-ui/cdk';
import {TuiBrightness, TuiModeDirective} from '@taiga-ui/core';
import {distinctUntilChanged, map, share, startWith} from 'rxjs/operators';
Expand Down Expand Up @@ -38,6 +39,7 @@ export class TuiDocMainComponent {
);

constructor(
@Inject(TUI_DOC_ICONS) private readonly icons: TuiDocIcons,
@Inject(TuiThemeService) readonly theme: TuiThemeService,
@Inject(TuiThemeNightService) readonly night: TuiThemeNightService,
) {}
Expand All @@ -46,4 +48,8 @@ export class TuiDocMainComponent {
get mode(): TuiBrightness | null {
return this.night.value ? 'onDark' : null;
}

get icon(): string {
return this.night.value ? this.icons.day : this.icons.night;
}
}
2 changes: 1 addition & 1 deletion projects/addon-doc/components/main/main.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
shape="rounded"
type="button"
class="tui-doc-night-mode-switch"
[icon]="night.value ? 'tuiIconSun' : 'tuiIconMoon'"
[icon]="icon"
(click)="night.toggle()"
></button>
</header>
Expand Down
Loading

0 comments on commit cc0828e

Please sign in to comment.