Skip to content

Commit e7a6ab5

Browse files
committed
icon add loading
1 parent 23effd6 commit e7a6ab5

3 files changed

Lines changed: 72 additions & 5 deletions

File tree

packages/umi-plugin-ui/src/bubble/Bubble.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from 'styled-components';
44
import Dragger from './Dragger';
55
import Hide from './Hide';
66
import logoDecorator from './Logo';
7+
import IconLoading from './IconLoading';
78
import * as ENUM from './enum';
89
import Close from './Close';
910

@@ -62,6 +63,14 @@ class Bubble extends React.Component {
6263
);
6364
};
6465

66+
/**
67+
* 初始化dom
68+
*/
69+
componentDidMount() {
70+
// eslint-disable-next-line
71+
this.nodeDom = ReactDOM.findDOMNode(this);
72+
}
73+
6574
showBubble = e => {
6675
// 显示 bubble 时取消页面的编辑模式
6776
window.postMessage(
@@ -71,7 +80,6 @@ class Bubble extends React.Component {
7180
'*',
7281
);
7382

74-
const node = ReactDOM.findDOMNode(this);
7583
const { toggleMiniOpen } = this.props;
7684
if (this.state.hide) {
7785
// isHide
@@ -83,7 +91,7 @@ class Bubble extends React.Component {
8391
window.localStorage.removeItem(ENUM.STORE_BUBBLE_HIDE);
8492
},
8593
);
86-
} else if (e.target === node) {
94+
} else if (e.target === this.nodeDom) {
8795
// not hide, show iframe
8896
toggleMiniOpen();
8997
}
@@ -96,11 +104,10 @@ class Bubble extends React.Component {
96104
};
97105

98106
render() {
99-
const { isBigfish, open, children, message } = this.props;
107+
const { isBigfish, open, loading, children, message } = this.props;
100108
const { hide } = this.state;
101109

102110
const Logo = logoDecorator({ isBigfish });
103-
104111
return (
105112
<Dragger
106113
open={open}
@@ -111,6 +118,7 @@ class Bubble extends React.Component {
111118
onDrag={this.handleDrag}
112119
>
113120
<BubbleWrapper open={open}>
121+
{loading && <IconLoading />}
114122
<Logo open={open} />
115123
<CloseComponent open={open} />
116124
</BubbleWrapper>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import styled, { keyframes } from 'styled-components';
3+
4+
const bounceTransform = keyframes`{
5+
0%, 100% {
6+
transform: scale(0.4);
7+
} 50% {
8+
transform: scale(1.0);
9+
}
10+
}`;
11+
12+
const Bounce = styled.div`
13+
width: 100%;
14+
height: 100%;
15+
border-radius: 50%;
16+
background-color: #1890ff;
17+
opacity: 0.6;
18+
position: absolute;
19+
top: 0;
20+
left: 0;
21+
animation: ${bounceTransform} 2s infinite ease-in-out;
22+
`;
23+
24+
const BounceTwo = styled.div`
25+
width: 100%;
26+
height: 100%;
27+
border-radius: 50%;
28+
background-color: #1890ff;
29+
opacity: 0.6;
30+
position: absolute;
31+
top: 0;
32+
left: 0;
33+
animation-delay: -1s;
34+
animation: ${bounceTransform} 2s infinite ease-in-out;
35+
`;
36+
37+
const Spinning = styled.div`
38+
width: 60px;
39+
height: 60px;
40+
position: absolute;
41+
top: 0;
42+
left: 0;
43+
`;
44+
45+
export default () => (
46+
<Spinning>
47+
<Bounce />
48+
<BounceTwo />
49+
</Spinning>
50+
);

packages/umi-plugin-ui/src/bubble/index.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class App extends React.Component {
2727
open: undefined,
2828
connected: false,
2929
uiLoaded: false,
30+
loading: false,
3031
currentProject: props.currentProject,
3132
};
3233
window.addEventListener('message', this.handleMessage, false);
@@ -63,6 +64,13 @@ class App extends React.Component {
6364
});
6465
break;
6566
}
67+
// 切换loading
68+
case 'umi.ui.toggleIconLoading': {
69+
this.setState(({ loading }) => ({
70+
loading: !loading,
71+
}));
72+
break;
73+
}
6674
default:
6775
// no thing
6876
}
@@ -142,7 +150,7 @@ class App extends React.Component {
142150
};
143151

144152
render() {
145-
const { open, connected, uiLoaded } = this.state;
153+
const { open, connected, uiLoaded, loading } = this.state;
146154
const { isBigfish = false } = this.props;
147155
const miniUrl = this.getMiniUrl();
148156
// get locale when first render
@@ -157,6 +165,7 @@ class App extends React.Component {
157165
// TODO: loading when currentProject not loaded
158166
toggleMiniOpen={this.toggleMiniOpen}
159167
open={open}
168+
loading={loading}
160169
message={message}
161170
>
162171
{open !== undefined && (

0 commit comments

Comments
 (0)