MCPcopy Create free account
hub / github.com/microsoft/SandDance / SliderBase1

Function SliderBase1

docs/app/js/sanddance-app.js:48712–48864  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

48710var SliderBase = /** @class */ function(_super) {
48711 (0, _tslib.__extends)(SliderBase1, _super);
48712 function SliderBase1(props) {
48713 var _this = _super.call(this, props) || this;
48714 _this._disposables = [];
48715 _this._sliderLine = _react.createRef();
48716 _this._thumb = _react.createRef();
48717 _this._lowerValueThumb = _react.createRef();
48718 _this._onKeyDownTimer = -1;
48719 _this._isAdjustingLowerValue = false;
48720 _this._getAriaValueText = function(value) {
48721 var ariaValueText = _this.props.ariaValueText;
48722 if (value !== undefined) return ariaValueText ? ariaValueText(value) : value.toString();
48723 return undefined;
48724 };
48725 _this._calculateCurrentSteps = function(event) {
48726 if (!_this._sliderLine.current) return;
48727 var _a = _this.props, max = _a.max, min = _a.min, step = _a.step;
48728 var steps = (max - min) / step;
48729 var sliderPositionRect = _this._sliderLine.current.getBoundingClientRect();
48730 var sliderLength = !_this.props.vertical ? sliderPositionRect.width : sliderPositionRect.height;
48731 var stepLength = sliderLength / steps;
48732 var currentSteps;
48733 var distance;
48734 if (!_this.props.vertical) {
48735 var left = _this._getPosition(event, _this.props.vertical);
48736 distance = (0, _utilities.getRTL)(_this.props.theme) ? sliderPositionRect.right - left : left - sliderPositionRect.left;
48737 currentSteps = distance / stepLength;
48738 } else {
48739 var bottom = _this._getPosition(event, _this.props.vertical);
48740 distance = sliderPositionRect.bottom - bottom;
48741 currentSteps = distance / stepLength;
48742 }
48743 return currentSteps;
48744 };
48745 _this._onMouseDownOrTouchStart = function(event) {
48746 var _a = _this.props, ranged = _a.ranged, min = _a.min, step = _a.step;
48747 if (ranged) {
48748 var currentSteps = _this._calculateCurrentSteps(event);
48749 var newRenderedValue = min + step * currentSteps;
48750 if (newRenderedValue <= _this.state.lowerValue || newRenderedValue - _this.state.lowerValue <= _this.state.value - newRenderedValue) _this._isAdjustingLowerValue = true;
48751 else _this._isAdjustingLowerValue = false;
48752 }
48753 if (event.type === "mousedown") _this._disposables.push((0, _utilities.on)(window, "mousemove", _this._onMouseMoveOrTouchMove, true), (0, _utilities.on)(window, "mouseup", _this._onMouseUpOrTouchEnd, true));
48754 else if (event.type === "touchstart") _this._disposables.push((0, _utilities.on)(window, "touchmove", _this._onMouseMoveOrTouchMove, true), (0, _utilities.on)(window, "touchend", _this._onMouseUpOrTouchEnd, true));
48755 _this._onMouseMoveOrTouchMove(event, true);
48756 };
48757 _this._onMouseMoveOrTouchMove = function(event, suppressEventCancelation) {
48758 if (!_this._sliderLine.current) return;
48759 var _a = _this.props, max = _a.max, min = _a.min, step = _a.step;
48760 var steps = (max - min) / step;
48761 var currentSteps = _this._calculateCurrentSteps(event);
48762 var currentValue;
48763 var renderedValue;
48764 // The value shouldn't be bigger than max or be smaller than min.
48765 if (currentSteps > Math.floor(steps)) renderedValue = currentValue = max;
48766 else if (currentSteps < 0) renderedValue = currentValue = min;
48767 else {
48768 renderedValue = min + step * currentSteps;
48769 currentValue = min + step * Math.round(currentSteps);

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.45
stopPropagationMethod · 0.45
forEachMethod · 0.45
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected