-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MenuToggle): updated recommended icon usage
- Loading branch information
1 parent
1ded4ca
commit 2314cb2
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
...ds/src/rules/v6/menuToggleWarnIconOnlyToggle/menuToggle-warn-iconOnly-toggle.md
This file contains 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,19 @@ | ||
### menuToggle-warn-iconOnly-toggle [(#10097)](https://github.com/patternfly/patternfly-react/pull/10097) | ||
|
||
We now recommend passing any icon to the `icon` prop instead of passing it as children, such as for plain, icon only toggles. Passing an icon as children will result in incorrect styling. | ||
|
||
#### Examples | ||
|
||
This rule will not provide a fix, but you can refer to the following code blocks to see what updates would need to be made manually. | ||
|
||
Previous recommendation: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
New recommendation: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
22 changes: 22 additions & 0 deletions
22
...odemods/src/rules/v6/menuToggleWarnIconOnlyToggle/menuToggle-warn-iconOnly-toggle.test.ts
This file contains 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,22 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./menuToggle-warn-iconOnly-toggle"; | ||
|
||
ruleTester.run("menuToggle-warn-iconOnly-toggle", rule, { | ||
valid: [ | ||
{ | ||
code: `<MenuToggle />`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { MenuToggle } from '@patternfly/react-core'; <MenuToggle />`, | ||
output: `import { MenuToggle } from '@patternfly/react-core'; <MenuToggle />`, | ||
errors: [ | ||
{ | ||
message: `We now recommend passing any icon to the \`icon\` prop instead of passing it as children, such as for plain, icon only toggles. Passing an icon as children will result in incorrect styling.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
35 changes: 35 additions & 0 deletions
35
...-pf-codemods/src/rules/v6/menuToggleWarnIconOnlyToggle/menuToggle-warn-iconOnly-toggle.ts
This file contains 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,35 @@ | ||
import { Rule } from "eslint"; | ||
import { ImportDeclaration, ImportSpecifier } from "estree-jsx"; | ||
import { getFromPackage } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10097 | ||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: function (context: Rule.RuleContext) { | ||
const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
||
const menuToggleImport = imports.find( | ||
(specifier) => specifier.imported.name === "MenuToggle" | ||
); | ||
|
||
return !menuToggleImport | ||
? {} | ||
: { | ||
ImportDeclaration(node: ImportDeclaration) { | ||
if ( | ||
node.specifiers.find( | ||
(specifier) => | ||
(specifier as ImportSpecifier).imported?.name === | ||
menuToggleImport.imported.name | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
message: | ||
"We now recommend passing any icon to the `icon` prop instead of passing it as children, such as for plain, icon only toggles. Passing an icon as children will result in incorrect styling.", | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
8 changes: 8 additions & 0 deletions
8
...-codemods/src/rules/v6/menuToggleWarnIconOnlyToggle/menuToggleWarnIconOnlyToggleInput.tsx
This file contains 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 { MenuToggle } from "@patternfly/react-core"; | ||
import EllipsisVIcon from "@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon"; | ||
|
||
export const MenuToggleWarnIconOnlyToggleInput = () => ( | ||
<MenuToggle aria-label='A descriptive aria-label' variant='plain'> | ||
<EllipsisVIcon /> | ||
</MenuToggle> | ||
); |
10 changes: 10 additions & 0 deletions
10
...codemods/src/rules/v6/menuToggleWarnIconOnlyToggle/menuToggleWarnIconOnlyToggleOutput.tsx
This file contains 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,10 @@ | ||
import { MenuToggle } from "@patternfly/react-core"; | ||
import EllipsisVIcon from "@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon"; | ||
|
||
export const MenuToggleWarnIconOnlyToggleInput = () => ( | ||
<MenuToggle | ||
icon={EllipsisVIcon} | ||
aria-label='A descriptive aria-label' | ||
variant='plain' | ||
/> | ||
); |