@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.js CHANGED
@@ -7,7 +7,7 @@ import ReactDOM from 'react-dom';
7
7
  import camelCase2 from 'lodash.camelcase';
8
8
  import mapKeys from 'lodash.mapkeys';
9
9
  import { jsx } from 'react/jsx-runtime';
10
- import { CheckboxField, CheckboxButton, TextField, Input, ListBoxItem, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, DropZone as DropZone$1, FileTrigger, useSlottedContext, PopoverContext, Popover, CollectionRendererContext, DefaultCollectionRenderer, ListBox, Autocomplete, RadioField, RadioButton, CheckboxGroup as CheckboxGroup$1, I18nProvider, DatePicker as DatePicker$1, Select, VisuallyHidden, NumberField, TimeField, SelectValue, CalendarCell, Calendar as Calendar$1, CalendarMonthPicker, CalendarYearPicker, CalendarGrid, DatePickerStateContext, DateInput as DateInput$1, DateSegment, TimeFieldStateContext, Text as Text$1, ProgressBar, ComboBox, DialogTrigger, TextArea as TextArea$1, ComboBoxStateContext } from 'react-aria-components';
10
+ import { CheckboxField, CheckboxButton, TextField, Input, ListBoxItem, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, DropZone as DropZone$1, FileTrigger, useSlottedContext, PopoverContext, Popover, CollectionRendererContext, DefaultCollectionRenderer, ListBox, Autocomplete, RadioField, RadioButton, CheckboxGroup as CheckboxGroup$1, I18nProvider, DatePicker as DatePicker$1, Select, VisuallyHidden, NumberField, TimeField, SelectValue, CalendarCell, Calendar as Calendar$1, CalendarMonthPicker, CalendarYearPicker, CalendarGrid, DatePickerStateContext, DateInput as DateInput$1, DateSegment, TimeFieldStateContext, ToggleButton, ToggleButtonGroup, Text as Text$1, ProgressBar, ComboBox, DialogTrigger, TextArea as TextArea$1, ComboBoxStateContext } from 'react-aria-components';
11
11
 
12
12
  var __create = Object.create;
13
13
  var __defProp = Object.defineProperty;
@@ -43282,6 +43282,7 @@ var ForcedState = /* @__PURE__ */ (function(ForcedState2) {
43282
43282
  ForcedState2["INPUT_FIELDS_ERROR"] = "INPUT_FIELDS_ERROR";
43283
43283
  ForcedState2["SUCCESS_MESSAGE"] = "SUCCESS_MESSAGE";
43284
43284
  ForcedState2["FORM_CLOSED"] = "FORM_CLOSED";
43285
+ ForcedState2["ERROR_MESSAGE"] = "ERROR_MESSAGE";
43285
43286
  ForcedState2["HIDDEN_FIELDS"] = "HIDDEN_FIELDS";
43286
43287
  return ForcedState2;
43287
43288
  })({});
@@ -55501,18 +55502,11 @@ function findProductWithDynamicPrice(products) {
55501
55502
  function getCustomAmount(productValue, customAmountProduct) {
55502
55503
  return productValue?.productId === customAmountProduct?.id ? String(productValue?.price ?? "") : "";
55503
55504
  }
55504
- function getProductValueOnCheckboxChange(productId, productValue, productsById) {
55505
- const newValue = productValue?.productId === productId ? void 0 : productId;
55506
- const product = newValue ? productsById[newValue] : void 0;
55507
- return product ? [
55508
- toProductValue(product, getProductPrice2(product))
55509
- ] : [];
55510
- }
55511
55505
 
55512
55506
  // ../form-fields/dist/esm/ui/donation-field/donation-field-headless.js
55513
55507
  var Donation = ({ children }) => {
55514
- const { id: id6, value, onChange, disabled, required, onBlur, onFocus, validation, addOther, addOtherPlaceholder, FieldLayout, hasError } = useFieldPropsV2();
55515
- const { labelId } = useFieldAttributes();
55508
+ const { id: id6, value, onChange, required, onBlur, onFocus, validation, addOther, addOtherPlaceholder, FieldLayout } = useFieldPropsV2();
55509
+ const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
55516
55510
  const { t } = useTranslation2();
55517
55511
  const { currency, regionalFormat } = useConfig();
55518
55512
  const productValue = value?.[0];
@@ -55532,13 +55526,15 @@ var Donation = ({ children }) => {
55532
55526
  format: (source) => toLocaleDecimalSeparator(String(source ?? ""), regionalFormat),
55533
55527
  regionalFormat
55534
55528
  });
55535
- const handleRadioChange = useCallback((selectedValue2) => {
55536
- onChange(getProductValueOnCheckboxChange(selectedValue2, productValue, productsById));
55529
+ const selectProduct = useCallback((productId) => {
55530
+ const product = productId === void 0 ? void 0 : productsById[productId];
55531
+ onChange(product ? [
55532
+ toProductValue(product, getProductPrice2(product))
55533
+ ] : []);
55537
55534
  setCustomAmount("");
55538
55535
  }, [
55539
55536
  onChange,
55540
55537
  productsById,
55541
- productValue,
55542
55538
  setCustomAmount
55543
55539
  ]);
55544
55540
  const handleCustomAmountChange = useCallback((amount) => {
@@ -55580,12 +55576,12 @@ var Donation = ({ children }) => {
55580
55576
  const selectedValue = productValue?.productId || null;
55581
55577
  const handleFocusCustomInput = useCallback(() => {
55582
55578
  if (customAmountProduct?.id && selectedValue !== customAmountProduct.id) {
55583
- handleRadioChange(customAmountProduct.id);
55579
+ selectProduct(customAmountProduct.id);
55584
55580
  }
55585
55581
  }, [
55586
55582
  customAmountProduct?.id,
55587
55583
  selectedValue,
55588
- handleRadioChange
55584
+ selectProduct
55589
55585
  ]);
55590
55586
  const labelElement = findChildOfType(children, Donation.Label);
55591
55587
  const controlElement = findChildOfType(children, Donation.Control);
@@ -55594,17 +55590,17 @@ var Donation = ({ children }) => {
55594
55590
  return /* @__PURE__ */ React173.createElement(FieldLayout, {
55595
55591
  fieldId: id6,
55596
55592
  renderLabel: () => labelElement,
55597
- renderInput: () => /* @__PURE__ */ React173.createElement(RadioGroup$1, {
55598
- "aria-labelledby": labelId,
55599
- value: selectedValue,
55600
- onChange: handleRadioChange,
55601
- isDisabled: disabled,
55602
- isInvalid: hasError,
55603
- isRequired: required,
55593
+ renderInput: () => /* @__PURE__ */ React173.createElement(FieldsetHeadless, {
55594
+ id: inputId,
55595
+ ariaLabelledBy: labelId,
55596
+ ariaDescribedBy,
55597
+ required,
55604
55598
  onBlur,
55605
55599
  onFocus
55606
55600
  }, controlElement ? applyInternalProps(controlElement, {
55607
55601
  productsById,
55602
+ selectedValue,
55603
+ onSelectProduct: selectProduct,
55608
55604
  addOther,
55609
55605
  customAmount,
55610
55606
  onCustomAmountInputChange: handleCustomAmountInputChange,
@@ -55618,7 +55614,7 @@ var Donation = ({ children }) => {
55618
55614
  });
55619
55615
  };
55620
55616
  var Control3 = ({ children, className, ...internal }) => {
55621
- const { productsById, addOther, customAmount, onCustomAmountInputChange, currency, t, placeholder, customAmountProductId, onFocusCustomInput } = internal;
55617
+ const { productsById, selectedValue, onSelectProduct, addOther, customAmount, onCustomAmountInputChange, currency, t, placeholder, customAmountProductId, onFocusCustomInput } = internal;
55622
55618
  const { hasError } = useFieldPropsV2();
55623
55619
  const optionsElement = findChildOfType(children, Donation.Options);
55624
55620
  const otherInputElement = findChildOfType(children, Donation.OtherInput);
@@ -55626,23 +55622,10 @@ var Control3 = ({ children, className, ...internal }) => {
55626
55622
  className,
55627
55623
  "data-invalid": hasError
55628
55624
  }, optionsElement ? applyInternalProps(optionsElement, {
55629
- productsById
55630
- }) : null, addOther && customAmountProductId && /* @__PURE__ */ React173.createElement(RadioField, {
55631
- value: customAmountProductId,
55632
- style: {
55633
- position: "absolute",
55634
- width: "1px",
55635
- height: "1px",
55636
- padding: "0",
55637
- margin: "-1px",
55638
- overflow: "hidden",
55639
- clip: "rect(0, 0, 0, 0)",
55640
- whiteSpace: "nowrap",
55641
- border: "0"
55642
- }
55643
- }, /* @__PURE__ */ React173.createElement(RadioButton, {
55644
- "aria-label": t("donation.other-option.label", "Custom amount")
55645
- }, t("donation.other-option.label", "Custom amount"))), otherInputElement && addOther ? applyInternalProps(otherInputElement, {
55625
+ productsById,
55626
+ selectedValue,
55627
+ onSelectProduct
55628
+ }) : null, otherInputElement && addOther ? applyInternalProps(otherInputElement, {
55646
55629
  customAmount,
55647
55630
  onCustomAmountInputChange,
55648
55631
  currency,
@@ -55653,12 +55636,22 @@ var Control3 = ({ children, className, ...internal }) => {
55653
55636
  }) : null);
55654
55637
  };
55655
55638
  var Options2 = ({ children, className, ...internal }) => {
55656
- const { productsById } = internal;
55657
- const { options, numberOfColumns } = useFieldPropsV2();
55639
+ const { productsById, selectedValue, onSelectProduct } = internal;
55640
+ const { options, numberOfColumns, disabled } = useFieldPropsV2();
55641
+ const { labelId } = useFieldAttributes();
55658
55642
  const optionElement = findChildOfType(children, Options2.Option);
55659
- return /* @__PURE__ */ React173.createElement("div", {
55643
+ return /* @__PURE__ */ React173.createElement(ToggleButtonGroup, {
55660
55644
  className,
55661
- "data-columns": numberOfColumns
55645
+ "data-columns": numberOfColumns,
55646
+ "aria-labelledby": labelId,
55647
+ selectionMode: "single",
55648
+ selectedKeys: selectedValue ? [
55649
+ selectedValue
55650
+ ] : [],
55651
+ onSelectionChange: (keys3) => onSelectProduct([
55652
+ ...keys3
55653
+ ][0]),
55654
+ isDisabled: disabled
55662
55655
  }, options.map((option2) => {
55663
55656
  const product = productsById[option2.value];
55664
55657
  const price = product?.fixedPriceOptions?.price;
@@ -55671,7 +55664,7 @@ var Options2 = ({ children, className, ...internal }) => {
55671
55664
  };
55672
55665
  var Option2 = ({ children, className, ...internal }) => {
55673
55666
  const { value, price } = internal;
55674
- const { id: id6 } = useFieldPropsV2();
55667
+ const { id: id6, hasError } = useFieldPropsV2();
55675
55668
  const { currency, regionalFormat } = useConfig();
55676
55669
  const valueElement = findChildOfType(children, Option2.Value);
55677
55670
  const currencyElement = findChildOfType(children, Option2.Currency);
@@ -55682,17 +55675,17 @@ var Option2 = ({ children, className, ...internal }) => {
55682
55675
  });
55683
55676
  const ref = useRef(null);
55684
55677
  useFocusFieldEvent(() => {
55685
- ref.current?.querySelector("input")?.focus();
55678
+ ref.current?.focus();
55686
55679
  }, id6);
55687
55680
  const renderedValue = valueElement ? applyInternalProps(valueElement, {
55688
55681
  price
55689
55682
  }) : null;
55690
- return /* @__PURE__ */ React173.createElement(RadioField, {
55691
- value
55692
- }, /* @__PURE__ */ React173.createElement(RadioButton, {
55683
+ return /* @__PURE__ */ React173.createElement(ToggleButton, {
55684
+ id: value,
55693
55685
  className,
55694
- ref
55695
- }, /* @__PURE__ */ React173.createElement(React173.Fragment, null, isCurrencyPrefixed && currencyElement, renderedValue, !isCurrencyPrefixed && currencyElement)));
55686
+ ref,
55687
+ "data-invalid": hasError || void 0
55688
+ }, /* @__PURE__ */ React173.createElement(React173.Fragment, null, isCurrencyPrefixed && currencyElement, renderedValue, !isCurrencyPrefixed && currencyElement));
55696
55689
  };
55697
55690
  var OptionValue = ({ className, ...internal }) => {
55698
55691
  const { price } = internal;