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

feat(notice-bar): extract common comp #1064

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/icons/static/shape/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/components/NoticeBar/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'

import { ICON } from '@/config'
import { LockIcon, NoticeIcon } from './styles/icon'

type TProps = {
type?: 'lock' | 'notice' | 'bot'
}

const Icon: React.FC<TProps> = ({ type = 'notice' }) => {
switch (type) {
case 'lock': {
return <LockIcon src={`${ICON}/shape/lock.svg`} />
}
default: {
return <NoticeIcon src={`${ICON}/shape/warning.svg`} />
}
}
}

export default React.memo(Icon)
58 changes: 58 additions & 0 deletions src/components/NoticeBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
*
* NoticeBar
*
*/

import React from 'react'

import TimeAgo from 'timeago-react'

import { buildLog } from '@/utils'
import { ICON } from '@/config'

import Icon from './Icon'

import { Wrapper, Main, UserName, AuthorTag, Timestamp, Why } from './styles'

/* eslint-disable-next-line */
const log = buildLog('c:NoticeBar:index')

type TProps = {
testid?: string
type?: 'lock' | 'notice' | 'bot'
user?: {
nickname: string
} | null
isArticleAuthor?: boolean
content: string
timestamp?: string | null
}

const NoticeBar: React.FC<TProps> = ({
testid = 'notice-bar',
type = 'notice',
user = null,
isArticleAuthor = false,
content,
timestamp = null,
}) => {
return (
<Wrapper testid={testid}>
<Icon type={type} />
<Main>
{user && <UserName>{user.nickname}</UserName>}
{isArticleAuthor && <AuthorTag>(作者)</AuthorTag>}
{content}
</Main>
{timestamp && (
<Timestamp>
<TimeAgo datetime={timestamp} locale="zh_CN" />
</Timestamp>
)}
<Why src={`${ICON}/shape/question.svg`} />
</Wrapper>
)
}

export default React.memo(NoticeBar)
17 changes: 17 additions & 0 deletions src/components/NoticeBar/styles/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from 'styled-components'

// import type { TTestable } from '@/spec'
import Img from '@/Img'
import { css, theme } from '@/utils'

const Icon = styled(Img)`
fill: #a57a32; // ${theme('thread.articleTitle')};
${css.size(15)};
margin-right: 12px;
`
export const LockIcon = styled(Icon)`
fill: #a57a32; // ${theme('thread.articleTitle')};
`
export const NoticeIcon = styled(Icon)`
fill: #a57a32; // ${theme('thread.articleTitle')};
`
47 changes: 47 additions & 0 deletions src/components/NoticeBar/styles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import styled from 'styled-components'

import type { TTestable } from '@/spec'

import Img from '@/Img'
import { css, theme } from '@/utils'

export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
'data-test-id': testid,
}))<TTestable>`
${css.flex('align-center')};
color: ${theme('thread.articleTitle')};
padding-left: 12px;
padding-right: 15px;
width: 100%;
height: 40px;
background: #00333f;
border-radius: 8px;
`
export const Main = styled.div`
flex-grow: 1;
font-size: 14px;
`
export const UserName = styled.span`
color: ${theme('thread.articleTitle')};
margin-right: 5px;
`
export const AuthorTag = styled.span`
color: ${theme('thread.articleDigest')};
margin-left: 2px;
margin-right: 5px;
`
export const Timestamp = styled.div`
color: ${theme('thread.articleDigest')};
font-size: 12px;
`
export const Why = styled(Img)`
${css.size(15)};
fill: ${theme('thread.articleDigest')};
margin-left: 10px;
margin-top: -1px;

&:hover {
fill: ${theme('thread.articleTitle')};
cursor: pointer;
}
`
10 changes: 10 additions & 0 deletions src/components/NoticeBar/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// import React from 'react'
// import { shallow } from 'enzyme'

// import NoticeBar from '../index'

describe('TODO <NoticeBar />', () => {
it('Expect to have unit tests specified', () => {
expect(true).toEqual(true)
})
})
11 changes: 11 additions & 0 deletions src/containers/unit/Comments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import React from 'react'

import { pluggedIn, buildLog } from '@/utils'

import Modal from '@/components/Modal'
import NoticeBar from '@/components/NoticeBar'

import CommentEditor from './CommentEditor'
import List from './List'
Expand Down Expand Up @@ -75,6 +77,15 @@ const CommentsContainer: React.FC<TProps> = ({
/>
)}

<br />
<NoticeBar
type="lock"
content="关闭了评论: 已解决"
timestamp={new Date().toLocaleDateString()}
user={{ nickname: 'mydearxym' }}
isArticleAuthor
/>

<List
accountInfo={accountInfo}
pagedComments={pagedCommentsData}
Expand Down