Skip to content

Commit 8613b55

Browse files
committed
Refactor Button component loading styles: streamline shimmer effect and remove redundant styleType checks
1 parent 723a189 commit 8613b55

File tree

5 files changed

+62
-57
lines changed

5 files changed

+62
-57
lines changed

src/components/Button/Button.tsx

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const Button = ({
5757
/>
5858
)}
5959

60-
{label ?? children}
60+
<span>{label ?? children}</span>
6161

6262
{iconRight && (
6363
<ButtonIcon
@@ -69,12 +69,21 @@ export const Button = ({
6969
</StyledButton>
7070
);
7171

72-
const shimmer = keyframes`
72+
const shimmerFullWidth = keyframes`
7373
0% {
74+
background-position: -100% 0;
75+
}
76+
100% {
7477
background-position: 100% 0;
7578
}
79+
`;
80+
81+
const shimmerFixedWidth = keyframes`
82+
0% {
83+
background-position: -200px 0;
84+
}
7685
100% {
77-
background-position: -100% 0;
86+
background-position: 200px 0;
7887
}
7988
`;
8089

@@ -108,27 +117,29 @@ const StyledButton = styled(BaseButton)<{
108117
right: 0;
109118
bottom: 0;
110119
pointer-events: none;
111-
background-size: 200% 100%;
120+
background-size: ${({ $fillWidth }) => ($fillWidth ? "200% 100%" : "200px 100%")};
112121
opacity: 0;
122+
z-index: 0;
113123
}
114124
115-
${({ $loading, $styleType, theme }) => {
116-
if (!$loading) return "";
125+
/* Ensure content stays above shimmer */
126+
> * {
127+
position: relative;
128+
z-index: 1;
129+
}
117130
118-
const bgHover = theme.click.button.basic.color[$styleType].background.hover;
131+
${({ $loading, $fillWidth, $styleType, theme }) => {
132+
if (!$loading) return "";
119133
120-
const shimmerGradient = `linear-gradient(
121-
90deg,
122-
${bgHover} 0%,
123-
transparent 50%,
124-
${bgHover} 100%
125-
)`;
134+
const shimmerGradient = theme.click.button.basic.color[$styleType].background.loading;
135+
const bgSize = $fillWidth ? "200% 100%" : "200px 100%";
136+
const shimmerAnimation = $fillWidth ? shimmerFullWidth : shimmerFixedWidth;
126137
127138
return css`
128139
&::before {
129140
background: ${shimmerGradient};
130-
background-size: 200% 100%;
131-
animation: ${shimmer} 1.5s ease-in-out infinite;
141+
background-size: ${bgSize};
142+
animation: ${shimmerAnimation} 1.5s ease-in-out infinite;
132143
opacity: 1;
133144
}
134145
`;
@@ -179,39 +190,17 @@ const StyledButton = styled(BaseButton)<{
179190
}}
180191
181192
/* Loading state styling */
182-
${({ $loading, $styleType }) => {
193+
${({ $loading }) => {
183194
if (!$loading) return "";
184195
185-
if ($styleType === "primary") {
186-
// Primary: 60% opacity + shimmer animation
187-
return css`
188-
cursor: not-allowed;
189-
190-
&::before {
191-
opacity: 0.6;
192-
}
193-
`;
194-
} else if ($styleType === "secondary" || $styleType === "empty") {
195-
// Secondary & Empty: Full opacity during loading, shimmer only, text dimmed (70%)
196-
return css`
197-
cursor: not-allowed;
198-
199-
&::before {
200-
opacity: 0.7;
201-
}
202-
`;
203-
} else if ($styleType === "danger") {
204-
// Destructive: Full opacity during loading, shimmer only, text dimmed (70%)
205-
return css`
206-
cursor: not-allowed;
207-
208-
&::before {
209-
opacity: 0.7;
210-
}
211-
`;
212-
}
196+
return css`
197+
cursor: not-allowed;
213198
214-
return "";
199+
/* Dim text and icons to 70% */
200+
> * {
201+
opacity: 0.7;
202+
}
203+
`;
215204
}}
216205
`;
217206

src/theme/tokens/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ export interface Theme {
399399
hover: string;
400400
active: string;
401401
disabled: string;
402+
loading: string;
402403
};
403404
stroke: {
404405
default: string;
@@ -419,6 +420,7 @@ export interface Theme {
419420
hover: string;
420421
active: string;
421422
disabled: string;
423+
loading: string;
422424
};
423425
stroke: {
424426
default: string;
@@ -445,6 +447,7 @@ export interface Theme {
445447
hover: string;
446448
active: string;
447449
disabled: string;
450+
loading: string;
448451
};
449452
stroke: {
450453
default: string;
@@ -465,6 +468,7 @@ export interface Theme {
465468
hover: string;
466469
active: string;
467470
disabled: string;
471+
loading: string;
468472
};
469473
stroke: {
470474
default: string;

src/theme/tokens/variables.dark.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
"default": "#FAFF69",
173173
"hover": "rgb(98.6% 100% 58.8%)",
174174
"active": "rgb(90.7% 92.5% 38.1%)",
175-
"disabled": "#414141"
175+
"disabled": "#414141",
176+
"loading": "linear-gradient(\n 90deg,\n rgba(250, 255, 105, 0.8) 0%,\n rgba(255, 255, 255, 0.5) 50%,\n rgba(250, 255, 105, 0.8) 100%\n)"
176177
},
177178
"stroke": {
178179
"default": "#FAFF69",
@@ -192,7 +193,8 @@
192193
"default": "#1F1F1C",
193194
"hover": "#282828",
194195
"active": "rgb(19.9% 19.9% 19.9%)",
195-
"disabled": "#414141"
196+
"disabled": "#414141",
197+
"loading": "linear-gradient(\n 90deg,\n rgb(31, 31, 28) 0%,\n rgba(255, 255, 255, 0.2) 50%,\n rgb(31, 31, 28) 100%\n)"
196198
},
197199
"stroke": {
198200
"default": "#414141",
@@ -218,7 +220,8 @@
218220
"default": "rgb(100% 13.7% 13.7% / 0.2)",
219221
"hover": "rgb(100% 13.7% 13.7% / 0.3)",
220222
"active": "rgb(100% 13.7% 13.7% / 0.45)",
221-
"disabled": "#414141"
223+
"disabled": "#414141",
224+
"loading": "linear-gradient(\n 90deg,\n rgb(76, 32, 29) 0%,\n rgba(255, 255, 255, 0.25) 50%,\n rgb(76, 32, 29) 100%\n)"
222225
},
223226
"stroke": {
224227
"default": "rgb(100% 22.3% 22.3% / 0.1)",
@@ -238,7 +241,8 @@
238241
"default": "rgba(0,0,0,0)",
239242
"hover": "#282828",
240243
"active": "rgba(0,0,0,0)",
241-
"disabled": "rgba(0,0,0,0)"
244+
"disabled": "rgba(0,0,0,0)",
245+
"loading": "linear-gradient(\n 90deg,\n rgba(250, 255, 105, 0.1) 0%,\n rgba(250, 255, 105, 0.3) 50%,\n rgba(250, 255, 105, 0.1) 100%\n)"
242246
},
243247
"stroke": {
244248
"default": "rgba(0,0,0,0)",

src/theme/tokens/variables.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@
398398
"default": "#302e32",
399399
"hover": "lch(29.5 4.18 267)",
400400
"active": "#161517",
401-
"disabled": "#dfdfdf"
401+
"disabled": "#dfdfdf",
402+
"loading": "linear-gradient(\n 90deg,\n rgb(61, 59, 60) 0%,\n rgba(255, 255, 255, 0.3) 50%,\n rgb(61, 59, 60) 100%\n)"
402403
},
403404
"stroke": {
404405
"default": "#302e32",
@@ -418,7 +419,8 @@
418419
"default": "rgba(0,0,0,0)",
419420
"hover": "#f6f7fa",
420421
"active": "lch(95.3 1.54 272)",
421-
"disabled": "#dfdfdf"
422+
"disabled": "#dfdfdf",
423+
"loading": "linear-gradient(\n 90deg,\n rgb(232, 233, 235) 0%,\n rgba(255, 255, 255, 0.95) 50%,\n rgb(232, 233, 235) 100%\n)"
422424
},
423425
"stroke": {
424426
"default": "#e6e7e9",
@@ -444,7 +446,8 @@
444446
"default": "rgb(100% 13.7% 13.7% / 0.1)",
445447
"hover": "rgb(100% 13.7% 13.7% / 0.2)",
446448
"active": "rgb(100% 13.7% 13.7% / 0.3)",
447-
"disabled": "#dfdfdf"
449+
"disabled": "#dfdfdf",
450+
"loading": "linear-gradient(\n 90deg,\n rgba(255, 35, 35, 0.05) 0%,\n rgba(255, 255, 255, 0.8) 50%,\n rgba(255, 35, 35, 0.05) 100%\n)"
448451
},
449452
"stroke": {
450453
"default": "rgb(100% 13.7% 13.7% / 0.1)",
@@ -464,7 +467,8 @@
464467
"default": "rgba(0,0,0,0)",
465468
"hover": "#f6f7fa",
466469
"active": "rgba(0,0,0,0)",
467-
"disabled": "rgba(0,0,0,0)"
470+
"disabled": "rgba(0,0,0,0)",
471+
"loading": "linear-gradient(\n 90deg,\n rgb(240, 242, 248) 0%,\n rgba(255, 255, 255, 0.8) 50%,\n rgb(240, 242, 248) 100%\n)"
468472
},
469473
"stroke": {
470474
"default": "rgba(0,0,0,0)",

src/theme/tokens/variables.light.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
"default": "#302e32",
173173
"hover": "lch(29.5 4.18 267)",
174174
"active": "#161517",
175-
"disabled": "#dfdfdf"
175+
"disabled": "#dfdfdf",
176+
"loading": "linear-gradient(\n 90deg,\n rgb(61, 59, 60) 0%,\n rgba(255, 255, 255, 0.3) 50%,\n rgb(61, 59, 60) 100%\n)"
176177
},
177178
"stroke": {
178179
"default": "#302e32",
@@ -192,7 +193,8 @@
192193
"default": "rgba(0,0,0,0)",
193194
"hover": "#f6f7fa",
194195
"active": "lch(95.3 1.54 272)",
195-
"disabled": "#dfdfdf"
196+
"disabled": "#dfdfdf",
197+
"loading": "linear-gradient(\n 90deg,\n rgb(232, 233, 235) 0%,\n rgba(255, 255, 255, 0.95) 50%,\n rgb(232, 233, 235) 100%\n)"
196198
},
197199
"stroke": {
198200
"default": "#e6e7e9",
@@ -218,7 +220,8 @@
218220
"default": "rgb(100% 13.7% 13.7% / 0.1)",
219221
"hover": "rgb(100% 13.7% 13.7% / 0.2)",
220222
"active": "rgb(100% 13.7% 13.7% / 0.3)",
221-
"disabled": "#dfdfdf"
223+
"disabled": "#dfdfdf",
224+
"loading": "linear-gradient(\n 90deg,\n rgba(255, 35, 35, 0.05) 0%,\n rgba(255, 255, 255, 0.8) 50%,\n rgba(255, 35, 35, 0.05) 100%\n)"
222225
},
223226
"stroke": {
224227
"default": "rgb(100% 13.7% 13.7% / 0.1)",
@@ -238,7 +241,8 @@
238241
"default": "rgba(0,0,0,0)",
239242
"hover": "#f6f7fa",
240243
"active": "rgba(0,0,0,0)",
241-
"disabled": "rgba(0,0,0,0)"
244+
"disabled": "rgba(0,0,0,0)",
245+
"loading": "linear-gradient(\n 90deg,\n rgb(240, 242, 248) 0%,\n rgba(255, 255, 255, 0.8) 50%,\n rgb(240, 242, 248) 100%\n)"
242246
},
243247
"stroke": {
244248
"default": "rgba(0,0,0,0)",

0 commit comments

Comments
 (0)