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