@wix/form-public 0.529.0 → 0.531.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.
package/dist/index.cjs CHANGED
@@ -43292,6 +43292,7 @@ var ForcedState = /* @__PURE__ */ (function(ForcedState2) {
43292
43292
  ForcedState2["INPUT_FIELDS_ERROR"] = "INPUT_FIELDS_ERROR";
43293
43293
  ForcedState2["SUCCESS_MESSAGE"] = "SUCCESS_MESSAGE";
43294
43294
  ForcedState2["FORM_CLOSED"] = "FORM_CLOSED";
43295
+ ForcedState2["ERROR_MESSAGE"] = "ERROR_MESSAGE";
43295
43296
  ForcedState2["HIDDEN_FIELDS"] = "HIDDEN_FIELDS";
43296
43297
  return ForcedState2;
43297
43298
  })({});
@@ -55511,18 +55512,11 @@ function findProductWithDynamicPrice(products) {
55511
55512
  function getCustomAmount(productValue, customAmountProduct) {
55512
55513
  return productValue?.productId === customAmountProduct?.id ? String(productValue?.price ?? "") : "";
55513
55514
  }
55514
- function getProductValueOnCheckboxChange(productId, productValue, productsById) {
55515
- const newValue = productValue?.productId === productId ? void 0 : productId;
55516
- const product = newValue ? productsById[newValue] : void 0;
55517
- return product ? [
55518
- toProductValue(product, getProductPrice2(product))
55519
- ] : [];
55520
- }
55521
55515
 
55522
55516
  // ../form-fields/dist/esm/ui/donation-field/donation-field-headless.js
55523
55517
  var Donation = ({ children }) => {
55524
- const { id: id6, value, onChange, disabled, required, onBlur, onFocus, validation, addOther, addOtherPlaceholder, FieldLayout, hasError } = useFieldPropsV2();
55525
- const { labelId } = useFieldAttributes();
55518
+ const { id: id6, value, onChange, required, onBlur, onFocus, validation, addOther, addOtherPlaceholder, FieldLayout } = useFieldPropsV2();
55519
+ const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
55526
55520
  const { t } = useTranslation2();
55527
55521
  const { currency, regionalFormat } = useConfig();
55528
55522
  const productValue = value?.[0];
@@ -55542,13 +55536,15 @@ var Donation = ({ children }) => {
55542
55536
  format: (source) => toLocaleDecimalSeparator(String(source ?? ""), regionalFormat),
55543
55537
  regionalFormat
55544
55538
  });
55545
- const handleRadioChange = React173.useCallback((selectedValue2) => {
55546
- onChange(getProductValueOnCheckboxChange(selectedValue2, productValue, productsById));
55539
+ const selectProduct = React173.useCallback((productId) => {
55540
+ const product = productId === void 0 ? void 0 : productsById[productId];
55541
+ onChange(product ? [
55542
+ toProductValue(product, getProductPrice2(product))
55543
+ ] : []);
55547
55544
  setCustomAmount("");
55548
55545
  }, [
55549
55546
  onChange,
55550
55547
  productsById,
55551
- productValue,
55552
55548
  setCustomAmount
55553
55549
  ]);
55554
55550
  const handleCustomAmountChange = React173.useCallback((amount) => {
@@ -55590,12 +55586,12 @@ var Donation = ({ children }) => {
55590
55586
  const selectedValue = productValue?.productId || null;
55591
55587
  const handleFocusCustomInput = React173.useCallback(() => {
55592
55588
  if (customAmountProduct?.id && selectedValue !== customAmountProduct.id) {
55593
- handleRadioChange(customAmountProduct.id);
55589
+ selectProduct(customAmountProduct.id);
55594
55590
  }
55595
55591
  }, [
55596
55592
  customAmountProduct?.id,
55597
55593
  selectedValue,
55598
- handleRadioChange
55594
+ selectProduct
55599
55595
  ]);
55600
55596
  const labelElement = findChildOfType(children, Donation.Label);
55601
55597
  const controlElement = findChildOfType(children, Donation.Control);
@@ -55604,17 +55600,17 @@ var Donation = ({ children }) => {
55604
55600
  return /* @__PURE__ */ React173__default.default.createElement(FieldLayout, {
55605
55601
  fieldId: id6,
55606
55602
  renderLabel: () => labelElement,
55607
- renderInput: () => /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioGroup, {
55608
- "aria-labelledby": labelId,
55609
- value: selectedValue,
55610
- onChange: handleRadioChange,
55611
- isDisabled: disabled,
55612
- isInvalid: hasError,
55613
- isRequired: required,
55603
+ renderInput: () => /* @__PURE__ */ React173__default.default.createElement(FieldsetHeadless, {
55604
+ id: inputId,
55605
+ ariaLabelledBy: labelId,
55606
+ ariaDescribedBy,
55607
+ required,
55614
55608
  onBlur,
55615
55609
  onFocus
55616
55610
  }, controlElement ? applyInternalProps(controlElement, {
55617
55611
  productsById,
55612
+ selectedValue,
55613
+ onSelectProduct: selectProduct,
55618
55614
  addOther,
55619
55615
  customAmount,
55620
55616
  onCustomAmountInputChange: handleCustomAmountInputChange,
@@ -55628,7 +55624,7 @@ var Donation = ({ children }) => {
55628
55624
  });
55629
55625
  };
55630
55626
  var Control3 = ({ children, className, ...internal }) => {
55631
- const { productsById, addOther, customAmount, onCustomAmountInputChange, currency, t, placeholder, customAmountProductId, onFocusCustomInput } = internal;
55627
+ const { productsById, selectedValue, onSelectProduct, addOther, customAmount, onCustomAmountInputChange, currency, t, placeholder, customAmountProductId, onFocusCustomInput } = internal;
55632
55628
  const { hasError } = useFieldPropsV2();
55633
55629
  const optionsElement = findChildOfType(children, Donation.Options);
55634
55630
  const otherInputElement = findChildOfType(children, Donation.OtherInput);
@@ -55636,23 +55632,10 @@ var Control3 = ({ children, className, ...internal }) => {
55636
55632
  className,
55637
55633
  "data-invalid": hasError
55638
55634
  }, optionsElement ? applyInternalProps(optionsElement, {
55639
- productsById
55640
- }) : null, addOther && customAmountProductId && /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioField, {
55641
- value: customAmountProductId,
55642
- style: {
55643
- position: "absolute",
55644
- width: "1px",
55645
- height: "1px",
55646
- padding: "0",
55647
- margin: "-1px",
55648
- overflow: "hidden",
55649
- clip: "rect(0, 0, 0, 0)",
55650
- whiteSpace: "nowrap",
55651
- border: "0"
55652
- }
55653
- }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioButton, {
55654
- "aria-label": t("donation.other-option.label", "Custom amount")
55655
- }, t("donation.other-option.label", "Custom amount"))), otherInputElement && addOther ? applyInternalProps(otherInputElement, {
55635
+ productsById,
55636
+ selectedValue,
55637
+ onSelectProduct
55638
+ }) : null, otherInputElement && addOther ? applyInternalProps(otherInputElement, {
55656
55639
  customAmount,
55657
55640
  onCustomAmountInputChange,
55658
55641
  currency,
@@ -55663,12 +55646,22 @@ var Control3 = ({ children, className, ...internal }) => {
55663
55646
  }) : null);
55664
55647
  };
55665
55648
  var Options2 = ({ children, className, ...internal }) => {
55666
- const { productsById } = internal;
55667
- const { options, numberOfColumns } = useFieldPropsV2();
55649
+ const { productsById, selectedValue, onSelectProduct } = internal;
55650
+ const { options, numberOfColumns, disabled } = useFieldPropsV2();
55651
+ const { labelId } = useFieldAttributes();
55668
55652
  const optionElement = findChildOfType(children, Options2.Option);
55669
- return /* @__PURE__ */ React173__default.default.createElement("div", {
55653
+ return /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.ToggleButtonGroup, {
55670
55654
  className,
55671
- "data-columns": numberOfColumns
55655
+ "data-columns": numberOfColumns,
55656
+ "aria-labelledby": labelId,
55657
+ selectionMode: "single",
55658
+ selectedKeys: selectedValue ? [
55659
+ selectedValue
55660
+ ] : [],
55661
+ onSelectionChange: (keys3) => onSelectProduct([
55662
+ ...keys3
55663
+ ][0]),
55664
+ isDisabled: disabled
55672
55665
  }, options.map((option2) => {
55673
55666
  const product = productsById[option2.value];
55674
55667
  const price = product?.fixedPriceOptions?.price;
@@ -55681,7 +55674,7 @@ var Options2 = ({ children, className, ...internal }) => {
55681
55674
  };
55682
55675
  var Option2 = ({ children, className, ...internal }) => {
55683
55676
  const { value, price } = internal;
55684
- const { id: id6 } = useFieldPropsV2();
55677
+ const { id: id6, hasError } = useFieldPropsV2();
55685
55678
  const { currency, regionalFormat } = useConfig();
55686
55679
  const valueElement = findChildOfType(children, Option2.Value);
55687
55680
  const currencyElement = findChildOfType(children, Option2.Currency);
@@ -55692,17 +55685,17 @@ var Option2 = ({ children, className, ...internal }) => {
55692
55685
  });
55693
55686
  const ref = React173.useRef(null);
55694
55687
  useFocusFieldEvent(() => {
55695
- ref.current?.querySelector("input")?.focus();
55688
+ ref.current?.focus();
55696
55689
  }, id6);
55697
55690
  const renderedValue = valueElement ? applyInternalProps(valueElement, {
55698
55691
  price
55699
55692
  }) : null;
55700
- return /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioField, {
55701
- value
55702
- }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioButton, {
55693
+ return /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.ToggleButton, {
55694
+ id: value,
55703
55695
  className,
55704
- ref
55705
- }, /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, isCurrencyPrefixed && currencyElement, renderedValue, !isCurrencyPrefixed && currencyElement)));
55696
+ ref,
55697
+ "data-invalid": hasError || void 0
55698
+ }, /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, isCurrencyPrefixed && currencyElement, renderedValue, !isCurrencyPrefixed && currencyElement));
55706
55699
  };
55707
55700
  var OptionValue = ({ className, ...internal }) => {
55708
55701
  const { price } = internal;