@launchpad-ui/form 0.15.16 → 0.15.18

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