@launchpad-ui/form 0.8.12 → 0.8.14

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 { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
3
  import { forwardRef, useState, useRef, Children, isValidElement, cloneElement } from "react";
3
4
  import { cx } from "classix";
4
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { AlertRhombus } from "@launchpad-ui/icons";
6
6
  import { VisuallyHidden } from "@react-aria/visually-hidden";
7
7
  const formGroup = "_formGroup_p76jo_10";
@@ -68,12 +68,7 @@ const RequiredAsterisk = ({
68
68
  ...rest
69
69
  }) => {
70
70
  const classes = cx(styles.requiredAsterisk, className);
71
- return /* @__PURE__ */ jsx("span", {
72
- ...rest,
73
- "data-test-id": testId,
74
- className: classes,
75
- children: "*"
76
- });
71
+ return /* @__PURE__ */ jsx("span", { ...rest, "data-test-id": testId, className: classes, children: "*" });
77
72
  };
78
73
  const Label = ({
79
74
  disabled,
@@ -85,141 +80,149 @@ const Label = ({
85
80
  ...rest
86
81
  }) => {
87
82
  const classes = cx(styles.label, className, disabled && styles.labelDisabled);
88
- return /* @__PURE__ */ jsxs("label", {
89
- ...rest,
90
- "data-test-id": testId,
91
- className: classes,
92
- children: [children, optional && !required && /* @__PURE__ */ jsx("small", {
93
- className: styles.labelOptional,
94
- children: "(optional)"
95
- }), required && !optional && /* @__PURE__ */ jsx(RequiredAsterisk, {})]
96
- });
83
+ return /* @__PURE__ */ jsxs("label", { ...rest, "data-test-id": testId, className: classes, children: [
84
+ children,
85
+ optional && !required && /* @__PURE__ */ jsx("small", { className: styles.labelOptional, children: "(optional)" }),
86
+ required && !optional && /* @__PURE__ */ jsx(RequiredAsterisk, {})
87
+ ] });
97
88
  };
98
- const Checkbox = forwardRef(({
99
- "aria-label": ariaLabel,
100
- "aria-labelledby": ariaLabelledby,
101
- children,
102
- disabled,
103
- checked,
104
- labelClassName,
105
- "data-test-id": testId = "checkbox",
106
- ...rest
107
- }, ref) => {
108
- const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
109
- if (!children && !hasAriaLabel) {
110
- console.warn("If you do not provide children, you must specify an aria-label for accessibility");
89
+ const Checkbox = forwardRef(
90
+ ({
91
+ "aria-label": ariaLabel,
92
+ "aria-labelledby": ariaLabelledby,
93
+ children,
94
+ disabled,
95
+ checked,
96
+ labelClassName,
97
+ "data-test-id": testId = "checkbox",
98
+ ...rest
99
+ }, ref) => {
100
+ const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
101
+ if (!children && !hasAriaLabel) {
102
+ console.warn(
103
+ "If you do not provide children, you must specify an aria-label for accessibility"
104
+ );
105
+ }
106
+ return /* @__PURE__ */ jsxs(Label, { className: labelClassName, children: [
107
+ /* @__PURE__ */ jsx(
108
+ "input",
109
+ {
110
+ ...rest,
111
+ ref,
112
+ checked,
113
+ "aria-checked": checked ? "true" : "false",
114
+ "aria-label": ariaLabel,
115
+ "aria-labelledby": ariaLabelledby,
116
+ className: styles.checkbox,
117
+ disabled,
118
+ type: "checkbox",
119
+ "data-test-id": testId
120
+ }
121
+ ),
122
+ " ",
123
+ disabled ? /* @__PURE__ */ jsx("span", { className: styles.labelDisabled, children }) : children
124
+ ] });
111
125
  }
112
- return /* @__PURE__ */ jsxs(Label, {
113
- className: labelClassName,
114
- children: [/* @__PURE__ */ jsx("input", {
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
- }), " ", disabled ? /* @__PURE__ */ jsx("span", {
126
- className: styles.labelDisabled,
127
- children
128
- }) : children]
129
- });
130
- });
126
+ );
131
127
  Checkbox.displayName = "Checkbox";
132
128
  const createFieldErrorId = (fieldIdentifier) => fieldIdentifier ? `${[...fieldIdentifier].join("")}-err` : void 0;
133
- const TextField = forwardRef(({
134
- className,
135
- type = "text",
136
- tiny = false,
137
- readOnly,
138
- tabIndex = 0,
139
- suffix: suffix2,
140
- overrideWidth,
141
- "data-test-id": testId = "text-field",
142
- ...rest
143
- }, ref) => {
144
- const classes = overrideWidth ? className : cx(styles.formInput, tiny && styles.formInputTiny, className);
145
- if (suffix2) {
146
- return /* @__PURE__ */ jsxs("div", {
147
- className: styles.suffixContainer,
148
- children: [/* @__PURE__ */ jsx("input", {
129
+ const TextField = forwardRef(
130
+ ({
131
+ className,
132
+ type = "text",
133
+ tiny = false,
134
+ readOnly,
135
+ tabIndex = 0,
136
+ suffix: suffix2,
137
+ overrideWidth,
138
+ "data-test-id": testId = "text-field",
139
+ ...rest
140
+ }, ref) => {
141
+ const classes = overrideWidth ? className : cx(styles.formInput, tiny && styles.formInputTiny, className);
142
+ if (suffix2) {
143
+ return /* @__PURE__ */ jsxs("div", { className: styles.suffixContainer, children: [
144
+ /* @__PURE__ */ jsx(
145
+ "input",
146
+ {
147
+ ...rest,
148
+ type,
149
+ "data-test-id": testId,
150
+ className: classes,
151
+ readOnly,
152
+ ref,
153
+ "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
154
+ }
155
+ ),
156
+ /* @__PURE__ */ jsx("label", { className: styles.suffix, htmlFor: rest.id, children: suffix2 })
157
+ ] });
158
+ }
159
+ return /* @__PURE__ */ jsx(
160
+ "input",
161
+ {
149
162
  ...rest,
150
163
  type,
151
- "data-test-id": testId,
152
164
  className: classes,
153
165
  readOnly,
166
+ tabIndex,
154
167
  ref,
168
+ "data-test-id": testId,
169
+ style: overrideWidth ? {
170
+ width: overrideWidth
171
+ } : void 0,
155
172
  "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
156
- }), /* @__PURE__ */ jsx("label", {
157
- className: styles.suffix,
158
- htmlFor: rest.id,
159
- children: suffix2
160
- })]
161
- });
173
+ }
174
+ );
162
175
  }
163
- return /* @__PURE__ */ jsx("input", {
164
- ...rest,
165
- type,
166
- className: classes,
167
- readOnly,
168
- tabIndex,
169
- ref,
170
- "data-test-id": testId,
171
- style: overrideWidth ? {
172
- width: overrideWidth
173
- } : void 0,
174
- "aria-describedby": rest["aria-describedby"] || createFieldErrorId(rest.id)
175
- });
176
- });
176
+ );
177
177
  TextField.displayName = "TextField";
178
- const CompactTextField = forwardRef(({
179
- className,
180
- id,
181
- label: label2,
182
- needsErrorFeedback,
183
- value,
184
- onFocus,
185
- onBlur,
186
- "data-test-id": testId = "compact-text-field",
187
- ...rest
188
- }, ref) => {
189
- const [isActive2, setIsActive] = useState((typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0);
190
- const isActiveState = isActive2 || needsErrorFeedback;
191
- const classes = cx(styles.compactTextField, className, isActiveState && styles.isActive);
192
- const placeholder = isActiveState ? "" : label2;
193
- const handleFocus = (event) => {
194
- setIsActive(true);
195
- if (onFocus) {
196
- onFocus(event);
197
- }
198
- };
199
- const handleBlur = (event) => {
200
- const value2 = event.target.value || "";
201
- setIsActive(value2.trim().length !== 0);
202
- if (onBlur) {
203
- onBlur(event);
204
- }
205
- };
206
- return /* @__PURE__ */ jsxs("div", {
207
- className: classes,
208
- "data-test-id": testId,
209
- children: [/* @__PURE__ */ jsx(Label, {
210
- htmlFor: id,
211
- children: label2
212
- }), /* @__PURE__ */ jsx(TextField, {
213
- ...rest,
214
- id,
215
- placeholder,
216
- value,
217
- ref,
218
- onFocus: handleFocus,
219
- onBlur: handleBlur
220
- })]
221
- });
222
- });
178
+ const CompactTextField = forwardRef(
179
+ ({
180
+ className,
181
+ id,
182
+ label: label2,
183
+ needsErrorFeedback,
184
+ value,
185
+ onFocus,
186
+ onBlur,
187
+ "data-test-id": testId = "compact-text-field",
188
+ ...rest
189
+ }, ref) => {
190
+ const [isActive2, setIsActive] = useState(
191
+ (typeof value === "boolean" || value ? value.toString() : "").trim().length !== 0
192
+ );
193
+ const isActiveState = isActive2 || needsErrorFeedback;
194
+ const classes = cx(styles.compactTextField, className, isActiveState && styles.isActive);
195
+ const placeholder = isActiveState ? "" : label2;
196
+ const handleFocus = (event) => {
197
+ setIsActive(true);
198
+ if (onFocus) {
199
+ onFocus(event);
200
+ }
201
+ };
202
+ const handleBlur = (event) => {
203
+ const value2 = event.target.value || "";
204
+ setIsActive(value2.trim().length !== 0);
205
+ if (onBlur) {
206
+ onBlur(event);
207
+ }
208
+ };
209
+ return /* @__PURE__ */ jsxs("div", { className: classes, "data-test-id": testId, children: [
210
+ /* @__PURE__ */ jsx(Label, { htmlFor: id, children: label2 }),
211
+ /* @__PURE__ */ jsx(
212
+ TextField,
213
+ {
214
+ ...rest,
215
+ id,
216
+ placeholder,
217
+ value,
218
+ ref,
219
+ onFocus: handleFocus,
220
+ onBlur: handleBlur
221
+ }
222
+ )
223
+ ] });
224
+ }
225
+ );
223
226
  CompactTextField.displayName = "CompactTextField";
224
227
  const FieldError = ({
225
228
  name,
@@ -231,17 +234,22 @@ const FieldError = ({
231
234
  if (!errorMessage) {
232
235
  return null;
233
236
  }
234
- return /* @__PURE__ */ jsxs("span", {
235
- ...rest,
236
- className: cx(styles.fieldError, className),
237
- "aria-live": "polite",
238
- "data-test-id": testId,
239
- "aria-label": "Error",
240
- id: createFieldErrorId(name),
241
- children: [/* @__PURE__ */ jsx(AlertRhombus, {
242
- size: "small"
243
- }), " ", errorMessage]
244
- });
237
+ return /* @__PURE__ */ jsxs(
238
+ "span",
239
+ {
240
+ ...rest,
241
+ className: cx(styles.fieldError, className),
242
+ "aria-live": "polite",
243
+ "data-test-id": testId,
244
+ "aria-label": "Error",
245
+ id: createFieldErrorId(name),
246
+ children: [
247
+ /* @__PURE__ */ jsx(AlertRhombus, { size: "small" }),
248
+ " ",
249
+ errorMessage
250
+ ]
251
+ }
252
+ );
245
253
  };
246
254
  const FieldSet = ({
247
255
  children,
@@ -250,12 +258,7 @@ const FieldSet = ({
250
258
  ...rest
251
259
  }) => {
252
260
  const classes = cx(styles.fieldSet, className);
253
- return /* @__PURE__ */ jsx("fieldset", {
254
- "data-test-id": testId,
255
- className: classes,
256
- ...rest,
257
- children
258
- });
261
+ return /* @__PURE__ */ jsx("fieldset", { "data-test-id": testId, className: classes, ...rest, children });
259
262
  };
260
263
  const Form = (props) => {
261
264
  const {
@@ -266,13 +269,13 @@ const Form = (props) => {
266
269
  "data-test-id": testId = "form",
267
270
  ...rest
268
271
  } = props;
269
- const classes = cx(styles.form, className, inline && styles.formInline, !!hasIncreasedErrorMargin && styles.formIncreasedErrorMargin);
270
- return /* @__PURE__ */ jsx("form", {
271
- ...rest,
272
- "data-test-id": testId,
273
- className: classes,
274
- children
275
- });
272
+ const classes = cx(
273
+ styles.form,
274
+ className,
275
+ inline && styles.formInline,
276
+ !!hasIncreasedErrorMargin && styles.formIncreasedErrorMargin
277
+ );
278
+ return /* @__PURE__ */ jsx("form", { ...rest, "data-test-id": testId, className: classes, children });
276
279
  };
277
280
  const FormGroup = (props) => {
278
281
  const {
@@ -284,13 +287,12 @@ const FormGroup = (props) => {
284
287
  "data-test-id": testId = "form-group",
285
288
  ...rest
286
289
  } = props;
287
- const classes = cx(styles.formGroup, className, !ignoreValidation && isInvalid2 && styles.isInvalid);
288
- return /* @__PURE__ */ jsx("fieldset", {
289
- className: classes,
290
- "data-test-id": testId,
291
- ...rest,
292
- children
293
- });
290
+ const classes = cx(
291
+ styles.formGroup,
292
+ className,
293
+ !ignoreValidation && isInvalid2 && styles.isInvalid
294
+ );
295
+ return /* @__PURE__ */ jsx("fieldset", { className: classes, "data-test-id": testId, ...rest, children });
294
296
  };
295
297
  const FormHint = ({
296
298
  className,
@@ -299,12 +301,7 @@ const FormHint = ({
299
301
  ...rest
300
302
  }) => {
301
303
  const classes = cx(styles.hint, className);
302
- return /* @__PURE__ */ jsx("div", {
303
- ...rest,
304
- "data-test-id": testId,
305
- className: classes,
306
- children
307
- });
304
+ return /* @__PURE__ */ jsx("div", { ...rest, "data-test-id": testId, className: classes, children });
308
305
  };
309
306
  const FormField = ({
310
307
  isRequired,
@@ -323,26 +320,23 @@ const FormField = ({
323
320
  const handleBlur = () => {
324
321
  onBlur && onBlur(name);
325
322
  };
326
- return /* @__PURE__ */ jsxs(FormGroup, {
327
- className: cx(styles.field, className),
328
- name,
329
- ignoreValidation,
330
- isInvalid: isInvalid2,
331
- onBlur: handleBlur,
332
- "data-test-id": testId,
333
- children: [label2 && /* @__PURE__ */ jsx(Label, {
334
- htmlFor,
335
- required: isRequired,
336
- children: label2
337
- }), hint2 && /* @__PURE__ */ jsx(FormHint, {
338
- className: styles.hint,
339
- children: hint2
340
- }), children, /* @__PURE__ */ jsx(FieldError, {
341
- className: styles.fieldErrorMessage,
323
+ return /* @__PURE__ */ jsxs(
324
+ FormGroup,
325
+ {
326
+ className: cx(styles.field, className),
342
327
  name,
343
- errorMessage
344
- })]
345
- });
328
+ ignoreValidation,
329
+ isInvalid: isInvalid2,
330
+ onBlur: handleBlur,
331
+ "data-test-id": testId,
332
+ children: [
333
+ label2 && /* @__PURE__ */ jsx(Label, { htmlFor, required: isRequired, children: label2 }),
334
+ hint2 && /* @__PURE__ */ jsx(FormHint, { className: styles.hint, children: hint2 }),
335
+ children,
336
+ /* @__PURE__ */ jsx(FieldError, { className: styles.fieldErrorMessage, name, errorMessage })
337
+ ]
338
+ }
339
+ );
346
340
  };
347
341
  const IconField = ({
348
342
  icon,
@@ -353,15 +347,10 @@ const IconField = ({
353
347
  }) => {
354
348
  const Icon = icon;
355
349
  const classes = cx(styles.iconField, className);
356
- return /* @__PURE__ */ jsxs("div", {
357
- className: classes,
358
- "data-test-id": testId,
359
- ...rest,
360
- children: [children, /* @__PURE__ */ jsx(Icon, {
361
- size: "small",
362
- className: styles.iconFieldIcon
363
- })]
364
- });
350
+ return /* @__PURE__ */ jsxs("div", { className: classes, "data-test-id": testId, ...rest, children: [
351
+ children,
352
+ /* @__PURE__ */ jsx(Icon, { size: "small", className: styles.iconFieldIcon })
353
+ ] });
365
354
  };
366
355
  const Radio = ({
367
356
  "aria-label": ariaLabel,
@@ -378,29 +367,27 @@ const Radio = ({
378
367
  }) => {
379
368
  const hasAriaLabel = ariaLabel !== void 0 || ariaLabelledby !== void 0;
380
369
  if (!children && !hasAriaLabel) {
381
- console.warn("If you do not provide children, you must specify an aria-label for accessibility");
370
+ console.warn(
371
+ "If you do not provide children, you must specify an aria-label for accessibility"
372
+ );
382
373
  }
383
- return /* @__PURE__ */ jsxs(Fragment, {
384
- children: [/* @__PURE__ */ jsx("input", {
385
- ...rest,
386
- "aria-label": ariaLabel,
387
- "aria-labelledby": ariaLabelledby,
388
- className: cx(styles.radio, className),
389
- checked,
390
- disabled,
391
- id,
392
- "data-test-id": testId,
393
- type: "radio"
394
- }), /* @__PURE__ */ jsx(Label, {
395
- className: labelClassName,
396
- htmlFor: id,
397
- style: labelStyle,
398
- children: disabled ? /* @__PURE__ */ jsx("span", {
399
- className: styles.labelDisabled,
400
- children
401
- }) : children
402
- })]
403
- });
374
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
375
+ /* @__PURE__ */ jsx(
376
+ "input",
377
+ {
378
+ ...rest,
379
+ "aria-label": ariaLabel,
380
+ "aria-labelledby": ariaLabelledby,
381
+ className: cx(styles.radio, className),
382
+ checked,
383
+ disabled,
384
+ id,
385
+ "data-test-id": testId,
386
+ type: "radio"
387
+ }
388
+ ),
389
+ /* @__PURE__ */ jsx(Label, { className: labelClassName, htmlFor: id, style: labelStyle, children: disabled ? /* @__PURE__ */ jsx("span", { className: styles.labelDisabled, children }) : children })
390
+ ] });
404
391
  };
405
392
  const RadioGroup = (props) => {
406
393
  const {
@@ -453,55 +440,41 @@ const RadioGroup = (props) => {
453
440
  return null;
454
441
  }
455
442
  const radios = Children.map(children, (child) => updateRadioElems(child));
456
- return /* @__PURE__ */ jsxs("fieldset", {
457
- "data-test-id": testId,
458
- ref: fieldsetRef,
459
- children: [legend && /* @__PURE__ */ jsx("legend", {
460
- children: /* @__PURE__ */ jsx(VisuallyHidden, {
461
- children: legend
462
- })
463
- }), /* @__PURE__ */ jsx("div", {
464
- ...rest,
465
- children: radios
466
- })]
467
- });
443
+ return /* @__PURE__ */ jsxs("fieldset", { "data-test-id": testId, ref: fieldsetRef, children: [
444
+ legend && /* @__PURE__ */ jsx("legend", { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: legend }) }),
445
+ /* @__PURE__ */ jsx("div", { ...rest, children: radios })
446
+ ] });
468
447
  };
469
- const SelectField = ({
470
- className,
471
- children,
472
- "data-test-id": testId = "select",
473
- ...rest
474
- }) => {
475
- const classes = cx(styles.formInput, className);
476
- return /* @__PURE__ */ jsx("select", {
477
- ...rest,
478
- "data-test-id": testId,
479
- className: classes,
480
- children
481
- });
482
- };
483
- const TextArea = forwardRef(({
484
- className,
485
- "data-test-id": testId = "text-area",
486
- ...props
487
- }, ref) => {
488
- const onKeyDown = (e) => {
489
- if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
490
- e.stopPropagation();
491
- }
492
- if (e.key === "Escape") {
493
- e.nativeEvent.stopImmediatePropagation();
494
- }
495
- };
496
- return /* @__PURE__ */ jsx("textarea", {
497
- ...props,
498
- className: cx(styles.formInput, className),
499
- ref,
500
- "data-test-id": testId,
501
- "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
502
- onKeyDown
503
- });
504
- });
448
+ const SelectField = forwardRef(
449
+ ({ className, children, "data-test-id": testId = "select", ...rest }, ref) => {
450
+ const classes = cx(styles.formInput, className);
451
+ return /* @__PURE__ */ jsx("select", { ...rest, "data-test-id": testId, className: classes, ref, children });
452
+ }
453
+ );
454
+ SelectField.displayName = "SelectField";
455
+ const TextArea = forwardRef(
456
+ ({ className, "data-test-id": testId = "text-area", ...props }, ref) => {
457
+ const onKeyDown = (e) => {
458
+ if (e.key === "ArrowRight" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "ArrowLeft") {
459
+ e.stopPropagation();
460
+ }
461
+ if (e.key === "Escape") {
462
+ e.nativeEvent.stopImmediatePropagation();
463
+ }
464
+ };
465
+ return /* @__PURE__ */ jsx(
466
+ "textarea",
467
+ {
468
+ ...props,
469
+ className: cx(styles.formInput, className),
470
+ ref,
471
+ "data-test-id": testId,
472
+ "aria-describedby": props["aria-describedby"] || createFieldErrorId(props.id),
473
+ onKeyDown
474
+ }
475
+ );
476
+ }
477
+ );
505
478
  TextArea.displayName = "TextArea";
506
479
  export {
507
480
  Checkbox,