Skip to content

Commit

Permalink
feat(Checkbox/Radio): replace isLabelBeforeButton with labelPosition=…
Browse files Browse the repository at this point in the history
…"start" (#587)

* feat(Checkbox/Radio): replace isLabelBeforeButton with labelPosition="start"

* feat(Checkbox/Radio): add rule to Beta rules before React PR is merged
  • Loading branch information
adamviktora authored Feb 28, 2024
1 parent 8e83ed5 commit 500ed7f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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",
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### checkbox-radio-replace-isLabelBeforeButton [(#10016)](https://github.com/patternfly/patternfly-react/pull/10016)

The `isLabelBeforeButton` prop in Checkbox and Radio has been replaced with `labelPosition="start"`

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const ruleTester = require("../../ruletester");
import * as rule from "./checkbox-radio-replace-isLabelBeforeButton";

ruleTester.run("checkbox-radio-replace-isLabelBeforeButton", rule, {
valid: [
{
code: `<Checkbox isLabelBeforeButton />`,
},
{
code: `import { Checkbox } from '@patternfly/react-core'; <Checkbox someOtherProp />`,
},
{
code: `<Radio isLabelBeforeButton />`,
},
{
code: `import { Radio } from '@patternfly/react-core'; <Radio someOtherProp />`,
},
],
invalid: ["Checkbox", "Radio"].map((component) => ({
code: `import { ${component} } from '@patternfly/react-core'; <${component} isLabelBeforeButton />`,
output: `import { ${component} } from '@patternfly/react-core'; <${component} labelPosition="start" />`,
errors: [
{
message: `isLabelBeforeButton prop for ${component} has been replaced with labelPosition="start"`,
type: "JSXOpeningElement",
},
],
})),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { renameProps } from "../../helpers";

const renames = {
isLabelBeforeButton: {
newName: 'labelPosition="start"',
replace: true,
},
};

// https://github.com/patternfly/patternfly-react/pull/10016
module.exports = {
meta: { fixable: "code" },
create: renameProps({
Checkbox: renames,
Radio: renames,
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Checkbox, Radio } from "@patternfly/react-core";

export const CheckboxReplaceIsLabelBeforeButtonInput = () => (
<Checkbox isLabelBeforeButton />
);
export const RadioReplaceIsLabelBeforeButtonInput = () => (
<Radio isLabelBeforeButton />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Checkbox, Radio } from "@patternfly/react-core";

export const CheckboxReplaceIsLabelBeforeButtonInput = () => (
<Checkbox labelPosition="start" />
);
export const RadioReplaceIsLabelBeforeButtonInput = () => (
<Radio labelPosition="start" />
);

0 comments on commit 500ed7f

Please sign in to comment.