Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2924915

Browse files
authored
refactor(follow-button): UI/UX adjust (#1119)
1 parent a623deb commit 2924915

File tree

16 files changed

+234
-190
lines changed

16 files changed

+234
-190
lines changed

src/components/Buttons/FollowButton/FollowedBtn.js

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FC, memo } from 'react'
2+
3+
import { TSIZE_TSM } from '@/spec'
4+
import { LavaLampLoading } from '@/components/Loading'
5+
6+
import { BtnWrapper, FollowedButton } from '../styles/follow_button'
7+
8+
type TProps = {
9+
size: TSIZE_TSM
10+
loading: boolean
11+
text: string
12+
onClick: () => void
13+
}
14+
15+
const FollowBtn: FC<TProps> = ({ size, loading, text, onClick }) => {
16+
return (
17+
<>
18+
{loading ? (
19+
<LavaLampLoading size="small" />
20+
) : (
21+
<FollowedButton size={size} type="primary" onClick={onClick} ghost>
22+
<BtnWrapper>{text}</BtnWrapper>
23+
</FollowedButton>
24+
)}
25+
</>
26+
)
27+
}
28+
29+
export default memo(FollowBtn)

src/components/Buttons/FollowButton/FollowingBtn.js

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { FC, memo } from 'react'
2+
3+
import { TSIZE_TSM } from '@/spec'
4+
import { ICON } from '@/config'
5+
6+
import { LavaLampLoading } from '@/components/Loading'
7+
import Tooltip from '@/components/Tooltip'
8+
9+
import {
10+
BtnWrapper,
11+
Popinfo,
12+
CheckedIcon,
13+
FollowingButton,
14+
} from '../styles/follow_button'
15+
16+
type TProps = {
17+
size: TSIZE_TSM
18+
loading: boolean
19+
text: string
20+
onClick: () => void
21+
}
22+
23+
const FollowingBtn: FC<TProps> = ({ size, loading, text, onClick }) => {
24+
return (
25+
<>
26+
{loading ? (
27+
<LavaLampLoading size="small" />
28+
) : (
29+
<Tooltip
30+
placement="bottom"
31+
delay={800}
32+
content={<Popinfo>点击取消关注</Popinfo>}
33+
noPadding
34+
>
35+
<FollowingButton
36+
size={size}
37+
type="primary"
38+
ghost
39+
onClick={onClick}
40+
noBorder
41+
>
42+
<BtnWrapper>
43+
<CheckedIcon src={`${ICON}/shape/checked.svg`} />
44+
{text}
45+
</BtnWrapper>
46+
</FollowingButton>
47+
</Tooltip>
48+
)}
49+
</>
50+
)
51+
}
52+
53+
export default memo(FollowingBtn)

src/components/Buttons/FollowButton/index.js

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* FollowButton
3+
*/
4+
5+
import { FC, memo, useState, useCallback } from 'react'
6+
7+
import { TID, TSIZE_TSM } from '@/spec'
8+
import { buildLog } from '@/utils'
9+
import { SIZE } from '@/constant'
10+
11+
import FollowingBtn from './FollowingBtn'
12+
import FollowedBtn from './FollowedBtn'
13+
14+
/* eslint-disable-next-line */
15+
const log = buildLog('c:FollowButton:index')
16+
17+
type TProps = {
18+
hasFollowed?: boolean
19+
userId?: TID
20+
size?: TSIZE_TSM
21+
loading?: boolean
22+
fakeLoading?: boolean
23+
followText?: string
24+
followingText?: string
25+
onFollow?: (userId: TID) => void
26+
onUndoFollow?: (userId: TID) => void
27+
}
28+
29+
const FollowButton: FC<TProps> = ({
30+
userId,
31+
size = SIZE.SMALL,
32+
fakeLoading = false,
33+
loading = false,
34+
hasFollowed = false,
35+
followText = '关 注',
36+
followingText = '已关注',
37+
onFollow = log,
38+
onUndoFollow = log,
39+
}) => {
40+
const [simuLoading, setSimuLoading] = useState(false)
41+
const isLoading = fakeLoading ? simuLoading : loading
42+
43+
const handleFollow = useCallback(() => {
44+
if (fakeLoading) {
45+
setSimuLoading(true)
46+
setTimeout(() => setSimuLoading(false), 1500)
47+
}
48+
onFollow(userId)
49+
}, [fakeLoading, onFollow, userId])
50+
51+
const handleUndoFollow = useCallback(() => {
52+
if (fakeLoading) {
53+
setSimuLoading(true)
54+
setTimeout(() => setSimuLoading(false), 1500)
55+
}
56+
onUndoFollow(userId)
57+
}, [fakeLoading, onUndoFollow, userId])
58+
59+
return (
60+
<>
61+
{hasFollowed ? (
62+
<FollowingBtn
63+
size={size}
64+
loading={isLoading}
65+
text={followingText}
66+
onClick={handleUndoFollow}
67+
/>
68+
) : (
69+
<FollowedBtn
70+
size={size}
71+
loading={isLoading}
72+
text={followText}
73+
onClick={handleFollow}
74+
/>
75+
)}
76+
</>
77+
)
78+
}
79+
80+
export default memo(FollowButton)

src/components/Buttons/styles/follow_button/index.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import styled from 'styled-components'
22

33
import { theme, animate, css } from '@/utils'
4+
import Button from '@/components/Buttons/Button'
45
import Img from '@/Img'
56

67
export const BtnWrapper = styled.div`
78
${css.flex('align-center')};
9+
padding: 2px 5px;
810
`
911
const BtnIcon = styled(Img)`
10-
height: 12px;
11-
width: 12px;
12-
display: block;
13-
margin-right: 3px;
12+
${css.size(14)};
13+
margin-right: 2px;
1414
`
1515
export const WatchIcon = styled(BtnIcon)`
1616
fill: ${theme('button.fg')};
@@ -30,3 +30,23 @@ export const LoadingIcon = styled(BtnIcon)<{ light: boolean }>`
3030
${css.size(15)};
3131
animation: ${animate.rotate360} 1s linear infinite;
3232
`
33+
export const CheckedIcon = styled(BtnIcon)`
34+
fill: ${theme('baseColor.green')};
35+
`
36+
export const FollowedButton = styled(Button)`
37+
border-radius: 10px;
38+
`
39+
export const FollowingButton = styled(Button)`
40+
color: ${theme('thread.articleTitle')};
41+
/* color: ${theme('baseColor.green')}; */
42+
border: none;
43+
border-radius: 10px;
44+
background: #003745;
45+
padding-top: 2px;
46+
padding-bottom: 2px;
47+
48+
&:hover {
49+
background: #003745;
50+
/* border: 1px solid; */
51+
}
52+
`

0 commit comments

Comments
 (0)