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

fix: switch from defaultProps to JS default params #6568

Merged
merged 1 commit into from Mar 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/AbstractModalHeader.tsx
Expand Up @@ -39,17 +39,19 @@ const propTypes = {
onHide: PropTypes.func,
};

const defaultProps = {
closeLabel: 'Close',
closeButton: false,
};

const AbstractModalHeader = React.forwardRef<
HTMLDivElement,
AbstractModalHeaderProps
>(
(
{ closeLabel, closeVariant, closeButton, onHide, children, ...props },
{
closeLabel = 'Close',
closeVariant,
closeButton = false,
onHide,
children,
...props
},
ref,
) => {
const context = useContext(ModalContext);
Expand All @@ -76,6 +78,5 @@ const AbstractModalHeader = React.forwardRef<
);

AbstractModalHeader.propTypes = propTypes;
AbstractModalHeader.defaultProps = defaultProps;

export default AbstractModalHeader;
16 changes: 4 additions & 12 deletions src/Alert.tsx
Expand Up @@ -86,26 +86,19 @@ const propTypes = {
transition: PropTypes.oneOfType([PropTypes.bool, elementType]),
};

const defaultProps = {
variant: 'primary',
show: true,
transition: Fade,
closeLabel: 'Close alert',
};

const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
(uncontrolledProps: AlertProps, ref) => {
const {
bsPrefix,
show,
closeLabel,
show = true,
closeLabel = 'Close alert',
closeVariant,
className,
children,
variant,
variant = 'primary',
onClose,
dismissible,
transition,
transition = Fade,
...props
} = useUncontrolled(uncontrolledProps, {
show: 'onClose',
Expand Down Expand Up @@ -152,7 +145,6 @@ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
);

Alert.displayName = 'Alert';
Alert.defaultProps = defaultProps;
Alert.propTypes = propTypes;

export default Object.assign(Alert, {
Expand Down
16 changes: 9 additions & 7 deletions src/Badge.tsx
Expand Up @@ -42,15 +42,18 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
bg: 'primary',
pill: false,
};

const Badge: BsPrefixRefForwardingComponent<'span', BadgeProps> =
React.forwardRef<HTMLElement, BadgeProps>(
(
{ bsPrefix, bg, pill, text, className, as: Component = 'span', ...props },
{
bsPrefix,
bg = 'primary',
pill = false,
text,
className,
as: Component = 'span',
...props
},
ref,
) => {
const prefix = useBootstrapPrefix(bsPrefix, 'badge');
Expand All @@ -72,6 +75,5 @@ const Badge: BsPrefixRefForwardingComponent<'span', BadgeProps> =

Badge.displayName = 'Badge';
Badge.propTypes = propTypes;
Badge.defaultProps = defaultProps;

export default Badge;
10 changes: 2 additions & 8 deletions src/Breadcrumb.tsx
Expand Up @@ -33,20 +33,15 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
label: 'breadcrumb',
listProps: {},
};

const Breadcrumb: BsPrefixRefForwardingComponent<'nav', BreadcrumbProps> =
React.forwardRef<HTMLElement, BreadcrumbProps>(
(
{
bsPrefix,
className,
listProps,
listProps = {},
children,
label,
label = 'breadcrumb',
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'nav',
...props
Expand Down Expand Up @@ -75,7 +70,6 @@ const Breadcrumb: BsPrefixRefForwardingComponent<'nav', BreadcrumbProps> =

Breadcrumb.displayName = 'Breadcrumb';
Breadcrumb.propTypes = propTypes;
Breadcrumb.defaultProps = defaultProps;

export default Object.assign(Breadcrumb, {
Item: BreadcrumbItem,
Expand Down
10 changes: 2 additions & 8 deletions src/BreadcrumbItem.tsx
Expand Up @@ -50,25 +50,20 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
active: false,
linkProps: {},
};

const BreadcrumbItem: BsPrefixRefForwardingComponent<
'li',
BreadcrumbItemProps
> = React.forwardRef<HTMLElement, BreadcrumbItemProps>(
(
{
bsPrefix,
active,
active = false,
children,
className,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'li',
linkAs: LinkComponent = Anchor,
linkProps,
linkProps = {},
href,
title,
target,
Expand Down Expand Up @@ -104,6 +99,5 @@ const BreadcrumbItem: BsPrefixRefForwardingComponent<

BreadcrumbItem.displayName = 'BreadcrumbItem';
BreadcrumbItem.propTypes = propTypes;
BreadcrumbItem.defaultProps = defaultProps;

export default BreadcrumbItem;
25 changes: 16 additions & 9 deletions src/Button.tsx
Expand Up @@ -67,18 +67,25 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
variant: 'primary',
active: false,
disabled: false,
};

const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
React.forwardRef<HTMLButtonElement, ButtonProps>(
({ as, bsPrefix, variant, size, active, className, ...props }, ref) => {
(
{
as,
bsPrefix,
variant = 'primary',
size,
active = false,
disabled = false,
className,
...props
},
ref,
) => {
const prefix = useBootstrapPrefix(bsPrefix, 'btn');
const [buttonProps, { tagName }] = useButtonProps({
tagName: as,
disabled,
...props,
});

Expand All @@ -89,13 +96,14 @@ const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
{...buttonProps}
{...props}
ref={ref}
disabled={disabled}
className={classNames(
className,
prefix,
active && 'active',
variant && `${prefix}-${variant}`,
size && `${prefix}-${size}`,
props.href && props.disabled && 'disabled',
props.href && disabled && 'disabled',
)}
/>
);
Expand All @@ -104,6 +112,5 @@ const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =

Button.displayName = 'Button';
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;

export default Button;
12 changes: 4 additions & 8 deletions src/ButtonGroup.tsx
Expand Up @@ -38,23 +38,19 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
vertical: false,
role: 'group',
};

const ButtonGroup: BsPrefixRefForwardingComponent<'div', ButtonGroupProps> =
React.forwardRef(
(
{
bsPrefix,
size,
vertical,
vertical = false,
className,
role = 'group',
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
...rest
}: ButtonGroupProps,
},
ref,
) => {
const prefix = useBootstrapPrefix(bsPrefix, 'btn-group');
Expand All @@ -66,6 +62,7 @@ const ButtonGroup: BsPrefixRefForwardingComponent<'div', ButtonGroupProps> =
<Component
{...rest}
ref={ref}
role={role}
className={classNames(
className,
baseClass,
Expand All @@ -78,6 +75,5 @@ const ButtonGroup: BsPrefixRefForwardingComponent<'div', ButtonGroupProps> =

ButtonGroup.displayName = 'ButtonGroup';
ButtonGroup.propTypes = propTypes;
ButtonGroup.defaultProps = defaultProps;

export default ButtonGroup;
15 changes: 8 additions & 7 deletions src/ButtonToolbar.tsx
Expand Up @@ -24,21 +24,22 @@ const propTypes = {
role: PropTypes.string,
};

const defaultProps = {
role: 'toolbar',
};

const ButtonToolbar = React.forwardRef<HTMLDivElement, ButtonToolbarProps>(
({ bsPrefix, className, ...props }, ref) => {
({ bsPrefix, className, role = 'toolbar', ...props }, ref) => {
const prefix = useBootstrapPrefix(bsPrefix, 'btn-toolbar');

return (
<div {...props} ref={ref} className={classNames(className, prefix)} />
<div
{...props}
ref={ref}
className={classNames(className, prefix)}
role={role}
/>
);
},
);

ButtonToolbar.displayName = 'ButtonToolbar';
ButtonToolbar.propTypes = propTypes;
ButtonToolbar.defaultProps = defaultProps;

export default ButtonToolbar;
7 changes: 1 addition & 6 deletions src/Card.tsx
Expand Up @@ -69,10 +69,6 @@ const propTypes = {
as: PropTypes.elementType,
};

const defaultProps = {
body: false,
};

const Card: BsPrefixRefForwardingComponent<'div', CardProps> = React.forwardRef<
HTMLElement,
CardProps
Expand All @@ -84,7 +80,7 @@ const Card: BsPrefixRefForwardingComponent<'div', CardProps> = React.forwardRef<
bg,
text,
border,
body,
body = false,
children,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
Expand Down Expand Up @@ -114,7 +110,6 @@ const Card: BsPrefixRefForwardingComponent<'div', CardProps> = React.forwardRef<

Card.displayName = 'Card';
Card.propTypes = propTypes;
Card.defaultProps = defaultProps;

export default Object.assign(Card, {
Img: CardImg,
Expand Down