Skip to content

Commit 325d17b

Browse files
committed
refactor(docs): improve pf-helper-text code, translate comments, align docs with pf-icon
1 parent 9a6f275 commit 325d17b

File tree

2 files changed

+84
-33
lines changed

2 files changed

+84
-33
lines changed

elements/pf-helper-text/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
# Helper Text
2-
Add a description of the component here.
1+
# `<pf-helper-text>`
32

4-
## Usage
5-
Describe how best to use this web component along with best practices.
3+
The **pf-helper-text** component provides contextual helper messages that indicate status, such as success, warning, error, or informational messages.
4+
It can include icons and supports custom content via slots.
65

6+
---
7+
8+
## Usage
9+
10+
Import the component before using it:
11+
12+
```js
13+
import '@patternfly/elements/pf-helper-text/pf-helper-text.js';
14+
import '@patternfly/elements/pf-icon/pf-icon.js';
15+
16+
import '@patternfly/elements/pf-helper-text/pf-helper-text.js';
17+
import '@patternfly/elements/pf-icon/pf-icon.js';
718
```html
8-
<pf-helper-text>
19+
<pf-helper-text status="warning">
20+
This is a warning helper text
21+
</pf-helper-text>
922
23+
<pf-helper-text status="error" icon="exclamation-triangle" icon-set="fas">
24+
This is an error helper text with icon
1025
</pf-helper-text>
26+
27+
<pf-helper-text status="success">
28+
<svg slot="icon" width="16" height="16" viewBox="0 0 16 16" fill="green" xmlns="http://www.w3.org/2000/svg">
29+
<path d="M6 10.8L3.2 8 2 9.2l4 4 8-8-1.2-1.2L6 10.8z"/>
30+
</svg>
31+
This is a success helper text with slotted icon
32+
</pf-helper-text>
33+
34+
1135
```

elements/pf-helper-text/pf-helper-text.ts

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,108 @@ import { ifDefined } from 'lit/directives/if-defined.js';
77
import 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
*/
1213
export 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')
2035
export 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

Comments
 (0)