@@ -7,81 +7,108 @@ import { ifDefined } from 'lit/directives/if-defined.js';
77import styles from './pf-helper-text.css' ;
88
99/**
10- * Helper Text Statuses
10+ * Status types for helper text.
11+ * Determines which default icon to show if no custom icon is provided.
1112 */
1213export type HelperTextStatus = 'default' | 'success' | 'warning' | 'error' | 'indeterminate' ;
1314
1415/**
1516 * Helper Text
16- * @slot icon - Custom icon to override default
17- * @slot - Place element content here
17+ *
18+ * Provides contextual feedback for form fields or UI elements.
19+ * Allows showing default icons based on status or custom icons via properties or slotted content.
20+ *
21+ * Slots:
22+ * - `icon`: optional slot to override the default icon
23+ * - default slot: place any text/content
24+ *
25+ * Properties:
26+ * - `status`: sets the helper text status and chooses a default icon
27+ * - `icon`: custom icon name (overrides default)
28+ * - `iconSet`: icon set to use when `icon` is specified
29+ *
30+ * Events:
31+ * - `icon-load`: fired when the icon successfully loads
32+ * - `icon-error`: fired if loading the icon fails, includes the error detail
1833 */
1934@customElement ( 'pf-helper-text' )
2035export class PfHelperText extends LitElement {
36+ /** Static styles for the component */
2137 static readonly styles : CSSStyleSheet [ ] = [ styles ] ;
2238
2339 /**
24- * Defines the helper text status and its corresponding icon.
25- * Options include 'default', 'success', 'warning', 'error', 'indeterminate'.
40+ * The helper text status.
41+ * Options: 'default' | 'success' | 'warning' | 'error' | 'indeterminate'
42+ * Determines the default icon if no custom icon is provided.
2643 */
2744 @property ( { attribute : 'status' } )
2845 status : HelperTextStatus = 'default' ;
2946
3047 /**
31- * The icon name to use. Overrides the default icon for a given status.
48+ * Name of a custom icon to display.
49+ * Overrides the default icon associated with the status.
3250 * Requires pf-icon to be imported.
3351 */
3452 @property ( { attribute : 'icon' } )
3553 icon : string | undefined ;
3654
3755 /**
38- * The icon set to use, e.g., 'fas' for Font Awesome Solid .
39- * Required when using the ' icon' property.
56+ * Icon set to use for the custom icon .
57+ * Required when specifying the ` icon` property.
4058 */
4159 @property ( { attribute : 'icon-set' } )
4260 iconSet : string | undefined ;
4361
4462 /**
45- * מחשב את האייקון שיוצג, בהתבסס על הסטטוס או המאפיין icon
63+ * Computes the icon name to display.
64+ * - Returns `icon` if defined
65+ * - Otherwise maps `status` to a default icon
66+ * - Returns undefined if no icon should be shown (status 'default')
4667 */
4768 private get _iconName ( ) : string | undefined {
48- // אם המשתמש הגדיר אייקון ספציפי, השתמש בו
69+ // Use custom icon if provided
4970 if ( this . icon ) {
5071 return this . icon ;
5172 }
5273
53- // אם לא הוגדר אייקון ספציפי, החזר אייקון ברירת מחדל לפי הסטטוס
74+ // Map status to default icons
5475 switch ( this . status ) {
55- case 'success' :
56- return 'circle-check' ;
57- case 'warning' :
58- return 'exclamation-triangle' ;
59- case 'error' :
60- return 'exclamation-circle' ;
61- case 'indeterminate' :
62- return 'minus-circle' ;
63- default :
64- return undefined ; // במצב 'default' אין אייקון ברירת מחדל
76+ case 'success' : return 'circle-check' ;
77+ case 'warning' : return 'exclamation-triangle' ;
78+ case 'error' : return 'exclamation-circle' ;
79+ case 'indeterminate' : return 'minus-circle' ;
80+ default : return undefined ; // no icon for default status
6581 }
6682 }
6783
68- // בקובץ pf-helper-text.ts
84+ /**
85+ * Render method for the helper text element.
86+ * - Renders `<pf-icon>` if there is an icon
87+ * - Supports lazy loading to optimize performance
88+ * - Fires `icon-load` and `icon-error` events from pf-icon
89+ * - Provides slots for custom icons and text content
90+ */
6991 render ( ) : TemplateResult < 1 > {
70- const iconName = this . _iconName ; // מקבל את שם האייקון או undefined
92+ const iconName = this . _iconName ;
7193 const hasIcon = ! ! iconName ;
7294
7395 return html `
74-
96+ <!-- Slot for user-defined icon. If none is provided, render pf-icon -->
7597 < slot name ="icon ">
76-
7798 ${ hasIcon ?
7899 html `
79- < pf-icon icon ="${ iconName } " set ="${ ifDefined ( this . iconSet ) } " > </ pf-icon >
80-
100+ < pf-icon
101+ icon ="${ iconName } " <!-- icon name from _iconName -->
102+ set ="${ ifDefined ( this . iconSet ) } " <!-- optional icon set -->
103+ loading ="lazy " <!-- defer loading until needed -->
104+ @load =${ ( ) => this . dispatchEvent ( new CustomEvent ( 'icon-load' , { bubbles : true } ) ) }
105+ @error =${ ( e : Event ) => this . dispatchEvent ( new CustomEvent ( 'icon-error' , { bubbles : true , detail : e } ) ) }
106+ > </ pf-icon >
81107 `
82108 : '' }
83109 </ slot >
84-
110+
111+ <!-- Default slot for helper text content -->
85112 < slot > </ slot >
86113 ` ;
87114 }
0 commit comments