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 button initial loading state #330

Merged
merged 1 commit into from
Nov 13, 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
8 changes: 6 additions & 2 deletions src/components/Button/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/jsx-props-no-spreading,react/button-has-type */
import React, { forwardRef, useCallback, useEffect, useMemo, useRef } from "react";
import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
import PropTypes from "prop-types";
import cx from "classnames";
import useResizeObserver from "../../hooks/useResizeObserver";
Expand Down Expand Up @@ -59,6 +59,7 @@ const Button = forwardRef(
ref
) => {
const buttonRef = useRef(null);
const [hasSizeStyle, setHasSizeStyle] = useState(false);

const updateCssVariables = useMemo(() => {
return ({ borderBoxSize }) => {
Expand All @@ -68,6 +69,7 @@ const Button = forwardRef(
if (!buttonRef.current) return;
buttonRef.current.style.setProperty("--element-width", `${width}px`);
buttonRef.current.style.setProperty("--element-height", `${height}px`);
setHasSizeStyle(true);
};
}, [buttonRef]);

Expand Down Expand Up @@ -132,6 +134,7 @@ const Button = forwardRef(
`monday-style-button--kind-${kind}`,
`monday-style-button--color-${calculatedColor}`,
{
"has-style-size": hasSizeStyle,
"monday-style-button--loading": loading,
[`monday-style-button--color-${calculatedColor}-active`]: active,
"monday-style-button--margin-right": marginRight,
Expand All @@ -155,7 +158,8 @@ const Button = forwardRef(
noSidePadding,
preventClickAnimation,
leftFlat,
rightFlat
rightFlat,
hasSizeStyle
]);

const mergedRef = useMergeRefs({ refs: [ref, buttonRef] });
Expand Down
6 changes: 4 additions & 2 deletions src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@

&.monday-style-button--loading {
min-width: 0;
width: var(--element-height);
height: var(--element-height);
&.has-style-size {
width: var(--element-height);
height: var(--element-height);
}
position: relative;
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/Button/__stories__/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ const LoadingButtonWrapper = ({ size, kind }) => {

export const Loading = () => (
<StoryStateRow>
<StoryStateColumn title="Left Icon Large">
<LoadingButtonWrapper size={Button.sizes.MEDIUM} kind={Button.kinds.PRIMARY} />
<StoryStateColumn title="Primary Large">
<LoadingButtonWrapper size={Button.sizes.LARGE} kind={Button.kinds.PRIMARY} />
</StoryStateColumn>
<StoryStateColumn title="Left Icon Medium">
<StoryStateColumn title="Secondary Medium">
<LoadingButtonWrapper size={Button.sizes.MEDIUM} kind={Button.kinds.SECONDARY} />
</StoryStateColumn>
<StoryStateColumn title="Left Icon Small">
<LoadingButtonWrapper size={Button.sizes.MEDIUM} kind={Button.kinds.TERTIARY} />
<StoryStateColumn title="Tertiary Small">
<LoadingButtonWrapper size={Button.sizes.SMALL} kind={Button.kinds.TERTIARY} />
</StoryStateColumn>
</StoryStateRow>
);
Expand Down