@trafilea/afrodita-components 4.0.2-beta.17 → 4.0.2-beta.18

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/build/index.js CHANGED
@@ -7686,7 +7686,7 @@ var Button$4 = function (_a) {
7686
7686
  throw new Error("Invalid button variant ".concat(variant));
7687
7687
  };
7688
7688
 
7689
- var Container$m = newStyled.div(templateObject_1$C || (templateObject_1$C = __makeTemplateObject(["\n overflow: hidden;\n\n input {\n border-radius: ", ";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right: none;\n }\n"], ["\n overflow: hidden;\n\n input {\n border-radius: ", ";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right: none;\n }\n"])), function (_a) {
7689
+ var Container$m = newStyled.div(templateObject_1$C || (templateObject_1$C = __makeTemplateObject(["\n overflow: hidden;\n\n input {\n border-radius: ", ";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right: none;\n width: 100%;\n }\n"], ["\n overflow: hidden;\n\n input {\n border-radius: ", ";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right: none;\n width: 100%;\n }\n"])), function (_a) {
7690
7690
  var theme = _a.theme;
7691
7691
  return theme.component.inputCustom.input.borderRadius;
7692
7692
  });
@@ -13035,10 +13035,28 @@ var Item = newStyled.span(templateObject_2 || (templateObject_2 = __makeTemplate
13035
13035
  var Number$1 = newStyled(Item)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 1.25rem;\n text-align: center;\n font-weight: 600;\n"], ["\n width: 1.25rem;\n text-align: center;\n font-weight: 600;\n"])));
13036
13036
  var IncreaseDecrease = newStyled(Item)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n cursor: pointer;\n user-select: none;\n padding: 0 0.313rem;\n font-weight: 400;\n"], ["\n cursor: pointer;\n user-select: none;\n padding: 0 0.313rem;\n font-weight: 400;\n"])));
13037
13037
  var QuantityPicker = function (_a) {
13038
- var _b = _a.initialValue, initialValue = _b === void 0 ? 0 : _b, _c = _a.maxValue, maxValue = _c === void 0 ? 99 : _c;
13038
+ var _b = _a.initialValue, initialValue = _b === void 0 ? 0 : _b, _c = _a.maxValue, maxValue = _c === void 0 ? 99 : _c, value = _a.value, onChange = _a.onChange;
13039
13039
  var theme = useTheme();
13040
- var _d = React__default["default"].useState(initialValue), value = _d[0], setValue = _d[1];
13041
- return (jsxRuntime.jsxs(Container, __assign({ borderColor: theme.colors.shades['200'].color, color: theme.colors.shades['700'].color, "data-testid": "QuantityPickerContainer" }, { children: [jsxRuntime.jsx(IncreaseDecrease, __assign({ onClick: function () { return setValue(function (val) { return (val > initialValue ? val - 1 : val); }); } }, { children: "-" }), void 0), jsxRuntime.jsx(Number$1, { children: value }, void 0), jsxRuntime.jsx(IncreaseDecrease, __assign({ onClick: function () { return setValue(function (val) { return (val < maxValue ? val + 1 : val); }); } }, { children: "+" }), void 0)] }), void 0));
13040
+ var _d = React.useState(value !== null && value !== void 0 ? value : initialValue), internal = _d[0], setInternal = _d[1];
13041
+ React.useEffect(function () {
13042
+ if (onChange) {
13043
+ onChange(internal);
13044
+ }
13045
+ }, [onChange, internal]);
13046
+ var clamp = React.useCallback(function (value) {
13047
+ // Math.max guards against numbers less than `initialValue`
13048
+ // Math.min guards against numbers greater than `maxValue`
13049
+ return Math.max(Math.min(value, maxValue), initialValue);
13050
+ }, [maxValue, initialValue]);
13051
+ React.useEffect(function () {
13052
+ setInternal(function (internal) {
13053
+ if (value == null) {
13054
+ return internal;
13055
+ }
13056
+ return clamp(value);
13057
+ });
13058
+ }, [value, clamp]);
13059
+ return (jsxRuntime.jsxs(Container, __assign({ borderColor: theme.colors.shades['200'].color, color: theme.colors.shades['700'].color, "data-testid": "QuantityPickerContainer" }, { children: [jsxRuntime.jsx(IncreaseDecrease, __assign({ onClick: function () { return setInternal(function (value) { return clamp(value - 1); }); } }, { children: "-" }), void 0), jsxRuntime.jsx(Number$1, { children: internal }, void 0), jsxRuntime.jsx(IncreaseDecrease, __assign({ onClick: function () { return setInternal(function (value) { return clamp(value + 1); }); } }, { children: "+" }), void 0)] }), void 0));
13042
13060
  };
13043
13061
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
13044
13062