@trackunit/react-form-components 0.0.453 → 0.0.455

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/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import { IconButton, Icon, Tooltip, Heading, Text, MenuItem, Tag, Spinner, useIs
4
4
  import { useCopyToClipboard } from 'react-use';
5
5
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
6
6
  import * as React from 'react';
7
- import React__default, { forwardRef, useState, useCallback, useRef, cloneElement, useEffect, useMemo, useImperativeHandle } from 'react';
7
+ import React__default, { isValidElement, forwardRef, useState, useCallback, useRef, cloneElement, useEffect, useMemo, useImperativeHandle } from 'react';
8
8
  import { v4 } from 'uuid';
9
9
  import { format } from 'date-fns';
10
10
  import { isValidDate } from 'rxjs/internal/util/isDate';
@@ -180,21 +180,56 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
180
180
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
181
181
  };
182
182
 
183
+ /**
184
+ * Used to compare two React nodes for deep equality.
185
+ */
186
+ const compareReactNodes = (node1, node2) => {
187
+ // Base case: If both objects are identical, return true.
188
+ if (node1 === node2) {
189
+ return true;
190
+ }
191
+ // Check if both objects are valid React elements.
192
+ if (isValidElement(node1) && isValidElement(node2)) {
193
+ const { type: type1, props: props1, key: key1 } = node1;
194
+ const { type: type2, props: props2, key: key2 } = node2;
195
+ if (type1 !== type2 || key1 !== key2) {
196
+ return false;
197
+ }
198
+ return compareReactNodes(props1, props2);
199
+ }
200
+ // Check if both objects are objects and not null.
201
+ if (typeof node1 !== "object" || typeof node2 !== "object" || node1 === null || node2 === null) {
202
+ return false;
203
+ }
204
+ // Get the keys of both objects.
205
+ const keys1 = Object.keys(node1);
206
+ const keys2 = Object.keys(node2);
207
+ // Check if the number of keys is the same.
208
+ if (keys1.length !== keys2.length) {
209
+ return false;
210
+ }
211
+ // Iterate through the keys and compare their values recursively.
212
+ for (const key of keys1) {
213
+ if (!keys2.includes(key) ||
214
+ !compareReactNodes(node1[key], node2[key])) {
215
+ return false;
216
+ }
217
+ }
218
+ // If all checks pass, the objects are deep equal.
219
+ return true;
220
+ };
221
+
183
222
  const cvaInputBase = cvaMerge([
184
223
  "component-baseInput-shadow",
185
224
  "component-baseInput-border",
186
225
  "component-baseInput-background",
187
226
  "border-slate-300",
188
- "focus-within:ring-2",
189
- "focus-within:ring-inset",
190
- "focus-within:ring-primary-500",
191
- "focus-within:border-slate-400",
192
227
  "hover:border-slate-400",
193
228
  "hover:bg-slate-50",
194
229
  "transition",
195
230
  ]);
196
231
  const cvaInputBaseDisabled = cvaMerge(["bg-slate-100", "hover:bg-slate-100", "hover:border-slate-300"]);
197
- const cvaInputBaseInvalid = cvaMerge(["border-danger-600", "focus-within:ring-danger-600"]);
232
+ const cvaInputBaseInvalid = cvaMerge(["border-danger-600"]);
198
233
  const cvaInput = cvaMerge(["relative", "flex", "h-10", cvaInputBase()], {
199
234
  variants: {
200
235
  size: {
@@ -203,24 +238,15 @@ const cvaInput = cvaMerge(["relative", "flex", "h-10", cvaInputBase()], {
203
238
  },
204
239
  disabled: {
205
240
  true: cvaInputBaseDisabled(),
206
- false: "",
241
+ false: [""],
207
242
  },
208
243
  invalid: {
209
244
  true: cvaInputBaseInvalid(),
210
- false: "",
245
+ false: [""],
211
246
  },
212
247
  },
213
248
  });
214
- const cvaInputField = cvaMerge([
215
- "w-full",
216
- "px-3",
217
- "border-0",
218
- "bg-transparent",
219
- "text-base",
220
- "text-slate-900",
221
- "placeholder-slate-400",
222
- "focus-visible:outline-none",
223
- ], {
249
+ const cvaInputField = cvaMerge(["w-full", "px-3", "border-0", "bg-transparent", "text-base", "text-slate-900", "placeholder-slate-400", "component-baseInput-border"], {
224
250
  variants: {
225
251
  size: {
226
252
  small: ["py-1"],
@@ -228,9 +254,28 @@ const cvaInputField = cvaMerge([
228
254
  },
229
255
  disabled: {
230
256
  true: ["text-slate-700"],
231
- false: "",
257
+ false: [""],
258
+ },
259
+ autoFocus: {
260
+ true: [""],
261
+ false: ["focus-visible:outline-none"],
262
+ },
263
+ addonBefore: {
264
+ true: [""],
265
+ false: [""],
266
+ },
267
+ prefix: {
268
+ true: ["ps-10"],
269
+ false: [""],
232
270
  },
233
271
  },
272
+ compoundVariants: [
273
+ {
274
+ addonBefore: true,
275
+ prefix: true,
276
+ className: ["ps-4"],
277
+ },
278
+ ],
234
279
  });
235
280
  const cvaInputAddon = cvaMerge([
236
281
  "flex",
@@ -242,7 +287,6 @@ const cvaInputAddon = cvaMerge([
242
287
  "bg-slate-50",
243
288
  ]);
244
289
  const cvaInputAddonBefore = cvaMerge([cvaInputAddon(), "border-r", "rounded-l-lg"]);
245
- const cvaInputAddonAfter = cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg"]);
246
290
  const cvaInputPrefix = cvaMerge([
247
291
  "flex",
248
292
  "justify-center",
@@ -252,21 +296,62 @@ const cvaInputPrefix = cvaMerge([
252
296
  "component-baseInput-prefix",
253
297
  "component-search-borderless",
254
298
  "pl-3",
299
+ "absolute",
300
+ "inset-y-0",
255
301
  ], {
256
302
  variants: {
257
303
  disabled: {
258
304
  true: ["text-slate-500"],
259
- false: "",
305
+ false: [""],
306
+ },
307
+ addonBefore: {
308
+ true: ["relative"],
309
+ false: [""],
260
310
  },
261
311
  },
262
312
  });
263
- const cvaInputSuffix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "px-3"], {
313
+ const cvaInputSuffix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "px-3", "absolute", "inset-y-0", "right-0"], {
264
314
  variants: {
265
315
  disabled: {
266
316
  true: ["text-slate-500"],
267
- false: "",
317
+ false: [""],
318
+ },
319
+ addonAfter: {
320
+ true: ["relative"],
321
+ false: [""],
322
+ },
323
+ actions: {
324
+ true: ["right-10"],
325
+ false: [""],
268
326
  },
269
327
  },
328
+ compoundVariants: [
329
+ {
330
+ addonAfter: true,
331
+ actions: true,
332
+ className: ["right-0"],
333
+ },
334
+ ],
335
+ });
336
+ const cvaInputAddonAfter = cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg", "ml-[1px]"]);
337
+ const cvaInputAction = cvaMerge(["absolute", "end-0.5"], {
338
+ variants: {
339
+ addonAfter: {
340
+ true: ["relative"],
341
+ false: [""],
342
+ },
343
+ suffix: {
344
+ true: ["absolute"],
345
+ false: [""],
346
+ },
347
+ },
348
+ compoundVariants: [
349
+ {
350
+ addonAfter: true,
351
+ suffix: true,
352
+ className: ["relative"],
353
+ },
354
+ ],
270
355
  });
271
356
 
272
357
  /**
@@ -289,14 +374,27 @@ const BaseInput = React.forwardRef((_a, ref) => {
289
374
  invalid: isInvalid,
290
375
  size: fieldSize,
291
376
  className,
292
- }), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [addonBefore ? (jsx("div", { className: cvaInputAddonBefore({ className: addonBeforeClassName }), "data-testid": dataTestId ? `${dataTestId}-addonBefore` : null, children: addonBefore })) : null, prefix && addonBefore !== prefix ? (jsx("div", { className: cvaInputPrefix({
377
+ }), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [addonBefore ? (jsx("div", { className: cvaInputAddonBefore({ className: addonBeforeClassName }), "data-testid": dataTestId ? `${dataTestId}-addonBefore` : null, children: addonBefore })) : null, prefix && !compareReactNodes(addonBefore, prefix) ? (jsx("div", { className: cvaInputPrefix({
293
378
  disabled: renderAsDisabled,
294
- }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, jsx("input", Object.assign({ "aria-required": rest.required, className: cvaInputField({ size: fieldSize, disabled: renderAsDisabled, className: inputClassName }), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsx("div", { className: cvaInputSuffix({
379
+ addonBefore: addonBefore !== undefined,
380
+ }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, jsx("input", Object.assign({ "aria-required": rest.required, className: cvaInputField({
381
+ autoFocus: rest.autoFocus,
382
+ size: fieldSize,
295
383
  disabled: renderAsDisabled,
384
+ className: inputClassName,
385
+ addonBefore: addonBefore !== undefined,
386
+ prefix: !compareReactNodes(addonBefore, prefix),
387
+ }), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef }, rest, { disabled: renderAsDisabled, readOnly: rest.readOnly || nonInteractive })), suffix && addonBefore !== suffix ? (jsx("div", { className: cvaInputSuffix({
388
+ disabled: renderAsDisabled,
389
+ addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
390
+ actions: (actions && !compareReactNodes(addonBefore, actions)) || false,
296
391
  }), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null, rest.readOnly === true &&
297
392
  showDefaultActions &&
298
393
  ((_b = innerRef.current) === null || _b === void 0 ? void 0 : _b.value.length) &&
299
- innerRef.current.value.length > 0 ? (jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && addonBefore !== actions ? actions : null, addonAfter && addonBefore !== addonAfter ? (jsx("div", { className: cvaInputAddonAfter(), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter })) : null] }));
394
+ innerRef.current.value.length > 0 ? (jsx(ActionButton, { type: "COPY", value: innerRef }, "default-copy-action")) : null, actions && !compareReactNodes(addonBefore, actions) ? (jsx("div", { className: cvaInputAction({
395
+ addonAfter: addonAfter !== undefined && !compareReactNodes(addonBefore, addonAfter),
396
+ suffix: !compareReactNodes(addonBefore, suffix),
397
+ }), children: actions })) : null, addonAfter && !compareReactNodes(addonBefore, addonAfter) && !compareReactNodes(addonAfter, suffix) ? (jsx("div", { className: cvaInputAddonAfter(), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter })) : null] }));
300
398
  });
301
399
  BaseInput.displayName = "BaseInput";
302
400
 
@@ -351,15 +449,11 @@ const cvaCheckbox = cvaMerge([
351
449
  "justify-center",
352
450
  "box-border",
353
451
  "transition",
354
- "focus:bg-slate-200",
355
452
  "outline-0",
356
453
  "active:bg-slate-200",
357
454
  "active:ring-2",
358
455
  "active:ring-inset",
359
456
  "active:ring-primary-700",
360
- "focus:ring-2",
361
- "focus:ring-inset",
362
- "focus:ring-primary-700",
363
457
  "cursor-pointer",
364
458
  "group-active:ring-2",
365
459
  "group-active:ring-inset",
@@ -367,13 +461,7 @@ const cvaCheckbox = cvaMerge([
367
461
  ], {
368
462
  variants: {
369
463
  invalid: {
370
- true: [
371
- "border-red-600",
372
- "active:ring-red-700",
373
- "focus:ring-red-700",
374
- "group-focus:ring-2",
375
- "group-focus:ring-inset",
376
- ],
464
+ true: ["border-red-600", "active:ring-red-700", "group-focus:ring-2", "group-focus:ring-inset"],
377
465
  false: "",
378
466
  },
379
467
  state: {
@@ -383,11 +471,8 @@ const cvaCheckbox = cvaMerge([
383
471
  "hover:bg-primary-700",
384
472
  "hover:border-primary-700",
385
473
  "active:bg-primary-700",
386
- "focus:bg-primary-700",
387
474
  "group-hover:bg-primary-700",
388
475
  "group-hover:border-primary-700",
389
- "group-focus:bg-primary-700",
390
- "group-focus:border-primary-700",
391
476
  ],
392
477
  deselected: ["group-hover:bg-slate-100"],
393
478
  indeterminate: [
@@ -395,14 +480,10 @@ const cvaCheckbox = cvaMerge([
395
480
  "border-primary-600",
396
481
  "hover:bg-primary-700",
397
482
  "hover:border-primary-700",
398
- "focus:bg-primary-800",
399
- "focus:border-primary-800",
400
483
  "active:bg-primary-800",
401
484
  "active:border-primary-800",
402
485
  "group-hover:bg-primary-700",
403
486
  "group-hover:border-primary-700",
404
- "group-focus:bg-primary-800",
405
- "group-focus:border-primary-800",
406
487
  ],
407
488
  },
408
489
  disabled: {
@@ -410,13 +491,8 @@ const cvaCheckbox = cvaMerge([
410
491
  "bg-slate-300",
411
492
  "border-slate-300",
412
493
  "cursor-not-allowed",
413
- "group-hover:bg-slate-300",
414
- "group-focus:bg-slate-300",
415
494
  "hover:bg-slate-300",
416
- "focus:bg-slate-300",
417
495
  "active:bg-slate-300",
418
- "focus:ring-0",
419
- "focus:ring-inset",
420
496
  "group-active:ring-0",
421
497
  "group-active:ring-inset",
422
498
  ],
@@ -777,7 +853,7 @@ const validateEmailAddress = (email) => {
777
853
  * For specific input types make sure to use the corresponding input component.
778
854
  */
779
855
  const EmailInput = React.forwardRef((_a, ref) => {
780
- var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false, onChange } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid", "onChange"]);
856
+ var { fieldSize = "medium", disabled = false, dataTestId, isInvalid = false, onChange, disableAction = false } = _a, rest = __rest(_a, ["fieldSize", "disabled", "dataTestId", "isInvalid", "onChange", "disableAction"]);
781
857
  const [email, setEmail] = React.useState("");
782
858
  const sendEmail = () => {
783
859
  return window.open(`mailto:${email}`);
@@ -788,7 +864,7 @@ const EmailInput = React.forwardRef((_a, ref) => {
788
864
  setEmail(newValue);
789
865
  }, [onChange]);
790
866
  const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
791
- return (jsx(BaseInput, Object.assign({ actions: email && email.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disabled, iconSize: fieldSize, onClick: sendEmail, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email" }, rest)));
867
+ return (jsx(BaseInput, Object.assign({ actions: email && email.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, iconSize: fieldSize, onClick: sendEmail, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email" }, rest)));
792
868
  });
793
869
  EmailInput.displayName = "EmailInput";
794
870
 
@@ -1015,7 +1091,7 @@ const PhoneInput = forwardRef((_a, ref) => {
1015
1091
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
1016
1092
  fieldIsFocused.current = true;
1017
1093
  }, [onFocus]);
1018
- return (jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsx(BaseInput, Object.assign({ actions: !disableAction && innerValue && innerValue.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: disabled || isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue }, rest)) }));
1094
+ return (jsx("div", { className: "grid grid-cols-1 gap-2", "data-testid": dataTestId ? `${dataTestId}-container` : null, children: jsx(BaseInput, Object.assign({ actions: !disableAction && innerValue && innerValue.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-phoneIcon` : undefined, disabled: isInvalid, iconSize: fieldSize, type: "PHONE_NUMBER", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" })) : null, dataTestId: dataTestId ? `${dataTestId}-phoneNumberInput` : undefined, disabled: disabled, fieldSize: fieldSize, id: "phoneInput-number", isInvalid: isInvalid, name: name, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocus, prefix: (countryCode && countryCodeToFlagEmoji(countryCode)) || undefined, readOnly: readOnly, ref: ref, type: "tel", value: innerValue }, rest)) }));
1019
1095
  });
1020
1096
  PhoneInput.displayName = "PhoneInput";
1021
1097
 
@@ -1116,9 +1192,6 @@ const cvaRadioItem = cvaMerge([
1116
1192
  "box-border",
1117
1193
  "hover:cursor-pointer",
1118
1194
  "hover:bg-slate-100",
1119
- "focus:ring-2",
1120
- "focus:ring-inset",
1121
- "focus:ring-primary-700",
1122
1195
  ], {
1123
1196
  variants: {
1124
1197
  checked: {
@@ -1134,10 +1207,6 @@ const cvaRadioItem = cvaMerge([
1134
1207
  "active:ring-2",
1135
1208
  "active:ring-inset",
1136
1209
  "active:ring-primary-700",
1137
- "focus:bg-slate-200",
1138
- "focus:ring-2",
1139
- "focus:ring-inset",
1140
- "focus:ring-primary-700",
1141
1210
  "group-active:ring-2",
1142
1211
  "group-active:ring-inset",
1143
1212
  "group-active:ring-primary-700",
@@ -1145,13 +1214,7 @@ const cvaRadioItem = cvaMerge([
1145
1214
  false: "",
1146
1215
  },
1147
1216
  invalid: {
1148
- true: [
1149
- "border-red-600",
1150
- "active:ring-red-700",
1151
- "focus:ring-red-700",
1152
- "group-focus:ring-2",
1153
- "group-focus:ring-inset",
1154
- ],
1217
+ true: ["border-red-600", "active:ring-red-700"],
1155
1218
  false: "",
1156
1219
  },
1157
1220
  disabled: {
@@ -1159,13 +1222,8 @@ const cvaRadioItem = cvaMerge([
1159
1222
  "bg-slate-400",
1160
1223
  "border-slate-300",
1161
1224
  "cursor-not-allowed",
1162
- "group-hover:bg-slate-400",
1163
- "group-focus:bg-slate-400",
1164
1225
  "hover:bg-slate-400",
1165
- "focus:bg-slate-400",
1166
1226
  "active:bg-slate-400",
1167
- "focus:ring-0",
1168
- "focus:ring-inset",
1169
1227
  "group-active:ring-0",
1170
1228
  "group-active:ring-inset",
1171
1229
  ],
@@ -1415,21 +1473,13 @@ const cvaSearch = cvaMerge([
1415
1473
  "component-search-background",
1416
1474
  "hover:component-search-background",
1417
1475
  "hover:component-search-focus-hover",
1418
- "focus:component-search-focus-hover",
1419
- "focus-within:component-search-focus-within",
1420
1476
  "transition-all",
1421
1477
  "duration-300",
1422
1478
  ], {
1423
1479
  variants: {
1424
1480
  border: { true: ["!component-search-borderless"], false: "" },
1425
1481
  widenOnFocus: {
1426
- true: [
1427
- "component-search-width",
1428
- "component-search-widen",
1429
- "hover:component-search-widen",
1430
- "focus-within:component-search-widen-focus",
1431
- "focus-within:w-full",
1432
- ],
1482
+ true: ["component-search-width", "component-search-widen", "hover:component-search-widen"],
1433
1483
  false: "w-full",
1434
1484
  },
1435
1485
  },
@@ -1454,25 +1504,19 @@ const cvaSelect = cvaMerge([
1454
1504
  "flex",
1455
1505
  "shadow-sm",
1456
1506
  "rounded-lg",
1457
- "border",
1458
1507
  "border-slate-300",
1459
- "focus-within:ring-2",
1460
- "focus-within:ring-inset",
1461
- "focus-within:ring-primary-600",
1462
- "focus-within:border-slate-400",
1463
1508
  "hover:border-slate-400",
1464
1509
  "hover:bg-slate-50",
1465
1510
  "bg-white",
1466
1511
  "transition",
1467
- "overflow-hidden",
1468
1512
  ], {
1469
1513
  variants: {
1470
1514
  invalid: {
1471
- true: "border-red-600 text-red-600 focus-within:ring-red-600 hover:border-red-600",
1515
+ true: "border border-red-600 text-red-600 hover:border-red-600",
1472
1516
  false: "",
1473
1517
  },
1474
1518
  disabled: {
1475
- true: "!bg-slate-100",
1519
+ true: "!bg-slate-100 hover:border-slate-300",
1476
1520
  false: "",
1477
1521
  },
1478
1522
  },
@@ -1481,10 +1525,56 @@ const cvaSelect = cvaMerge([
1481
1525
  disabled: false,
1482
1526
  },
1483
1527
  });
1484
- const cvaSelectIcon = cvaMerge(["mr-2", "flex", "cursor-pointer", "items-center", "justify-center", "text-slate-400", "hover:text-slate-500"]);
1485
- const cvaSelectPrefix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "pl-2"]);
1486
- const cvaSelectXIcon = cvaMerge(["mr-2", "flex", "cursor-pointer", "items-center", "justify-center", "text-slate-400", "hover:text-slate-500", "ml-1"]);
1487
- const cvaSelectMenuList = cvaMerge(["min-w-min", "shadow-md", "rounded-lg", "z-20", "bg-white", "p-1", "border", "border-slate-300", "gap-1", "grid"], {
1528
+ const cvaSelectControl = cvaMerge([], {
1529
+ variants: {
1530
+ isDisabled: {
1531
+ true: "!bg-slate-100",
1532
+ false: "",
1533
+ },
1534
+ prefix: {
1535
+ true: ["ps-7"],
1536
+ false: "",
1537
+ },
1538
+ invalid: {
1539
+ true: "!border-0",
1540
+ false: "",
1541
+ },
1542
+ },
1543
+ defaultVariants: {
1544
+ isDisabled: false,
1545
+ prefix: false,
1546
+ invalid: false,
1547
+ },
1548
+ });
1549
+ const cvaSelectIcon = cvaMerge([
1550
+ "mr-2",
1551
+ "flex",
1552
+ "cursor-pointer",
1553
+ "items-center",
1554
+ "justify-center",
1555
+ "text-slate-400",
1556
+ "hover:text-slate-500",
1557
+ ]);
1558
+ const cvaSelectPrefix = cvaMerge([
1559
+ "flex",
1560
+ "justify-center",
1561
+ "items-center",
1562
+ "text-slate-400",
1563
+ "pl-2",
1564
+ "absolute",
1565
+ "inset-y-0",
1566
+ ]);
1567
+ const cvaSelectXIcon = cvaMerge([
1568
+ "mr-2",
1569
+ "flex",
1570
+ "cursor-pointer",
1571
+ "items-center",
1572
+ "justify-center",
1573
+ "text-slate-400",
1574
+ "hover:text-slate-500",
1575
+ "ml-1",
1576
+ ]);
1577
+ const cvaSelectMenuList = cvaMerge([], {
1488
1578
  variants: {
1489
1579
  menuIsOpen: {
1490
1580
  true: "animate-fade-in-fast",
@@ -1667,7 +1757,7 @@ const TagsContainer = ({ items, width = "100%", itemsGap = 5, postFix, disabled
1667
1757
  * @param {JSX.Element} dropdownIcon an custom dropdown icon
1668
1758
  * @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
1669
1759
  */
1670
- const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
1760
+ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError) => {
1671
1761
  const [t] = useTranslation();
1672
1762
  // perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
1673
1763
  const customComponents = React.useMemo(() => {
@@ -1718,7 +1808,11 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
1718
1808
  }
1719
1809
  return (jsx(components.ClearIndicator, Object.assign({}, props, { children: jsx("div", { className: cvaSelectXIcon(), "data-testid": dataTestId ? `${dataTestId}-XMarkIcon` : null, onClick: props.clearValue, children: jsx(Icon, { name: "XCircle", size: "medium", title: t("clearIndicator.icon.tooltip.clearAll") }) }) })));
1720
1810
  }, Control: props => {
1721
- return jsx(components.Control, Object.assign({}, props, { className: props.isDisabled ? "bg-slate-100" : "" }));
1811
+ return (jsx(components.Control, Object.assign({}, props, { className: cvaSelectControl({
1812
+ isDisabled: props.isDisabled,
1813
+ prefix: prefix ? true : false,
1814
+ invalid: hasError,
1815
+ }) })));
1722
1816
  }, SingleValue: props => {
1723
1817
  return (jsx(components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? "text-slate-700" : "", children: jsx("div", { "data-testid": dataTestId + "-singleValue", children: props.children }) })));
1724
1818
  }, Menu: props => {
@@ -1758,18 +1852,16 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
1758
1852
  const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled) => {
1759
1853
  const customStyles = React.useMemo(() => {
1760
1854
  return Object.assign({ control: base => {
1761
- return Object.assign(Object.assign({}, base), { border: "0", boxShadow: "0", "&:hover": {
1762
- border: "0",
1763
- }, backgroundColor: "" });
1855
+ return Object.assign(Object.assign({}, base), { borderRadius: "var(--border-radius-lg)", backgroundColor: "" });
1764
1856
  }, singleValue: base => (Object.assign({}, base)), multiValue: base => (Object.assign({}, base)), multiValueLabel: base => (Object.assign({}, base)), indicatorsContainer: base => (Object.assign(Object.assign({}, base), (disabled && { display: "none" }))), indicatorSeparator: () => ({
1765
1857
  width: "0px",
1766
1858
  }), menu: base => {
1767
1859
  return Object.assign(Object.assign({}, base), { width: "100%", marginTop: "4px", marginBottom: "18px", transition: "all 1s ease-in-out" });
1768
- }, input: base => (Object.assign(Object.assign({}, base), { marginLeft: "0px" })), placeholder: base => (Object.assign({}, base)), option: () => ({}), menuPortal: base => (Object.assign(Object.assign({}, base), { width: refContainer.current ? `${refContainer.current.clientWidth}px` : base.width, transform: refPrefix.current ? `translate(-${refPrefix.current.clientWidth + 2}px)` : "translate(-2px)", backgroundColor: "#ffffff", borderRadius: "var(--border-radius-lg)", zIndex: 20, borderColor: "rgb(var(--color-slate-300))", boxShadow: "var(--tw-ring-inset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)" })), menuList: base => {
1860
+ }, input: base => (Object.assign(Object.assign({}, base), { marginLeft: "0px" })), placeholder: base => (Object.assign({}, base)), option: () => ({}), menuPortal: base => (Object.assign(Object.assign({}, base), { width: refContainer.current ? `${refContainer.current.clientWidth}px` : base.width, transform: "translate(0px, 0px)", backgroundColor: "#ffffff", borderRadius: "var(--border-radius-lg)", zIndex: 20, borderColor: "rgb(var(--color-slate-300))", boxShadow: "var(--tw-ring-inset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)" })), menuList: base => {
1769
1861
  return Object.assign(Object.assign({}, base), { position: "relative", padding: "var(--spacing-1)", display: "grid", gap: "var(--spacing-1)", width: "100%", borderRadius: "0px", boxShadow: "none", paddingTop: "0px" });
1770
1862
  }, valueContainer: base => {
1771
1863
  return Object.assign(Object.assign({}, base), { flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap", gap: "0.25rem" });
1772
- }, container: base => (Object.assign(Object.assign({}, base), { border: "none", width: "100%" })), dropdownIndicator: base => (Object.assign(Object.assign({}, base), { padding: "0px" })), clearIndicator: base => {
1864
+ }, container: base => (Object.assign(Object.assign({}, base), { width: "100%" })), dropdownIndicator: base => (Object.assign(Object.assign({}, base), { padding: "0px" })), clearIndicator: base => {
1773
1865
  return Object.assign(Object.assign({}, base), { padding: "0px" });
1774
1866
  } }, styles);
1775
1867
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1791,7 +1883,7 @@ const useSelect = (_a) => {
1791
1883
  const { customStyles } = useCustomStyles(refContainer, refPrefix, maxSelectedDisplayCount, styles, disabled);
1792
1884
  const [menuIsOpen, setMenuIsOpen] = React__default.useState((_b = props.menuIsOpen) !== null && _b !== void 0 ? _b : false);
1793
1885
  const refMenuIsEnabled = React__default.useRef(true);
1794
- const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon);
1886
+ const customComponents = useCustomComponents(components, disabled || false, menuIsOpen, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon, prefix, hasError);
1795
1887
  const menuPlacement = "auto";
1796
1888
  const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
1797
1889
  onMenuOpen && onMenuOpen();
@@ -1864,6 +1956,8 @@ const CreatableSelect = (props) => {
1864
1956
  onInputChange,
1865
1957
  allowCreateWhileLoading,
1866
1958
  onCreateOption,
1959
+ isDisabled: disabled || props.isDisabled,
1960
+ readOnly,
1867
1961
  };
1868
1962
  const renderAsDisabled = rest.disabled || rest.readOnly || rest.isDisabled; // TODO remove one of the disable props from the type
1869
1963
  return (jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })), async ? (jsx(ReactAsyncCreatableSelect, Object.assign({}, rest, creatableSelectProps, async, { onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : placeholder }))) : (jsx(ReactCreatableSelect, Object.assign({}, rest, creatableSelectProps, { hideSelectedOptions: false, isMulti: isMulti, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : placeholder })))] }));
@@ -1907,6 +2001,8 @@ const Select = (props) => {
1907
2001
  onMenuScrollToBottom,
1908
2002
  onInputChange,
1909
2003
  hideSelectedOptions,
2004
+ isDisabled: disabled || props.isDisabled,
2005
+ readOnly,
1910
2006
  };
1911
2007
  const renderAsDisabled = rest.disabled || rest.readOnly || rest.isDisabled; // TODO remove one of the disable props from the type
1912
2008
  return (jsxs("div", { className: cvaSelect({ invalid: hasError, disabled: disabled || readOnly, className }), "data-testid": dataTestId, ref: refContainer, children: [prefix !== undefined && (jsx("div", { className: cvaSelectPrefix(), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: refPrefix, children: prefix })), async ? (jsx(ReactAsyncSelect, Object.assign({}, rest, selectProps, async, { menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, placeholder: renderAsDisabled ? null : placeholder }))) : (jsx(ReactSelect, Object.assign({}, rest, selectProps, { isMulti: isMulti, menuPosition: menuPosition, onMenuClose: closeMenuHandler, onMenuOpen: openMenuHandler, options: filterOption ? orderedOptions : options, placeholder: renderAsDisabled ? null : placeholder })))] }));
@@ -2007,7 +2103,6 @@ const cvaTextArea = cvaMerge([
2007
2103
  "text-base",
2008
2104
  "text-slate-900",
2009
2105
  "placeholder-slate-400",
2010
- "focus-visible:outline-none",
2011
2106
  "w-full",
2012
2107
  "h-20",
2013
2108
  "transition",
@@ -2086,7 +2181,7 @@ const TextField = React.forwardRef((_a, ref) => {
2086
2181
  }
2087
2182
  }, [onChange]);
2088
2183
  return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon ||
2089
- (typeof maxLength === "number" && jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength })), helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsx(TextInput, Object.assign({ "aria-labelledby": htmlFor + "-label", disabled: rest.readOnly, id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId, onChange: handleChange })) }));
2184
+ (typeof maxLength === "number" && jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength })), helpText: (renderAsInvalid && errorMessage) || helpText, htmlFor: htmlFor, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsx(TextInput, Object.assign({ "aria-labelledby": htmlFor + "-label", id: htmlFor, isInvalid: renderAsInvalid, maxLength: maxLength, ref: ref, value: value }, rest, { className: className, dataTestId: dataTestId, onChange: handleChange })) }));
2090
2185
  });
2091
2186
  TextField.displayName = "TextField";
2092
2187
 
@@ -2105,16 +2200,7 @@ const TimeRangeField = (_a) => {
2105
2200
 
2106
2201
  const cvaToggleWrapper = cvaMerge(["flex", "gap-2", "items-center"]);
2107
2202
  cvaMerge(["relative"]);
2108
- const cvaToggleTrack = cvaMerge([
2109
- "shrink-0",
2110
- "p-1",
2111
- "cursor-pointer",
2112
- "rounded-full",
2113
- "bg-slate-300",
2114
- "focus:bg-slate-400",
2115
- "hover:bg-slate-400",
2116
- "active:bg-slate-500",
2117
- ], {
2203
+ const cvaToggleTrack = cvaMerge(["shrink-0", "p-1", "cursor-pointer", "rounded-full", "bg-slate-300", "hover:bg-slate-400", "active:bg-slate-500"], {
2118
2204
  variants: {
2119
2205
  size: {
2120
2206
  small: ["w-8", "h-4"],
@@ -2125,7 +2211,7 @@ const cvaToggleTrack = cvaMerge([
2125
2211
  false: "",
2126
2212
  },
2127
2213
  toggled: {
2128
- true: ["bg-primary-600", "focus:bg-primary-700", "hover:bg-primary-700", "active:bg-primary-800"],
2214
+ true: ["bg-primary-600", "hover:bg-primary-700", "active:bg-primary-800"],
2129
2215
  false: "",
2130
2216
  },
2131
2217
  },
@@ -2246,7 +2332,7 @@ const UrlInput = forwardRef((_a, ref) => {
2246
2332
  var { dataTestId, isInvalid, disabled = false, fieldSize = "medium", disableAction = false, value, defaultValue } = _a, rest = __rest(_a, ["dataTestId", "isInvalid", "disabled", "fieldSize", "disableAction", "value", "defaultValue"]);
2247
2333
  const [url, setUrl] = useState((value === null || value === void 0 ? void 0 : value.toString()) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString()));
2248
2334
  const renderAsInvalid = (url && typeof url === "string" && !validateUrlAddress(url)) || isInvalid;
2249
- return (jsx(BaseInput, Object.assign({ dataTestId: dataTestId ? `${dataTestId}-url-input` : undefined, disabled: disabled, id: "url-input", isInvalid: renderAsInvalid, onChange: e => setUrl(e.target.value), placeholder: rest.placeholder || "https://www.example.com", ref: ref, type: "url", value: url }, rest, { actions: !disableAction && (jsx(ActionButton, { dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", disabled: renderAsInvalid || disabled, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) })));
2335
+ return (jsx(BaseInput, Object.assign({ dataTestId: dataTestId ? `${dataTestId}-url-input` : undefined, disabled: disabled, id: "url-input", isInvalid: renderAsInvalid, onChange: e => setUrl(e.target.value), placeholder: rest.placeholder || "https://www.example.com", ref: ref, type: "url", value: url }, rest, { actions: !disableAction && (jsx(ActionButton, { dataTestId: (dataTestId && `${dataTestId}-url-input-Icon`) || "url-input-action-icon", disabled: renderAsInvalid || disableAction, iconSize: fieldSize, type: "WEB_ADDRESS", value: url })) })));
2250
2336
  });
2251
2337
  UrlInput.displayName = "UrlField";
2252
2338
 
@@ -2263,7 +2349,7 @@ const UrlField = forwardRef((_a, ref) => {
2263
2349
  return typeof inputValue === "string";
2264
2350
  }
2265
2351
  const renderAsInvalid = !!errorMessage || (value && isString(value) && !validateUrlAddress(value)) || isInvalid;
2266
- return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: renderAsInvalid ? errorMessage : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", disabled: rest.disabled, id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
2352
+ return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, disabled: rest.disabled, helpAddon: helpAddon, helpText: renderAsInvalid ? errorMessage : helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, required: rest.required, tip: tip, children: jsx(UrlInput, Object.assign({ "aria-labelledby": htmlForId + "-label", id: htmlForId, isInvalid: renderAsInvalid, ref: ref, value: value || defaultValue }, rest, { className: className, dataTestId: dataTestId })) }));
2267
2353
  });
2268
2354
  UrlField.displayName = "UrlField";
2269
2355
 
@@ -2371,4 +2457,4 @@ const useZodValidators = () => {
2371
2457
  */
2372
2458
  setupLibraryTranslations();
2373
2459
 
2374
- export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, isValidHEXColor, parseSchedule, serializeSchedule, useCustomComponents, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
2460
+ export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAction, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectControl, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, isValidHEXColor, parseSchedule, serializeSchedule, useCustomComponents, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.453",
3
+ "version": "0.0.455",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {