This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork37
feat(notice-bar): extract common comp#1064
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionspublic/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 deletionssrc/components/NoticeBar/Icon.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/components/NoticeBar/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/components/NoticeBar/styles/icon.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/components/NoticeBar/styles/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/components/NoticeBar/tests/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 deletionssrc/containers/unit/Comments/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.