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.

refactor(follow-button): UI/UX adjust#1119

Merged
mydearxym merged 1 commit intodevfromanimated-follow-button
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletionssrc/components/Buttons/FollowButton/FollowedBtn.js
View file
Open in desktop

This file was deleted.

29 changes: 29 additions & 0 deletionssrc/components/Buttons/FollowButton/FollowedBtn.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
import { FC, memo } from 'react'

import { TSIZE_TSM } from '@/spec'
import { LavaLampLoading } from '@/components/Loading'

import { BtnWrapper, FollowedButton } from '../styles/follow_button'

type TProps = {
size: TSIZE_TSM
loading: boolean
text: string
onClick: () => void
}

const FollowBtn: FC<TProps> = ({ size, loading, text, onClick }) => {
return (
<>
{loading ? (
<LavaLampLoading size="small" />
) : (
<FollowedButton size={size} type="primary" onClick={onClick} ghost>
<BtnWrapper>{text}</BtnWrapper>
</FollowedButton>
)}
</>
)
}

export default memo(FollowBtn)
49 changes: 0 additions & 49 deletionssrc/components/Buttons/FollowButton/FollowingBtn.js
View file
Open in desktop

This file was deleted.

53 changes: 53 additions & 0 deletionssrc/components/Buttons/FollowButton/FollowingBtn.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
import { FC, memo } from 'react'

import { TSIZE_TSM } from '@/spec'
import { ICON } from '@/config'

import { LavaLampLoading } from '@/components/Loading'
import Tooltip from '@/components/Tooltip'

import {
BtnWrapper,
Popinfo,
CheckedIcon,
FollowingButton,
} from '../styles/follow_button'

type TProps = {
size: TSIZE_TSM
loading: boolean
text: string
onClick: () => void
}

const FollowingBtn: FC<TProps> = ({ size, loading, text, onClick }) => {
return (
<>
{loading ? (
<LavaLampLoading size="small" />
) : (
<Tooltip
placement="bottom"
delay={800}
content={<Popinfo>点击取消关注</Popinfo>}
noPadding
>
<FollowingButton
size={size}
type="primary"
ghost
onClick={onClick}
noBorder
>
<BtnWrapper>
<CheckedIcon src={`${ICON}/shape/checked.svg`} />
{text}
</BtnWrapper>
</FollowingButton>
</Tooltip>
)}
</>
)
}

export default memo(FollowingBtn)
86 changes: 0 additions & 86 deletionssrc/components/Buttons/FollowButton/index.js
View file
Open in desktop

This file was deleted.

80 changes: 80 additions & 0 deletionssrc/components/Buttons/FollowButton/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
/*
* FollowButton
*/

import { FC, memo, useState, useCallback } from 'react'

import { TID, TSIZE_TSM } from '@/spec'
import { buildLog } from '@/utils'
import { SIZE } from '@/constant'

import FollowingBtn from './FollowingBtn'
import FollowedBtn from './FollowedBtn'

/* eslint-disable-next-line */
const log = buildLog('c:FollowButton:index')

type TProps = {
hasFollowed?: boolean
userId?: TID
size?: TSIZE_TSM
loading?: boolean
fakeLoading?: boolean
followText?: string
followingText?: string
onFollow?: (userId: TID) => void
onUndoFollow?: (userId: TID) => void
}

const FollowButton: FC<TProps> = ({
userId,
size = SIZE.SMALL,
fakeLoading = false,
loading = false,
hasFollowed = false,
followText = '关 注',
followingText = '已关注',
onFollow = log,
onUndoFollow = log,
}) => {
const [simuLoading, setSimuLoading] = useState(false)
const isLoading = fakeLoading ? simuLoading : loading

const handleFollow = useCallback(() => {
if (fakeLoading) {
setSimuLoading(true)
setTimeout(() => setSimuLoading(false), 1500)
}
onFollow(userId)
}, [fakeLoading, onFollow, userId])

const handleUndoFollow = useCallback(() => {
if (fakeLoading) {
setSimuLoading(true)
setTimeout(() => setSimuLoading(false), 1500)
}
onUndoFollow(userId)
}, [fakeLoading, onUndoFollow, userId])

return (
<>
{hasFollowed ? (
<FollowingBtn
size={size}
loading={isLoading}
text={followingText}
onClick={handleUndoFollow}
/>
) : (
<FollowedBtn
size={size}
loading={isLoading}
text={followText}
onClick={handleFollow}
/>
)}
</>
)
}

export default memo(FollowButton)
28 changes: 24 additions & 4 deletionssrc/components/Buttons/styles/follow_button/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
import styled from 'styled-components'

import { theme, animate, css } from '@/utils'
import Button from '@/components/Buttons/Button'
import Img from '@/Img'

export const BtnWrapper = styled.div`
${css.flex('align-center')};
padding: 2px 5px;
`
const BtnIcon = styled(Img)`
height: 12px;
width: 12px;
display: block;
margin-right: 3px;
${css.size(14)};
margin-right: 2px;
`
export const WatchIcon = styled(BtnIcon)`
fill: ${theme('button.fg')};
Expand All@@ -30,3 +30,23 @@ export const LoadingIcon = styled(BtnIcon)<{ light: boolean }>`
${css.size(15)};
animation: ${animate.rotate360} 1s linear infinite;
`
export const CheckedIcon = styled(BtnIcon)`
fill: ${theme('baseColor.green')};
`
export const FollowedButton = styled(Button)`
border-radius: 10px;
`
export const FollowingButton = styled(Button)`
color: ${theme('thread.articleTitle')};
/* color: ${theme('baseColor.green')}; */
border: none;
border-radius: 10px;
background: #003745;
padding-top: 2px;
padding-bottom: 2px;

&:hover {
background: #003745;
/* border: 1px solid; */
}
`
Loading

[8]ページ先頭

©2009-2025 Movatter.jp