Skip to content
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

feat(MenuToggle): updated recommended icon usage #586

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const warningRules = [
"formControls-updated-markup",
"horizontalSubnav-warn-ariaLabel",
"label-warn-truncated-default",
"menuToggle-warn-iconOnly-toggle",
"nav-warn-flyouts-now-inline",
"overflowMenu-warn-updated-dropdownItem",
"popover-warn-appendTo-default",
Expand Down
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%
```
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",
},
],
},
],
});
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.",
});
}
},
};
},
};
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>
);
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'
/>
);
Loading