@trackunit/react-table-base-components 0.0.177 → 0.0.178

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
@@ -334,8 +334,14 @@ const Tfoot = (_a) => {
334
334
  * @returns {JSX.Element} Th component
335
335
  */
336
336
  const Th = (_a) => {
337
- var { dataTestId, className, children } = _a, rest = __rest(_a, ["dataTestId", "className", "children"]);
338
- return (jsxRuntime.jsx("th", Object.assign({ "data-testid": dataTestId, className: cvaTh({ className }) }, rest, { children: children })));
337
+ var { dataTestId, className, children, tooltipLabel } = _a, rest = __rest(_a, ["dataTestId", "className", "children", "tooltipLabel"]);
338
+ const [showToolTip, setShowTooltipVisible] = react.useState(false);
339
+ const [thWidth, setThWidth] = react.useState(0);
340
+ const [childrenWidth, setChildrenWidth] = react.useState(0);
341
+ react.useEffect(() => {
342
+ setShowTooltipVisible(thWidth > childrenWidth);
343
+ }, [thWidth, childrenWidth, tooltipLabel]);
344
+ return (jsxRuntime.jsx("th", Object.assign({ ref: elementRef => setThWidth(elementRef ? elementRef.clientWidth : 0), className: cvaTh({ className }), "data-testid": dataTestId }, rest, { children: tooltipLabel ? (jsxRuntime.jsx(reactComponents.Tooltip, { disabled: showToolTip, label: tooltipLabel, placement: "bottom", className: cvaTooltip(), children: jsxRuntime.jsx("div", { className: cvaChildrenContainer(), ref: elementRef => setChildrenWidth(elementRef ? elementRef.clientWidth : 0), children: children }) })) : (jsxRuntime.jsx("div", { className: cvaChildrenContainer(), ref: elementRef => setChildrenWidth(elementRef ? elementRef.clientWidth : 0), children: children })) })));
339
345
  };
340
346
  const cvaTh = cssClassVarianceUtilities.cvaMerge([
341
347
  "hover:bg-neutral-200",
@@ -343,9 +349,10 @@ const cvaTh = cssClassVarianceUtilities.cvaMerge([
343
349
  "overflow-hidden",
344
350
  "font-medium",
345
351
  "whitespace-nowrap",
346
- "px-3",
347
- "py-table-spacing",
352
+ "p-0",
348
353
  ]);
354
+ const cvaTooltip = cssClassVarianceUtilities.cvaMerge(["w-full"]);
355
+ const cvaChildrenContainer = cssClassVarianceUtilities.cvaMerge(["max-w-full", "px-3", "py-table-spacing"]);
349
356
 
350
357
  /**
351
358
  * The Thead is a wrapper for the thead html element.
package/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { Checkbox } from '@trackunit/react-form-components';
3
3
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
4
4
  import { formatDateUtil, timeSinceAuto } from '@trackunit/date-and-time-utils';
5
5
  import { Indicator, ExternalLink, Tooltip, Tag } from '@trackunit/react-components';
6
- import { useState } from 'react';
6
+ import { useState, useEffect } from 'react';
7
7
 
8
8
  const cvaCheckboxCell = cvaMerge([""]);
9
9
 
@@ -330,8 +330,14 @@ const Tfoot = (_a) => {
330
330
  * @returns {JSX.Element} Th component
331
331
  */
332
332
  const Th = (_a) => {
333
- var { dataTestId, className, children } = _a, rest = __rest(_a, ["dataTestId", "className", "children"]);
334
- return (jsx("th", Object.assign({ "data-testid": dataTestId, className: cvaTh({ className }) }, rest, { children: children })));
333
+ var { dataTestId, className, children, tooltipLabel } = _a, rest = __rest(_a, ["dataTestId", "className", "children", "tooltipLabel"]);
334
+ const [showToolTip, setShowTooltipVisible] = useState(false);
335
+ const [thWidth, setThWidth] = useState(0);
336
+ const [childrenWidth, setChildrenWidth] = useState(0);
337
+ useEffect(() => {
338
+ setShowTooltipVisible(thWidth > childrenWidth);
339
+ }, [thWidth, childrenWidth, tooltipLabel]);
340
+ return (jsx("th", Object.assign({ ref: elementRef => setThWidth(elementRef ? elementRef.clientWidth : 0), className: cvaTh({ className }), "data-testid": dataTestId }, rest, { children: tooltipLabel ? (jsx(Tooltip, { disabled: showToolTip, label: tooltipLabel, placement: "bottom", className: cvaTooltip(), children: jsx("div", { className: cvaChildrenContainer(), ref: elementRef => setChildrenWidth(elementRef ? elementRef.clientWidth : 0), children: children }) })) : (jsx("div", { className: cvaChildrenContainer(), ref: elementRef => setChildrenWidth(elementRef ? elementRef.clientWidth : 0), children: children })) })));
335
341
  };
336
342
  const cvaTh = cvaMerge([
337
343
  "hover:bg-neutral-200",
@@ -339,9 +345,10 @@ const cvaTh = cvaMerge([
339
345
  "overflow-hidden",
340
346
  "font-medium",
341
347
  "whitespace-nowrap",
342
- "px-3",
343
- "py-table-spacing",
348
+ "p-0",
344
349
  ]);
350
+ const cvaTooltip = cvaMerge(["w-full"]);
351
+ const cvaChildrenContainer = cvaMerge(["max-w-full", "px-3", "py-table-spacing"]);
345
352
 
346
353
  /**
347
354
  * The Thead is a wrapper for the thead html element.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table-base-components",
3
- "version": "0.0.177",
3
+ "version": "0.0.178",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -13,6 +13,10 @@ export interface ThProps extends CommonProps, React.HTMLAttributes<HTMLTableCell
13
13
  * Children to render in the table cell.
14
14
  */
15
15
  children?: ReactNode;
16
+ /**
17
+ * Label for the tooltip.
18
+ */
19
+ tooltipLabel?: string;
16
20
  }
17
21
  /**
18
22
  * The Th is a wrapper for the th html element.
@@ -24,4 +28,4 @@ export interface ThProps extends CommonProps, React.HTMLAttributes<HTMLTableCell
24
28
  * @param {ThProps} props - The props for the Th component
25
29
  * @returns {JSX.Element} Th component
26
30
  */
27
- export declare const Th: ({ dataTestId, className, children, ...rest }: ThProps) => JSX.Element;
31
+ export declare const Th: ({ dataTestId, className, children, tooltipLabel, ...rest }: ThProps) => JSX.Element;