Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitf416433

Browse files
committed
feat(FollowBtn): fake loading effects
1 parentefdce2c commitf416433

File tree

4 files changed

+129
-36
lines changed

4 files changed

+129
-36
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importReactfrom'react'
2+
import{Button}from'antd'
3+
4+
import{ICON_CMD}from'../../config'
5+
6+
import{BtnWrapper,WatchIcon,LoadingIcon}from'./styles'
7+
8+
constFollowBtn=({ size, loading, onClick})=>{
9+
return(
10+
<React.Fragment>
11+
{loading ?(
12+
<Buttonsize={size}type="primary"ghost>
13+
<BtnWrapper>
14+
<LoadingIconsrc={`${ICON_CMD}/loading_sand.svg`}/>
15+
<div>关注中...</div>
16+
</BtnWrapper>
17+
</Button>
18+
) :(
19+
<Buttonsize={size}type="primary"onClick={onClick}>
20+
<BtnWrapper>
21+
<WatchIconsrc={`${ICON_CMD}/plus_follow.svg`}/>
22+
<div>关 注</div>
23+
</BtnWrapper>
24+
</Button>
25+
)}
26+
</React.Fragment>
27+
)
28+
}
29+
30+
exportdefaultFollowBtn
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
importReactfrom'react'
2+
import{Button}from'antd'
3+
4+
import{ICON_CMD}from'../../config'
5+
importPopoverfrom'../Popover'
6+
7+
import{BtnWrapper,WatchedIcon,Popinfo,LoadingIcon}from'./styles'
8+
9+
constFollowingBtn=({ size, loading, onClick})=>{
10+
return(
11+
<React.Fragment>
12+
{loading ?(
13+
<Buttonsize={size}type="primary">
14+
<BtnWrapper>
15+
<LoadingIconsrc={`${ICON_CMD}/loading_sand.svg`}light/>
16+
<div>取关中...</div>
17+
</BtnWrapper>
18+
</Button>
19+
) :(
20+
<Popover
21+
placement="bottom"
22+
trigger="hover"
23+
content={<Popinfo>点击取消关注</Popinfo>}
24+
>
25+
<Buttonsize={size}type="primary"ghostonClick={onClick}>
26+
<BtnWrapper>
27+
<WatchedIconsrc={`${ICON_CMD}/check2.svg`}/>
28+
<div>已关注</div>
29+
</BtnWrapper>
30+
</Button>
31+
</Popover>
32+
)}
33+
</React.Fragment>
34+
)
35+
}
36+
37+
exportdefaultFollowingBtn

‎components/FollowButton/index.js‎

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,65 @@
66

77
importReactfrom'react'
88
importPropTypesfrom'prop-types'
9-
import{Button}from'antd'
109

11-
import{ICON_CMD}from'../../config'
12-
importPopoverfrom'../Popover'
13-
14-
import{BtnWrapper,WatchIcon,WatchedIcon,Popinfo}from'./styles'
10+
importFollowingBtnfrom'./FollowingBtn'
11+
importFollowBtnfrom'./FollowBtn'
1512

1613
import{makeDebugger}from'../../utils'
1714
/* eslint-disable no-unused-vars */
1815
constdebug=makeDebugger('c:FollowButton:index')
1916
/* eslint-enable no-unused-vars */
2017

21-
constFollowButton=({ userId, hasFollowd, size, onFollow, onUndoFollow})=>(
22-
<React.Fragment>
23-
{hasFollowd ?(
24-
<Popover
25-
placement="bottom"
26-
trigger="hover"
27-
content={<Popinfo>点击取消关注</Popinfo>}
28-
>
29-
<Button
30-
size={size}
31-
type="primary"
32-
ghost
33-
onClick={onUndoFollow.bind(this,userId)}
34-
>
35-
<BtnWrapper>
36-
<WatchedIconsrc={`${ICON_CMD}/check2.svg`}/>
37-
<div>已关注</div>
38-
</BtnWrapper>
39-
</Button>
40-
</Popover>
41-
) :(
42-
<Buttonsize={size}type="primary"onClick={onFollow.bind(this,userId)}>
43-
<BtnWrapper>
44-
<WatchIconsrc={`${ICON_CMD}/plus_follow.svg`}/>
45-
<div>关 注</div>
46-
</BtnWrapper>
47-
</Button>
48-
)}
49-
</React.Fragment>
50-
)
18+
classFollowButtonextendsReact.Component{
19+
state={loading:false}
20+
21+
onFollow(){
22+
const{ userId, onFollow}=this.props
23+
debug('onFollow :',userId)
24+
25+
this.fakeLoading()
26+
onFollow(userId)
27+
}
28+
29+
onUndoFollow(){
30+
const{ userId, onUndoFollow}=this.props
31+
32+
debug('onUndoFollow :',userId)
33+
34+
this.fakeLoading()
35+
onUndoFollow(userId)
36+
}
37+
38+
fakeLoading(){
39+
this.setState({loading:true})
40+
setTimeout(()=>{
41+
this.setState({loading:false})
42+
},1000)
43+
}
44+
45+
render(){
46+
const{ hasFollowd, size}=this.props
47+
const{ loading}=this.state
48+
49+
return(
50+
<React.Fragment>
51+
{hasFollowd ?(
52+
<FollowingBtn
53+
size={size}
54+
loading={loading}
55+
onClick={this.onUndoFollow.bind(this)}
56+
/>
57+
) :(
58+
<FollowBtn
59+
size={size}
60+
loading={loading}
61+
onClick={this.onFollow.bind(this)}
62+
/>
63+
)}
64+
</React.Fragment>
65+
)
66+
}
67+
}
5168

5269
FollowButton.propTypes={
5370
hasFollowd:PropTypes.bool.isRequired,

‎components/FollowButton/styles/index.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importstyledfrom'styled-components'
22

33
importImgfrom'../../Img'
4-
import{theme}from'../../../utils'
4+
import{theme,Animate}from'../../../utils'
55

66
exportconstBtnWrapper=styled.div`
77
display: flex;
@@ -25,3 +25,12 @@ export const Popinfo = styled.div`
2525
color:${theme('thread.articleTitle')};
2626
padding: 5px 8px;
2727
`
28+
29+
exportconstLoadingIcon=styled(BtnIcon)`
30+
fill:${({ light})=>
31+
light ?theme('button.fg') :theme('thread.articleTitle')};
32+
33+
height: 20px;
34+
width: 20px;
35+
animation:${Animate.rotate360} 1s linear infinite;
36+
`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp