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

Commit d1c682f

Browse files
authored
refactor: faq outline mode (#1310)
* style(faq): adjust margin/layout * refactor(faq): ux for collapse FAQ
1 parent 78dca92 commit d1c682f

File tree

9 files changed

+126
-70
lines changed

9 files changed

+126
-70
lines changed

src/containers/thread/HelpThread/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { markStates, toJS } from '@/utils/mobx'
1313
const log = buildLog('S:HelpThread')
1414

1515
const HelpThread = T.model('HelpThread', {
16-
mode: T.optional(T.enumeration(['full', 'helpcenter', 'faq']), 'full'),
16+
// mode: T.optional(T.enumeration(['full', 'helpcenter', 'faq']), 'full'),
17+
mode: T.optional(T.enumeration(['full', 'helpcenter', 'faq']), 'faq'),
1718
})
1819
.views((self) => ({
1920
get curCommunity(): TCommunity {

src/containers/thread/HelpThread/styles/faq_layout.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import css from '@/utils/css'
44
import { MainWrapper } from './index'
55

66
export const Wrapper = styled(MainWrapper)`
7-
${css.flexColumn()};
8-
width: 100%;
9-
max-width: 800px;
10-
margin-top: 20px;
7+
${css.flexColumn('align-center')};
8+
margin-top: 30px;
119
padding-left: 22px;
10+
padding-right: 0;
1211
border-right: none;
1312
`
1413
export const Holder = styled.div``

src/containers/unit/Footer/styles/desktop_view/simple_layout.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import css, { theme } from '@/utils/css'
55
export const Wrapper = styled.div`
66
${css.flex('align-both')};
77
width: 100%;
8-
// the article page offset
9-
padding-right: 40px;
108
`
119
export const Note = styled.div`
1210
font-size: 13px;

src/widgets/ChangelogItem/styles/outline_layout/cover.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { theme } from '@/utils/css'
66
export const Wrapper = styled.div`
77
position: relative;
88
border: 1px solid;
9-
border-color: ${theme('border')};
9+
border-color: #c2c2c2;
1010
border-radius: 4px;
1111
width: 40px;
1212
height: 50px;
@@ -22,7 +22,8 @@ export const CoverImg = styled(Img)`
2222
const BaseBar = styled.div`
2323
position: absolute;
2424
height: 2px;
25-
background: ${theme('border')};
25+
background: ${theme('thread.extraInfo')};
26+
opacity: 0.4;
2627
border-radius: 2px;
2728
`
2829
export const DescBar = styled(BaseBar)`

src/widgets/ChangelogItem/styles/outline_layout/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
1010
'data-test-id': testid,
1111
}))<TTestable>`
1212
${css.flex('align-start')};
13-
margin-bottom: 14px;
13+
margin-bottom: 20px;
14+
cursor: pointer;
1415
`
1516
export const Main = styled.div`
1617
width: 574px;
1718
`
1819
export const Title = styled.div`
19-
color: ${theme('thread.articleTitle')};
20+
color: ${theme('thread.articleDigest')};
2021
font-size: 15px;
2122
font-weight: 580;
2223
margin-bottom: 2px;
24+
margin-top: 2px;
25+
26+
${Wrapper}:hover & {
27+
color: ${theme('thread.articleTitle')};
28+
}
2329
`
2430
export const Version = styled.span`
2531
color: ${theme('thread.articleDigest')};
@@ -34,7 +40,11 @@ export const Body = styled.div`
3440
color: ${theme('thread.articleDigest')};
3541
${css.lineClamp(1)};
3642
font-size: 14px;
37-
opacity: 0.9;
43+
opacity: 0.65;
44+
45+
${Wrapper}:hover & {
46+
opacity: 1;
47+
}
3848
`
3949
export const Footer = styled.div`
4050
${css.flex('align-center')};
@@ -66,9 +76,9 @@ export const DateTime = styled.div`
6676
`
6777
export const TagsWrapper = styled.div`
6878
${css.flex('align-center')};
69-
margin-top: 10px;
79+
margin-top: 13px;
7080
opacity: 0.8;
71-
margin-right: 2px;
81+
margin-right: 3px;
7282
`
7383
export const TagDot = styled.div<{ color: string }>`
7484
${css.circle(5)};

src/widgets/FaqList/Collapse.tsx

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
1-
import { FC, memo } from 'react'
1+
import { FC, memo, useState, useCallback } from 'react'
2+
import { includes, reject } from 'ramda'
3+
4+
import type { TID } from '@/spec'
25

36
import {
47
Wrapper,
5-
Header,
68
FAQ,
79
FAQTitle,
8-
FAQDesc,
10+
Header,
11+
Title,
12+
ArrowIcon,
13+
Body,
914
MoreLink,
1015
Section,
11-
ArrowIcon,
12-
Title,
16+
Footer,
1317
} from './styles/collapse'
1418

1519
import type { TProps as TIndex } from './index'
1620

1721
type TProps = Pick<TIndex, 'articles'>
1822

1923
const Collapse: FC<TProps> = ({ articles }) => {
24+
const [openedIDs, setOpenedIDs] = useState<TID[]>([])
25+
26+
const toggle = useCallback(
27+
(id) => {
28+
includes(id, openedIDs)
29+
? setOpenedIDs(reject((_id) => _id === id, openedIDs))
30+
: setOpenedIDs([id, ...openedIDs])
31+
},
32+
[openedIDs],
33+
)
34+
2035
return (
2136
<Wrapper>
22-
<Header>
23-
<FAQ>
24-
<FAQTitle>常见问题</FAQTitle>
25-
</FAQ>
26-
</Header>
27-
28-
{articles.map((item) => (
29-
<Section key={item.title}>
30-
<ArrowIcon />
31-
<Title>{item.title}</Title>
32-
</Section>
33-
))}
34-
35-
<FAQDesc>
37+
<FAQ>
38+
<FAQTitle>常见问题</FAQTitle>
39+
</FAQ>
40+
41+
{articles.map((item) => {
42+
const isOpend = includes(item.id, openedIDs)
43+
44+
return (
45+
<Section key={item.id}>
46+
<Header onClick={() => toggle(item.id)}>
47+
<Title $active={isOpend}>{item.title}</Title>
48+
<ArrowIcon $active={isOpend} />
49+
</Header>
50+
51+
<Body show={isOpend}>{item.body}</Body>
52+
</Section>
53+
)
54+
})}
55+
56+
<Footer>
3657
<div>如有其他疑问,请</div>
3758
<MoreLink>告诉我们</MoreLink>
38-
</FAQDesc>
59+
</Footer>
3960
</Wrapper>
4061
)
4162
}

src/widgets/FaqList/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { FC, memo } from 'react'
88

9+
import type { TArticle } from '@/spec'
910
import { buildLog } from '@/utils/logger'
1011

1112
import Sidebar from './Sidebar'
@@ -19,38 +20,41 @@ const log = buildLog('c:FaqList:index')
1920

2021
const defaultArticles = [
2122
{
23+
id: '1',
2224
title: '购买标准版或者高级版是否可开具发票?',
23-
body: '',
25+
body: '首先很多西方国家员工能摆烂,很大部分原因是他们有资本积累,在行业上游。有主导权和议价权,竞争壁垒高,别人就是可以三五个人占据关键岗位,剩下的事交给别人来做。',
2426
},
2527
{
28+
id: '2',
2629
title: '高级版使用过程中如何增加团队人数?',
27-
body: '',
30+
body: '曾遇见一个沃达丰的小哥,跑跨国业务线,工作之余就去学语言学管理。每次问他去不去摸鱼,他也去,只是期间我会选择玩几局王者,他在旁边看新语言的单词',
2831
},
2932
{
33+
id: '3',
3034
title: '小画桌如何保障数据安全?',
31-
body: '',
35+
body: '有廉价又产出高的不用,选择养这帮喜欢吃大锅饭的人?矛盾冲突是生产力,这个世界运作动力来自于竞争,不管是欧美也好,欠发达地区也好。',
3236
},
3337
{
38+
id: '4',
3439
title: '标准版是否可以升级为高级版?',
35-
body: '',
40+
body: '欧洲当年也内卷,然后罗曼洛夫一家都被扬了,整个苏联的资本家和贵族要么在电线杆上,要么不在俄国境内。',
3641
},
3742
{
43+
id: '5',
3844
title: '小画桌语音是否支持额外购买?',
3945
body: '是否支持7天无理由退款?',
4046
},
4147
{
48+
id: '6',
4249
title: '为什么修改了环境变量(或全局变量)值,而引用的地方没有生效?',
43-
body: '',
50+
body: '再然后只能吃土豆皮的基尔水兵就哗变了,整个德国的贵族和资本家害怕像俄国的同行们一样上电线杆,直接投降。',
4451
},
4552
]
4653

4754
export type TProps = {
4855
testid?: string
4956
mode?: 'sidebar' | 'search-hint' | 'collapse'
50-
articles?: {
51-
title: string
52-
body?: string
53-
}[]
57+
articles?: TArticle[]
5458
}
5559

5660
const FaqList: FC<TProps> = ({
Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
import styled from 'styled-components'
22

3+
import type { TActive } from '@/spec'
4+
35
import css, { theme } from '@/utils/css'
46
import FAQSVG from '@/icons/FAQ'
5-
import ArrowSVG from '@/icons/ArrowSolid'
7+
import ArrowSVG from '@/icons/ArrowSimple'
68

79
export const Wrapper = styled.div`
810
${css.flexColumn()};
9-
`
10-
export const Header = styled.div`
11-
margin-bottom: 20px;
11+
width: 55%;
12+
max-width: 55%;
13+
min-width: 550px;
14+
max-width: 550px;
1215
`
1316
export const FAQ = styled.div`
14-
${css.flex('align-center')};
17+
${css.flex('align-both')};
18+
margin-bottom: 34px;
19+
margin-left: -40px;
1520
`
1621
export const FAQIcon = styled(FAQSVG)`
17-
${css.size(16)};
22+
${css.size(18)};
1823
fill: ${theme('thread.articleDigest')};
19-
margin-right: 10px;
2024
margin-top: 2px;
2125
`
2226
export const FAQTitle = styled.div`
2327
color: ${theme('thread.articleTitle')};
2428
font-size: 20px;
2529
font-weight: 500;
2630
`
27-
export const FAQDesc = styled.div`
28-
${css.flex('align-center')};
31+
export const Footer = styled.div`
32+
${css.flex('align-both')};
2933
color: ${theme('thread.articleDigest')};
30-
padding-top: 5px;
3134
font-size: 12px;
32-
margin-top: 35px;
35+
margin-top: 60px;
36+
margin-left: -50px;
3337
`
3438
export const MoreLink = styled.div`
3539
color: ${theme('link')};
@@ -42,25 +46,41 @@ export const MoreLink = styled.div`
4246
transition: all 0.2s;
4347
`
4448
export const Section = styled.div`
45-
${css.flex('align-center')};
46-
padding-top: 20px;
47-
padding-bottom: 20px;
48-
border-bottom: 1px solid;
49-
border-bottom-color: ${theme('border')};
49+
padding: 18px 0;
50+
width: 100%;
5051
`
51-
export const ArrowIcon = styled(ArrowSVG)`
52-
${css.size(12)};
53-
fill: ${theme('thread.extraInfo')};
54-
margin-right: 10px;
52+
export const Header = styled.div`
53+
${css.flex('align-center', 'justify-between')};
54+
cursor: pointer;
5555
`
56-
export const Title = styled.div`
57-
${css.lineClamp(1)}
58-
color: ${theme('thread.articleDigest')};
56+
export const Title = styled.div<TActive>`
57+
${css.cutRest('440px')};
58+
color: ${({ $active }) =>
59+
$active ? theme('thread.articleTitle') : theme('thread.articleDigest')};
5960
font-size: 16px;
6061
font-weight: 500;
6162
62-
&:hover {
63+
${Section}:hover & {
6364
color: ${theme('thread.articleTitle')};
64-
cursor: pointer;
6565
}
6666
`
67+
export const Body = styled.div<TActive>`
68+
color: ${theme('thread.articleDigest')};
69+
font-size: 15px;
70+
margin-top: ${({ show }) => (show ? '12px' : 0)};
71+
max-height: ${({ show }) => (show ? 'auto' : 0)};
72+
line-height: 1.8;
73+
overflow: hidden;
74+
75+
opacity: ${({ show }) => (show ? 1 : 0)};
76+
transition: all 0.3s;
77+
`
78+
export const ArrowIcon = styled(ArrowSVG)<TActive>`
79+
${css.size(16)};
80+
fill: ${theme('thread.extraInfo')};
81+
margin-left: 20px;
82+
margin-right: 10px;
83+
transform: ${({ $active }) => ($active ? 'rotate(270deg)' : 'rotate(90deg)')};
84+
85+
transition: all 0.5s;
86+
`

src/widgets/FaqList/styles/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import styled from 'styled-components'
33
import type { TTestable } from '@/spec'
44

55
// import Img from '@/Img'
6-
// import { theme } from '@/utils/themes'
6+
import css from '@/utils/css'
77

88
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
99
'data-test-id': testid,
10-
}))<TTestable>``
10+
}))<TTestable>`
11+
${css.flexColumn('align-center')};
12+
`
1113

1214
export const Title = styled.div``

0 commit comments

Comments
 (0)