@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.d.ts CHANGED
@@ -1593,11 +1593,20 @@ declare const CartProductItem: {
1593
1593
  CloseButton: ({ onClick }: CloseButtonProps) => JSX.Element;
1594
1594
  };
1595
1595
 
1596
- interface QuantityPickerProps {
1596
+ declare type QuantityPickerPropsOnChange = (value: number) => void;
1597
+ declare type QuantityPickerPropsControlled = {
1598
+ value: number;
1599
+ onChange: QuantityPickerPropsOnChange;
1600
+ };
1601
+ declare type QuantityPickerPropsUncontrolled = {
1602
+ value?: never;
1603
+ onChange?: QuantityPickerPropsOnChange;
1604
+ };
1605
+ declare type QuantityPickerProps = {
1597
1606
  initialValue?: number;
1598
1607
  maxValue?: number;
1599
- }
1600
- declare const QuantityPicker: ({ initialValue, maxValue }: QuantityPickerProps) => JSX.Element;
1608
+ } & (QuantityPickerPropsControlled | QuantityPickerPropsUncontrolled);
1609
+ declare const QuantityPicker: ({ initialValue, maxValue, value, onChange, }: QuantityPickerProps) => JSX.Element;
1601
1610
 
1602
1611
  declare const useOnClickOutside: <T extends HTMLElement = HTMLElement>(ref: RefObject<T>, handler: (event: Event) => void) => void;
1603
1612
 
@@ -7678,7 +7678,7 @@ var Button$4 = function (_a) {
7678
7678
  throw new Error("Invalid button variant ".concat(variant));
7679
7679
  };
7680
7680
 
7681
- 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) {
7681
+ 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) {
7682
7682
  var theme = _a.theme;
7683
7683
  return theme.component.inputCustom.input.borderRadius;
7684
7684
  });
@@ -13027,10 +13027,28 @@ var Item = newStyled.span(templateObject_2 || (templateObject_2 = __makeTemplate
13027
13027
  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"])));
13028
13028
  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"])));
13029
13029
  var QuantityPicker = function (_a) {
13030
- var _b = _a.initialValue, initialValue = _b === void 0 ? 0 : _b, _c = _a.maxValue, maxValue = _c === void 0 ? 99 : _c;
13030
+ 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;
13031
13031
  var theme = useTheme();
13032
- var _d = React.useState(initialValue), value = _d[0], setValue = _d[1];
13033
- return (jsxs$1(Container, __assign({ borderColor: theme.colors.shades['200'].color, color: theme.colors.shades['700'].color, "data-testid": "QuantityPickerContainer" }, { children: [jsx$1(IncreaseDecrease, __assign({ onClick: function () { return setValue(function (val) { return (val > initialValue ? val - 1 : val); }); } }, { children: "-" }), void 0), jsx$1(Number$1, { children: value }, void 0), jsx$1(IncreaseDecrease, __assign({ onClick: function () { return setValue(function (val) { return (val < maxValue ? val + 1 : val); }); } }, { children: "+" }), void 0)] }), void 0));
13032
+ var _d = useState(value !== null && value !== void 0 ? value : initialValue), internal = _d[0], setInternal = _d[1];
13033
+ useEffect(function () {
13034
+ if (onChange) {
13035
+ onChange(internal);
13036
+ }
13037
+ }, [onChange, internal]);
13038
+ var clamp = useCallback(function (value) {
13039
+ // Math.max guards against numbers less than `initialValue`
13040
+ // Math.min guards against numbers greater than `maxValue`
13041
+ return Math.max(Math.min(value, maxValue), initialValue);
13042
+ }, [maxValue, initialValue]);
13043
+ useEffect(function () {
13044
+ setInternal(function (internal) {
13045
+ if (value == null) {
13046
+ return internal;
13047
+ }
13048
+ return clamp(value);
13049
+ });
13050
+ }, [value, clamp]);
13051
+ return (jsxs$1(Container, __assign({ borderColor: theme.colors.shades['200'].color, color: theme.colors.shades['700'].color, "data-testid": "QuantityPickerContainer" }, { children: [jsx$1(IncreaseDecrease, __assign({ onClick: function () { return setInternal(function (value) { return clamp(value - 1); }); } }, { children: "-" }), void 0), jsx$1(Number$1, { children: internal }, void 0), jsx$1(IncreaseDecrease, __assign({ onClick: function () { return setInternal(function (value) { return clamp(value + 1); }); } }, { children: "+" }), void 0)] }), void 0));
13034
13052
  };
13035
13053
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
13036
13054