8000 fix: switch from defaultProps to JS default params · react-bootstrap/react-bootstrap@fb3c257 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit fb3c257

Browse files
committed
fix: switch from defaultProps to JS default params
1 parent b415c70 commit fb3c257

25 files changed

+73
-209
lines changed

src/Alert.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,18 @@ const propTypes = {
8585
transition: PropTypes.oneOfType([PropTypes.bool, elementType]),
8686
};
8787

88-
const defaultProps = {
89-
show: true,
90-
transition: Fade,
91-
closeLabel: 'Close alert',
92-
};
93-
94-
const Alert = (React.forwardRef<HTMLDivElement, AlertProps>(
88+
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
9589
(uncontrolledProps: AlertProps, ref) => {
9690
const {
9791
bsPrefix,
98-
show,
99-
closeLabel,
92+
show = true,
93+
closeLabel = 'Close alert',
10094
className,
10195
children,
10296
variant,
10397
onClose,
10498
dismissible,
105-
transition,
99+
transition = Fade,
106100
...props
107101
} = useUncontrolled(uncontrolledProps, {
108102
show: 'onClose',
@@ -142,10 +136,9 @@ const Alert = (React.forwardRef<HTMLDivElement, AlertProps>(
142136
</Transition>
143137
);
144138
},
145-
) as unknown) as Alert;
139+
) as unknown as Alert;
146140

147141
Alert.displayName = 'Alert';
148-
Alert.defaultProps = defaultProps as any;
149142
Alert.propTypes = propTypes;
150143
Alert.Link = AlertLink;
151144
Alert.Heading = AlertHeading;

src/Badge.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ const propTypes = {
3434
as: PropTypes.elementType,
3535
};
3636

37-
const defaultProps = {
38-
pill: false,
39-
};
40-
4137
const Badge: Badge = React.forwardRef(
4238
(
4339
{
4440
bsPrefix,
4541
variant,
46-
pill,
42+
pill = false,
4743
className,
4844
as: Component = 'span',
4945
...props
@@ -68,6 +64,5 @@ const Badge: Badge = React.forwardRef(
6864

6965
Badge.displayName = 'Badge';
7066
Badge.propTypes = propTypes;
71-
Badge.defaultProps = defaultProps;
7267

7368
export default Badge;

src/Breadcrumb.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,14 @@ const propTypes = {
3737
as: PropTypes.elementType,
3838
};
3939

40-
const defaultProps = {
41-
label: 'breadcrumb',
42-
listProps: {},
43-
};
44-
45-
const Breadcrumb: Breadcrumb = (React.forwardRef(
40+
const Breadcrumb: Breadcrumb = React.forwardRef(
4641
(
4742
{
4843
bsPrefix,
4944
className,
50-
listProps,
45+
listProps = {},
5146
children,
52-
label,
47+
label = 'breadcrumb',
5348
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
5449
as: Component = 'nav',
5550
...props
@@ -66,11 +61,10 @@ const Breadcrumb: Breadcrumb = (React.forwardRef(
6661
</Component>
6762
);
6863
},
69-
) as unknown) as Breadcrumb;
64+
) as unknown as Breadcrumb;
7065

7166
Breadcrumb.displayName = 'Breadcrumb';
7267
Breadcrumb.propTypes = propTypes;
73-
Breadcrumb.defaultProps = defaultProps;
7468
Breadcrumb.Item = BreadcrumbItem;
7569

7670
export default Breadcrumb;

src/BreadcrumbItem.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,17 @@ const propTypes = {
5454
as: PropTypes.elementType,
5555
};
5656

57-
const defaultProps = {
58-
active: false,
59-
linkProps: {},
60-
};
61-
6257
const BreadcrumbItem: BreadcrumbItem = React.forwardRef(
6358
(
6459
{
6560
bsPrefix,
66-
active,
61+
active = false,
6762
children,
6863
className,
6964
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
7065
as: Component = 'li',
7166
linkAs: LinkComponent = SafeAnchor,
72-
linkProps,
67+
linkProps = {},
7368
href,
7469
title,
7570
target,
@@ -105,6 +100,5 @@ const BreadcrumbItem: BreadcrumbItem = React.forwardRef(
105100

106101
BreadcrumbItem.displayName = 'BreadcrumbItem';
107102
BreadcrumbItem.propTypes = propTypes;
108-
BreadcrumbItem.defaultProps = defaultProps;
109103

110104
export default BreadcrumbItem;

src/Card.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,15 @@ const propTypes = {
8383
as: PropTypes.elementType,
8484
};
8585

86-
const defaultProps = {
87-
body: false,
88-
};
89-
90-
const Card: Card = (React.forwardRef(
86+
const Card: Card = React.forwardRef(
9187
(
9288
{
9389
bsPrefix,
9490
className,
9591
bg,
9692
text,
9793
border,
98-
body,
94+
body = false,
9995
children,
10096
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
10197
as: Component = 'div',
@@ -134,11 +130,10 @@ const Card: Card = (React.forwardRef(
134130
</CardContext.Provider>
135131
);
136132
},
137-
) as unknown) as Card;
133+
) as unknown as Card;
138134

139135
Card.displayName = 'Card';
140136
Card.propTypes = propTypes;
141-
Card.defaultProps = defaultProps;
142137

143138
Card.Img = CardImg;
144139
Card.Title = CardTitle;

src/CardImg.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@ const propTypes = {
2828
as: PropTypes.elementType,
2929
};
3030

31-
const defaultProps = {
32-
variant: null,
33-
};
34-
3531
const CardImg: CardImg = React.forwardRef(
3632
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
3733
(
3834
{
3935
bsPrefix,
4036
className,
41-
variant,
37+
variant = null,
4238
as: Component = 'img',
4339
...props
4440
}: CardImgProps,
@@ -60,6 +56,5 @@ const CardImg: CardImg = React.forwardRef(
6056
);
6157
CardImg.displayName = 'CardImg';
6258
CardImg.propTypes = propTypes;
63-
CardImg.defaultProps = defaultProps;
6459

6560
export default CardImg;

src/Carousel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,9 @@ function CarouselFunc(uncontrolledProps: CarouselProps, ref) {
612612
);
613613
}
614614

615-
const Carousel: Carousel = (React.forwardRef(
615+
const Carousel: Carousel = React.forwardRef(
616616
CarouselFunc,
617-
) as unknown) as Carousel;
617+
) as unknown as Carousel;
618618

619619
Carousel.displayName = 'Carousel';
620620
Carousel.propTypes = propTypes;

src/CloseButton.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ const propTypes = {
1212
onClick: PropTypes.func,
1313
};
1414

15-
const defaultProps = {
16-
label: 'Close',
17-
};
18-
1915
const CloseButton = React.forwardRef<HTMLButtonElement, CloseButtonProps>(
20-
({ label, onClick, className, ...props }: CloseButtonProps, ref) => (
16+
(
17+
{ label = 'Close', onClick, className, ...props }: CloseButtonProps,
18+
ref,
19+
) => (
2120
<button
2221
ref={ref}
2322
type="button"
@@ -33,6 +32,5 @@ const CloseButton = React.forwardRef<HTMLButtonElement, CloseButtonProps>(
3332

3433
CloseButton.displayName = 'CloseButton';
3534
CloseButton.propTypes = propTypes;
36-
CloseButton.defaultProps = defaultProps;
3735

3836
export default CloseButton;

src/Container.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ const propTypes = {
3636
as: PropTypes.elementType,
3737
};
3838

39-
const defaultProps = {
40-
fluid: false,
41-
};
42-
4339
const Container: Container = React.forwardRef(
4440
(
4541
{
4642
bsPrefix,
47-
fluid,
43+
fluid = false,
4844
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
4945
as: Component = 'div',
5046
className,
@@ -66,6 +62,5 @@ const Container: Container = React.forwardRef(
6662

6763
Container.displayName = 'Container';
6864
Container.propTypes = propTypes;
69-
Container.defaultProps = defaultProps;
7065

7166
export default Container;

src/DropdownItem.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,19 @@ const propTypes = {
6969
as: PropTypes.elementType,
7070
};
7171

72-
const defaultProps = {
73-
as: SafeAnchor,
74-
disabled: false,
75-
};
76-
7772
const DropdownItem: DropdownItem = React.forwardRef(
7873
(
7974
{
8075
bsPrefix,
8176
className,
8277
children,
8378
eventKey,
84-
disabled,
79+
disabled = false,
8580
href,
8681
onClick,
8782
onSelect,
8883
active: propActive,
89-
as: Component,
84+
as: Component = SafeAnchor,
9085
...props
9186
}: DropdownItemProps,
9287
ref,
@@ -137,6 +132,5 @@ const DropdownItem: DropdownItem = React.forwardRef(
137132

138133
DropdownItem.displayName = 'DropdownItem';
139134
DropdownItem.propTypes = propTypes;
140-
DropdownItem.defaultProps = defaultProps;
141135

142136
export default DropdownItem;

0 commit comments

Comments
 (0)
0