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

Commit 5104542

Browse files
authored
refactor(post-item): preview in sidebar by default (#1312)
1 parent 097bd8d commit 5104542

File tree

11 files changed

+100
-93
lines changed

11 files changed

+100
-93
lines changed

src/containers/tool/Drawer/AddOn/CloseButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const CloseButton: FC = () => {
88
<IconButton
99
icon="close"
1010
onClick={closeDrawer}
11+
mTop={4}
1112
size={20}
12-
mLeft={7}
13-
dimWhenIdle
13+
mLeft={6}
1414
/>
1515
)
1616
}

src/containers/tool/Drawer/AddOn/ShareButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const ShareButton: FC = () => {
99
onClick={shareTo}
1010
path="article/share.svg"
1111
size={15}
12-
mTop={12}
12+
mTop={9}
1313
mRight={14}
14-
mLeft={15}
14+
mLeft={12}
1515
hint="分享内容"
1616
hintPlacement="bottom"
1717
dimWhenIdle

src/containers/tool/Drawer/styles/add_on/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from 'styled-components'
33
import css, { theme } from '@/utils/css'
44

55
export const Wrapper = styled.div`
6+
/* border: 1px solid tomato; */
67
width: 60px;
78
${css.flexColumn('align-end')};
89
@@ -11,20 +12,35 @@ export const Wrapper = styled.div`
1112
`};
1213
`
1314
export const TopArea = styled.div<{ showShare: boolean }>`
14-
width: 30px;
15+
width: 42px;
1516
height: ${({ showShare }) => (showShare ? '80px' : '50px')};
16-
17-
position: absolute;
17+
position: fixed;
1818
top: 0;
1919
left: 34px;
2020
display: block;
2121
background: white;
22-
border-bottom-left-radius: 40px;
22+
border-top-left-radius: 8px;
23+
border-bottom-left-radius: 28px;
2324
box-shadow: ${theme('drawer.closerShadow')};
2425
${css.flexColumn('align-both')}
25-
padding-left: 16px;
26+
padding-left: 12px;
27+
z-index: 100000;
2628
transform: rotate(2deg);
2729
30+
&:before {
31+
content: '';
32+
position: absolute;
33+
background: white;
34+
bottom: -7px;
35+
right: -9px;
36+
width: 25px;
37+
height: 9px;
38+
transform: rotate(42deg);
39+
border-bottom-left-radius: 0;
40+
border-bottom-right-radius: 15px;
41+
/* border: 1px solid lightgrey; */
42+
}
43+
2844
&:after {
2945
// this is for cover the box-shadow
3046
content: '';
@@ -34,7 +50,6 @@ export const TopArea = styled.div<{ showShare: boolean }>`
3450
right: -10px;
3551
width: 10px;
3652
height: 100%;
37-
/* border: 1px solid tomato; */
3853
}
3954
`
4055
export const MobileCloser = styled.div`

src/widgets/Buttons/IconButton.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,20 @@ const IconButton: FC<TProps> = ({
7373
mBottom={mBottom}
7474
onClick={onClick}
7575
>
76-
<>
77-
{hint ? (
78-
<Tooltip
79-
placement={hintPlacement}
80-
content={<Hint>{hint}</Hint>}
81-
noPadding
82-
delay={hintDelay}
83-
>
84-
<Content>{realIcon}</Content>
85-
</Tooltip>
86-
) : (
76+
{hint ? (
77+
<Tooltip
78+
placement={hintPlacement}
79+
content={<Hint>{hint}</Hint>}
80+
noPadding
81+
delay={hintDelay}
82+
forceZIndex
83+
>
8784
<Content>{realIcon}</Content>
88-
)}
89-
<HoverBg size={size} />
90-
</>
85+
</Tooltip>
86+
) : (
87+
<Content>{realIcon}</Content>
88+
)}
89+
<HoverBg size={size} />
9190
</Wrapper>
9291
)
9392
}

src/widgets/Buttons/styles/icon_button.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import MoreIcon from '@/icons/More'
2929

3030
import type { TProps as TIconButtonProps } from '../IconButton'
3131

32-
const CloseCross = dynamic(() => import('@/icons/CloseCross'), {
32+
const CloseCross = dynamic(() => import('@/icons/CloseLight'), {
3333
ssr: false,
3434
})
3535

@@ -64,6 +64,7 @@ export const HoverBg = styled.div<{ size: number }>`
6464
top: -2px;
6565
background: ${theme('hoverBg')};
6666
opacity: 0;
67+
cursor: pointer;
6768
6869
${Wrapper}:hover & {
6970
opacity: 1;

src/widgets/Icons/CloseLight.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { memo, SVGProps } from 'react'
2+
3+
const CloseLight = (props: SVGProps<SVGSVGElement>) => {
4+
return (
5+
<svg
6+
className="icon"
7+
viewBox="0 0 1024 1024"
8+
xmlns="http://www.w3.org/2000/svg"
9+
width={200}
10+
height={200}
11+
{...props}
12+
>
13+
<path d="m512 451.67 225.835-225.835a42.667 42.667 0 0 1 60.33 60.33L572.331 512l225.834 225.835a42.667 42.667 0 0 1-60.33 60.33L512 572.331 286.165 798.165a42.667 42.667 0 1 1-60.33-60.33L451.669 512 225.835 286.165a42.667 42.667 0 0 1 60.33-60.33L512 451.669z" />
14+
</svg>
15+
)
16+
}
17+
18+
export default memo(CloseLight)

src/widgets/Modal/styles/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from 'styled-components'
22

33
import type { TActive } from '@/spec'
44
import css, { theme, animate } from '@/utils/css'
5-
import CloseCrossSVG from '@/icons/CloseCross'
5+
import CloseCrossSVG from '@/icons/CloseLight'
66

77
// display: ${props => (props.show ? 'block' : 'none')};
88
export const Mask = styled.div<TActive>`
@@ -53,13 +53,13 @@ export const ChildrenWrapper = styled.div`
5353
type TCloseBtn = { mode: string }
5454
export const CloseBtn = styled(CloseCrossSVG)<TCloseBtn>`
5555
position: absolute;
56-
top: 12px;
57-
right: 14px;
56+
top: 16px;
57+
right: 18px;
5858
fill: ${({ mode }) =>
5959
mode === 'default' ? theme('thread.extraInfo') : theme('baseColor.red')};
6060
${css.size(20)};
6161
z-index: ${css.zIndex.modalCloseBtn};
62-
opacity: 0.5;
62+
opacity: 0.8;
6363
6464
&:hover {
6565
animation: ${animate.pulse} 0.3s linear;

src/widgets/PostItem/DesktopView/Header.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { FC, useCallback } from 'react'
2-
import Router from 'next/router'
1+
import { FC } from 'react'
32
import dynamic from 'next/dynamic'
43

54
import type { TPost } from '@/spec'
6-
import { ARTICLE_THREAD } from '@/constant'
5+
import { EVENT } from '@/constant'
6+
7+
import { send } from '@/utils/helper'
78

89
import AvatarsRow from '@/widgets/AvatarsRow'
910
// import TagsList from '@/widgets/TagsList'
1011

11-
import { Wrapper, Brief, Title } from '../styles/desktop_view/header'
12-
13-
// const AvatarsRow = dynamic(() => import('@/widgets/AvatarsRow'), {
14-
// ssr: false,
15-
// })
12+
import {
13+
Wrapper,
14+
Brief,
15+
Title,
16+
AvatarsWrapper,
17+
} from '../styles/desktop_view/header'
1618

1719
const TagsList = dynamic(() => import('@/widgets/TagsList'), {
1820
ssr: false,
@@ -23,28 +25,25 @@ type TProps = {
2325
}
2426

2527
const Header: FC<TProps> = ({ item }) => {
26-
const gotoArticle = useCallback(() => {
27-
Router.push(`/${ARTICLE_THREAD.POST}/${item.id}`)
28-
}, [item.id])
28+
// const gotoArticle = useCallback(() => {
29+
// Router.push(`/${ARTICLE_THREAD.POST}/${item.id}`)
30+
// }, [item.id])
2931

3032
return (
3133
<Wrapper>
3234
<Brief>
33-
<Title onClick={gotoArticle}>{item.title}</Title>
34-
{/* {item.linkAddr && (
35-
<TitleLink>
36-
<LinkIcon />
37-
<span style={{ marginLeft: 9 }}>{parseDomain(item.linkAddr)}</span>
38-
</TitleLink>
39-
)} */}
40-
35+
<Title onClick={() => send(EVENT.PREVIEW_ARTICLE, { article: item })}>
36+
{item.title}
37+
</Title>
4138
{/* @ts-ignore */}
4239
<TagsList items={item.articleTags} mLeft={12} />
4340
</Brief>
44-
<AvatarsRow
45-
users={item.commentsParticipants}
46-
total={item.commentsCount}
47-
/>
41+
<AvatarsWrapper>
42+
<AvatarsRow
43+
users={item.commentsParticipants}
44+
total={item.commentsCount}
45+
/>
46+
</AvatarsWrapper>
4847
</Wrapper>
4948
)
5049
}

src/widgets/PostItem/styles/desktop_view/header.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export const Brief = styled.div`
1313
color: ${theme('thread.articleTitle')};
1414
`
1515
export const Title = styled.div`
16+
position: relative;
1617
font-size: 15px;
1718
font-weight: 600;
1819
color: ${theme('thread.articleTitle')};
19-
text-decoration: none;
20+
2021
@media (max-width: 1450px) {
2122
${css.cutRest('500px')};
2223
}
@@ -29,13 +30,14 @@ export const Title = styled.div`
2930
3031
&:hover {
3132
color: ${theme('thread.articleDigest')};
32-
text-decoration: underline;
33-
text-decoration-color: ${theme('thread.articleDigest')};
3433
cursor: pointer;
3534
}
3635
3736
transition: color 0.2s;
3837
`
38+
export const TitlePopInfo = styled.div`
39+
padding: 4px 8px;
40+
`
3941
export const TitleLink = styled.div`
4042
position: relative;
4143
font-size: 15px;
@@ -52,3 +54,7 @@ export const LinkIcon = styled(LinkSVG)`
5254
left: -5px;
5355
${css.size(12)};
5456
`
57+
58+
export const AvatarsWrapper = styled.div`
59+
margin-top: -1px;
60+
`

src/widgets/Tooltip/RealTooltip.tsx

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
* use custom animation Globally at GlobalStyle.ts
55
*/
66

7-
import { FC, ReactNode, useState, useRef, memo } from 'react'
7+
import { FC, useState, useRef, memo } from 'react'
88
import { hideAll } from 'tippy.js'
99

10-
import type { TTooltipPlacement } from '@/spec'
11-
1210
import css from '@/utils/css'
1311
import { buildLog } from '@/utils/logger'
1412
import { isString } from '@/utils/validator'
1513
import { isDescendant } from '@/utils/dom'
1614

1715
import useOutsideClick from '@/hooks/useOutsideClick'
1816

17+
import type { TProps } from './index'
1918
import ConfirmFooter from './ConfirmFooter'
2019
import { FOOTER_BEHAVIOR } from './constant'
2120

@@ -32,39 +31,6 @@ import {
3231
/* eslint-disable-next-line */
3332
const log = buildLog('c:Tooltip:index')
3433

35-
type TProps = {
36-
children: ReactNode
37-
content: string | ReactNode
38-
placement?: TTooltipPlacement
39-
// more options see: https://atomiks.github.io/tippyjs/all-options/
40-
delay?: number
41-
duration?: number
42-
trigger?: 'mouseenter focus' | 'click'
43-
hideOnClick?: boolean
44-
noPadding?: boolean
45-
showArrow?: boolean
46-
behavior?: 'default' | 'confirm' | 'delete-confirm' | 'add'
47-
// currently only for AvatarsRow, it will collapse the height
48-
// for same reason, figure out later
49-
contentHeight?: string
50-
51-
/**
52-
* z-index is a magic number for IconSwitcher's mask situation,
53-
* DO NOT USE unless you know what you are doing
54-
* 在类似 IconSwitcher 的场景下(有一个基于 positon: absolute 的滑动遮罩)的场景下,需要将外层
55-
* 的 ChildrenWrapper z-index 置为 1, 否则滑动遮罩会在最外面。
56-
*
57-
* 理论上 zIndex 一直设置为 1,也没问题,但是会导致某些使用了 Tooltip 的地方有严重的粘滞感,比如 “CopyRight” 那里。
58-
* 暂时没有精力看 Tippy 的具体实现,小心使用。
59-
*/
60-
forceZIndex?: boolean
61-
interactive?: boolean
62-
63-
onShow?: () => void
64-
onHide?: () => void
65-
onConfirm?: () => void
66-
}
67-
6834
const Tooltip: FC<TProps> = ({
6935
children,
7036
noPadding = false,
@@ -73,6 +39,7 @@ const Tooltip: FC<TProps> = ({
7339
onShow,
7440
placement = 'top',
7541
delay = 0,
42+
offset = [5, 5],
7643
duration = 0,
7744
content,
7845
hideOnClick = true,
@@ -149,7 +116,8 @@ const Tooltip: FC<TProps> = ({
149116
zIndex: css.zIndex.popover,
150117
active: true,
151118
delay: [delay, 0] as [number, number],
152-
offset: [5, 5] as [number, number],
119+
offset,
120+
// offset: [0, -8] as [number, number],
153121
duration,
154122
trigger,
155123
// see https://github.com/atomiks/tippyjs/issues/751#issuecomment-611979594 for detail

0 commit comments

Comments
 (0)