From adb37590e76fd9ced5a7fbb7d9fdd2ab3ace7b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Wed, 25 Oct 2017 08:07:18 -0500 Subject: [PATCH] Refactor number info (#28) * Add NumberInfo[gap] * Move NumberInfo outside Charts --- src/components/ActiveChart/index.js | 5 ++-- src/components/Charts/demo/mix.md | 3 +- src/components/Charts/index.js | 2 -- src/components/Charts/index.md | 10 ------- src/components/NumberInfo/demo/basic.md | 29 +++++++++++++++++++ .../{Charts => }/NumberInfo/index.js | 11 +++---- .../{Charts => }/NumberInfo/index.less | 13 ++++----- src/components/NumberInfo/index.md | 19 ++++++++++++ src/routes/Dashboard/Analysis.js | 8 +++-- src/routes/Dashboard/Monitor.js | 3 +- 10 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 src/components/NumberInfo/demo/basic.md rename src/components/{Charts => }/NumberInfo/index.js (64%) rename src/components/{Charts => }/NumberInfo/index.less (86%) create mode 100644 src/components/NumberInfo/index.md diff --git a/src/components/ActiveChart/index.js b/src/components/ActiveChart/index.js index 916a322d..42e1694d 100644 --- a/src/components/ActiveChart/index.js +++ b/src/components/ActiveChart/index.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; -import { NumberInfo, MiniArea } from '../Charts'; +import { MiniArea } from '../Charts'; +import NumberInfo from '../NumberInfo'; import { fixedZero } from '../../utils/utils'; import styles from './index.less'; @@ -46,9 +47,7 @@ export default class ActiveChart extends PureComponent { + 本周访问} + total={numeral(12321).format('0,0')} + status="up" + subTotal={17.1} + /> + 本周访问} + total={numeral(12321).format('0,0')} + status="up" + subTotal={17.1} + style={{ marginTop: 16 }} + /> + +, mountNode); +```` diff --git a/src/components/Charts/NumberInfo/index.js b/src/components/NumberInfo/index.js similarity index 64% rename from src/components/Charts/NumberInfo/index.js rename to src/components/NumberInfo/index.js index bdcba7f5..0b90cbd9 100644 --- a/src/components/Charts/NumberInfo/index.js +++ b/src/components/NumberInfo/index.js @@ -1,10 +1,11 @@ import React from 'react'; import { Icon } from 'antd'; import classNames from 'classnames'; - import styles from './index.less'; -export default ({ theme, title, subTitle, total, subTotal, status, suffix, ...rest }) => ( +export default ({ + theme, title, subTitle, total, subTotal, status, suffix, gap, ...rest +}) => (
- {title &&

{title}

} - {subTitle &&
{subTitle}
} -
+ {title &&
{title}
} + {subTitle &&
{subTitle}
} +
{total} {suffix && {suffix}} diff --git a/src/components/Charts/NumberInfo/index.less b/src/components/NumberInfo/index.less similarity index 86% rename from src/components/Charts/NumberInfo/index.less rename to src/components/NumberInfo/index.less index 8f221d9c..2545624d 100644 --- a/src/components/Charts/NumberInfo/index.less +++ b/src/components/NumberInfo/index.less @@ -1,5 +1,5 @@ @import "~antd/lib/style/themes/default.less"; -@import "../../../utils/utils.less"; +@import "../../utils/utils.less"; .numberInfo { .suffix { @@ -8,22 +8,21 @@ font-style: normal; margin-left: 4px; } - h4 { + .numberInfoTitle { color: @text-color; font-size: @font-size-lg; margin-bottom: 16px; transition: all .3s; } - h6 { + .numberInfoSubTitle { color: @text-color-secondary; font-size: @font-size-base; - font-weight: normal; height: 22px; line-height: 22px; .textOverflow(); } - & > div { - margin-top: 8px; + .numberInfoValue { + margin-top: 4px; font-size: 0; .textOverflow(); & > span { @@ -48,7 +47,7 @@ } } .numberInfolight { - & > div { + .numberInfoValue { & > span { color: @text-color; } diff --git a/src/components/NumberInfo/index.md b/src/components/NumberInfo/index.md new file mode 100644 index 00000000..05a9552d --- /dev/null +++ b/src/components/NumberInfo/index.md @@ -0,0 +1,19 @@ +--- +type: General +title: NumberInfo +subtitle: 数据文本 +cols: 1 +--- + +常用在数据卡片中,用于突出展示某个业务数据。 + +## API + +参数 | 说明 | 类型 | 默认值 +----|------|-----|------ +title | 标题 | ReactNode\|string | - +subTitle | 子标题 | ReactNode\|string | - +total | 总量 | ReactNode\|string | - +status | 增加状态 | 'up'\/'down' | - +theme | 状态样式 | string | 'light' +gap | 设置数字和描述直接的间距(像素) | number | 8 diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js index 8640e232..3f69f798 100644 --- a/src/routes/Dashboard/Analysis.js +++ b/src/routes/Dashboard/Analysis.js @@ -3,9 +3,10 @@ import { connect } from 'dva'; import { Row, Col, Icon, Card, Tabs, Table, Radio, DatePicker, Tooltip } from 'antd'; import numeral from 'numeral'; import { - ChartCard, yuan, MiniArea, MiniBar, MiniProgress, Field, Bar, Pie, NumberInfo, TimelineChart, + ChartCard, yuan, MiniArea, MiniBar, MiniProgress, Field, Bar, Pie, TimelineChart, } from '../../components/Charts'; import Trend from '../../components/Trend'; +import NumberInfo from '../../components/NumberInfo'; import { getTimeDistance } from '../../utils/utils'; import styles from './Analysis.less'; @@ -178,7 +179,8 @@ export default class Analysis extends Component { {data.cvr * 100}%} + gap={2} + total={`${data.cvr * 100}%`} theme={(currentKey !== data.name) && 'light'} /> @@ -370,6 +372,7 @@ export default class Analysis extends Component { } + gap={8} total={numeral(12321).format('0,0')} status="up" subTotal={17.1} @@ -386,6 +389,7 @@ export default class Analysis extends Component { total={2.7} status="down" subTotal={26.2} + gap={8} />