@shopgate/pwa-ui-shared 6.20.0-beta.1 → 6.20.0-beta.12
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}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);}import{logger}from'@shopgate/pwa-core/helpers';import{ELEMENT_TYPE_COUNTRY,ELEMENT_TYPE_PROVINCE}from"../elementTypes";/** Noop function */var noop=function noop(){};/**
|
|
1
|
+
var _excluded=["custom"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}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);}import{logger}from'@shopgate/pwa-core/helpers';import{ELEMENT_TYPE_COUNTRY,ELEMENT_TYPE_PROVINCE}from"../elementTypes";/** Noop function */var noop=function noop(){};/**
|
|
2
2
|
* @typedef {Object} FormElement
|
|
3
3
|
* @property {string} id
|
|
4
4
|
* @property {boolean} custom
|
|
@@ -26,6 +26,6 @@ function _objectWithoutProperties(source,excluded){if(source==null)return{};var
|
|
|
26
26
|
*/var addFormElement=function addFormElement(id,field){var custom=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;// The "custom" field is just a placeholder for more fields
|
|
27
27
|
if(typeof field.type!=='string'){return;}// Make sure country and province elements are only added once
|
|
28
28
|
if(field.type===ELEMENT_TYPE_COUNTRY){if(hasCountryElement){logger.error("Error: Can not add multiple elements of type '".concat(field.type,"'"));return;}hasCountryElement=true;}if(field.type===ELEMENT_TYPE_PROVINCE){if(hasProvinceElement){logger.error("Error: Can not add multiple elements of type '".concat(field.type,"'"));return;}hasProvinceElement=true;}elementList.push(_extends({id:id},field,{custom:custom,handleChange:function handleChange(value){return elementChangeHandler(id,value);}}));};// Extract custom fields, do not mix with normal fields
|
|
29
|
-
var _formConfig$fields=formConfig.fields,custom=_formConfig$fields.custom,restFields=_objectWithoutProperties(_formConfig$fields,
|
|
29
|
+
var _formConfig$fields=formConfig.fields,custom=_formConfig$fields.custom,restFields=_objectWithoutProperties(_formConfig$fields,_excluded);// Add all non-custom attributes and mark them as such
|
|
30
30
|
Object.keys(restFields).forEach(function(id){addFormElement(id,formConfig.fields[id]);});// Add custom fields to the element list
|
|
31
31
|
if(custom){Object.keys(custom).forEach(function(id){addFormElement(id,formConfig.fields.custom[id],true);});}return elementList;});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{ELEMENT_TYPE_COUNTRY}from"../elementTypes";import buildFormElements from"./buildFormElements";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var formElementConfig={sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true};var formElement={id:'field',sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true,custom:false};describe('buildFormElements',function(){it('should not build custom field',function(){var config={fields:{custom:formElementConfig}};expect(buildFormElements(config)).toEqual([]);});it('should not build empty config',function(){var config={fields:{}};expect(buildFormElements(config)).toEqual([]);});it('should build text element',function(){var config={fields:{field:formElementConfig}};var _buildFormElements$=buildFormElements(config)[0],ignore=_buildFormElements$.handleChange,restElement=_objectWithoutProperties(_buildFormElements$,
|
|
1
|
+
var _excluded=["handleChange"],_excluded2=["handleChange"],_excluded3=["handleChange"];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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{ELEMENT_TYPE_COUNTRY}from"../elementTypes";import buildFormElements from"./buildFormElements";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var formElementConfig={sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true};var formElement={id:'field',sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true,custom:false};describe('buildFormElements',function(){it('should not build custom field',function(){var config={fields:{custom:formElementConfig}};expect(buildFormElements(config)).toEqual([]);});it('should not build empty config',function(){var config={fields:{}};expect(buildFormElements(config)).toEqual([]);});it('should build text element',function(){var config={fields:{field:formElementConfig}};var _buildFormElements$=buildFormElements(config)[0],ignore=_buildFormElements$.handleChange,restElement=_objectWithoutProperties(_buildFormElements$,_excluded);expect(restElement).toEqual(formElement);});it('should build 1 country element',function(){var config={fields:{country:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY}),country_2:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY})}};var expected=_extends({},formElement,{id:'country',type:ELEMENT_TYPE_COUNTRY});var _buildFormElements$2=buildFormElements(config)[0],ignore=_buildFormElements$2.handleChange,restElement=_objectWithoutProperties(_buildFormElements$2,_excluded2);expect(restElement).toEqual(expected);});it('should build custom text element',function(){var config={fields:{custom:{field:formElementConfig}}};var expected=_extends({},formElement,{custom:true});var _buildFormElements$3=buildFormElements(config)[0],ignore=_buildFormElements$3.handleChange,restElement=_objectWithoutProperties(_buildFormElements$3,_excluded3);expect(restElement).toEqual(expected);});it('should build correct change handler for text field',function(){var config={fields:{field:formElementConfig}};var mockHandler=jest.fn();var handleChange=buildFormElements(config,mockHandler)[0].handleChange;// Invoke handler with field value
|
|
2
2
|
handleChange('bar');expect(mockHandler).toBeCalledWith('field','bar');});});
|
|
@@ -4,4 +4,4 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
4
4
|
* @param {string} countryCode Country code of the country to fetch provinces from
|
|
5
5
|
* @param {?Object} optional object to prepend optional choice
|
|
6
6
|
* @return {Object}
|
|
7
|
-
*/export default(function(countryCode){var optional=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(!iso3166){return{};}/** @property {iso3166} divisions */var provinceList=iso3166[countryCode]?iso3166[countryCode].divisions:{};if(!optional){return provinceList;}return _extends({},optional,
|
|
7
|
+
*/export default(function(countryCode){var optional=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(!iso3166){return{};}/** @property {iso3166} divisions */var provinceList=iso3166[countryCode]?iso3166[countryCode].divisions:{};if(!optional){return provinceList;}return _extends({},optional,provinceList);});
|
|
@@ -1,6 +1,6 @@
|
|
|
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;}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 _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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}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{logger}from'@shopgate/pwa-core/helpers';import{ELEMENT_TYPE_NUMBER,ELEMENT_TYPE_COUNTRY,ELEMENT_TYPE_PROVINCE,ELEMENT_TYPE_CHECKBOX}from"../../elementTypes";import{ACTION_TYPE_UPDATE_PROVINCE_ELEMENT,ACTION_TYPE_SET_VISIBILITY,ACTION_TYPE_SET_VALUE,ACTION_TYPE_TRANSFORM,ACTION_SET_VALUE_FIXED,ACTION_SET_VALUE_COPY_FROM,ACTION_SET_VALUE_LENGTH_OF,ACTION_RULE_TYPE_NOT_IN,ACTION_RULE_TYPE_ONE_OF,ACTION_RULE_TYPE_BOOLEAN,ACTION_RULE_TYPE_REGEX,ACTION_RULE_DATA_TYPES,ACTION_RULES_CONCAT_METHOD_ALL,ACTION_RULES_CONCAT_METHOD_ANY,ACTION_RULES_CONCAT_METHOD_NONE}from"./constants";/**
|
|
2
2
|
* ActionListener and handler for the FormBuilder component
|
|
3
|
-
*/var ActionListener
|
|
3
|
+
*/var ActionListener=/*#__PURE__*/_createClass(/**
|
|
4
4
|
* Constructor
|
|
5
5
|
* @param {function(string)} getProvincesList Takes a country code and returns a list of provinces
|
|
6
6
|
* @param {Object} defaults Form defaults
|
|
@@ -37,4 +37,4 @@ newState=notifyListener(prevState,newState);});}return newState;});this.defaults
|
|
|
37
37
|
* Takes the elements to be rendered by the FormBuilder and attaches available action listeners
|
|
38
38
|
* to the component.
|
|
39
39
|
* @param {FormElement[]} elementList List of all elements
|
|
40
|
-
|
|
40
|
+
*/);export default ActionListener;
|
|
@@ -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 _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 Checkbox from"../../Checkbox";/**
|
|
2
2
|
* Takes an element and renders it, if the type matches
|
|
3
3
|
* @param {Object} element The data of the element to be rendered
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var CheckboxElement=/*#__PURE__*/function(_PureComponent){_inherits(CheckboxElement,_PureComponent);function CheckboxElement(){_classCallCheck(this,CheckboxElement);return
|
|
5
|
+
*/var CheckboxElement=/*#__PURE__*/function(_PureComponent){_inherits(CheckboxElement,_PureComponent);var _super=_createSuper(CheckboxElement);function CheckboxElement(){_classCallCheck(this,CheckboxElement);return _super.apply(this,arguments);}_createClass(CheckboxElement,[{key:"render",value:/**
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
7
|
+
*/function render(){var _this$props=this.props,element=_this$props.element,style=_this$props.style,errorText=_this$props.errorText,value=_this$props.value,name=_this$props.name;return/*#__PURE__*/React.createElement(Checkbox,{name:name,errorText:errorText,checked:value,className:style.fields,label:element.label,onChange:element.handleChange,translateErrorText:false});}}]);return CheckboxElement;}(PureComponent);_defineProperty(CheckboxElement,"defaultProps",{value:false,style:{fields:''}});export default CheckboxElement;
|
|
@@ -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 _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 Select from"../../Select";/**
|
|
2
2
|
* React component that takes the element and additional data and renders a select box
|
|
3
3
|
* with a list of countries to select from.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var CountryElement=/*#__PURE__*/function(_PureComponent){_inherits(CountryElement,_PureComponent);function CountryElement(){_classCallCheck(this,CountryElement);return
|
|
5
|
+
*/var CountryElement=/*#__PURE__*/function(_PureComponent){_inherits(CountryElement,_PureComponent);var _super=_createSuper(CountryElement);function CountryElement(){_classCallCheck(this,CountryElement);return _super.apply(this,arguments);}_createClass(CountryElement,[{key:"render",value:/**
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
7
|
+
*/function render(){var _this$props=this.props,countryList=_this$props.countryList,element=_this$props.element,errorText=_this$props.errorText,name=_this$props.name,style=_this$props.style,value=_this$props.value;return/*#__PURE__*/React.createElement(Select,{name:name,className:style.fields,label:element.label,placeholder:element.placeholder,value:value,options:countryList,onChange:element.handleChange,errorText:errorText,isControlled:true,translateErrorText:false});}}]);return CountryElement;}(PureComponent);_defineProperty(CountryElement,"defaultProps",{countryList:{},value:'',style:{fields:''}});export default CountryElement;
|
|
@@ -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 _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 Select from"../../Select";/**
|
|
2
2
|
* React component that takes the element and additional data and renders a select box
|
|
3
3
|
* with a list of provinces to select from.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var ProvinceElement=/*#__PURE__*/function(_PureComponent){_inherits(ProvinceElement,_PureComponent);function ProvinceElement(){_classCallCheck(this,ProvinceElement);return
|
|
5
|
+
*/var ProvinceElement=/*#__PURE__*/function(_PureComponent){_inherits(ProvinceElement,_PureComponent);var _super=_createSuper(ProvinceElement);function ProvinceElement(){_classCallCheck(this,ProvinceElement);return _super.apply(this,arguments);}_createClass(ProvinceElement,[{key:"render",value:/**
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
7
|
+
*/function render(){var _this$props=this.props,provincesList=_this$props.provincesList,element=_this$props.element,errorText=_this$props.errorText,name=_this$props.name,style=_this$props.style,value=_this$props.value;return/*#__PURE__*/React.createElement(Select,{name:name,className:style.fields,label:element.label,placeholder:element.placeholder,value:value,options:provincesList,onChange:element.handleChange,errorText:errorText,isControlled:true,translateErrorText:false});}}]);return ProvinceElement;}(PureComponent);_defineProperty(ProvinceElement,"defaultProps",{provincesList:{},value:'',style:{fields:''}});export default ProvinceElement;
|
|
@@ -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 _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 RadioGroup from"../../RadioGroup";import RadioItem from"../../RadioGroup/components/Item";/**
|
|
2
2
|
* React component that takes the element and additional data and renders a radio group
|
|
3
3
|
* with a list of radio items.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var RadioElement=/*#__PURE__*/function(_PureComponent){_inherits(RadioElement,_PureComponent);function RadioElement(){_classCallCheck(this,RadioElement);return
|
|
5
|
+
*/var RadioElement=/*#__PURE__*/function(_PureComponent){_inherits(RadioElement,_PureComponent);var _super=_createSuper(RadioElement);function RadioElement(){_classCallCheck(this,RadioElement);return _super.apply(this,arguments);}_createClass(RadioElement,[{key:"render",value:/**
|
|
6
6
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
7
|
+
*/function render(){var _this$props=this.props,element=_this$props.element,errorText=_this$props.errorText,name=_this$props.name,style=_this$props.style,value=_this$props.value;return/*#__PURE__*/React.createElement(RadioGroup,{name:name,className:style.fields,label:element.label,value:value,onChange:element.handleChange,errorText:errorText,isControlled:true,translateErrorText:false},Object.keys(element.options).map(function(itemName){return/*#__PURE__*/React.createElement(RadioItem,{key:itemName,name:itemName,label:element.options[itemName]});}));}}]);return RadioElement;}(PureComponent);_defineProperty(RadioElement,"defaultProps",{value:'',style:{fields:''}});export default RadioElement;
|
|
@@ -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,{PureComponent}from'react';import PropTypes from'prop-types';import Select from"../../Select";/**
|
|
2
2
|
* React component that takes the element and additional data and renders a configured select box.
|
|
3
3
|
* @returns {JSX}
|
|
4
|
-
*/var SelectElement=/*#__PURE__*/function(_PureComponent){_inherits(SelectElement,_PureComponent);function SelectElement(){_classCallCheck(this,SelectElement);return
|
|
4
|
+
*/var SelectElement=/*#__PURE__*/function(_PureComponent){_inherits(SelectElement,_PureComponent);var _super=_createSuper(SelectElement);function SelectElement(){_classCallCheck(this,SelectElement);return _super.apply(this,arguments);}_createClass(SelectElement,[{key:"render",value:/**
|
|
5
5
|
* @returns {JSX}
|
|
6
|
-
*/
|
|
6
|
+
*/function render(){var _this$props=this.props,element=_this$props.element,errorText=_this$props.errorText,name=_this$props.name,style=_this$props.style,value=_this$props.value;return/*#__PURE__*/React.createElement(Select,{name:name,className:style.fields,label:element.label,placeholder:element.placeholder,value:value,options:element.options,onChange:element.handleChange,errorText:errorText,isControlled:true,translateErrorText:false});}}]);return SelectElement;}(PureComponent);_defineProperty(SelectElement,"defaultProps",{value:'',style:{fields:''}});export default SelectElement;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
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);}var _mapping;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 TextField from"../../../TextField";import{ELEMENT_TYPE_TEXT,ELEMENT_TYPE_NUMBER,ELEMENT_TYPE_EMAIL,ELEMENT_TYPE_PASSWORD,ELEMENT_TYPE_DATE,ELEMENT_TYPE_PHONE}from"../elementTypes";// Map element type to input type
|
|
2
2
|
var mapping=(_mapping={},_defineProperty(_mapping,ELEMENT_TYPE_TEXT,'text'),_defineProperty(_mapping,ELEMENT_TYPE_NUMBER,'number'),_defineProperty(_mapping,ELEMENT_TYPE_EMAIL,'email'),_defineProperty(_mapping,ELEMENT_TYPE_PASSWORD,'password'),_defineProperty(_mapping,ELEMENT_TYPE_DATE,'date'),_defineProperty(_mapping,ELEMENT_TYPE_PHONE,'tel'),_mapping);/**
|
|
3
3
|
* React component that takes the element and additional data and renders a configured text input.
|
|
4
|
-
*/var TextElement=/*#__PURE__*/function(_PureComponent){_inherits(TextElement,_PureComponent);function TextElement(){_classCallCheck(this,TextElement);return
|
|
4
|
+
*/var TextElement=/*#__PURE__*/function(_PureComponent){_inherits(TextElement,_PureComponent);var _super=_createSuper(TextElement);function TextElement(){_classCallCheck(this,TextElement);return _super.apply(this,arguments);}_createClass(TextElement,[{key:"render",value:/**
|
|
5
5
|
* @returns {JSX}
|
|
6
|
-
*/
|
|
6
|
+
*/function render(){var _this$props=this.props,element=_this$props.element,errorText=_this$props.errorText,name=_this$props.name,style=_this$props.style,value=_this$props.value;var type=mapping[element.type];return/*#__PURE__*/React.createElement(TextField,{type:type,name:name,className:style.fields,label:element.label,value:value,onChange:element.handleChange,errorText:errorText,isControlled:true,translateErrorText:false});}}]);return TextElement;}(PureComponent);_defineProperty(TextElement,"defaultProps",{value:'',style:{field:''}});export default TextElement;
|
package/Form/Builder/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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);}import _isEqual from"lodash/isEqual";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;}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,Fragment}from'react';import PropTypes from'prop-types';import{logger}from'@shopgate/pwa-core/helpers';import Portal from'@shopgate/pwa-common/components/Portal';import Form from'@shopgate/pwa-ui-shared/Form';import{BEFORE,AFTER}from'@shopgate/pwa-common/constants/Portals';import ActionListener from"./classes/ActionListener";import{ELEMENT_TYPE_EMAIL,ELEMENT_TYPE_PASSWORD,ELEMENT_TYPE_TEXT,ELEMENT_TYPE_NUMBER,ELEMENT_TYPE_SELECT,ELEMENT_TYPE_COUNTRY,ELEMENT_TYPE_PROVINCE,ELEMENT_TYPE_CHECKBOX,ELEMENT_TYPE_RADIO,ELEMENT_TYPE_DATE,ELEMENT_TYPE_PHONE}from"./elementTypes";import TextElement from"./components/TextElement";import SelectElement from"./components/SelectElement";import CountryElement from"./components/CountryElement";import ProvinceElement from"./components/ProvinceElement";import RadioElement from"./components/RadioElement";import CheckboxElement from"./components/CheckboxElement";import buildFormElements from"./builders/buildFormElements";import buildFormDefaults from"./builders/buildFormDefaults";import buildCountryList from"./builders/buildCountryList";import buildProvinceList from"./builders/buildProvinceList";import buildValidationErrorList from"./builders/buildValidationErrorList";/**
|
|
2
2
|
* Takes a string and converts it to a part to be used in a portal name
|
|
3
3
|
* @package FormBuilder
|
|
4
4
|
* @param {string} s The string to be sanitized
|
|
@@ -9,7 +9,10 @@ import _isEqual from"lodash/isEqual";function _typeof(obj){if(typeof Symbol==="f
|
|
|
9
9
|
*/var emptySelectOption={'':''};/**
|
|
10
10
|
* Takes a form configuration and handles rendering and updates of the form fields.
|
|
11
11
|
* Note: Only one country and one province element is supported per FormBuilder instance.
|
|
12
|
-
*/var Builder=/*#__PURE__*/function(_Component){_inherits(Builder,_Component);
|
|
12
|
+
*/var Builder=/*#__PURE__*/function(_Component){_inherits(Builder,_Component);var _super=_createSuper(Builder);/**
|
|
13
|
+
* Initializes the component.
|
|
14
|
+
* @param {Object} props The components props.
|
|
15
|
+
*/function Builder(props){var _this;_classCallCheck(this,Builder);_this=_super.call(this,props);// Prepare internal state
|
|
13
16
|
_defineProperty(_assertThisInitialized(_this),"elementSortFunc",function(element1,element2){// Keep current sort order when no specific sort order was set for both
|
|
14
17
|
if(element1.sortOrder===undefined||element2.sortOrder===undefined){return 0;}// Sort in ascending order of sortOrder otherwise
|
|
15
18
|
return element1.sortOrder-element2.sortOrder;});_defineProperty(_assertThisInitialized(_this),"elementChangeHandler",function(elementId,value){// Apply value change to new state
|
|
@@ -24,7 +27,7 @@ var updateData={};_this.formElements.forEach(function(el){if(el.custom){if(updat
|
|
|
24
27
|
_this.props.handleUpdate(updateData,hasErrors||hasValidationErrors);});_defineProperty(_assertThisInitialized(_this),"renderElement",function(element){var elementName="".concat(_this.props.name,".").concat(element.id);var elementErrorText=_this.state.errors[element.id]||'';var elementValue=_this.state.formData[element.id];var elementVisible=_this.state.elementVisibility[element.id]||false;if(!elementVisible){return null;}/*
|
|
25
28
|
* Elements do check the type before they render themselves, but not even trying to render
|
|
26
29
|
* creates a better React DOM
|
|
27
|
-
*/switch(element.type){case ELEMENT_TYPE_TEXT:case ELEMENT_TYPE_NUMBER:case ELEMENT_TYPE_EMAIL:case ELEMENT_TYPE_PASSWORD:case ELEMENT_TYPE_DATE:case ELEMENT_TYPE_PHONE:{return
|
|
30
|
+
*/switch(element.type){case ELEMENT_TYPE_TEXT:case ELEMENT_TYPE_NUMBER:case ELEMENT_TYPE_EMAIL:case ELEMENT_TYPE_PASSWORD:case ELEMENT_TYPE_DATE:case ELEMENT_TYPE_PHONE:{return/*#__PURE__*/React.createElement(TextElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue||'',visible:elementVisible});}case ELEMENT_TYPE_SELECT:return/*#__PURE__*/React.createElement(SelectElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue,visible:elementVisible});case ELEMENT_TYPE_COUNTRY:return/*#__PURE__*/React.createElement(CountryElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue,visible:elementVisible,countryList:_this.countryList});case ELEMENT_TYPE_PROVINCE:{var countryElement=_this.formElements.find(function(el){return el.type===ELEMENT_TYPE_COUNTRY;});var provincesList=countryElement&&_this.state.formData[countryElement.id]?buildProvinceList(_this.state.formData[countryElement.id],element.required?null:emptySelectOption):{};return/*#__PURE__*/React.createElement(ProvinceElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue,visible:elementVisible,provincesList:provincesList});}case ELEMENT_TYPE_RADIO:{return/*#__PURE__*/React.createElement(RadioElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue,visible:elementVisible});}case ELEMENT_TYPE_CHECKBOX:{return/*#__PURE__*/React.createElement(CheckboxElement,{name:elementName,element:element,errorText:elementErrorText,value:elementValue,visible:elementVisible});}default:{logger.error("Unknown form element type: ".concat(element.type));break;}}return null;});_this.state={elementVisibility:{},formData:{},// Convert errors structure to direct access errors
|
|
28
31
|
errors:buildValidationErrorList(props.validationErrors)};// Reorganize form elements into a structure that can be easily rendered
|
|
29
32
|
var formElements=buildFormElements(props.config,_this.elementChangeHandler);// Compute defaults
|
|
30
33
|
var formDefaults=buildFormDefaults(formElements,props.defaults);// Assign defaults to state
|
|
@@ -46,10 +49,7 @@ var _newState=_this.state;_this.formElements.forEach(function(element){_newState
|
|
|
46
49
|
* @param {FormElement} element1 First element
|
|
47
50
|
* @param {FormElement} element2 Second element
|
|
48
51
|
* @returns {number}
|
|
49
|
-
*/},{key:"render"
|
|
52
|
+
*/},{key:"render",value:/**
|
|
50
53
|
* Renders the component based on the given config
|
|
51
54
|
* @return {JSX}
|
|
52
|
-
*/
|
|
53
|
-
* Initializes the component.
|
|
54
|
-
* @param {Object} props The components props.
|
|
55
|
-
*/});export default Builder;
|
|
55
|
+
*/function render(){var _this2=this;return/*#__PURE__*/React.createElement(Fragment,null,/*#__PURE__*/React.createElement(Form,{onSubmit:this.props.onSubmit},/*#__PURE__*/React.createElement("div",{className:this.props.className},this.formElements.map(function(element){return/*#__PURE__*/React.createElement(Fragment,{key:"".concat(_this2.props.name,".").concat(element.id)},/*#__PURE__*/React.createElement(Portal,{name:"".concat(sanitize(_this2.props.name),".").concat(sanitize(element.id),".").concat(BEFORE)}),/*#__PURE__*/React.createElement(Portal,{name:"".concat(sanitize(_this2.props.name),".").concat(sanitize(element.id))},_this2.renderElement(element)),/*#__PURE__*/React.createElement(Portal,{name:"".concat(sanitize(_this2.props.name),".").concat(sanitize(element.id),".").concat(AFTER)}));}))));}}]);return Builder;}(Component);_defineProperty(Builder,"defaultProps",{className:'',defaults:{},onSubmit:function onSubmit(){},validationErrors:[]});export default Builder;
|
package/Form/Builder/spec.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
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);}/* eslint-disable extra-rules/no-single-line-objects */import React from'react';import{mount}from'enzyme';import FormBuilder from'.';describe('<FormBuilder />',function(){it('should render empty form',function(){var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();});it('should render two text fields',function(){var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{firstName:{label:'foo',type:'text',visible:true},lastName:{label:'bar',type:'text',visible:true}}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);});it('should not render invisible field',function(){var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{firstName:{label:'foo',type:'text',visible:false}}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(0);});it('should hide element if setVisibilty rule applies',function(){var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true},bar:{label:'bar',type:'text',actions:[{type:'setVisibility',rules:[{context:'foo',type:'notIn',data:['abc']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Both should be visible at the beginning.
|
|
1
|
+
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);}/* eslint-disable extra-rules/no-single-line-objects */import React from'react';import{mount}from'enzyme';import FormBuilder from'.';describe('<FormBuilder />',function(){it('should render empty form',function(){var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();});it('should render two text fields',function(){var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{firstName:{label:'foo',type:'text',visible:true},lastName:{label:'bar',type:'text',visible:true}}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);});it('should not render invisible field',function(){var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{firstName:{label:'foo',type:'text',visible:false}}},name:"foo",handleUpdate:function handleUpdate(){}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(0);});it('should hide element if setVisibilty rule applies',function(){var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true},bar:{label:'bar',type:'text',actions:[{type:'setVisibility',rules:[{context:'foo',type:'notIn',data:['abc']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Both should be visible at the beginning.
|
|
2
2
|
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);// Simulate user input to the text field.
|
|
3
3
|
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});// Second field should be hidden now.
|
|
4
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(1);});it('should reset value when rule applies',function(){var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'},bar:{label:'bar',type:'text',"default":'default',actions:[{type:'setValue',params:{value:'cheat',type:'fixed'},rules:[{context:'foo',type:'notIn',data:['default']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Default values should be in the inputs.
|
|
4
|
+
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(1);});it('should reset value when rule applies',function(){var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'},bar:{label:'bar',type:'text',"default":'default',actions:[{type:'setValue',params:{value:'cheat',type:'fixed'},rules:[{context:'foo',type:'notIn',data:['default']}]}]}}},name:"foo",handleUpdate:function handleUpdate(){}}));// Default values should be in the inputs.
|
|
5
5
|
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);expect(wrapper.find('input').at(0).props().value).toEqual('default');expect(wrapper.find('input').at(1).props().value).toEqual('default');// Simulate text input to trigger rule.
|
|
6
6
|
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});wrapper.update();// Second field should be hidden now.
|
|
7
|
-
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);expect(wrapper.find('input').at(0).props().value).toEqual('abc');expect(wrapper.find('input').at(1).props().value).toEqual('cheat');});it('should call onChange callback when input is changed',function(){var handleUpdate=jest.fn();var wrapper=mount(React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'}}},name:"foo",id:"foo",handleUpdate:handleUpdate}));// Should call with initial state.
|
|
7
|
+
expect(wrapper).toMatchSnapshot();expect(wrapper.find('TextField').length).toEqual(2);expect(wrapper.find('input').at(0).props().value).toEqual('abc');expect(wrapper.find('input').at(1).props().value).toEqual('cheat');});it('should call onChange callback when input is changed',function(){var handleUpdate=jest.fn();var wrapper=mount(/*#__PURE__*/React.createElement(FormBuilder,{config:{fields:{foo:{label:'foo',type:'text',visible:true,"default":'default'}}},name:"foo",id:"foo",handleUpdate:handleUpdate}));// Should call with initial state.
|
|
8
8
|
expect(wrapper).toMatchSnapshot();expect(handleUpdate).toHaveBeenCalledWith({foo:'default'},false);handleUpdate.mockClear();// Update input
|
|
9
9
|
wrapper.find('input').first().simulate('change',{target:{value:'abc'}});// Should call with updated state.
|
|
10
10
|
expect(handleUpdate).toHaveBeenCalledWith({foo:'abc'},false);});describe('FormBuilder::elementChangeHandler',function(){it('should take the updated state from action listener',function(){// Create mocked Form builder.
|
package/Form/Checkbox/index.js
CHANGED
|
@@ -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);}var _excluded=["name","label","onChange","className","errorText","translateErrorText"];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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}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 classNames from'classnames';import I18n from'@shopgate/pwa-common/components/I18n';import UICheckbox from'@shopgate/pwa-ui-shared/Checkbox';import FormElement from'@shopgate/pwa-ui-shared/FormElement';import style from"./style";/**
|
|
2
2
|
* A component that provides a styled checkbox field.
|
|
3
3
|
* @returns {JSX}
|
|
4
|
-
*/var Checkbox=/*#__PURE__*/function(_PureComponent){_inherits(Checkbox,_PureComponent);function Checkbox(){_classCallCheck(this,Checkbox);return
|
|
4
|
+
*/var Checkbox=/*#__PURE__*/function(_PureComponent){_inherits(Checkbox,_PureComponent);var _super=_createSuper(Checkbox);function Checkbox(){_classCallCheck(this,Checkbox);return _super.apply(this,arguments);}_createClass(Checkbox,[{key:"render",value:/**
|
|
5
5
|
* @return {JSX}
|
|
6
|
-
*/
|
|
6
|
+
*/function render(){var _this$props=this.props,name=_this$props.name,label=_this$props.label,onChange=_this$props.onChange,className=_this$props.className,errorText=_this$props.errorText,translateErrorText=_this$props.translateErrorText,restProps=_objectWithoutProperties(_this$props,_excluded);return/*#__PURE__*/React.createElement(FormElement,{className:"".concat(className," ").concat(style.root," ui-shared__form__checkbox"),htmlFor:name,errorText:errorText,translateErrorText:translateErrorText,hasUnderline:false,hasPlaceholder:false},/*#__PURE__*/React.createElement(UICheckbox,_extends({},restProps,{name:name,onCheck:onChange,checkedClassName:"".concat(className," ").concat(style.checked),unCheckedClassName:className,labelPosition:"right",label:/*#__PURE__*/React.createElement("div",{className:classNames(style.labelWrapper,'label')},/*#__PURE__*/React.createElement(I18n.Text,{className:style.label,string:label}))})));}}]);return Checkbox;}(PureComponent);_defineProperty(Checkbox,"defaultProps",{className:'',defaultChecked:undefined,errorText:'',label:'',onChange:function onChange(){},translateErrorText:true});export default Checkbox;
|
package/Form/Password/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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 ToggleIcon from"../../ToggleIcon";import VisibilityIcon from"../../icons/VisibilityIcon";import VisibilityOffIcon from"../../icons/VisibilityOffIcon";import TextField from"../TextField";import style from"./style";/**
|
|
2
2
|
* A component that provides a password field with visibility toggle.
|
|
3
|
-
*/var Password=/*#__PURE__*/function(_Component){_inherits(Password,_Component);/**
|
|
3
|
+
*/var Password=/*#__PURE__*/function(_Component){_inherits(Password,_Component);var _super=_createSuper(Password);/**
|
|
4
4
|
* Initializes the component.
|
|
5
5
|
* @param {Object} props The components props.
|
|
6
|
-
*/function Password(props){var _this;_classCallCheck(this,Password);_this=
|
|
6
|
+
*/function Password(props){var _this;_classCallCheck(this,Password);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"togglePasswordVisibility",function(isVisible){_this.setState({isVisible:isVisible});});_this.state={isVisible:false};return _this;}/**
|
|
7
7
|
* @param {boolean} isVisible The next isVisible state.
|
|
8
|
-
*/_createClass(Password,[{key:"render"
|
|
8
|
+
*/_createClass(Password,[{key:"render",value:/**
|
|
9
9
|
* @return {*}
|
|
10
|
-
*/
|
|
10
|
+
*/function render(){var isVisible=this.state.isVisible;return/*#__PURE__*/React.createElement(TextField,_extends({},this.props,{className:"ui-shared__form__password ".concat(this.props.className),rightElement:/*#__PURE__*/React.createElement(ToggleIcon,{on:isVisible,onIcon:/*#__PURE__*/React.createElement(VisibilityIcon,{size:24}),offIcon:/*#__PURE__*/React.createElement(VisibilityOffIcon,{size:24,className:style.visOff}),toggleHandler:this.togglePasswordVisibility}),type:isVisible?'text':'password'}));}}]);return Password;}(Component);export default Password;
|
package/Form/Password/spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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);}import React from'react';import{mount}from'enzyme';import Password from"./index";var inputProps={name:'test-input'};describe('<Password>',function(){it('should render a password field',function(){var wrapper=mount(React.createElement(Password,inputProps));expect(wrapper).toMatchSnapshot();expect(wrapper.find('input[type="password"]').length).toBe(1);});it('should trigger the onChange callback',function(){var onChangeMock=jest.fn();var wrapper=mount(React.createElement(Password,_extends({},inputProps,{onChange:onChangeMock})));wrapper.find('input').simulate('change',{target:{value:'a'}});expect(wrapper).toMatchSnapshot();expect(onChangeMock.mock.calls.length).toBe(2);});it('should toggle password visibility',function(){var wrapper=mount(React.createElement(Password,inputProps));var input=wrapper.find('ToggleIcon');expect(wrapper.find('input[type="password"]').length).toBe(1);input.simulate('click');expect(wrapper.find('input[type="text"]').length).toBe(1);});});
|
|
1
|
+
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);}import React from'react';import{mount}from'enzyme';import Password from"./index";var inputProps={name:'test-input'};describe('<Password>',function(){it('should render a password field',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Password,inputProps));expect(wrapper).toMatchSnapshot();expect(wrapper.find('input[type="password"]').length).toBe(1);});it('should trigger the onChange callback',function(){var onChangeMock=jest.fn();var wrapper=mount(/*#__PURE__*/React.createElement(Password,_extends({},inputProps,{onChange:onChangeMock})));wrapper.find('input').simulate('change',{target:{value:'a'}});expect(wrapper).toMatchSnapshot();expect(onChangeMock.mock.calls.length).toBe(2);});it('should toggle password visibility',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Password,inputProps));var input=wrapper.find('ToggleIcon');expect(wrapper.find('input[type="password"]').length).toBe(1);input.simulate('click');expect(wrapper.find('input[type="text"]').length).toBe(1);});});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
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);}import _camelCase from"lodash/camelCase";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 classNames from'classnames';import CheckedIcon from'@shopgate/pwa-ui-shared/icons/RadioCheckedIcon';import UncheckedIcon from'@shopgate/pwa-ui-shared/icons/RadioUncheckedIcon';import I18n from'@shopgate/pwa-common/components/I18n';import style from"./style";/**
|
|
2
2
|
* RadioItem component.
|
|
3
|
-
*/var RadioItem=/*#__PURE__*/function(_PureComponent){_inherits(RadioItem,_PureComponent);function RadioItem(){_classCallCheck(this,RadioItem);return
|
|
3
|
+
*/var RadioItem=/*#__PURE__*/function(_PureComponent){_inherits(RadioItem,_PureComponent);var _super=_createSuper(RadioItem);function RadioItem(){_classCallCheck(this,RadioItem);return _super.apply(this,arguments);}_createClass(RadioItem,[{key:"render",value:/**
|
|
4
4
|
* Renders the component.
|
|
5
5
|
* @returns {JSX}
|
|
6
|
-
*/});export default RadioItem;
|
|
6
|
+
*/function render(){var _this$props=this.props,label=_this$props.label,name=_this$props.name,onChange=_this$props.onChange,checked=_this$props.checked;return/*#__PURE__*/React.createElement("label",{className:classNames(style.container,_camelCase(name),'radioItem'),htmlFor:this.key},checked&&/*#__PURE__*/React.createElement(CheckedIcon,{className:classNames(style.active,style.icon,'checkedIcon')}),!checked&&/*#__PURE__*/React.createElement(UncheckedIcon,{className:classNames(style.icon,'uncheckedIcon')}),/*#__PURE__*/React.createElement("input",{className:classNames(style.input,'input'),checked:checked,type:"radio",name:name,onChange:onChange}),/*#__PURE__*/React.createElement(I18n.Text,{className:classNames(style.label,'label'),string:label}));}}]);return RadioItem;}(PureComponent);_defineProperty(RadioItem,"defaultProps",{checked:false,onChange:function onChange(){}});export default RadioItem;
|
package/Form/RadioGroup/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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,Children,cloneElement}from'react';import PropTypes from'prop-types';import classNames from'classnames';import FormElement from'@shopgate/pwa-ui-shared/FormElement';import style from"./style";/**
|
|
2
2
|
* RadioGroup component.
|
|
3
|
-
*/var RadioGroup=/*#__PURE__*/function(_Component){_inherits(RadioGroup,_Component);
|
|
3
|
+
*/var RadioGroup=/*#__PURE__*/function(_Component){_inherits(RadioGroup,_Component);var _super=_createSuper(RadioGroup);/**
|
|
4
|
+
* Initializes the component.
|
|
5
|
+
* @param {Object} props The components props.
|
|
6
|
+
*/function RadioGroup(props){var _this;_classCallCheck(this,RadioGroup);_this=_super.call(this,props);_defineProperty(_assertThisInitialized(_this),"handleChange",function(_ref){var name=_ref.target.name;if(!_this.props.isControlled){_this.setState({value:name});}_this.props.onChange(name);});_this.state={value:props.value};return _this;}/**
|
|
4
7
|
* @param {Object} nextProps props
|
|
5
8
|
*/_createClass(RadioGroup,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isControlled&&this.state.value!==nextProps.value){this.setState({value:nextProps.value});}}/**
|
|
6
9
|
* @param {string} event click from radio element
|
|
7
|
-
*/},{key:"render"
|
|
10
|
+
*/},{key:"render",value:/**
|
|
8
11
|
* Renders the component.
|
|
9
12
|
* @returns {JSX}
|
|
10
|
-
*/
|
|
11
|
-
* Initializes the component.
|
|
12
|
-
* @param {Object} props The components props.
|
|
13
|
-
*/});export default RadioGroup;
|
|
13
|
+
*/function render(){var _this2=this;var _this$props=this.props,children=_this$props.children,label=_this$props.label,errorText=_this$props.errorText,direction=_this$props.direction,name=_this$props.name,translateErrorText=_this$props.translateErrorText;return/*#__PURE__*/React.createElement(FormElement,{className:"ui-shared__form__radio-group",label:label,errorText:errorText,translateErrorText:translateErrorText,htmlFor:"none",hasUnderline:false,hasValue:true},/*#__PURE__*/React.createElement("div",{className:classNames(style.container(direction),'radioGroup')},Children.map(children,function(child){return/*#__PURE__*/cloneElement(child,{key:"".concat(name,"_").concat(child.props.name),checked:_this2.state.value===child.props.name,onChange:_this2.handleChange});})));}}]);return RadioGroup;}(Component);_defineProperty(RadioGroup,"defaultProps",{onChange:function onChange(){},children:null,direction:'column',errorText:'',isControlled:false,label:'',translateErrorText:true,value:null});export default RadioGroup;
|
package/Form/RadioGroup/spec.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
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 _typeof(obj){
|
|
1
|
+
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 _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);}import React from'react';import{mount}from'enzyme';import RadioItem from"./components/Item";import RadioGroup from'.';var defProps={name:'radio'};describe('<RadioGroup />',function(){it('should render empty group',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,defProps));expect(wrapper).toMatchSnapshot();});it('should render column group with items',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,defProps,/*#__PURE__*/React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);expect(_typeof(wrapper.find(RadioItem).prop('onChange'))).toEqual('function');});it('should render rows group with items',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,_extends({},defProps,{direction:"rows"}),/*#__PURE__*/React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();});it('should use default value',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,_extends({},defProps,{value:"foo"}),/*#__PURE__*/React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);expect(wrapper.find(RadioItem).prop('checked')).toEqual(true);});it('should have on value at a time',function(){var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,defProps,/*#__PURE__*/React.createElement(RadioItem,{name:"foo",label:"foo"}),/*#__PURE__*/React.createElement(RadioItem,{name:"bar",label:"bar"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(2);var radio1=wrapper.find(RadioItem).at(0).find('input');var radio2=wrapper.find(RadioItem).at(1).find('input');// First element value
|
|
2
2
|
radio1.simulate('change');wrapper.update();expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(true);expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(false);// Second element value
|
|
3
|
-
radio2.simulate('change');wrapper.update();expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);});it('should call onChange callback',function(){var onChange=jest.fn();var wrapper=mount(React.createElement(RadioGroup,_extends({},defProps,{onChange:onChange})
|
|
3
|
+
radio2.simulate('change');wrapper.update();expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);});it('should call onChange callback',function(){var onChange=jest.fn();var wrapper=mount(/*#__PURE__*/React.createElement(RadioGroup,_extends({},defProps,{onChange:onChange}),/*#__PURE__*/React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);var radio=wrapper.find(RadioItem).at(0).find('input');radio.simulate('change');expect(onChange).toHaveBeenCalledWith('foo');});});
|