2019-01-12 03:33:27 +00:00
|
|
|
import { initDefaultProps } from '../../_util/props-util';
|
|
|
|
import enhancer from './enhancer';
|
|
|
|
import { propTypes, defaultProps } from './types';
|
2018-04-03 03:00:05 +00:00
|
|
|
|
|
|
|
const Line = {
|
|
|
|
props: initDefaultProps(propTypes, defaultProps),
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2018-04-03 03:00:05 +00:00
|
|
|
const {
|
|
|
|
percent,
|
|
|
|
prefixCls,
|
|
|
|
strokeColor,
|
|
|
|
strokeLinecap,
|
|
|
|
strokeWidth,
|
|
|
|
trailColor,
|
|
|
|
trailWidth,
|
|
|
|
...restProps
|
2019-01-12 03:33:27 +00:00
|
|
|
} = this.$props;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
delete restProps.gapPosition;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
|
|
|
const pathStyle = {
|
|
|
|
strokeDasharray: '100px, 100px',
|
2019-01-12 03:33:27 +00:00
|
|
|
strokeDashoffset: `${100 - percent}px`,
|
2018-04-03 03:00:05 +00:00
|
|
|
transition: 'stroke-dashoffset 0.3s ease 0s, stroke 0.3s linear',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const center = strokeWidth / 2;
|
|
|
|
const right = 100 - strokeWidth / 2;
|
|
|
|
const pathString = `M ${strokeLinecap === 'round' ? center : 0},${center}
|
|
|
|
L ${strokeLinecap === 'round' ? right : 100},${center}`;
|
|
|
|
const viewBoxString = `0 0 100 ${strokeWidth}`;
|
2018-12-10 14:25:16 +00:00
|
|
|
|
2018-04-03 03:00:05 +00:00
|
|
|
const pathFirst = {
|
|
|
|
attrs: {
|
2019-01-12 03:33:27 +00:00
|
|
|
d: pathString,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-linecap': strokeLinecap,
|
2019-01-12 03:33:27 +00:00
|
|
|
stroke: trailColor,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-width': trailWidth || strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
|
|
|
},
|
|
|
|
class: `${prefixCls}-line-trail`,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
const pathSecond = {
|
|
|
|
attrs: {
|
2019-01-12 03:33:27 +00:00
|
|
|
d: pathString,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-linecap': strokeLinecap,
|
2019-01-12 03:33:27 +00:00
|
|
|
stroke: strokeColor,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-width': strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
|
|
|
},
|
|
|
|
class: `${prefixCls}-line-path`,
|
|
|
|
style: pathStyle,
|
|
|
|
ref: 'svgPathRef',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
return (
|
|
|
|
<svg
|
|
|
|
class={`${prefixCls}-line`}
|
|
|
|
viewBox={viewBoxString}
|
2019-01-12 03:33:27 +00:00
|
|
|
preserveAspectRatio="none"
|
2018-04-03 03:00:05 +00:00
|
|
|
{...restProps}
|
|
|
|
>
|
2019-01-12 03:33:27 +00:00
|
|
|
<path {...pathFirst} />
|
|
|
|
<path {...pathSecond} />
|
2018-04-03 03:00:05 +00:00
|
|
|
</svg>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-04-03 03:00:05 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default enhancer(Line);
|