Browse Source

Refactor number info (#28)

* Add NumberInfo[gap]

* Move NumberInfo outside Charts
pull/37/head
偏右 9 years ago
committed by GitHub
parent
commit
adb37590e7
  1. 5
      src/components/ActiveChart/index.js
  2. 3
      src/components/Charts/demo/mix.md
  3. 2
      src/components/Charts/index.js
  4. 10
      src/components/Charts/index.md
  5. 29
      src/components/NumberInfo/demo/basic.md
  6. 11
      src/components/NumberInfo/index.js
  7. 13
      src/components/NumberInfo/index.less
  8. 19
      src/components/NumberInfo/index.md
  9. 8
      src/routes/Dashboard/Analysis.js
  10. 3
      src/routes/Dashboard/Monitor.js

5
src/components/ActiveChart/index.js

@ -1,6 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { NumberInfo, MiniArea } from '../Charts'; import { MiniArea } from '../Charts';
import NumberInfo from '../NumberInfo';
import { fixedZero } from '../../utils/utils'; import { fixedZero } from '../../utils/utils';
import styles from './index.less'; import styles from './index.less';
@ -46,9 +47,7 @@ export default class ActiveChart extends PureComponent {
<MiniArea <MiniArea
animate={false} animate={false}
line line
borderColor="#00a2fc"
borderWidth={2} borderWidth={2}
color="#c9eafe"
height={84} height={84}
yAxis={{ yAxis={{
tickCount: 3, tickCount: 3,

3
src/components/Charts/demo/mix.md

@ -6,8 +6,9 @@ title: 图表套件组合展示
利用 Ant Design Pro 提供的图表套件,可以灵活组合符合设计规范的图表来满足复杂的业务需求。 利用 Ant Design Pro 提供的图表套件,可以灵活组合符合设计规范的图表来满足复杂的业务需求。
````jsx ````jsx
import { ChartCard, yuan, Field, NumberInfo, MiniArea, MiniBar, MiniProgress } from 'ant-design-pro/lib/Charts'; import { ChartCard, yuan, Field, MiniArea, MiniBar, MiniProgress } from 'ant-design-pro/lib/Charts';
import Trend from 'ant-design-pro/lib/Trend'; import Trend from 'ant-design-pro/lib/Trend';
import NumberInfo from 'ant-design-pro/lib/NumberInfo';
import { Row, Col, Icon, Tooltip } from 'antd'; import { Row, Col, Icon, Tooltip } from 'antd';
import numeral from 'numeral'; import numeral from 'numeral';
import moment from 'moment'; import moment from 'moment';

2
src/components/Charts/index.js

@ -8,7 +8,6 @@ import MiniArea from './MiniArea';
import MiniBar from './MiniBar'; import MiniBar from './MiniBar';
import MiniProgress from './MiniProgress'; import MiniProgress from './MiniProgress';
import Field from './Field'; import Field from './Field';
import NumberInfo from './NumberInfo';
import WaterWave from './WaterWave'; import WaterWave from './WaterWave';
import TagCloud from './TagCloud'; import TagCloud from './TagCloud';
import TimelineChart from './TimelineChart'; import TimelineChart from './TimelineChart';
@ -26,7 +25,6 @@ export default {
MiniProgress, MiniProgress,
ChartCard, ChartCard,
Field, Field,
NumberInfo,
WaterWave, WaterWave,
TagCloud, TagCloud,
TimelineChart, TimelineChart,

10
src/components/Charts/index.md

@ -119,16 +119,6 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https
| titleMap | 指标别名 | Object{y1: '客流量', y2: '支付笔数'} | - | | titleMap | 指标别名 | Object{y1: '客流量', y2: '支付笔数'} | - |
| height | 高度值 | number | 400 | | height | 高度值 | number | 400 |
### NumberInfo
| 参数 | 说明 | 类型 | 默认值 |
|----------|------------------------------------------|-------------|-------|
| title | 标题 | ReactNode\|string | - |
| subTitle | 子标题 | ReactNode\|string | - |
| total | 总量 | ReactNode\|string | - |
| status | 增加状态 | 'up'\/'down' | - |
| theme | 状态样式 | string | 'light' |
### Field ### Field
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |

29
src/components/NumberInfo/demo/basic.md

@ -0,0 +1,29 @@
---
order: 0
title: 演示
---
各种数据文案的展现方式。
````jsx
import NumberInfo from 'ant-design-pro/lib/NumberInfo';
import numeral from 'numeral';
ReactDOM.render(
<div>
<NumberInfo
subTitle={<span>本周访问</span>}
total={numeral(12321).format('0,0')}
status="up"
subTotal={17.1}
/>
<NumberInfo
subTitle={<span>本周访问</span>}
total={numeral(12321).format('0,0')}
status="up"
subTotal={17.1}
style={{ marginTop: 16 }}
/>
</div>
, mountNode);
````

11
src/components/Charts/NumberInfo/index.js → src/components/NumberInfo/index.js

@ -1,10 +1,11 @@
import React from 'react'; import React from 'react';
import { Icon } from 'antd'; import { Icon } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import styles from './index.less'; 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
}) => (
<div <div
className={ className={
classNames(styles.numberInfo, { classNames(styles.numberInfo, {
@ -13,9 +14,9 @@ export default ({ theme, title, subTitle, total, subTotal, status, suffix, ...re
} }
{...rest} {...rest}
> >
{title && <h4>{title}</h4>} {title && <div className={styles.numberInfoTitle}>{title}</div>}
{subTitle && <h6>{subTitle}</h6>} {subTitle && <div className={styles.numberInfoSubTitle}>{subTitle}</div>}
<div> <div className={styles.numberInfoValue} style={gap ? { marginTop: gap } : null}>
<span> <span>
{total} {total}
{suffix && <em className={styles.suffix}>{suffix}</em>} {suffix && <em className={styles.suffix}>{suffix}</em>}

13
src/components/Charts/NumberInfo/index.less → src/components/NumberInfo/index.less

@ -1,5 +1,5 @@
@import "~antd/lib/style/themes/default.less"; @import "~antd/lib/style/themes/default.less";
@import "../../../utils/utils.less"; @import "../../utils/utils.less";
.numberInfo { .numberInfo {
.suffix { .suffix {
@ -8,22 +8,21 @@
font-style: normal; font-style: normal;
margin-left: 4px; margin-left: 4px;
} }
h4 { .numberInfoTitle {
color: @text-color; color: @text-color;
font-size: @font-size-lg; font-size: @font-size-lg;
margin-bottom: 16px; margin-bottom: 16px;
transition: all .3s; transition: all .3s;
} }
h6 { .numberInfoSubTitle {
color: @text-color-secondary; color: @text-color-secondary;
font-size: @font-size-base; font-size: @font-size-base;
font-weight: normal;
height: 22px; height: 22px;
line-height: 22px; line-height: 22px;
.textOverflow(); .textOverflow();
} }
& > div { .numberInfoValue {
margin-top: 8px; margin-top: 4px;
font-size: 0; font-size: 0;
.textOverflow(); .textOverflow();
& > span { & > span {
@ -48,7 +47,7 @@
} }
} }
.numberInfolight { .numberInfolight {
& > div { .numberInfoValue {
& > span { & > span {
color: @text-color; color: @text-color;
} }

19
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

8
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 { Row, Col, Icon, Card, Tabs, Table, Radio, DatePicker, Tooltip } from 'antd';
import numeral from 'numeral'; import numeral from 'numeral';
import { import {
ChartCard, yuan, MiniArea, MiniBar, MiniProgress, Field, Bar, Pie, NumberInfo, TimelineChart, ChartCard, yuan, MiniArea, MiniBar, MiniProgress, Field, Bar, Pie, TimelineChart,
} from '../../components/Charts'; } from '../../components/Charts';
import Trend from '../../components/Trend'; import Trend from '../../components/Trend';
import NumberInfo from '../../components/NumberInfo';
import { getTimeDistance } from '../../utils/utils'; import { getTimeDistance } from '../../utils/utils';
import styles from './Analysis.less'; import styles from './Analysis.less';
@ -178,7 +179,8 @@ export default class Analysis extends Component {
<NumberInfo <NumberInfo
title={data.name} title={data.name}
subTitle="转化率" subTitle="转化率"
total={<span style={{ top: '-6px', position: 'relative' }}>{data.cvr * 100}%</span>} gap={2}
total={`${data.cvr * 100}%`}
theme={(currentKey !== data.name) && 'light'} theme={(currentKey !== data.name) && 'light'}
/> />
</Col> </Col>
@ -370,6 +372,7 @@ export default class Analysis extends Component {
</Tooltip> </Tooltip>
</span> </span>
} }
gap={8}
total={numeral(12321).format('0,0')} total={numeral(12321).format('0,0')}
status="up" status="up"
subTotal={17.1} subTotal={17.1}
@ -386,6 +389,7 @@ export default class Analysis extends Component {
total={2.7} total={2.7}
status="down" status="down"
subTotal={26.2} subTotal={26.2}
gap={8}
/> />
<MiniArea <MiniArea
line line

3
src/routes/Dashboard/Monitor.js

@ -3,7 +3,8 @@ import { connect } from 'dva';
import { Row, Col, Card } from 'antd'; import { Row, Col, Card } from 'antd';
import numeral from 'numeral'; import numeral from 'numeral';
import { NumberInfo, Pie, WaterWave, Gauge, TagCloud } from '../../components/Charts'; import { Pie, WaterWave, Gauge, TagCloud } from '../../components/Charts';
import NumberInfo from '../../components/NumberInfo';
import CountDown from '../../components/CountDown'; import CountDown from '../../components/CountDown';
import ActiveChart from '../../components/ActiveChart'; import ActiveChart from '../../components/ActiveChart';

Loading…
Cancel
Save