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

Commit f15f26f

Browse files
authored
feat(notice-bar): extract common comp (#1064)
1 parent 0a15926 commit f15f26f

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed

public/icons/static/shape/warning.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/NoticeBar/Icon.tsx

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+
import { ICON } from '@/config'
4+
import { LockIcon, NoticeIcon } from './styles/icon'
5+
6+
type TProps = {
7+
type?: 'lock' | 'notice' | 'bot'
8+
}
9+
10+
const Icon: React.FC<TProps> = ({ type = 'notice' }) => {
11+
switch (type) {
12+
case 'lock': {
13+
return <LockIcon src={`${ICON}/shape/lock.svg`} />
14+
}
15+
default: {
16+
return <NoticeIcon src={`${ICON}/shape/warning.svg`} />
17+
}
18+
}
19+
}
20+
21+
export default React.memo(Icon)

src/components/NoticeBar/index.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
*
3+
* NoticeBar
4+
*
5+
*/
6+
7+
import React from 'react'
8+
9+
import TimeAgo from 'timeago-react'
10+
11+
import { buildLog } from '@/utils'
12+
import { ICON } from '@/config'
13+
14+
import Icon from './Icon'
15+
16+
import { Wrapper, Main, UserName, AuthorTag, Timestamp, Why } from './styles'
17+
18+
/* eslint-disable-next-line */
19+
const log = buildLog('c:NoticeBar:index')
20+
21+
type TProps = {
22+
testid?: string
23+
type?: 'lock' | 'notice' | 'bot'
24+
user?: {
25+
nickname: string
26+
} | null
27+
isArticleAuthor?: boolean
28+
content: string
29+
timestamp?: string | null
30+
}
31+
32+
const NoticeBar: React.FC<TProps> = ({
33+
testid = 'notice-bar',
34+
type = 'notice',
35+
user = null,
36+
isArticleAuthor = false,
37+
content,
38+
timestamp = null,
39+
}) => {
40+
return (
41+
<Wrapper testid={testid}>
42+
<Icon type={type} />
43+
<Main>
44+
{user && <UserName>{user.nickname}</UserName>}
45+
{isArticleAuthor && <AuthorTag>(作者)</AuthorTag>}
46+
{content}
47+
</Main>
48+
{timestamp && (
49+
<Timestamp>
50+
<TimeAgo datetime={timestamp} locale="zh_CN" />
51+
</Timestamp>
52+
)}
53+
<Why src={`${ICON}/shape/question.svg`} />
54+
</Wrapper>
55+
)
56+
}
57+
58+
export default React.memo(NoticeBar)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import styled from 'styled-components'
2+
3+
// import type { TTestable } from '@/spec'
4+
import Img from '@/Img'
5+
import { css, theme } from '@/utils'
6+
7+
const Icon = styled(Img)`
8+
fill: #a57a32; // ${theme('thread.articleTitle')};
9+
${css.size(15)};
10+
margin-right: 12px;
11+
`
12+
export const LockIcon = styled(Icon)`
13+
fill: #a57a32; // ${theme('thread.articleTitle')};
14+
`
15+
export const NoticeIcon = styled(Icon)`
16+
fill: #a57a32; // ${theme('thread.articleTitle')};
17+
`
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import styled from 'styled-components'
2+
3+
import type { TTestable } from '@/spec'
4+
5+
import Img from '@/Img'
6+
import { css, theme } from '@/utils'
7+
8+
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
9+
'data-test-id': testid,
10+
}))<TTestable>`
11+
${css.flex('align-center')};
12+
color: ${theme('thread.articleTitle')};
13+
padding-left: 12px;
14+
padding-right: 15px;
15+
width: 100%;
16+
height: 40px;
17+
background: #00333f;
18+
border-radius: 8px;
19+
`
20+
export const Main = styled.div`
21+
flex-grow: 1;
22+
font-size: 14px;
23+
`
24+
export const UserName = styled.span`
25+
color: ${theme('thread.articleTitle')};
26+
margin-right: 5px;
27+
`
28+
export const AuthorTag = styled.span`
29+
color: ${theme('thread.articleDigest')};
30+
margin-left: 2px;
31+
margin-right: 5px;
32+
`
33+
export const Timestamp = styled.div`
34+
color: ${theme('thread.articleDigest')};
35+
font-size: 12px;
36+
`
37+
export const Why = styled(Img)`
38+
${css.size(15)};
39+
fill: ${theme('thread.articleDigest')};
40+
margin-left: 10px;
41+
margin-top: -1px;
42+
43+
&:hover {
44+
fill: ${theme('thread.articleTitle')};
45+
cursor: pointer;
46+
}
47+
`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import NoticeBar from '../index'
5+
6+
describe('TODO <NoticeBar />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

src/containers/unit/Comments/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import React from 'react'
88

99
import { pluggedIn, buildLog } from '@/utils'
10+
1011
import Modal from '@/components/Modal'
12+
import NoticeBar from '@/components/NoticeBar'
1113

1214
import CommentEditor from './CommentEditor'
1315
import List from './List'
@@ -75,6 +77,15 @@ const CommentsContainer: React.FC<TProps> = ({
7577
/>
7678
)}
7779

80+
<br />
81+
<NoticeBar
82+
type="lock"
83+
content="关闭了评论: 已解决"
84+
timestamp={new Date().toLocaleDateString()}
85+
user={{ nickname: 'mydearxym' }}
86+
isArticleAuthor
87+
/>
88+
7889
<List
7990
accountInfo={accountInfo}
8091
pagedComments={pagedCommentsData}

0 commit comments

Comments
 (0)