Skip to content

Commit 5311374

Browse files
authored
Remove default props from func components (#1293)
1 parent 0477693 commit 5311374

32 files changed

+94
-346
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
}],
5353
"react/no-unescaped-entities": ["error", { "forbid": [">", "}"] }],
5454
"react/prop-types": [2, { "ignore": ["children"] }],
55+
"react/require-default-props": [2, {
56+
"functions": "ignore" // ignore rule for function components
57+
}],
5558
"react/react-in-jsx-scope": [0],
5659
"react/sort-comp": [2, {
5760
"order": [

src/Accordion/Accordion.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,4 @@ function Accordion({
5959
);
6060
}
6161

62-
Accordion.defaultProps = {
63-
activeKey: undefined,
64-
alwaysOpen: undefined,
65-
as: undefined,
66-
defaultActiveKey: undefined,
67-
flush: undefined,
68-
UNSAFE_className: undefined,
69-
onSelect: undefined,
70-
};
71-
7262
export default Accordion;

src/Accordion/AccordionCollapse.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,4 @@ function AccordionCollapse({
4949
);
5050
}
5151

52-
AccordionCollapse.defaultProps = {
53-
variant: undefined,
54-
UNSAFE_className: undefined,
55-
};
56-
5752
export default AccordionCollapse;

src/Accordion/AccordionItem.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,4 @@ function AccordionItem({
4646
);
4747
}
4848

49-
AccordionItem.defaultProps = {
50-
variant: undefined,
51-
as: undefined,
52-
borderless: undefined,
53-
UNSAFE_className: undefined,
54-
};
5549
export default AccordionItem;

src/Accordion/AccordionToggle.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ type AccordionToggleProps = {
4545
function AccordionToggle({
4646
borderBottom,
4747
children,
48-
chevronLateral,
49-
chevronLeft,
50-
chevronRight,
48+
chevronLateral = false,
49+
chevronLeft = false,
50+
chevronRight = true,
5151
collapsedText,
5252
disabled,
5353
eventKey,
@@ -136,16 +136,4 @@ function AccordionToggle({
136136
);
137137
}
138138

139-
AccordionToggle.defaultProps = {
140-
chevronLateral: false,
141-
chevronLeft: false,
142-
chevronRight: true,
143-
collapsedText: undefined,
144-
disabled: undefined,
145-
helperText: undefined,
146-
leadingIcon: undefined,
147-
title: undefined,
148-
UNSAFE_className: undefined,
149-
};
150-
151139
export default AccordionToggle;

src/Avatar/Avatar.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ type AvatarProps = {
1717
};
1818

1919
function Avatar({
20-
ariaHidden,
20+
ariaHidden = false,
2121
colorId,
2222
image,
2323
initials,
24-
large,
24+
large = false,
2525
name = '',
26-
showAlert,
26+
showAlert = false,
2727
url,
2828
}: AvatarProps) {
2929
const [imageLoadFailed, setImageLoadFailed] = useState(false);
@@ -83,14 +83,4 @@ function Avatar({
8383
);
8484
}
8585

86-
Avatar.defaultProps = {
87-
ariaHidden: false,
88-
colorId: undefined,
89-
image: undefined,
90-
large: false,
91-
name: '',
92-
showAlert: false,
93-
url: undefined,
94-
};
95-
9686
export default Avatar;

src/CardStack/CardStack.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ function CardStack({
3535
);
3636
}
3737

38-
CardStack.defaultProps = {
39-
size: undefined,
40-
UNSAFE_className: undefined,
41-
};
42-
4338
export default CardStack;

src/CheckboxButton/CheckboxButton.jsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const CheckboxButton = React.forwardRef(({
4444
/>
4545
);
4646
});
47-
47+
// The rule is configured to not care about default props for function
48+
// components but because this is a forwardRef it is being triggered
49+
/* eslint-disable react/require-default-props */
4850
CheckboxButton.propTypes = {
4951
checked: PropTypes.bool,
5052
className: PropTypes.string,
@@ -59,16 +61,7 @@ CheckboxButton.propTypes = {
5961
]),
6062
onChange: PropTypes.func,
6163
};
62-
63-
CheckboxButton.defaultProps = {
64-
checked: undefined,
65-
className: undefined,
66-
disabled: undefined,
67-
indeterminate: undefined,
68-
name: undefined,
69-
value: undefined,
70-
onChange: undefined,
71-
};
64+
/* eslint-enable react/require-default-props */
7265

7366
CheckboxButton.displayName = 'CheckboxButton';
7467

src/CheckboxButtonGroup/CheckboxButtonGroup.jsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import './CheckboxButtonGroup.scss';
88

99
export default function CheckboxButtonGroup({
1010
children,
11-
fullWidth,
11+
fullWidth = false,
1212
id,
13-
orientation,
14-
parseInput,
15-
value,
13+
orientation = ORIENTATIONS.ROW,
14+
parseInput = (i) => i,
15+
value = [],
1616
onChange,
1717
}) {
1818
const row = orientation === ORIENTATIONS.ROW;
@@ -73,11 +73,3 @@ CheckboxButtonGroup.propTypes = {
7373
),
7474
onChange: PropTypes.func,
7575
};
76-
77-
CheckboxButtonGroup.defaultProps = {
78-
fullWidth: false,
79-
orientation: ORIENTATIONS.ROW,
80-
parseInput: (i) => i,
81-
value: [],
82-
onChange: undefined,
83-
};

src/CopyToClipboardButton/CopyToClipboardButton.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,4 @@ function CopyToClipboardButton({
7272
);
7373
}
7474

75-
CopyToClipboardButton.defaultProps = {
76-
copyText: '',
77-
displayText: undefined,
78-
variant: ButtonVariants.NEUTRAL,
79-
};
80-
8175
export default CopyToClipboardButton;

0 commit comments

Comments
 (0)