-
Notifications
You must be signed in to change notification settings - Fork 106
feat(helper-text): add pf-helper-text element #2947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bennypowers
merged 13 commits into
patternfly:main
from
dali327519294:feat/pf-helper-text
Dec 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5de6b70
feat: create pf-helper-text element
dali327519294 9a6f275
style(helper-text): improved demo page for more accurate alignment wi…
dali327519294 325d17b
refactor(docs): improve pf-helper-text code, translate comments, alig…
dali327519294 d868e40
docs(helper-text): add detailed documentation with examples and icon …
dali327519294 db4dee5
feat(helper-text): implement pf-helper-text component and refactor demos
dali327519294 1445eef
Merge remote-tracking branch 'upstream/main' into feat/pf-helper-text
dali327519294 b1020bd
Merge branch 'main' into feat/pf-helper-text
bennypowers 9f457b3
docs(helper-text): update demos
bennypowers 58baaae
fix(helper-text): simplify
bennypowers 8663749
fix: attribution
bennypowers aabe533
test: add tests
bennypowers 847a227
docs: add demo
bennypowers 2879f92
fix: revert other changes
bennypowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Helper Text | ||
| Add a description of the component here. | ||
|
|
||
| ## Usage | ||
| Describe how best to use this web component along with best practices. | ||
|
|
||
| ```html | ||
| <pf-helper-text> | ||
|
|
||
| </pf-helper-text> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <script type="module"> | ||
| import '@patternfly/elements/pf-icon/pf-icon.js'; | ||
| import '@patternfly/elements/pf-helper-text/pf-helper-text.js'; | ||
| PfIcon.addIconSet('fas', (set, icon) => { | ||
|
|
||
| return new URL(`@fortawesome/fontawesome-free/svgs/solid/${icon}.svg`, import.meta.url); | ||
| }); | ||
| </script> | ||
|
|
||
| <pf-helper-text status="warning"> | ||
| This is a warning helper text | ||
| </pf-helper-text> | ||
|
|
||
| <pf-helper-text status="error" icon="exclamation-triangle" icon-set="fas"> | ||
| This is an error helper text with icon | ||
| </pf-helper-text> | ||
|
|
||
| <pf-helper-text status="success"> | ||
| <svg slot="icon" width="16" height="16" viewBox="0 0 16 16" fill="green" xmlns="http://www.w3.org/2000/svg"> | ||
| <path d="M6 10.8L3.2 8 2 9.2l4 4 8-8-1.2-1.2L6 10.8z"/> | ||
| </svg> | ||
| This is a success helper text with slotted icon | ||
| </pf-helper-text> | ||
|
|
||
| <pf-helper-text status="indeterminate"> | ||
| This is an indeterminate helper text | ||
| </pf-helper-text> | ||
|
|
||
| <pf-helper-text icon="arrow" icon-set="patternfly"> | ||
| Custom Icon | ||
| </pf-helper-text> | ||
|
|
||
|
|
||
|
|
||
| <style> | ||
| pf-helper-text { | ||
| display: block; | ||
| margin: 1rem 0; | ||
| font-family: var(--pf-global--FontFamily--sans-serif, Arial, sans-serif); | ||
| } | ||
|
|
||
| pf-helper-text .helper-container { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| } | ||
|
|
||
| pf-helper-text .icon-container { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| pf-helper-text[status="warning"] { | ||
| color: var(--pf-global--warning-color, #f0ab00); | ||
| } | ||
|
|
||
| pf-helper-text[status="error"] { | ||
| color: var(--pf-global--danger-color, #c9190b); | ||
| } | ||
|
|
||
| pf-helper-text[status="success"] { | ||
| color: var(--pf-global--success-color, #3e8635); | ||
| } | ||
|
|
||
| pf-helper-text[status="indeterminate"] { | ||
| color: var(--pf-global--info-color, #06c); | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| {% renderOverview %} | ||
| <pf-helper-text></pf-helper-text> | ||
| {% endrenderOverview %} | ||
|
|
||
| {% band header="Usage" %}{% endband %} | ||
|
|
||
| {% renderSlots %}{% endrenderSlots %} | ||
|
|
||
| {% renderAttributes %}{% endrenderAttributes %} | ||
|
|
||
| {% renderMethods %}{% endrenderMethods %} | ||
|
|
||
| {% renderEvents %}{% endrenderEvents %} | ||
|
|
||
| {% renderCssCustomProperties %}{% endrenderCssCustomProperties %} | ||
|
|
||
| {% renderCssParts %}{% endrenderCssParts %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| :host { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 0.4rem; | ||
| font-size: 14px; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| .helper-container { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 0.4rem; | ||
| } | ||
|
|
||
| :host([status="error"]) { | ||
| color: var(--pf-global--danger-color--100, #c9190b); | ||
| } | ||
|
|
||
| :host([status="warning"]) { | ||
| color: var(--pf-global--warning-color--100, #f0ab00); | ||
| } | ||
|
|
||
| :host([status="success"]) { | ||
| color: var(--pf-global--success-color--100, #3e8635); | ||
| } | ||
|
|
||
| :host([status="indeterminate"]) { | ||
| color: var(--pf-global--palette--black-600, #6a6e73); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import '@patternfly/elements/pf-icon/pf-icon.js'; | ||
| import { LitElement, html, type TemplateResult } from 'lit'; | ||
| import { customElement } from 'lit/decorators/custom-element.js'; | ||
| import { property } from 'lit/decorators/property.js'; | ||
| import { ifDefined } from 'lit/directives/if-defined.js'; | ||
|
|
||
| import styles from './pf-helper-text.css'; | ||
|
|
||
| /** | ||
| * Helper Text Statuses | ||
| */ | ||
| export type HelperTextStatus = 'default' | 'success' | 'warning' | 'error' | 'indeterminate'; | ||
|
|
||
| /** | ||
| * Helper Text | ||
| * @slot icon - Custom icon to override default | ||
| * @slot - Place element content here | ||
|
dali327519294 marked this conversation as resolved.
Outdated
|
||
| */ | ||
| @customElement('pf-helper-text') | ||
| export class PfHelperText extends LitElement { | ||
| static readonly styles: CSSStyleSheet[] = [styles]; | ||
|
|
||
| /** | ||
| * Defines the helper text status and its corresponding icon. | ||
| * Options include 'default', 'success', 'warning', 'error', 'indeterminate'. | ||
| */ | ||
| @property({ attribute: 'status' }) | ||
| status: HelperTextStatus = 'default'; | ||
|
|
||
| /** | ||
| * The icon name to use. Overrides the default icon for a given status. | ||
| * Requires pf-icon to be imported. | ||
| */ | ||
| @property({ attribute: 'icon' }) | ||
| icon: string | undefined; | ||
|
|
||
| /** | ||
| * The icon set to use, e.g., 'fas' for Font Awesome Solid. | ||
| * Required when using the 'icon' property. | ||
| */ | ||
| @property({ attribute: 'icon-set' }) | ||
| iconSet: string | undefined; | ||
|
|
||
| /** | ||
| * מחשב את האייקון שיוצג, בהתבסס על הסטטוס או המאפיין icon | ||
|
dali327519294 marked this conversation as resolved.
Outdated
|
||
| */ | ||
| private get _iconName(): string | undefined { | ||
| // אם המשתמש הגדיר אייקון ספציפי, השתמש בו | ||
| if (this.icon) { | ||
| return this.icon; | ||
| } | ||
|
|
||
| // אם לא הוגדר אייקון ספציפי, החזר אייקון ברירת מחדל לפי הסטטוס | ||
| switch (this.status) { | ||
| case 'success': | ||
| return 'circle-check'; | ||
| case 'warning': | ||
| return 'exclamation-triangle'; | ||
| case 'error': | ||
| return 'exclamation-circle'; | ||
| case 'indeterminate': | ||
| return 'minus-circle'; | ||
| default: | ||
| return undefined; // במצב 'default' אין אייקון ברירת מחדל | ||
| } | ||
| } | ||
|
|
||
| // בקובץ pf-helper-text.ts | ||
| render(): TemplateResult<1> { | ||
| const iconName = this._iconName; // מקבל את שם האייקון או undefined | ||
| const hasIcon = !!iconName; | ||
|
|
||
| return html` | ||
|
|
||
| <slot name="icon"> | ||
|
|
||
| ${hasIcon ? | ||
| html` | ||
| <pf-icon icon="${iconName}" set="${ifDefined(this.iconSet)}" ></pf-icon> | ||
|
|
||
| ` | ||
| : ''} | ||
| </slot> | ||
|
|
||
| <slot></slot> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'pf-helper-text': PfHelperText; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { test } from '@playwright/test'; | ||
| import { PfeDemoPage } from '@patternfly/pfe-tools/test/playwright/PfeDemoPage.js'; | ||
| import { SSRPage } from '@patternfly/pfe-tools/test/playwright/SSRPage.js'; | ||
|
|
||
| const tagName = 'pf-helper-text'; | ||
|
|
||
| test.describe(tagName, () => { | ||
| test('snapshot', async ({ page }) => { | ||
| const componentPage = new PfeDemoPage(page, tagName); | ||
| await componentPage.navigate(); | ||
| await componentPage.snapshot(); | ||
| }); | ||
|
|
||
| test('ssr', async ({ browser }) => { | ||
| const fixture = new SSRPage({ | ||
| tagName, | ||
| browser, | ||
| demoDir: new URL('../demo/', import.meta.url), | ||
| importSpecifiers: [ | ||
| `@patternfly/elements/${tagName}/${tagName}.js`, | ||
| ], | ||
| }); | ||
| await fixture.snapshots(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { expect, html } from '@open-wc/testing'; | ||
| import { createFixture } from '@patternfly/pfe-tools/test/create-fixture.js'; | ||
| import { PfHelperText } from '@patternfly/elements/pf-helper-text/pf-helper-text.js'; | ||
|
|
||
| describe('<pf-helper-text>', function() { | ||
| describe('simply instantiating', function() { | ||
| let element: PfHelperText; | ||
| it('imperatively instantiates', function() { | ||
| expect(document.createElement('pf-helper-text')).to.be.an.instanceof(PfHelperText); | ||
| }); | ||
|
|
||
| it('should upgrade', async function() { | ||
| element = await createFixture<PfHelperText>(html`<pf-helper-text></pf-helper-text>`); | ||
| const klass = customElements.get('pf-helper-text'); | ||
| expect(element) | ||
| .to.be.an.instanceOf(klass) | ||
| .and | ||
| .to.be.an.instanceOf(PfHelperText); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.