@launchpad-ui/form 0.15.17 → 0.15.19

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.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import './style.css';
2
- import { Children, cloneElement, forwardRef, isValidElement, useMemo, useRef, useState } from "react";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import { forwardRef, useRef, useMemo, useState, cloneElement, Children, isValidElement } from "react";
3
4
  import { cx } from "classix";
4
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Icon } from "@launchpad-ui/icons";
6
6
  import { IconButton } from "@launchpad-ui/button";
7
7
  import { Tooltip } from "@launchpad-ui/tooltip";
@@ -10,460 +10,560 @@ import { useLocale } from "react-aria/I18nProvider";
10
10
  import { useButton } from "react-aria/useButton";
11
11
  import { useNumberField as useNumberField$1 } from "react-aria/useNumberField";
12
12
  import { useNumberFieldState } from "react-stately/useNumberFieldState";
13
- const checkbox = "QJPOUG_checkbox";
14
- const compactTextField = "QJPOUG_compactTextField";
15
- const field = "QJPOUG_field";
16
- const fieldError = "QJPOUG_fieldError";
17
- const fieldErrorMessage = "QJPOUG_fieldErrorMessage";
18
- const fieldSet = "QJPOUG_fieldSet";
19
- const form = "QJPOUG_form";
20
- const formGroup = "QJPOUG_formGroup";
21
- const formIncreasedErrorMargin = "QJPOUG_formIncreasedErrorMargin";
22
- const formInline = "QJPOUG_formInline";
23
- const formInput = "QJPOUG_formInput";
24
- const formInputTiny = "QJPOUG_formInputTiny";
25
- const hint = "QJPOUG_hint";
26
- const iconField = "QJPOUG_iconField";
27
- const iconFieldButton = "QJPOUG_iconFieldButton";
28
- const iconFieldIcon = "QJPOUG_iconFieldIcon";
29
- const iconFieldIconFill = "QJPOUG_iconFieldIconFill";
30
- const inlineForm = "QJPOUG_inlineForm";
31
- const isActive = "QJPOUG_isActive";
32
- const isDisabled = "QJPOUG_isDisabled";
33
- const isFocused = "QJPOUG_isFocused";
34
- const isInvalid = "QJPOUG_isInvalid";
35
- const label = "QJPOUG_label";
36
- const labelDisabled = "QJPOUG_labelDisabled";
37
- const labelOptional = "QJPOUG_labelOptional";
38
- const number = "QJPOUG_number";
39
- const numberField = "QJPOUG_numberField";
40
- const radio = "QJPOUG_radio";
41
- const requiredAsterisk = "QJPOUG_requiredAsterisk";
42
- const suffix = "QJPOUG_suffix";
43
- const suffixContainer = "QJPOUG_suffixContainer";
44
- var Form_module_default = {
45
- checkbox,
46
- compactTextField,
47
- field,
48
- fieldError,
49
- fieldErrorMessage,
50
- fieldSet,
51
- form,
52
- formGroup,
53
- formIncreasedErrorMargin,
54
- formInline,
55
- formInput,
56
- formInputTiny,
57
- hint,
58
- iconField,
59
- iconFieldButton,
60
- iconFieldIcon,
61
- iconFieldIconFill,
62
- inlineForm,
63
- isActive,
64
- isDisabled,
65
- isFocused,
66
- isInvalid,
67
- label,
68
- labelDisabled,
69
- labelOptional,
70
- number,
71
- numberField,
72
- "numberField-input": "QJPOUG_numberField-input",
73
- "numberField-stepper": "QJPOUG_numberField-stepper",
74
- "numberField-stepperContainer": "QJPOUG_numberField-stepperContainer",
75
- radio,
76
- requiredAsterisk,
77
- suffix,
78
- suffixContainer
13
+ const checkbox = "_1FRyG_checkbox";
14
+ const compactTextField = "_1FRyG_compactTextField";
15
+ const field = "_1FRyG_field";
16
+ const fieldError = "_1FRyG_fieldError";
17
+ const fieldErrorMessage = "_1FRyG_fieldErrorMessage";
18
+ const fieldSet = "_1FRyG_fieldSet";
19
+ const form = "_1FRyG_form";
20
+ const formGroup = "_1FRyG_formGroup";
21
+ const formIncreasedErrorMargin = "_1FRyG_formIncreasedErrorMargin";
22
+ const formInline = "_1FRyG_formInline";
23
+ const formInput = "_1FRyG_formInput";
24
+ const formInputTiny = "_1FRyG_formInputTiny";
25
+ const hint = "_1FRyG_hint";
26
+ const iconField = "_1FRyG_iconField";
27
+ const iconFieldButton = "_1FRyG_iconFieldButton";
28
+ const iconFieldIcon = "_1FRyG_iconFieldIcon";
29
+ const iconFieldIconFill = "_1FRyG_iconFieldIconFill";
30
+ const isActive = "_1FRyG_isActive";
31
+ const isInvalid = "_1FRyG_isInvalid";
32
+ const label = "_1FRyG_label";
33
+ const labelDisabled = "_1FRyG_labelDisabled";
34
+ const labelOptional = "_1FRyG_labelOptional";
35
+ const numberField = "_1FRyG_numberField";
36
+ const radio = "_1FRyG_radio";
37
+ const requiredAsterisk = "_1FRyG_requiredAsterisk";
38
+ const suffix = "_1FRyG_suffix";
39
+ const suffixContainer = "_1FRyG_suffixContainer";
40
+ const styles = {
41
+ checkbox,
42
+ compactTextField,
43
+ field,
44
+ fieldError,
45
+ fieldErrorMessage,
46
+ fieldSet,
47
+ form,
48
+ formGroup,
49
+ formIncreasedErrorMargin,
50
+ formInline,
51
+ formInput,
52
+ formInputTiny,
53
+ hint,
54
+ iconField,
55
+ iconFieldButton,
56
+ iconFieldIcon,
57
+ iconFieldIconFill,
58
+ isActive,
59
+ isInvalid,
60
+ label,
61
+ labelDisabled,
62
+ labelOptional,
63
+ numberField,
64
+ "numberField-input": "_1FRyG_numberField-input",
65
+ "numberField-stepper": "_1FRyG_numberField-stepper",
66
+ "numberField-stepperContainer": "_1FRyG_numberField-stepperContainer",
67
+ radio,
68
+ requiredAsterisk,
69
+ suffix,
70
+ suffixContainer
79
71
  };
80
- var RequiredAsterisk = ({ className, "data-test-id": testId = "required-asterisk", ...rest }) => {
81
- const classes = cx(Form_module_default.requiredAsterisk, className);
82
- return /* @__PURE__ */ jsx("span", {
83
- ...rest,
84
- "data-test-id": testId,
85
- className: classes,
86
- children: "*"
87
- });
72
+ const RequiredAsterisk = ({
73
+ className,
74
+ "data-test-id": testId = "required-asterisk",
75
+ ...rest
76
+ }) => {
77
+ const classes = cx(styles.requiredAsterisk, className);
78
+ return /* @__PURE__ */ jsx("span", { ...rest, "data-test-id": testId, className: classes, children: "*" });
88
79
  };
89
- var Label = ({ disabled, className, children, required = false, optional = false, "data-test-id": testId = "label", ...rest }) => {
90
- const classes = cx(Form_module_default.label, className, disabled && Form_module_default.labelDisabled);
91
- return /* @__PURE__ */ jsxs("label", {
92
- ...rest,
93
- "data-test-id": testId,
94
- className: classes,
95
- children: [
96
- children,
97
- optional && !required && /* @__PURE__ */ jsx("small", {
98
- className: Form_module_default.labelOptional,
99
- children: "(optional)"
100
- }),
101
- required && !optional && /* @__PURE__ */ jsx(RequiredAsterisk, {})
102
- ]
103
- });
80
+ const Label = ({
81
+ disabled,
82
+ className,
83
+ children,
84
+ required = false,
85
+ optional = false,
86
+ "data-test-id": testId = "label",
87
+ ...rest
88
+ }) => {
89
+ const classes = cx(styles.label, className, disabled && styles.labelDisabled);
90
+ return /* @__PURE__ */ jsxs("label", { ...rest, "data-test-id": testId, className: classes, children: [
91
+ children,
92
+ optional && !required && /* @__PURE__ */ jsx("small", { className: styles.labelOptional, children: "(optional)" }),
93
+ required && !optional && /* @__PURE__ */ jsx(RequiredAsterisk, {})
94
+ ] });
104
95
  };
105
- var Checkbox = /* @__PURE__ */ forwardRef(({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, children, disabled, checked, labelClassName, "data-test-id": testId = "checkbox", ...rest }, ref) => {
106
- if (!children && !(ariaLabel !== void 0 || ariaLabelledby !== void 0)) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
107
- return /* @__PURE__ */ jsxs(Label, {
108
- className: labelClassName,
109
- children: [
110
- /* @__PURE__ */ jsx("input", {
111
- ...rest,
112
- ref,
113
- checked,
114
- "aria-checked": checked ? "true" : "false",
115
- "aria-label": ariaLabel,
116
- "aria-labelledby": ariaLabelledby,
117
- className: Form_module_default.checkbox,
118
- disabled,
119
- type: "checkbox",
120
- "data-test-id": testId
121
- }),
122
- " ",
123
- disabled ? /* @__PURE__ */ jsx("span", {
124
- className: Form_module_default.labelDisabled,
125
- children
126
- }) : children
127
- ]
128
- });
129
- });
96
+ const Checkbox = /* @__PURE__ */ forwardRef(
97
+ ({
98
+ "aria-label": ariaLabel,
99
+ "aria-labelledby": ariaLabelledby,
100
+ children,
101
+ disabled,
102
+ checked,
103
+ labelClassName,
104
+ "data-test-id": testId = "checkbox",
105
+ ...rest
106
+ }, ref) => {
107
+ const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
108
+ if (!children && !hasAriaLabel) {
109
+ console.warn("If you do not provide children, you must specify an aria-label for accessibility");
110
+ }
111
+ return /* @__PURE__ */ jsxs(Label, { className: labelClassName, children: [
112
+ /* @__PURE__ */ jsx(
113
+ "input",
114
+ {
115
+ ...rest,
116
+ ref,
117
+ checked,
118
+ "aria-checked": checked ? "true" : "false",
119
+ "aria-label": ariaLabel,
120
+ "aria-labelledby": ariaLabelledby,
121
+ className: styles.checkbox,
122
+ disabled,
123
+ type: "checkbox",
124
+ "data-test-id": testId
125
+ }
126
+ ),
127
+ " ",
128
+ disabled ? /* @__PURE__ */ jsx("span", { className: styles.labelDisabled, children }) : children
129
+ ] });
130
+ }
131
+ );
130
132
  Checkbox.displayName = "Checkbox";
131
- var createFieldErrorId = (fieldIdentifier) => fieldIdentifier ? `${[...fieldIdentifier].join("")}-err` : void 0;
133
+ const createFieldErrorId = (fieldIdentifier) => fieldIdentifier ? `${[...fieldIdentifier].join("")}-err` : void 0;
132
134
  function hasObjectChanged(obj1, obj2) {
133
- return Object.keys(obj1).length !== Object.keys(obj2).length || Object.keys(obj1).some((k) => {
134
- const key = k;
135
- return typeof obj1[key] === "object" && typeof obj2[key] === "object" ? hasObjectChanged(obj1[key], obj2[key]) : obj1[key] !== obj2[key];
136
- });
135
+ return Object.keys(obj1).length !== Object.keys(obj2).length || Object.keys(obj1).some((k) => {
136
+ const key = k;
137
+ return typeof obj1[key] === "object" && typeof obj2[key] === "object" ? hasObjectChanged(obj1[key], obj2[key]) : obj1[key] !== obj2[key];
138
+ });
137
139
  }
138
140
  function useObjectMemo(obj) {
139
- const objRef = useRef(obj);
140
- return useMemo(() => {
141
- if (hasObjectChanged(obj, objRef.current)) objRef.current = obj;
142
- return objRef.current;
143
- }, [obj]);
141
+ const objRef = useRef(obj);
142
+ return useMemo(() => {
143
+ if (hasObjectChanged(obj, objRef.current)) {
144
+ objRef.current = obj;
145
+ }
146
+ return objRef.current;
147
+ }, [obj]);
144
148
  }
145
- var TextField = /* @__PURE__ */ forwardRef(({ className, type = "text", tiny = false, readOnly, tabIndex = 0, suffix: suffix$1, overrideWidth, "data-test-id": testId = "text-field", autoComplete, ...rest }, ref) => {
146
- const classes = overrideWidth ? className : cx(Form_module_default.formInput, tiny && Form_module_default.formInputTiny, className);
147
- const disablePasswordManagers = autoComplete === "off";
148
- if (suffix$1) return /* @__PURE__ */ jsxs("div", {
149
- className: Form_module_default.suffixContainer,
150
- children: [/* @__PURE__ */ jsx("input", {
151
- ...rest,
152
- type,
153
- "data-test-id": testId,
154
- autoComplete,
155
- className: classes,
156
- readOnly,
157
- ref,
158
- "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
159
- }), /* @__PURE__ */ jsx("label", {
160
- className: Form_module_default.suffix,
161
- htmlFor: rest.id,
162
- children: suffix$1
163
- })]
164
- });
165
- return /* @__PURE__ */ jsx("input", {
166
- ...rest,
167
- "data-1p-ignore": disablePasswordManagers,
168
- type,
169
- className: classes,
170
- readOnly,
171
- tabIndex,
172
- autoComplete,
173
- ref,
174
- "data-test-id": testId,
175
- style: overrideWidth ? { width: overrideWidth } : void 0,
176
- "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
177
- });
178
- });
149
+ const TextField = /* @__PURE__ */ forwardRef(
150
+ ({
151
+ className,
152
+ type = "text",
153
+ tiny = false,
154
+ readOnly,
155
+ tabIndex = 0,
156
+ suffix: suffix2,
157
+ overrideWidth,
158
+ "data-test-id": testId = "text-field",
159
+ autoComplete,
160
+ ...rest
161
+ }, ref) => {
162
+ const classes = overrideWidth ? className : cx(styles.formInput, tiny && styles.formInputTiny, className);
163
+ const disablePasswordManagers = autoComplete === "off";
164
+ if (suffix2) {
165
+ return /* @__PURE__ */ jsxs("div", { className: styles.suffixContainer, children: [
166
+ /* @__PURE__ */ jsx(
167
+ "input",
168
+ {
169
+ ...rest,
170
+ type,
171
+ "data-test-id": testId,
172
+ autoComplete,
173
+ className: classes,
174
+ readOnly,
175
+ ref,
176
+ "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
177
+ }
178
+ ),
179
+ /* @__PURE__ */ jsx("label", { className: styles.suffix, htmlFor: rest.id, children: suffix2 })
180
+ ] });
181
+ }
182
+ return /* @__PURE__ */ jsx(
183
+ "input",
184
+ {
185
+ ...rest,
186
+ "data-1p-ignore": disablePasswordManagers,
187
+ type,
188
+ className: classes,
189
+ readOnly,
190
+ tabIndex,
191
+ autoComplete,
192
+ ref,
193
+ "data-test-id": testId,
194
+ style: overrideWidth ? {
195
+ width: overrideWidth
196
+ } : void 0,
197
+ "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
198
+ }
199
+ );
200
+ }
201
+ );
179
202
  TextField.displayName = "TextField";
180
- var CompactTextField = /* @__PURE__ */ forwardRef(({ className, id, label: label$1, needsErrorFeedback, value, onFocus, onBlur, "data-test-id": testId = "compact-text-field", ...rest }, ref) => {
181
- const [isActive$1, setIsActive] = useState((typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0);
182
- const isActiveState = isActive$1 || needsErrorFeedback;
183
- const classes = cx(Form_module_default.compactTextField, className, isActiveState && Form_module_default.isActive);
184
- const placeholder = isActiveState ? "" : label$1;
185
- const handleFocus = (event) => {
186
- setIsActive(true);
187
- if (onFocus) onFocus(event);
188
- };
189
- const handleBlur = (event) => {
190
- setIsActive((event.target.value || "").trim().length !== 0);
191
- if (onBlur) onBlur(event);
192
- };
193
- return /* @__PURE__ */ jsxs("div", {
194
- className: classes,
195
- "data-test-id": testId,
196
- children: [/* @__PURE__ */ jsx(Label, {
197
- htmlFor: id,
198
- children: label$1
199
- }), /* @__PURE__ */ jsx(TextField, {
200
- ...rest,
201
- id,
202
- placeholder,
203
- value,
204
- ref,
205
- onFocus: handleFocus,
206
- onBlur: handleBlur
207
- })]
208
- });
209
- });
203
+ const CompactTextField = /* @__PURE__ */ forwardRef(
204
+ ({
205
+ className,
206
+ id,
207
+ label: label2,
208
+ needsErrorFeedback,
209
+ value,
210
+ onFocus,
211
+ onBlur,
212
+ "data-test-id": testId = "compact-text-field",
213
+ ...rest
214
+ }, ref) => {
215
+ const [isActive2, setIsActive] = useState(
216
+ (typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0
217
+ );
218
+ const isActiveState = isActive2 || needsErrorFeedback;
219
+ const classes = cx(styles.compactTextField, className, isActiveState && styles.isActive);
220
+ const placeholder = isActiveState ? "" : label2;
221
+ const handleFocus = (event) => {
222
+ setIsActive(true);
223
+ if (onFocus) {
224
+ onFocus(event);
225
+ }
226
+ };
227
+ const handleBlur = (event) => {
228
+ const inputValue = event.target.value || "";
229
+ setIsActive(inputValue.trim().length !== 0);
230
+ if (onBlur) {
231
+ onBlur(event);
232
+ }
233
+ };
234
+ return /* @__PURE__ */ jsxs("div", { className: classes, "data-test-id": testId, children: [
235
+ /* @__PURE__ */ jsx(Label, { htmlFor: id, children: label2 }),
236
+ /* @__PURE__ */ jsx(
237
+ TextField,
238
+ {
239
+ ...rest,
240
+ id,
241
+ placeholder,
242
+ value,
243
+ ref,
244
+ onFocus: handleFocus,
245
+ onBlur: handleBlur
246
+ }
247
+ )
248
+ ] });
249
+ }
250
+ );
210
251
  CompactTextField.displayName = "CompactTextField";
211
- var FieldError = ({ name, errorMessage, className, "data-test-id": testId = "field-error", ...rest }) => {
212
- if (!errorMessage) return null;
213
- return /* @__PURE__ */ jsxs("span", {
214
- ...rest,
215
- className: cx(Form_module_default.fieldError, className),
216
- "aria-live": "polite",
217
- "data-test-id": testId,
218
- "aria-label": "Error",
219
- id: createFieldErrorId(name),
220
- children: [
221
- /* @__PURE__ */ jsx(Icon, {
222
- name: "alert-rhombus",
223
- size: "small"
224
- }),
225
- " ",
226
- errorMessage
227
- ]
228
- });
252
+ const FieldError = ({
253
+ name,
254
+ errorMessage,
255
+ className,
256
+ "data-test-id": testId = "field-error",
257
+ ...rest
258
+ }) => {
259
+ if (!errorMessage) {
260
+ return null;
261
+ }
262
+ return (
263
+ // biome-ignore lint/a11y/useAriaPropsSupportedByRole: ignore
264
+ /* @__PURE__ */ jsxs(
265
+ "span",
266
+ {
267
+ ...rest,
268
+ className: cx(styles.fieldError, className),
269
+ "aria-live": "polite",
270
+ "data-test-id": testId,
271
+ "aria-label": "Error",
272
+ id: createFieldErrorId(name),
273
+ children: [
274
+ /* @__PURE__ */ jsx(Icon, { name: "alert-rhombus", size: "small" }),
275
+ " ",
276
+ errorMessage
277
+ ]
278
+ }
279
+ )
280
+ );
229
281
  };
230
- var FieldSet = ({ children, className, "data-test-id": testId = "field-set", ...rest }) => {
231
- const classes = cx(Form_module_default.fieldSet, className);
232
- return /* @__PURE__ */ jsx("fieldset", {
233
- "data-test-id": testId,
234
- className: classes,
235
- ...rest,
236
- children
237
- });
282
+ const FieldSet = ({ children, className, "data-test-id": testId = "field-set", ...rest }) => {
283
+ const classes = cx(styles.fieldSet, className);
284
+ return /* @__PURE__ */ jsx("fieldset", { "data-test-id": testId, className: classes, ...rest, children });
238
285
  };
239
- var Form = (props) => {
240
- const { className, inline, children, hasIncreasedErrorMargin, "data-test-id": testId = "form", ...rest } = props;
241
- const classes = cx(Form_module_default.form, className, inline && Form_module_default.formInline, !!hasIncreasedErrorMargin && Form_module_default.formIncreasedErrorMargin);
242
- return /* @__PURE__ */ jsx("form", {
243
- ...rest,
244
- "data-test-id": testId,
245
- className: classes,
246
- children
247
- });
286
+ const Form = (props) => {
287
+ const { className, inline, children, hasIncreasedErrorMargin, "data-test-id": testId = "form", ...rest } = props;
288
+ const classes = cx(
289
+ styles.form,
290
+ className,
291
+ inline && styles.formInline,
292
+ !!hasIncreasedErrorMargin && styles.formIncreasedErrorMargin
293
+ );
294
+ return /* @__PURE__ */ jsx("form", { ...rest, "data-test-id": testId, className: classes, children });
248
295
  };
249
- var FormGroup = (props) => {
250
- const { className, name, ignoreValidation, isInvalid: isInvalid$1, children, "data-test-id": testId = "form-group", ...rest } = props;
251
- return /* @__PURE__ */ jsx("fieldset", {
252
- className: cx(Form_module_default.formGroup, className, !ignoreValidation && isInvalid$1 && Form_module_default.isInvalid),
253
- "data-test-id": testId,
254
- ...rest,
255
- children
256
- });
296
+ const FormGroup = (props) => {
297
+ const {
298
+ className,
299
+ // biome-ignore lint/correctness/noUnusedVariables: ignore
300
+ name,
301
+ ignoreValidation,
302
+ isInvalid: isInvalid2,
303
+ children,
304
+ "data-test-id": testId = "form-group",
305
+ ...rest
306
+ } = props;
307
+ const classes = cx(styles.formGroup, className, !ignoreValidation && isInvalid2 && styles.isInvalid);
308
+ return /* @__PURE__ */ jsx("fieldset", { className: classes, "data-test-id": testId, ...rest, children });
257
309
  };
258
- var FormHint = ({ className, children, "data-test-id": testId = "form-hint", ...rest }) => {
259
- const classes = cx(Form_module_default.hint, className);
260
- return /* @__PURE__ */ jsx("div", {
261
- ...rest,
262
- "data-test-id": testId,
263
- className: classes,
264
- children
265
- });
310
+ const FormHint = ({ className, children, "data-test-id": testId = "form-hint", ...rest }) => {
311
+ const classes = cx(styles.hint, className);
312
+ return /* @__PURE__ */ jsx("div", { ...rest, "data-test-id": testId, className: classes, children });
266
313
  };
267
- var FormField = ({ isRequired, label: label$1, name, htmlFor, hint: hint$1, errorMessage, ignoreValidation, isInvalid: isInvalid$1, children, className, onBlur, "data-test-id": testId = "form-field", LabelProps = {}, FormHintProps = {}, FieldErrorProps = {} }) => {
268
- const handleBlur = () => {
269
- onBlur?.(name);
270
- };
271
- return /* @__PURE__ */ jsxs(FormGroup, {
272
- className: cx(Form_module_default.field, className),
273
- name,
274
- ignoreValidation,
275
- isInvalid: isInvalid$1,
276
- onBlur: handleBlur,
277
- "data-test-id": testId,
278
- children: [
279
- label$1 && /* @__PURE__ */ jsx(Label, {
280
- htmlFor,
281
- required: isRequired,
282
- ...LabelProps,
283
- children: label$1
284
- }),
285
- hint$1 && /* @__PURE__ */ jsx(FormHint, {
286
- className: Form_module_default.hint,
287
- ...FormHintProps,
288
- children: hint$1
289
- }),
290
- children,
291
- /* @__PURE__ */ jsx(FieldError, {
292
- className: Form_module_default.fieldErrorMessage,
293
- name,
294
- errorMessage,
295
- ...FieldErrorProps
296
- })
297
- ]
298
- });
314
+ const FormField = ({
315
+ isRequired,
316
+ label: label2,
317
+ name,
318
+ htmlFor,
319
+ hint: hint2,
320
+ errorMessage,
321
+ ignoreValidation,
322
+ isInvalid: isInvalid2,
323
+ children,
324
+ className,
325
+ onBlur,
326
+ "data-test-id": testId = "form-field",
327
+ LabelProps = {},
328
+ FormHintProps = {},
329
+ FieldErrorProps = {}
330
+ }) => {
331
+ const handleBlur = () => {
332
+ onBlur?.(name);
333
+ };
334
+ return /* @__PURE__ */ jsxs(
335
+ FormGroup,
336
+ {
337
+ className: cx(styles.field, className),
338
+ name,
339
+ ignoreValidation,
340
+ isInvalid: isInvalid2,
341
+ onBlur: handleBlur,
342
+ "data-test-id": testId,
343
+ children: [
344
+ label2 && /* @__PURE__ */ jsx(Label, { htmlFor, required: isRequired, ...LabelProps, children: label2 }),
345
+ hint2 && /* @__PURE__ */ jsx(FormHint, { className: styles.hint, ...FormHintProps, children: hint2 }),
346
+ children,
347
+ /* @__PURE__ */ jsx(FieldError, { className: styles.fieldErrorMessage, name, errorMessage, ...FieldErrorProps })
348
+ ]
349
+ }
350
+ );
299
351
  };
300
- var IconField = ({ icon, children, className, "data-test-id": testId = "icon-field", tooltip, renderIconLast = false, ariaLabel = "More info", ...rest }) => {
301
- const iconElement = /* @__PURE__ */ cloneElement(icon, {
302
- size: "small",
303
- className: cx(Form_module_default.iconFieldIcon, Form_module_default.iconFieldIconFill)
304
- });
305
- const classes = cx(Form_module_default.iconField, renderIconLast ? "IconAfter" : "IconBefore", className);
306
- const renderIcon = tooltip ? /* @__PURE__ */ jsx(Tooltip, {
307
- content: tooltip,
308
- targetClassName: Form_module_default.iconFieldButton,
309
- children: /* @__PURE__ */ jsx(IconButton, {
310
- icon: /* @__PURE__ */ cloneElement(icon, { className: Form_module_default.iconFieldIconFill }),
311
- size: "small",
312
- className: Form_module_default.iconFieldIcon,
313
- style: renderIconLast ? { right: "0.313rem" } : { left: "0.313rem" },
314
- "aria-label": ariaLabel
315
- })
316
- }) : iconElement;
317
- return /* @__PURE__ */ jsxs("div", {
318
- className: classes,
319
- "data-test-id": testId,
320
- ...rest,
321
- children: [
322
- !renderIconLast && renderIcon,
323
- children,
324
- renderIconLast && renderIcon
325
- ]
326
- });
352
+ const IconField = ({
353
+ icon,
354
+ children,
355
+ className,
356
+ "data-test-id": testId = "icon-field",
357
+ tooltip,
358
+ renderIconLast = false,
359
+ ariaLabel = "More info",
360
+ ...rest
361
+ }) => {
362
+ const iconElement = /* @__PURE__ */ cloneElement(icon, {
363
+ size: "small",
364
+ className: cx(styles.iconFieldIcon, styles.iconFieldIconFill)
365
+ });
366
+ const classes = cx(styles.iconField, renderIconLast ? "IconAfter" : "IconBefore", className);
367
+ const renderIcon = tooltip ? /* @__PURE__ */ jsx(Tooltip, { content: tooltip, targetClassName: styles.iconFieldButton, children: /* @__PURE__ */ jsx(
368
+ IconButton,
369
+ {
370
+ icon: /* @__PURE__ */ cloneElement(icon, {
371
+ className: styles.iconFieldIconFill
372
+ }),
373
+ size: "small",
374
+ className: styles.iconFieldIcon,
375
+ style: renderIconLast ? { right: "0.313rem" } : { left: "0.313rem" },
376
+ "aria-label": ariaLabel
377
+ }
378
+ ) }) : iconElement;
379
+ return /* @__PURE__ */ jsxs("div", { className: classes, "data-test-id": testId, ...rest, children: [
380
+ !renderIconLast && renderIcon,
381
+ children,
382
+ renderIconLast && renderIcon
383
+ ] });
327
384
  };
328
- var Radio = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, checked = false, children, className, disabled = false, id, labelClassName, labelStyle, "data-test-id": testId = "radio", ...rest }) => {
329
- if (!children && !(ariaLabel !== void 0 || ariaLabelledby !== void 0)) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
330
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
331
- ...rest,
332
- "aria-label": ariaLabel,
333
- "aria-labelledby": ariaLabelledby,
334
- className: cx(Form_module_default.radio, className),
335
- checked,
336
- disabled,
337
- id,
338
- "data-test-id": testId,
339
- type: "radio"
340
- }), /* @__PURE__ */ jsx(Label, {
341
- className: labelClassName,
342
- htmlFor: id,
343
- style: labelStyle,
344
- children: disabled ? /* @__PURE__ */ jsx("span", {
345
- className: Form_module_default.labelDisabled,
346
- children
347
- }) : children
348
- })] });
385
+ const Radio = ({
386
+ "aria-label": ariaLabel,
387
+ "aria-labelledby": ariaLabelledby,
388
+ checked = false,
389
+ children,
390
+ className,
391
+ disabled = false,
392
+ id,
393
+ labelClassName,
394
+ labelStyle,
395
+ "data-test-id": testId = "radio",
396
+ ...rest
397
+ }) => {
398
+ const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
399
+ if (!children && !hasAriaLabel) {
400
+ console.warn("If you do not provide children, you must specify an aria-label for accessibility");
401
+ }
402
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
403
+ /* @__PURE__ */ jsx(
404
+ "input",
405
+ {
406
+ ...rest,
407
+ "aria-label": ariaLabel,
408
+ "aria-labelledby": ariaLabelledby,
409
+ className: cx(styles.radio, className),
410
+ checked,
411
+ disabled,
412
+ id,
413
+ "data-test-id": testId,
414
+ type: "radio"
415
+ }
416
+ ),
417
+ /* @__PURE__ */ jsx(Label, { className: labelClassName, htmlFor: id, style: labelStyle, children: disabled ? /* @__PURE__ */ jsx("span", { className: styles.labelDisabled, children }) : children })
418
+ ] });
349
419
  };
350
- var RadioGroup = (props) => {
351
- const { name, value, onChange, children, disabled, legend, "data-test-id": testId = "radio-group", ...rest } = props;
352
- const fieldsetRef = useRef(null);
353
- function updateRadioElems(elem) {
354
- if (!/* @__PURE__ */ isValidElement(elem)) return elem;
355
- const item = elem;
356
- if (item?.type && item.type === Radio) return /* @__PURE__ */ cloneElement(item, {
357
- ...item.props,
358
- name,
359
- checked: item.props.value === value,
360
- onChange,
361
- disabled: typeof item.props?.disabled !== "undefined" ? item.props.disabled : disabled
362
- });
363
- if (item?.type && item.type === Label) return /* @__PURE__ */ cloneElement(item, {
364
- ...item.props,
365
- onChange,
366
- disabled
367
- });
368
- const elemChildren = item?.props?.children;
369
- if (elemChildren) {
370
- if (Array.isArray(elemChildren)) return /* @__PURE__ */ cloneElement(item, { children: Children.map(elemChildren, (elemChild) => updateRadioElems(elemChild)) });
371
- return /* @__PURE__ */ cloneElement(item, { children: updateRadioElems(elemChildren) });
372
- }
373
- if (item?.type && item.type !== Radio && item.type !== Label) return item;
374
- return null;
375
- }
376
- const radios = Children.map(children, (child) => updateRadioElems(child));
377
- return /* @__PURE__ */ jsxs("fieldset", {
378
- "data-test-id": testId,
379
- ref: fieldsetRef,
380
- children: [legend && /* @__PURE__ */ jsx("legend", { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: legend }) }), /* @__PURE__ */ jsx("div", {
381
- ...rest,
382
- children: radios
383
- })]
384
- });
420
+ const RadioGroup = (props) => {
421
+ const { name, value, onChange, children, disabled, legend, "data-test-id": testId = "radio-group", ...rest } = props;
422
+ const fieldsetRef = useRef(null);
423
+ function updateRadioElems(elem) {
424
+ if (!/* @__PURE__ */ isValidElement(elem)) {
425
+ return elem;
426
+ }
427
+ const item = elem;
428
+ if (item?.type && item.type === Radio) {
429
+ return /* @__PURE__ */ cloneElement(item, {
430
+ ...item.props,
431
+ name,
432
+ checked: item.props.value === value,
433
+ onChange,
434
+ disabled: typeof item.props?.disabled !== "undefined" ? item.props.disabled : disabled
435
+ });
436
+ }
437
+ if (item?.type && item.type === Label) {
438
+ return /* @__PURE__ */ cloneElement(item, {
439
+ ...item.props,
440
+ onChange,
441
+ disabled
442
+ });
443
+ }
444
+ const elemChildren = item?.props?.children;
445
+ if (elemChildren) {
446
+ if (Array.isArray(elemChildren)) {
447
+ return /* @__PURE__ */ cloneElement(item, {
448
+ children: Children.map(elemChildren, (elemChild) => updateRadioElems(elemChild))
449
+ });
450
+ }
451
+ return /* @__PURE__ */ cloneElement(item, {
452
+ children: updateRadioElems(elemChildren)
453
+ });
454
+ }
455
+ if (item?.type && item.type !== Radio && item.type !== Label) {
456
+ return item;
457
+ }
458
+ return null;
459
+ }
460
+ const radios = Children.map(children, (child) => updateRadioElems(child));
461
+ return /* @__PURE__ */ jsxs("fieldset", { "data-test-id": testId, ref: fieldsetRef, children: [
462
+ legend && /* @__PURE__ */ jsx("legend", { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: legend }) }),
463
+ /* @__PURE__ */ jsx("div", { ...rest, children: radios })
464
+ ] });
385
465
  };
386
- var SelectField = /* @__PURE__ */ forwardRef(({ className, children, "data-test-id": testId = "select", ...rest }, ref) => {
387
- const classes = cx(Form_module_default.formInput, className);
388
- return /* @__PURE__ */ jsx("select", {
389
- ...rest,
390
- "data-test-id": testId,
391
- className: classes,
392
- ref,
393
- children
394
- });
395
- });
466
+ const SelectField = /* @__PURE__ */ forwardRef(
467
+ ({ className, children, "data-test-id": testId = "select", ...rest }, ref) => {
468
+ const classes = cx(styles.formInput, className);
469
+ return /* @__PURE__ */ jsx("select", { ...rest, "data-test-id": testId, className: classes, ref, children });
470
+ }
471
+ );
396
472
  SelectField.displayName = "SelectField";
397
- var TextArea = /* @__PURE__ */ forwardRef(({ className, "data-test-id": testId = "text-area", ...props }, ref) => {
398
- const onKeyDown = (e) => {
399
- if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") e.stopPropagation();
400
- if (e.key === "Escape") e.nativeEvent.stopImmediatePropagation();
401
- };
402
- return /* @__PURE__ */ jsx("textarea", {
403
- ...props,
404
- className: cx(Form_module_default.formInput, className),
405
- ref,
406
- "data-test-id": testId,
407
- "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
408
- onKeyDown
409
- });
410
- });
473
+ const TextArea = /* @__PURE__ */ forwardRef(
474
+ ({ className, "data-test-id": testId = "text-area", ...props }, ref) => {
475
+ const onKeyDown = (e) => {
476
+ if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
477
+ e.stopPropagation();
478
+ }
479
+ if (e.key === "Escape") {
480
+ e.nativeEvent.stopImmediatePropagation();
481
+ }
482
+ };
483
+ return /* @__PURE__ */ jsx(
484
+ "textarea",
485
+ {
486
+ ...props,
487
+ className: cx(styles.formInput, className),
488
+ ref,
489
+ "data-test-id": testId,
490
+ "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
491
+ onKeyDown
492
+ }
493
+ );
494
+ }
495
+ );
411
496
  TextArea.displayName = "TextArea";
412
- var defaultFormatOptions = { maximumFractionDigits: 6 };
413
- var useNumberField = ({ className, "data-test-id": testId = "input", id, name, ...otherProps } = {}) => {
414
- const formatOptions = useObjectMemo({
415
- ...defaultFormatOptions,
416
- ...otherProps.formatOptions
417
- });
418
- const { locale } = useLocale();
419
- const numberFieldState = useNumberFieldState({
420
- ...otherProps,
421
- locale,
422
- formatOptions
423
- });
424
- const inputRef = useRef(null);
425
- const { descriptionProps: formHintProps, errorMessageProps: fieldErrorProps, labelProps, groupProps, inputProps, incrementButtonProps, decrementButtonProps } = useNumberField$1({
426
- ...otherProps,
427
- formatOptions,
428
- id
429
- }, numberFieldState, inputRef);
430
- return {
431
- fieldErrorProps,
432
- formHintProps,
433
- labelProps,
434
- renderNumberField: () => /* @__PURE__ */ jsxs("div", {
435
- ...groupProps,
436
- className: Form_module_default.numberField,
437
- children: [/* @__PURE__ */ jsx("input", {
438
- ...inputProps,
439
- className: cx(Form_module_default.formInput, Form_module_default["numberField-input"]),
440
- "data-test-id": testId,
441
- name,
442
- ref: inputRef
443
- }), /* @__PURE__ */ jsxs("div", {
444
- className: Form_module_default["numberField-stepperContainer"],
445
- children: [/* @__PURE__ */ jsx(Stepper, {
446
- ...incrementButtonProps,
447
- children: /* @__PURE__ */ jsx(Icon, { name: "chevron-up" })
448
- }), /* @__PURE__ */ jsx(Stepper, {
449
- ...decrementButtonProps,
450
- children: /* @__PURE__ */ jsx(Icon, { name: "chevron-down" })
451
- })]
452
- })]
453
- })
454
- };
497
+ const defaultFormatOptions = {
498
+ maximumFractionDigits: 6
455
499
  };
456
- var Stepper = (props) => {
457
- const buttonRef = useRef(null);
458
- const { buttonProps } = useButton(props, buttonRef);
459
- return /* @__PURE__ */ jsx("button", {
460
- type: "button",
461
- ...buttonProps,
462
- className: Form_module_default["numberField-stepper"],
463
- ref: buttonRef,
464
- children: props.children
465
- });
500
+ const useNumberField = ({
501
+ className,
502
+ "data-test-id": testId = "input",
503
+ id,
504
+ name,
505
+ ...otherProps
506
+ } = {}) => {
507
+ const formatOptions = useObjectMemo({
508
+ ...defaultFormatOptions,
509
+ ...otherProps.formatOptions
510
+ });
511
+ const { locale } = useLocale();
512
+ const numberFieldState = useNumberFieldState({ ...otherProps, locale, formatOptions });
513
+ const inputRef = useRef(null);
514
+ const {
515
+ descriptionProps: formHintProps,
516
+ errorMessageProps: fieldErrorProps,
517
+ labelProps,
518
+ groupProps,
519
+ inputProps,
520
+ incrementButtonProps,
521
+ decrementButtonProps
522
+ } = useNumberField$1({ ...otherProps, formatOptions, id }, numberFieldState, inputRef);
523
+ return {
524
+ fieldErrorProps,
525
+ formHintProps,
526
+ labelProps,
527
+ renderNumberField: () => /* @__PURE__ */ jsxs("div", { ...groupProps, className: styles.numberField, children: [
528
+ /* @__PURE__ */ jsx(
529
+ "input",
530
+ {
531
+ ...inputProps,
532
+ className: cx(styles.formInput, styles["numberField-input"]),
533
+ "data-test-id": testId,
534
+ name,
535
+ ref: inputRef
536
+ }
537
+ ),
538
+ /* @__PURE__ */ jsxs("div", { className: styles["numberField-stepperContainer"], children: [
539
+ /* @__PURE__ */ jsx(Stepper, { ...incrementButtonProps, children: /* @__PURE__ */ jsx(Icon, { name: "chevron-up" }) }),
540
+ /* @__PURE__ */ jsx(Stepper, { ...decrementButtonProps, children: /* @__PURE__ */ jsx(Icon, { name: "chevron-down" }) })
541
+ ] })
542
+ ] })
543
+ };
466
544
  };
467
- export { Checkbox, CompactTextField, FieldError, FieldSet, Form, FormField, FormGroup, FormHint, IconField, Label, Radio, RadioGroup, RequiredAsterisk, SelectField, TextArea, TextField, useNumberField };
468
-
469
- //# sourceMappingURL=index.es.js.map
545
+ const Stepper = (props) => {
546
+ const buttonRef = useRef(null);
547
+ const { buttonProps } = useButton(props, buttonRef);
548
+ return /* @__PURE__ */ jsx("button", { type: "button", ...buttonProps, className: styles["numberField-stepper"], ref: buttonRef, children: props.children });
549
+ };
550
+ export {
551
+ Checkbox,
552
+ CompactTextField,
553
+ FieldError,
554
+ FieldSet,
555
+ Form,
556
+ FormField,
557
+ FormGroup,
558
+ FormHint,
559
+ IconField,
560
+ Label,
561
+ Radio,
562
+ RadioGroup,
563
+ RequiredAsterisk,
564
+ SelectField,
565
+ TextArea,
566
+ TextField,
567
+ useNumberField
568
+ };
569
+ //# sourceMappingURL=index.es.js.map