@shopgate/pwa-ui-shared 6.20.0-beta.1 → 6.20.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AccordionContainer/index.js +7 -4
- package/AccordionContainer/spec.js +2 -2
- package/ActionButton/index.js +7 -7
- package/ActionButton/spec.js +1 -1
- package/AddToCartButton/index.js +7 -6
- package/AddToCartButton/mock.js +3 -3
- package/AddToCartButton/spec.js +1 -1
- package/Availability/index.js +1 -1
- package/Availability/spec.js +1 -1
- package/Button/index.js +7 -7
- package/Button/spec.js +1 -1
- package/ButtonLink/index.js +3 -3
- package/ButtonLink/spec.js +1 -1
- package/Card/index.js +1 -1
- package/CardList/components/Item/index.js +1 -1
- package/CardList/index.js +3 -3
- package/CartTotalLine/components/Amount/index.js +1 -1
- package/CartTotalLine/components/Hint/index.js +1 -1
- package/CartTotalLine/components/Label/index.js +1 -1
- package/CartTotalLine/index.js +1 -1
- package/Checkbox/index.js +2 -2
- package/Chip/index.js +1 -1
- package/Chip/spec.js +1 -1
- package/ClientInformation/index.js +5 -5
- package/ClientInformation/spec.js +1 -1
- package/ContextMenu/components/Item/index.js +2 -2
- package/ContextMenu/components/Item/style.js +5 -1
- package/ContextMenu/components/Position/index.js +4 -4
- package/ContextMenu/index.js +8 -8
- package/ContextMenu/spec.js +3 -3
- package/ContextMenu/style.js +1 -1
- package/Dialog/components/PipelineErrorDialog/index.js +9 -9
- package/Dialog/components/PipelineErrorDialog/spec.js +2 -2
- package/Dialog/components/TextMessageDialog/index.js +1 -1
- package/Dialog/components/TextMessageDialog/spec.js +1 -1
- package/Dialog/components/VariantSelectModal/index.js +1 -1
- package/Dialog/components/VariantSelectModal/spec.js +2 -2
- package/Dialog/constants.js +1 -1
- package/Dialog/index.js +4 -4
- package/Dialog/spec.js +2 -2
- package/DiscountBadge/index.js +1 -1
- package/DiscountBadge/spec.js +1 -1
- package/FavoritesButton/connector.js +2 -2
- package/FavoritesButton/index.js +8 -8
- package/FavoritesButton/spec.js +1 -1
- package/Footer/index.js +9 -9
- package/Footer/index.spec.js +4 -4
- package/Form/Builder/builders/buildCountryList.js +1 -1
- package/Form/Builder/builders/buildFormDefaults.js +1 -1
- package/Form/Builder/builders/buildFormElements.js +2 -2
- package/Form/Builder/builders/buildFormElements.spec.js +1 -1
- package/Form/Builder/builders/buildProvinceList.js +1 -1
- package/Form/Builder/classes/ActionListener/index.js +3 -3
- package/Form/Builder/components/CheckboxElement.js +3 -3
- package/Form/Builder/components/CountryElement.js +3 -3
- package/Form/Builder/components/ProvinceElement.js +3 -3
- package/Form/Builder/components/RadioElement.js +3 -3
- package/Form/Builder/components/SelectElement.js +3 -3
- package/Form/Builder/components/TextElement.js +3 -3
- package/Form/Builder/index.js +8 -8
- package/Form/Builder/spec.js +3 -3
- package/Form/Checkbox/index.js +3 -3
- package/Form/Password/index.js +5 -5
- package/Form/Password/spec.js +1 -1
- package/Form/RadioGroup/components/Item/index.js +3 -3
- package/Form/RadioGroup/index.js +7 -7
- package/Form/RadioGroup/spec.js +2 -2
- package/Form/Select/index.js +5 -5
- package/Form/Select/spec.js +1 -1
- package/Form/TextField/index.js +5 -5
- package/Form/TextField/spec.js +1 -1
- package/Form/index.js +8 -8
- package/FormElement/components/ErrorText/index.js +1 -1
- package/FormElement/components/Label/index.js +1 -1
- package/FormElement/components/Placeholder/index.js +1 -1
- package/FormElement/components/Underline/index.js +1 -1
- package/FormElement/index.js +6 -6
- package/FormElement/spec.js +1 -1
- package/Glow/index.js +6 -6
- package/Glow/spec.js +1 -1
- package/IndicatorCircle/index.js +1 -1
- package/IndicatorCircle/spec.js +1 -1
- package/LoadingIndicator/index.js +1 -1
- package/Manufacturer/index.js +1 -1
- package/MessageBar/index.js +1 -1
- package/MessageBar/spec.js +1 -1
- package/NoResults/components/Icon/index.js +1 -1
- package/NoResults/index.js +1 -1
- package/Placeholder/index.js +3 -3
- package/PlaceholderLabel/index.js +1 -1
- package/PlaceholderLabel/spec.js +1 -1
- package/PlaceholderParagraph/index.js +1 -1
- package/PlaceholderParagraph/spec.js +1 -1
- package/Price/index.js +1 -1
- package/PriceInfo/index.js +1 -1
- package/PriceStriked/index.js +6 -6
- package/ProductProperties/index.js +1 -1
- package/ProductProperties/index.spec.js +1 -1
- package/ProgressBar/index.js +4 -4
- package/ProgressBar/spec.js +1 -1
- package/RadioButton/index.js +1 -1
- package/RadioButton/spec.js +1 -1
- package/RatingNumber/index.js +1 -1
- package/RatingNumber/index.spec.js +2 -2
- package/RatingStars/index.js +5 -5
- package/RatingStars/spec.js +2 -2
- package/Ripple/components/RippleAnimation/index.js +3 -3
- package/Ripple/index.js +16 -16
- package/RippleButton/index.js +7 -7
- package/RippleButton/spec.js +1 -1
- package/ScannerOverlay/components/CameraOverlay/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +1 -1
- package/ScannerOverlay/components/ScannerBar/index.js +1 -1
- package/ScannerOverlay/index.js +7 -7
- package/ScannerOverlay/index.spec.js +1 -1
- package/Sheet/components/Header/components/SearchBar/index.js +2 -2
- package/Sheet/components/Header/components/SearchBar/spec.js +1 -1
- package/Sheet/components/Header/index.js +4 -4
- package/Sheet/components/Header/spec.js +1 -1
- package/Sheet/index.js +10 -10
- package/Sheet/spec.js +2 -2
- package/TaxDisclaimer/index.js +1 -1
- package/TaxDisclaimer/spec.js +2 -2
- package/TextField/components/ErrorText/index.js +1 -1
- package/TextField/components/FormElement/index.js +1 -1
- package/TextField/components/Hint/index.js +1 -1
- package/TextField/components/Label/index.js +2 -2
- package/TextField/components/Underline/index.js +1 -1
- package/TextField/index.js +8 -8
- package/TextField/spec.js +2 -2
- package/ToggleIcon/index.js +5 -5
- package/ToggleIcon/spec.js +1 -1
- package/icons/AccountBoxIcon.js +1 -1
- package/icons/AddMoreIcon.js +1 -1
- package/icons/ArrowDropIcon.js +1 -1
- package/icons/ArrowIcon.js +2 -2
- package/icons/BarcodeScannerIcon.js +1 -1
- package/icons/BoxIcon.js +1 -1
- package/icons/BrowseIcon.js +1 -1
- package/icons/BurgerIcon.js +1 -1
- package/icons/CartCouponIcon.js +1 -1
- package/icons/CartIcon.js +1 -1
- package/icons/CartPlusIcon.js +1 -1
- package/icons/CheckIcon.js +1 -1
- package/icons/CheckedIcon.js +1 -1
- package/icons/ChevronIcon.js +1 -1
- package/icons/CreditCardIcon.js +1 -1
- package/icons/CrossIcon.js +1 -1
- package/icons/DescriptionIcon.js +1 -1
- package/icons/FilterIcon.js +1 -1
- package/icons/FlashDisabledIcon.js +1 -1
- package/icons/FlashEnabledIcon.js +1 -1
- package/icons/GridIcon.js +1 -1
- package/icons/HeartIcon.js +1 -1
- package/icons/HeartOutlineIcon.js +1 -1
- package/icons/HomeIcon.js +1 -1
- package/icons/InfoIcon.js +1 -1
- package/icons/InfoOutlineIcon.js +1 -1
- package/icons/ListIcon.js +1 -1
- package/icons/LocalShippingIcon.js +1 -1
- package/icons/LockIcon.js +1 -1
- package/icons/LogoutIcon.js +1 -1
- package/icons/MagnifierIcon.js +1 -1
- package/icons/MoreIcon.js +1 -1
- package/icons/MoreVertIcon.js +1 -1
- package/icons/PlaceholderIcon.js +1 -1
- package/icons/RadioCheckedIcon.js +1 -1
- package/icons/RadioUncheckedIcon.js +1 -1
- package/icons/SecurityIcon.js +1 -1
- package/icons/ShoppingCartIcon.js +1 -1
- package/icons/SortIcon.js +1 -1
- package/icons/StarHalfIcon.js +1 -1
- package/icons/StarIcon.js +1 -1
- package/icons/StarOutlineIcon.js +1 -1
- package/icons/TickIcon.js +1 -1
- package/icons/TrashIcon.js +1 -1
- package/icons/UncheckedIcon.js +1 -1
- package/icons/ViewListIcon.js +1 -1
- package/icons/VisibilityIcon.js +1 -1
- package/icons/VisibilityOffIcon.js +1 -1
- package/package.json +5 -5
- package/Dialog/components/HtmlContentDialog/index.js +0 -6
- package/Dialog/components/HtmlContentDialog/spec.js +0 -1
package/ProgressBar/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Transition from'react-transition-group/Transition';import UIEvents from'@shopgate/pwa-core/emitters/ui';import styles from"./style";var duration=150;var transitionStyles={entering:{transform:'scale(1, 1)'},entered:{transform:'scale(1, 1)'},exited:{transform:'scale(1, 0)'},exiting:{transform:'scale(1, 0)'}};/**
|
|
2
2
|
* A component for visualizing any kind of progress.
|
|
3
3
|
* This component will show the current progress in a linear bar.
|
|
4
|
-
*/var ProgressBar=/*#__PURE__*/function(_Component){_inherits(ProgressBar,_Component);/**
|
|
4
|
+
*/var ProgressBar=/*#__PURE__*/function(_Component){_inherits(ProgressBar,_Component);var _super=_createSuper(ProgressBar);/**
|
|
5
5
|
* Shows the progress bar.
|
|
6
6
|
* @param {string} pattern The router pattern to show the bar for.
|
|
7
7
|
*/ /**
|
|
@@ -10,7 +10,7 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
10
10
|
*/ /**
|
|
11
11
|
* The constructor
|
|
12
12
|
* @param {Object} props The component props.
|
|
13
|
-
*/function ProgressBar(props){var _this;_classCallCheck(this,ProgressBar);_this=
|
|
13
|
+
*/function ProgressBar(props){var _this;_classCallCheck(this,ProgressBar);_this=_super.call(this,props);_this.state={isAnimating:props.isVisible,isVisible:props.isVisible};return _this;}/**
|
|
14
14
|
* Update the state based on props.
|
|
15
15
|
* @param {Object} nextProps The next set of props.
|
|
16
16
|
*/_createClass(ProgressBar,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isVisible===nextProps.isVisible){return;}this.setState(_extends({},nextProps.isVisible&&{isAnimating:true},{isVisible:nextProps.isVisible}));}/**
|
|
@@ -22,4 +22,4 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
22
22
|
* Renders the component.
|
|
23
23
|
* @return {JSX}
|
|
24
24
|
*/},{key:"render",value:function render(){var _this2=this;var animationClasses=[styles.innerElement];// Add the animation if we need it.
|
|
25
|
-
if(this.state.isAnimating){animationClasses.push(styles.animating);}return
|
|
25
|
+
if(this.state.isAnimating){animationClasses.push(styles.animating);}return/*#__PURE__*/React.createElement(Transition,{"in":this.state.isVisible,timeout:duration,onExited:function onExited(){_this2.setState({isAnimating:false});}},function(state){return/*#__PURE__*/React.createElement("div",{className:"".concat(styles.wrapper," ui-shared__progress-bar"),style:transitionStyles[state]},/*#__PURE__*/React.createElement("div",{className:animationClasses.join(' ')}));});}}]);return ProgressBar;}(Component);_defineProperty(ProgressBar,"PROGRESS_BAR_SHOW",'PROGRESS_BAR_SHOW');_defineProperty(ProgressBar,"PROGRESS_BAR_HIDE",'PROGRESS_BAR_HIDE');_defineProperty(ProgressBar,"show",function(pattern){UIEvents.emit(ProgressBar.PROGRESS_BAR_SHOW,pattern);});_defineProperty(ProgressBar,"hide",function(pattern){UIEvents.emit(ProgressBar.PROGRESS_BAR_HIDE,pattern);});_defineProperty(ProgressBar,"defaultProps",{isVisible:true});export default ProgressBar;
|
package/ProgressBar/spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import Transition from'react-transition-group/Transition';import ProgressBar from"./index";describe('<ProgressBar />',function(){it('renders an indeterminate progress bar.',function(){var wrapper=shallow(React.createElement(ProgressBar,{isVisible:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Transition).length).toBe(1);});});
|
|
1
|
+
import React from'react';import{shallow}from'enzyme';import Transition from'react-transition-group/Transition';import ProgressBar from"./index";describe('<ProgressBar />',function(){it('renders an indeterminate progress bar.',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(ProgressBar,{isVisible:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Transition).length).toBe(1);});});
|
package/RadioButton/index.js
CHANGED
|
@@ -2,4 +2,4 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
2
2
|
* The RadioButton template component.
|
|
3
3
|
* @param {Object} props The component properties.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var RadioButton=function RadioButton(props){return
|
|
5
|
+
*/var RadioButton=function RadioButton(props){return/*#__PURE__*/React.createElement(BaseCheckbox,_extends({},props,{checkedIcon:/*#__PURE__*/React.createElement(CheckedIcon,{className:styles.checkedIcon}),uncheckedIcon:/*#__PURE__*/React.createElement(UncheckedIcon,{className:styles.uncheckedIcon})}));};export default RadioButton;
|
package/RadioButton/spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import React from'react';import{mount}from'enzyme';import CheckedIcon from"../icons/RadioCheckedIcon";import UncheckedIcon from"../icons/RadioUncheckedIcon";import RadioButton from"./index";describe('RadioButton',function(){it('should render selected RadioButton',function(){var wrapper=mount(React.createElement(RadioButton,{checked:true}));expect(wrapper.find(CheckedIcon).exists()).toBe(true);expect(wrapper.find(UncheckedIcon).exists()).toBe(false);expect(wrapper).toMatchSnapshot();});it('should render unselected RadioButton',function(){var wrapper=mount(React.createElement(RadioButton,null));expect(wrapper.find(CheckedIcon).exists()).toBe(false);expect(wrapper.find(UncheckedIcon).exists()).toBe(true);expect(wrapper).toMatchSnapshot();});});
|
|
1
|
+
import React from'react';import{mount}from'enzyme';import CheckedIcon from"../icons/RadioCheckedIcon";import UncheckedIcon from"../icons/RadioUncheckedIcon";import RadioButton from"./index";describe('RadioButton',function(){it('should render selected RadioButton',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioButton,{checked:true}));expect(wrapper.find(CheckedIcon).exists()).toBe(true);expect(wrapper.find(UncheckedIcon).exists()).toBe(false);expect(wrapper).toMatchSnapshot();});it('should render unselected RadioButton',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioButton,null));expect(wrapper.find(CheckedIcon).exists()).toBe(false);expect(wrapper.find(UncheckedIcon).exists()).toBe(true);expect(wrapper).toMatchSnapshot();});});
|
package/RatingNumber/index.js
CHANGED
|
@@ -4,4 +4,4 @@ import React from'react';import PropTypes from'prop-types';import I18n from'@sho
|
|
|
4
4
|
* @param {number} props.rating Rating value.
|
|
5
5
|
* @param {string} props.className Class name.
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/var RatingNumber=function RatingNumber(_ref){var rating=_ref.rating,className=_ref.className;if(!rating&&rating!==0){return null;}var number=rating/RATING_SCALE_DIVISOR;if(Number.isNaN(number)){return null;}return
|
|
7
|
+
*/var RatingNumber=function RatingNumber(_ref){var rating=_ref.rating,className=_ref.className;if(!rating&&rating!==0){return null;}var number=rating/RATING_SCALE_DIVISOR;if(Number.isNaN(number)){return null;}return/*#__PURE__*/React.createElement(I18n.Number,{number:number,className:"".concat(className," ui-shared__rating-number"),fractions:2});};RatingNumber.defaultProps={className:'',rating:null};export default RatingNumber;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* eslint-disable no-console */import React from'react';import{mount}from'enzyme';import RatingNumber from"./index";jest.mock('@shopgate/pwa-common/components/I18n',function(){return{// eslint-disable-next-line react/prop-types
|
|
2
|
-
Number:function Number(_ref){var rating=_ref.rating;return
|
|
3
|
-
console.error=jest.fn();describe('RatingNumber',function(){it('should render a number',function(){var component=mount(React.createElement(RatingNumber,{rating:100,className:"class-test"}));expect(component).toMatchSnapshot();expect(component.find('Number').props().number).toBe(5);expect(component.find('Number').props().fractions).toBe(2);expect(component.find('Number').props().className).toBe('class-test ui-shared__rating-number');expect(console.error).not.toHaveBeenCalled();});it('should return when rating is null',function(){var component=mount(React.createElement(RatingNumber,{rating:null}));expect(component.html()).toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return Number when rating is zero',function(){var component=mount(React.createElement(RatingNumber,{rating:0}));expect(component.html()).not.toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return number when division result is NaN',function(){var component=mount(React.createElement(RatingNumber,{rating:{}}));expect(component.html()).toBe(null);expect(console.error).toHaveBeenCalledTimes(1);});});/* eslint-enable no-console */
|
|
2
|
+
Number:function Number(_ref){var rating=_ref.rating;return/*#__PURE__*/React.createElement("div",null,rating);}};});// One of the tests deliberately produces a react warning. The console is mocked to avoid ugly logs.
|
|
3
|
+
console.error=jest.fn();describe('RatingNumber',function(){it('should render a number',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:100,className:"class-test"}));expect(component).toMatchSnapshot();expect(component.find('Number').props().number).toBe(5);expect(component.find('Number').props().fractions).toBe(2);expect(component.find('Number').props().className).toBe('class-test ui-shared__rating-number');expect(console.error).not.toHaveBeenCalled();});it('should return when rating is null',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:null}));expect(component.html()).toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return Number when rating is zero',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:0}));expect(component.html()).not.toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return number when division result is NaN',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:{}}));expect(component.html()).toBe(null);expect(console.error).toHaveBeenCalledTimes(1);});});/* eslint-enable no-console */
|
package/RatingStars/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import times from'lodash/times';import StarIcon from"../icons/StarIcon";import StarHalfIcon from"../icons/StarHalfIcon";import styles from"./style";import{RATING_SCALE_DIVISOR}from"./constants";/**
|
|
2
2
|
* The available style keys for the rating stars.
|
|
3
3
|
*/var numStars=5;/**
|
|
4
4
|
* The rating stars component.
|
|
5
5
|
* @param {Object} props The component props.
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/var RatingStars=/*#__PURE__*/function(_Component){_inherits(RatingStars,_Component);function RatingStars(){_classCallCheck(this,RatingStars);return
|
|
7
|
+
*/var RatingStars=/*#__PURE__*/function(_Component){_inherits(RatingStars,_Component);var _super=_createSuper(RatingStars);function RatingStars(){_classCallCheck(this,RatingStars);return _super.apply(this,arguments);}_createClass(RatingStars,[{key:"shouldComponentUpdate",value:/**
|
|
8
8
|
* Context types definition.
|
|
9
9
|
* @type {{i18n: shim}}
|
|
10
10
|
*/ /**
|
|
11
11
|
* Only update the component if the star rating changed.
|
|
12
12
|
* @param {Object} nextProps The next component props.
|
|
13
13
|
* @returns {boolean}
|
|
14
|
-
*/
|
|
14
|
+
*/function shouldComponentUpdate(nextProps){return nextProps.value!==this.props.value;}/**
|
|
15
15
|
* Returns textual version of stars for screen readers.
|
|
16
16
|
* @param {number} stars Number of stars.
|
|
17
17
|
* @returns {string}
|
|
@@ -26,5 +26,5 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
26
26
|
*/},{key:"handleSelection",value:function handleSelection(e,pos){var onSelection=this.props.onSelection;e.target.value=pos*RATING_SCALE_DIVISOR;onSelection(e);}/**
|
|
27
27
|
* Renders the component.
|
|
28
28
|
* @returns {JSX}
|
|
29
|
-
*/},{key:"render",value:function render(){var _this=this;var _this$props=this.props,value=_this$props.value,isSelectable=_this$props.isSelectable;var ratedStars=value/RATING_SCALE_DIVISOR;var numFullStars=Math.floor(ratedStars);var numHalfStars=Math.ceil(ratedStars-numFullStars);var size=styles.iconStyles[this.props.display].iconSize;var className=[styles.container,this.props.className,'ui-shared__rating-stars'].join(' ');var iconClassName=[styles.iconStyles[this.props.display].iconStyle,styles.icon].join(' ');var emptyStars=[].concat(times(numStars,function(i){var pos=i+1;var starProps=_extends({className:iconClassName,key:pos},isSelectable&&{'aria-label':_this.getTextualCTA(pos),role:'button',onClick:function onClick(e){return _this.handleSelection(e,pos);}});return
|
|
30
|
-
role:'button',onClick:function onClick(e){return _this.handleSelection(e,pos);}});return
|
|
29
|
+
*/},{key:"render",value:function render(){var _this=this;var _this$props=this.props,value=_this$props.value,isSelectable=_this$props.isSelectable;var ratedStars=value/RATING_SCALE_DIVISOR;var numFullStars=Math.floor(ratedStars);var numHalfStars=Math.ceil(ratedStars-numFullStars);var size=styles.iconStyles[this.props.display].iconSize;var className=[styles.container,this.props.className,'ui-shared__rating-stars'].join(' ');var iconClassName=[styles.iconStyles[this.props.display].iconStyle,styles.icon].join(' ');var emptyStars=[].concat(times(numStars,function(i){var pos=i+1;var starProps=_extends({className:iconClassName,key:pos},isSelectable&&{'aria-label':_this.getTextualCTA(pos),role:'button',onClick:function onClick(e){return _this.handleSelection(e,pos);}});return/*#__PURE__*/React.createElement("div",starProps,/*#__PURE__*/React.createElement(StarIcon,{size:size}));}));var filledStars=[].concat(times(numFullStars,function(i){var pos=i+1;var starProps=_extends({className:iconClassName,key:numStars+pos},isSelectable&&{'aria-hidden':true,// Aria hidden since it's basically a duplicate for a screen reader.
|
|
30
|
+
role:'button',onClick:function onClick(e){return _this.handleSelection(e,pos);}});return/*#__PURE__*/React.createElement("div",starProps,/*#__PURE__*/React.createElement(StarIcon,{size:size}));}),times(numHalfStars,function(i){return/*#__PURE__*/React.createElement("div",{className:iconClassName,key:i+numFullStars},/*#__PURE__*/React.createElement(StarHalfIcon,{size:size}));}));/* eslint-disable jsx-a11y/aria-role */return/*#__PURE__*/React.createElement("div",{role:"text",className:className,"aria-label":this.getTextualFinal(ratedStars),"data-test-id":"ratedStars: ".concat(ratedStars)},/*#__PURE__*/React.createElement("div",{className:"".concat(styles.emptyStars," rating-stars-empty")},emptyStars),/*#__PURE__*/React.createElement("div",{className:"".concat(styles.filledStars," rating-stars-filled")},filledStars));/* eslint-enable jsx-a11y/aria-role */}}]);return RatingStars;}(Component);_defineProperty(RatingStars,"contextTypes",{i18n:PropTypes.func});_defineProperty(RatingStars,"defaultProps",{className:'',display:'small',isSelectable:false,onSelection:function onSelection(){}});export default RatingStars;
|
package/RatingStars/spec.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from'react';import{shallow}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import StarIcon from"../icons/StarIcon";import StarHalfIcon from"../icons/StarHalfIcon";import RatingStars from"./index";var numEmptyStars=5;describe('<RatingStars />',function(){it('renders with value of 50',function(){var wrapper=shallow(React.createElement(RatingStars,{value:50}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars+2);expect(wrapper.find(StarHalfIcon).length).toBe(1);});it('renders with value of 0',function(){var wrapper=shallow(React.createElement(RatingStars,{value:0}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars);expect(wrapper.find(StarHalfIcon).length).toBe(0);});it('renders with value of 100',function(){var wrapper=shallow(React.createElement(RatingStars,{value:100}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars+5);expect(wrapper.find(StarHalfIcon).length).toBe(0);});it('should change rating on click',function(){var wrapper=shallow(React.createElement(RatingStars,{value:100,isSelectable:true}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(10);wrapper.setProps({value:20});expect(wrapper.find(StarIcon).length).toBe(6);wrapper.setProps({value:70});expect(wrapper.find(StarIcon).length).toBe(8);expect(wrapper.find(StarHalfIcon).length).toBe(1);expect(wrapper).toMatchSnapshot();});it('should call onSelection callback when component is selectable',function(){var spy=jest.fn();var wrapper=shallow(React.createElement(RatingStars,{value:100,isSelectable:true,onSelection:function onSelection(e){wrapper.setProps({value:e.target.value});spy();}}),mockRenderOptions);// Click on 1 filled star.
|
|
1
|
+
import React from'react';import{shallow}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import StarIcon from"../icons/StarIcon";import StarHalfIcon from"../icons/StarHalfIcon";import RatingStars from"./index";var numEmptyStars=5;describe('<RatingStars />',function(){it('renders with value of 50',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:50}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars+2);expect(wrapper.find(StarHalfIcon).length).toBe(1);});it('renders with value of 0',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:0}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars);expect(wrapper.find(StarHalfIcon).length).toBe(0);});it('renders with value of 100',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:100}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(numEmptyStars+5);expect(wrapper.find(StarHalfIcon).length).toBe(0);});it('should change rating on click',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:100,isSelectable:true}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find(StarIcon).length).toBe(10);wrapper.setProps({value:20});expect(wrapper.find(StarIcon).length).toBe(6);wrapper.setProps({value:70});expect(wrapper.find(StarIcon).length).toBe(8);expect(wrapper.find(StarHalfIcon).length).toBe(1);expect(wrapper).toMatchSnapshot();});it('should call onSelection callback when component is selectable',function(){var spy=jest.fn();var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:100,isSelectable:true,onSelection:function onSelection(e){wrapper.setProps({value:e.target.value});spy();}}),mockRenderOptions);// Click on 1 filled star.
|
|
2
2
|
wrapper.find('[role="button"]').at(5).simulate('click',{target:{value:10}});expect(spy.mock.calls.length).toBe(1);expect(wrapper.find('[role="button"]').length).toBe(6);// Click on 4th empty star
|
|
3
|
-
wrapper.find('[role="button"]').at(3).simulate('click',{target:{value:80}});expect(wrapper.find('[role="button"]').length).toBe(9);expect(spy.mock.calls.length).toBe(2);});it('should NOT call onSelection callback when component is NOT selectable',function(){var spy=jest.fn();var wrapper=shallow(React.createElement(RatingStars,{value:100,onSelection:spy}),mockRenderOptions);wrapper.find(StarIcon).at(5).parent('div').simulate('click');expect(wrapper.find('[role="button"]').length).toBe(0);expect(spy.mock.calls.length).toBe(0);});});
|
|
3
|
+
wrapper.find('[role="button"]').at(3).simulate('click',{target:{value:80}});expect(wrapper.find('[role="button"]').length).toBe(9);expect(spy.mock.calls.length).toBe(2);});it('should NOT call onSelection callback when component is NOT selectable',function(){var spy=jest.fn();var wrapper=shallow(/*#__PURE__*/React.createElement(RatingStars,{value:100,onSelection:spy}),mockRenderOptions);wrapper.find(StarIcon).at(5).parent('div').simulate('click');expect(wrapper.find('[role="button"]').length).toBe(0);expect(spy.mock.calls.length).toBe(0);});});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Transition from'react-inline-transition-group';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import style from"../../style";/**
|
|
2
2
|
* The ripple animation component.
|
|
3
|
-
*/var RippleAnimation=/*#__PURE__*/function(_Component){_inherits(RippleAnimation,_Component);function RippleAnimation(){var
|
|
3
|
+
*/var RippleAnimation=/*#__PURE__*/function(_Component){_inherits(RippleAnimation,_Component);var _super=_createSuper(RippleAnimation);function RippleAnimation(){var _this;_classCallCheck(this,RippleAnimation);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"handlePhaseEnd",function(){_this.props.onComplete();});return _this;}_createClass(RippleAnimation,[{key:"render",value:/**
|
|
4
4
|
* Renders the component.
|
|
5
5
|
* @returns {JSX}
|
|
6
|
-
*/
|
|
6
|
+
*/function render(){var duration=this.props.duration;return/*#__PURE__*/React.createElement(Transition,{childrenStyles:{base:{backgroundColor:this.props.color,height:this.props.size,width:this.props.size,transform:'translate3d(-50%, -50%, 0) scale3d(0, 0, 1)',transition:"opacity ".concat(duration,"ms cubic-bezier(0.25, 0.1, 0.25, 1), transform ").concat(duration,"ms cubic-bezier(0.25, 0.1, 0.25, 1)"),left:this.props.x,top:this.props.y,opacity:0.25},appear:{transform:'translate3d(-50%, -50%, 0) scale3d(1, 1, 1)',opacity:0},enter:{transform:'translate3d(-50%, -50%, 0) scale3d(1, 1, 1)',opacity:0},leave:{}},onPhaseEnd:this.handlePhaseEnd},/*#__PURE__*/React.createElement("div",{className:style.ripple}));}}]);return RippleAnimation;}(Component);_defineProperty(RippleAnimation,"defaultProps",{color:themeConfig.colors.dark,duration:300,onComplete:function onComplete(){},size:48,x:0,y:0});export default RippleAnimation;
|
package/Ripple/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{PureComponent}from'react';import PropTypes from'prop-types';import{findDOMNode}from'react-dom';import clamp from'lodash/clamp';import{shift}from'@shopgate/pwa-common/helpers/data';import{getOffset}from'@shopgate/pwa-common/helpers/dom';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import RippleAnimation from"./components/RippleAnimation";import style from"./style";/**
|
|
2
2
|
* The ripple component.
|
|
3
|
-
*/var Ripple=/*#__PURE__*/function(_PureComponent){_inherits(Ripple,_PureComponent);/**
|
|
3
|
+
*/var Ripple=/*#__PURE__*/function(_PureComponent){_inherits(Ripple,_PureComponent);var _super=_createSuper(Ripple);/**
|
|
4
4
|
* Constructor.
|
|
5
5
|
* @param {Object} props The component props.
|
|
6
|
-
*/function Ripple(props){var _this;_classCallCheck(this,Ripple);_this=
|
|
6
|
+
*/function Ripple(props){var _this;_classCallCheck(this,Ripple);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"handleClick",function(event){if(_this.props.disabled){return;}_this.addRipple(event,true);_this.props.onClick();});_defineProperty(_assertThisInitialized(_this),"removeRipple",function(){if(!_this.mounted){return;}_this.setState(function(prevState){var ripples=shift(prevState.ripples);_this.props.onComplete();return{ripples:ripples,hasRipples:!!ripples.length};});});_this.state={ripples:[],nextKey:0,hasRipples:false};_this.duration=500;_this.ignoreNextMouseDown=false;_this.mounted=false;_this.offset=null;_this.position=null;_this.rootNode=null;_this.style=null;return _this;}/**
|
|
7
7
|
* Sets the `mounted` flag to true.
|
|
8
8
|
*/_createClass(Ripple,[{key:"componentDidMount",value:function componentDidMount(){var fill=this.props.fill;// Reference to Ripple container (for now and later).
|
|
9
9
|
this.rootNode=findDOMNode(this);// eslint-disable-line react/no-find-dom-node
|
|
@@ -18,11 +18,16 @@ this.style=!this.props.overflow?{overflow:'hidden',position:'relative'}:null;}/*
|
|
|
18
18
|
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){this.mounted=false;}/**
|
|
19
19
|
* Calculate the size of the ripple.
|
|
20
20
|
* @returns {number}
|
|
21
|
-
*/},{key:"
|
|
21
|
+
*/},{key:"rippleSize",get:function get(){if(this.props.size){if(this.props.fill){return this.props.size*2;}return this.props.size;}/**
|
|
22
|
+
* We want the Ripple to fill the element. We set the diameter of the Ripple
|
|
23
|
+
* to double the distance of the opposing corners of the node. That way the Ripple
|
|
24
|
+
* will reach the furthest away corner if you click at a corner.
|
|
25
|
+
*/if(this.props.fill){return Math.sqrt(Math.pow(this.rootNode.offsetWidth,2)+Math.pow(this.rootNode.offsetHeight,2))*2;}// Otherwise we set the size to be the smaller of the element's height and width.
|
|
26
|
+
return Math.min(this.rootNode.offsetWidth,this.rootNode.offsetHeight);}/**
|
|
22
27
|
* Calculates the ripple position from the event.
|
|
23
28
|
* @param {Object} event The event object.
|
|
24
29
|
* @returns {Object} An object containing x and y values for the ripple.
|
|
25
|
-
*/value:function getRipplePosition(event){// If the Ripple is to fill the element then we should set the
|
|
30
|
+
*/},{key:"getRipplePosition",value:function getRipplePosition(event){// If the Ripple is to fill the element then we should set the
|
|
26
31
|
// Starting position to be where the user clicked within that element.
|
|
27
32
|
if(this.props.fill){// Determine if event is a touch event.
|
|
28
33
|
var isTouchEvent=event.touches&&event.touches.length;// Find the center points of the event.
|
|
@@ -30,28 +35,23 @@ var pageX=isTouchEvent?event.touches[0].pageX:event.pageX;var pageY=isTouchEvent
|
|
|
30
35
|
this.position.x=pageX-this.offset.left;this.position.y=pageY-this.offset.top;}return this.position;}/**
|
|
31
36
|
* Triggers adding of a new ripple on touch start event.
|
|
32
37
|
* @param {Object} event The even object.
|
|
33
|
-
*/},{key:"addRipple"
|
|
38
|
+
*/},{key:"addRipple",value:/**
|
|
34
39
|
* Adds a new Ripple to the queue.
|
|
35
40
|
* @param {Object} event The event object.
|
|
36
41
|
* @param {boolean} isTouchGenerated Whether the action was triggered by a touch or click.
|
|
37
|
-
*/
|
|
42
|
+
*/function addRipple(event,isTouchGenerated){// If the adding of the Ripple was already triggered
|
|
38
43
|
// By a touch start event, no further action will be done.
|
|
39
44
|
if(this.ignoreNextMouseDown&&!isTouchGenerated){this.ignoreNextMouseDown=false;return;}// Get the position of the element and store it.
|
|
40
45
|
this.offset=getOffset(this.rootNode);// Receive the x and y position for the new Ripple.
|
|
41
46
|
var _this$getRipplePositi=this.getRipplePosition(event),x=_this$getRipplePositi.x,y=_this$getRipplePositi.y;var ripples=this.state.ripples;// Append the new ripple to the ripples array.
|
|
42
|
-
ripples.push(React.createElement(RippleAnimation,{color:this.props.color,duration:this.duration,fill:this.props.fill,key:this.state.nextKey,onComplete:this.removeRipple,size:this.rippleSize,x:x,y:y}));this.ignoreNextMouseDown=isTouchGenerated;// Update the state.
|
|
47
|
+
ripples.push(/*#__PURE__*/React.createElement(RippleAnimation,{color:this.props.color,duration:this.duration,fill:this.props.fill,key:this.state.nextKey,onComplete:this.removeRipple,size:this.rippleSize,x:x,y:y}));this.ignoreNextMouseDown=isTouchGenerated;// Update the state.
|
|
43
48
|
this.setState(function(_ref){var nextKey=_ref.nextKey;return{ripples:ripples,nextKey:nextKey+1,hasRipples:true};});}/**
|
|
44
49
|
* Renders all the ripples in the queue.
|
|
45
50
|
* @returns {JSX|null}
|
|
46
51
|
*/},{key:"renderRipples",value:function renderRipples(){// It only needs to render, if there is at least one ripple in the queue.
|
|
47
|
-
if(!this.state.hasRipples){return null;}return
|
|
52
|
+
if(!this.state.hasRipples){return null;}return/*#__PURE__*/React.createElement("div",{className:style.container},this.state.ripples);}/**
|
|
48
53
|
* Renders the final ripple component including it's contents.
|
|
49
54
|
* @returns {JSX}
|
|
50
55
|
*/},{key:"render",value:function render(){/* eslint-disable jsx-a11y/click-events-have-key-events,
|
|
51
|
-
jsx-a11y/no-static-element-interactions */return
|
|
52
|
-
jsx-a11y/no-static-element-interactions */}},
|
|
53
|
-
* We want the Ripple to fill the element. We set the diameter of the Ripple
|
|
54
|
-
* to double the distance of the opposing corners of the node. That way the Ripple
|
|
55
|
-
* will reach the furthest away corner if you click at a corner.
|
|
56
|
-
*/if(this.props.fill){return Math.sqrt(Math.pow(this.rootNode.offsetWidth,2)+Math.pow(this.rootNode.offsetHeight,2))*2;}// Otherwise we set the size to be the smaller of the element's height and width.
|
|
57
|
-
return Math.min(this.rootNode.offsetWidth,this.rootNode.offsetHeight);}}]);return Ripple;}(PureComponent);_defineProperty(Ripple,"defaultProps",{className:'',color:themeConfig.colors.dark,disabled:false,fill:false,onClick:function onClick(){},onComplete:function onComplete(){},overflow:false,size:null});export default Ripple;
|
|
56
|
+
jsx-a11y/no-static-element-interactions */return/*#__PURE__*/React.createElement("div",{className:"ui-shared__ripple ".concat(this.props.className),"data-test-id":"Ripple",onClick:this.handleClick,style:this.style},this.renderRipples(),this.props.children);/* eslint-enable jsx-a11y/click-events-have-key-events,
|
|
57
|
+
jsx-a11y/no-static-element-interactions */}}]);return Ripple;}(PureComponent);_defineProperty(Ripple,"defaultProps",{className:'',color:themeConfig.colors.dark,disabled:false,fill:false,onClick:function onClick(){},onComplete:function onComplete(){},overflow:false,size:null});export default Ripple;
|
package/RippleButton/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Ripple from"../Ripple";import Button from"../Button";import style from"../Button/style";/**
|
|
2
2
|
* The ripple button component is a special derivation of the basic button component
|
|
3
3
|
* that adds a ripple effect when clicked.
|
|
4
|
-
*/var RippleButton=/*#__PURE__*/function(_Component){_inherits(RippleButton,_Component);function RippleButton(){_classCallCheck(this,RippleButton);return
|
|
5
|
-
* Renders the component.
|
|
6
|
-
* @returns {JSX}
|
|
7
|
-
*/value:function render(){if(this.props.disabled){// Don't show the ripple effect when the button is disabled.
|
|
8
|
-
return React.createElement(Button,_extends({},this.buttonProps,{wrapContent:true}),this.props.children);}var rippleProps={className:"".concat(style.contentWrapper," ").concat(this.props.rippleClassName),fill:true,size:this.props.rippleSize,overflow:true};return React.createElement(Button,_extends({},this.buttonProps,{testId:this.props.testId}),React.createElement(Ripple,rippleProps,this.props.children));}},{key:"buttonProps",/**
|
|
4
|
+
*/var RippleButton=/*#__PURE__*/function(_Component){_inherits(RippleButton,_Component);var _super=_createSuper(RippleButton);function RippleButton(){_classCallCheck(this,RippleButton);return _super.apply(this,arguments);}_createClass(RippleButton,[{key:"buttonProps",get:/**
|
|
9
5
|
* Getter for the calculated button props.
|
|
10
6
|
* @returns {Object}
|
|
11
|
-
*/
|
|
7
|
+
*/function get(){return{className:"".concat(this.props.className," ui-shared__ripple-button"),disabled:this.props.disabled,onClick:this.props.onClick,flat:this.props.flat,type:this.props.type,wrapContent:false};}/**
|
|
8
|
+
* Renders the component.
|
|
9
|
+
* @returns {JSX}
|
|
10
|
+
*/},{key:"render",value:function render(){if(this.props.disabled){// Don't show the ripple effect when the button is disabled.
|
|
11
|
+
return/*#__PURE__*/React.createElement(Button,_extends({},this.buttonProps,{wrapContent:true}),this.props.children);}var rippleProps={className:"".concat(style.contentWrapper," ").concat(this.props.rippleClassName),fill:true,size:this.props.rippleSize,overflow:true};return/*#__PURE__*/React.createElement(Button,_extends({},this.buttonProps,{testId:this.props.testId}),/*#__PURE__*/React.createElement(Ripple,rippleProps,this.props.children));}}]);return RippleButton;}(Component);_defineProperty(RippleButton,"defaultProps",_extends({},Button.defaultProps,{rippleClassName:'',rippleSize:null,testId:'Button'}));export default RippleButton;
|
package/RippleButton/spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import trim from'lodash/trim';import React from'react';import{shallow,mount}from'enzyme';import Button from'@shopgate/pwa-common/components/Button';import Ripple from"../Ripple";import styles from"../Button/style";import RippleButton from"./index";describe('<RippleButton />',function(){it('should render as a regular ripple button effect if type is omitted',function(){var wrapper=shallow(React.createElement(RippleButton,null,"Press me"));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Ripple).render().text()).toEqual('Press me');});it('should render as a regular ripple button if type is explicitly defined',function(){var wrapper=mount(React.createElement(RippleButton,{type:"regular"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.regular(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a primary ripple button',function(){var wrapper=mount(React.createElement(RippleButton,{type:"primary"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.primary(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a secondary ripple button',function(){var wrapper=mount(React.createElement(RippleButton,{type:"secondary"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.secondary(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a disabled ripple button',function(){var wrapper=mount(React.createElement(RippleButton,{disabled:true},"Press me"));expect(wrapper.find(Button).props().disabled).toBe(true);expect(wrapper).toMatchSnapshot();});});
|
|
1
|
+
import trim from'lodash/trim';import React from'react';import{shallow,mount}from'enzyme';import Button from'@shopgate/pwa-common/components/Button';import Ripple from"../Ripple";import styles from"../Button/style";import RippleButton from"./index";describe('<RippleButton />',function(){it('should render as a regular ripple button effect if type is omitted',function(){var wrapper=shallow(/*#__PURE__*/React.createElement(RippleButton,null,"Press me"));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Ripple).render().text()).toEqual('Press me');});it('should render as a regular ripple button if type is explicitly defined',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RippleButton,{type:"regular"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.regular(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a primary ripple button',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RippleButton,{type:"primary"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.primary(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a secondary ripple button',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RippleButton,{type:"secondary"},"Press me"));expect(trim(wrapper.find(Button).props().className)).toEqual("ui-shared__button ".concat(styles.secondary(false).button," ui-shared__ripple-button"));expect(wrapper.find(Ripple).render().text()).toEqual('Press me');expect(wrapper).toMatchSnapshot();});it('should render as a disabled ripple button',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RippleButton,{disabled:true},"Press me"));expect(wrapper.find(Button).props().disabled).toBe(true);expect(wrapper).toMatchSnapshot();});});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from'react';import SurroundPortals from'@shopgate/pwa-common/components/SurroundPortals';import{SCANNER_CAMERA}from'@shopgate/pwa-common-commerce/scanner/constants/Portals';import styles from"./style";/**
|
|
2
2
|
* @returns {JSX}
|
|
3
|
-
*/var CameraOverlay=function CameraOverlay(){return
|
|
3
|
+
*/var CameraOverlay=function CameraOverlay(){return/*#__PURE__*/React.createElement(SurroundPortals,{portalName:SCANNER_CAMERA},/*#__PURE__*/React.createElement("div",{className:styles},/*#__PURE__*/React.createElement("div",null)));};export default CameraOverlay;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from'react';import PropTypes from'prop-types';import ToggleIcon from'@shopgate/pwa-ui-shared/ToggleIcon';import FlashEnabledIcon from'@shopgate/pwa-ui-shared/icons/FlashEnabledIcon';import FlashDisabledIcon from'@shopgate/pwa-ui-shared/icons/FlashDisabledIcon';import{SCANNER_FLASH}from'@shopgate/pwa-common-commerce/scanner/constants/Portals';import SurroundPortals from'@shopgate/pwa-common/components/SurroundPortals';import styles from"./style";/**
|
|
2
2
|
* The FlashlightButton component.
|
|
3
3
|
* @returns {JSX}
|
|
4
|
-
*/var FlashlightButton=function FlashlightButton(_ref){var flashlightState=_ref.flashlightState,onToggle=_ref.onToggle;return
|
|
4
|
+
*/var FlashlightButton=function FlashlightButton(_ref){var flashlightState=_ref.flashlightState,onToggle=_ref.onToggle;return/*#__PURE__*/React.createElement(SurroundPortals,{portalName:SCANNER_FLASH},/*#__PURE__*/React.createElement("button",{className:styles.button,onClick:onToggle,role:"link",type:"button"},/*#__PURE__*/React.createElement(ToggleIcon,{on:flashlightState,onIcon:/*#__PURE__*/React.createElement(FlashEnabledIcon,{className:styles.icon}),offIcon:/*#__PURE__*/React.createElement(FlashDisabledIcon,{className:styles.icon})})));};export default FlashlightButton;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from'react';import I18n from'@shopgate/pwa-common/components/I18n';import SurroundPortals from'@shopgate/pwa-common/components/SurroundPortals';import{SCANNER_INSTRUCTIONS}from'@shopgate/pwa-common-commerce/scanner/constants/Portals';/**
|
|
2
2
|
* The FlashlightButton component.
|
|
3
3
|
* @returns {JSX}
|
|
4
|
-
*/var ScannerInstructions=function ScannerInstructions(){return
|
|
4
|
+
*/var ScannerInstructions=function ScannerInstructions(){return/*#__PURE__*/React.createElement(SurroundPortals,{portalName:SCANNER_INSTRUCTIONS},/*#__PURE__*/React.createElement(I18n.Text,{string:"scanner.instructions"}));};export default ScannerInstructions;
|
|
@@ -2,4 +2,4 @@ import React from'react';import{createPortal}from'react-dom';import PropTypes fr
|
|
|
2
2
|
* @param {boolean} flashlightState The on/off state of the flashlight.
|
|
3
3
|
* @param {Function} onToggleFlashlight The toggle event triggered by the user.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var ScannerBar=function ScannerBar(_ref){var flashlightState=_ref.flashlightState,onToggleFlashlight=_ref.onToggleFlashlight;return
|
|
5
|
+
*/var ScannerBar=function ScannerBar(_ref){var flashlightState=_ref.flashlightState,onToggleFlashlight=_ref.onToggleFlashlight;return/*#__PURE__*/createPortal(/*#__PURE__*/React.createElement(SurroundPortals,{portalName:SCANNER_BAR,portalProps:{flashlightState:flashlightState,onToggleFlashlight:onToggleFlashlight}},/*#__PURE__*/React.createElement(Grid,{className:"".concat(styles.container," ui-shared__scanner-bar")},/*#__PURE__*/React.createElement(Grid.Item,{className:styles.column},/*#__PURE__*/React.createElement(FlashlightButton,{onToggle:onToggleFlashlight,flashlightState:flashlightState})),/*#__PURE__*/React.createElement(Grid.Item,{className:styles.column},/*#__PURE__*/React.createElement(ScannerInstructions,null)))),document.getElementById('AppFooter'));};export default ScannerBar;
|
package/ScannerOverlay/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Fragment,PureComponent}from'react';import PropTypes from'prop-types';import AppScanner from'@shopgate/pwa-core/classes/Scanner';import CameraOverlay from"./components/CameraOverlay";import ScannerBar from"./components/ScannerBar";/**
|
|
2
2
|
* The scanner overlay component.
|
|
3
|
-
*/var ScannerOverlay=/*#__PURE__*/function(_PureComponent){_inherits(ScannerOverlay,_PureComponent);
|
|
3
|
+
*/var ScannerOverlay=/*#__PURE__*/function(_PureComponent){_inherits(ScannerOverlay,_PureComponent);var _super=_createSuper(ScannerOverlay);/**
|
|
4
|
+
* Initializes the component.
|
|
5
|
+
* @param {Object} props The components props.
|
|
6
|
+
*/function ScannerOverlay(props){var _this;_classCallCheck(this,ScannerOverlay);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"handleToggleFlashlight",function(){_this.setState({flashlight:AppScanner.toggleFlashlight()});});_this.state={flashlight:props.flashlight};return _this;}/**
|
|
4
7
|
* @param {Object} nextProps New props to apply.
|
|
5
|
-
*/_createClass(ScannerOverlay,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.state.flashlight!==nextProps.flashlight){this.setState({flashlight:nextProps.flashlight});}}},{key:"render"
|
|
8
|
+
*/_createClass(ScannerOverlay,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.state.flashlight!==nextProps.flashlight){this.setState({flashlight:nextProps.flashlight});}}},{key:"render",value:/**
|
|
6
9
|
* Render the camera overlay and the bottom bar with its contents.
|
|
7
10
|
* @returns {JSX}
|
|
8
|
-
*/
|
|
9
|
-
* Initializes the component.
|
|
10
|
-
* @param {Object} props The components props.
|
|
11
|
-
*/});export default ScannerOverlay;
|
|
11
|
+
*/function render(){return/*#__PURE__*/React.createElement(Fragment,null,/*#__PURE__*/React.createElement(CameraOverlay,null),/*#__PURE__*/React.createElement(ScannerBar,{flashlightState:this.state.flashlight,onToggleFlashlight:this.handleToggleFlashlight}));}}]);return ScannerOverlay;}(PureComponent);_defineProperty(ScannerOverlay,"defaultProps",{flashlight:false});export default ScannerOverlay;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import{defaultClientInformation}from'@shopgate/pwa-core/helpers/version';import AppScanner from'@shopgate/pwa-core/classes/Scanner';import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE,SCANNER_MIN_APP_LIB_VERSION}from'@shopgate/pwa-core/constants/Scanner';import CameraOverlay from"./components/CameraOverlay";import FlashlightButton from"./components/ScannerBar/components/FlashlightButton";import ScannerOverlay from"./index";jest.mock('@shopgate/pwa-core/classes/AppCommand');jest.mock('react-dom',function(){return{createPortal:function createPortal(element){return
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import{defaultClientInformation}from'@shopgate/pwa-core/helpers/version';import AppScanner from'@shopgate/pwa-core/classes/Scanner';import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE,SCANNER_MIN_APP_LIB_VERSION}from'@shopgate/pwa-core/constants/Scanner';import CameraOverlay from"./components/CameraOverlay";import FlashlightButton from"./components/ScannerBar/components/FlashlightButton";import ScannerOverlay from"./index";jest.mock('@shopgate/pwa-core/classes/AppCommand');jest.mock('react-dom',function(){return{createPortal:function createPortal(element){return/*#__PURE__*/React.createElement("div",{id:"portal-content"},element);}};});defaultClientInformation.libVersion=SCANNER_MIN_APP_LIB_VERSION;describe('<ScannerOverlay />',function(){var toggleFlashlightSpy=jest.spyOn(AppScanner,'toggleFlashlight');it('should render the component',function(){var wrapper=mount(/*#__PURE__*/React.createElement(ScannerOverlay,null));expect(wrapper).toMatchSnapshot();expect(wrapper.find(CameraOverlay)).not.toBeEmptyRender();expect(wrapper.find(CameraOverlay)).not.toBeEmptyRender();expect(wrapper.state('flashlight')).toBe(false);});it('should toggle the flashlight when the button is pressed',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var wrapper,button;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return AppScanner.open(SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE);case 2:wrapper=mount(/*#__PURE__*/React.createElement(ScannerOverlay,null));button=wrapper.find(FlashlightButton).find('ToggleIcon');button.simulate('click');expect(wrapper.state('flashlight')).toBe(true);expect(toggleFlashlightSpy).toHaveBeenCalledTimes(1);button.simulate('click');expect(wrapper.state('flashlight')).toBe(false);expect(toggleFlashlightSpy).toHaveBeenCalledTimes(2);case 10:case"end":return _context.stop();}}},_callee);})));});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useState}from'react';import PropTypes from'prop-types';import classNames from'classnames';import I18n from'@shopgate/pwa-common/components/I18n';import Input from'@shopgate/pwa-common/components/Input';import MagnifierIcon from"../../../../../icons/MagnifierIcon";import styles from"./style";/**
|
|
2
2
|
* @return {JSX}
|
|
3
|
-
*/var SearchBar=function SearchBar(_ref){var handleChange=_ref.handleChange;var _useState=useState(''),_useState2=_slicedToArray(_useState,2),query=_useState2[0],setQuery=_useState2[1];var name='search';return
|
|
3
|
+
*/var SearchBar=function SearchBar(_ref){var handleChange=_ref.handleChange;var _useState=useState(''),_useState2=_slicedToArray(_useState,2),query=_useState2[0],setQuery=_useState2[1];var name='search';return/*#__PURE__*/React.createElement("div",{className:"ui-shared__sheet__search-field","data-test-id":"SearchField"},/*#__PURE__*/React.createElement("div",{className:styles.container},/*#__PURE__*/React.createElement("div",{className:styles.inputWrapper},/*#__PURE__*/React.createElement("form",{onSubmit:function onSubmit(e){e.preventDefault();}},/*#__PURE__*/React.createElement("label",{htmlFor:name,className:styles.label},/*#__PURE__*/React.createElement("div",{className:styles.icon},/*#__PURE__*/React.createElement(MagnifierIcon,null)),!query.length&&/*#__PURE__*/React.createElement(I18n.Text,{string:"search.placeholder"})),/*#__PURE__*/React.createElement(Input,{name:name,autoComplete:false,className:classNames(styles.input),onChange:function onChange(value){handleChange(value);setQuery(value);},value:query,type:"search"})))));};export default SearchBar;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import SearchBar from"./index";describe('<SearchBar />',function(){it('should call handleChange on input',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var handleChange,wrapper;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:handleChange=jest.fn();_context.next=3;return mount(React.createElement(SearchBar,{handleChange:handleChange}));case 3:wrapper=_context.sent;expect(wrapper).toMatchSnapshot();// Update input
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import SearchBar from"./index";describe('<SearchBar />',function(){it('should call handleChange on input',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var handleChange,wrapper;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:handleChange=jest.fn();_context.next=3;return mount(/*#__PURE__*/React.createElement(SearchBar,{handleChange:handleChange}));case 3:wrapper=_context.sent;expect(wrapper).toMatchSnapshot();// Update input
|
|
2
2
|
wrapper.find('input').first().simulate('change',{target:{name:'search',value:'asdf'}});// Should call with updated state.
|
|
3
3
|
expect(handleChange).toHaveBeenCalledWith('asdf');case 7:case"end":return _context.stop();}}},_callee);})));});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import classNames from'classnames';import Grid from'@shopgate/pwa-common/components/Grid';import Ripple from"../../../Ripple";import CrossIcon from"../../../icons/CrossIcon";import styles from"./style";import SearchBar from"./components/SearchBar";/**
|
|
2
2
|
* Header component.
|
|
3
|
-
*/var Header=/*#__PURE__*/function(_Component){_inherits(Header,_Component);function Header(){_classCallCheck(this,Header);return
|
|
3
|
+
*/var Header=/*#__PURE__*/function(_Component){_inherits(Header,_Component);var _super=_createSuper(Header);function Header(){_classCallCheck(this,Header);return _super.apply(this,arguments);}_createClass(Header,[{key:"shouldComponentUpdate",value:/**
|
|
4
4
|
* The component's default props.
|
|
5
5
|
* @type {Object}
|
|
6
6
|
*/ /**
|
|
7
7
|
* @param {Object} nextProps Next Props
|
|
8
8
|
* @returns {boolean}
|
|
9
|
-
*/
|
|
9
|
+
*/function shouldComponentUpdate(nextProps){return this.props.shadow!==nextProps.shadow||this.props.title!==nextProps.title;}/**
|
|
10
10
|
* Renders the component.
|
|
11
11
|
* @returns {JSX}
|
|
12
|
-
*/},{key:"render",value:function render(){var classes=classNames(styles.wrapper);var _this$context$i18n=this.context.i18n(),__=_this$context$i18n.__;return
|
|
12
|
+
*/},{key:"render",value:function render(){var classes=classNames(styles.wrapper);var _this$context$i18n=this.context.i18n(),__=_this$context$i18n.__;return/*#__PURE__*/React.createElement("div",{className:classNames(_defineProperty({},styles.shadow,this.props.shadow))},/*#__PURE__*/React.createElement(Grid,{className:classes,component:"div",wrap:false},/*#__PURE__*/React.createElement("button",{className:styles.closeButton,onClick:this.props.onToggleClose,"aria-label":__('common.close'),type:"button"},/*#__PURE__*/React.createElement(Ripple,{className:styles.closeIcon},/*#__PURE__*/React.createElement(CrossIcon,{size:24}))),/*#__PURE__*/React.createElement(Grid.Item,{className:styles.title,component:"div",grow:1,role:"heading"},this.props.title)),this.props.showSearch&&/*#__PURE__*/React.createElement(SearchBar,{handleChange:this.props.handleChange}));}}]);return Header;}(Component);_defineProperty(Header,"defaultProps",{onToggleClose:function onToggleClose(){},shadow:false,handleChange:function handleChange(){},showSearch:false});_defineProperty(Header,"contextTypes",{i18n:PropTypes.func});export default Header;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import React from'react';import{shallow,mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import Header from"./index";describe('<Header />',function(){it('should render with correct title',function(){var title='My Title';var wrapper=shallow(React.createElement(Header,{title:title}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find('GridItem').first().props().children).toEqual(title);});it('should render searchbar',function(){var title='My Title';var wrapper=mount(React.createElement(Header,{title:title,showSearch:true}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find('SearchBar').length).toBe(1);});it('should call handleChange on input',function(){var title='My Title';var handleChange=jest.fn();var wrapper=mount(React.createElement(Header,{title:title,showSearch:true,handleChange:handleChange}),mockRenderOptions);wrapper.find('input').first().simulate('change',{target:{name:'search',value:'asdf'}});expect(handleChange).toHaveBeenCalledWith('asdf');});});
|
|
1
|
+
import React from'react';import{shallow,mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import Header from"./index";describe('<Header />',function(){it('should render with correct title',function(){var title='My Title';var wrapper=shallow(/*#__PURE__*/React.createElement(Header,{title:title}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find('GridItem').first().props().children).toEqual(title);});it('should render searchbar',function(){var title='My Title';var wrapper=mount(/*#__PURE__*/React.createElement(Header,{title:title,showSearch:true}),mockRenderOptions);expect(wrapper).toMatchSnapshot();expect(wrapper.find('SearchBar').length).toBe(1);});it('should call handleChange on input',function(){var title='My Title';var handleChange=jest.fn();var wrapper=mount(/*#__PURE__*/React.createElement(Header,{title:title,showSearch:true,handleChange:handleChange}),mockRenderOptions);wrapper.find('input').first().simulate('change',{target:{name:'search',value:'asdf'}});expect(handleChange).toHaveBeenCalledWith('asdf');});});
|