Skip to content

Commit

Permalink
🪟 🐛 🧹 Fix issues with Button component (#20737)
Browse files Browse the repository at this point in the history
* Disable button in loading state

* Remove defaultProps from Button and clean up some prop handling
  • Loading branch information
edmundito authored Jan 4, 2023
1 parent 6176ecb commit 40b4ad1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
8 changes: 4 additions & 4 deletions airbyte-webapp/src/components/ui/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
width: 100%;
}

&:disabled {
opacity: 0.25;
}

&:disabled,
&.isLoading {
pointer-events: none;
Expand All @@ -38,6 +34,10 @@
outline: 3px solid colors.$blue-50;
}

&:disabled:not(.isLoading) {
opacity: 0.25;
}

.buttonIcon {
display: flex;
justify-content: center;
Expand Down
25 changes: 10 additions & 15 deletions airbyte-webapp/src/components/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import { ButtonProps } from "./types";

export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
const {
full = false,
size = "xs",
iconPosition = "left",
variant = "primary",
children,
className,
clickable,
full,
icon,
iconPosition,
isLoading,
size,
variant,
wasActive,
width,
disabled,
...buttonProps
} = props;

const buttonStyles = {
[styles.full]: full,
[styles.isLoading]: isLoading,
Expand All @@ -34,15 +36,15 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
[styles.typeSecondary]: variant === "secondary",
[styles.typeDark]: variant === "dark",
};
const widthStyle: { width?: string } = {};
if (width) {
widthStyle.width = `${width}px`;
}

const widthStyle: React.CSSProperties = width ? { width: `${width}px` } : {};

return (
<button
ref={ref}
style={widthStyle}
className={classNames(styles.button, className, buttonStyles)}
disabled={disabled || isLoading}
{...buttonProps}
>
{isLoading && (
Expand Down Expand Up @@ -75,10 +77,3 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
</button>
);
});

Button.defaultProps = {
full: false,
size: "xs",
variant: "primary",
iconPosition: "left",
};
10 changes: 10 additions & 0 deletions airbyte-webapp/src/components/ui/Button/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@ Primary.args = {
children: "Primary",
icon: <FontAwesomeIcon icon={faTimes} />,
iconPosition: "left",
disabled: false,
};

export const LoadingButton = Template.bind({});
LoadingButton.args = {
variant: "primary",
children: "Primary",
isLoading: true,
disabled: false,
};

export const ButtonWithIcon = Template.bind({});
ButtonWithIcon.args = {
variant: "primary",
icon: <FontAwesomeIcon icon={faTimes} />,
iconPosition: "left",
disabled: false,
};

export const ButtonWithTextAndIconLeft = Template.bind({});
Expand All @@ -42,6 +45,7 @@ ButtonWithTextAndIconLeft.args = {
icon: <FontAwesomeIcon icon={faTimes} />,
iconPosition: "left",
children: "Icon Left",
disabled: false,
};

export const ButtonWithTextAndIconRight = Template.bind({});
Expand All @@ -50,34 +54,40 @@ ButtonWithTextAndIconRight.args = {
icon: <FontAwesomeIcon icon={faTimes} />,
iconPosition: "right",
children: "Icon Right",
disabled: false,
};

export const Secondary = Template.bind({});
Secondary.args = {
variant: "secondary",
children: "Secondary",
disabled: false,
};

export const Light = Template.bind({});
Light.args = {
variant: "light",
children: "Light",
disabled: false,
};

export const Danger = Template.bind({});
Danger.args = {
variant: "danger",
children: "Danger",
disabled: false,
};

export const Clear = Template.bind({});
Clear.args = {
variant: "clear",
children: "No Stroke",
disabled: false,
};

export const Dark = Template.bind({});
Dark.args = {
variant: "dark",
children: "Dark",
disabled: false,
};

0 comments on commit 40b4ad1

Please sign in to comment.