Skip to content

Commit

Permalink
feat(FormGroup): rename labelIcon to labelHelp (#581)
Browse files Browse the repository at this point in the history
* feat(FormGroup): rename labelIcon to labelHelp

* prettier fix

* docs(FormGroup): use actual classname instead of token

* feat(FormGroup): add rule to Beta rules before React PR is merged
  • Loading branch information
adamviktora authored Feb 28, 2024
1 parent c0e4dd1 commit 61f97d0
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// if you want your rule to only run when explicitly called for using the --only flag, add the rule name to the below array
export const betaRuleNames: string[] = [
"checkbox-radio-replace-isLabelBeforeButton",
"formGroup-rename-labelIcon",
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### formGroup-rename-labelIcon [(#10016)](https://github.com/patternfly/patternfly-react/pull/10016)

The `labelIcon` prop for FormGroup has been renamed to `labelHelp`. We recommend using FormGroupLabelHelp element for the labelHelp prop. The markup has also changed, we now wrap the labelHelp element in `<span className="pf-v6-c-form__group-label-help">`, so there is no need to add `className="pf-v6-c-form__group-label-help"` to the labelHelp element.

#### 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 "./formGroup-rename-labelIcon";

ruleTester.run("formGroup-rename-labelIcon", rule, {
valid: [
{
code: `<FormGroup labelIcon />`,
},
{
code: `import { FormGroup } from '@patternfly/react-core'; <FormGroup someOtherProp />`,
},
],
invalid: [
{
code: `import { FormGroup } from '@patternfly/react-core'; <FormGroup labelIcon={<>Help icon</>} />`,
output: `import { FormGroup } from '@patternfly/react-core'; <FormGroup labelHelp={<>Help icon</>} />`,
errors: [
{
message: `The \`labelIcon\` prop for FormGroup has been renamed to \`labelHelp\`. We recommend using FormGroupLabelHelp element for the labelHelp prop. The markup has also changed, we now wrap the labelHelp element in \`<span className="pf-v6-c-form__group-label-help">\`, so there is no need to add \`className="pf-v6-c-form__group-label-help"\` to the labelHelp element.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { renameProps } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/10016
module.exports = {
meta: { fixable: "code" },
create: renameProps({
FormGroup: {
labelIcon: {
newName: "labelHelp",
message: `The \`labelIcon\` prop for FormGroup has been renamed to \`labelHelp\`. We recommend using FormGroupLabelHelp element for the labelHelp prop. The markup has also changed, we now wrap the labelHelp element in \`<span className="pf-v6-c-form__group-label-help">\`, so there is no need to add \`className="pf-v6-c-form__group-label-help"\` to the labelHelp element.`,
},
},
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FormGroup } from "@patternfly/react-core";

export const FormGroupRenameLabelIconInput = () => (
<FormGroup labelIcon={<>Help icon</>} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FormGroup } from "@patternfly/react-core";

export const FormGroupRenameLabelIconInput = () => (
<FormGroup labelHelp={<>Help icon</>} />
);

0 comments on commit 61f97d0

Please sign in to comment.