UNPKG

wix-style-react

Version:
252 lines (209 loc) • 9.2 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory } from 'wix-ui-test-utils/base-driver'; import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver'; import { dataHooks } from './constants'; import deprecationLog from '../utils/deprecationLog'; export var sliderUniDriverFactory = function sliderUniDriverFactory(base, body) { var $sliderHandles = function $sliderHandles() { return base.$$("[data-hook=\"".concat(dataHooks.sliderHandle, "\"]")); }; var $sliderDots = function $sliderDots() { return base.$$('.wsr-slider-dot'); }; var $sliderMarks = function $sliderMarks() { return base.$$("[data-hook=\"".concat(dataHooks.sliderMarkLabel, "\"]")); }; var getTooltipDriver = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(index) { var sliderDataHook, tooltipDataHook; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return base.attr('data-hook'); case 2: sliderDataHook = _context.sent; tooltipDataHook = sliderDataHook ? "".concat(sliderDataHook, "-").concat(dataHooks.sliderTooltip, "-").concat(index) : "".concat(dataHooks.sliderTooltip, "-").concat(index); return _context.abrupt("return", tooltipDriverFactory(base.$("[data-hook=\"".concat(tooltipDataHook, "\"]")), body)); case 5: case "end": return _context.stop(); } } }, _callee); })); return function getTooltipDriver(_x) { return _ref.apply(this, arguments); }; }(); var currentHandleIndex = 0; return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** returns true if slider grade is selected */ isDotSelected: function isDotSelected(number) { return $sliderDots().get(number - 1).hasClass('wsr-slider-dot-active'); }, /** returns number of slider grades */ numOfSliderDots: function numOfSliderDots() { return $sliderDots().count(); }, /** returns number of slider handles */ numOfSliderHandles: function numOfSliderHandles() { return $sliderHandles().count(); }, /** returns number of slider marks labels */ numOfSliderMarksLabels: function numOfSliderMarksLabels() { return $sliderMarks().count(); }, /** returns slider tooltip value */ getToolTipValue: function () { var _getToolTipValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var _ref2, handleIndex, index, tooltipDriver, text, _args2 = arguments; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, handleIndex = _ref2.handleIndex; if (!handleIndex) { deprecationLog('handleIndex is not provided, in next major release this will be required'); } index = handleIndex || currentHandleIndex; _context2.next = 5; return getTooltipDriver(index); case 5: tooltipDriver = _context2.sent; text = null; _context2.prev = 7; _context2.next = 10; return tooltipDriver.getTooltipText(); case 10: text = _context2.sent; _context2.next = 15; break; case 13: _context2.prev = 13; _context2.t0 = _context2["catch"](7); case 15: return _context2.abrupt("return", text); case 16: case "end": return _context2.stop(); } } }, _callee2, null, [[7, 13]]); })); function getToolTipValue() { return _getToolTipValue.apply(this, arguments); } return getToolTipValue; }(), /** hovers on slider handle */ hoverHandle: function () { var _hoverHandle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) { var handleIndex, tooltipDriver; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: handleIndex = _ref3.handleIndex; deprecationLog('hoverHandle is deprecated and will be removed in next major release, please use getToolTipValue directly with handleIndex'); currentHandleIndex = handleIndex; _context3.next = 5; return getTooltipDriver(handleIndex); case 5: tooltipDriver = _context3.sent; return _context3.abrupt("return", tooltipDriver.mouseEnter()); case 7: case "end": return _context3.stop(); } } }, _callee3); })); function hoverHandle(_x2) { return _hoverHandle.apply(this, arguments); } return hoverHandle; }(), /** mouse leaves slider handle */ unHoverHandle: function () { var _unHoverHandle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) { var handleIndex, tooltipDriver; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: handleIndex = _ref4.handleIndex; deprecationLog('unHoverHandle is deprecated and will be removed in next major release, please use getToolTipValue directly with handleIndex'); currentHandleIndex = 0; _context4.next = 5; return getTooltipDriver(handleIndex); case 5: tooltipDriver = _context4.sent; return _context4.abrupt("return", tooltipDriver.mouseLeave()); case 7: case "end": return _context4.stop(); } } }, _callee4); })); function unHoverHandle(_x3) { return _unHoverHandle.apply(this, arguments); } return unHoverHandle; }(), /** returns if the slider is disabled */ isDisabled: function () { var _isDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return base.$('.wsr-slider-disabled'); case 2: return _context5.abrupt("return", !!_context5.sent); case 3: case "end": return _context5.stop(); } } }, _callee5); })); function isDisabled() { return _isDisabled.apply(this, arguments); } return isDisabled; }(), /** returns direction either horizontal or vertical */ getDirection: function () { var _getDirection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: return _context6.abrupt("return", base.attr('data-direction')); case 1: case "end": return _context6.stop(); } } }, _callee6); })); function getDirection() { return _getDirection.apply(this, arguments); } return getDirection; }() }); };