Skip to content

Commit 9370c30

Browse files
author
Robin Métral
authored
feat: Implement LoadingButton error state (#428)
* Add error svg icon * Implement error state in LoadingButton - Refactor styles to reuse for success and error states - Dynamically render success or error icons and remove visible prop * feat(components): rename svgIcon prop and update story and snapshots "svgIcon" prop is renamed "as" for clarity (uses Emotion as prop) after review * test(components): test LoadingIcon error state with snapshot
1 parent c3abfe6 commit 9370c30

File tree

8 files changed

+171
-280
lines changed

8 files changed

+171
-280
lines changed

src/components/LoadingButton/Container.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Container Container', () => {
3636
});
3737
});
3838

39-
describe('isLoading false nextProp with LOADING_STATEC.ACTIVE', () => {
39+
describe('isLoading false nextProp with LOADING_STATE.ACTIVE', () => {
4040
describe('no exitAnimation', () => {
4141
it('should update the state with LOADING_STATES.DISABLED', () => {
4242
const wrapper = mount(<Container isLoading />);

src/components/LoadingButton/Container.story.js

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ storiesOf(`${GROUPS.COMPONENTS}|Button/LoadingButton`, module)
3939
</LoadingButton>
4040
))
4141
)
42+
.add(
43+
'LoadingButton with Error animation',
44+
withInfo()(() => (
45+
<LoadingButton
46+
isLoading={boolean('Loading', false)}
47+
onClick={action('clicked')}
48+
onAnimationComplete={action('animation completed')}
49+
exitAnimation={LoadingButton.ERROR}
50+
primary
51+
>
52+
Click me
53+
</LoadingButton>
54+
))
55+
)
4256
.add(
4357
'LoadingButton with no exit animation',
4458
withInfo()(() => (

src/components/LoadingButton/__snapshots__/Container.spec.js.snap

+11-30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Container Container Style tests should have default styles 1`] = `
4-
.circuit-9 {
4+
.circuit-7 {
55
background-color: #FAFBFC;
66
border-color: #D8DDE1;
77
border-radius: 4px;
@@ -22,32 +22,32 @@ exports[`Container Container Style tests should have default styles 1`] = `
2222
padding: calc(8px - 0px) calc(24px - 0px);
2323
}
2424
25-
.circuit-9:active {
25+
.circuit-7:active {
2626
background-color: #D8DDE1;
2727
border-color: #9DA7B1;
2828
box-shadow: inset 0 4px 8px 0 rgba(12,15,20,0.3);
2929
}
3030
31-
.circuit-9:focus {
31+
.circuit-7:focus {
3232
border-color: #9DA7B1;
3333
border-width: 2px;
3434
outline: 0;
3535
padding: calc(8px - 1px) calc(24px - 1px);
3636
}
3737
38-
.circuit-9:hover {
38+
.circuit-7:hover {
3939
background-color: #D8DDE1;
4040
}
4141
42-
.circuit-9:hover,
43-
.circuit-9:active {
42+
.circuit-7:hover,
43+
.circuit-7:active {
4444
border-color: #9DA7B1;
4545
border-width: 1px;
4646
padding: calc(8px - 0px) calc(24px - 0px);
4747
}
4848
49-
.circuit-9[disabled],
50-
.circuit-9:disabled {
49+
.circuit-7[disabled],
50+
.circuit-7:disabled {
5151
opacity: 0.4;
5252
pointer-events: none;
5353
-webkit-user-selectable: none;
@@ -56,7 +56,7 @@ exports[`Container Container Style tests should have default styles 1`] = `
5656
user-selectable: none;
5757
}
5858
59-
.circuit-7 {
59+
.circuit-5 {
6060
position: relative;
6161
}
6262
@@ -79,17 +79,6 @@ exports[`Container Container Style tests should have default styles 1`] = `
7979
}
8080
8181
.circuit-3 {
82-
position: absolute;
83-
left: 50%;
84-
top: 50%;
85-
-webkit-transform: translate(-50%,-50%);
86-
-ms-transform: translate(-50%,-50%);
87-
transform: translate(-50%,-50%);
88-
height: 24px;
89-
width: 24px;
90-
}
91-
92-
.circuit-5 {
9382
opacity: 1;
9483
-webkit-transform: translate(0,0);
9584
-ms-transform: translate(0,0);
@@ -100,13 +89,13 @@ exports[`Container Container Style tests should have default styles 1`] = `
10089
}
10190
10291
<button
103-
className="circuit-9 circuit-10"
92+
className="circuit-7 circuit-8"
10493
disabled={false}
10594
size="mega"
10695
target={null}
10796
>
10897
<div
109-
className="circuit-7 circuit-8"
98+
className="circuit-5 circuit-6"
11099
>
111100
<div
112101
aria-busy="true"
@@ -121,14 +110,6 @@ exports[`Container Container Style tests should have default styles 1`] = `
121110
</div>
122111
<div
123112
className="circuit-3 circuit-4"
124-
size="mega"
125-
>
126-
<div>
127-
success.svg
128-
</div>
129-
</div>
130-
<div
131-
className="circuit-5 circuit-6"
132113
/>
133114
</div>
134115
</button>

0 commit comments

Comments
 (0)