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
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface ButtonProps {
shouldStopPropagation?: boolean;
shouldFocus?: boolean;
ariaLabel?: string;
customSpinner?: React.ReactNode;
customClassName?: string;
tabIndex?: number;
}
Expand Down Expand Up @@ -54,15 +53,8 @@ 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
});
const spinnerContent = customSpinner || (
<Spinner
customClassName={"button__spinner"}
aria-label={"Button spinner visible. Button inactivated."}
/>
);

return (
<button
Expand All @@ -82,7 +74,16 @@ function Button({
onBlur={onBlur}
disabled={isButtonDisabled}
aria-label={ariaLabel}>
{shouldDisplaySpinner ? spinnerContent : children}
{children}

{shouldDisplaySpinner && (
<div className={"button__spinner-container"}>
<Spinner
customClassName={"button__spinner"}
aria-label={"Button spinner visible. Button inactivated."}
/>
</div>
)}
</button>
);

Expand Down
16 changes: 15 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,18 @@
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

// top: 0;
// right: 0;
// bottom: 0;
// left: 0;

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 @@ -29,6 +29,8 @@
align-items: center;
justify-content: center;

padding: 0 8px;

cursor: pointer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/progress-bar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ProgressBar(props: ProgressBarProps) {
<div
className={progressBarClassName}
style={{
backgroundColor: backgroundColor
backgroundColor
}}>
<div
className={"progress-bar__track"}
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";
import SpinnerStorySample from "./utils/constants/spinner/SpinnerStorySample";

storiesOf("Button", module).add("Button States", () => (
Expand All @@ -20,12 +21,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 />

Expand Down