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

Commit 9a9d24b

Browse files
authored
refactor(tags): redesign with hash concept (#1004)
* refactor(tags-bar): redesign wip: hash tag && mini chart * style(inline-tags): use hash style && post item margin adjust * style(post-item): active string positon adjust * style(tags-bar): make active tag look nice * refactor(tags-bar): re-org dir structure for fold feat * refactor(tags-bar): extract TagItem comp * refactor(tags-bar): group concept UI/UX
1 parent bc5f5af commit 9a9d24b

File tree

24 files changed

+553
-244
lines changed

24 files changed

+553
-244
lines changed

public/icons/static/hash-solid.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/InlineTags/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ import { buildLog, sortByColor, Trans } from '@/utils'
1111
import Maybe from '@/components/Maybe'
1212
import Tooltip from '@/components/Tooltip'
1313

14-
import { Wrapper, Tag, Dot, Title, MoreText, PopoverInfo } from './styles'
14+
import { Wrapper, Tag, HashSign, Title, MoreText, PopoverInfo } from './styles'
1515

1616
/* eslint-disable-next-line */
1717
const log = buildLog('c:InlineTags:index')
1818

19-
const FullList = ({ data, marginLeft }) => (
20-
<Wrapper marginLeft={marginLeft}>
21-
{sortByColor(data).map((tag) => (
22-
<Tag key={tag.title}>
23-
<Dot color={tag.color} />
24-
<Title>{Trans(tag.title)}</Title>
25-
</Tag>
26-
))}
27-
</Wrapper>
28-
)
19+
const FullList = ({ data, marginLeft }) => {
20+
return (
21+
<Wrapper marginLeft={marginLeft}>
22+
{sortByColor(data).map((tag) => (
23+
<Tag key={tag.title}>
24+
<HashSign color={tag.color} />
25+
<Title>{Trans(tag.title)}</Title>
26+
</Tag>
27+
))}
28+
</Wrapper>
29+
)
30+
}
2931

3032
const InlineTags = ({ data, max, marginLeft }) => {
3133
if (data.length > max) {
@@ -43,7 +45,7 @@ const InlineTags = ({ data, max, marginLeft }) => {
4345
.slice(0, max)
4446
.map((tag) => (
4547
<Tag key={tag.title}>
46-
<Dot color={tag.color} />
48+
<HashSign color={tag.color} />
4749
<Title>{Trans(tag.title)}</Title>
4850
</Tag>
4951
))}

src/components/InlineTags/styles/index.js

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

3-
/* import { Img } from '../..' */
3+
import HashTagSVG from '@/SvgIcons/HashTagSVG'
44
import { theme, css } from '@/utils'
55

66
export const Wrapper = styled.div`
@@ -16,7 +16,7 @@ export const Tag = styled.div`
1616
export const Title = styled.div`
1717
color: ${theme('thread.articleTag')};
1818
opacity: 0.8;
19-
font-size: 0.8rem;
19+
font-size: 12px;
2020
2121
${css.media.mobile`
2222
color: ${theme('thread.articleDigest')};
@@ -25,18 +25,18 @@ export const Title = styled.div`
2525
`};
2626
`
2727
export const MoreText = styled.div``
28-
export const Dot = styled.div`
29-
${css.circle(10)};
30-
margin-right: 4px;
31-
background-color: ${({ color }) => color};
32-
margin-top: -1px;
33-
28+
export const HashSign = styled(HashTagSVG)`
29+
fill: ${({ color }) => color};
30+
${css.size(12)};
31+
transform: rotate(18deg);
3432
opacity: ${theme('tags.dotOpacity')};
33+
margin-right: 2px;
3534
3635
${css.media.mobile`
37-
${css.circle(8)};
36+
${css.circle(10)};
3837
`};
3938
`
39+
4040
export const PopoverInfo = styled.div`
4141
padding: 10px;
4242
padding-top: 12px;

src/components/PostItem/DigestView/DesktopView/Body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Body = ({ item, onPreview }) => {
3939
</LeftPart>
4040
<SpaceGrow />
4141

42-
<ActiveItemWrapper>
42+
<ActiveItemWrapper hasComments={item.commentsCount > 0}>
4343
<Tooltip content={<div>最后回复</div>} placement="bottom">
4444
<ActiveIcon src={`${ICON}/shape/activity.svg`} />
4545
</Tooltip>

src/components/PostItem/styles/digest_view/body.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const Wrapper = styled.div`
1111
margin-top: -10px;
1212
`
1313
export const Extra = styled.li`
14+
position: relative;
1415
${css.flex('align-end')};
1516
color: ${theme('thread.extraInfo')};
1617
opacity: 0.7;
@@ -44,10 +45,13 @@ export const ViewsIcon = styled(Img)`
4445
`
4546

4647
export const ActiveItemWrapper = styled.div`
48+
position: absolute;
49+
top: ${({ hasComments }) => (hasComments ? '5px' : '-24px')};
50+
right: 0;
4751
${css.flex('align-center')};
4852
color: ${theme('thread.articleDigest')};
4953
margin-right: 6px;
50-
margin-top: 5px;
54+
margin-top: 8px;
5155
opacity: 0;
5256
5357
${Main}:hover & {

src/components/PostItem/styles/digest_view/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const Wrapper = styled.div`
88
`
99
export const Brief = styled.div`
1010
${css.flexGrow('align-center')};
11-
margin-bottom: 10px;
11+
margin-bottom: 7px;
1212
margin-left: 10px;
1313
color: ${theme('thread.articleTitle')};
1414
`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
3+
function SvgComponent(props) {
4+
return (
5+
<svg
6+
className="prefix__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+
<defs>
14+
<style />
15+
</defs>
16+
<path d="M925.5 541.9c-12.2-37.6-52.6-58.1-90.1-45.9l-80 26L703 360.9l80-26c37.6-12.2 58.1-52.6 45.9-90.1-12.2-37.6-52.6-58.1-90.1-45.9l-80 26-26.2-80.6c-12.2-37.6-52.6-58.1-90.1-45.9-37.5 12.2-58.1 52.6-45.9 90.1l26.2 80.6-161.1 52.4-26.2-80.6c-12.2-37.6-52.6-58.1-90.1-45.9s-58.1 52.6-45.9 90.1l26.2 80.6-81.1 26.4c-37.6 12.2-58.1 52.6-45.9 90.1 12.2 37.6 52.6 58.1 90.1 45.9l81.1-26.4 52.4 161.1-81.3 26.3c-37.6 12.2-58.1 52.6-45.9 90.1 12.2 37.6 52.6 58.1 90.1 45.9l81.1-26.4 26.2 80.6c12.2 37.6 52.6 58.1 90.1 45.9 37.6-12.2 58.1-52.6 45.9-90.1l-26.2-80.6 161.1-52.4 26.2 80.6c12.2 37.6 52.6 58.1 90.1 45.9 37.6-12.2 58.1-52.6 45.9-90.1l-26-80.5 80-26c37.5-12.1 58.1-52.5 45.9-90.1zm-467.3 76.7l-52.4-161.1L567 405.1l52.4 161.1-161.2 52.4z" />
17+
</svg>
18+
)
19+
}
20+
21+
export default SvgComponent

src/containers/unit/TagsBar/DesktopView.js

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import React, { useState } from 'react'
2+
3+
import { findIndex } from 'ramda'
4+
5+
import { ICON } from '@/config'
6+
import { sortByColor } from '@/utils'
7+
8+
import TagItem from './TagItem'
9+
10+
import { TagsWrapper } from '../styles/desktop_view'
11+
import {
12+
Wrapper,
13+
Header,
14+
ArrowIcon,
15+
Title,
16+
Content,
17+
SubToggle,
18+
SubToggleTitle,
19+
SubTogglePrefixIcon,
20+
} from '../styles/desktop_view/folder'
21+
22+
const MAX_DISPLAY_COUNT = 5
23+
const TOGGLE_SUB_TOGGLE_THROLD = 5 // TODO: only for test, should be 15
24+
25+
const Folder = ({ title, groupTags, allTags, activeTag, onSelect }) => {
26+
// 如果标签总数都没有超过 15 个,那么就不用显示 '展示更多'了,直接全部显示完事儿
27+
const needSubToggle = allTags?.length > TOGGLE_SUB_TOGGLE_THROLD || false
28+
29+
const initDisplayCount = needSubToggle ? MAX_DISPLAY_COUNT : groupTags.length
30+
31+
const [isFolderOpen, toggleFolder] = useState(true)
32+
const [curDisplayCount, setCurDisplayCount] = useState(initDisplayCount)
33+
34+
const sortedTags = sortByColor(groupTags)
35+
36+
const isActiveTagInFolder =
37+
findIndex((item) => item.id === activeTag.id, groupTags) >= 0
38+
39+
return (
40+
<Wrapper>
41+
<Header onClick={() => toggleFolder(!isFolderOpen)}>
42+
<ArrowIcon
43+
isOpen={isFolderOpen}
44+
src={`${ICON}/shape/arrow-simple.svg`}
45+
/>
46+
<Title>{title}</Title>
47+
{!isFolderOpen && isActiveTagInFolder && (
48+
<TagItem tag={activeTag} active isInline />
49+
)}
50+
</Header>
51+
52+
<Content isOpen={isFolderOpen}>
53+
<TagsWrapper>
54+
{sortedTags.slice(0, curDisplayCount).map((tag) => (
55+
<TagItem
56+
key={tag.id}
57+
tag={tag}
58+
active={activeTag.title === tag.title}
59+
activeId={activeTag.id}
60+
onSelect={onSelect}
61+
/>
62+
))}
63+
</TagsWrapper>
64+
{needSubToggle && (
65+
<SubToggle
66+
onClick={() => {
67+
setCurDisplayCount(
68+
curDisplayCount === MAX_DISPLAY_COUNT
69+
? groupTags.length
70+
: MAX_DISPLAY_COUNT,
71+
)
72+
}}
73+
>
74+
<SubTogglePrefixIcon src={`${ICON}/shape/more.svg`} />
75+
<SubToggleTitle>
76+
{curDisplayCount === MAX_DISPLAY_COUNT ? '展开更多' : '收起'}
77+
</SubToggleTitle>
78+
</SubToggle>
79+
)}
80+
</Content>
81+
</Wrapper>
82+
)
83+
}
84+
85+
export default Folder
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
3+
import { ICON } from '@/config'
4+
5+
import { Wrapper, TagIcon, TagTitle } from '../styles/desktop_view/goback_tag'
6+
import { onTagSelect } from '../logic'
7+
8+
const GobackTag = ({ onSelect }) => {
9+
const emptytag = { id: '', title: '', color: '' }
10+
11+
return (
12+
<Wrapper onClick={() => onTagSelect(emptytag, onSelect)}>
13+
<TagIcon src={`${ICON}/hash-solid.svg`} />
14+
<TagTitle>全部标签</TagTitle>
15+
</Wrapper>
16+
)
17+
}
18+
19+
export default GobackTag

0 commit comments

Comments
 (0)