Skip to content

Commit

Permalink
feat(kit): File add ability to customize icons (#6418)
Browse files Browse the repository at this point in the history
Co-authored-by: taiga-family-bot <[email protected]>
  • Loading branch information
vladimirpotekhin and taiga-family-bot authored Jan 10, 2024
1 parent b03d8db commit a13e88a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions projects/cdk/constants/used-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export const TUI_USED_ICONS = [
'tuiIconChevronDown',
'tuiIconChevronDownLarge',
'tuiIconFileLarge',
'tuiIconTrashLarge',
'tuiIconAlertCircleLarge',
'tuiIconCheckCircleLarge',
'tuiIconAlertCircleLarge',
'tuiIconTrashLarge',
'tuiIconCopy',
'tuiIconEyeOffLarge',
'tuiIconEyeLarge',
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/constants/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const TUI_VERSION = `3.61.0`;
export const TUI_VERSION = '3.61.0';
15 changes: 14 additions & 1 deletion projects/kit/components/files/file/file-options.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import {tuiCreateToken} from '@taiga-ui/cdk';
import {TuiContextWithImplicit, 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<TuiFileState, 'loading'>,
PolymorpheusContent<TuiContextWithImplicit<TuiSizeL>>
>;
}

export const TUI_FILE_DEFAULT_OPTIONS: TuiFileOptions = {
formatSize: tuiFormatSize,
icons: {
normal: ({$implicit}) =>
$implicit === 'l' ? 'tuiIconFileLarge' : 'tuiIconCheckCircleLarge',
error: 'tuiIconAlertCircleLarge',
deleted: 'tuiIconTrashLarge',
},
};

/**
Expand Down
22 changes: 8 additions & 14 deletions projects/kit/components/files/file/file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
Output,
} from '@angular/core';
import {DomSanitizer, SafeValue} from '@angular/platform-browser';
import {TuiInjectionTokenType, tuiIsObserved, tuiPure} from '@taiga-ui/cdk';
import {
TuiContextWithImplicit,
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';
Expand Down Expand Up @@ -89,19 +94,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<TuiContextWithImplicit<TuiSizeL>> {
return this.state === 'loading' ? '' : this.options.icons[this.state];
}

@HostBinding('class._link')
Expand Down
3 changes: 2 additions & 1 deletion projects/kit/components/files/file/file.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@
</ng-template>
<ng-template #svg>
<tui-svg
*polymorpheusOutlet="icon as src; context: {$implicit: size}"
automation-id="tui-file__icon"
class="t-icon"
[class.t-icon_blank]="isBig || isDeleted"
[class.t-icon_error]="isError"
[src]="icon"
[src]="src"
></tui-svg>
</ng-template>
</ng-template>

0 comments on commit a13e88a

Please sign in to comment.