@wix/editor-react-components 1.2356.0 → 1.2357.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.
@@ -1,8 +1,9 @@
1
1
  import { A11y, Direction } from '@wix/editor-react-types';
2
2
  import { SdkFunctionFocusableProps } from '../../../utils/functions/sdkFunctionCallbackProps';
3
+ import { FieldValidationProps } from '../../../utils/validation/types';
3
4
  import { RadioButtonsDefaultSelection, RadioButtonsOption } from './constants';
4
5
  export type { RadioButtonsOption } from './constants';
5
- export type RadioButtonsProps = SdkFunctionFocusableProps & {
6
+ export type RadioButtonsProps = SdkFunctionFocusableProps & FieldValidationProps<string> & {
6
7
  id: string;
7
8
  className: string;
8
9
  options: Array<RadioButtonsOption>;
@@ -1,15 +1,16 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useId } from "react";
2
3
  import { c as clsx } from "../chunks/clsx.js";
3
4
  import { a as Fieldset, T as Tooltip, R as RadioGroup_RadioGroup_RadioGroup, b as Radio } from "../chunks/index10.js";
4
- import "react";
5
5
  import { useService } from "@wix/services-manager-react";
6
6
  import { E as EnvironmentDefinition } from "../chunks/index2.js";
7
7
  import { f as formatClassNames } from "../chunks/classNames.js";
8
8
  import { a as getDataAttributes } from "../chunks/dataUtils.js";
9
9
  import { R as RequiredIndicator, I as InfoCircleSmall_default } from "../chunks/RequiredIndicator.js";
10
+ import { u as useValidatedField } from "../chunks/useValidatedField.js";
10
11
  import { d as directionStyles } from "../chunks/direction.module.js";
11
12
  import { p as presetWrapperStyles } from "../chunks/presetWrapper.module.js";
12
- import { d as defaultValues, a as defaultOptions, s as selectors, T as TestIds, b as semanticClassNames } from "../chunks/constants24.js";
13
+ import { d as defaultValues, a as defaultOptions, V as VALUE_MISSING_MESSAGE, s as selectors, T as TestIds, b as semanticClassNames } from "../chunks/constants24.js";
13
14
  const root = "root__4SkBh";
14
15
  const fieldset = "fieldset__2OxuS";
15
16
  const labelRow = "labelRow__xKUgE";
@@ -21,6 +22,7 @@ const option = "option__hEAm9";
21
22
  const control = "control__w6l6-";
22
23
  const indicator = "indicator__m9-hW";
23
24
  const label = "label__bJi-o";
25
+ const errorMessage = "errorMessage__F6jDK";
24
26
  const styles = {
25
27
  root,
26
28
  fieldset,
@@ -32,7 +34,8 @@ const styles = {
32
34
  option,
33
35
  control,
34
36
  indicator,
35
- label
37
+ label,
38
+ errorMessage
36
39
  };
37
40
  const noop = () => {
38
41
  };
@@ -49,6 +52,10 @@ function RadioButtonsComponent(props) {
49
52
  onChange = noop,
50
53
  onFocus = noop,
51
54
  onBlur = noop,
55
+ fieldValidity,
56
+ showValidityIndication,
57
+ onValidate,
58
+ onValidityChange,
52
59
  wix
53
60
  } = props;
54
61
  const sourceOptions = Array.isArray(props.options) && props.options.length ? props.options : defaultOptions;
@@ -63,12 +70,37 @@ function RadioButtonsComponent(props) {
63
70
  const required = props.required ?? defaultValues.required;
64
71
  const disabled = props.disabled ?? defaultValues.disabled;
65
72
  const isControlled = props.value !== void 0;
66
- const selectionProps = isControlled ? { value: props.value } : {
67
- defaultValue: firstSelectedByDefault === "first" ? (_a = options[0]) == null ? void 0 : _a.value : void 0
68
- };
73
+ const defaultSelectedValue = firstSelectedByDefault === "first" ? (_a = options[0]) == null ? void 0 : _a.value : void 0;
74
+ const selectionProps = isControlled ? { value: props.value } : { defaultValue: defaultSelectedValue };
75
+ const [uncontrolledValue, setUncontrolledValue] = useState(defaultSelectedValue);
76
+ const currentValue = isControlled ? props.value : uncontrolledValue;
77
+ const intrinsic = required && !disabled && !readOnly && !currentValue ? { valid: false, validationMessage: VALUE_MISSING_MESSAGE } : { valid: true, validationMessage: "" };
78
+ const {
79
+ validity,
80
+ showValidityIndication: showIndication,
81
+ handleBlur: handleValidationBlur
82
+ } = useValidatedField({
83
+ value: currentValue ?? "",
84
+ intrinsic,
85
+ fieldValidity,
86
+ showValidityIndication,
87
+ onValidate,
88
+ onValidityChange
89
+ });
90
+ const isInvalid = showIndication && !validity.valid;
91
+ const errorId = useId();
69
92
  const handleValueChange = (next) => {
93
+ if (!isControlled) {
94
+ setUncontrolledValue(next);
95
+ }
70
96
  onChange(next);
71
97
  };
98
+ const handleBlur = (event) => {
99
+ onBlur(event);
100
+ if (!event.currentTarget.contains(event.relatedTarget)) {
101
+ handleValidationBlur();
102
+ }
103
+ };
72
104
  const hasLegend = !!label2;
73
105
  const ariaLabel = !hasLegend ? (a11y == null ? void 0 : a11y.ariaLabel) || void 0 : void 0;
74
106
  const presetsWrapperProps = (wix == null ? void 0 : wix.presetsWrapperProps) || {};
@@ -134,11 +166,13 @@ function RadioButtonsComponent(props) {
134
166
  disabled,
135
167
  readOnly,
136
168
  "aria-required": required || void 0,
169
+ "aria-invalid": isInvalid || void 0,
170
+ "aria-describedby": isInvalid && validity.validationMessage ? errorId : void 0,
137
171
  "aria-label": ariaLabel,
138
172
  className: styles.group,
139
173
  "data-testid": TestIds.group,
140
174
  onFocus,
141
- onBlur,
175
+ onBlur: handleBlur,
142
176
  children: options.map((option2, index) => /* @__PURE__ */ jsxs(
143
177
  "label",
144
178
  {
@@ -154,6 +188,7 @@ function RadioButtonsComponent(props) {
154
188
  value: option2.value,
155
189
  readOnly,
156
190
  disabled: disabled || !!option2.disabled,
191
+ "data-invalid": isInvalid || void 0,
157
192
  className: clsx(
158
193
  styles.control,
159
194
  selectors.radio,
@@ -191,6 +226,18 @@ function RadioButtonsComponent(props) {
191
226
  option2.value || index
192
227
  ))
193
228
  }
229
+ ),
230
+ isInvalid && validity.validationMessage && /* @__PURE__ */ jsx(
231
+ "div",
232
+ {
233
+ id: errorId,
234
+ className: clsx(
235
+ styles.errorMessage,
236
+ formatClassNames(semanticClassNames.errorMessage)
237
+ ),
238
+ "data-testid": TestIds.errorMessage,
239
+ children: validity.validationMessage
240
+ }
194
241
  )
195
242
  ] })
196
243
  }
@@ -79,6 +79,7 @@ export declare const defaultValues: {
79
79
  readonly readOnly: false;
80
80
  readonly disabled: false;
81
81
  };
82
+ export declare const VALUE_MISSING_MESSAGE = "This field is required";
82
83
  export declare const TestIds: {
83
84
  readonly root: "radio-buttons-root";
84
85
  readonly group: "radio-buttons-group";
@@ -89,6 +90,7 @@ export declare const TestIds: {
89
90
  readonly control: "radio-buttons-control";
90
91
  readonly indicator: "radio-buttons-indicator";
91
92
  readonly optionLabel: "radio-buttons-option-label";
93
+ readonly errorMessage: "radio-buttons-error-message";
92
94
  };
93
95
  export declare const selectors: {
94
96
  readonly root: "radio-buttons";
@@ -105,4 +107,5 @@ export declare const semanticClassNames: {
105
107
  readonly radio: "radio-buttons__radio";
106
108
  readonly indicator: "radio-buttons__indicator";
107
109
  readonly label: "radio-buttons__label";
110
+ readonly errorMessage: "radio-buttons__error-message";
108
111
  };
@@ -160,6 +160,12 @@
160
160
  .label__bJi-o {
161
161
  cursor: pointer;
162
162
  margin-bottom: 0;
163
+ }
164
+
165
+ .errorMessage__F6jDK {
166
+ align-self: var(--alignment, flex-start);
167
+ font: normal normal normal 12px/1.4em madefor-text, sans-serif;
168
+ color: var(--errorTextColor, #e62214);
163
169
  }.radio-buttons {
164
170
  --radiosSpacing: 6px;
165
171
  --labelSpacing: 16px;
@@ -3,6 +3,7 @@ import { D as DesignStates, c as DisplayNames, d as defaultValues, s as selector
3
3
  import { w as withSpec, g as getSelector } from "../chunks/manifest.js";
4
4
  import { I as IS_SUPPORT_DESIGN_STATE_SPEC } from "../chunks/specs.js";
5
5
  import { m as manifestFocusable, a as manifestChangeable } from "../chunks/manifestSdkMixins.js";
6
+ import { m as manifestValidation } from "../chunks/manifest2.js";
6
7
  const manifest = {
7
8
  id: "01a3965d-95d7-49e2-903a-3a496de97054",
8
9
  type: "wixEditorElements.RadioButtons__DEV__v3",
@@ -119,7 +120,8 @@ const manifest = {
119
120
  dataType: DATA.DATA_TYPE.direction
120
121
  },
121
122
  ...manifestChangeable(),
122
- ...manifestFocusable()
123
+ ...manifestFocusable(),
124
+ ...manifestValidation({ valueDataType: DATA.DATA_TYPE.text })
123
125
  },
124
126
  displayGroups: {
125
127
  optionsGroup: {
@@ -70,6 +70,7 @@ const defaultValues = {
70
70
  readOnly: false,
71
71
  disabled: false
72
72
  };
73
+ const VALUE_MISSING_MESSAGE = "This field is required";
73
74
  const TestIds = {
74
75
  root: "radio-buttons-root",
75
76
  group: "radio-buttons-group",
@@ -79,7 +80,8 @@ const TestIds = {
79
80
  option: "radio-buttons-option",
80
81
  control: "radio-buttons-control",
81
82
  indicator: "radio-buttons-indicator",
82
- optionLabel: "radio-buttons-option-label"
83
+ optionLabel: "radio-buttons-option-label",
84
+ errorMessage: "radio-buttons-error-message"
83
85
  };
84
86
  const selectors = {
85
87
  root: "radio-buttons",
@@ -94,11 +96,13 @@ const semanticClassNames = {
94
96
  option: "radio-buttons__option",
95
97
  radio: "radio-buttons__radio",
96
98
  indicator: "radio-buttons__indicator",
97
- label: "radio-buttons__label"
99
+ label: "radio-buttons__label",
100
+ errorMessage: "radio-buttons__error-message"
98
101
  };
99
102
  export {
100
103
  DesignStates as D,
101
104
  TestIds as T,
105
+ VALUE_MISSING_MESSAGE as V,
102
106
  defaultOptions as a,
103
107
  semanticClassNames as b,
104
108
  DisplayNames as c,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/editor-react-components",
3
- "version": "1.2356.0",
3
+ "version": "1.2357.0",
4
4
  "description": "React components for the Wix Editor",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -199,5 +199,5 @@
199
199
  "registry": "https://registry.npmjs.org/",
200
200
  "access": "public"
201
201
  },
202
- "falconPackageHash": "c933b35458ec28142d198d9bafec750fd29593d7bbe5fcd7f6570b9d"
202
+ "falconPackageHash": "d4bfc9da268b29efe1ddb1073eee5deb49e827b001018a694cf859ad"
203
203
  }