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

Commit cb39a54

Browse files
authored
feat(comment): fold & redesign (#1126)
* fix(copy-button): avoid un-expected animation with value change * fix(tooltip): z-index edge case * fix(switcher-icon): active style adjust * fix(report): reset view on close * feat(comment): basic fold/extand UI/UX * feat(comment): range bar wip
1 parent 9bd0162 commit cb39a54

File tree

27 files changed

+377
-85
lines changed

27 files changed

+377
-85
lines changed
Lines changed: 1 addition & 0 deletions
Loading

src/components/Buttons/CopyButton/Animate.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import { FC, memo, useEffect, useState } from 'react'
22

33
import { ICON } from '@/config'
44
import { IconButton } from '@/components/Buttons'
5-
import { CopyToClipboard } from 'react-copy-to-clipboard'
65

76
import { AnimateOnChange } from 'react-animation'
87
import { CopyedHintIcon } from '../styles/copy_button'
98

10-
type TProps = {
11-
value: string
12-
}
13-
14-
const CopyButton: FC<TProps> = ({ value }) => {
9+
const CopyButton: FC = () => {
1510
const [done, setDone] = useState(false)
1611

1712
useEffect(() => {
@@ -28,9 +23,13 @@ const CopyButton: FC<TProps> = ({ value }) => {
2823
durationOut={100}
2924
>
3025
{!done && (
31-
<CopyToClipboard text={value} onCopy={() => setDone(true)}>
32-
<IconButton path="article/clipboard.svg" mRight={5} />
33-
</CopyToClipboard>
26+
<IconButton
27+
path="article/clipboard.svg"
28+
mRight={5}
29+
onClick={() => {
30+
setDone(true)
31+
}}
32+
/>
3433
)}
3534
{done && <CopyedHintIcon src={`${ICON}/shape/checked.svg`} />}
3635
</AnimateOnChange>

src/components/Buttons/CopyButton/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { FC, memo } from 'react'
22
import dynamic from 'next/dynamic'
33

4+
import { CopyToClipboard } from 'react-copy-to-clipboard'
5+
46
import IconButton from '../IconButton'
57
import { Wrapper } from '../styles/copy_button'
68

@@ -19,7 +21,9 @@ type TProps = {
1921
const CopyButton: FC<TProps> = ({ value }) => {
2022
return (
2123
<Wrapper>
22-
<AnimatedCopyButton value={value} />
24+
<CopyToClipboard text={value}>
25+
<AnimatedCopyButton />
26+
</CopyToClipboard>
2327
</Wrapper>
2428
)
2529
}

src/components/Switcher/IconSwitcher.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,12 @@ const TabLabel: React.FC<TTabLabel> = ({ item, activeKey, onChange }) => {
4949
}
5050

5151
return (
52-
<Tooltip
53-
content={<DescText>{item.desc}</DescText>}
54-
placement="bottom"
55-
delay={500}
56-
noPadding
57-
>
58-
<Label onClick={() => onChange(item)}>
59-
{!nilOrEmpty(item.localIcon) && <>{item.localIcon}</>}
60-
{!nilOrEmpty(item.iconSrc) && (
61-
<Icon src={item.iconSrc} checked={activeKey === item.key} />
62-
)}
63-
</Label>
64-
</Tooltip>
52+
<Label onClick={() => onChange(item)}>
53+
{!nilOrEmpty(item.localIcon) && <>{item.localIcon}</>}
54+
{!nilOrEmpty(item.iconSrc) && (
55+
<Icon src={item.iconSrc} checked={activeKey === item.key} />
56+
)}
57+
</Label>
6558
)
6659
}
6760

@@ -79,12 +72,16 @@ const IconSwitcher: FC<TProps> = ({ items, activeKey, onChange }) => {
7972
<AccessZone />
8073
<Tabs>
8174
{items.map((item) => (
82-
<TabLabel
75+
<Tooltip
8376
key={item.key}
84-
item={item}
85-
activeKey={activeKey}
86-
onChange={onChange}
87-
/>
77+
content={<DescText>{item.desc}</DescText>}
78+
placement="top"
79+
delay={500}
80+
forceZIndex
81+
noPadding
82+
>
83+
<TabLabel item={item} activeKey={activeKey} onChange={onChange} />
84+
</Tooltip>
8885
))}
8986
<Slider index={slideIndex} />
9087
</Tabs>

src/components/Switcher/styles/icon_selector.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const Label = styled.label`
4343
width: ${width};
4444
height: ${height};
4545
font-size: 15px;
46-
z-index: 2;
4746
transition: color 0.15s ease-in;
4847
4948
&:hover {
@@ -57,11 +56,15 @@ export const DescText = styled.div`
5756
`
5857
export const Icon = styled(Img)<{ checked: boolean }>`
5958
fill: ${({ checked }) =>
60-
checked ? '#66b5e8' : theme('thread.articleDigest')};
59+
checked ? theme('thread.articleTitle') : theme('thread.articleDigest')};
6160
width: ${({ checked }) => (checked ? '14px' : '12px')};
6261
height: ${({ checked }) => (checked ? '14px' : '12px')};
6362
display: block;
6463
transition: all 0.25s;
64+
65+
&:hover {
66+
fill: #66b5e8;
67+
}
6568
`
6669
export const Slider = styled.span<{ index: number }>`
6770
${css.flex()};

src/components/Tooltip/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ type TProps = {
4141
// for same reason, figure out later
4242
contentHeight?: string
4343

44+
/**
45+
* z-index is a magic number for IconSwitcher's mask situation,
46+
* DO NOT USE unless you know what you are doing
47+
* 在类似 IconSwitcher 的场景下(有一个基于 positon: absolute 的滑动遮罩)的场景下,需要将外层
48+
* 的 ContentWrapper z-index 置为 1, 否则滑动遮罩会在最外面。
49+
*
50+
* 理论上 zIndex 一直设置为 1,也没问题,但是会导致某些使用了 Tooltip 的地方有严重的粘滞感,比如 “CopyRight” 那里。
51+
* 暂时没有精力看 Tippy 的具体实现,小心使用。
52+
*/
53+
forceZIndex?: boolean
54+
4455
onShow?: () => void
4556
onHide?: () => void
4657
onConfirm?: () => void
@@ -57,6 +68,7 @@ const Tooltip: FC<TProps> = ({
5768
content,
5869
hideOnClick = true,
5970
showArrow = false,
71+
forceZIndex = false,
6072
footerBehavior = 'default',
6173
trigger = 'mouseenter focus',
6274
onConfirm,
@@ -66,15 +78,15 @@ const Tooltip: FC<TProps> = ({
6678
const [active, setActive] = useState(false)
6779

6880
const ContentComp = showArrow ? (
69-
<ContentWrapper contentHeight={contentHeight}>
81+
<ContentWrapper contentHeight={contentHeight} forceZIndex={forceZIndex}>
7082
{active && placement === 'bottom' && <TopArrow />}
7183
{active && placement === 'top' && <BottomArrow />}
7284
{active && placement === 'right' && <LeftArrow />}
7385

7486
<div>{children}</div>
7587
</ContentWrapper>
7688
) : (
77-
<ContentWrapper contentHeight={contentHeight}>
89+
<ContentWrapper contentHeight={contentHeight} forceZIndex={forceZIndex}>
7890
<div>{children}</div>
7991
</ContentWrapper>
8092
)

src/components/Tooltip/styles/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export const NoPaddingStyledTippy = styled(StyledTippy)`
2626
padding: 0;
2727
}
2828
`
29-
export const ContentWrapper = styled.div<{ contentHeight: string }>`
29+
type TContentWrapper = { contentHeight: string; forceZIndex: boolean }
30+
export const ContentWrapper = styled.div<TContentWrapper>`
3031
position: relative;
3132
height: ${({ contentHeight }) => contentHeight};
32-
/* z-index: 1; */
33+
z-index: ${({ forceZIndex }) => (forceZIndex ? 1 : 0)};
3334
`
3435
const Arrow = styled.div`
3536
position: absolute;

src/components/Upvote/styles/comment_layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export const UpWrapper = styled.div`
1818
`
1919
export const CountWrapper = styled.div`
2020
margin-top: -4px;
21+
margin-left: 1px;
2122
`

src/containers/tool/AbuseReport/logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const selectItem = (checkedItemRaw: string): void => {
3636
store.mark({ checkedItemRaw, view: 'detail' })
3737
}
3838

39-
export const close = (): void => store.mark({ show: false })
39+
export const close = (): void => store.mark({ show: false, view: 'main' })
4040

4141
const DataResolver = [
4242
{

src/containers/tool/Share/styles/platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const LogoWrapper = styled.div<{ noBg: boolean }>`
4545
margin-bottom: 5px;
4646
`
4747
export const Logo = styled(Img)<{ small: boolean }>`
48-
fill: #e7f2f7; // ${theme('thread.articleTitle')};
48+
fill: ${theme('thread.articleTitle')};
4949
${({ small }) => (small ? css.circle('24px') : css.circle('38px'))};
5050
filter: saturate(0.6);
5151
opacity: 0.8;

0 commit comments

Comments
 (0)