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

feat(button): Adjust dynamically button width #84

Merged
merged 8 commits into from
May 4, 2021
21 changes: 10 additions & 11 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ function Button({
}: ButtonProps) {
const isButtonDisabled = Boolean(isDisabled || shouldDisplaySpinner);
const containerClassName = classNames("button", customClassName, {
"button--is-inactive": isButtonDisabled,
"button--is-pending": shouldDisplaySpinner
"button--is-inactive": isButtonDisabled
});

return (
Expand All @@ -73,15 +72,15 @@ function Button({
onBlur={onBlur}
disabled={isButtonDisabled}
aria-label={ariaLabel}>
{shouldDisplaySpinner ? (
<Spinner
customClassName={classNames("button__spinner", {
[`${customClassName}__spinner`]: customClassName
})}
aria-label={"Button spinner visible. Button inactivated."}
/>
) : (
children
{children}

{shouldDisplaySpinner && (
<div className={"button__spinner__container"}>
<Spinner
customClassName={"button__spinner"}
aria-label={"Button spinner visible. Button inactivated."}
/>
</div>
)}
</button>
);
Expand Down
12 changes: 11 additions & 1 deletion src/button/_button.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.button {
--button-width: 100%;
--button-width: max-content;
--button-height: 35px;
--button-bg: black;
--button-color: white;

position: relative;

display: flex;
align-items: center;
justify-content: center;
Expand Down Expand Up @@ -31,6 +33,14 @@
cursor: not-allowed;
}

.button__spinner__container {
position: absolute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but probably we need to set top,left,right,bottom to 0 make sure it's on correct position


width: 100%;

background-color: var(--button-bg);
}

.button__spinner {
.spinner__background {
background: var(--button-bg);
Expand Down
8 changes: 6 additions & 2 deletions src/dropdown/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $dropdown-header-horizontal-padding: 8px;
}

.dropdown__header-button__text {
@include truncate-line(calc(100% - #{$dropdown-header-horizontal-padding}));
@include truncate-line();

flex: 1;

Expand All @@ -64,6 +64,10 @@ $dropdown-header-horizontal-padding: 8px;
padding: 0 $dropdown-header-horizontal-padding;

svg {
margin-bottom: 1px;
margin: 0 0 1px 8px;
}

.spinner {
margin-left: 8px;
}
}
2 changes: 2 additions & 0 deletions src/form/input/file/_file-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
align-items: center;
justify-content: center;

padding: 0 8px;

cursor: pointer;
}

Expand Down
17 changes: 11 additions & 6 deletions stories/3-Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {storiesOf} from "@storybook/react";
import Button from "../src/button/Button";
import FileUploadButton from "../src/button/file-upload/FileUploadButton";
import StoryFragment from "./utils/StoryFragment";
import StateProvider from "./utils/StateProvider";

storiesOf("Button", module).add("Button States", () => (
<StoryFragment>
Expand All @@ -19,12 +20,16 @@ storiesOf("Button", module).add("Button States", () => (

<br />

<Button
type={"button"}
onClick={(e) => alert("Thank You!")}
shouldDisplaySpinner={true}>
{"Click Me - shouldDisplaySpinner"}
</Button>
<StateProvider initialState={false}>
{(state, setState) => (
<Button
type={"button"}
onClick={() => setState(true)}
shouldDisplaySpinner={state}>
{"Click Me - shouldDisplaySpinner"}
</Button>
)}
</StateProvider>

<br />
<hr />
Expand Down