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): File add ability to customize icons #6417

Merged
merged 2 commits into from
Jan 10, 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
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
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 {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<TuiFileState, 'loading'>,
PolymorpheusContent<TuiContext<TuiSizeL>>
>;
}

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

/**
Expand Down
17 changes: 3 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,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';
Expand Down Expand Up @@ -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<TuiContext<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>
Loading