UNPKG

wix-style-react

Version:
124 lines (123 loc) • 6.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.linearProgressBarUniDriverFactory = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _unidriver = require("../../test-utils/utils/unidriver"); var _DataHooks = require("./DataHooks"); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var getNative = base => { if (base.type !== 'react') { throw new Error('Supported only in React/DOM.'); } return base.getNative(); }; var linearProgressBarUniDriverFactory = base => { var byDataHook = dataHook => "[data-hook=\"".concat(dataHook, "\"]"); var getValue = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)(function* () { if (!(yield base.exists())) { return null; } return base.$(byDataHook(_DataHooks.ProgressBarDataHooks.progressPercentage)).$('span').text(); }); return function getValue() { return _ref.apply(this, arguments); }; }(); var getDataAttribute = /*#__PURE__*/function () { var _ref2 = (0, _asyncToGenerator2.default)(function* (key, parsingFunction) { if (!(yield base.exists()) || !(yield base.attr(key))) { return null; } var value = yield base.attr(key); return !!parsingFunction && parsingFunction instanceof Function ? parsingFunction(value) : value; }); return function getDataAttribute(_x, _x2) { return _ref2.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { getWidth: function () { var _getWidth = (0, _asyncToGenerator2.default)(function* () { var bar = base.$(byDataHook(_DataHooks.ProgressBarDataHooks.foreground)); return (yield getNative(bar)).style.width; }); function getWidth() { return _getWidth.apply(this, arguments); } return getWidth; }(), isSuccessIconDisplayed: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.successIcon)).exists(), isErrorIconDisplayed: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.errorIcon)).exists(), isPercentagesProgressDisplayed: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.progressPercentage)).exists(), getValue: function (_getValue) { function getValue() { return _getValue.apply(this, arguments); } getValue.toString = function () { return _getValue.toString(); }; return getValue; }(/*#__PURE__*/(0, _asyncToGenerator2.default)(function* () { return getValue(); })), getNumericValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.value, Number), isCompleted: function () { var _isCompleted = (0, _asyncToGenerator2.default)(function* () { return ( // @ts-ignore (yield getValue()) >= (yield getDataAttribute(_DataHooks.ProgressBarDataKeys.max)) ); }); function isCompleted() { return _isCompleted.apply(this, arguments); } return isCompleted; }(), hasError: function () { var _hasError = (0, _asyncToGenerator2.default)(function* () { return (yield base.attr('data-error')) === 'true'; }); function hasError() { return _hasError.apply(this, arguments); } return hasError; }(), getMinValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.min, Number), getMaxValue: () => getDataAttribute(_DataHooks.ProgressBarDataKeys.max, Number), getAriaValueNow: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuenow, Number), getAriaValueMax: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuemax, Number), getAriaValueMin: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuemin, Number), getAriaValueText: () => getDataAttribute(_DataHooks.ProgressBarAriaKeys.valuetext), getRoleAttribute: () => getDataAttribute('role'), hasPrefixIndication: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.prefixIndicator)).exists(), hasSuffixIndication: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.suffixIndicator)).exists(), getSuffixIndicationText: () => base.$(byDataHook(_DataHooks.ProgressBarDataHooks.suffixIndicator)).text(), hasPrefixAriaHidden: function () { var _hasPrefixAriaHidden = (0, _asyncToGenerator2.default)(function* () { return (yield base.$(byDataHook(_DataHooks.ProgressBarDataHooks.prefixIndicator)).attr(_DataHooks.ProgressBarInnerAriaKeys.hidden)) === 'true'; }); function hasPrefixAriaHidden() { return _hasPrefixAriaHidden.apply(this, arguments); } return hasPrefixAriaHidden; }(), hasProgressIndicatorAriaHidden: function () { var _hasProgressIndicatorAriaHidden = (0, _asyncToGenerator2.default)(function* () { return (yield base.$(byDataHook(_DataHooks.ProgressBarDataHooks.progressIndicator)).attr(_DataHooks.ProgressBarInnerAriaKeys.hidden)) === 'true'; }); function hasProgressIndicatorAriaHidden() { return _hasProgressIndicatorAriaHidden.apply(this, arguments); } return hasProgressIndicatorAriaHidden; }(), getAriaLabel: () => // @ts-ignore base.$(byDataHook(_DataHooks.ProgressBarDataHooks.container)).attr(_DataHooks.ProgressBarInnerAriaKeys.label) }); }; exports.linearProgressBarUniDriverFactory = linearProgressBarUniDriverFactory; //# sourceMappingURL=LinearProgressBarCore.uni.driver.js.map