From 8895a2fd2d6d0de36ca5919907e404ca0f77a8a2 Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Tue, 9 Oct 2018 10:12:13 +0800 Subject: [PATCH] extract ListContent as a component (#2482) * extract ListContent as a component * rename ListContent to ArticleListContent --- src/components/ArticleListContent/index.js | 17 +++++++++ src/components/ArticleListContent/index.less | 38 ++++++++++++++++++++ src/pages/Account/Center/Articles.js | 19 +++------- src/pages/Account/Center/Articles.less | 5 +++ src/pages/List/Articles.js | 28 +++------------ src/pages/List/Articles.less | 34 ------------------ 6 files changed, 69 insertions(+), 72 deletions(-) create mode 100644 src/components/ArticleListContent/index.js create mode 100644 src/components/ArticleListContent/index.less diff --git a/src/components/ArticleListContent/index.js b/src/components/ArticleListContent/index.js new file mode 100644 index 00000000..c4525d6a --- /dev/null +++ b/src/components/ArticleListContent/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import moment from 'moment'; +import { Avatar } from 'antd'; +import styles from './index.less'; + +const ArticleListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => ( +
+
{content}
+
+ + {owner} 发布在 {href} + {moment(updatedAt).format('YYYY-MM-DD HH:mm')} +
+
+); + +export default ArticleListContent; diff --git a/src/components/ArticleListContent/index.less b/src/components/ArticleListContent/index.less new file mode 100644 index 00000000..acf2c919 --- /dev/null +++ b/src/components/ArticleListContent/index.less @@ -0,0 +1,38 @@ +@import '~antd/lib/style/themes/default.less'; + +.listContent { + .description { + line-height: 22px; + max-width: 720px; + } + .extra { + color: @text-color-secondary; + margin-top: 16px; + line-height: 22px; + & > :global(.ant-avatar) { + vertical-align: top; + margin-right: 8px; + width: 20px; + height: 20px; + position: relative; + top: 1px; + } + & > em { + color: @disabled-color; + font-style: normal; + margin-left: 16px; + } + } +} + +@media screen and (max-width: @screen-xs) { + .listContent { + .extra { + & > em { + display: block; + margin-left: 0; + margin-top: 8px; + } + } + } +} diff --git a/src/pages/Account/Center/Articles.js b/src/pages/Account/Center/Articles.js index dcdaf873..9bb5ac30 100644 --- a/src/pages/Account/Center/Articles.js +++ b/src/pages/Account/Center/Articles.js @@ -1,8 +1,7 @@ import React, { PureComponent } from 'react'; -import { List, Icon, Avatar, Tag } from 'antd'; -import moment from 'moment'; +import { List, Icon, Tag } from 'antd'; import { connect } from 'dva'; -import stylesArticles from '../../List/Articles.less'; +import ArticleListContent from '@/components/ArticleListContent'; import styles from './Articles.less'; @connect(({ list }) => ({ @@ -19,16 +18,6 @@ class Center extends PureComponent { {text} ); - const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => ( -
-
{content}
-
- - {owner} 发布在 {href} - {moment(updatedAt).format('YYYY-MM-DD HH:mm')} -
-
- ); return ( + {item.title} } @@ -59,7 +48,7 @@ class Center extends PureComponent { } /> - + )} /> diff --git a/src/pages/Account/Center/Articles.less b/src/pages/Account/Center/Articles.less index 36cdd0c3..2e51509b 100644 --- a/src/pages/Account/Center/Articles.less +++ b/src/pages/Account/Center/Articles.less @@ -1,3 +1,5 @@ +@import '~antd/lib/style/themes/default.less'; + .articleList { :global { .ant-list-item:first-child { @@ -5,3 +7,6 @@ } } } +a.listItemMetaTitle { + color: @heading-color; +} diff --git a/src/pages/List/Articles.js b/src/pages/List/Articles.js index 4d7cd011..5df46d5f 100644 --- a/src/pages/List/Articles.js +++ b/src/pages/List/Articles.js @@ -1,10 +1,10 @@ import React, { Component, Fragment } from 'react'; -import moment from 'moment'; import { connect } from 'dva'; -import { Form, Card, Select, List, Tag, Icon, Avatar, Row, Col, Button } from 'antd'; +import { Form, Card, Select, List, Tag, Icon, Row, Col, Button } from 'antd'; import TagSelect from '@/components/TagSelect'; import StandardFormRow from '@/components/StandardFormRow'; +import ArticleListContent from '@/components/ArticleListContent'; import styles from './Articles.less'; const { Option } = Select; @@ -96,18 +96,6 @@ class SearchList extends Component { ); - const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => ( -
-
{content}
-
- - {owner} 发布在 - {href} - {moment(updatedAt).format('YYYY-MM-DD HH:mm')} -
-
- ); - const formItemLayout = { wrapperCol: { xs: { span: 24 }, @@ -186,10 +174,7 @@ class SearchList extends Component { {getFieldDecorator('user', {})( - )} @@ -198,10 +183,7 @@ class SearchList extends Component { {getFieldDecorator('rate', {})( - )} @@ -247,7 +229,7 @@ class SearchList extends Component { } /> - + )} /> diff --git a/src/pages/List/Articles.less b/src/pages/List/Articles.less index 3f2db2b2..3ec95015 100644 --- a/src/pages/List/Articles.less +++ b/src/pages/List/Articles.less @@ -1,30 +1,5 @@ @import '~antd/lib/style/themes/default.less'; -@import '~@/utils/utils.less'; -.listContent { - .description { - line-height: 22px; - max-width: 720px; - } - .extra { - color: @text-color-secondary; - margin-top: 16px; - line-height: 22px; - & > :global(.ant-avatar) { - vertical-align: top; - margin-right: 8px; - width: 20px; - height: 20px; - position: relative; - top: 1px; - } - & > em { - color: @disabled-color; - font-style: normal; - margin-left: 16px; - } - } -} a.listItemMetaTitle { color: @heading-color; } @@ -41,15 +16,6 @@ a.listItemMetaTitle { display: block; margin-left: 0; } - .listContent { - .extra { - & > em { - display: block; - margin-left: 0; - margin-top: 8px; - } - } - } } @media screen and (max-width: @screen-md) { .selfTrigger { -- GitLab