@wix/form-public 0.97.0 → 0.98.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
@@ -1,7 +1,7 @@
1
1
  import { initReactI18next } from 'react-i18next';
2
2
  import i18next from 'i18next';
3
3
  import * as React40 from 'react';
4
- import React40__default, { createContext, useRef, useMemo, useCallback, useState, useEffect, useLayoutEffect, Children, isValidElement, cloneElement, useContext, useImperativeHandle } from 'react';
4
+ import React40__default, { createContext, useMemo, useRef, useCallback, useState, useEffect, useLayoutEffect, Children, isValidElement, cloneElement, useContext, useImperativeHandle } from 'react';
5
5
  import camelCase from 'lodash.camelcase';
6
6
  import mapKeys from 'lodash.mapkeys';
7
7
  import { jsx } from 'react/jsx-runtime';
@@ -32024,13 +32024,30 @@ RichLabel.Required = Required;
32024
32024
 
32025
32025
  // ../form-fields/dist/esm/ui/checkbox-field/checkbox-field-headless.js
32026
32026
  var Checkbox = (_ref) => {
32027
+ let {
32028
+ children
32029
+ } = _ref;
32030
+ const {
32031
+ id,
32032
+ FieldLayout
32033
+ } = useFieldPropsV2();
32034
+ const checkboxElement = findChildOfType(children, Checkbox.Checkbox);
32035
+ const descriptionElement = findChildOfType(children, Checkbox.Description);
32036
+ const errorElement = findChildOfType(children, Checkbox.Error);
32037
+ return /* @__PURE__ */ React40__default.createElement(FieldLayout, {
32038
+ fieldId: id,
32039
+ renderLabel: () => null,
32040
+ renderInput: () => checkboxElement,
32041
+ renderDescription: () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, descriptionElement, errorElement)
32042
+ });
32043
+ };
32044
+ var CheckboxContainer = (_ref2) => {
32027
32045
  let {
32028
32046
  children,
32029
32047
  className
32030
- } = _ref;
32048
+ } = _ref2;
32031
32049
  const {
32032
32050
  id,
32033
- FieldLayout,
32034
32051
  value,
32035
32052
  onChange,
32036
32053
  disabled,
@@ -32047,42 +32064,36 @@ var Checkbox = (_ref) => {
32047
32064
  var _ref$current;
32048
32065
  (_ref$current = ref.current) == null || _ref$current.focus();
32049
32066
  }, id);
32050
- const labelElement = findChildOfType(children, Checkbox.Label);
32051
- const inputElement = findChildOfType(children, Checkbox.Input);
32052
- const descriptionElement = findChildOfType(children, Checkbox.Description);
32053
- const errorElement = findChildOfType(children, Checkbox.Error);
32067
+ const labelElement = findChildOfType(children, CheckboxContainer.Label);
32068
+ const inputElement = findChildOfType(children, CheckboxContainer.Input);
32054
32069
  const handleChange = useCallback((isSelected) => {
32055
32070
  onChange(isSelected);
32056
32071
  }, [onChange]);
32057
- return /* @__PURE__ */ React40__default.createElement(FieldLayout, {
32058
- fieldId: id,
32059
- renderLabel: () => null,
32060
- renderInput: () => /* @__PURE__ */ React40__default.createElement(Checkbox$1, {
32061
- ref,
32062
- id: inputId,
32063
- "aria-describedby": ariaDescribedBy,
32064
- isSelected: Boolean(value),
32065
- onChange: handleChange,
32066
- isDisabled: disabled,
32067
- isRequired: required,
32068
- onBlur,
32069
- onFocus,
32070
- className
32071
- }, () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, inputElement, labelElement)),
32072
- renderDescription: () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, descriptionElement, errorElement)
32073
- });
32072
+ return /* @__PURE__ */ React40__default.createElement(Checkbox$1, {
32073
+ ref,
32074
+ id: inputId,
32075
+ "aria-describedby": ariaDescribedBy,
32076
+ isSelected: Boolean(value),
32077
+ onChange: handleChange,
32078
+ isDisabled: disabled,
32079
+ isRequired: required,
32080
+ onBlur,
32081
+ onFocus,
32082
+ className
32083
+ }, () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, inputElement, labelElement));
32074
32084
  };
32075
- var Input = (_ref2) => {
32085
+ var Input = (_ref3) => {
32076
32086
  let {
32077
32087
  className
32078
- } = _ref2;
32088
+ } = _ref3;
32079
32089
  return /* @__PURE__ */ React40__default.createElement("div", {
32080
32090
  "aria-hidden": "true",
32081
32091
  className
32082
32092
  });
32083
32093
  };
32084
- Checkbox.Label = RichLabel;
32085
- Checkbox.Input = Input;
32094
+ CheckboxContainer.Label = RichLabel;
32095
+ CheckboxContainer.Input = Input;
32096
+ Checkbox.Checkbox = CheckboxContainer;
32086
32097
  Checkbox.Description = Description;
32087
32098
  Checkbox.Error = Error2;
32088
32099
 
@@ -32363,12 +32374,33 @@ var Options = (_ref2) => {
32363
32374
  isOther: true
32364
32375
  }));
32365
32376
  };
32366
- var Option = (_ref3) => {
32377
+ var OptionInput = (_ref3) => {
32378
+ let {
32379
+ className
32380
+ } = _ref3;
32381
+ return /* @__PURE__ */ React40__default.createElement("div", {
32382
+ "aria-hidden": "true",
32383
+ className
32384
+ });
32385
+ };
32386
+ var OptionLabel = (_ref4) => {
32387
+ let {
32388
+ className,
32389
+ ...internal
32390
+ } = _ref4;
32391
+ const {
32392
+ label
32393
+ } = internal;
32394
+ return /* @__PURE__ */ React40__default.createElement("span", {
32395
+ className
32396
+ }, label);
32397
+ };
32398
+ var Checkbox2 = (_ref5) => {
32367
32399
  let {
32368
32400
  children,
32369
32401
  className,
32370
32402
  ...internal
32371
- } = _ref3;
32403
+ } = _ref5;
32372
32404
  const {
32373
32405
  value,
32374
32406
  label,
@@ -32383,9 +32415,7 @@ var Option = (_ref3) => {
32383
32415
  disabled,
32384
32416
  hasError,
32385
32417
  options,
32386
- addOtherLabel,
32387
- addOtherPlaceholder,
32388
- otherInputCharacterLimit
32418
+ addOtherLabel
32389
32419
  } = props;
32390
32420
  const checkboxRef = useRef(null);
32391
32421
  useFocusFieldEvent(() => {
@@ -32396,17 +32426,9 @@ var Option = (_ref3) => {
32396
32426
  });
32397
32427
  }
32398
32428
  }, fieldId);
32399
- const labelElement = findChildOfType(children, Option.Label);
32400
- const inputElement = findChildOfType(children, Option.Input);
32401
- const otherInputElement = findChildOfType(children, Option.OtherInput);
32429
+ const labelElement = findChildOfType(children, Checkbox2.Label);
32430
+ const inputElement = findChildOfType(children, Checkbox2.Input);
32402
32431
  const _value = useMemo(() => fieldValue || [], [fieldValue]);
32403
- const isOtherSelected = useMemo(() => {
32404
- if (!isOther) {
32405
- return false;
32406
- }
32407
- const optionsValues = getOptionsValues(options || []);
32408
- return getIsOtherOptionSelected(_value, optionsValues);
32409
- }, [isOther, _value, options]);
32410
32432
  const actualValue = useMemo(() => {
32411
32433
  if (isOther) {
32412
32434
  return _value.find((val) => val === label || val.startsWith(`${addOtherLabel}: `)) || label;
@@ -32432,6 +32454,49 @@ var Option = (_ref3) => {
32432
32454
  "data-hook": `checkbox-${label}`
32433
32455
  }, inputElement, applyInternalProps(labelElement, {
32434
32456
  label
32457
+ }));
32458
+ };
32459
+ Checkbox2.Label = OptionLabel;
32460
+ Checkbox2.Input = OptionInput;
32461
+ var Option = (_ref6) => {
32462
+ let {
32463
+ children,
32464
+ ...internal
32465
+ } = _ref6;
32466
+ const {
32467
+ value,
32468
+ label,
32469
+ isFirst = false,
32470
+ isOther = false,
32471
+ fieldId
32472
+ } = internal;
32473
+ const props = useFieldPropsV2();
32474
+ const {
32475
+ value: fieldValue,
32476
+ onChange,
32477
+ options,
32478
+ addOtherLabel,
32479
+ addOtherPlaceholder,
32480
+ otherInputCharacterLimit,
32481
+ disabled,
32482
+ hasError
32483
+ } = props;
32484
+ const checkboxElement = findChildOfType(children, Checkbox2);
32485
+ const otherInputElement = findChildOfType(children, OtherInput);
32486
+ const _value = useMemo(() => fieldValue || [], [fieldValue]);
32487
+ const isOtherSelected = useMemo(() => {
32488
+ if (!isOther) {
32489
+ return false;
32490
+ }
32491
+ const optionsValues = getOptionsValues(options || []);
32492
+ return getIsOtherOptionSelected(_value, optionsValues);
32493
+ }, [isOther, _value, options]);
32494
+ return /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, applyInternalProps(checkboxElement, {
32495
+ value,
32496
+ label,
32497
+ isFirst,
32498
+ isOther,
32499
+ fieldId
32435
32500
  }), isOther && isOtherSelected && applyInternalProps(otherInputElement, {
32436
32501
  fieldValue: _value,
32437
32502
  onChange,
@@ -32445,32 +32510,11 @@ var Option = (_ref3) => {
32445
32510
  options
32446
32511
  }));
32447
32512
  };
32448
- var OptionInput = (_ref4) => {
32449
- let {
32450
- className
32451
- } = _ref4;
32452
- return /* @__PURE__ */ React40__default.createElement("div", {
32453
- "aria-hidden": "true",
32454
- className
32455
- });
32456
- };
32457
- var OptionLabel = (_ref5) => {
32458
- let {
32459
- className,
32460
- ...internal
32461
- } = _ref5;
32462
- const {
32463
- label
32464
- } = internal;
32465
- return /* @__PURE__ */ React40__default.createElement("span", {
32466
- className
32467
- }, label);
32468
- };
32469
- var OtherInput = (_ref6) => {
32513
+ var OtherInput = (_ref7) => {
32470
32514
  let {
32471
32515
  className,
32472
32516
  ...internal
32473
- } = _ref6;
32517
+ } = _ref7;
32474
32518
  const {
32475
32519
  fieldValue,
32476
32520
  onChange,
@@ -32521,8 +32565,7 @@ var OtherInput = (_ref6) => {
32521
32565
  CheckboxGroup.Label = Label;
32522
32566
  CheckboxGroup.Options = Options;
32523
32567
  Options.Option = Option;
32524
- Option.Label = OptionLabel;
32525
- Option.Input = OptionInput;
32568
+ Option.Checkbox = Checkbox2;
32526
32569
  Option.OtherInput = OtherInput;
32527
32570
  CheckboxGroup.Description = Description;
32528
32571
  CheckboxGroup.Error = Error2;