From 95adfd735d658ff1ad8fcdd2086c64d5bbf74b6f Mon Sep 17 00:00:00 2001 From: Dennis Walker Date: Thu, 26 Jun 2025 04:11:06 +0600 Subject: [PATCH 1/2] Add icon in Storybook --- .../entity-logo/entity-logo.component.html | 4 +- .../entity-logo.component.stories.ts | 59 +++++++++++++++++++ .../lib/entity-logo/entity-logo.component.ts | 32 ++++++++-- 3 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 libs/ui/src/lib/entity-logo/entity-logo.component.stories.ts diff --git a/libs/ui/src/lib/entity-logo/entity-logo.component.html b/libs/ui/src/lib/entity-logo/entity-logo.component.html index f0abad285..692fb1d3b 100644 --- a/libs/ui/src/lib/entity-logo/entity-logo.component.html +++ b/libs/ui/src/lib/entity-logo/entity-logo.component.html @@ -1,4 +1,6 @@ -@if (src) { +@if (useLogo) { + +} @else if (src) { ; + +type Story = StoryObj; + +export const Default: Story = { + args: { + dataSource: DataSource.MANUAL, + symbol: 'GHOST', + useLogo: true, + size: 'large' + } +}; + +export const WithUrl: Story = { + args: { + size: 'large', + tooltip: 'Ghostfolio', + url: 'https://ghostfol.io', + useLogo: true + } +}; diff --git a/libs/ui/src/lib/entity-logo/entity-logo.component.ts b/libs/ui/src/lib/entity-logo/entity-logo.component.ts index 7598fb4d5..4d2f56b26 100644 --- a/libs/ui/src/lib/entity-logo/entity-logo.component.ts +++ b/libs/ui/src/lib/entity-logo/entity-logo.component.ts @@ -1,17 +1,21 @@ import { CommonModule } from '@angular/common'; +import { HttpClient } from '@angular/common/http'; import { - CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, + ChangeDetectorRef, Component, Input, OnChanges } from '@angular/core'; import { DataSource } from '@prisma/client'; +import { of } from 'rxjs'; +import { catchError } from 'rxjs/operators'; + +import { GfLogoComponent } from '../logo/logo.component'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, - imports: [CommonModule], - schemas: [CUSTOM_ELEMENTS_SCHEMA], + imports: [CommonModule, GfLogoComponent], selector: 'gf-entity-logo', styleUrls: ['./entity-logo.component.scss'], templateUrl: './entity-logo.component.html' @@ -22,14 +26,34 @@ export class GfEntityLogoComponent implements OnChanges { @Input() symbol: string; @Input() tooltip: string; @Input() url: string; + @Input() useLogo = false; public src: string; + public constructor( + private readonly changeDetectorRef: ChangeDetectorRef, + private readonly http: HttpClient + ) {} + public ngOnChanges() { + if (this.useLogo) { + return; + } + if (this.dataSource && this.symbol) { this.src = `../api/v1/logo/${this.dataSource}/${this.symbol}`; } else if (this.url) { - this.src = `../api/v1/logo?url=${this.url}`; + this.http + .get<{ logoUrl: string }>(`../api/v1/logo?url=${this.url}`) + .pipe( + catchError(() => { + return of({ logoUrl: '' }); + }) + ) + .subscribe(({ logoUrl }) => { + this.src = logoUrl; + this.changeDetectorRef.markForCheck(); + }); } } } From 7117a62341b264a6859e0124beeb960919de7118 Mon Sep 17 00:00:00 2001 From: Dennis Walker Date: Sat, 28 Jun 2025 06:12:59 +0600 Subject: [PATCH 2/2] Reverted all the changes exceprt Storybook. --- .../entity-logo/entity-logo.component.html | 4 +- .../entity-logo.component.stories.ts | 78 ++++++++++++------- .../lib/entity-logo/entity-logo.component.ts | 32 +------- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/libs/ui/src/lib/entity-logo/entity-logo.component.html b/libs/ui/src/lib/entity-logo/entity-logo.component.html index 692fb1d3b..f0abad285 100644 --- a/libs/ui/src/lib/entity-logo/entity-logo.component.html +++ b/libs/ui/src/lib/entity-logo/entity-logo.component.html @@ -1,6 +1,4 @@ -@if (useLogo) { - -} @else if (src) { +@if (src) { ([ [ '../api/v1/logo?url=https://ghostfol.io', - { - logoUrl: '/assets/ghost.svg' - } + { logoUrl: '/assets/ghost.svg' } ] ]) ) } ] }) - ] + ], + parameters: { + backgrounds: { + default: 'light' + } + }, + argTypes: { + size: { + control: 'select', + options: ['large', 'medium'], + description: 'Size of the logo' + }, + tooltip: { + control: 'text', + description: 'Tooltip text for the logo' + }, + url: { + control: 'text', + description: 'URL for the logo' + } + } } as Meta; type Story = StoryObj; export const Default: Story = { - args: { - dataSource: DataSource.MANUAL, - symbol: 'GHOST', - useLogo: true, - size: 'large' - } -}; - -export const WithUrl: Story = { args: { size: 'large', tooltip: 'Ghostfolio', - url: 'https://ghostfol.io', - useLogo: true - } + url: 'https://ghostfol.io' + }, + parameters: { + docs: { + description: { + story: + 'Entity logo component with size ("large"), tooltip ("Ghostfolio") and url ("https://ghostfol.io") inputs.' + } + } + }, + render: (args) => ({ + props: args, + template: ` +
+ +
+ ` + }) }; diff --git a/libs/ui/src/lib/entity-logo/entity-logo.component.ts b/libs/ui/src/lib/entity-logo/entity-logo.component.ts index 4d2f56b26..7598fb4d5 100644 --- a/libs/ui/src/lib/entity-logo/entity-logo.component.ts +++ b/libs/ui/src/lib/entity-logo/entity-logo.component.ts @@ -1,21 +1,17 @@ import { CommonModule } from '@angular/common'; -import { HttpClient } from '@angular/common/http'; import { + CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, - ChangeDetectorRef, Component, Input, OnChanges } from '@angular/core'; import { DataSource } from '@prisma/client'; -import { of } from 'rxjs'; -import { catchError } from 'rxjs/operators'; - -import { GfLogoComponent } from '../logo/logo.component'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, - imports: [CommonModule, GfLogoComponent], + imports: [CommonModule], + schemas: [CUSTOM_ELEMENTS_SCHEMA], selector: 'gf-entity-logo', styleUrls: ['./entity-logo.component.scss'], templateUrl: './entity-logo.component.html' @@ -26,34 +22,14 @@ export class GfEntityLogoComponent implements OnChanges { @Input() symbol: string; @Input() tooltip: string; @Input() url: string; - @Input() useLogo = false; public src: string; - public constructor( - private readonly changeDetectorRef: ChangeDetectorRef, - private readonly http: HttpClient - ) {} - public ngOnChanges() { - if (this.useLogo) { - return; - } - if (this.dataSource && this.symbol) { this.src = `../api/v1/logo/${this.dataSource}/${this.symbol}`; } else if (this.url) { - this.http - .get<{ logoUrl: string }>(`../api/v1/logo?url=${this.url}`) - .pipe( - catchError(() => { - return of({ logoUrl: '' }); - }) - ) - .subscribe(({ logoUrl }) => { - this.src = logoUrl; - this.changeDetectorRef.markForCheck(); - }); + this.src = `../api/v1/logo?url=${this.url}`; } } }