@trackunit/react-table-base-components 2.1.6-alpha-3c308b4aefc.0 → 2.1.7
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
|
@@ -7,6 +7,7 @@ var tailwindMerge = require('tailwind-merge');
|
|
|
7
7
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
8
8
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
9
|
var dateAndTimeUtils = require('@trackunit/date-and-time-utils');
|
|
10
|
+
var reactDateAndTimeHooks = require('@trackunit/react-date-and-time-hooks');
|
|
10
11
|
var react = require('react');
|
|
11
12
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
12
13
|
|
|
@@ -287,7 +288,11 @@ const cvaDateTimeSince$1 = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "
|
|
|
287
288
|
* @param {DateTimeCellProps} props - The props for the DateTimeCell component
|
|
288
289
|
* @returns {ReactElement} DateTimeCell component
|
|
289
290
|
*/
|
|
290
|
-
const DateTimeCell = ({ format,
|
|
291
|
+
const DateTimeCell = ({ format, date, withTimeSince = true, className, "data-testid": dataTestId, style, timeZone: timeZoneProp, locale: localeProp, }) => {
|
|
292
|
+
const { preferred: preferredTimezone } = reactDateAndTimeHooks.useTimezone();
|
|
293
|
+
const resolvedLocale = reactDateAndTimeHooks.useLocale();
|
|
294
|
+
const timeZone = timeZoneProp ?? preferredTimezone.id;
|
|
295
|
+
const locale = localeProp ?? resolvedLocale;
|
|
291
296
|
if (!date) {
|
|
292
297
|
return null;
|
|
293
298
|
}
|
|
@@ -627,12 +632,19 @@ const cvaMultiValueTextCellTooltip = cssClassVarianceUtilities.cvaMerge(["whites
|
|
|
627
632
|
* @param {MultiValueTextCellProps} props - The props for the MultiValueTextCell component
|
|
628
633
|
* @returns {ReactElement} MultiValueTextCell component
|
|
629
634
|
*/
|
|
630
|
-
const MultiValueTextCell = ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, }) => {
|
|
635
|
+
const MultiValueTextCell = ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, unifiedTooltip = false, }) => {
|
|
631
636
|
const [isTooltipVisible, setIsTooltipVisible] = react.useState(false);
|
|
632
637
|
const updateTooltipVisibility = (element) => {
|
|
633
638
|
setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
|
|
634
639
|
};
|
|
635
|
-
|
|
640
|
+
const isCountDefined = count !== undefined && count !== null;
|
|
641
|
+
const isMultiValueCell = isCountDefined && count > 1;
|
|
642
|
+
const unifiedTooltipLabel = isMultiValueCell ? (countTooltip ?? "") : (countTooltip ?? content ?? "");
|
|
643
|
+
const hasUnifiedTooltipLabel = isMultiValueCell
|
|
644
|
+
? countTooltip !== undefined && countTooltip !== null
|
|
645
|
+
: Boolean(unifiedTooltipLabel);
|
|
646
|
+
const isUnifiedTooltipEnabled = unifiedTooltip && isCountDefined && (isMultiValueCell || isTooltipVisible) && hasUnifiedTooltipLabel;
|
|
647
|
+
return count !== null && count !== undefined && count > 0 ? (jsxRuntime.jsx(reactComponents.Tooltip, { "data-testid": dataTestId ? `${dataTestId}-unified-tooltip` : undefined, disabled: !isUnifiedTooltipEnabled, label: unifiedTooltipLabel, placement: "bottom", children: jsxRuntime.jsxs("div", { className: cvaMultiValueTextCellWrapper({ className }), "data-testid": dataTestId, onMouseEnter: unifiedTooltip ? onMouseEnter : undefined, ref: ref, style: style, children: [icon ? (jsxRuntime.jsx(reactComponents.Tooltip, { "data-testid": dataTestId ? `${dataTestId}-icon-tooltip` : undefined, disabled: isUnifiedTooltipEnabled || !iconTooltip, label: iconTooltip ?? "", placement: "bottom", children: jsxRuntime.jsx("span", { className: "inline-flex items-center", children: icon }) })) : null, jsxRuntime.jsx("span", { className: cvaMultiValueTextCellTooltip(), ref: updateTooltipVisibility, children: unifiedTooltip ? (jsxRuntime.jsx(reactComponents.Text, { className: "inline", children: content ?? "" })) : (jsxRuntime.jsx(reactComponents.Tooltip, { "data-testid": dataTestId ? `${dataTestId}-content-tooltip` : undefined, disabled: !isTooltipVisible, label: content ?? "", placement: "bottom", children: jsxRuntime.jsx(reactComponents.Text, { className: "inline", children: content ?? "" }) })) }), count > 1 ? (unifiedTooltip ? (jsxRuntime.jsxs(reactComponents.Tag, { className: "inline", color: "neutral", size: "small", children: ["+", count - 1] })) : (jsxRuntime.jsx(reactComponents.Tooltip, { "data-testid": dataTestId ? `${dataTestId}-count-tooltip` : undefined, disabled: countTooltip === undefined || countTooltip === null, label: countTooltip ?? "", placement: "bottom", children: jsxRuntime.jsxs(reactComponents.Tag, { className: "inline", color: "neutral", onMouseEnter: onMouseEnter, size: "small", children: ["+", count - 1] }) }))) : null] }) })) : null;
|
|
636
648
|
};
|
|
637
649
|
|
|
638
650
|
/**
|
package/index.esm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { twMerge } from 'tailwind-merge';
|
|
|
5
5
|
import { Checkbox } from '@trackunit/react-form-components';
|
|
6
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
7
7
|
import { formatDateUtil, timeSinceAuto, timeSinceInDays, Temporal } from '@trackunit/date-and-time-utils';
|
|
8
|
+
import { useTimezone, useLocale } from '@trackunit/react-date-and-time-hooks';
|
|
8
9
|
import { useMemo, useState, useEffect, isValidElement, cloneElement } from 'react';
|
|
9
10
|
import { DateTimeFormat } from '@trackunit/shared-utils';
|
|
10
11
|
|
|
@@ -285,7 +286,11 @@ const cvaDateTimeSince$1 = cvaMerge(["slashed-zero", "text-neutral-500", "text-x
|
|
|
285
286
|
* @param {DateTimeCellProps} props - The props for the DateTimeCell component
|
|
286
287
|
* @returns {ReactElement} DateTimeCell component
|
|
287
288
|
*/
|
|
288
|
-
const DateTimeCell = ({ format,
|
|
289
|
+
const DateTimeCell = ({ format, date, withTimeSince = true, className, "data-testid": dataTestId, style, timeZone: timeZoneProp, locale: localeProp, }) => {
|
|
290
|
+
const { preferred: preferredTimezone } = useTimezone();
|
|
291
|
+
const resolvedLocale = useLocale();
|
|
292
|
+
const timeZone = timeZoneProp ?? preferredTimezone.id;
|
|
293
|
+
const locale = localeProp ?? resolvedLocale;
|
|
289
294
|
if (!date) {
|
|
290
295
|
return null;
|
|
291
296
|
}
|
|
@@ -625,12 +630,19 @@ const cvaMultiValueTextCellTooltip = cvaMerge(["whitespace-no-wrap", "overflow-h
|
|
|
625
630
|
* @param {MultiValueTextCellProps} props - The props for the MultiValueTextCell component
|
|
626
631
|
* @returns {ReactElement} MultiValueTextCell component
|
|
627
632
|
*/
|
|
628
|
-
const MultiValueTextCell = ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, }) => {
|
|
633
|
+
const MultiValueTextCell = ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, unifiedTooltip = false, }) => {
|
|
629
634
|
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
630
635
|
const updateTooltipVisibility = (element) => {
|
|
631
636
|
setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
|
|
632
637
|
};
|
|
633
|
-
|
|
638
|
+
const isCountDefined = count !== undefined && count !== null;
|
|
639
|
+
const isMultiValueCell = isCountDefined && count > 1;
|
|
640
|
+
const unifiedTooltipLabel = isMultiValueCell ? (countTooltip ?? "") : (countTooltip ?? content ?? "");
|
|
641
|
+
const hasUnifiedTooltipLabel = isMultiValueCell
|
|
642
|
+
? countTooltip !== undefined && countTooltip !== null
|
|
643
|
+
: Boolean(unifiedTooltipLabel);
|
|
644
|
+
const isUnifiedTooltipEnabled = unifiedTooltip && isCountDefined && (isMultiValueCell || isTooltipVisible) && hasUnifiedTooltipLabel;
|
|
645
|
+
return count !== null && count !== undefined && count > 0 ? (jsx(Tooltip, { "data-testid": dataTestId ? `${dataTestId}-unified-tooltip` : undefined, disabled: !isUnifiedTooltipEnabled, label: unifiedTooltipLabel, placement: "bottom", children: jsxs("div", { className: cvaMultiValueTextCellWrapper({ className }), "data-testid": dataTestId, onMouseEnter: unifiedTooltip ? onMouseEnter : undefined, ref: ref, style: style, children: [icon ? (jsx(Tooltip, { "data-testid": dataTestId ? `${dataTestId}-icon-tooltip` : undefined, disabled: isUnifiedTooltipEnabled || !iconTooltip, label: iconTooltip ?? "", placement: "bottom", children: jsx("span", { className: "inline-flex items-center", children: icon }) })) : null, jsx("span", { className: cvaMultiValueTextCellTooltip(), ref: updateTooltipVisibility, children: unifiedTooltip ? (jsx(Text, { className: "inline", children: content ?? "" })) : (jsx(Tooltip, { "data-testid": dataTestId ? `${dataTestId}-content-tooltip` : undefined, disabled: !isTooltipVisible, label: content ?? "", placement: "bottom", children: jsx(Text, { className: "inline", children: content ?? "" }) })) }), count > 1 ? (unifiedTooltip ? (jsxs(Tag, { className: "inline", color: "neutral", size: "small", children: ["+", count - 1] })) : (jsx(Tooltip, { "data-testid": dataTestId ? `${dataTestId}-count-tooltip` : undefined, disabled: countTooltip === undefined || countTooltip === null, label: countTooltip ?? "", placement: "bottom", children: jsxs(Tag, { className: "inline", color: "neutral", onMouseEnter: onMouseEnter, size: "small", children: ["+", count - 1] }) }))) : null] }) })) : null;
|
|
634
646
|
};
|
|
635
647
|
|
|
636
648
|
/**
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table-base-components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/react-components": "2.1.5
|
|
11
|
-
"@trackunit/ui-icons": "1.13.16
|
|
12
|
-
"@trackunit/react-form-components": "2.1.6
|
|
13
|
-
"@trackunit/css-class-variance-utilities": "1.13.15
|
|
14
|
-
"@trackunit/date-and-time-utils": "1.13.16
|
|
15
|
-
"@trackunit/
|
|
16
|
-
"@trackunit/
|
|
10
|
+
"@trackunit/react-components": "2.1.5",
|
|
11
|
+
"@trackunit/ui-icons": "1.13.16",
|
|
12
|
+
"@trackunit/react-form-components": "2.1.6",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.13.15",
|
|
14
|
+
"@trackunit/date-and-time-utils": "1.13.16",
|
|
15
|
+
"@trackunit/react-date-and-time-hooks": "2.1.6",
|
|
16
|
+
"@trackunit/shared-utils": "1.15.15",
|
|
17
|
+
"@trackunit/i18n-library-translation": "2.0.7",
|
|
17
18
|
"tailwind-merge": "^2.0.0"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TemporalFormat } from "@trackunit/date-and-time-utils";
|
|
2
2
|
import { CommonProps, Refable, type Styleable } from "@trackunit/react-components";
|
|
3
|
+
import { ReactElement } from "react";
|
|
3
4
|
export interface DateTimeCellProps extends CommonProps, Refable<HTMLDivElement>, Styleable {
|
|
4
5
|
/**
|
|
5
6
|
* The date to render.
|
|
@@ -20,13 +21,16 @@ export interface DateTimeCellProps extends CommonProps, Refable<HTMLDivElement>,
|
|
|
20
21
|
*/
|
|
21
22
|
format?: TemporalFormat;
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* Explicit timezone override (IANA timezone string, e.g. `"America/New_York"`).
|
|
25
|
+
* When provided, takes precedence over the automatically resolved timezone from context.
|
|
26
|
+
*
|
|
27
|
+
* In most cases you do not need this — the component resolves the correct timezone
|
|
28
|
+
* automatically via `AssetTimezoneProvider` and user preference context.
|
|
25
29
|
*/
|
|
26
30
|
timeZone?: string;
|
|
27
31
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
32
|
+
* Explicit locale override (BCP 47 language tag, e.g. `"en-US"`).
|
|
33
|
+
* When provided, takes precedence over the locale resolved from context.
|
|
30
34
|
*/
|
|
31
35
|
locale?: string;
|
|
32
36
|
}
|
|
@@ -86,7 +90,4 @@ export interface DateTimeCellProps extends CommonProps, Refable<HTMLDivElement>,
|
|
|
86
90
|
* @param {DateTimeCellProps} props - The props for the DateTimeCell component
|
|
87
91
|
* @returns {ReactElement} DateTimeCell component
|
|
88
92
|
*/
|
|
89
|
-
export declare const DateTimeCell: ({ format,
|
|
90
|
-
export interface TimeSinceProps extends Pick<DateTimeCellProps, "date" | "timeZone" | "locale"> {
|
|
91
|
-
date: Date;
|
|
92
|
-
}
|
|
93
|
+
export declare const DateTimeCell: ({ format, date, withTimeSince, className, "data-testid": dataTestId, style, timeZone: timeZoneProp, locale: localeProp, }: DateTimeCellProps) => ReactElement | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommonProps, Refable, type Styleable } from "@trackunit/react-components";
|
|
2
2
|
import { MouseEventHandler, ReactElement, ReactNode } from "react";
|
|
3
|
-
|
|
3
|
+
type MultiValueTextCellBaseProps = CommonProps & Refable<HTMLDivElement> & Styleable & {
|
|
4
4
|
/**
|
|
5
5
|
* Icon rendered to the left of the text.
|
|
6
6
|
* Provides visual context for the primary value.
|
|
@@ -9,6 +9,8 @@ export interface MultiValueTextCellProps extends CommonProps, Refable<HTMLDivEle
|
|
|
9
9
|
/**
|
|
10
10
|
* Tooltip text for the icon.
|
|
11
11
|
* If omitted, the icon tooltip is disabled.
|
|
12
|
+
* When `unifiedTooltip` is true and the unified cell tooltip is active, `iconTooltip` is
|
|
13
|
+
* suppressed so only the unified tooltip is shown (including over the icon).
|
|
12
14
|
*/
|
|
13
15
|
iconTooltip?: string;
|
|
14
16
|
/**
|
|
@@ -22,19 +24,57 @@ export interface MultiValueTextCellProps extends CommonProps, Refable<HTMLDivEle
|
|
|
22
24
|
* - If count > 1, a +N badge is shown where N = count - 1.
|
|
23
25
|
*/
|
|
24
26
|
count?: number | null;
|
|
27
|
+
};
|
|
28
|
+
type MultiValueTextCellDefaultProps = MultiValueTextCellBaseProps & {
|
|
25
29
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
+
* Tooltip content for the +N badge.
|
|
31
|
+
* Accepts strings, React elements, or any ReactNode.
|
|
32
|
+
* If omitted, the badge tooltip is disabled.
|
|
33
|
+
* Recommended: use the `ListTooltip` component to render a list of the remaining items.
|
|
30
34
|
*/
|
|
31
35
|
countTooltip?: ReactNode;
|
|
32
36
|
/**
|
|
33
|
-
* Mouse enter handler for the
|
|
34
|
-
*
|
|
37
|
+
* Mouse enter handler for lazy-loading tooltip content (e.g., fetching the remaining items).
|
|
38
|
+
* Runs on the +N badge by default; when `unifiedTooltip` is true, runs on the cell wrapper instead
|
|
39
|
+
* (fires once when the cell is first entered).
|
|
35
40
|
*/
|
|
36
41
|
onMouseEnter?: MouseEventHandler<HTMLDivElement>;
|
|
37
|
-
|
|
42
|
+
/**
|
|
43
|
+
* When true, primary text, the optional icon, and the +N badge share one tooltip over the
|
|
44
|
+
* whole cell. When false, separate tooltips are shown on the truncated content, icon, and +N badge.
|
|
45
|
+
* When true, `iconTooltip` is not shown while the unified tooltip is active.
|
|
46
|
+
* Defaults to false.
|
|
47
|
+
*/
|
|
48
|
+
unifiedTooltip?: false;
|
|
49
|
+
};
|
|
50
|
+
type MultiValueTextCellUnifiedProps = MultiValueTextCellBaseProps & {
|
|
51
|
+
/**
|
|
52
|
+
* Tooltip content for the unified cell tooltip and the +N badge (when `unifiedTooltip` is false).
|
|
53
|
+
* Required when `unifiedTooltip` is true and `count` > 1 (unless lazy-loading via `onMouseEnter`).
|
|
54
|
+
* When `count` is 1 and the primary text is truncated, `content` is used if `countTooltip` is omitted.
|
|
55
|
+
*/
|
|
56
|
+
countTooltip?: ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Mouse enter handler for lazy-loading tooltip content (e.g., fetching the remaining items).
|
|
59
|
+
* Runs on the cell wrapper (fires once when the cell is first entered).
|
|
60
|
+
*/
|
|
61
|
+
onMouseEnter?: MouseEventHandler<HTMLDivElement>;
|
|
62
|
+
/**
|
|
63
|
+
* When true, primary text, the optional icon, and the +N badge share one tooltip over the
|
|
64
|
+
* whole cell. `iconTooltip` is not shown while the unified tooltip is active.
|
|
65
|
+
*/
|
|
66
|
+
unifiedTooltip: true;
|
|
67
|
+
} & ({
|
|
68
|
+
count: 1;
|
|
69
|
+
} | {
|
|
70
|
+
countTooltip: ReactNode;
|
|
71
|
+
} | {
|
|
72
|
+
onMouseEnter: MouseEventHandler<HTMLDivElement>;
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* When `unifiedTooltip` is true and `count` is not the literal `1`, provide `countTooltip` or `onMouseEnter`.
|
|
76
|
+
*/
|
|
77
|
+
export type MultiValueTextCellProps = MultiValueTextCellDefaultProps | MultiValueTextCellUnifiedProps;
|
|
38
78
|
/**
|
|
39
79
|
* The `<MultiValueTextCell>` component is used for displaying the text values with multiple values in a table cell. First element is displayed as a text, the rest of the values are displayed as a number. Icon can be passed as an optional prop.
|
|
40
80
|
* The text content is not editable and will be truncated if the cell is too narrow.
|
|
@@ -42,4 +82,5 @@ export interface MultiValueTextCellProps extends CommonProps, Refable<HTMLDivEle
|
|
|
42
82
|
* @param {MultiValueTextCellProps} props - The props for the MultiValueTextCell component
|
|
43
83
|
* @returns {ReactElement} MultiValueTextCell component
|
|
44
84
|
*/
|
|
45
|
-
export declare const MultiValueTextCell: ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, }: MultiValueTextCellProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
85
|
+
export declare const MultiValueTextCell: ({ content, count, countTooltip, icon, iconTooltip, "data-testid": dataTestId, className, onMouseEnter, ref, style, unifiedTooltip, }: MultiValueTextCellProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
86
|
+
export {};
|