@configura/web-ui 1.4.0 → 1.6.0-alpha.0

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.
Files changed (96) hide show
  1. package/.postcssrc.json +8 -8
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/components/CanvasWrapper.d.ts +9 -9
  5. package/dist/components/CanvasWrapper.js +8 -8
  6. package/dist/components/CfgPriceView.d.ts +7 -0
  7. package/dist/components/CfgPriceView.js +13 -0
  8. package/dist/components/ConfigurationActionsButtonRow.d.ts +11 -11
  9. package/dist/components/ConfigurationActionsButtonRow.js +13 -13
  10. package/dist/components/Configurator.d.ts +12 -12
  11. package/dist/components/Configurator.js +15 -15
  12. package/dist/components/ConfiguratorWrapper.d.ts +8 -8
  13. package/dist/components/ConfiguratorWrapper.js +5 -5
  14. package/dist/components/CurrencyPrice.d.ts +9 -9
  15. package/dist/components/CurrencyPrice.js +7 -7
  16. package/dist/components/ExpandableHeadingRow.d.ts +15 -15
  17. package/dist/components/ExpandableHeadingRow.js +21 -21
  18. package/dist/components/Loading.d.ts +13 -13
  19. package/dist/components/Loading.js +20 -20
  20. package/dist/components/ProductInformation.d.ts +13 -10
  21. package/dist/components/ProductInformation.js +14 -23
  22. package/dist/components/TaskListView.d.ts +9 -0
  23. package/dist/components/TaskListView.js +54 -0
  24. package/dist/components/TaskStartView.d.ts +13 -0
  25. package/dist/components/TaskStartView.js +22 -0
  26. package/dist/components/icons/Checkmark.d.ts +6 -5
  27. package/dist/components/icons/Checkmark.js +12 -12
  28. package/dist/components/icons/Chevron.d.ts +7 -6
  29. package/dist/components/icons/Chevron.js +18 -18
  30. package/dist/components/icons/CircleXmarkIcon.d.ts +4 -0
  31. package/dist/components/icons/CircleXmarkIcon.js +8 -0
  32. package/dist/components/icons/DownloadIcon.d.ts +4 -0
  33. package/dist/components/icons/DownloadIcon.js +8 -0
  34. package/dist/components/icons/ErrorIcon.d.ts +4 -0
  35. package/dist/components/icons/ErrorIcon.js +8 -0
  36. package/dist/components/productConfiguration/CfgAdditionalProductView.d.ts +3 -3
  37. package/dist/components/productConfiguration/CfgAdditionalProductView.js +38 -28
  38. package/dist/components/productConfiguration/CfgCheckboxView.d.ts +19 -18
  39. package/dist/components/productConfiguration/CfgCheckboxView.js +22 -22
  40. package/dist/components/productConfiguration/CfgCheckboxesView.d.ts +13 -12
  41. package/dist/components/productConfiguration/CfgCheckboxesView.js +19 -18
  42. package/dist/components/productConfiguration/CfgDropdownOptionView.d.ts +19 -18
  43. package/dist/components/productConfiguration/CfgDropdownOptionView.js +36 -35
  44. package/dist/components/productConfiguration/CfgDropdownView.d.ts +13 -12
  45. package/dist/components/productConfiguration/CfgDropdownView.js +21 -20
  46. package/dist/components/productConfiguration/CfgFeatureView.d.ts +29 -27
  47. package/dist/components/productConfiguration/CfgFeatureView.js +36 -34
  48. package/dist/components/productConfiguration/CfgGroupView.d.ts +4 -4
  49. package/dist/components/productConfiguration/CfgGroupView.js +7 -13
  50. package/dist/components/productConfiguration/CfgOptionFeaturesView.d.ts +6 -6
  51. package/dist/components/productConfiguration/CfgOptionFeaturesView.js +13 -13
  52. package/dist/components/productConfiguration/CfgOptionNumericView.d.ts +27 -27
  53. package/dist/components/productConfiguration/CfgOptionNumericView.js +119 -117
  54. package/dist/components/productConfiguration/CfgOptionPriceView.d.ts +9 -9
  55. package/dist/components/productConfiguration/CfgOptionPriceView.js +29 -29
  56. package/dist/components/productConfiguration/CfgProductConfigurationView.d.ts +18 -18
  57. package/dist/components/productConfiguration/CfgProductConfigurationView.js +46 -45
  58. package/dist/css/web-ui.css +1 -1
  59. package/dist/css/web-ui.css.map +1 -1
  60. package/dist/index.d.ts +22 -20
  61. package/dist/index.js +22 -20
  62. package/dist/scss/_button.scss +36 -36
  63. package/dist/scss/_configurator.scss +87 -67
  64. package/dist/scss/_expandable.scss +37 -37
  65. package/dist/scss/_feature-item.scss +137 -124
  66. package/dist/scss/_forms.scss +42 -0
  67. package/dist/scss/_hr.scss +16 -16
  68. package/dist/scss/_loading.scss +98 -98
  69. package/dist/scss/_mixins.scss +56 -56
  70. package/dist/scss/_option-tree.scss +29 -29
  71. package/dist/scss/_product-information.scss +49 -49
  72. package/dist/scss/_range-view.scss +39 -28
  73. package/dist/scss/_slider.scss +70 -70
  74. package/dist/scss/_tasks.scss +72 -0
  75. package/dist/scss/_themed.scss +147 -124
  76. package/dist/scss/_utilities.scss +21 -21
  77. package/dist/scss/_variables.scss +6 -6
  78. package/dist/scss/icons/_checkmark.scss +46 -46
  79. package/dist/scss/icons/_chevron.scss +62 -62
  80. package/dist/scss/icons/_circle-xmark-icon.scss +24 -0
  81. package/dist/scss/icons/_download-icon.scss +24 -0
  82. package/dist/scss/icons/_error-icon.scss +24 -0
  83. package/dist/scss/web-ui.scss +11 -11
  84. package/dist/useObservable.d.ts +4 -4
  85. package/dist/useObservable.js +18 -18
  86. package/dist/useRerender.d.ts +1 -1
  87. package/dist/useRerender.js +5 -5
  88. package/dist/useResize.d.ts +6 -6
  89. package/dist/useResize.js +47 -47
  90. package/dist/useSelected.d.ts +2 -2
  91. package/dist/useSelected.js +13 -13
  92. package/dist/useUniqueId.d.ts +1 -1
  93. package/dist/useUniqueId.js +7 -7
  94. package/dist/utilities.d.ts +5 -5
  95. package/dist/utilities.js +1 -1
  96. package/package.json +3 -3
@@ -1,28 +1,28 @@
1
- import { CfgOption, NumericValueDiscrete, NumericValueRangeDefinition } from "@configura/web-api";
2
- import { LengthUnit } from "@configura/web-utilities";
3
- import React from "react";
4
- import { CssProps } from "../../utilities.js";
5
- export declare const CfgOptionNumericView: React.FC<{
6
- option: CfgOption;
7
- } & CssProps>;
8
- /**
9
- * Displays GUI for selecting in one "range". Please note that the range
10
- * parameter can also be a discrete value.
11
- */
12
- export declare const NumericValueView: React.FC<{
13
- currentValue: number;
14
- unit: LengthUnit;
15
- range: NumericValueRangeDefinition | NumericValueDiscrete;
16
- updateValue: (val: number, commit: boolean) => void;
17
- hasNoSiblings: boolean;
18
- }>;
19
- export declare const RangeView: React.FC<{
20
- currentValue: number;
21
- unit: LengthUnit;
22
- range: NumericValueRangeDefinition;
23
- inputValue: number;
24
- onChange: (val: number, instantUpdate: boolean) => void;
25
- onCommit: () => void;
26
- showRangeError: boolean;
27
- } & CssProps>;
1
+ import { CfgOption, NumericValueDiscrete, NumericValueRangeDefinition } from "@configura/web-api";
2
+ import { LengthUnit } from "@configura/web-utilities";
3
+ import React from "react";
4
+ import { CssProps } from "../../utilities.js";
5
+ export declare const CfgOptionNumericView: React.FC<{
6
+ option: CfgOption;
7
+ } & CssProps>;
8
+ /**
9
+ * Displays GUI for selecting in one "range". Please note that the range
10
+ * parameter can also be a discrete value.
11
+ */
12
+ export declare const NumericValueView: React.FC<{
13
+ currentValue: number;
14
+ unit: LengthUnit;
15
+ range: NumericValueRangeDefinition | NumericValueDiscrete;
16
+ updateValue: (val: number, commit: boolean) => void;
17
+ hasNoSiblings: boolean;
18
+ }>;
19
+ export declare const RangeView: React.FC<{
20
+ currentValue: number;
21
+ unit: LengthUnit;
22
+ range: NumericValueRangeDefinition;
23
+ inputValue: number;
24
+ onChange: (val: number, instantUpdate: boolean) => void;
25
+ onCommit: () => void;
26
+ showRangeError: boolean;
27
+ } & CssProps>;
28
28
  //# sourceMappingURL=CfgOptionNumericView.d.ts.map
@@ -1,117 +1,119 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { NumericValueDiscrete, NumericValueRangeDefinition } from "@configura/web-api";
11
- import React, { useEffect, useState } from "react";
12
- import { useRerender } from "../../useRerender.js";
13
- import { useUuid } from "../../useUniqueId.js";
14
- import { Checkmark } from "../icons/Checkmark.js";
15
- export const CfgOptionNumericView = (props) => {
16
- const { option } = props;
17
- const { isUseNumericValue } = option;
18
- // Contrary to most other components this one has its own connection to the
19
- // option that is backing it. This is for it to be able to "live" update
20
- // as we drag sliders. The value is not "commited" at immediate drag, and so
21
- // the full machinery of validations and such is not run until later.
22
- const rerender = useRerender();
23
- useEffect(() => {
24
- option.listenForChange(rerender);
25
- return () => {
26
- option.stopListenForChange(rerender);
27
- };
28
- }, [option, rerender]);
29
- if (!isUseNumericValue) {
30
- return null;
31
- }
32
- const { allowedNumericValues, numericValue, unit } = option;
33
- if (allowedNumericValues === undefined) {
34
- throw new Error("AllowedNumericValues undefined for numeric option");
35
- }
36
- if (numericValue === undefined) {
37
- throw new Error("Numeric value not set for numeric option");
38
- }
39
- const { ranges } = allowedNumericValues;
40
- const isSingleRange = ranges.length === 1;
41
- if (isSingleRange && ranges[0] instanceof NumericValueDiscrete) {
42
- return null;
43
- }
44
- return (React.createElement("ul", { className: `cfgOptionTree cfgOptionTree--subLevel cfgOptionTree--indent ${props.className || ""}`, style: props.style }, ranges.map((range) => (React.createElement(NumericValueView, { currentValue: numericValue, unit: unit, range: range, key: range.first, hasNoSiblings: isSingleRange, updateValue: (value, commit) => __awaiter(void 0, void 0, void 0, function* () { return yield option.setNumericValue(value, commit); }) })))));
45
- };
46
- /**
47
- * Displays GUI for selecting in one "range". Please note that the range
48
- * parameter can also be a discrete value.
49
- */
50
- export const NumericValueView = (props) => {
51
- const { range, currentValue, updateValue, hasNoSiblings } = props;
52
- const { legend, first } = range;
53
- const selected = range.includesValue(currentValue);
54
- const optionClasses = selected ? "cfgFeatureItemOption--checked" : "";
55
- const uniqueId = useUuid();
56
- const [inputValue, setInputValue] = useState(first);
57
- const [inputCommited, setInputCommited] = useState(true);
58
- const [showRangeError, setShowRangeError] = useState(false);
59
- if (inputCommited && inputValue !== currentValue && range.includesValue(currentValue)) {
60
- setInputValue(currentValue);
61
- }
62
- function isAcceptableValue(value) {
63
- return !isNaN(value) && range.includesValue(value);
64
- }
65
- return (React.createElement("li", { className: `cfgFeatureItem cfgMb1 ${hasNoSiblings ? "" : "cfgMt1"}` },
66
- !hasNoSiblings && (React.createElement("label", { className: `cfgFeatureItemOption ${optionClasses}`, htmlFor: uniqueId },
67
- React.createElement("input", { checked: selected, className: "cfgFeatureItem__hiddenInput", id: uniqueId, name: uniqueId, onChange: (event) => {
68
- if (event.target.checked) {
69
- updateValue(inputValue, true);
70
- }
71
- }, type: "radio", value: first }),
72
- React.createElement("div", { className: "cfgFeatureItem__radio" }, selected && React.createElement(Checkmark, null)),
73
- React.createElement("div", { className: "cfgFeatureItemOption__titleWrapper" },
74
- React.createElement("div", { className: "cfgFeatureItemOption__title" }, legend)))),
75
- selected && range instanceof NumericValueRangeDefinition && (React.createElement(RangeView, Object.assign({}, props, { className: hasNoSiblings ? undefined : "cfgOptionTree--indent", range: range, onChange: (val, instantUpdate) => {
76
- setInputValue(val);
77
- if (!isAcceptableValue(inputValue)) {
78
- return;
79
- }
80
- if (instantUpdate) {
81
- updateValue(val, false);
82
- }
83
- setShowRangeError(false);
84
- setInputCommited(false);
85
- }, onCommit: () => {
86
- if (inputCommited) {
87
- return;
88
- }
89
- if (!isAcceptableValue(inputValue)) {
90
- setShowRangeError(true);
91
- return;
92
- }
93
- updateValue(inputValue, true);
94
- setShowRangeError(false);
95
- setInputCommited(true);
96
- }, inputValue: inputValue, showRangeError: showRangeError })))));
97
- };
98
- export const RangeView = (props) => {
99
- const { currentValue, unit, inputValue, range, onChange, onCommit, showRangeError } = props;
100
- const { minValue, maxValue, increment, legend } = range;
101
- const getOnChange = (instant) => (event) => onChange(event.currentTarget.valueAsNumber, instant);
102
- const inputProps = {
103
- min: minValue,
104
- max: maxValue,
105
- step: increment || Math.pow(10, Math.round(Math.log10(maxValue - minValue)) - 3),
106
- onBlur: onCommit,
107
- onMouseUp: onCommit,
108
- };
109
- return (React.createElement("div", { className: `cfgRangeView cfgMt1 ${props.className || ""}`, style: props.style },
110
- React.createElement("div", { className: "cfgRangeView__inputs" },
111
- React.createElement("input", Object.assign({}, inputProps, { type: "number", value: isNaN(inputValue) ? "" : inputValue, onChange: getOnChange(false), className: "cfgRangeView__number-input" })),
112
- React.createElement("span", { className: "cfgRangeView__unit-label" }, unit),
113
- React.createElement("input", Object.assign({}, inputProps, { type: "range", className: "cfgSlider cfgRangeView__slider-input", value: currentValue, onChange: getOnChange(true) }))),
114
- showRangeError && (React.createElement("div", { className: "cfgRangeView__error" },
115
- "Value not allowed, allowed values are ",
116
- legend))));
117
- };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { NumericValueDiscrete, NumericValueRangeDefinition } from "@configura/web-api";
11
+ import React, { useEffect, useState } from "react";
12
+ import { useRerender } from "../../useRerender.js";
13
+ import { useUuid } from "../../useUniqueId.js";
14
+ import { Checkmark } from "../icons/Checkmark.js";
15
+ import { ErrorIcon } from "../icons/ErrorIcon.js";
16
+ export const CfgOptionNumericView = (props) => {
17
+ const { option } = props;
18
+ const { isUseNumericValue } = option;
19
+ // Contrary to most other components this one has its own connection to the
20
+ // option that is backing it. This is for it to be able to "live" update
21
+ // as we drag sliders. The value is not "commited" at immediate drag, and so
22
+ // the full machinery of validations and such is not run until later.
23
+ const rerender = useRerender();
24
+ useEffect(() => {
25
+ option.listenForChange(rerender);
26
+ return () => {
27
+ option.stopListenForChange(rerender);
28
+ };
29
+ }, [option, rerender]);
30
+ if (!isUseNumericValue) {
31
+ return null;
32
+ }
33
+ const { allowedNumericValues, numericValue, unit } = option;
34
+ if (allowedNumericValues === undefined) {
35
+ throw new Error("AllowedNumericValues undefined for numeric option");
36
+ }
37
+ if (numericValue === undefined) {
38
+ throw new Error("Numeric value not set for numeric option");
39
+ }
40
+ const { ranges } = allowedNumericValues;
41
+ const isSingleRange = ranges.length === 1;
42
+ if (isSingleRange && ranges[0] instanceof NumericValueDiscrete) {
43
+ return null;
44
+ }
45
+ return (React.createElement("ul", { className: `cfgOptionTree cfgOptionTree--subLevel cfgOptionTree--indent ${props.className || ""}`, style: props.style }, ranges.map((range) => (React.createElement(NumericValueView, { currentValue: numericValue, unit: unit, range: range, key: range.first, hasNoSiblings: isSingleRange, updateValue: (value, commit) => __awaiter(void 0, void 0, void 0, function* () { return yield option.setNumericValue(value, commit); }) })))));
46
+ };
47
+ /**
48
+ * Displays GUI for selecting in one "range". Please note that the range
49
+ * parameter can also be a discrete value.
50
+ */
51
+ export const NumericValueView = (props) => {
52
+ const { range, currentValue, updateValue, hasNoSiblings } = props;
53
+ const { legend, first } = range;
54
+ const selected = range.includesValue(currentValue);
55
+ const optionClasses = selected ? "cfgFeatureItemOption--checked" : "";
56
+ const uniqueId = useUuid();
57
+ const [inputValue, setInputValue] = useState(first);
58
+ const [inputCommited, setInputCommited] = useState(true);
59
+ const [showRangeError, setShowRangeError] = useState(false);
60
+ if (inputCommited && inputValue !== currentValue && range.includesValue(currentValue)) {
61
+ setInputValue(currentValue);
62
+ }
63
+ function isAcceptableValue(value) {
64
+ return !isNaN(value) && range.includesValue(value);
65
+ }
66
+ return (React.createElement("li", { className: `cfgFeatureItem cfgMb1 ${hasNoSiblings ? "" : "cfgMt1"}` },
67
+ !hasNoSiblings && (React.createElement("label", { className: `cfgFeatureItemOption ${optionClasses}`, htmlFor: uniqueId },
68
+ React.createElement("input", { checked: selected, className: "cfgFeatureItem__hiddenInput", id: uniqueId, name: uniqueId, onChange: (event) => {
69
+ if (event.target.checked) {
70
+ updateValue(inputValue, true);
71
+ }
72
+ }, type: "radio", value: first }),
73
+ React.createElement("div", { className: "cfgFeatureItem__radio" }, selected && React.createElement(Checkmark, null)),
74
+ React.createElement("div", { className: "cfgFeatureItemOption__titleWrapper" },
75
+ React.createElement("div", { className: "cfgFeatureItemOption__title" }, legend)))),
76
+ selected && range instanceof NumericValueRangeDefinition && (React.createElement(RangeView, Object.assign({}, props, { className: hasNoSiblings ? undefined : "cfgOptionTree--indent", range: range, onChange: (val, instantUpdate) => {
77
+ setInputValue(val);
78
+ if (!isAcceptableValue(inputValue)) {
79
+ return;
80
+ }
81
+ if (instantUpdate) {
82
+ updateValue(val, false);
83
+ }
84
+ setShowRangeError(false);
85
+ setInputCommited(false);
86
+ }, onCommit: () => {
87
+ if (inputCommited) {
88
+ return;
89
+ }
90
+ if (!isAcceptableValue(inputValue)) {
91
+ setShowRangeError(true);
92
+ return;
93
+ }
94
+ updateValue(inputValue, true);
95
+ setShowRangeError(false);
96
+ setInputCommited(true);
97
+ }, inputValue: inputValue, showRangeError: showRangeError })))));
98
+ };
99
+ export const RangeView = (props) => {
100
+ const { currentValue, unit, inputValue, range, onChange, onCommit, showRangeError } = props;
101
+ const { minValue, maxValue, increment, legend } = range;
102
+ const getOnChange = (instant) => (event) => onChange(event.currentTarget.valueAsNumber, instant);
103
+ const inputProps = {
104
+ min: minValue,
105
+ max: maxValue,
106
+ step: increment || Math.pow(10, Math.round(Math.log10(maxValue - minValue)) - 3),
107
+ onBlur: onCommit,
108
+ onMouseUp: onCommit,
109
+ };
110
+ return (React.createElement("div", { className: `cfgRangeView cfgMt1 ${props.className || ""}`, style: props.style },
111
+ React.createElement("div", { className: "cfgRangeView__inputs" },
112
+ React.createElement("input", Object.assign({}, inputProps, { type: "number", value: isNaN(inputValue) ? "" : inputValue, onChange: getOnChange(false), className: "cfgInput cfgRangeView__number-input" })),
113
+ React.createElement("span", { className: "cfgRangeView__unit-label" }, unit),
114
+ React.createElement("input", Object.assign({}, inputProps, { type: "range", className: "cfgSlider cfgRangeView__slider-input", value: currentValue, onChange: getOnChange(true) }))),
115
+ showRangeError && (React.createElement("div", { className: "cfgRangeView__error" },
116
+ React.createElement(ErrorIcon, null),
117
+ " Value not allowed, allowed values are ",
118
+ legend))));
119
+ };
@@ -1,10 +1,10 @@
1
- import { CfgOption } from "@configura/web-api";
2
- import React from "react";
3
- import { UpchargeDisplayMode } from "./CfgProductConfigurationView.js";
4
- declare type Props = {
5
- option: CfgOption;
6
- upchargeDisplayMode: UpchargeDisplayMode | undefined;
7
- };
8
- export declare const CfgOptionPriceView: React.FC<Props>;
9
- export {};
1
+ import { CfgOption } from "@configura/web-api";
2
+ import React from "react";
3
+ import { UpchargeDisplayMode } from "./CfgProductConfigurationView.js";
4
+ declare type Props = {
5
+ option: CfgOption;
6
+ upchargeDisplayMode: UpchargeDisplayMode | undefined;
7
+ };
8
+ export declare const CfgOptionPriceView: React.FC<Props>;
9
+ export {};
10
10
  //# sourceMappingURL=CfgOptionPriceView.d.ts.map
@@ -1,29 +1,29 @@
1
- import React from "react";
2
- import { CurrencyPrice } from "../CurrencyPrice.js";
3
- import { UpchargeDisplayMode } from "./CfgProductConfigurationView.js";
4
- export const CfgOptionPriceView = (props) => {
5
- const { option, upchargeDisplayMode } = props;
6
- const { currency, fractionDigits, lang } = option.parentProduct;
7
- if (currency === "") {
8
- return null;
9
- }
10
- switch (upchargeDisplayMode) {
11
- case UpchargeDisplayMode.None:
12
- return null;
13
- case UpchargeDisplayMode.Price:
14
- const { upcharge } = option;
15
- if (upcharge === undefined || upcharge === 0) {
16
- return null;
17
- }
18
- return (React.createElement("div", { className: "cfgFeatureItemOption__price" },
19
- React.createElement(CurrencyPrice, { currency: currency, language: lang, price: upcharge, fractionDigits: fractionDigits })));
20
- default:
21
- const { priceChangeAtSelectChange } = option;
22
- if (priceChangeAtSelectChange === undefined || priceChangeAtSelectChange === 0) {
23
- return null;
24
- }
25
- return (React.createElement("div", { className: "cfgFeatureItemOption__price" },
26
- priceChangeAtSelectChange < 0 ? "-" : "+",
27
- React.createElement(CurrencyPrice, { currency: currency, language: lang, price: Math.abs(priceChangeAtSelectChange), fractionDigits: fractionDigits })));
28
- }
29
- };
1
+ import React from "react";
2
+ import { CurrencyPrice } from "../CurrencyPrice.js";
3
+ import { UpchargeDisplayMode } from "./CfgProductConfigurationView.js";
4
+ export const CfgOptionPriceView = (props) => {
5
+ const { option, upchargeDisplayMode } = props;
6
+ const { currency, fractionDigits, lang } = option.parentProduct;
7
+ if (currency === "") {
8
+ return null;
9
+ }
10
+ switch (upchargeDisplayMode) {
11
+ case UpchargeDisplayMode.None:
12
+ return null;
13
+ case UpchargeDisplayMode.Price:
14
+ const { upcharge } = option;
15
+ if (upcharge === undefined || upcharge === 0) {
16
+ return null;
17
+ }
18
+ return (React.createElement("div", { className: "cfgFeatureItemOption__price" },
19
+ React.createElement(CurrencyPrice, { currency: currency, language: lang, price: upcharge, fractionDigits: fractionDigits })));
20
+ default:
21
+ const { priceChangeAtSelectChange } = option;
22
+ if (priceChangeAtSelectChange === undefined || priceChangeAtSelectChange === 0) {
23
+ return null;
24
+ }
25
+ return (React.createElement("div", { className: "cfgFeatureItemOption__price" },
26
+ priceChangeAtSelectChange < 0 ? "-" : "+",
27
+ React.createElement(CurrencyPrice, { currency: currency, language: lang, price: Math.abs(priceChangeAtSelectChange), fractionDigits: fractionDigits })));
28
+ }
29
+ };
@@ -1,19 +1,19 @@
1
- import { CfgProduct, CfgProductConfiguration } from "@configura/web-api";
2
- import React from "react";
3
- import { CssProps } from "../../utilities.js";
4
- import { CfgProductConfigurationComponentAndPassthroughProps } from "./CfgFeatureView.js";
5
- export declare enum UpchargeDisplayMode {
6
- SelectionImpact = 0,
7
- None = 1,
8
- Price = 2
9
- }
10
- export declare type PassthroughProps = {
11
- upchargeDisplayMode?: UpchargeDisplayMode;
12
- };
13
- declare type Props = PassthroughProps & {
14
- productOrConfiguration: CfgProductConfiguration | CfgProduct;
15
- permanentlyExpandedAdditionalProductLevels?: number;
16
- };
17
- export declare const CfgProductConfigurationView: React.FC<Props & CfgProductConfigurationComponentAndPassthroughProps & CssProps>;
18
- export {};
1
+ import { CfgProduct, CfgProductConfiguration } from "@configura/web-api";
2
+ import React from "react";
3
+ import { CssProps } from "../../utilities.js";
4
+ import { CfgProductConfigurationComponentAndPassthroughProps } from "./CfgFeatureView.js";
5
+ export declare enum UpchargeDisplayMode {
6
+ SelectionImpact = 0,
7
+ None = 1,
8
+ Price = 2
9
+ }
10
+ export declare type PassthroughProps = {
11
+ upchargeDisplayMode?: UpchargeDisplayMode;
12
+ };
13
+ declare type Props = PassthroughProps & {
14
+ productOrConfiguration: CfgProductConfiguration | CfgProduct;
15
+ permanentlyExpandedAdditionalProductLevels?: number;
16
+ };
17
+ export declare const CfgProductConfigurationView: React.FC<Props & CfgProductConfigurationComponentAndPassthroughProps & CssProps>;
18
+ export {};
19
19
  //# sourceMappingURL=CfgProductConfigurationView.d.ts.map
@@ -1,45 +1,46 @@
1
- import { CfgProduct } from "@configura/web-api";
2
- import React, { useEffect } from "react";
3
- import { useRerender } from "../../useRerender.js";
4
- import { CfgAdditionalProductView } from "./CfgAdditionalProductView.js";
5
- import { CfgFeatureViewMemo, forwardProps, } from "./CfgFeatureView.js";
6
- export var UpchargeDisplayMode;
7
- (function (UpchargeDisplayMode) {
8
- UpchargeDisplayMode[UpchargeDisplayMode["SelectionImpact"] = 0] = "SelectionImpact";
9
- UpchargeDisplayMode[UpchargeDisplayMode["None"] = 1] = "None";
10
- UpchargeDisplayMode[UpchargeDisplayMode["Price"] = 2] = "Price";
11
- })(UpchargeDisplayMode || (UpchargeDisplayMode = {}));
12
- export const CfgProductConfigurationView = React.memo((props) => {
13
- const { productOrConfiguration, permanentlyExpandedAdditionalProductLevels, additionalProductComponent, } = props;
14
- const configuration = productOrConfiguration instanceof CfgProduct
15
- ? productOrConfiguration.configuration
16
- : productOrConfiguration;
17
- const features = configuration.features.reduce((agg, feature) => {
18
- // It is possible in Cat Creator to double add a Feature. This fills no known
19
- // purpose and React can not handle this, so we filter out the duplicates.
20
- const code = feature.code;
21
- if (agg.every((f) => f.code !== code)) {
22
- agg.push(feature);
23
- }
24
- return agg;
25
- }, []);
26
- const additionalProducts = productOrConfiguration instanceof CfgProduct
27
- ? productOrConfiguration.additionalProducts
28
- : undefined;
29
- const AdditionalProductComponent = additionalProductComponent || CfgAdditionalProductView;
30
- // Re-rendering is driven from the very top of the tree. However, when selecting an option
31
- // the change is not bubbled all the way to the top (and then down again) until after
32
- // validation has been done. This keeps the 3D-view from re-rendering until after validation
33
- // has been done. But it also makes the state of this GUI not update until after validate,
34
- // which does not look good. So we add this extra hook to make this rerender early.
35
- const rerender = useRerender();
36
- useEffect(() => {
37
- configuration.listenForChange(rerender);
38
- return () => {
39
- configuration.stopListenForChange(rerender);
40
- };
41
- }, [configuration, rerender]);
42
- return (React.createElement(React.Fragment, null,
43
- React.createElement("ul", { className: `cfgOptionTree cfgOptionTree--topLevel ${props.className || ""}`, style: props.style }, features.map((f) => (React.createElement(CfgFeatureViewMemo, Object.assign({ feature: f, key: f.key }, forwardProps(props)))))),
44
- additionalProducts !== undefined && (React.createElement("ul", { className: `cfgAdditionalProduct cfgOptionTree cfgOptionTree--topLevel` }, additionalProducts.map((additionalProduct) => (React.createElement(AdditionalProductComponent, Object.assign({ key: additionalProduct.key }, forwardProps(props), { additionalProductComponent: AdditionalProductComponent, product: additionalProduct, permanentlyExpandedLevels: permanentlyExpandedAdditionalProductLevels || 0 }))))))));
45
- });
1
+ import { CfgProduct, CfgProductConfiguration } from "@configura/web-api";
2
+ import React, { useEffect } from "react";
3
+ import { useRerender } from "../../useRerender.js";
4
+ import { CfgAdditionalProductView } from "./CfgAdditionalProductView.js";
5
+ import { CfgFeatureViewMemo, forwardProps, } from "./CfgFeatureView.js";
6
+ export var UpchargeDisplayMode;
7
+ (function (UpchargeDisplayMode) {
8
+ UpchargeDisplayMode[UpchargeDisplayMode["SelectionImpact"] = 0] = "SelectionImpact";
9
+ UpchargeDisplayMode[UpchargeDisplayMode["None"] = 1] = "None";
10
+ UpchargeDisplayMode[UpchargeDisplayMode["Price"] = 2] = "Price";
11
+ })(UpchargeDisplayMode || (UpchargeDisplayMode = {}));
12
+ export const CfgProductConfigurationView = React.memo((props) => {
13
+ const { productOrConfiguration, permanentlyExpandedAdditionalProductLevels, additionalProductComponent, } = props;
14
+ const configuration = productOrConfiguration instanceof CfgProduct
15
+ ? productOrConfiguration.configuration
16
+ : productOrConfiguration;
17
+ const configurationVisible = productOrConfiguration instanceof CfgProductConfiguration || productOrConfiguration.visible;
18
+ const features = configuration.features.reduce((agg, feature) => {
19
+ // It is possible in Cat Creator to double add a Feature. This fills no known
20
+ // purpose and React can not handle this, so we filter out the duplicates.
21
+ const code = feature.code;
22
+ if (agg.every((f) => f.code !== code)) {
23
+ agg.push(feature);
24
+ }
25
+ return agg;
26
+ }, []);
27
+ const additionalProducts = productOrConfiguration instanceof CfgProduct
28
+ ? productOrConfiguration.additionalProducts
29
+ : undefined;
30
+ const AdditionalProductComponent = additionalProductComponent || CfgAdditionalProductView;
31
+ // Re-rendering is driven from the very top of the tree. However, when selecting an option
32
+ // the change is not bubbled all the way to the top (and then down again) until after
33
+ // validation has been done. This keeps the 3D-view from re-rendering until after validation
34
+ // has been done. But it also makes the state of this GUI not update until after validate,
35
+ // which does not look good. So we add this extra hook to make this rerender early.
36
+ const rerender = useRerender();
37
+ useEffect(() => {
38
+ configuration.listenForChange(rerender);
39
+ return () => {
40
+ configuration.stopListenForChange(rerender);
41
+ };
42
+ }, [configuration, rerender]);
43
+ return (React.createElement(React.Fragment, null,
44
+ configurationVisible && (React.createElement("ul", { className: `cfgOptionTree cfgOptionTree--topLevel ${props.className || ""}`, style: props.style }, features.map((f) => (React.createElement(CfgFeatureViewMemo, Object.assign({ feature: f, key: f.key }, forwardProps(props))))))),
45
+ additionalProducts !== undefined && (React.createElement("ul", { className: `cfgOptionTree cfgOptionTree--topLevel` }, additionalProducts.map((additionalProduct) => (React.createElement(AdditionalProductComponent, Object.assign({ key: additionalProduct.key }, forwardProps(props), { additionalProductComponent: AdditionalProductComponent, product: additionalProduct, permanentlyExpandedLevels: permanentlyExpandedAdditionalProductLevels !== null && permanentlyExpandedAdditionalProductLevels !== void 0 ? permanentlyExpandedAdditionalProductLevels : 0 }))))))));
46
+ });