vue-antd-ui
Version:
An enterprise-class UI design language and Vue-based implementation
61 lines (52 loc) • 2.19 kB
JavaScript
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _extends from 'babel-runtime/helpers/extends';
import classNames from 'classnames';
import warning from '../../../_util/warning';
var calcPoints = function calcPoints(vertical, marks, dots, step, min, max) {
warning(dots ? step > 0 : true, '`Slider[step]` should be a positive number in order to make Slider[dots] work.');
var points = Object.keys(marks).map(parseFloat);
if (dots) {
for (var i = min; i <= max; i = i + step) {
if (points.indexOf(i) >= 0) continue;
points.push(i);
}
}
return points;
};
var Steps = {
functional: true,
render: function render(createElement, context) {
var h = arguments[0];
var _context$props = context.props,
prefixCls = _context$props.prefixCls,
vertical = _context$props.vertical,
marks = _context$props.marks,
dots = _context$props.dots,
step = _context$props.step,
included = _context$props.included,
lowerBound = _context$props.lowerBound,
upperBound = _context$props.upperBound,
max = _context$props.max,
min = _context$props.min,
dotStyle = _context$props.dotStyle,
activeDotStyle = _context$props.activeDotStyle;
var range = max - min;
var elements = calcPoints(vertical, marks, dots, step, min, max).map(function (point) {
var _classNames;
var offset = Math.abs(point - min) / range * 100 + '%';
var isActived = !included && point === upperBound || included && point <= upperBound && point >= lowerBound;
var style = vertical ? _extends({ bottom: offset }, dotStyle) : _extends({ left: offset }, dotStyle);
if (isActived) {
style = _extends({}, style, activeDotStyle);
}
var pointClassName = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls + '-dot', true), _defineProperty(_classNames, prefixCls + '-dot-active', isActived), _classNames));
return h('span', { 'class': pointClassName, style: style, key: point });
});
return h(
'div',
{ 'class': prefixCls + '-step' },
[elements]
);
}
};
export default Steps;