-
Notifications
You must be signed in to change notification settings - Fork 20
feat(851): PageToggleButton BarsIcon to isHamburgerButton prop #852
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
wise-king-sullyman
merged 2 commits into
patternfly:main
from
gitdallas:feat/pageToggleButton-HamburgerButton
Aug 4, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions
17
...thIsHamburgerButton/pageToggleButton-replace-barsIcon-with-isHamburgerButton.md
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 @@ | ||
| ### pageToggleButton-replace-barsIcon-with-isHamburgerButton [(#11861)](https://github.com/patternfly/patternfly-react/pull/11861) | ||
|
|
||
| The `BarsIcon` child component should be replaced with the `isHamburgerButton` prop on PageToggleButton. This simplifies the API and provides a more semantic way to indicate that the toggle button should render as a hamburger menu button. It also allows for the button to use animation. | ||
|
|
||
| #### Examples | ||
|
|
||
| In: | ||
|
|
||
| ```jsx | ||
| %inputExample% | ||
| ``` | ||
|
|
||
| Out: | ||
|
|
||
| ```jsx | ||
| %outputExample% | ||
| ``` |
86 changes: 86 additions & 0 deletions
86
...conWithIsHamburgerButton/pageToggleButton-replace-barsIcon-with-isHamburgerButton.test.ts
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,86 @@ | ||
| const ruleTester = require("../../ruletester"); | ||
| import * as rule from "./pageToggleButton-replace-barsIcon-with-isHamburgerButton"; | ||
|
|
||
| ruleTester.run("pageToggleButton-replace-barsIcon-with-isHamburgerButton", rule, { | ||
| valid: [ | ||
| { | ||
| code: `<PageToggleButton isHamburgerButton />`, | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; <PageToggleButton isHamburgerButton />`, | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; <PageToggleButton><SomeOtherIcon /></PageToggleButton>`, | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; <PageToggleButton>Some text content</PageToggleButton>`, | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; <PageToggleButton />`, | ||
| }, | ||
| // PageToggleButton not imported from PatternFly, but BarsIcon is | ||
| { | ||
| code: `import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| }, | ||
| // Neither PageToggleButton nor BarsIcon imported from PatternFly | ||
| { | ||
| code: `import { BarsIcon } from 'some-other-package'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| }, | ||
| // PageToggleButton imported from PatternFly, but BarsIcon not imported from PatternFly | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; import { BarsIcon } from 'some-other-package'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| output: `import { PageToggleButton } from '@patternfly/react-core'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton isHamburgerButton />`, | ||
| errors: [ | ||
| { | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| type: "JSXElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core/dist/esm/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| output: `import { PageToggleButton } from '@patternfly/react-core/dist/esm/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton isHamburgerButton />`, | ||
| errors: [ | ||
| { | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| type: "JSXElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core/dist/js/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| output: `import { PageToggleButton } from '@patternfly/react-core/dist/js/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton isHamburgerButton />`, | ||
| errors: [ | ||
| { | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| type: "JSXElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core/dist/dynamic/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /></PageToggleButton>`, | ||
| output: `import { PageToggleButton } from '@patternfly/react-core/dist/dynamic/components/PageToggleButton/index.js'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton isHamburgerButton />`, | ||
| errors: [ | ||
| { | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| type: "JSXElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { PageToggleButton } from '@patternfly/react-core'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton><BarsIcon /><SomeOtherContent /></PageToggleButton>`, | ||
| output: `import { PageToggleButton } from '@patternfly/react-core'; import { BarsIcon } from '@patternfly/react-icons'; <PageToggleButton isHamburgerButton><SomeOtherContent /></PageToggleButton>`, | ||
| errors: [ | ||
| { | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| type: "JSXElement", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
83 changes: 83 additions & 0 deletions
83
...BarsIconWithIsHamburgerButton/pageToggleButton-replace-barsIcon-with-isHamburgerButton.ts
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,83 @@ | ||
| import { Rule } from "eslint"; | ||
| import { JSXElement } from "estree-jsx"; | ||
| import { | ||
| getFromPackage, | ||
| getChildJSXElementByName, | ||
| isReactIcon, | ||
| getAttribute, | ||
| removeElement, | ||
| makeJSXElementSelfClosing, | ||
| } from "../../helpers"; | ||
|
|
||
| // https://github.com/patternfly/patternfly-react/pull/11861 | ||
| module.exports = { | ||
| meta: { fixable: "code" }, | ||
| create: function (context: Rule.RuleContext) { | ||
| const source = context.getSourceCode(); | ||
| const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
|
||
| const pageToggleButtonImport = imports.find( | ||
| (specifier) => specifier.imported.name === "PageToggleButton" | ||
| ); | ||
|
|
||
| return !pageToggleButtonImport | ||
| ? {} | ||
| : { | ||
| JSXElement(node: JSXElement) { | ||
| if ( | ||
| node.openingElement.name.type === "JSXIdentifier" && | ||
| pageToggleButtonImport.local.name === node.openingElement.name.name | ||
| ) { | ||
| // Check if isHamburgerButton prop already exists | ||
| const isHamburgerButtonProp = getAttribute(node, "isHamburgerButton"); | ||
|
|
||
| if (isHamburgerButtonProp) { | ||
| return; // Already has the prop, skip | ||
| } | ||
|
|
||
| // Check if BarsIcon is a direct child | ||
| const barsIconChild = getChildJSXElementByName(node, "BarsIcon"); | ||
|
|
||
| if (!barsIconChild) { | ||
| return; // No BarsIcon child found | ||
| } | ||
|
|
||
| // Check if BarsIcon is imported from PatternFly | ||
| if (!isReactIcon(context, barsIconChild)) { | ||
| return; // BarsIcon is not from PatternFly, skip | ||
| } | ||
|
|
||
| context.report({ | ||
| node, | ||
| message: `The BarsIcon child component should be replaced with the \`isHamburgerButton\` prop on PageToggleButton.`, | ||
| fix(fixer) { | ||
| // Check if we need to make the element self-closing | ||
| const otherChildren = node.children.filter(child => child !== barsIconChild); | ||
| const shouldBeSelfClosing = otherChildren.length === 0 && node.closingElement; | ||
|
|
||
| // Always add the isHamburgerButton prop | ||
| const addPropFix = fixer.insertTextAfter( | ||
| node.openingElement.name, | ||
| " isHamburgerButton" | ||
| ); | ||
|
|
||
| if (shouldBeSelfClosing) { | ||
| // For self-closing case: add prop and make self-closing (which removes children) | ||
| return [ | ||
| addPropFix, | ||
| ...makeJSXElementSelfClosing(node, context, fixer, true) | ||
| ]; | ||
| } else { | ||
| // For non-self-closing case: add prop and remove the specific child | ||
| return [ | ||
| addPropFix, | ||
| ...removeElement(fixer, barsIconChild) | ||
| ]; | ||
| } | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
8 changes: 8 additions & 0 deletions
8
...rsIconWithIsHamburgerButton/pageToggleButtonReplaceBarsIconWithIsHamburgerButtonInput.tsx
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,8 @@ | ||
| import { PageToggleButton } from "@patternfly/react-core"; | ||
| import { BarsIcon } from "@patternfly/react-icons"; | ||
|
|
||
| export const PageToggleButtonReplaceBarsIconWithIsHamburgerButtonInput = () => ( | ||
| <PageToggleButton> | ||
| <BarsIcon /> | ||
| </PageToggleButton> | ||
| ); |
5 changes: 5 additions & 0 deletions
5
...sIconWithIsHamburgerButton/pageToggleButtonReplaceBarsIconWithIsHamburgerButtonOutput.tsx
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,5 @@ | ||
| import { PageToggleButton } from "@patternfly/react-core"; | ||
|
|
||
| export const PageToggleButtonReplaceBarsIconWithIsHamburgerButtonOutput = () => ( | ||
| <PageToggleButton isHamburgerButton /> | ||
| ); |
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
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.