choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
131 lines (114 loc) • 4.05 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["value", "dragging", "index"],
_excluded2 = ["range", "prefixCls"];
import React, { Component } from 'react';
import Tooltip from '../tooltip';
import RcSlider, { Handle as RcHandle, Range as RcRange } from '../rc-components/slider';
import ConfigContext from '../config-provider/ConfigContext';
var Slider = /*#__PURE__*/function (_Component) {
_inherits(Slider, _Component);
var _super = _createSuper(Slider);
function Slider(props) {
var _this;
_classCallCheck(this, Slider);
_this = _super.call(this, props);
_this.toggleTooltipVisible = function (index, visible) {
_this.setState(function (_ref) {
var visibles = _ref.visibles;
return {
visibles: _objectSpread(_objectSpread({}, visibles), {}, _defineProperty({}, index, visible))
};
});
};
_this.handleWithTooltip = function (_ref2) {
var value = _ref2.value,
dragging = _ref2.dragging,
index = _ref2.index,
restProps = _objectWithoutProperties(_ref2, _excluded);
var _this$props = _this.props,
tooltipPrefixCls = _this$props.tooltipPrefixCls,
tooltipVisible = _this$props.tooltipVisible,
tipFormatter = _this$props.tipFormatter;
var visibles = _this.state.visibles;
var visible = tooltipVisible ? visibles[index] || dragging : false;
return /*#__PURE__*/React.createElement(Tooltip, {
prefixCls: tooltipPrefixCls,
title: tipFormatter ? tipFormatter(value) : "".concat(value),
visible: visible,
placement: "top",
transitionName: "zoom-down",
key: index
}, /*#__PURE__*/React.createElement(RcHandle, _extends({}, restProps, {
value: value,
onMouseEnter: function onMouseEnter() {
return _this.toggleTooltipVisible(index, true);
},
onMouseLeave: function onMouseLeave() {
return _this.toggleTooltipVisible(index, false);
}
})));
};
_this.saveSlider = function (node) {
_this.rcSlider = node;
};
_this.state = {
visibles: {}
};
return _this;
}
_createClass(Slider, [{
key: "focus",
value: function focus() {
this.rcSlider.focus();
}
}, {
key: "blur",
value: function blur() {
this.rcSlider.focus();
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
range = _this$props2.range,
customizePrefixCls = _this$props2.prefixCls,
restProps = _objectWithoutProperties(_this$props2, _excluded2);
var getPrefixCls = this.context.getPrefixCls;
var prefixCls = getPrefixCls('slider', customizePrefixCls);
if (range) {
return /*#__PURE__*/React.createElement(RcRange, _extends({}, restProps, {
ref: this.saveSlider,
handle: this.handleWithTooltip,
prefixCls: prefixCls
}));
}
return /*#__PURE__*/React.createElement(RcSlider, _extends({}, restProps, {
ref: this.saveSlider,
handle: this.handleWithTooltip,
prefixCls: prefixCls
}));
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return Slider;
}(Component);
export { Slider as default };
Slider.displayName = 'Slider';
Slider.defaultProps = {
tooltipVisible: true,
tipFormatter: function tipFormatter(value) {
return value.toString();
}
};
//# sourceMappingURL=index.js.map