ant-design-vue/components/statistic/Statistic.jsx

66 lines
2.0 KiB
Vue
Raw Normal View History

import { inject } from 'vue';
2019-05-25 09:18:04 +00:00
import PropTypes from '../_util/vue-types';
import { getComponent, initDefaultProps } from '../_util/props-util';
2019-05-25 14:43:44 +00:00
import { ConfigConsumerProps } from '../config-provider';
2019-05-25 09:18:04 +00:00
import StatisticNumber from './Number';
export const StatisticProps = {
prefixCls: PropTypes.string,
decimalSeparator: PropTypes.string,
groupSeparator: PropTypes.string,
format: PropTypes.string,
2019-09-18 12:03:13 +00:00
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object]),
2019-05-25 09:18:04 +00:00
valueStyle: PropTypes.any,
valueRender: PropTypes.any,
formatter: PropTypes.any,
precision: PropTypes.number,
prefix: PropTypes.any,
suffix: PropTypes.any,
title: PropTypes.any,
};
export default {
name: 'AStatistic',
props: initDefaultProps(StatisticProps, {
decimalSeparator: '.',
groupSeparator: ',',
}),
2019-05-25 14:43:44 +00:00
inject: {
2019-09-11 14:35:25 +00:00
configProvider: { default: () => ConfigConsumerProps },
2019-05-25 14:43:44 +00:00
},
2019-05-25 09:18:04 +00:00
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
2019-05-25 09:18:04 +00:00
render() {
2019-05-28 03:37:38 +00:00
const { prefixCls: customizePrefixCls, value = 0, valueStyle, valueRender } = this.$props;
2019-09-11 14:35:25 +00:00
const getPrefixCls = this.configProvider.getPrefixCls;
2019-05-25 14:43:44 +00:00
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
const title = getComponent(this, 'title');
let prefix = getComponent(this, 'prefix');
let suffix = getComponent(this, 'suffix');
const formatter = getComponent(this, 'formatter', {}, false);
2019-05-25 09:18:04 +00:00
let valueNode = (
2019-09-18 12:03:13 +00:00
<StatisticNumber {...{ props: { ...this.$props, prefixCls, value, formatter } }} />
2019-05-25 09:18:04 +00:00
);
if (valueRender) {
valueNode = valueRender(valueNode);
}
return (
<div class={prefixCls}>
{title && <div class={`${prefixCls}-title`}>{title}</div>}
<div style={valueStyle} class={`${prefixCls}-content`}>
{prefix && <span class={`${prefixCls}-content-prefix`}>{prefix}</span>}
{valueNode}
{suffix && <span class={`${prefixCls}-content-suffix`}>{suffix}</span>}
</div>
</div>
);
},
};