|
1 | 1 | # `<pf-helper-text>` |
2 | 2 |
|
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. |
| 3 | +The **pf-helper-text** component provides contextual feedback messages for form fields or other UI elements. |
| 4 | +It visually communicates states such as success, warning, error, or informational messages. |
| 5 | +The component can display a default status icon or a fully custom icon provided through a slot or property. |
| 6 | + |
| 7 | +Read more about dropdown in the [PatternFly Elements Dropdown |
| 8 | +documentation](https://patternflyelements.org/components/dropdown) |
5 | 9 |
|
6 | 10 | --- |
| 11 | +## Installation |
7 | 12 |
|
8 | | -## Usage |
| 13 | +Load `<pf-helper-text>` via CDN: |
| 14 | + |
| 15 | +```html |
| 16 | +<script src="https://jspm.dev/@patternfly/elements/pf-helper-text/pf-helper-text.js"></script> |
| 17 | + |
| 18 | +<script src="https://jspm.dev/@patternfly/elements/pf-icon/pf-icon.js"></script> |
| 19 | +``` |
| 20 | + |
| 21 | +Or, if you are using [NPM](https://npm.im), install it |
9 | 22 |
|
10 | | -Import the component before using it: |
| 23 | +```bash |
| 24 | +npm install @patternfly/elements |
| 25 | +``` |
| 26 | + |
| 27 | +Then once installed, import it to your application: |
11 | 28 |
|
12 | 29 | ```js |
13 | 30 | import '@patternfly/elements/pf-helper-text/pf-helper-text.js'; |
14 | 31 | import '@patternfly/elements/pf-icon/pf-icon.js'; |
15 | 32 |
|
16 | | -import '@patternfly/elements/pf-helper-text/pf-helper-text.js'; |
17 | | -import '@patternfly/elements/pf-icon/pf-icon.js'; |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
18 | 37 | ```html |
19 | | -<pf-helper-text status="warning"> |
20 | | - This is a warning helper text |
| 38 | +<script type="module"> |
| 39 | + import '@patternfly/elements/pf-icon/pf-icon.js'; |
| 40 | + import '@patternfly/elements/pf-helper-text/pf-helper-text.js'; |
| 41 | +
|
| 42 | + // Optional: add FontAwesome icon set |
| 43 | + PfIcon.addIconSet('fas', (set, icon) => { |
| 44 | + return new URL(`@fortawesome/fontawesome-free/svgs/solid/${icon}.svg`, import.meta.url); |
| 45 | + }); |
| 46 | +</script> |
| 47 | +
|
| 48 | +<pf-helper-text> |
| 49 | + This is default helper text |
| 50 | +</pf-helper-text> |
| 51 | +
|
| 52 | +<pf-helper-text status="indeterminate" icon="minus" icon-set="fas"> |
| 53 | + This is indeterminate helper text |
21 | 54 | </pf-helper-text> |
22 | 55 |
|
23 | | -<pf-helper-text status="error" icon="exclamation-triangle" icon-set="fas"> |
24 | | - This is an error helper text with icon |
| 56 | +<pf-helper-text status="warning" icon="exclamation-triangle" icon-set="fas"> |
| 57 | + This is warning helper text |
25 | 58 | </pf-helper-text> |
26 | 59 |
|
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 |
| 60 | +<pf-helper-text status="success" icon="check-circle" icon-set="fas"> |
| 61 | + This is success helper text |
32 | 62 | </pf-helper-text> |
33 | 63 |
|
| 64 | +<pf-helper-text status="error" icon="exclamation-circle" icon-set="fas"> |
| 65 | + This is error helper text |
| 66 | +</pf-helper-text> |
| 67 | +
|
| 68 | +<style> |
| 69 | +pf-helper-text { |
| 70 | + display: block; |
| 71 | + margin: 1rem 0; |
| 72 | + font-family: var(--pf-global--FontFamily--sans-serif, Arial, sans-serif); |
| 73 | +} |
| 74 | +
|
| 75 | +pf-helper-text:not([status]) { |
| 76 | + color: var(--pf-global--Color--100, #151515); |
| 77 | +} |
| 78 | +pf-helper-text[status="indeterminate"] { |
| 79 | + color: var(--pf-global--Color--200, #6a6e73); |
| 80 | +} |
| 81 | +pf-helper-text[status="warning"] { |
| 82 | + color: var(--pf-global--warning-color--100, #f0ab00); |
| 83 | +} |
| 84 | +pf-helper-text[status="success"] { |
| 85 | + color: var(--pf-global--success-color--100, #3e8635); |
| 86 | +} |
| 87 | +pf-helper-text[status="error"] { |
| 88 | + color: var(--pf-global--danger-color--100, #c9190b); |
| 89 | +} |
| 90 | +
|
| 91 | +pf-helper-text [slot="icon"], |
| 92 | +pf-icon { |
| 93 | + fill: currentColor; |
| 94 | +} |
| 95 | +</style> |
| 96 | +
|
34 | 97 |
|
35 | 98 | ``` |
| 99 | +## Slots |
| 100 | +
|
| 101 | +| Name | Description | |
| 102 | +|------------|----------------------------------------------------------------------------------------| |
| 103 | +| `icon` | Optional named slot for providing a custom icon.<br>Overrides the default status icon. | |
| 104 | +| (default) | Default unnamed slot for the helper text content (text or other inline elements). | |
| 105 | +
|
| 106 | +Properties |
| 107 | +
|
| 108 | +|Name | Type | Default | Description| |
| 109 | +| ----- |-----------------------------------------------------|---------|-------------------------- |
| 110 | +|status |'default','success','warning','error','indeterminate'|'default'| Defines the visual state of the helper text and determines which default icon is shown if no custom icon is provided.| |
| 111 | +|icon | string |undefined| Custom icon name to display. Overrides the default icon derived from status. Requires pf-icon to be imported.| |
| 112 | +|iconSet| string |undefined| Icon set to use when specifying a custom icon (e.g., 'fas').| |
| 113 | +
|
| 114 | +## Events |
| 115 | +
|
| 116 | +| Event Name | Description | |
| 117 | +| ------------ | -------------------------------------------------------------------------------- | |
| 118 | +| `icon-load` | Fired when a custom or default icon successfully loads. | |
| 119 | +| `icon-error` | Fired if the icon fails to load. The event’s `detail` contains the error object. | |
| 120 | +
|
| 121 | +## Default Icons by Status |
| 122 | +
|
| 123 | +| Status | Default Icon | |
| 124 | +| --------------- | ---------------------- | |
| 125 | +| `default` | *(none)* | |
| 126 | +| `indeterminate` | `minus-circle` | |
| 127 | +| `warning` | `exclamation-triangle` | |
| 128 | +| `success` | `circle-check` | |
| 129 | +| `error` | `exclamation-circle` | |
| 130 | +
|
| 131 | +## Notes |
| 132 | +
|
| 133 | +Providing a custom <slot name="icon"> overrides the default icon. |
| 134 | +
|
| 135 | +Icons are lazy-loaded (loading="lazy") to optimize performance. |
| 136 | +
|
| 137 | +The pf-icon element must be imported if using built-in icons. |
| 138 | +
|
| 139 | +The component emits icon-load and icon-error events to track icon state. |
| 140 | +
|
| 141 | +
|
0 commit comments