From 14b78342fadd53cffc7ac080d4555e1ddbc46a47 Mon Sep 17 00:00:00 2001 From: vladimirpotekhin Date: Wed, 10 Jan 2024 16:59:22 +0300 Subject: [PATCH 1/2] feat(kit): `File` add ability to customize icons --- .../kit/components/files/file/file-options.ts | 15 ++++++++++++++- .../kit/components/files/file/file.component.ts | 17 +++-------------- .../components/files/file/file.template.html | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/projects/kit/components/files/file/file-options.ts b/projects/kit/components/files/file/file-options.ts index c9102d5e941a..8aedad517089 100644 --- a/projects/kit/components/files/file/file-options.ts +++ b/projects/kit/components/files/file/file-options.ts @@ -1,15 +1,28 @@ -import {tuiCreateToken} from '@taiga-ui/cdk'; +import {TuiContext, tuiCreateToken} from '@taiga-ui/cdk'; +import {TuiSizeL} from '@taiga-ui/core'; +import {TuiFileState} from '@taiga-ui/kit/types'; import {tuiFormatSize} from '@taiga-ui/kit/utils'; +import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; export interface TuiFileOptions { readonly formatSize: ( units: [string, string, string], size?: number, ) => string | null; + readonly icons: Record< + Exclude, + PolymorpheusContent> + >; } export const TUI_FILE_DEFAULT_OPTIONS: TuiFileOptions = { formatSize: tuiFormatSize, + icons: { + normal: ({$implicit}) => + $implicit === 'l' ? 'tuiIconFileLarge' : 'tuiIconCheckCircleLarge', + error: 'tuiIconAlertCircleLarge', + deleted: 'tuiIconTrashLarge', + }, }; /** diff --git a/projects/kit/components/files/file/file.component.ts b/projects/kit/components/files/file/file.component.ts index 921a9cce2bc3..c1f127e88a4a 100644 --- a/projects/kit/components/files/file/file.component.ts +++ b/projects/kit/components/files/file/file.component.ts @@ -8,7 +8,7 @@ import { Output, } from '@angular/core'; import {DomSanitizer, SafeValue} from '@angular/platform-browser'; -import {TuiInjectionTokenType, tuiIsObserved, tuiPure} from '@taiga-ui/cdk'; +import {TuiContext, TuiInjectionTokenType, tuiIsObserved, tuiPure} from '@taiga-ui/cdk'; import {TUI_COMMON_ICONS, TuiCommonIcons, TuiSizeL} from '@taiga-ui/core'; import {TuiLanguage} from '@taiga-ui/i18n'; import {TuiFileLike} from '@taiga-ui/kit/interfaces'; @@ -88,19 +88,8 @@ export class TuiFileComponent { return this.showDelete && tuiIsObserved(this.removed); } - get icon(): string { - if (this.state === 'normal' && this.isBig) { - return 'tuiIconFileLarge'; - } - - switch (this.state) { - case 'deleted': - return 'tuiIconTrashLarge'; - case 'error': - return 'tuiIconAlertCircleLarge'; - default: - return 'tuiIconCheckCircleLarge'; - } + get icon(): PolymorpheusContent> { + return this.state === 'loading' ? '' : this.options.icons[this.state]; } @HostBinding('class._link') diff --git a/projects/kit/components/files/file/file.template.html b/projects/kit/components/files/file/file.template.html index 778b994445bc..ff57d857515b 100644 --- a/projects/kit/components/files/file/file.template.html +++ b/projects/kit/components/files/file/file.template.html @@ -92,11 +92,12 @@ From 395d6e29242ea0ccce1e319f354f43a20fe175b1 Mon Sep 17 00:00:00 2001 From: taiga-family-bot Date: Wed, 10 Jan 2024 14:59:37 +0000 Subject: [PATCH 2/2] chore: icons have changed [bot] --- projects/cdk/constants/used-icons.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/cdk/constants/used-icons.ts b/projects/cdk/constants/used-icons.ts index 890cd5266033..60585e8fe509 100644 --- a/projects/cdk/constants/used-icons.ts +++ b/projects/cdk/constants/used-icons.ts @@ -54,9 +54,9 @@ export const TUI_USED_ICONS = [ 'tuiIconChevronDown', 'tuiIconChevronDownLarge', 'tuiIconFileLarge', - 'tuiIconTrashLarge', - 'tuiIconAlertCircleLarge', 'tuiIconCheckCircleLarge', + 'tuiIconAlertCircleLarge', + 'tuiIconTrashLarge', 'tuiIconCopy', 'tuiIconEyeOffLarge', 'tuiIconEyeLarge',