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(Nav): props updates #585

Merged
merged 4 commits 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
@@ -0,0 +1,18 @@
### nav-remove-tertiary-variant [(#9948)](https://github.com/patternfly/patternfly-react/pull/9948)

The "tertiary" Nav variant is no longer supported. Use `variant="horizontal-subnav"` instead.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const ruleTester = require("../../ruletester");
import * as rule from "./nav-remove-tertiary-variant";

ruleTester.run("nav-remove-tertiary-variant", rule, {
valid: [
{
code: `<Nav variant="tertiary" />`,
},
{
code: `import { Nav } from '@patternfly/react-core'; <Nav someOtherProp />`,
},
{
code: `import { Nav } from '@patternfly/react-core'; <Nav variant="default" />`,
},
],
invalid: [
{
code: `import { Nav } from '@patternfly/react-core'; <Nav variant="tertiary" />`,
output: `import { Nav } from '@patternfly/react-core'; <Nav variant="horizontal-subnav" />`,
errors: [
{
message: `The "tertiary" Nav variant is no longer supported. Use variant="horizontal-subnav" instead.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Nav } from '@patternfly/react-core'; <Nav variant={'tertiary'} />`,
output: `import { Nav } from '@patternfly/react-core'; <Nav variant={"horizontal-subnav"} />`,
errors: [
{
message: `The "tertiary" Nav variant is no longer supported. Use variant="horizontal-subnav" instead.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Rule } from "eslint";
import { getFromPackage } from "../../helpers";
import { JSXAttribute, JSXOpeningElement, Literal } from "estree-jsx";

// https://github.com/patternfly/patternfly-react/pull/9948
module.exports = {
meta: { fixable: "code" },
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const navImport = imports.find(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "Nav"
);

return !navImport
? {}
: {
JSXOpeningElement(node: JSXOpeningElement) {
if (
node.name.type === "JSXIdentifier" &&
navImport.local.name === node.name.name
) {
const variantAttribute = node.attributes.find(
(attr) =>
attr.type === "JSXAttribute" && attr.name?.name === "variant"
) as JSXAttribute;

if (!variantAttribute) {
return;
}

let variantLiteral: Literal | null = null;

if (variantAttribute.value?.type === "Literal") {
variantLiteral = variantAttribute.value;
}

if (
variantAttribute.value?.type === "JSXExpressionContainer" &&
variantAttribute.value?.expression.type === "Literal"
) {
variantLiteral = variantAttribute.value?.expression;
}

if (variantLiteral?.value === "tertiary") {
context.report({
node,
message:
'The "tertiary" Nav variant is no longer supported. Use variant="horizontal-subnav" instead.',
fix: <Rule.ReportFixer>function (fixer) {
return fixer.replaceText(
variantLiteral!,
'"horizontal-subnav"'
);
},
});
}
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Nav } from "@patternfly/react-core";

export const NavRemoveTertiaryVariantInput = () => <Nav variant="tertiary" />;
export const NavRemoveTertiaryVariantInput2 = () => (
<Nav variant={"tertiary"} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Nav } from "@patternfly/react-core";

export const NavRemoveTertiaryVariantInput = () => (
<Nav variant="horizontal-subnav" />
);
export const NavRemoveTertiaryVariantInput2 = () => (
<Nav variant={"horizontal-subnav"} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### nav-remove-theme-prop [(#9948)](https://github.com/patternfly/patternfly-react/pull/9948)

The `theme` prop is no longer supported in Nav. Use light/dark mode theming instead.

#### Examples

In:

```jsx
%inputExample%
```

Out:

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

ruleTester.run("nav-remove-theme-prop", rule, {
valid: [
{
code: `<Nav theme />`,
},
{
code: `import { Nav } from '@patternfly/react-core'; <Nav someOtherProp />`,
},
],
invalid: [
{
code: `import { Nav } from '@patternfly/react-core'; <Nav theme="dark" />`,
output: `import { Nav } from '@patternfly/react-core'; <Nav />`,
errors: [
{
message: `The \`theme\` prop is no longer supported in Nav. Use light/dark mode theming instead.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { Nav } from '@patternfly/react-core'; <Nav theme="light" />`,
output: `import { Nav } from '@patternfly/react-core'; <Nav />`,
errors: [
{
message: `The \`theme\` prop is no longer supported in Nav. Use light/dark mode theming instead.`,
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/9948
module.exports = {
meta: { fixable: "code" },
create: renameProps({
Nav: {
theme: {
newName: "",
message:
"The `theme` prop is no longer supported in Nav. Use light/dark mode theming instead.",
},
},
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Nav } from "@patternfly/react-core";

export const NavRemoveThemePropInput = () => <Nav theme="dark" />;
export const NavRemoveThemePropInput2 = () => <Nav theme="light" />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Nav } from "@patternfly/react-core";

export const NavRemoveThemePropInput = () => <Nav />;
export const NavRemoveThemePropInput2 = () => <Nav />;
Loading