@shopgate/pwa-ui-shared 7.30.0-alpha.10 → 7.30.0-alpha.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 +17 -11
- package/AccordionContainer/spec.js +12 -3
- package/ActionButton/index.js +47 -33
- package/ActionButton/spec.js +5 -1
- package/AddToCartButton/index.js +44 -33
- package/AddToCartButton/mock.js +20 -8
- package/AddToCartButton/spec.js +4 -3
- package/Availability/index.js +5 -3
- package/Availability/spec.js +6 -5
- package/Button/index.js +73 -58
- package/Button/spec.js +16 -10
- package/ButtonLink/index.js +20 -12
- package/ButtonLink/spec.js +5 -3
- package/Card/index.js +5 -3
- package/CardList/components/Item/index.js +5 -3
- package/CardList/index.js +21 -12
- package/CartTotalLine/components/Amount/index.js +10 -8
- package/CartTotalLine/components/Hint/index.js +7 -5
- package/CartTotalLine/components/Label/index.js +12 -10
- package/CartTotalLine/components/Spacer/index.js +5 -3
- package/CartTotalLine/index.js +5 -3
- package/Checkbox/index.js +6 -5
- package/Chip/index.js +28 -22
- package/Chip/spec.js +9 -6
- package/ContextMenu/ContextMenuProvider.js +5 -3
- package/ContextMenu/components/Item/index.js +14 -11
- package/ContextMenu/components/Position/index.js +20 -12
- package/ContextMenu/index.js +54 -44
- package/ContextMenu/spec.js +31 -20
- package/Dialog/components/HtmlContentDialog/index.js +9 -7
- package/Dialog/components/HtmlContentDialog/spec.js +9 -6
- package/Dialog/components/PipelineErrorDialog/index.js +106 -47
- package/Dialog/components/PipelineErrorDialog/spec.js +5 -4
- package/Dialog/components/TextMessageDialog/index.js +9 -7
- package/Dialog/components/TextMessageDialog/spec.js +9 -6
- package/Dialog/components/VariantSelectModal/index.js +7 -5
- package/Dialog/components/VariantSelectModal/spec.js +6 -3
- package/Dialog/index.js +12 -8
- package/Dialog/spec.js +7 -6
- package/DiscountBadge/index.js +10 -8
- package/DiscountBadge/spec.js +3 -2
- package/FavoritesButton/index.js +40 -31
- package/FavoritesButton/spec.js +7 -3
- package/Form/Builder/classes/ActionListener/index.js +400 -401
- package/Form/Builder/components/CheckboxElement.js +13 -5
- package/Form/Builder/components/CountryElement.js +13 -5
- package/Form/Builder/components/ProvinceElement.js +13 -5
- package/Form/Builder/components/RadioElement.js +19 -11
- package/Form/Builder/components/SelectElement.js +26 -16
- package/Form/Builder/components/TextElement.js +13 -5
- package/Form/Builder/index.js +70 -60
- package/Form/Builder/spec.js +10 -9
- package/Form/Checkbox/index.js +31 -21
- package/Form/InfoField/index.js +19 -12
- package/Form/InfoField/spec.js +4 -1
- package/Form/Password/index.js +22 -15
- package/Form/Password/spec.js +10 -5
- package/Form/RadioGroup/components/Item/index.js +34 -25
- package/Form/RadioGroup/index.js +37 -28
- package/Form/RadioGroup/spec.js +45 -31
- package/Form/Select/index.js +52 -43
- package/Form/Select/spec.js +5 -2
- package/Form/SelectContextChoices/index.js +26 -22
- package/Form/SelectContextChoices/spec.js +4 -1
- package/Form/TextField/index.js +40 -27
- package/Form/TextField/spec.js +34 -21
- package/Form/index.js +23 -15
- package/FormElement/components/ErrorText/index.js +7 -5
- package/FormElement/components/Label/index.js +6 -4
- package/FormElement/components/Placeholder/index.js +7 -5
- package/FormElement/components/Underline/index.js +8 -6
- package/FormElement/index.js +62 -46
- package/FormElement/spec.js +10 -9
- package/Glow/index.js +30 -22
- package/Glow/spec.js +6 -1
- package/IndicatorCircle/index.js +10 -8
- package/IndicatorCircle/spec.js +3 -2
- package/LoadingIndicator/index.js +8 -6
- package/Manufacturer/index.js +9 -7
- package/MessageBar/index.js +20 -17
- package/MessageBar/spec.js +6 -5
- package/NoResults/components/Icon/index.js +134 -110
- package/NoResults/index.js +27 -21
- package/Placeholder/index.js +13 -5
- package/PlaceholderLabel/index.js +2 -1
- package/PlaceholderLabel/spec.js +13 -6
- package/PlaceholderParagraph/index.js +13 -12
- package/PlaceholderParagraph/spec.js +13 -6
- package/Price/index.js +46 -28
- package/PriceInfo/index.js +2 -1
- package/PriceStriked/index.js +41 -29
- package/ProductProperties/index.js +13 -10
- package/ProgressBar/index.js +28 -19
- package/ProgressBar/spec.js +2 -1
- package/RadioButton/index.js +6 -5
- package/RadioButton/spec.js +3 -2
- package/RatingNumber/index.js +2 -1
- package/RatingStars/index.js +50 -34
- package/RatingStars/spec.js +7 -6
- package/Ripple/components/RippleAnimation/index.js +12 -10
- package/Ripple/index.js +72 -62
- package/RippleButton/index.js +44 -27
- package/RippleButton/spec.js +20 -13
- package/ScannerOverlay/components/CameraOverlay/index.js +8 -5
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +25 -21
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +7 -5
- package/ScannerOverlay/components/ScannerBar/index.js +17 -12
- package/ScannerOverlay/index.js +24 -15
- package/Sheet/components/Header/components/SearchBar/index.js +35 -28
- package/Sheet/components/Header/components/SearchBar/spec.js +2 -1
- package/Sheet/components/Header/index.js +47 -34
- package/Sheet/components/Header/spec.js +2 -1
- package/Sheet/index.js +80 -65
- package/Sheet/spec.js +27 -14
- package/TaxDisclaimer/index.js +13 -10
- package/TaxDisclaimer/spec.js +3 -2
- package/TextField/components/ErrorText/index.js +7 -5
- package/TextField/components/FormElement/index.js +4 -3
- package/TextField/components/Hint/index.js +7 -5
- package/TextField/components/Label/index.js +6 -4
- package/TextField/components/Underline/index.js +8 -6
- package/TextField/index.js +102 -85
- package/TextField/spec.js +37 -23
- package/ToggleIcon/index.js +23 -15
- package/ToggleIcon/spec.js +12 -8
- package/icons/AccountBoxIcon.js +5 -4
- package/icons/AddMoreIcon.js +5 -4
- package/icons/ArrowDropIcon.js +5 -4
- package/icons/ArrowIcon.js +5 -4
- package/icons/BarcodeScannerIcon.js +5 -4
- package/icons/BoxIcon.js +5 -4
- package/icons/BrowseIcon.js +5 -4
- package/icons/BurgerIcon.js +5 -4
- package/icons/CalendarIcon.js +5 -5
- package/icons/CartCouponIcon.js +5 -4
- package/icons/CartIcon.js +5 -4
- package/icons/CartPlusIcon.js +5 -4
- package/icons/CheckIcon.js +5 -4
- package/icons/CheckedIcon.js +5 -4
- package/icons/ChevronIcon.js +5 -4
- package/icons/CreditCardIcon.js +5 -4
- package/icons/CrossIcon.js +5 -4
- package/icons/DescriptionIcon.js +5 -4
- package/icons/FilterIcon.js +5 -4
- package/icons/FlashDisabledIcon.js +5 -4
- package/icons/FlashEnabledIcon.js +5 -4
- package/icons/GridIcon.js +5 -4
- package/icons/HeartIcon.js +5 -4
- package/icons/HeartOutlineIcon.js +5 -4
- package/icons/HeartPlusIcon.js +5 -4
- package/icons/HeartPlusOutlineIcon.js +5 -4
- package/icons/HomeIcon.js +5 -4
- package/icons/InfoIcon.js +5 -4
- package/icons/InfoOutlineIcon.js +5 -4
- package/icons/ListIcon.js +5 -4
- package/icons/LocalShippingIcon.js +5 -4
- package/icons/LocationIcon.js +5 -4
- package/icons/LocatorIcon.js +5 -4
- package/icons/LockIcon.js +5 -4
- package/icons/LogoutIcon.js +5 -4
- package/icons/MagnifierIcon.js +5 -4
- package/icons/MapMarkerIcon.js +5 -4
- package/icons/MoreIcon.js +5 -4
- package/icons/MoreVertIcon.js +5 -4
- package/icons/NotificationIcon.js +5 -4
- package/icons/PersonIcon.js +5 -4
- package/icons/PhoneIcon.js +5 -4
- package/icons/PlaceholderIcon.js +5 -4
- package/icons/RadioCheckedIcon.js +5 -4
- package/icons/RadioUncheckedIcon.js +5 -4
- package/icons/SecurityIcon.js +5 -4
- package/icons/ShippingMethodIcon.js +5 -4
- package/icons/ShoppingCartIcon.js +5 -4
- package/icons/SortIcon.js +5 -4
- package/icons/StarHalfIcon.js +5 -4
- package/icons/StarIcon.js +5 -4
- package/icons/StarOutlineIcon.js +5 -4
- package/icons/StopIcon.js +5 -4
- package/icons/TickIcon.js +5 -4
- package/icons/TimeIcon.js +5 -4
- package/icons/TrashIcon.js +5 -4
- package/icons/TrashOutlineIcon.js +5 -4
- package/icons/UncheckedIcon.js +5 -4
- package/icons/ViewListIcon.js +5 -4
- package/icons/VisibilityIcon.js +5 -4
- package/icons/VisibilityOffIcon.js +5 -4
- package/icons/WarningIcon.js +5 -4
- package/package.json +7 -8
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Checkbox from "../../Checkbox";
|
|
@@ -7,11 +8,17 @@ import Checkbox from "../../Checkbox";
|
|
|
7
8
|
* @param {Object} element The data of the element to be rendered
|
|
8
9
|
* @returns {JSX}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
let CheckboxElement = /*#__PURE__*/function (_PureComponent) {
|
|
13
|
+
function CheckboxElement() {
|
|
14
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(CheckboxElement, _PureComponent);
|
|
17
|
+
var _proto = CheckboxElement.prototype;
|
|
11
18
|
/**
|
|
12
19
|
* @returns {JSX}
|
|
13
20
|
*/
|
|
14
|
-
render() {
|
|
21
|
+
_proto.render = function render() {
|
|
15
22
|
const {
|
|
16
23
|
element,
|
|
17
24
|
style,
|
|
@@ -19,7 +26,7 @@ class CheckboxElement extends PureComponent {
|
|
|
19
26
|
value,
|
|
20
27
|
name
|
|
21
28
|
} = this.props;
|
|
22
|
-
return /*#__PURE__*/
|
|
29
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
23
30
|
name: name,
|
|
24
31
|
errorText: errorText,
|
|
25
32
|
checked: value,
|
|
@@ -28,8 +35,9 @@ class CheckboxElement extends PureComponent {
|
|
|
28
35
|
onChange: element.handleChange,
|
|
29
36
|
translateErrorText: false
|
|
30
37
|
});
|
|
31
|
-
}
|
|
32
|
-
|
|
38
|
+
};
|
|
39
|
+
return CheckboxElement;
|
|
40
|
+
}(PureComponent);
|
|
33
41
|
CheckboxElement.defaultProps = {
|
|
34
42
|
value: false,
|
|
35
43
|
style: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Select from "../../Select";
|
|
@@ -7,11 +8,17 @@ import Select from "../../Select";
|
|
|
7
8
|
* with a list of countries to select from.
|
|
8
9
|
* @returns {JSX}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
let CountryElement = /*#__PURE__*/function (_PureComponent) {
|
|
13
|
+
function CountryElement() {
|
|
14
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(CountryElement, _PureComponent);
|
|
17
|
+
var _proto = CountryElement.prototype;
|
|
11
18
|
/**
|
|
12
19
|
* @returns {JSX}
|
|
13
20
|
*/
|
|
14
|
-
render() {
|
|
21
|
+
_proto.render = function render() {
|
|
15
22
|
const {
|
|
16
23
|
countryList,
|
|
17
24
|
element,
|
|
@@ -20,7 +27,7 @@ class CountryElement extends PureComponent {
|
|
|
20
27
|
style,
|
|
21
28
|
value
|
|
22
29
|
} = this.props;
|
|
23
|
-
return /*#__PURE__*/
|
|
30
|
+
return /*#__PURE__*/_jsx(Select, {
|
|
24
31
|
name: name,
|
|
25
32
|
className: style.fields,
|
|
26
33
|
label: element.label,
|
|
@@ -32,8 +39,9 @@ class CountryElement extends PureComponent {
|
|
|
32
39
|
isControlled: true,
|
|
33
40
|
translateErrorText: false
|
|
34
41
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
42
|
+
};
|
|
43
|
+
return CountryElement;
|
|
44
|
+
}(PureComponent);
|
|
37
45
|
CountryElement.defaultProps = {
|
|
38
46
|
countryList: {},
|
|
39
47
|
value: '',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Select from "../../Select";
|
|
@@ -7,11 +8,17 @@ import Select from "../../Select";
|
|
|
7
8
|
* with a list of provinces to select from.
|
|
8
9
|
* @returns {JSX}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
let ProvinceElement = /*#__PURE__*/function (_PureComponent) {
|
|
13
|
+
function ProvinceElement() {
|
|
14
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(ProvinceElement, _PureComponent);
|
|
17
|
+
var _proto = ProvinceElement.prototype;
|
|
11
18
|
/**
|
|
12
19
|
* @returns {JSX}
|
|
13
20
|
*/
|
|
14
|
-
render() {
|
|
21
|
+
_proto.render = function render() {
|
|
15
22
|
const {
|
|
16
23
|
provincesList,
|
|
17
24
|
element,
|
|
@@ -20,7 +27,7 @@ class ProvinceElement extends PureComponent {
|
|
|
20
27
|
style,
|
|
21
28
|
value
|
|
22
29
|
} = this.props;
|
|
23
|
-
return /*#__PURE__*/
|
|
30
|
+
return /*#__PURE__*/_jsx(Select, {
|
|
24
31
|
name: name,
|
|
25
32
|
className: style.fields,
|
|
26
33
|
label: element.label,
|
|
@@ -32,8 +39,9 @@ class ProvinceElement extends PureComponent {
|
|
|
32
39
|
isControlled: true,
|
|
33
40
|
translateErrorText: false
|
|
34
41
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
42
|
+
};
|
|
43
|
+
return ProvinceElement;
|
|
44
|
+
}(PureComponent);
|
|
37
45
|
ProvinceElement.defaultProps = {
|
|
38
46
|
provincesList: {},
|
|
39
47
|
value: '',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import RadioGroup from "../../RadioGroup";
|
|
@@ -8,11 +9,17 @@ import RadioItem from "../../RadioGroup/components/Item";
|
|
|
8
9
|
* with a list of radio items.
|
|
9
10
|
* @returns {JSX}
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
let RadioElement = /*#__PURE__*/function (_PureComponent) {
|
|
14
|
+
function RadioElement() {
|
|
15
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
16
|
+
}
|
|
17
|
+
_inheritsLoose(RadioElement, _PureComponent);
|
|
18
|
+
var _proto = RadioElement.prototype;
|
|
12
19
|
/**
|
|
13
20
|
* @returns {JSX}
|
|
14
21
|
*/
|
|
15
|
-
render() {
|
|
22
|
+
_proto.render = function render() {
|
|
16
23
|
const {
|
|
17
24
|
element,
|
|
18
25
|
errorText,
|
|
@@ -20,7 +27,7 @@ class RadioElement extends PureComponent {
|
|
|
20
27
|
style,
|
|
21
28
|
value
|
|
22
29
|
} = this.props;
|
|
23
|
-
return /*#__PURE__*/
|
|
30
|
+
return /*#__PURE__*/_jsx(RadioGroup, {
|
|
24
31
|
name: name,
|
|
25
32
|
className: style.fields,
|
|
26
33
|
label: element.label,
|
|
@@ -28,14 +35,15 @@ class RadioElement extends PureComponent {
|
|
|
28
35
|
onChange: element.handleChange,
|
|
29
36
|
errorText: errorText,
|
|
30
37
|
isControlled: true,
|
|
31
|
-
translateErrorText: false
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
38
|
+
translateErrorText: false,
|
|
39
|
+
children: Object.keys(element.options).map(itemName => /*#__PURE__*/_jsx(RadioItem, {
|
|
40
|
+
name: itemName,
|
|
41
|
+
label: element.options[itemName]
|
|
42
|
+
}, itemName))
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return RadioElement;
|
|
46
|
+
}(PureComponent);
|
|
39
47
|
RadioElement.defaultProps = {
|
|
40
48
|
value: '',
|
|
41
49
|
style: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent, Fragment } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Chevron from "../../../icons/CheckIcon";
|
|
@@ -7,11 +8,17 @@ import Select from "../../Select";
|
|
|
7
8
|
* React component that takes the element and additional data and renders a configured select box.
|
|
8
9
|
* @returns {JSX}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
let SelectElement = /*#__PURE__*/function (_PureComponent) {
|
|
13
|
+
function SelectElement() {
|
|
14
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(SelectElement, _PureComponent);
|
|
17
|
+
var _proto = SelectElement.prototype;
|
|
11
18
|
/**
|
|
12
19
|
* @returns {JSX}
|
|
13
20
|
*/
|
|
14
|
-
render() {
|
|
21
|
+
_proto.render = function render() {
|
|
15
22
|
const {
|
|
16
23
|
element,
|
|
17
24
|
errorText,
|
|
@@ -19,20 +26,23 @@ class SelectElement extends PureComponent {
|
|
|
19
26
|
style,
|
|
20
27
|
value
|
|
21
28
|
} = this.props;
|
|
22
|
-
return /*#__PURE__*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
29
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
30
|
+
children: [/*#__PURE__*/_jsx(Select, {
|
|
31
|
+
name: name,
|
|
32
|
+
className: style.fields,
|
|
33
|
+
label: element.label,
|
|
34
|
+
placeholder: element.placeholder,
|
|
35
|
+
value: value,
|
|
36
|
+
options: element.options,
|
|
37
|
+
onChange: element.handleChange,
|
|
38
|
+
errorText: errorText,
|
|
39
|
+
isControlled: true,
|
|
40
|
+
translateErrorText: false
|
|
41
|
+
}), /*#__PURE__*/_jsx(Chevron, {})]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
return SelectElement;
|
|
45
|
+
}(PureComponent);
|
|
36
46
|
SelectElement.defaultProps = {
|
|
37
47
|
value: '',
|
|
38
48
|
style: {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import TextField from "../../../TextField";
|
|
4
5
|
import { ELEMENT_TYPE_TEXT, ELEMENT_TYPE_NUMBER, ELEMENT_TYPE_EMAIL, ELEMENT_TYPE_PASSWORD, ELEMENT_TYPE_DATE, ELEMENT_TYPE_PHONE } from "../elementTypes";
|
|
5
6
|
|
|
6
7
|
// Map element type to input type
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
9
|
const mapping = {
|
|
8
10
|
[ELEMENT_TYPE_TEXT]: 'text',
|
|
9
11
|
[ELEMENT_TYPE_NUMBER]: 'number',
|
|
@@ -16,11 +18,16 @@ const mapping = {
|
|
|
16
18
|
/**
|
|
17
19
|
* React component that takes the element and additional data and renders a configured text input.
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
let TextElement = /*#__PURE__*/function (_PureComponent) {
|
|
22
|
+
function TextElement() {
|
|
23
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
24
|
+
}
|
|
25
|
+
_inheritsLoose(TextElement, _PureComponent);
|
|
26
|
+
var _proto = TextElement.prototype;
|
|
20
27
|
/**
|
|
21
28
|
* @returns {JSX}
|
|
22
29
|
*/
|
|
23
|
-
render() {
|
|
30
|
+
_proto.render = function render() {
|
|
24
31
|
const {
|
|
25
32
|
element,
|
|
26
33
|
errorText,
|
|
@@ -29,7 +36,7 @@ class TextElement extends PureComponent {
|
|
|
29
36
|
value
|
|
30
37
|
} = this.props;
|
|
31
38
|
const type = mapping[element.type];
|
|
32
|
-
return /*#__PURE__*/
|
|
39
|
+
return /*#__PURE__*/_jsx(TextField, {
|
|
33
40
|
type: type,
|
|
34
41
|
name: name,
|
|
35
42
|
className: style.fields,
|
|
@@ -40,8 +47,9 @@ class TextElement extends PureComponent {
|
|
|
40
47
|
isControlled: true,
|
|
41
48
|
translateErrorText: false
|
|
42
49
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
50
|
+
};
|
|
51
|
+
return TextElement;
|
|
52
|
+
}(PureComponent);
|
|
45
53
|
TextElement.defaultProps = {
|
|
46
54
|
value: '',
|
|
47
55
|
style: {
|
package/Form/Builder/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import _isEqual from "lodash/isEqual";
|
|
2
3
|
import "core-js/modules/es.string.replace.js";
|
|
3
4
|
import React, { Component, Fragment } from 'react';
|
|
@@ -26,6 +27,7 @@ import buildValidationErrorList from "./builders/buildValidationErrorList";
|
|
|
26
27
|
* @param {string} s The string to be sanitized
|
|
27
28
|
* @return {string}
|
|
28
29
|
*/
|
|
30
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
31
|
const sanitize = s => s.replace(/[\\._]/, '-');
|
|
30
32
|
/**
|
|
31
33
|
* Optional select element
|
|
@@ -39,13 +41,14 @@ const emptySelectOption = {
|
|
|
39
41
|
* Takes a form configuration and handles rendering and updates of the form fields.
|
|
40
42
|
* Note: Only one country and one province element is supported per FormBuilder instance.
|
|
41
43
|
*/
|
|
42
|
-
|
|
44
|
+
let Builder = /*#__PURE__*/function (_Component) {
|
|
43
45
|
/**
|
|
44
46
|
* Initializes the component.
|
|
45
47
|
* @param {Object} props The components props.
|
|
46
48
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
function Builder(props) {
|
|
50
|
+
var _this;
|
|
51
|
+
_this = _Component.call(this, props) || this;
|
|
49
52
|
|
|
50
53
|
// Prepare internal state
|
|
51
54
|
/**
|
|
@@ -58,7 +61,7 @@ class Builder extends Component {
|
|
|
58
61
|
* @param {FormElement} element2 Second element
|
|
59
62
|
* @returns {number}
|
|
60
63
|
*/
|
|
61
|
-
|
|
64
|
+
_this.elementSortFunc = (element1, element2) => {
|
|
62
65
|
// Keep current sort order when no specific sort order was set for both
|
|
63
66
|
if (element1.sortOrder === undefined || element2.sortOrder === undefined) {
|
|
64
67
|
return 0;
|
|
@@ -72,12 +75,12 @@ class Builder extends Component {
|
|
|
72
75
|
* @param {string} elementId Element to create the handler for
|
|
73
76
|
* @param {string} value Element value
|
|
74
77
|
*/
|
|
75
|
-
|
|
78
|
+
_this.elementChangeHandler = (elementId, value) => {
|
|
76
79
|
// Apply value change to new state
|
|
77
80
|
const newState = {
|
|
78
|
-
...
|
|
81
|
+
..._this.state,
|
|
79
82
|
formData: {
|
|
80
|
-
...
|
|
83
|
+
..._this.state.formData,
|
|
81
84
|
[elementId]: value
|
|
82
85
|
}
|
|
83
86
|
};
|
|
@@ -85,20 +88,20 @@ class Builder extends Component {
|
|
|
85
88
|
// Remove validation error message on first change of the element
|
|
86
89
|
Object.keys(newState.errors).forEach(key => {
|
|
87
90
|
// Action listeners might add some again
|
|
88
|
-
if (
|
|
91
|
+
if (_this.state.formData[key] !== newState.formData[key]) {
|
|
89
92
|
delete newState.errors[key];
|
|
90
93
|
}
|
|
91
94
|
});
|
|
92
95
|
const hasBackendValidationErrors = Object.keys(newState.errors).length > 0;
|
|
93
96
|
|
|
94
97
|
// Handle context sensitive functionality by via "action" listener and use the "new" state
|
|
95
|
-
const updatedState =
|
|
98
|
+
const updatedState = _this.actionListener.notify(elementId, _this.state, newState);
|
|
96
99
|
|
|
97
100
|
// TODO: handle frontend validation errors and set "hasErrors" accordingly
|
|
98
101
|
let hasErrors = false;
|
|
99
102
|
|
|
100
103
|
// Check "required" fields for all visible elements and enable rendering on changes
|
|
101
|
-
|
|
104
|
+
_this.formElements.forEach(formElement => {
|
|
102
105
|
if (!updatedState.elementVisibility[formElement.id] || !formElement.required) {
|
|
103
106
|
return;
|
|
104
107
|
}
|
|
@@ -110,11 +113,11 @@ class Builder extends Component {
|
|
|
110
113
|
const hasValidationErrors = hasBackendValidationErrors && hasFrontendValidationErrors;
|
|
111
114
|
|
|
112
115
|
// Handle state internally and send an "onChange" event to parent if this finished
|
|
113
|
-
|
|
116
|
+
_this.setState(updatedState);
|
|
114
117
|
|
|
115
118
|
// Transform to external structure (unavailable ones will be set undefined)
|
|
116
119
|
const updateData = {};
|
|
117
|
-
|
|
120
|
+
_this.formElements.forEach(el => {
|
|
118
121
|
if (el.custom) {
|
|
119
122
|
if (updateData.customAttributes === undefined) {
|
|
120
123
|
updateData.customAttributes = {};
|
|
@@ -126,7 +129,7 @@ class Builder extends Component {
|
|
|
126
129
|
});
|
|
127
130
|
|
|
128
131
|
// Trigger the given update action
|
|
129
|
-
|
|
132
|
+
_this.props.handleUpdate(updateData, hasErrors || hasValidationErrors);
|
|
130
133
|
};
|
|
131
134
|
/**
|
|
132
135
|
* Takes an element of any type and renders it depending on type.
|
|
@@ -134,11 +137,11 @@ class Builder extends Component {
|
|
|
134
137
|
* @param {Object} element The data of the element to be rendered
|
|
135
138
|
* @returns {JSX}
|
|
136
139
|
*/
|
|
137
|
-
|
|
138
|
-
const elementName = `${
|
|
139
|
-
const elementErrorText =
|
|
140
|
-
const elementValue =
|
|
141
|
-
const elementVisible =
|
|
140
|
+
_this.renderElement = element => {
|
|
141
|
+
const elementName = `${_this.props.name}.${element.id}`;
|
|
142
|
+
const elementErrorText = _this.state.errors[element.id] || '';
|
|
143
|
+
const elementValue = _this.state.formData[element.id];
|
|
144
|
+
const elementVisible = _this.state.elementVisibility[element.id] || false;
|
|
142
145
|
if (!elementVisible) {
|
|
143
146
|
return null;
|
|
144
147
|
}
|
|
@@ -155,7 +158,7 @@ class Builder extends Component {
|
|
|
155
158
|
case ELEMENT_TYPE_DATE:
|
|
156
159
|
case ELEMENT_TYPE_PHONE:
|
|
157
160
|
{
|
|
158
|
-
return /*#__PURE__*/
|
|
161
|
+
return /*#__PURE__*/_jsx(TextElement, {
|
|
159
162
|
name: elementName,
|
|
160
163
|
element: element,
|
|
161
164
|
errorText: elementErrorText,
|
|
@@ -164,7 +167,7 @@ class Builder extends Component {
|
|
|
164
167
|
});
|
|
165
168
|
}
|
|
166
169
|
case ELEMENT_TYPE_SELECT:
|
|
167
|
-
return /*#__PURE__*/
|
|
170
|
+
return /*#__PURE__*/_jsx(SelectElement, {
|
|
168
171
|
name: elementName,
|
|
169
172
|
element: element,
|
|
170
173
|
errorText: elementErrorText,
|
|
@@ -172,19 +175,19 @@ class Builder extends Component {
|
|
|
172
175
|
visible: elementVisible
|
|
173
176
|
});
|
|
174
177
|
case ELEMENT_TYPE_COUNTRY:
|
|
175
|
-
return /*#__PURE__*/
|
|
178
|
+
return /*#__PURE__*/_jsx(CountryElement, {
|
|
176
179
|
name: elementName,
|
|
177
180
|
element: element,
|
|
178
181
|
errorText: elementErrorText,
|
|
179
182
|
value: elementValue,
|
|
180
183
|
visible: elementVisible,
|
|
181
|
-
countryList:
|
|
184
|
+
countryList: _this.countryList
|
|
182
185
|
});
|
|
183
186
|
case ELEMENT_TYPE_PROVINCE:
|
|
184
187
|
{
|
|
185
|
-
const countryElement =
|
|
186
|
-
const provincesList = countryElement &&
|
|
187
|
-
return /*#__PURE__*/
|
|
188
|
+
const countryElement = _this.formElements.find(el => el.type === ELEMENT_TYPE_COUNTRY);
|
|
189
|
+
const provincesList = countryElement && _this.state.formData[countryElement.id] ? buildProvinceList(_this.state.formData[countryElement.id], element.required ? null : emptySelectOption) : {};
|
|
190
|
+
return /*#__PURE__*/_jsx(ProvinceElement, {
|
|
188
191
|
name: elementName,
|
|
189
192
|
element: element,
|
|
190
193
|
errorText: elementErrorText,
|
|
@@ -195,7 +198,7 @@ class Builder extends Component {
|
|
|
195
198
|
}
|
|
196
199
|
case ELEMENT_TYPE_RADIO:
|
|
197
200
|
{
|
|
198
|
-
return /*#__PURE__*/
|
|
201
|
+
return /*#__PURE__*/_jsx(RadioElement, {
|
|
199
202
|
name: elementName,
|
|
200
203
|
element: element,
|
|
201
204
|
errorText: elementErrorText,
|
|
@@ -205,7 +208,7 @@ class Builder extends Component {
|
|
|
205
208
|
}
|
|
206
209
|
case ELEMENT_TYPE_CHECKBOX:
|
|
207
210
|
{
|
|
208
|
-
return /*#__PURE__*/
|
|
211
|
+
return /*#__PURE__*/_jsx(CheckboxElement, {
|
|
209
212
|
name: elementName,
|
|
210
213
|
element: element,
|
|
211
214
|
errorText: elementErrorText,
|
|
@@ -221,7 +224,7 @@ class Builder extends Component {
|
|
|
221
224
|
}
|
|
222
225
|
return null;
|
|
223
226
|
};
|
|
224
|
-
|
|
227
|
+
_this.state = {
|
|
225
228
|
elementVisibility: {},
|
|
226
229
|
formData: {},
|
|
227
230
|
// Convert errors structure to direct access errors
|
|
@@ -229,50 +232,53 @@ class Builder extends Component {
|
|
|
229
232
|
};
|
|
230
233
|
|
|
231
234
|
// Reorganize form elements into a structure that can be easily rendered
|
|
232
|
-
const formElements = buildFormElements(props.config,
|
|
235
|
+
const formElements = buildFormElements(props.config, _this.elementChangeHandler);
|
|
233
236
|
// Compute defaults
|
|
234
237
|
const formDefaults = buildFormDefaults(formElements, props.defaults);
|
|
235
238
|
// Assign defaults to state
|
|
236
|
-
|
|
239
|
+
_this.state.formData = formDefaults;
|
|
237
240
|
|
|
238
241
|
// Handle fixed visibilities
|
|
239
242
|
formElements.forEach(element => {
|
|
240
243
|
// Assume as visible except it's explicitly set to "false"
|
|
241
|
-
|
|
244
|
+
_this.state.elementVisibility[element.id] = element.visible !== false;
|
|
242
245
|
});
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
_this.actionListener = new ActionListener(buildProvinceList, formDefaults);
|
|
247
|
+
_this.actionListener.attachAll(formElements);
|
|
245
248
|
|
|
246
249
|
// Sort the elements after attaching action listeners to keep action hierarchy same as creation
|
|
247
|
-
|
|
250
|
+
_this.formElements = formElements.sort(_this.elementSortFunc);
|
|
248
251
|
|
|
249
252
|
// Assemble combined country/province list based on the config element
|
|
250
|
-
const _countryElement =
|
|
253
|
+
const _countryElement = _this.formElements.find(el => el.type === ELEMENT_TYPE_COUNTRY);
|
|
251
254
|
if (_countryElement) {
|
|
252
|
-
|
|
253
|
-
const provinceElement =
|
|
255
|
+
_this.countryList = buildCountryList(_countryElement, emptySelectOption);
|
|
256
|
+
const provinceElement = _this.formElements.find(el => el.type === ELEMENT_TYPE_PROVINCE);
|
|
254
257
|
if (provinceElement && provinceElement.required && !!formDefaults[_countryElement.id] && !formDefaults[provinceElement.id]) {
|
|
255
258
|
// Set default for province field for given country
|
|
256
259
|
const [first] = Object.values(buildProvinceList(formDefaults[_countryElement.id]));
|
|
257
260
|
if (first) {
|
|
258
|
-
|
|
261
|
+
_this.state.formData[provinceElement.id] = first;
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
// Final form initialization, by triggering actionListeners and enable rendering for elements
|
|
264
|
-
let _newState =
|
|
265
|
-
|
|
266
|
-
_newState =
|
|
267
|
+
let _newState = _this.state;
|
|
268
|
+
_this.formElements.forEach(element => {
|
|
269
|
+
_newState = _this.actionListener.notify(element.id, _this.state, _newState);
|
|
267
270
|
});
|
|
268
|
-
|
|
271
|
+
_this.state = _newState;
|
|
272
|
+
return _this;
|
|
269
273
|
}
|
|
270
274
|
|
|
271
275
|
/**
|
|
272
276
|
* Handles response of validation errors
|
|
273
277
|
* @param {Object} nextProps The new props object with changed data
|
|
274
278
|
*/
|
|
275
|
-
|
|
279
|
+
_inheritsLoose(Builder, _Component);
|
|
280
|
+
var _proto = Builder.prototype;
|
|
281
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
276
282
|
const oldValidationErrors = buildValidationErrorList(this.props.validationErrors);
|
|
277
283
|
const newValidationErrors = buildValidationErrorList(nextProps.validationErrors);
|
|
278
284
|
if (!_isEqual(oldValidationErrors, newValidationErrors)) {
|
|
@@ -280,27 +286,31 @@ class Builder extends Component {
|
|
|
280
286
|
errors: newValidationErrors
|
|
281
287
|
});
|
|
282
288
|
}
|
|
283
|
-
}
|
|
289
|
+
};
|
|
284
290
|
/**
|
|
285
291
|
* Renders the component based on the given config
|
|
286
292
|
* @return {JSX}
|
|
287
293
|
*/
|
|
288
|
-
render() {
|
|
289
|
-
return /*#__PURE__*/
|
|
290
|
-
onSubmit: this.props.onSubmit
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
294
|
+
_proto.render = function render() {
|
|
295
|
+
return /*#__PURE__*/_jsx(Form, {
|
|
296
|
+
onSubmit: this.props.onSubmit,
|
|
297
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
298
|
+
className: this.props.className,
|
|
299
|
+
children: this.formElements.map(element => /*#__PURE__*/_jsxs(Fragment, {
|
|
300
|
+
children: [/*#__PURE__*/_jsx(Portal, {
|
|
301
|
+
name: `${sanitize(this.props.name)}.${sanitize(element.id)}.${BEFORE}`
|
|
302
|
+
}), /*#__PURE__*/_jsx(Portal, {
|
|
303
|
+
name: `${sanitize(this.props.name)}.${sanitize(element.id)}`,
|
|
304
|
+
children: this.renderElement(element)
|
|
305
|
+
}), /*#__PURE__*/_jsx(Portal, {
|
|
306
|
+
name: `${sanitize(this.props.name)}.${sanitize(element.id)}.${AFTER}`
|
|
307
|
+
})]
|
|
308
|
+
}, `${this.props.name}.${element.id}`))
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
return Builder;
|
|
313
|
+
}(Component);
|
|
304
314
|
Builder.defaultProps = {
|
|
305
315
|
className: '',
|
|
306
316
|
defaults: {},
|