@@ -2,6 +2,7 @@ import { LitElement, html, isServer, type TemplateResult } from 'lit';
22import { customElement } from 'lit/decorators/custom-element.js' ;
33import { property } from 'lit/decorators/property.js' ;
44import { classMap } from 'lit/directives/class-map.js' ;
5+ import { ifDefined } from 'lit/directives/if-defined.js' ;
56
67import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js' ;
78
@@ -68,6 +69,9 @@ export class PfLabel extends LitElement {
6869 /** Text label for a removable label's close button */
6970 @property ( { attribute : 'close-button-label' } ) closeButtonLabel ?: string ;
7071
72+ /** When set, the label becomes a link. The label text renders inside an anchor element. */
73+ @property ( { reflect : true } ) href ?: string ;
74+
7175 /** Represents the state of the anonymous and icon slots */
7276 #slots = new SlotController ( this , null , 'icon' ) ;
7377
@@ -79,15 +83,17 @@ export class PfLabel extends LitElement {
7983 }
8084
8185 override render ( ) : TemplateResult < 1 > {
82- const { compact, truncated } = this ;
86+ const { compact, truncated, href } = this ;
8387 const { variant, color, icon } = this ;
8488 const hasIcon = ! ! icon || this . #slots. hasSlotted ( 'icon' ) ;
89+ const isLink = ! ! href ;
8590 return html `
8691 < span id ="container "
8792 class ="${ classMap ( {
8893 hasIcon,
8994 compact,
9095 truncated,
96+ link : isLink ,
9197 [ variant ?? '' ] : ! ! variant ,
9298 [ color ?? '' ] : ! ! color } ) } ">
9399 <!-- slot:
@@ -101,7 +107,11 @@ export class PfLabel extends LitElement {
101107 .icon ="${ this . icon || undefined as unknown as string } "> </ pf-icon >
102108 </ slot >
103109 <!-- summary: Must contain the text for the label. -->
110+ ${ isLink ? html `
111+ < a id ="link " href ="${ ifDefined ( href ) } "> < slot id ="text "> </ slot > </ a >
112+ ` : html `
104113 < slot id ="text "> </ slot >
114+ ` }
105115 <!-- summary: container for removable labels' close button -->
106116 < span part ="close-button " ?hidden =${ ! this . removable } >
107117 < pf-button plain
0 commit comments