choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
163 lines (139 loc) • 4.84 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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
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({}, visibles, _defineProperty({}, index, visible))
};
});
};
_this.handleWithTooltip = function (_ref2) {
var value = _ref2.value,
dragging = _ref2.dragging,
index = _ref2.index,
restProps = _objectWithoutProperties(_ref2, ["value", "dragging", "index"]);
var _this$props = _this.props,
customizeTooltipPrefixCls = _this$props.tooltipPrefixCls,
tipFormatter = _this$props.tipFormatter;
var getPrefixCls = _this.context.getPrefixCls;
var tooltipPrefixCls = getPrefixCls('tooltip', customizeTooltipPrefixCls);
var visibles = _this.state.visibles;
var visible = tipFormatter ? visibles[index] || dragging : false;
return React.createElement(Tooltip, {
prefixCls: tooltipPrefixCls,
title: tipFormatter ? tipFormatter(value) : '',
visible: visible,
placement: "top",
transitionName: "zoom-down",
key: index
}, 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, ["range", "prefixCls"]);
var getPrefixCls = this.context.getPrefixCls;
var prefixCls = getPrefixCls('slider', customizePrefixCls);
if (range) {
return React.createElement(RcRange, _extends({}, restProps, {
ref: this.saveSlider,
handle: this.handleWithTooltip,
prefixCls: prefixCls
}));
}
return 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 = {
tipFormatter: function tipFormatter(value) {
return value.toString();
}
};
//# sourceMappingURL=index.js.map