1- import {
2- Component ,
3- computed ,
4- EventEmitter ,
5- HostBinding ,
6- inject ,
7- Input ,
8- input ,
9- Output ,
10- ElementRef ,
11- Renderer2 ,
12- AfterViewInit ,
13- OnDestroy ,
14- } from '@angular/core' ;
1+ import { Component , HostBinding , inject , input , ElementRef , Renderer2 , AfterViewInit , OnDestroy , output } from '@angular/core' ;
152import { CommonModule } from '@angular/common' ;
163import { Card } from 'primeng/card' ;
17- import { FeatureData } from '../models/feature-detail.model' ;
18- import { FeatureDetailPopupService } from '../feature-detail/services/feature-detail-popup-service' ;
4+ import { FeatureData } from '../models/feature-detail/feature-detail.model' ;
5+ import { PopupService } from '../services/popup/popup.service' ;
6+ import { FeatureDetailComponent } from '../feature-detail/feature-detail.component' ;
197
20- export type RoleType = 'product-showcase' ;
8+ export type RoleType = 'product-showcase' | 'product-showcase-small' ;
219
2210@Component ( {
2311 selector : 'garuda-card' ,
12+ standalone : true ,
2413 imports : [ CommonModule , Card ] ,
2514 templateUrl : './card.component.html' ,
26- styleUrl : './card.component.scss' ,
15+ styleUrls : [ './card.component.scss' ] ,
2716 host : {
2817 class : 'garuda-card' ,
2918 } ,
3019} )
3120export class CardComponent implements AfterViewInit , OnDestroy {
3221 cardRole = input . required < RoleType > ( ) ;
33- @Input ( ) feature ?: FeatureData ;
34- @Input ( ) actionFeatures ?: Record < string , FeatureData > = { } ;
35- @Output ( ) actionClicked : EventEmitter < string > = new EventEmitter < string > ( ) ;
22+ link = input < string | undefined > ( '' ) ;
23+ feature = input < FeatureData > ( ) ;
24+ actionFeatures = input < Record < string , FeatureData > > ( { } ) ;
25+ actionClicked = output < string > ( ) ;
3626
37- private featureDetailPopupService = inject ( FeatureDetailPopupService ) ;
27+ private popupService = inject ( PopupService ) ;
3828 private el = inject ( ElementRef < HTMLElement > ) ;
3929 private renderer = inject ( Renderer2 ) ;
4030 private removeClickListener ?: ( ) => void ;
4131
4232 @HostBinding ( 'class.garuda-card__product-showcase' )
43- private productShowcaseClass = computed ( ( ) => this . cardRole ( ) === 'product-showcase' ) ;
33+ get isProductShowcase ( ) : boolean {
34+ return this . cardRole ( ) === 'product-showcase' ;
35+ }
36+
37+ @HostBinding ( 'class.garuda-card__product-showcase-small' )
38+ get isProductShowcaseSmall ( ) : boolean {
39+ return this . cardRole ( ) === 'product-showcase-small' ;
40+ }
4441
4542 ngAfterViewInit ( ) : void {
46- //data-action
4743 this . removeClickListener = this . renderer . listen ( this . el . nativeElement , 'click' , ( event : Event ) => {
4844 const target = event . target as HTMLElement ;
4945 const actionElement = target . closest ( '[garudaCardAction], [data-action]' ) as HTMLElement | null ;
5046 const action = actionElement ?. dataset ?. [ 'action' ] ;
47+
5148 if ( action ) {
5249 event . stopPropagation ( ) ;
5350 this . openDetail ( action ) ;
@@ -61,9 +58,16 @@ export class CardComponent implements AfterViewInit, OnDestroy {
6158
6259 openDetail ( action : string ) : void {
6360 this . actionClicked . emit ( action ) ;
64- const featureData = this . actionFeatures ?. [ action ] || this . feature ;
65- if ( featureData ) {
66- this . featureDetailPopupService . open ( featureData ) ;
61+
62+ const featureData = this . actionFeatures ( ) ?. [ action ] || this . feature ;
63+ if ( ! featureData ) return ;
64+
65+ this . popupService . open ( FeatureDetailComponent , { data : { feature : featureData } , title : featureData ?. title , showHeader : false } ) ;
66+ }
67+
68+ navigate ( ) {
69+ if ( this . link ) {
70+ window . location . href = this . link ( ) ?? '' ;
6771 }
6872 }
6973}
0 commit comments