-
Notifications
You must be signed in to change notification settings - Fork 115
chore: add helper for react-icons #8147
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
Changes from all commits
65cc0f7
90f98dc
787e55b
a7caabf
336927b
face56c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,8 @@ | ||||||||
| import { patternflyNamespace, patternflyVersion } from './init.mjs'; | ||||||||
| import fs from 'fs'; | ||||||||
| import path from 'path'; | ||||||||
| import Handlebars from 'handlebars'; | ||||||||
| import { createRequire } from 'module'; | ||||||||
|
|
||||||||
| // TODO: TODO: update ternary to not escape chars | ||||||||
|
|
||||||||
|
|
@@ -359,3 +363,32 @@ export const pfv = (type) => { | |||||||
| export const prefix = function (term) { | ||||||||
| return pfv('c') + term; | ||||||||
| } | ||||||||
|
|
||||||||
| // ====================================================================================== | ||||||||
| // pfIcon: a helper function to use svg's from @patternfly/react-icons | ||||||||
| // ====================================================================================== | ||||||||
| // | ||||||||
| // Usage: | ||||||||
| // {{pfIcon 'arrow-right'}} | ||||||||
| // | ||||||||
| // ====================================================================================== | ||||||||
| export const pfIcon = function (iconName) { | ||||||||
| try { | ||||||||
| if (!iconName || typeof iconName !== 'string') { | ||||||||
| console.error(`\x1b[31mInvalid icon name: ${iconName}\x1b[0m`); | ||||||||
| return new Handlebars.SafeString(`<!-- Invalid icon name -->`); | ||||||||
| } | ||||||||
| const baseName = path.basename(iconName); | ||||||||
| const require = createRequire(import.meta.url); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider hoisting
♻️ Proposed refactorAt the top of the file (after the existing imports): import { createRequire } from 'module';
+
+const require = createRequire(import.meta.url);Inside const baseName = path.basename(iconName);
- const require = createRequire(import.meta.url);
const packageJsonPath = require.resolve('@patternfly/react-icons/package.json');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| const packageJsonPath = require.resolve('@patternfly/react-icons/package.json'); | ||||||||
| const packageDir = path.dirname(packageJsonPath); | ||||||||
| const iconDir = path.join(packageDir, 'dist/static'); | ||||||||
| const iconPath = path.join(iconDir, `${baseName}.svg`); | ||||||||
| const svgContent = fs.readFileSync(iconPath, 'utf8'); | ||||||||
| return new Handlebars.SafeString(svgContent); | ||||||||
| } catch (error) { | ||||||||
| const safeName = (iconName && typeof iconName === 'string') ? path.basename(iconName) : 'unknown'; | ||||||||
| console.error(`\x1b[31mError loading icon "${safeName}": ${error.message}\x1b[0m`); | ||||||||
| return new Handlebars.SafeString(`<!-- Icon "${safeName}" not found -->`); | ||||||||
| } | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||
| } | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| {{#> compass-header}} | ||
| {{#> compass-logo}} | ||
| {{> compass--icons compass--icons--redhat=true}} | ||
| {{/compass-logo}} | ||
| {{#> compass-nav}} | ||
| {{#> compass-panel compass-panel--HasNoPadding=false compass-panel--IsPill=true}} | ||
| {{#> compass-nav-content}} | ||
| {{#> compass-nav-home}} | ||
| {{#> button button--IsPlain=true button--aria-label="Home" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-home"}} | ||
| {{/button}} | ||
| {{/compass-nav-home}} | ||
| {{#> compass-nav-main}} | ||
| {{#> tabs tabs--id="primary-nav" tabs--type="nav" tabs--IsNav=true tabs--aria-label="Compass primary" tabs-link--isLink="true"}} | ||
| {{> __tabs-list}} | ||
| {{/tabs}} | ||
| {{/compass-nav-main}} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| {{#> compass-nav-search}} | ||
| {{#> button button--IsPlain=true button--aria-label="Search" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-search"}} | ||
| {{/button}} | ||
| {{/compass-nav-search}} | ||
| {{/compass-nav-content}} | ||
| {{/compass-panel}} | ||
| {{#> compass-panel compass-panel--HasNoPadding=false compass-panel--IsPill=true}} | ||
| {{#> compass-nav-content}} | ||
| {{#> compass-nav-main}} | ||
| {{#> tabs tabs--id="secondary-nav" tabs--type="nav" tabs--IsNav=true tabs--aria-label="Compass secondary" tabs-link--isLink="true" tabs--modifier="pf-m-subtab"}} | ||
| {{> __tabs-list-secondary __tabs-list--IsDisabled="true"}} | ||
| {{/tabs}} | ||
| {{/compass-nav-main}} | ||
| {{/compass-nav-content}} | ||
| {{/compass-panel}} | ||
| {{/compass-nav}} | ||
| {{#> compass-profile}} | ||
| {{#> menu-toggle menu-toggle--IsPlain=true menu-toggle--IsText=true menu-toggle--IsCircle=true}} | ||
| {{#> menu-toggle-icon}} | ||
| {{> avatar avatar--modifier="pf-m-md"}} | ||
| {{/menu-toggle-icon}} | ||
| {{#> menu-toggle-text}} | ||
| Ned Username | ||
| {{/menu-toggle-text}} | ||
| {{#> menu-toggle-controls}} | ||
| {{> menu-toggle-toggle-icon}} | ||
| {{/menu-toggle-controls}} | ||
| {{/menu-toggle}} | ||
| {{/compass-profile}} | ||
| {{/compass-header}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| {{#> compass-sidebar compass-sidebar--IsEnd=true}} | ||
| {{#> compass-panel compass-panel--IsPill=true}} | ||
| {{#> action-list action-list--modifier="pf-m-icons" action-list--IsVertical=true}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Notifications" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-notification"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="List" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-list"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Zap" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-electricity"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Download" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-download"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Help" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-question-mark-circle"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{/action-list}} | ||
| {{/compass-panel}} | ||
| {{/compass-sidebar}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| {{#> compass-sidebar compass-sidebar--IsStart=true}} | ||
| {{#> compass-panel compass-panel--IsPill=true}} | ||
| {{#> action-list action-list--modifier="pf-m-icons" action-list--IsVertical=true}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Add" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-add-square"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Collections" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-collection"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--modifier=(concat (pfv "unset-prefix") "m-ai-indicator") button--IsPlain=true button--aria-label="AI assistant" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-ai-experience-fill"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Volume" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-volume-up"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{#> action-list-item}} | ||
| {{#> button button--IsPlain=true button--aria-label="Use microphone" button--IsCircle=true button--IsIcon=true}} | ||
| {{pfIcon "rh-ui-microphone"}} | ||
| {{/button}} | ||
| {{/action-list-item}} | ||
| {{/action-list}} | ||
| {{/compass-panel}} | ||
| {{/compass-sidebar}} |
Uh oh!
There was an error while loading. Please reload this page.