@trackunit/react-form-components 1.8.44 → 1.8.46
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.cjs.js +27 -6
- package/index.esm.js +29 -8
- package/package.json +8 -8
- package/src/components/ColorField/ColorField.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -434,9 +434,30 @@ const BaseInput = ({ className, isInvalid, dataTestId, prefix, suffix, addonBefo
|
|
|
434
434
|
const renderAsDisabled = Boolean(rest.disabled);
|
|
435
435
|
const renderAsReadonly = Boolean(rest.readOnly);
|
|
436
436
|
const beforeContainerRef = react.useRef(null);
|
|
437
|
-
const { width: beforeContainerWidth } = reactComponents.useGeometry(beforeContainerRef);
|
|
438
437
|
const afterContainerRef = react.useRef(null);
|
|
439
|
-
|
|
438
|
+
react.useEffect(() => {
|
|
439
|
+
const setVars = () => {
|
|
440
|
+
const beforeEl = beforeContainerRef.current || null;
|
|
441
|
+
const afterEl = afterContainerRef.current || null;
|
|
442
|
+
if (beforeEl) {
|
|
443
|
+
beforeEl.parentElement?.style.setProperty("--before-width", `${Math.ceil(beforeEl.offsetWidth)}px`);
|
|
444
|
+
}
|
|
445
|
+
if (afterEl) {
|
|
446
|
+
afterEl.parentElement?.style.setProperty("--after-width", `${Math.ceil(afterEl.offsetWidth)}px`);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
const ro = new ResizeObserver(setVars);
|
|
450
|
+
const beforeElement = beforeContainerRef.current || null;
|
|
451
|
+
const afterElement = afterContainerRef.current || null;
|
|
452
|
+
if (beforeElement) {
|
|
453
|
+
ro.observe(beforeElement);
|
|
454
|
+
}
|
|
455
|
+
if (afterElement) {
|
|
456
|
+
ro.observe(afterElement);
|
|
457
|
+
}
|
|
458
|
+
requestAnimationFrame(setVars);
|
|
459
|
+
return () => ro.disconnect();
|
|
460
|
+
}, []);
|
|
440
461
|
// Keep a reference to the input element
|
|
441
462
|
const innerRef = react.useRef(null);
|
|
442
463
|
react.useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -452,8 +473,8 @@ const BaseInput = ({ className, isInvalid, dataTestId, prefix, suffix, addonBefo
|
|
|
452
473
|
disabled: renderAsDisabled,
|
|
453
474
|
className: cvaInputItemPlacementManager({ position: "span", className: inputClassName }),
|
|
454
475
|
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef, style: {
|
|
455
|
-
paddingLeft:
|
|
456
|
-
paddingRight:
|
|
476
|
+
paddingLeft: `calc(var(--before-width, 0px) + ${uiDesignTokens.themeSpacing[2]})`,
|
|
477
|
+
paddingRight: `calc(var(--after-width, 0px) + ${uiDesignTokens.themeSpacing[2]})`,
|
|
457
478
|
}, type: type, ...rest, disabled: renderAsDisabled, readOnly: renderAsReadonly || nonInteractive }), jsxRuntime.jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "after" }) }), "data-testid": dataTestId ? `${dataTestId}-after-container` : undefined, ref: afterContainerRef, children: [jsxRuntime.jsx(LockReasonRenderer, { dataTestId: dataTestId + "-disabled", lockReason: rest.disabled }), jsxRuntime.jsx(LockReasonRenderer, { dataTestId: dataTestId + "-readonly", lockReason: rest.readOnly && !rest.disabled ? rest.readOnly : undefined }), jsxRuntime.jsx(GenericActionsRenderer, { fieldSize: fieldSize, genericAction: genericAction, innerRef: innerRef }), jsxRuntime.jsx(SuffixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, isInvalid: isInvalid, isWarning: isWarning, suffix: suffix }), actions, jsxRuntime.jsx(AddonRenderer, { addon: addonAfter, dataTestId: dataTestId, fieldSize: fieldSize, position: "after" })] })] }));
|
|
458
479
|
};
|
|
459
480
|
BaseInput.displayName = "BaseInput";
|
|
@@ -1026,7 +1047,7 @@ const cvaInputColorField = cssClassVarianceUtilities.cvaMerge([
|
|
|
1026
1047
|
* Validates if the given value is a valid hex color.
|
|
1027
1048
|
*
|
|
1028
1049
|
* @param value - The string value to be validated.
|
|
1029
|
-
* @returns True if the value is a valid hex color, otherwise false.
|
|
1050
|
+
* @returns {boolean} True if the value is a valid hex color, otherwise false.
|
|
1030
1051
|
*/
|
|
1031
1052
|
const isValidHEXColor = (value) => {
|
|
1032
1053
|
const hexRegex = /^#([0-9A-F]{6})$/i;
|
|
@@ -1257,7 +1278,7 @@ const EmailBaseInput = ({ fieldSize = "medium", disabled = false, dataTestId, is
|
|
|
1257
1278
|
setEmail(newValue);
|
|
1258
1279
|
}, [onChange]);
|
|
1259
1280
|
const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
|
|
1260
|
-
return (jsxRuntime.jsx(BaseInput, { actions: email && email.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, onClick: sendEmail, size: fieldSize ?? undefined, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email", ...rest }));
|
|
1281
|
+
return (jsxRuntime.jsx(BaseInput, { actions: email && email.length > 0 ? (jsxRuntime.jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, onClick: sendEmail, size: fieldSize ?? undefined, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, fieldSize: fieldSize, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email", ...rest }));
|
|
1261
1282
|
};
|
|
1262
1283
|
|
|
1263
1284
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useNamespaceTranslation, registerTranslations, NamespaceTrans } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { Temporal } from '@js-temporal/polyfill';
|
|
4
|
-
import { IconButton, Icon, Tooltip,
|
|
4
|
+
import { IconButton, Icon, Tooltip, useIsTextTruncated, Text, Heading, Tag, Spinner, MenuItem, useResize, useDebounce, useIsFirstRender } from '@trackunit/react-components';
|
|
5
5
|
import { themeSpacing } from '@trackunit/ui-design-tokens';
|
|
6
|
-
import { forwardRef, useRef, useImperativeHandle, useCallback,
|
|
6
|
+
import { forwardRef, useRef, useEffect, useImperativeHandle, useCallback, useState, useMemo, cloneElement, createContext, useContext, isValidElement, useLayoutEffect } from 'react';
|
|
7
7
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
8
8
|
import { titleCase } from 'string-ts';
|
|
9
9
|
import { useCopyToClipboard } from 'usehooks-ts';
|
|
@@ -433,9 +433,30 @@ const BaseInput = ({ className, isInvalid, dataTestId, prefix, suffix, addonBefo
|
|
|
433
433
|
const renderAsDisabled = Boolean(rest.disabled);
|
|
434
434
|
const renderAsReadonly = Boolean(rest.readOnly);
|
|
435
435
|
const beforeContainerRef = useRef(null);
|
|
436
|
-
const { width: beforeContainerWidth } = useGeometry(beforeContainerRef);
|
|
437
436
|
const afterContainerRef = useRef(null);
|
|
438
|
-
|
|
437
|
+
useEffect(() => {
|
|
438
|
+
const setVars = () => {
|
|
439
|
+
const beforeEl = beforeContainerRef.current || null;
|
|
440
|
+
const afterEl = afterContainerRef.current || null;
|
|
441
|
+
if (beforeEl) {
|
|
442
|
+
beforeEl.parentElement?.style.setProperty("--before-width", `${Math.ceil(beforeEl.offsetWidth)}px`);
|
|
443
|
+
}
|
|
444
|
+
if (afterEl) {
|
|
445
|
+
afterEl.parentElement?.style.setProperty("--after-width", `${Math.ceil(afterEl.offsetWidth)}px`);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const ro = new ResizeObserver(setVars);
|
|
449
|
+
const beforeElement = beforeContainerRef.current || null;
|
|
450
|
+
const afterElement = afterContainerRef.current || null;
|
|
451
|
+
if (beforeElement) {
|
|
452
|
+
ro.observe(beforeElement);
|
|
453
|
+
}
|
|
454
|
+
if (afterElement) {
|
|
455
|
+
ro.observe(afterElement);
|
|
456
|
+
}
|
|
457
|
+
requestAnimationFrame(setVars);
|
|
458
|
+
return () => ro.disconnect();
|
|
459
|
+
}, []);
|
|
439
460
|
// Keep a reference to the input element
|
|
440
461
|
const innerRef = useRef(null);
|
|
441
462
|
useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -451,8 +472,8 @@ const BaseInput = ({ className, isInvalid, dataTestId, prefix, suffix, addonBefo
|
|
|
451
472
|
disabled: renderAsDisabled,
|
|
452
473
|
className: cvaInputItemPlacementManager({ position: "span", className: inputClassName }),
|
|
453
474
|
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef, style: {
|
|
454
|
-
paddingLeft:
|
|
455
|
-
paddingRight:
|
|
475
|
+
paddingLeft: `calc(var(--before-width, 0px) + ${themeSpacing[2]})`,
|
|
476
|
+
paddingRight: `calc(var(--after-width, 0px) + ${themeSpacing[2]})`,
|
|
456
477
|
}, type: type, ...rest, disabled: renderAsDisabled, readOnly: renderAsReadonly || nonInteractive }), jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "after" }) }), "data-testid": dataTestId ? `${dataTestId}-after-container` : undefined, ref: afterContainerRef, children: [jsx(LockReasonRenderer, { dataTestId: dataTestId + "-disabled", lockReason: rest.disabled }), jsx(LockReasonRenderer, { dataTestId: dataTestId + "-readonly", lockReason: rest.readOnly && !rest.disabled ? rest.readOnly : undefined }), jsx(GenericActionsRenderer, { fieldSize: fieldSize, genericAction: genericAction, innerRef: innerRef }), jsx(SuffixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, isInvalid: isInvalid, isWarning: isWarning, suffix: suffix }), actions, jsx(AddonRenderer, { addon: addonAfter, dataTestId: dataTestId, fieldSize: fieldSize, position: "after" })] })] }));
|
|
457
478
|
};
|
|
458
479
|
BaseInput.displayName = "BaseInput";
|
|
@@ -1025,7 +1046,7 @@ const cvaInputColorField = cvaMerge([
|
|
|
1025
1046
|
* Validates if the given value is a valid hex color.
|
|
1026
1047
|
*
|
|
1027
1048
|
* @param value - The string value to be validated.
|
|
1028
|
-
* @returns True if the value is a valid hex color, otherwise false.
|
|
1049
|
+
* @returns {boolean} True if the value is a valid hex color, otherwise false.
|
|
1029
1050
|
*/
|
|
1030
1051
|
const isValidHEXColor = (value) => {
|
|
1031
1052
|
const hexRegex = /^#([0-9A-F]{6})$/i;
|
|
@@ -1256,7 +1277,7 @@ const EmailBaseInput = ({ fieldSize = "medium", disabled = false, dataTestId, is
|
|
|
1256
1277
|
setEmail(newValue);
|
|
1257
1278
|
}, [onChange]);
|
|
1258
1279
|
const renderAsInvalid = (email && !validateEmailAddress(email)) || isInvalid;
|
|
1259
|
-
return (jsx(BaseInput, { actions: email && email.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, onClick: sendEmail, size: fieldSize ?? undefined, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email", ...rest }));
|
|
1280
|
+
return (jsx(BaseInput, { actions: email && email.length > 0 ? (jsx(ActionButton, { dataTestId: dataTestId ? `${dataTestId}-emailIcon` : undefined, disabled: disableAction || isInvalid, onClick: sendEmail, size: fieldSize ?? undefined, type: "EMAIL", value: email })) : null, dataTestId: dataTestId, disabled: disabled, fieldSize: fieldSize, isInvalid: renderAsInvalid, onChange: handleChange, placeholder: rest.placeholder || "mail@example.com", ref: ref, type: "email", ...rest }));
|
|
1260
1281
|
};
|
|
1261
1282
|
|
|
1262
1283
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-components",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.46",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"zod": "^3.23.8",
|
|
17
17
|
"react-hook-form": "7.62.0",
|
|
18
18
|
"tailwind-merge": "^2.0.0",
|
|
19
|
-
"@trackunit/css-class-variance-utilities": "1.7.
|
|
20
|
-
"@trackunit/react-components": "1.9.
|
|
21
|
-
"@trackunit/ui-icons": "1.7.
|
|
22
|
-
"@trackunit/shared-utils": "1.9.
|
|
23
|
-
"@trackunit/ui-design-tokens": "1.7.
|
|
24
|
-
"@trackunit/i18n-library-translation": "1.7.
|
|
19
|
+
"@trackunit/css-class-variance-utilities": "1.7.30",
|
|
20
|
+
"@trackunit/react-components": "1.9.44",
|
|
21
|
+
"@trackunit/ui-icons": "1.7.32",
|
|
22
|
+
"@trackunit/shared-utils": "1.9.30",
|
|
23
|
+
"@trackunit/ui-design-tokens": "1.7.31",
|
|
24
|
+
"@trackunit/i18n-library-translation": "1.7.36",
|
|
25
25
|
"string-ts": "^2.0.0",
|
|
26
|
-
"@trackunit/react-test-setup": "1.4.
|
|
26
|
+
"@trackunit/react-test-setup": "1.4.30",
|
|
27
27
|
"@js-temporal/polyfill": "^0.5.1"
|
|
28
28
|
},
|
|
29
29
|
"module": "./index.esm.js",
|
|
@@ -5,7 +5,7 @@ type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" |
|
|
|
5
5
|
* Validates if the given value is a valid hex color.
|
|
6
6
|
*
|
|
7
7
|
* @param value - The string value to be validated.
|
|
8
|
-
* @returns True if the value is a valid hex color, otherwise false.
|
|
8
|
+
* @returns {boolean} True if the value is a valid hex color, otherwise false.
|
|
9
9
|
*/
|
|
10
10
|
export declare const isValidHEXColor: (value: string) => boolean;
|
|
11
11
|
export interface ColorFieldProps extends FormGroupExposedProps, BaseInputProps {
|