@wix/form-public 0.96.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';
@@ -25960,7 +25960,7 @@ function useFieldAttributes2() {
25960
25960
 
25961
25961
  // ../form-fields/dist/esm/ui/form/components/form/input-field.js
25962
25962
  var InputField = (_ref) => {
25963
- var _field$properties;
25963
+ var _field$properties, _field$properties2;
25964
25964
  let {
25965
25965
  field,
25966
25966
  errors,
@@ -26032,6 +26032,7 @@ var InputField = (_ref) => {
26032
26032
  const FieldComponent = componentsById[field.fieldType];
26033
26033
  const fieldProps = {
26034
26034
  ...field.properties,
26035
+ readOnly: Boolean((_field$properties2 = field.properties) == null ? void 0 : _field$properties2.readOnly),
26035
26036
  onChange: handleChange,
26036
26037
  onBlur: _onBlur,
26037
26038
  onFocus: _onFocus,
@@ -32023,13 +32024,30 @@ RichLabel.Required = Required;
32023
32024
 
32024
32025
  // ../form-fields/dist/esm/ui/checkbox-field/checkbox-field-headless.js
32025
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) => {
32026
32045
  let {
32027
32046
  children,
32028
32047
  className
32029
- } = _ref;
32048
+ } = _ref2;
32030
32049
  const {
32031
32050
  id,
32032
- FieldLayout,
32033
32051
  value,
32034
32052
  onChange,
32035
32053
  disabled,
@@ -32046,42 +32064,36 @@ var Checkbox = (_ref) => {
32046
32064
  var _ref$current;
32047
32065
  (_ref$current = ref.current) == null || _ref$current.focus();
32048
32066
  }, id);
32049
- const labelElement = findChildOfType(children, Checkbox.Label);
32050
- const inputElement = findChildOfType(children, Checkbox.Input);
32051
- const descriptionElement = findChildOfType(children, Checkbox.Description);
32052
- const errorElement = findChildOfType(children, Checkbox.Error);
32067
+ const labelElement = findChildOfType(children, CheckboxContainer.Label);
32068
+ const inputElement = findChildOfType(children, CheckboxContainer.Input);
32053
32069
  const handleChange = useCallback((isSelected) => {
32054
32070
  onChange(isSelected);
32055
32071
  }, [onChange]);
32056
- return /* @__PURE__ */ React40__default.createElement(FieldLayout, {
32057
- fieldId: id,
32058
- renderLabel: () => null,
32059
- renderInput: () => /* @__PURE__ */ React40__default.createElement(Checkbox$1, {
32060
- ref,
32061
- id: inputId,
32062
- "aria-describedby": ariaDescribedBy,
32063
- isSelected: Boolean(value),
32064
- onChange: handleChange,
32065
- isDisabled: disabled,
32066
- isRequired: required,
32067
- onBlur,
32068
- onFocus,
32069
- className
32070
- }, () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, inputElement, labelElement)),
32071
- renderDescription: () => /* @__PURE__ */ React40__default.createElement(React40__default.Fragment, null, descriptionElement, errorElement)
32072
- });
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));
32073
32084
  };
32074
- var Input = (_ref2) => {
32085
+ var Input = (_ref3) => {
32075
32086
  let {
32076
32087
  className
32077
- } = _ref2;
32088
+ } = _ref3;
32078
32089
  return /* @__PURE__ */ React40__default.createElement("div", {
32079
32090
  "aria-hidden": "true",
32080
32091
  className
32081
32092
  });
32082
32093
  };
32083
- Checkbox.Label = RichLabel;
32084
- Checkbox.Input = Input;
32094
+ CheckboxContainer.Label = RichLabel;
32095
+ CheckboxContainer.Input = Input;
32096
+ Checkbox.Checkbox = CheckboxContainer;
32085
32097
  Checkbox.Description = Description;
32086
32098
  Checkbox.Error = Error2;
32087
32099
 
@@ -32362,12 +32374,33 @@ var Options = (_ref2) => {
32362
32374
  isOther: true
32363
32375
  }));
32364
32376
  };
32365
- 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) => {
32366
32399
  let {
32367
32400
  children,
32368
32401
  className,
32369
32402
  ...internal
32370
- } = _ref3;
32403
+ } = _ref5;
32371
32404
  const {
32372
32405
  value,
32373
32406
  label,
@@ -32382,9 +32415,7 @@ var Option = (_ref3) => {
32382
32415
  disabled,
32383
32416
  hasError,
32384
32417
  options,
32385
- addOtherLabel,
32386
- addOtherPlaceholder,
32387
- otherInputCharacterLimit
32418
+ addOtherLabel
32388
32419
  } = props;
32389
32420
  const checkboxRef = useRef(null);
32390
32421
  useFocusFieldEvent(() => {
@@ -32395,17 +32426,9 @@ var Option = (_ref3) => {
32395
32426
  });
32396
32427
  }
32397
32428
  }, fieldId);
32398
- const labelElement = findChildOfType(children, Option.Label);
32399
- const inputElement = findChildOfType(children, Option.Input);
32400
- const otherInputElement = findChildOfType(children, Option.OtherInput);
32429
+ const labelElement = findChildOfType(children, Checkbox2.Label);
32430
+ const inputElement = findChildOfType(children, Checkbox2.Input);
32401
32431
  const _value = useMemo(() => fieldValue || [], [fieldValue]);
32402
- const isOtherSelected = useMemo(() => {
32403
- if (!isOther) {
32404
- return false;
32405
- }
32406
- const optionsValues = getOptionsValues(options || []);
32407
- return getIsOtherOptionSelected(_value, optionsValues);
32408
- }, [isOther, _value, options]);
32409
32432
  const actualValue = useMemo(() => {
32410
32433
  if (isOther) {
32411
32434
  return _value.find((val) => val === label || val.startsWith(`${addOtherLabel}: `)) || label;
@@ -32431,6 +32454,49 @@ var Option = (_ref3) => {
32431
32454
  "data-hook": `checkbox-${label}`
32432
32455
  }, inputElement, applyInternalProps(labelElement, {
32433
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
32434
32500
  }), isOther && isOtherSelected && applyInternalProps(otherInputElement, {
32435
32501
  fieldValue: _value,
32436
32502
  onChange,
@@ -32444,32 +32510,11 @@ var Option = (_ref3) => {
32444
32510
  options
32445
32511
  }));
32446
32512
  };
32447
- var OptionInput = (_ref4) => {
32448
- let {
32449
- className
32450
- } = _ref4;
32451
- return /* @__PURE__ */ React40__default.createElement("div", {
32452
- "aria-hidden": "true",
32453
- className
32454
- });
32455
- };
32456
- var OptionLabel = (_ref5) => {
32457
- let {
32458
- className,
32459
- ...internal
32460
- } = _ref5;
32461
- const {
32462
- label
32463
- } = internal;
32464
- return /* @__PURE__ */ React40__default.createElement("span", {
32465
- className
32466
- }, label);
32467
- };
32468
- var OtherInput = (_ref6) => {
32513
+ var OtherInput = (_ref7) => {
32469
32514
  let {
32470
32515
  className,
32471
32516
  ...internal
32472
- } = _ref6;
32517
+ } = _ref7;
32473
32518
  const {
32474
32519
  fieldValue,
32475
32520
  onChange,
@@ -32520,8 +32565,7 @@ var OtherInput = (_ref6) => {
32520
32565
  CheckboxGroup.Label = Label;
32521
32566
  CheckboxGroup.Options = Options;
32522
32567
  Options.Option = Option;
32523
- Option.Label = OptionLabel;
32524
- Option.Input = OptionInput;
32568
+ Option.Checkbox = Checkbox2;
32525
32569
  Option.OtherInput = OtherInput;
32526
32570
  CheckboxGroup.Description = Description;
32527
32571
  CheckboxGroup.Error = Error2;