From 95b490b6184e512a6f32c84feffe382b8fe307d0 Mon Sep 17 00:00:00 2001 From: linyongping Date: Fri, 8 Feb 2019 23:30:05 +0800 Subject: [PATCH] add actionsText prop to TagSelect, add locales to List page #3367 (#3442) * add actionsText prop to TagSelect, add locales to List page * add actionsText prop to TagSelect, add locales to List page --- src/components/TagSelect/index.d.ts | 1 + src/components/TagSelect/index.js | 21 +++++++++++++++++---- src/locales/en-US.js | 2 ++ src/locales/en-US/component.js | 5 +++++ src/locales/pt-BR.js | 2 ++ src/locales/pt-BR/component.js | 5 +++++ src/locales/zh-CN.js | 2 ++ src/locales/zh-CN/component.js | 5 +++++ src/locales/zh-TW.js | 2 ++ src/locales/zh-TW/component.js | 5 +++++ src/pages/List/Applications.js | 11 ++++++++++- src/pages/List/Articles.js | 11 ++++++++++- src/pages/List/Projects.js | 11 ++++++++++- 13 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/locales/en-US/component.js create mode 100644 src/locales/pt-BR/component.js create mode 100644 src/locales/zh-CN/component.js create mode 100644 src/locales/zh-TW/component.js diff --git a/src/components/TagSelect/index.d.ts b/src/components/TagSelect/index.d.ts index 736ca52f..9de30263 100644 --- a/src/components/TagSelect/index.d.ts +++ b/src/components/TagSelect/index.d.ts @@ -7,6 +7,7 @@ export interface ITagSelectProps { value?: string[] | number[]; style?: React.CSSProperties; hideCheckAll?: boolean; + actionsText?: { expandText?: string; collapseText?: string; selectAllText?: string }; } export default class TagSelect extends React.Component { diff --git a/src/components/TagSelect/index.js b/src/components/TagSelect/index.js index f65764f5..34d6ba2d 100644 --- a/src/components/TagSelect/index.js +++ b/src/components/TagSelect/index.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Tag, Icon } from 'antd'; @@ -15,8 +16,18 @@ const TagSelectOption = ({ children, checked, onChange, value }) => ( TagSelectOption.isTagSelectOption = true; class TagSelect extends Component { + static propTypes = { + actionsText: PropTypes.object, + hideCheckAll: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), + }; + static defaultProps = { hideCheckAll: false, + actionsText: { + expandText: 'Expand', + collapseText: 'Collapse', + selectAllText: 'All', + }, }; constructor(props) { @@ -88,19 +99,21 @@ class TagSelect extends Component { render() { const { value, expand } = this.state; - const { children, hideCheckAll, className, style, expandable } = this.props; - + const { children, hideCheckAll, className, style, expandable, actionsText } = this.props; const checkedAll = this.getAllTags().length === value.length; + const { expandText = 'Expand', collapseText = 'Collapse', selectAllText = 'All' } = + actionsText === null ? {} : actionsText; const cls = classNames(styles.tagSelect, className, { [styles.hasExpandTag]: expandable, [styles.expanded]: expand, }); + return (
{hideCheckAll ? null : ( - 全部 + {selectAllText} )} {value && @@ -117,7 +130,7 @@ class TagSelect extends Component { })} {expandable && ( - {expand ? '收起' : '展开'} + {expand ? collapseText : expandText} )}
diff --git a/src/locales/en-US.js b/src/locales/en-US.js index fcaffceb..25f2888c 100644 --- a/src/locales/en-US.js +++ b/src/locales/en-US.js @@ -9,6 +9,7 @@ import result from './en-US/result'; import settingDrawer from './en-US/settingDrawer'; import settings from './en-US/settings'; import pwa from './en-US/pwa'; +import component from './en-US/component'; export default { 'navBar.lang': 'Languages', @@ -30,4 +31,5 @@ export default { ...settingDrawer, ...settings, ...pwa, + ...component, }; diff --git a/src/locales/en-US/component.js b/src/locales/en-US/component.js new file mode 100644 index 00000000..3ba7eeda --- /dev/null +++ b/src/locales/en-US/component.js @@ -0,0 +1,5 @@ +export default { + 'component.tagSelect.expand': 'Expand', + 'component.tagSelect.collapse': 'Collapse', + 'component.tagSelect.all': 'All', +}; diff --git a/src/locales/pt-BR.js b/src/locales/pt-BR.js index d0fe21b7..af8bcee5 100644 --- a/src/locales/pt-BR.js +++ b/src/locales/pt-BR.js @@ -9,6 +9,7 @@ import result from './pt-BR/result'; import settingDrawer from './pt-BR/settingDrawer'; import settings from './pt-BR/settings'; import pwa from './pt-BR/pwa'; +import component from './pt-BR/component'; export default { 'navBar.lang': 'Idiomas', @@ -30,4 +31,5 @@ export default { ...settingDrawer, ...settings, ...pwa, + ...component, }; diff --git a/src/locales/pt-BR/component.js b/src/locales/pt-BR/component.js new file mode 100644 index 00000000..1af478de --- /dev/null +++ b/src/locales/pt-BR/component.js @@ -0,0 +1,5 @@ +export default { + 'component.tagSelect.expand': 'Expandir', + 'component.tagSelect.collapse': 'Colapso', + 'component.tagSelect.all': 'Todas', +}; diff --git a/src/locales/zh-CN.js b/src/locales/zh-CN.js index 4330d60a..cf601f37 100644 --- a/src/locales/zh-CN.js +++ b/src/locales/zh-CN.js @@ -9,6 +9,7 @@ import result from './zh-CN/result'; import settingDrawer from './zh-CN/settingDrawer'; import settings from './zh-CN/settings'; import pwa from './zh-CN/pwa'; +import component from './zh-CN/component'; export default { 'navBar.lang': '语言', @@ -30,4 +31,5 @@ export default { ...settingDrawer, ...settings, ...pwa, + ...component, }; diff --git a/src/locales/zh-CN/component.js b/src/locales/zh-CN/component.js new file mode 100644 index 00000000..1f1feadb --- /dev/null +++ b/src/locales/zh-CN/component.js @@ -0,0 +1,5 @@ +export default { + 'component.tagSelect.expand': '展开', + 'component.tagSelect.collapse': '收起', + 'component.tagSelect.all': '全部', +}; diff --git a/src/locales/zh-TW.js b/src/locales/zh-TW.js index 986820ef..c6217339 100644 --- a/src/locales/zh-TW.js +++ b/src/locales/zh-TW.js @@ -9,6 +9,7 @@ import result from './zh-TW/result'; import settingDrawer from './zh-TW/settingDrawer'; import settings from './zh-TW/settings'; import pwa from './zh-TW/pwa'; +import component from './zh-TW/component'; export default { 'navBar.lang': '語言', @@ -30,4 +31,5 @@ export default { ...settingDrawer, ...settings, ...pwa, + ...component, }; diff --git a/src/locales/zh-TW/component.js b/src/locales/zh-TW/component.js new file mode 100644 index 00000000..ba48e299 --- /dev/null +++ b/src/locales/zh-TW/component.js @@ -0,0 +1,5 @@ +export default { + 'component.tagSelect.expand': '展開', + 'component.tagSelect.collapse': '收起', + 'component.tagSelect.all': '全部', +}; diff --git a/src/pages/List/Applications.js b/src/pages/List/Applications.js index 4f32f8e6..e36012dd 100644 --- a/src/pages/List/Applications.js +++ b/src/pages/List/Applications.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import numeral from 'numeral'; import { connect } from 'dva'; +import { FormattedMessage } from 'umi/locale'; import { Row, Col, Form, Card, Select, Icon, Avatar, List, Tooltip, Dropdown, Menu } from 'antd'; import TagSelect from '@/components/TagSelect'; import StandardFormRow from '@/components/StandardFormRow'; @@ -69,6 +70,14 @@ class FilterCardList extends PureComponent { }, }; + const actionsTextMap = { + expandText: , + collapseText: ( + + ), + selectAllText: , + }; + const itemMenu = ( @@ -96,7 +105,7 @@ class FilterCardList extends PureComponent { {getFieldDecorator('category')( - + 类目一 类目二 类目三 diff --git a/src/pages/List/Articles.js b/src/pages/List/Articles.js index 5df46d5f..c1c04b72 100644 --- a/src/pages/List/Articles.js +++ b/src/pages/List/Articles.js @@ -1,6 +1,7 @@ import React, { Component, Fragment } from 'react'; import { connect } from 'dva'; import { Form, Card, Select, List, Tag, Icon, Row, Col, Button } from 'antd'; +import { FormattedMessage } from 'umi/locale'; import TagSelect from '@/components/TagSelect'; import StandardFormRow from '@/components/StandardFormRow'; @@ -104,6 +105,14 @@ class SearchList extends Component { }, }; + const actionsTextMap = { + expandText: , + collapseText: ( + + ), + selectAllText: , + }; + const loadMore = list.length > 0 ? (
@@ -126,7 +135,7 @@ class SearchList extends Component { {getFieldDecorator('category')( - + 类目一 类目二 类目三 diff --git a/src/pages/List/Projects.js b/src/pages/List/Projects.js index 430ca420..3f4a6e9d 100644 --- a/src/pages/List/Projects.js +++ b/src/pages/List/Projects.js @@ -2,6 +2,7 @@ import React, { PureComponent } from 'react'; import moment from 'moment'; import { connect } from 'dva'; import { Row, Col, Form, Card, Select, List } from 'antd'; +import { FormattedMessage } from 'umi/locale'; import TagSelect from '@/components/TagSelect'; import AvatarList from '@/components/AvatarList'; @@ -96,6 +97,14 @@ class CoverCardList extends PureComponent { }, }; + const actionsTextMap = { + expandText: , + collapseText: ( + + ), + selectAllText: , + }; + return (
@@ -103,7 +112,7 @@ class CoverCardList extends PureComponent { {getFieldDecorator('category')( - + 类目一 类目二 类目三 -- GitLab