@launchpad-ui/form 0.8.13 → 0.8.15

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,39 +1,44 @@
1
1
  require('./style.css');
2
2
  "use strict";
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const jsxRuntime = require("react/jsx-runtime");
4
5
  const react = require("react");
5
6
  const classix = require("classix");
6
- const jsxRuntime = require("react/jsx-runtime");
7
7
  const icons = require("@launchpad-ui/icons");
8
8
  const visuallyHidden = require("@react-aria/visually-hidden");
9
- const formGroup = "_formGroup_p76jo_10";
10
- const formIncreasedErrorMargin = "_formIncreasedErrorMargin_p76jo_18";
11
- const formInline = "_formInline_p76jo_22";
12
- const form = "_form_p76jo_10";
13
- const formInput = "_formInput_p76jo_36";
14
- const isFocused = "_isFocused_p76jo_56";
15
- const iconField = "_iconField_p76jo_73";
16
- const suffixContainer = "_suffixContainer_p76jo_77";
17
- const isInvalid = "_isInvalid_p76jo_82";
18
- const inlineForm = "_inlineForm_p76jo_93";
19
- const label = "_label_p76jo_98";
20
- const labelDisabled = "_labelDisabled_p76jo_104";
21
- const labelOptional = "_labelOptional_p76jo_108";
22
- const compactTextField = "_compactTextField_p76jo_114";
23
- const fieldError = "_fieldError_p76jo_138";
24
- const hint = "_hint_p76jo_184";
25
- const field = "_field_p76jo_138";
26
- const fieldErrorMessage = "_fieldErrorMessage_p76jo_204";
27
- const isDisabled = "_isDisabled_p76jo_217";
28
- const checkbox = "_checkbox_p76jo_284";
29
- const radio = "_radio_p76jo_291";
30
- const number = "_number_p76jo_295";
31
- const suffix = "_suffix_p76jo_77";
32
- const iconFieldIcon = "_iconFieldIcon_p76jo_333";
33
- const formInputTiny = "_formInputTiny_p76jo_341";
34
- const requiredAsterisk = "_requiredAsterisk_p76jo_350";
35
- const fieldSet = "_fieldSet_p76jo_354";
36
- const isActive = "_isActive_p76jo_365";
9
+ const button = require("@react-aria/button");
10
+ const i18n = require("@react-aria/i18n");
11
+ const numberfield$1 = require("@react-aria/numberfield");
12
+ const numberfield = require("@react-stately/numberfield");
13
+ const formGroup = "_formGroup_1u9hb_10";
14
+ const formIncreasedErrorMargin = "_formIncreasedErrorMargin_1u9hb_18";
15
+ const formInline = "_formInline_1u9hb_22";
16
+ const form = "_form_1u9hb_10";
17
+ const formInput = "_formInput_1u9hb_36";
18
+ const isFocused = "_isFocused_1u9hb_56";
19
+ const iconField = "_iconField_1u9hb_73";
20
+ const suffixContainer = "_suffixContainer_1u9hb_77";
21
+ const isInvalid = "_isInvalid_1u9hb_82";
22
+ const inlineForm = "_inlineForm_1u9hb_93";
23
+ const label = "_label_1u9hb_98";
24
+ const labelDisabled = "_labelDisabled_1u9hb_104";
25
+ const labelOptional = "_labelOptional_1u9hb_108";
26
+ const compactTextField = "_compactTextField_1u9hb_114";
27
+ const fieldError = "_fieldError_1u9hb_138";
28
+ const hint = "_hint_1u9hb_184";
29
+ const field = "_field_1u9hb_138";
30
+ const fieldErrorMessage = "_fieldErrorMessage_1u9hb_204";
31
+ const isDisabled = "_isDisabled_1u9hb_217";
32
+ const checkbox = "_checkbox_1u9hb_284";
33
+ const radio = "_radio_1u9hb_291";
34
+ const number = "_number_1u9hb_295";
35
+ const suffix = "_suffix_1u9hb_77";
36
+ const iconFieldIcon = "_iconFieldIcon_1u9hb_333";
37
+ const formInputTiny = "_formInputTiny_1u9hb_341";
38
+ const requiredAsterisk = "_requiredAsterisk_1u9hb_350";
39
+ const fieldSet = "_fieldSet_1u9hb_354";
40
+ const isActive = "_isActive_1u9hb_365";
41
+ const numberField = "_numberField_1u9hb_372";
37
42
  const styles = {
38
43
  formGroup,
39
44
  formIncreasedErrorMargin,
@@ -62,7 +67,11 @@ const styles = {
62
67
  formInputTiny,
63
68
  requiredAsterisk,
64
69
  fieldSet,
65
- isActive
70
+ isActive,
71
+ numberField,
72
+ "numberField-input": "_numberField-input_1u9hb_376",
73
+ "numberField-stepperContainer": "_numberField-stepperContainer_1u9hb_380",
74
+ "numberField-stepper": "_numberField-stepper_1u9hb_380"
66
75
  };
67
76
  const RequiredAsterisk = ({
68
77
  className,
@@ -70,12 +79,7 @@ const RequiredAsterisk = ({
70
79
  ...rest
71
80
  }) => {
72
81
  const classes = classix.cx(styles.requiredAsterisk, className);
73
- return /* @__PURE__ */ jsxRuntime.jsx("span", {
74
- ...rest,
75
- "data-test-id": testId,
76
- className: classes,
77
- children: "*"
78
- });
82
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { ...rest, "data-test-id": testId, className: classes, children: "*" });
79
83
  };
80
84
  const Label = ({
81
85
  disabled,
@@ -87,141 +91,164 @@ const Label = ({
87
91
  ...rest
88
92
  }) => {
89
93
  const classes = classix.cx(styles.label, className, disabled && styles.labelDisabled);
90
- return /* @__PURE__ */ jsxRuntime.jsxs("label", {
91
- ...rest,
92
- "data-test-id": testId,
93
- className: classes,
94
- children: [children, optional && !required && /* @__PURE__ */ jsxRuntime.jsx("small", {
95
- className: styles.labelOptional,
96
- children: "(optional)"
97
- }), required && !optional && /* @__PURE__ */ jsxRuntime.jsx(RequiredAsterisk, {})]
98
- });
94
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { ...rest, "data-test-id": testId, className: classes, children: [
95
+ children,
96
+ optional && !required && /* @__PURE__ */ jsxRuntime.jsx("small", { className: styles.labelOptional, children: "(optional)" }),
97
+ required && !optional && /* @__PURE__ */ jsxRuntime.jsx(RequiredAsterisk, {})
98
+ ] });
99
99
  };
100
- const Checkbox = react.forwardRef(({
101
- "aria-label": ariaLabel,
102
- "aria-labelledby": ariaLabelledby,
103
- children,
104
- disabled,
105
- checked,
106
- labelClassName,
107
- "data-test-id": testId = "checkbox",
108
- ...rest
109
- }, ref) => {
110
- const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
111
- if (!children && !hasAriaLabel) {
112
- console.warn("If you do not provide children, you must specify an aria-label for accessibility");
100
+ const Checkbox = react.forwardRef(
101
+ ({
102
+ "aria-label": ariaLabel,
103
+ "aria-labelledby": ariaLabelledby,
104
+ children,
105
+ disabled,
106
+ checked,
107
+ labelClassName,
108
+ "data-test-id": testId = "checkbox",
109
+ ...rest
110
+ }, ref) => {
111
+ const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
112
+ if (!children && !hasAriaLabel) {
113
+ console.warn(
114
+ "If you do not provide children, you must specify an aria-label for accessibility"
115
+ );
116
+ }
117
+ return /* @__PURE__ */ jsxRuntime.jsxs(Label, { className: labelClassName, children: [
118
+ /* @__PURE__ */ jsxRuntime.jsx(
119
+ "input",
120
+ {
121
+ ...rest,
122
+ ref,
123
+ checked,
124
+ "aria-checked": checked ? "true" : "false",
125
+ "aria-label": ariaLabel,
126
+ "aria-labelledby": ariaLabelledby,
127
+ className: styles.checkbox,
128
+ disabled,
129
+ type: "checkbox",
130
+ "data-test-id": testId
131
+ }
132
+ ),
133
+ " ",
134
+ disabled ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelDisabled, children }) : children
135
+ ] });
113
136
  }
114
- return /* @__PURE__ */ jsxRuntime.jsxs(Label, {
115
- className: labelClassName,
116
- children: [/* @__PURE__ */ jsxRuntime.jsx("input", {
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
- }), " ", disabled ? /* @__PURE__ */ jsxRuntime.jsx("span", {
128
- className: styles.labelDisabled,
129
- children
130
- }) : children]
131
- });
132
- });
137
+ );
133
138
  Checkbox.displayName = "Checkbox";
134
139
  const createFieldErrorId = (fieldIdentifier) => fieldIdentifier ? `${[...fieldIdentifier].join("")}-err` : void 0;
135
- const TextField = react.forwardRef(({
136
- className,
137
- type = "text",
138
- tiny = false,
139
- readOnly,
140
- tabIndex = 0,
141
- suffix: suffix2,
142
- overrideWidth,
143
- "data-test-id": testId = "text-field",
144
- ...rest
145
- }, ref) => {
146
- const classes = overrideWidth ? className : classix.cx(styles.formInput, tiny && styles.formInputTiny, className);
147
- if (suffix2) {
148
- return /* @__PURE__ */ jsxRuntime.jsxs("div", {
149
- className: styles.suffixContainer,
150
- children: [/* @__PURE__ */ jsxRuntime.jsx("input", {
140
+ function hasObjectChanged(obj1, obj2) {
141
+ return Object.keys(obj1).length !== Object.keys(obj2).length || Object.keys(obj1).some((k) => {
142
+ const key = k;
143
+ return typeof obj1[key] === "object" && typeof obj2[key] === "object" ? hasObjectChanged(obj1[key], obj2[key]) : obj1[key] !== obj2[key];
144
+ });
145
+ }
146
+ function useObjectMemo(obj) {
147
+ const objRef = react.useRef(obj);
148
+ return react.useMemo(() => {
149
+ if (hasObjectChanged(obj, objRef.current)) {
150
+ objRef.current = obj;
151
+ }
152
+ return objRef.current;
153
+ }, [obj]);
154
+ }
155
+ const TextField = react.forwardRef(
156
+ ({
157
+ className,
158
+ type = "text",
159
+ tiny = false,
160
+ readOnly,
161
+ tabIndex = 0,
162
+ suffix: suffix2,
163
+ overrideWidth,
164
+ "data-test-id": testId = "text-field",
165
+ ...rest
166
+ }, ref) => {
167
+ const classes = overrideWidth ? className : classix.cx(styles.formInput, tiny && styles.formInputTiny, className);
168
+ if (suffix2) {
169
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.suffixContainer, children: [
170
+ /* @__PURE__ */ jsxRuntime.jsx(
171
+ "input",
172
+ {
173
+ ...rest,
174
+ type,
175
+ "data-test-id": testId,
176
+ className: classes,
177
+ readOnly,
178
+ ref,
179
+ "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
180
+ }
181
+ ),
182
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: styles.suffix, htmlFor: rest.id, children: suffix2 })
183
+ ] });
184
+ }
185
+ return /* @__PURE__ */ jsxRuntime.jsx(
186
+ "input",
187
+ {
151
188
  ...rest,
152
189
  type,
153
- "data-test-id": testId,
154
190
  className: classes,
155
191
  readOnly,
192
+ tabIndex,
156
193
  ref,
194
+ "data-test-id": testId,
195
+ style: overrideWidth ? {
196
+ width: overrideWidth
197
+ } : void 0,
157
198
  "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
158
- }), /* @__PURE__ */ jsxRuntime.jsx("label", {
159
- className: styles.suffix,
160
- htmlFor: rest.id,
161
- children: suffix2
162
- })]
163
- });
199
+ }
200
+ );
164
201
  }
165
- return /* @__PURE__ */ jsxRuntime.jsx("input", {
166
- ...rest,
167
- type,
168
- className: classes,
169
- readOnly,
170
- tabIndex,
171
- ref,
172
- "data-test-id": testId,
173
- style: overrideWidth ? {
174
- width: overrideWidth
175
- } : void 0,
176
- "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
177
- });
178
- });
202
+ );
179
203
  TextField.displayName = "TextField";
180
- const CompactTextField = react.forwardRef(({
181
- className,
182
- id,
183
- label: label2,
184
- needsErrorFeedback,
185
- value,
186
- onFocus,
187
- onBlur,
188
- "data-test-id": testId = "compact-text-field",
189
- ...rest
190
- }, ref) => {
191
- const [isActive2, setIsActive] = react.useState((typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0);
192
- const isActiveState = isActive2 || needsErrorFeedback;
193
- const classes = classix.cx(styles.compactTextField, className, isActiveState && styles.isActive);
194
- const placeholder = isActiveState ? "" : label2;
195
- const handleFocus = (event) => {
196
- setIsActive(true);
197
- if (onFocus) {
198
- onFocus(event);
199
- }
200
- };
201
- const handleBlur = (event) => {
202
- const value2 = event.target.value || "";
203
- setIsActive(value2.trim().length !== 0);
204
- if (onBlur) {
205
- onBlur(event);
206
- }
207
- };
208
- return /* @__PURE__ */ jsxRuntime.jsxs("div", {
209
- className: classes,
210
- "data-test-id": testId,
211
- children: [/* @__PURE__ */ jsxRuntime.jsx(Label, {
212
- htmlFor: id,
213
- children: label2
214
- }), /* @__PURE__ */ jsxRuntime.jsx(TextField, {
215
- ...rest,
216
- id,
217
- placeholder,
218
- value,
219
- ref,
220
- onFocus: handleFocus,
221
- onBlur: handleBlur
222
- })]
223
- });
224
- });
204
+ const CompactTextField = react.forwardRef(
205
+ ({
206
+ className,
207
+ id,
208
+ label: label2,
209
+ needsErrorFeedback,
210
+ value,
211
+ onFocus,
212
+ onBlur,
213
+ "data-test-id": testId = "compact-text-field",
214
+ ...rest
215
+ }, ref) => {
216
+ const [isActive2, setIsActive] = react.useState(
217
+ (typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0
218
+ );
219
+ const isActiveState = isActive2 || needsErrorFeedback;
220
+ const classes = classix.cx(styles.compactTextField, className, isActiveState && styles.isActive);
221
+ const placeholder = isActiveState ? "" : label2;
222
+ const handleFocus = (event) => {
223
+ setIsActive(true);
224
+ if (onFocus) {
225
+ onFocus(event);
226
+ }
227
+ };
228
+ const handleBlur = (event) => {
229
+ const value2 = event.target.value || "";
230
+ setIsActive(value2.trim().length !== 0);
231
+ if (onBlur) {
232
+ onBlur(event);
233
+ }
234
+ };
235
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, "data-test-id": testId, children: [
236
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: id, children: label2 }),
237
+ /* @__PURE__ */ jsxRuntime.jsx(
238
+ TextField,
239
+ {
240
+ ...rest,
241
+ id,
242
+ placeholder,
243
+ value,
244
+ ref,
245
+ onFocus: handleFocus,
246
+ onBlur: handleBlur
247
+ }
248
+ )
249
+ ] });
250
+ }
251
+ );
225
252
  CompactTextField.displayName = "CompactTextField";
226
253
  const FieldError = ({
227
254
  name,
@@ -233,17 +260,22 @@ const FieldError = ({
233
260
  if (!errorMessage) {
234
261
  return null;
235
262
  }
236
- return /* @__PURE__ */ jsxRuntime.jsxs("span", {
237
- ...rest,
238
- className: classix.cx(styles.fieldError, className),
239
- "aria-live": "polite",
240
- "data-test-id": testId,
241
- "aria-label": "Error",
242
- id: createFieldErrorId(name),
243
- children: [/* @__PURE__ */ jsxRuntime.jsx(icons.AlertRhombus, {
244
- size: "small"
245
- }), " ", errorMessage]
246
- });
263
+ return /* @__PURE__ */ jsxRuntime.jsxs(
264
+ "span",
265
+ {
266
+ ...rest,
267
+ className: classix.cx(styles.fieldError, className),
268
+ "aria-live": "polite",
269
+ "data-test-id": testId,
270
+ "aria-label": "Error",
271
+ id: createFieldErrorId(name),
272
+ children: [
273
+ /* @__PURE__ */ jsxRuntime.jsx(icons.AlertRhombus, { size: "small" }),
274
+ " ",
275
+ errorMessage
276
+ ]
277
+ }
278
+ );
247
279
  };
248
280
  const FieldSet = ({
249
281
  children,
@@ -252,12 +284,7 @@ const FieldSet = ({
252
284
  ...rest
253
285
  }) => {
254
286
  const classes = classix.cx(styles.fieldSet, className);
255
- return /* @__PURE__ */ jsxRuntime.jsx("fieldset", {
256
- "data-test-id": testId,
257
- className: classes,
258
- ...rest,
259
- children
260
- });
287
+ return /* @__PURE__ */ jsxRuntime.jsx("fieldset", { "data-test-id": testId, className: classes, ...rest, children });
261
288
  };
262
289
  const Form = (props) => {
263
290
  const {
@@ -268,13 +295,13 @@ const Form = (props) => {
268
295
  "data-test-id": testId = "form",
269
296
  ...rest
270
297
  } = props;
271
- const classes = classix.cx(styles.form, className, inline && styles.formInline, !!hasIncreasedErrorMargin && styles.formIncreasedErrorMargin);
272
- return /* @__PURE__ */ jsxRuntime.jsx("form", {
273
- ...rest,
274
- "data-test-id": testId,
275
- className: classes,
276
- children
277
- });
298
+ const classes = classix.cx(
299
+ styles.form,
300
+ className,
301
+ inline && styles.formInline,
302
+ !!hasIncreasedErrorMargin && styles.formIncreasedErrorMargin
303
+ );
304
+ return /* @__PURE__ */ jsxRuntime.jsx("form", { ...rest, "data-test-id": testId, className: classes, children });
278
305
  };
279
306
  const FormGroup = (props) => {
280
307
  const {
@@ -286,13 +313,12 @@ const FormGroup = (props) => {
286
313
  "data-test-id": testId = "form-group",
287
314
  ...rest
288
315
  } = props;
289
- const classes = classix.cx(styles.formGroup, className, !ignoreValidation && isInvalid2 && styles.isInvalid);
290
- return /* @__PURE__ */ jsxRuntime.jsx("fieldset", {
291
- className: classes,
292
- "data-test-id": testId,
293
- ...rest,
294
- children
295
- });
316
+ const classes = classix.cx(
317
+ styles.formGroup,
318
+ className,
319
+ !ignoreValidation && isInvalid2 && styles.isInvalid
320
+ );
321
+ return /* @__PURE__ */ jsxRuntime.jsx("fieldset", { className: classes, "data-test-id": testId, ...rest, children });
296
322
  };
297
323
  const FormHint = ({
298
324
  className,
@@ -301,12 +327,7 @@ const FormHint = ({
301
327
  ...rest
302
328
  }) => {
303
329
  const classes = classix.cx(styles.hint, className);
304
- return /* @__PURE__ */ jsxRuntime.jsx("div", {
305
- ...rest,
306
- "data-test-id": testId,
307
- className: classes,
308
- children
309
- });
330
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ...rest, "data-test-id": testId, className: classes, children });
310
331
  };
311
332
  const FormField = ({
312
333
  isRequired,
@@ -320,31 +341,39 @@ const FormField = ({
320
341
  children,
321
342
  className,
322
343
  onBlur,
323
- "data-test-id": testId = "form-field"
344
+ "data-test-id": testId = "form-field",
345
+ LabelProps = {},
346
+ FormHintProps = {},
347
+ FieldErrorProps = {}
324
348
  }) => {
325
349
  const handleBlur = () => {
326
350
  onBlur && onBlur(name);
327
351
  };
328
- return /* @__PURE__ */ jsxRuntime.jsxs(FormGroup, {
329
- className: classix.cx(styles.field, className),
330
- name,
331
- ignoreValidation,
332
- isInvalid: isInvalid2,
333
- onBlur: handleBlur,
334
- "data-test-id": testId,
335
- children: [label2 && /* @__PURE__ */ jsxRuntime.jsx(Label, {
336
- htmlFor,
337
- required: isRequired,
338
- children: label2
339
- }), hint2 && /* @__PURE__ */ jsxRuntime.jsx(FormHint, {
340
- className: styles.hint,
341
- children: hint2
342
- }), children, /* @__PURE__ */ jsxRuntime.jsx(FieldError, {
343
- className: styles.fieldErrorMessage,
352
+ return /* @__PURE__ */ jsxRuntime.jsxs(
353
+ FormGroup,
354
+ {
355
+ className: classix.cx(styles.field, className),
344
356
  name,
345
- errorMessage
346
- })]
347
- });
357
+ ignoreValidation,
358
+ isInvalid: isInvalid2,
359
+ onBlur: handleBlur,
360
+ "data-test-id": testId,
361
+ children: [
362
+ label2 && /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor, required: isRequired, ...LabelProps, children: label2 }),
363
+ hint2 && /* @__PURE__ */ jsxRuntime.jsx(FormHint, { className: styles.hint, ...FormHintProps, children: hint2 }),
364
+ children,
365
+ /* @__PURE__ */ jsxRuntime.jsx(
366
+ FieldError,
367
+ {
368
+ className: styles.fieldErrorMessage,
369
+ name,
370
+ errorMessage,
371
+ ...FieldErrorProps
372
+ }
373
+ )
374
+ ]
375
+ }
376
+ );
348
377
  };
349
378
  const IconField = ({
350
379
  icon,
@@ -355,15 +384,10 @@ const IconField = ({
355
384
  }) => {
356
385
  const Icon = icon;
357
386
  const classes = classix.cx(styles.iconField, className);
358
- return /* @__PURE__ */ jsxRuntime.jsxs("div", {
359
- className: classes,
360
- "data-test-id": testId,
361
- ...rest,
362
- children: [children, /* @__PURE__ */ jsxRuntime.jsx(Icon, {
363
- size: "small",
364
- className: styles.iconFieldIcon
365
- })]
366
- });
387
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, "data-test-id": testId, ...rest, children: [
388
+ children,
389
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: "small", className: styles.iconFieldIcon })
390
+ ] });
367
391
  };
368
392
  const Radio = ({
369
393
  "aria-label": ariaLabel,
@@ -380,29 +404,27 @@ const Radio = ({
380
404
  }) => {
381
405
  const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
382
406
  if (!children && !hasAriaLabel) {
383
- console.warn("If you do not provide children, you must specify an aria-label for accessibility");
407
+ console.warn(
408
+ "If you do not provide children, you must specify an aria-label for accessibility"
409
+ );
384
410
  }
385
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
386
- children: [/* @__PURE__ */ jsxRuntime.jsx("input", {
387
- ...rest,
388
- "aria-label": ariaLabel,
389
- "aria-labelledby": ariaLabelledby,
390
- className: classix.cx(styles.radio, className),
391
- checked,
392
- disabled,
393
- id,
394
- "data-test-id": testId,
395
- type: "radio"
396
- }), /* @__PURE__ */ jsxRuntime.jsx(Label, {
397
- className: labelClassName,
398
- htmlFor: id,
399
- style: labelStyle,
400
- children: disabled ? /* @__PURE__ */ jsxRuntime.jsx("span", {
401
- className: styles.labelDisabled,
402
- children
403
- }) : children
404
- })]
405
- });
411
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
412
+ /* @__PURE__ */ jsxRuntime.jsx(
413
+ "input",
414
+ {
415
+ ...rest,
416
+ "aria-label": ariaLabel,
417
+ "aria-labelledby": ariaLabelledby,
418
+ className: classix.cx(styles.radio, className),
419
+ checked,
420
+ disabled,
421
+ id,
422
+ "data-test-id": testId,
423
+ type: "radio"
424
+ }
425
+ ),
426
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { className: labelClassName, htmlFor: id, style: labelStyle, children: disabled ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelDisabled, children }) : children })
427
+ ] });
406
428
  };
407
429
  const RadioGroup = (props) => {
408
430
  const {
@@ -455,56 +477,95 @@ const RadioGroup = (props) => {
455
477
  return null;
456
478
  }
457
479
  const radios = react.Children.map(children, (child) => updateRadioElems(child));
458
- return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", {
459
- "data-test-id": testId,
460
- ref: fieldsetRef,
461
- children: [legend && /* @__PURE__ */ jsxRuntime.jsx("legend", {
462
- children: /* @__PURE__ */ jsxRuntime.jsx(visuallyHidden.VisuallyHidden, {
463
- children: legend
464
- })
465
- }), /* @__PURE__ */ jsxRuntime.jsx("div", {
466
- ...rest,
467
- children: radios
468
- })]
469
- });
480
+ return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { "data-test-id": testId, ref: fieldsetRef, children: [
481
+ legend && /* @__PURE__ */ jsxRuntime.jsx("legend", { children: /* @__PURE__ */ jsxRuntime.jsx(visuallyHidden.VisuallyHidden, { children: legend }) }),
482
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ...rest, children: radios })
483
+ ] });
470
484
  };
471
- const SelectField = ({
472
- className,
473
- children,
474
- "data-test-id": testId = "select",
475
- ...rest
476
- }) => {
477
- const classes = classix.cx(styles.formInput, className);
478
- return /* @__PURE__ */ jsxRuntime.jsx("select", {
479
- ...rest,
480
- "data-test-id": testId,
481
- className: classes,
482
- children
483
- });
485
+ const SelectField = react.forwardRef(
486
+ ({ className, children, "data-test-id": testId = "select", ...rest }, ref) => {
487
+ const classes = classix.cx(styles.formInput, className);
488
+ return /* @__PURE__ */ jsxRuntime.jsx("select", { ...rest, "data-test-id": testId, className: classes, ref, children });
489
+ }
490
+ );
491
+ SelectField.displayName = "SelectField";
492
+ const TextArea = react.forwardRef(
493
+ ({ className, "data-test-id": testId = "text-area", ...props }, ref) => {
494
+ const onKeyDown = (e) => {
495
+ if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
496
+ e.stopPropagation();
497
+ }
498
+ if (e.key === "Escape") {
499
+ e.nativeEvent.stopImmediatePropagation();
500
+ }
501
+ };
502
+ return /* @__PURE__ */ jsxRuntime.jsx(
503
+ "textarea",
504
+ {
505
+ ...props,
506
+ className: classix.cx(styles.formInput, className),
507
+ ref,
508
+ "data-test-id": testId,
509
+ "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
510
+ onKeyDown
511
+ }
512
+ );
513
+ }
514
+ );
515
+ TextArea.displayName = "TextArea";
516
+ const defaultFormatOptions = {
517
+ maximumFractionDigits: 6
484
518
  };
485
- const TextArea = react.forwardRef(({
486
- className,
487
- "data-test-id": testId = "text-area",
488
- ...props
489
- }, ref) => {
490
- const onKeyDown = (e) => {
491
- if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
492
- e.stopPropagation();
493
- }
494
- if (e.key === "Escape") {
495
- e.nativeEvent.stopImmediatePropagation();
496
- }
497
- };
498
- return /* @__PURE__ */ jsxRuntime.jsx("textarea", {
499
- ...props,
500
- className: classix.cx(styles.formInput, className),
501
- ref,
502
- "data-test-id": testId,
503
- "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
504
- onKeyDown
519
+ const useNumberField = ({
520
+ className: rootClassName,
521
+ "data-test-id": testId = "input",
522
+ id,
523
+ name,
524
+ ...otherProps
525
+ } = {}) => {
526
+ const formatOptions = useObjectMemo({
527
+ ...defaultFormatOptions,
528
+ ...otherProps.formatOptions
505
529
  });
506
- });
507
- TextArea.displayName = "TextArea";
530
+ const { locale } = i18n.useLocale();
531
+ const numberFieldState = numberfield.useNumberFieldState({ ...otherProps, locale, formatOptions });
532
+ const inputRef = react.useRef(null);
533
+ const {
534
+ descriptionProps: formHintProps,
535
+ errorMessageProps: fieldErrorProps,
536
+ labelProps,
537
+ groupProps,
538
+ inputProps,
539
+ incrementButtonProps,
540
+ decrementButtonProps
541
+ } = numberfield$1.useNumberField({ ...otherProps, formatOptions, id }, numberFieldState, inputRef);
542
+ return {
543
+ fieldErrorProps,
544
+ formHintProps,
545
+ labelProps,
546
+ renderNumberField: () => /* @__PURE__ */ jsxRuntime.jsxs("div", { ...groupProps, className: styles.numberField, children: [
547
+ /* @__PURE__ */ jsxRuntime.jsx(
548
+ "input",
549
+ {
550
+ ...inputProps,
551
+ className: classix.cx(styles.formInput, styles["numberField-input"]),
552
+ "data-test-id": testId,
553
+ name,
554
+ ref: inputRef
555
+ }
556
+ ),
557
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles["numberField-stepperContainer"], children: [
558
+ /* @__PURE__ */ jsxRuntime.jsx(Stepper, { ...incrementButtonProps, children: /* @__PURE__ */ jsxRuntime.jsx(icons.ExpandLess, {}) }),
559
+ /* @__PURE__ */ jsxRuntime.jsx(Stepper, { ...decrementButtonProps, children: /* @__PURE__ */ jsxRuntime.jsx(icons.ExpandMore, {}) })
560
+ ] })
561
+ ] })
562
+ };
563
+ };
564
+ const Stepper = (props) => {
565
+ const buttonRef = react.useRef(null);
566
+ const { buttonProps } = button.useButton(props, buttonRef);
567
+ return /* @__PURE__ */ jsxRuntime.jsx("button", { ...buttonProps, className: styles["numberField-stepper"], ref: buttonRef, children: props.children });
568
+ };
508
569
  exports.Checkbox = Checkbox;
509
570
  exports.CompactTextField = CompactTextField;
510
571
  exports.FieldError = FieldError;
@@ -521,4 +582,5 @@ exports.RequiredAsterisk = RequiredAsterisk;
521
582
  exports.SelectField = SelectField;
522
583
  exports.TextArea = TextArea;
523
584
  exports.TextField = TextField;
585
+ exports.useNumberField = useNumberField;
524
586
  //# sourceMappingURL=index.js.map