Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitf15f26f

Browse files
authored
feat(notice-bar): extract common comp (#1064)
1 parent0a15926 commitf15f26f

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed
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+
importReactfrom'react'
2+
3+
import{ICON}from'@/config'
4+
import{LockIcon,NoticeIcon}from'./styles/icon'
5+
6+
typeTProps={
7+
type?:'lock'|'notice'|'bot'
8+
}
9+
10+
constIcon:React.FC<TProps>=({ type='notice'})=>{
11+
switch(type){
12+
case'lock':{
13+
return<LockIconsrc={`${ICON}/shape/lock.svg`}/>
14+
}
15+
default:{
16+
return<NoticeIconsrc={`${ICON}/shape/warning.svg`}/>
17+
}
18+
}
19+
}
20+
21+
exportdefaultReact.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+
importReactfrom'react'
8+
9+
importTimeAgofrom'timeago-react'
10+
11+
import{buildLog}from'@/utils'
12+
import{ICON}from'@/config'
13+
14+
importIconfrom'./Icon'
15+
16+
import{Wrapper,Main,UserName,AuthorTag,Timestamp,Why}from'./styles'
17+
18+
/* eslint-disable-next-line */
19+
constlog=buildLog('c:NoticeBar:index')
20+
21+
typeTProps={
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+
constNoticeBar: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+
<Wrappertestid={testid}>
42+
<Icontype={type}/>
43+
<Main>
44+
{user&&<UserName>{user.nickname}</UserName>}
45+
{isArticleAuthor&&<AuthorTag>(作者)</AuthorTag>}
46+
{content}
47+
</Main>
48+
{timestamp&&(
49+
<Timestamp>
50+
<TimeAgodatetime={timestamp}locale="zh_CN"/>
51+
</Timestamp>
52+
)}
53+
<Whysrc={`${ICON}/shape/question.svg`}/>
54+
</Wrapper>
55+
)
56+
}
57+
58+
exportdefaultReact.memo(NoticeBar)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
importstyledfrom'styled-components'
2+
3+
// import type { TTestable } from '@/spec'
4+
importImgfrom'@/Img'
5+
import{css,theme}from'@/utils'
6+
7+
constIcon=styled(Img)`
8+
fill: #a57a32; //${theme('thread.articleTitle')};
9+
${css.size(15)};
10+
margin-right: 12px;
11+
`
12+
exportconstLockIcon=styled(Icon)`
13+
fill: #a57a32; //${theme('thread.articleTitle')};
14+
`
15+
exportconstNoticeIcon=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+
importstyledfrom'styled-components'
2+
3+
importtype{TTestable}from'@/spec'
4+
5+
importImgfrom'@/Img'
6+
import{css,theme}from'@/utils'
7+
8+
exportconstWrapper=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+
exportconstMain=styled.div`
21+
flex-grow: 1;
22+
font-size: 14px;
23+
`
24+
exportconstUserName=styled.span`
25+
color:${theme('thread.articleTitle')};
26+
margin-right: 5px;
27+
`
28+
exportconstAuthorTag=styled.span`
29+
color:${theme('thread.articleDigest')};
30+
margin-left: 2px;
31+
margin-right: 5px;
32+
`
33+
exportconstTimestamp=styled.div`
34+
color:${theme('thread.articleDigest')};
35+
font-size: 12px;
36+
`
37+
exportconstWhy=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
importReactfrom'react'
88

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

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp