@trackunit/react-form-components 1.27.4 → 1.27.6

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 CHANGED
@@ -2407,6 +2407,14 @@ formatOptionLabel, }) => {
2407
2407
  // from this ref, so the latest function is always used.
2408
2408
  const formatOptionLabelRef = react.useRef(formatOptionLabel);
2409
2409
  formatOptionLabelRef.current = formatOptionLabel;
2410
+ const getOptionLabelDescriptionRef = react.useRef(getOptionLabelDescription);
2411
+ getOptionLabelDescriptionRef.current = getOptionLabelDescription;
2412
+ const getOptionPrefixRef = react.useRef(getOptionPrefix);
2413
+ getOptionPrefixRef.current = getOptionPrefix;
2414
+ const resolveOptionPrefixRef = react.useRef(undefined);
2415
+ if (resolveOptionPrefixRef.current === undefined) {
2416
+ resolveOptionPrefixRef.current = (data) => getOptionPrefixRef.current?.(data);
2417
+ }
2410
2418
  // perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
2411
2419
  // Component functions stay stable (reading from refs), so react-select won't lose focus
2412
2420
  const customComponents = react.useMemo(() => {
@@ -2479,10 +2487,11 @@ formatOptionLabel, }) => {
2479
2487
  return (jsxRuntime.jsx(ReactSelect.components.NoOptionsMessage, { ...selectNoOptionsMessage, className: cvaSelectNoOptionsMessage({ className: selectNoOptionsMessage.className }), getStyles: getNoStyles, children: selectNoOptionsMessage.children ?? t("select.noOptionsMessage") }));
2480
2488
  },
2481
2489
  SingleValue: selectSingleValue => {
2482
- const optionPrefix = getOptionPrefix ? getOptionPrefix(selectSingleValue.data) : null;
2490
+ const optionPrefix = getOptionPrefixRef.current ? getOptionPrefixRef.current(selectSingleValue.data) : null;
2491
+ const optionLabelDescription = getOptionLabelDescriptionRef.current?.(selectSingleValue.data);
2483
2492
  return (jsxRuntime.jsx(ReactSelect.components.SingleValue, { ...selectSingleValue, className: cvaSelectSingleValue({
2484
2493
  className: selectSingleValue.className,
2485
- }), getStyles: getNoStyles, children: jsxRuntime.jsxs("div", { className: "flex items-center gap-1", "data-testid": dataTestId + "-singleValue", children: [optionPrefix !== null ? optionPrefix : null, selectSingleValue.children, getOptionLabelDescription && getOptionLabelDescription(selectSingleValue.data) ? (jsxRuntime.jsxs("span", { className: "ml-1 text-neutral-400", children: ["(", getOptionLabelDescription(selectSingleValue.data), ")"] })) : null] }) }));
2494
+ }), getStyles: getNoStyles, children: jsxRuntime.jsxs("div", { className: "flex items-center gap-1", "data-testid": dataTestId + "-singleValue", children: [optionPrefix !== null ? optionPrefix : null, selectSingleValue.children, optionLabelDescription !== undefined && optionLabelDescription !== "" ? (jsxRuntime.jsxs("span", { className: "ml-1 text-neutral-400", children: ["(", optionLabelDescription, ")"] })) : null] }) }));
2486
2495
  },
2487
2496
  MultiValueContainer: ({ children }) => children, // Just pass on the children
2488
2497
  MultiValueRemove: () => null, // is built-in to the MultiValue (tag) component
@@ -2496,7 +2505,7 @@ formatOptionLabel, }) => {
2496
2505
  return (jsxRuntime.jsx(ReactSelect.components.MultiValue, { ...selectMultiValue, getStyles: getNoStyles, children: jsxRuntime.jsx(MultiValue, { className: cvaSelectMultiValue({
2497
2506
  hidden: currentIsComplete && index + 1 > currentVisibleCount, // Hide if doesn't fit
2498
2507
  invisible: currentWithCounter && !currentIsComplete, // Make invisible if measuring with counter. When there's a counter, it would otherwise briefly change layout to make room for the "fake" counter
2499
- }), data: selectMultiValue.data, "data-testid": dataTestId ? `${dataTestId}-multiValue-${index}` : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, getOptionPrefix: getOptionPrefix, onClose: selectMultiValue.removeProps.onClick, ref: setGeometryRef(index), removeTagLabel: t("select.multiValue.remove"), children: selectMultiValue.children }) }));
2508
+ }), data: selectMultiValue.data, "data-testid": dataTestId ? `${dataTestId}-multiValue-${index}` : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, getOptionPrefix: getOptionPrefixRef.current ? resolveOptionPrefixRef.current : undefined, onClose: selectMultiValue.removeProps.onClick, ref: setGeometryRef(index), removeTagLabel: t("select.multiValue.remove"), children: selectMultiValue.children }) }));
2500
2509
  },
2501
2510
  Menu: selectMenu => {
2502
2511
  return (jsxRuntime.jsx(ReactSelect.components.Menu, { ...selectMenu, className: cvaSelectMenu({ className: selectMenu.className, placement: selectMenu.placement }), getStyles: getNoStyles, innerProps: {
@@ -2542,7 +2551,7 @@ formatOptionLabel, }) => {
2542
2551
  return (jsxRuntime.jsx(ReactSelect.components.Option, { ...selectOption, innerProps: {
2543
2552
  ...selectOption.innerProps,
2544
2553
  role: "option",
2545
- }, children: selectOption.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescription?.(selectOption.data), optionPrefix: getOptionPrefix?.(selectOption.data) })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: optionDisabled, fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescription?.(selectOption.data), optionPrefix: getOptionPrefix?.(selectOption.data) })) }));
2554
+ }, children: selectOption.isMulti ? (jsxRuntime.jsx(MultiSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescriptionRef.current?.(selectOption.data), optionPrefix: getOptionPrefixRef.current?.(selectOption.data) })) : (jsxRuntime.jsx(SingleSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: optionDisabled, fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescriptionRef.current?.(selectOption.data), optionPrefix: getOptionPrefixRef.current?.(selectOption.data) })) }));
2546
2555
  },
2547
2556
  };
2548
2557
  }, [
@@ -2563,8 +2572,6 @@ formatOptionLabel, }) => {
2563
2572
  setCounterRef,
2564
2573
  autoComplete,
2565
2574
  t,
2566
- getOptionPrefix,
2567
- getOptionLabelDescription,
2568
2575
  setGeometryRef,
2569
2576
  setMenuRef,
2570
2577
  ]);
@@ -2605,7 +2612,7 @@ const useSelect = (props) => {
2605
2612
  options, value, defaultValue,
2606
2613
  // Extract callbacks - most are passed through directly to allow recalculation when changed
2607
2614
  // Only onMenuOpen and onMenuClose get wrapped with ref pattern (see below)
2608
- onMenuOpen, onMenuClose, onChange, onInputChange, onFocus, onBlur, getOptionLabel, getOptionValue, filterOption, formatOptionLabel, formatGroupLabel, isOptionDisabled, isOptionSelected, onKeyDown, onMenuScrollToTop, onMenuScrollToBottom,
2615
+ onMenuOpen, onMenuClose, onChange, onInputChange, onFocus, onBlur, getOptionLabel, getOptionValue, filterOption, formatOptionLabel, getOptionLabelDescription, getOptionPrefix, formatGroupLabel, isOptionDisabled, isOptionSelected, onKeyDown, onMenuScrollToTop, onMenuScrollToBottom,
2609
2616
  // Extract other props used in final useMemo
2610
2617
  label, isSearchable, openMenuOnClick, openMenuOnFocus, isMulti, isClearable, menuPlacement, placeholder, hideSelectedOptions, readOnly,
2611
2618
  // Extract commonly-used props to prevent them from ending up in restProps
@@ -2632,8 +2639,8 @@ const useSelect = (props) => {
2632
2639
  prefix: stableRestProps.prefix,
2633
2640
  hasError: stableRestProps.hasError,
2634
2641
  fieldSize: stableRestProps.fieldSize,
2635
- getOptionLabelDescription: stableRestProps.getOptionLabelDescription,
2636
- getOptionPrefix: stableRestProps.getOptionPrefix,
2642
+ getOptionLabelDescription,
2643
+ getOptionPrefix,
2637
2644
  isMulti: isMulti ?? false,
2638
2645
  className: stableRestProps.className,
2639
2646
  autoComplete: stableRestProps.autoComplete,
package/index.esm.js CHANGED
@@ -2406,6 +2406,14 @@ formatOptionLabel, }) => {
2406
2406
  // from this ref, so the latest function is always used.
2407
2407
  const formatOptionLabelRef = useRef(formatOptionLabel);
2408
2408
  formatOptionLabelRef.current = formatOptionLabel;
2409
+ const getOptionLabelDescriptionRef = useRef(getOptionLabelDescription);
2410
+ getOptionLabelDescriptionRef.current = getOptionLabelDescription;
2411
+ const getOptionPrefixRef = useRef(getOptionPrefix);
2412
+ getOptionPrefixRef.current = getOptionPrefix;
2413
+ const resolveOptionPrefixRef = useRef(undefined);
2414
+ if (resolveOptionPrefixRef.current === undefined) {
2415
+ resolveOptionPrefixRef.current = (data) => getOptionPrefixRef.current?.(data);
2416
+ }
2409
2417
  // perhaps it should not be wrap in memo (causing some issues with opening and closing on mobiles)
2410
2418
  // Component functions stay stable (reading from refs), so react-select won't lose focus
2411
2419
  const customComponents = useMemo(() => {
@@ -2478,10 +2486,11 @@ formatOptionLabel, }) => {
2478
2486
  return (jsx(components.NoOptionsMessage, { ...selectNoOptionsMessage, className: cvaSelectNoOptionsMessage({ className: selectNoOptionsMessage.className }), getStyles: getNoStyles, children: selectNoOptionsMessage.children ?? t("select.noOptionsMessage") }));
2479
2487
  },
2480
2488
  SingleValue: selectSingleValue => {
2481
- const optionPrefix = getOptionPrefix ? getOptionPrefix(selectSingleValue.data) : null;
2489
+ const optionPrefix = getOptionPrefixRef.current ? getOptionPrefixRef.current(selectSingleValue.data) : null;
2490
+ const optionLabelDescription = getOptionLabelDescriptionRef.current?.(selectSingleValue.data);
2482
2491
  return (jsx(components.SingleValue, { ...selectSingleValue, className: cvaSelectSingleValue({
2483
2492
  className: selectSingleValue.className,
2484
- }), getStyles: getNoStyles, children: jsxs("div", { className: "flex items-center gap-1", "data-testid": dataTestId + "-singleValue", children: [optionPrefix !== null ? optionPrefix : null, selectSingleValue.children, getOptionLabelDescription && getOptionLabelDescription(selectSingleValue.data) ? (jsxs("span", { className: "ml-1 text-neutral-400", children: ["(", getOptionLabelDescription(selectSingleValue.data), ")"] })) : null] }) }));
2493
+ }), getStyles: getNoStyles, children: jsxs("div", { className: "flex items-center gap-1", "data-testid": dataTestId + "-singleValue", children: [optionPrefix !== null ? optionPrefix : null, selectSingleValue.children, optionLabelDescription !== undefined && optionLabelDescription !== "" ? (jsxs("span", { className: "ml-1 text-neutral-400", children: ["(", optionLabelDescription, ")"] })) : null] }) }));
2485
2494
  },
2486
2495
  MultiValueContainer: ({ children }) => children, // Just pass on the children
2487
2496
  MultiValueRemove: () => null, // is built-in to the MultiValue (tag) component
@@ -2495,7 +2504,7 @@ formatOptionLabel, }) => {
2495
2504
  return (jsx(components.MultiValue, { ...selectMultiValue, getStyles: getNoStyles, children: jsx(MultiValue, { className: cvaSelectMultiValue({
2496
2505
  hidden: currentIsComplete && index + 1 > currentVisibleCount, // Hide if doesn't fit
2497
2506
  invisible: currentWithCounter && !currentIsComplete, // Make invisible if measuring with counter. When there's a counter, it would otherwise briefly change layout to make room for the "fake" counter
2498
- }), data: selectMultiValue.data, "data-testid": dataTestId ? `${dataTestId}-multiValue-${index}` : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, getOptionPrefix: getOptionPrefix, onClose: selectMultiValue.removeProps.onClick, ref: setGeometryRef(index), removeTagLabel: t("select.multiValue.remove"), children: selectMultiValue.children }) }));
2507
+ }), data: selectMultiValue.data, "data-testid": dataTestId ? `${dataTestId}-multiValue-${index}` : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, getOptionPrefix: getOptionPrefixRef.current ? resolveOptionPrefixRef.current : undefined, onClose: selectMultiValue.removeProps.onClick, ref: setGeometryRef(index), removeTagLabel: t("select.multiValue.remove"), children: selectMultiValue.children }) }));
2499
2508
  },
2500
2509
  Menu: selectMenu => {
2501
2510
  return (jsx(components.Menu, { ...selectMenu, className: cvaSelectMenu({ className: selectMenu.className, placement: selectMenu.placement }), getStyles: getNoStyles, innerProps: {
@@ -2541,7 +2550,7 @@ formatOptionLabel, }) => {
2541
2550
  return (jsx(components.Option, { ...selectOption, innerProps: {
2542
2551
  ...selectOption.innerProps,
2543
2552
  role: "option",
2544
- }, children: selectOption.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescription?.(selectOption.data), optionPrefix: getOptionPrefix?.(selectOption.data) })) : (jsx(SingleSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: optionDisabled, fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescription?.(selectOption.data), optionPrefix: getOptionPrefix?.(selectOption.data) })) }));
2553
+ }, children: selectOption.isMulti ? (jsx(MultiSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: Boolean(disabled), fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescriptionRef.current?.(selectOption.data), optionPrefix: getOptionPrefixRef.current?.(selectOption.data) })) : (jsx(SingleSelectMenuItem, { ...componentProps, "data-testid": typeof selectOption.label === "string" ? selectOption.label : undefined, disabled: optionDisabled, fieldSize: fieldSize, optionContent: optionContent, optionLabelDescription: getOptionLabelDescriptionRef.current?.(selectOption.data), optionPrefix: getOptionPrefixRef.current?.(selectOption.data) })) }));
2545
2554
  },
2546
2555
  };
2547
2556
  }, [
@@ -2562,8 +2571,6 @@ formatOptionLabel, }) => {
2562
2571
  setCounterRef,
2563
2572
  autoComplete,
2564
2573
  t,
2565
- getOptionPrefix,
2566
- getOptionLabelDescription,
2567
2574
  setGeometryRef,
2568
2575
  setMenuRef,
2569
2576
  ]);
@@ -2604,7 +2611,7 @@ const useSelect = (props) => {
2604
2611
  options, value, defaultValue,
2605
2612
  // Extract callbacks - most are passed through directly to allow recalculation when changed
2606
2613
  // Only onMenuOpen and onMenuClose get wrapped with ref pattern (see below)
2607
- onMenuOpen, onMenuClose, onChange, onInputChange, onFocus, onBlur, getOptionLabel, getOptionValue, filterOption, formatOptionLabel, formatGroupLabel, isOptionDisabled, isOptionSelected, onKeyDown, onMenuScrollToTop, onMenuScrollToBottom,
2614
+ onMenuOpen, onMenuClose, onChange, onInputChange, onFocus, onBlur, getOptionLabel, getOptionValue, filterOption, formatOptionLabel, getOptionLabelDescription, getOptionPrefix, formatGroupLabel, isOptionDisabled, isOptionSelected, onKeyDown, onMenuScrollToTop, onMenuScrollToBottom,
2608
2615
  // Extract other props used in final useMemo
2609
2616
  label, isSearchable, openMenuOnClick, openMenuOnFocus, isMulti, isClearable, menuPlacement, placeholder, hideSelectedOptions, readOnly,
2610
2617
  // Extract commonly-used props to prevent them from ending up in restProps
@@ -2631,8 +2638,8 @@ const useSelect = (props) => {
2631
2638
  prefix: stableRestProps.prefix,
2632
2639
  hasError: stableRestProps.hasError,
2633
2640
  fieldSize: stableRestProps.fieldSize,
2634
- getOptionLabelDescription: stableRestProps.getOptionLabelDescription,
2635
- getOptionPrefix: stableRestProps.getOptionPrefix,
2641
+ getOptionLabelDescription,
2642
+ getOptionPrefix,
2636
2643
  isMulti: isMulti ?? false,
2637
2644
  className: stableRestProps.className,
2638
2645
  autoComplete: stableRestProps.autoComplete,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "1.27.4",
3
+ "version": "1.27.6",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -10,17 +10,17 @@
10
10
  "dependencies": {
11
11
  "react-calendar": "^6.0.0",
12
12
  "react-select": "^5.10.2",
13
- "@trackunit/date-and-time-utils": "1.13.6",
13
+ "@trackunit/date-and-time-utils": "1.13.7",
14
14
  "usehooks-ts": "^3.1.0",
15
15
  "libphonenumber-js": "^1.12.22",
16
16
  "zod": "^3.25.76",
17
17
  "tailwind-merge": "^2.0.0",
18
- "@trackunit/css-class-variance-utilities": "1.13.6",
19
- "@trackunit/react-components": "1.26.3",
20
- "@trackunit/ui-icons": "1.13.6",
21
- "@trackunit/shared-utils": "1.15.6",
22
- "@trackunit/ui-design-tokens": "1.13.6",
23
- "@trackunit/i18n-library-translation": "1.22.1",
18
+ "@trackunit/css-class-variance-utilities": "1.13.7",
19
+ "@trackunit/react-components": "1.26.4",
20
+ "@trackunit/ui-icons": "1.13.7",
21
+ "@trackunit/shared-utils": "1.15.7",
22
+ "@trackunit/ui-design-tokens": "1.13.7",
23
+ "@trackunit/i18n-library-translation": "1.22.2",
24
24
  "string-ts": "^2.0.0",
25
25
  "es-toolkit": "^1.39.10"
26
26
  },