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(Accordion): updates props #569

Merged
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 @@ -4,6 +4,7 @@ export const betaRuleNames: string[] = [];
// if you want a rule to have a severity that defaults to warning rather than error, add the rule name to the below array
export const warningRules = [
"aboutModalBoxHero-remove-subcomponent",
"accordionItem-warn-update-markup",
"applicationLauncher-warn-input",
"card-deprecate-props",
"card-warn-component",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### accordionContent-remove-isHidden-prop [(#9876)](https://github.com/patternfly/patternfly-react/pull/9876)

The `isHidden` prop has been removed from AccordionContent, as its visibility will now be set automatically based on the `isExpanded` prop on AccordionItem.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ruleTester = require("../../ruletester");
import * as rule from "./accordionContent-remove-isHidden-prop";

ruleTester.run("accordionContent-remove-isHidden-prop", rule, {
valid: [
{
code: `<AccordionContent isHidden />`,
},
{
code: `import { AccordionContent } from '@patternfly/react-core'; <AccordionContent someOtherProp />`,
},
],
invalid: [
{
code: `import { AccordionContent } from '@patternfly/react-core'; <AccordionContent isHidden />`,
output: `import { AccordionContent } from '@patternfly/react-core'; <AccordionContent />`,
errors: [
{
message: `The \`isHidden\` prop has been removed from AccordionContent, as its visibility will now be set automatically based on the \`isExpanded\` prop on AccordionItem.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { renameProps } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/9876
module.exports = {
meta: { fixable: "code" },
create: renameProps({
AccordionContent: {
isHidden: {
newName: "",
message:
"The `isHidden` prop has been removed from AccordionContent, as its visibility will now be set automatically based on the `isExpanded` prop on AccordionItem.",
},
},
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AccordionContent } from "@patternfly/react-core";

export const AccordionContentRemoveIsHiddenPropInput = () => (
<AccordionContent isHidden />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AccordionContent } from "@patternfly/react-core";

export const AccordionContentRemoveIsHiddenPropInput = () => (
<AccordionContent />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### accordionItem-warn-update-markup [(#9876)](https://github.com/patternfly/patternfly-react/pull/9876)

The markup for AccordionItem has been updated, and it now renders a `div` element as a wrapper.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ruleTester = require("../../ruletester");
import * as rule from "./accordionItem-warn-update-markup";

ruleTester.run("accordionItem-warn-update-markup", rule, {
valid: [
{
code: `<AccordionItem />`,
},
],
invalid: [
{
code: `import { AccordionItem } from '@patternfly/react-core'; <AccordionItem />`,
output: `import { AccordionItem } from '@patternfly/react-core'; <AccordionItem />`,
errors: [
{
message: `The markup for AccordionItem has been updated, and it now renders a \`div\` element as a wrapper.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getFromPackage } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/9876
module.exports = {
meta: {},
create: function (context: {
report: (arg0: {
node: any;
message: string;
fix?(fixer: any): any;
}) => void;
}) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const componentImports = imports.filter(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "AccordionItem"
);

return !componentImports.length
? {}
: {
JSXOpeningElement(node: { name: { name: any }; attributes: any[] }) {
if (
componentImports
.map((imp: { local: { name: any } }) => imp.local.name)
.includes(node.name.name)
) {
context.report({
node,
message:
"The markup for AccordionItem has been updated, and it now renders a `div` element as a wrapper.",
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { AccordionItem } from "@patternfly/react-core";

export const AccordionItemWarnUpdateMarkupInput = () => <AccordionItem />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { AccordionItem } from "@patternfly/react-core";

export const AccordionItemWarnUpdateMarkupInput = () => <AccordionItem />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### accordionToggle-move-isExpanded-prop [(#9876)](https://github.com/patternfly/patternfly-react/pull/9876)

The `isExpanded` prop for AccordionToggle has been moved to AccordionItem.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const ruleTester = require("../../ruletester");
import * as rule from "./accordionToggle-move-isExpanded-prop";

ruleTester.run("accordionToggle-move-isExpanded-prop", rule, {
valid: [
{
code: `<AccordionToggle isExpanded />`,
},
{
code: `import { AccordionToggle } from '@patternfly/react-core'; <AccordionToggle someOtherProp />`,
},
],
invalid: [
{
code: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem><AccordionToggle isExpanded /></AccordionItem>`,
output: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem isExpanded><AccordionToggle /></AccordionItem>`,
errors: [
{
message: `The \`isExpanded\` prop for AccordionToggle has been moved to AccordionItem.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem><AccordionToggle isExpanded={someReference} /></AccordionItem>`,
output: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem isExpanded={someReference}><AccordionToggle /></AccordionItem>`,
errors: [
{
message: `The \`isExpanded\` prop for AccordionToggle has been moved to AccordionItem.`,
type: "JSXOpeningElement",
},
],
},
{
// Test that the prop is moved correctly when AccordionItem already has a prop
code: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem className="someClass"><AccordionToggle isExpanded /></AccordionItem>`,
output: `import { AccordionItem, AccordionToggle } from '@patternfly/react-core'; <AccordionItem isExpanded className="someClass"><AccordionToggle /></AccordionItem>`,
errors: [
{
message: `The \`isExpanded\` prop for AccordionToggle has been moved to AccordionItem.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { getFromPackage, findAncestor } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/9876
module.exports = {
meta: { fixable: "code" },
create: function (context: {
getSourceCode: () => {
getText(node: any): string;
};
report: (arg0: {
node: any;
message: string;
fix(fixer: any): any;
}) => void;
}) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const componentImports = imports.filter(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "AccordionToggle"
);

return !componentImports.length
? {}
: {
JSXOpeningElement(node: { name: { name: any }; attributes: any[] }) {
if (
componentImports
.map((imp: { local: { name: any } }) => imp.local.name)
.includes(node.name.name)
) {
const attribute = node.attributes.find(
(attr: { name: { name: string } }) =>
attr.name?.name === "isExpanded"
);
if (attribute) {
context.report({
node,
message:
"The `isExpanded` prop for AccordionToggle has been moved to AccordionItem.",
fix(fixer: {
replaceText: (arg0: any, arg1: string) => any;
insertTextAfter: (arg0: string, arg1: string) => any;
}) {
const accordionItemAncestor = findAncestor(
node,
(current) =>
current?.openingElement?.name?.name === "AccordionItem"
);
const attributeValue = context
.getSourceCode()
.getText(attribute);
return [
fixer.replaceText(attribute, ""),
fixer.insertTextAfter(
accordionItemAncestor.openingElement.name,
` ${attributeValue}`
),
];
},
});
}
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AccordionItem, AccordionToggle } from "@patternfly/react-core";

export const AccordionToggleMoveIsExpandedPropInput = () => (
<AccordionItem>
<AccordionToggle isExpanded />
</AccordionItem>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AccordionItem, AccordionToggle } from "@patternfly/react-core";

export const AccordionToggleMoveIsExpandedPropInput = () => (
<AccordionItem isExpanded>
<AccordionToggle />
</AccordionItem>
);
Loading