@trackunit/react-table-base-components 0.0.20 → 0.0.21

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
@@ -6,6 +6,7 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var reactFormComponents = require('@trackunit/react-form-components');
7
7
  var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
8
8
  var reactComponents = require('@trackunit/react-components');
9
+ var react = require('react');
9
10
 
10
11
  const cvaCheckboxCell = cssClassVarianceUtilities.cvaMerge([""]);
11
12
 
@@ -205,6 +206,24 @@ const Td = (_a) => {
205
206
  };
206
207
  const cvaTd = cssClassVarianceUtilities.cvaMerge(["overflow-hidden", "align-middle", "py-table-spacing", "px-2", "whitespace-nowrap"]);
207
208
 
209
+ const cvaTextCell = cssClassVarianceUtilities.cvaMerge(["truncate"]);
210
+ const cvaTextCellTooltip = cssClassVarianceUtilities.cvaMerge(["grid"]);
211
+
212
+ /**
213
+ * The `<TextCell>` component is used for displaying text in a table cell.
214
+ * The text is not editable and will be truncated if the cell is too narrow.
215
+ *
216
+ * @param {TextCellProps} props - The props for the TextCell component
217
+ * @returns {JSX.Element} TextCell component
218
+ */
219
+ const TextCell = ({ content = "", className, dataTestId }) => {
220
+ const [isTooltipVisible, setIsTooltipVisible] = react.useState(false);
221
+ const updateTooltipVisibility = (element) => {
222
+ setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
223
+ };
224
+ return (jsxRuntime.jsx(reactComponents.Tooltip, { disabled: !isTooltipVisible, label: content, className: cvaTextCellTooltip(), children: jsxRuntime.jsx("span", { ref: elementRef => updateTooltipVisibility(elementRef), className: cvaTextCell({ className }), "data-testid": dataTestId, children: content }) }));
225
+ };
226
+
208
227
  /**
209
228
  * The Tfoot is a wrapper for the tfoot html element.
210
229
  * It is used to render a table, and adds some default styling.
@@ -304,6 +323,7 @@ exports.TableRoot = TableRoot;
304
323
  exports.TagsCell = TagsCell;
305
324
  exports.Tbody = Tbody;
306
325
  exports.Td = Td;
326
+ exports.TextCell = TextCell;
307
327
  exports.Tfoot = Tfoot;
308
328
  exports.Th = Th;
309
329
  exports.Thead = Thead;
package/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { Checkbox } from '@trackunit/react-form-components';
3
3
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
4
- import { ExternalLink, Tag } from '@trackunit/react-components';
4
+ import { ExternalLink, Tag, Tooltip } from '@trackunit/react-components';
5
+ import { useState } from 'react';
5
6
 
6
7
  const cvaCheckboxCell = cvaMerge([""]);
7
8
 
@@ -201,6 +202,24 @@ const Td = (_a) => {
201
202
  };
202
203
  const cvaTd = cvaMerge(["overflow-hidden", "align-middle", "py-table-spacing", "px-2", "whitespace-nowrap"]);
203
204
 
205
+ const cvaTextCell = cvaMerge(["truncate"]);
206
+ const cvaTextCellTooltip = cvaMerge(["grid"]);
207
+
208
+ /**
209
+ * The `<TextCell>` component is used for displaying text in a table cell.
210
+ * The text is not editable and will be truncated if the cell is too narrow.
211
+ *
212
+ * @param {TextCellProps} props - The props for the TextCell component
213
+ * @returns {JSX.Element} TextCell component
214
+ */
215
+ const TextCell = ({ content = "", className, dataTestId }) => {
216
+ const [isTooltipVisible, setIsTooltipVisible] = useState(false);
217
+ const updateTooltipVisibility = (element) => {
218
+ setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
219
+ };
220
+ return (jsx(Tooltip, { disabled: !isTooltipVisible, label: content, className: cvaTextCellTooltip(), children: jsx("span", { ref: elementRef => updateTooltipVisibility(elementRef), className: cvaTextCell({ className }), "data-testid": dataTestId, children: content }) }));
221
+ };
222
+
204
223
  /**
205
224
  * The Tfoot is a wrapper for the tfoot html element.
206
225
  * It is used to render a table, and adds some default styling.
@@ -292,4 +311,4 @@ const cvaTr = cvaMerge(["border-b", "border-neutral-300", "w-full", "h-max"], {
292
311
  },
293
312
  });
294
313
 
295
- export { CheckboxCell, LinkCell, ResizeHandle, SortIndicator, TableRoot, TagsCell, Tbody, Td, Tfoot, Th, Thead, Tr };
314
+ export { CheckboxCell, LinkCell, ResizeHandle, SortIndicator, TableRoot, TagsCell, Tbody, Td, TextCell, Tfoot, Th, Thead, Tr };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table-base-components",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -9,8 +9,8 @@
9
9
  "dependencies": {
10
10
  "@trackunit/css-class-variance-utilities": "0.0.14",
11
11
  "@trackunit/date-and-time-utils": "0.0.1",
12
- "@trackunit/react-components": "0.1.161",
13
- "@trackunit/react-form-components": "0.0.147",
12
+ "@trackunit/react-components": "0.1.162",
13
+ "@trackunit/react-form-components": "0.0.148",
14
14
  "@trackunit/ui-design-tokens": "0.0.77",
15
15
  "react": "18.2.0"
16
16
  },
@@ -1 +1,2 @@
1
1
  export declare const cvaTextCell: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
+ export declare const cvaTextCellTooltip: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
package/src/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./components/TableRoot";
6
6
  export * from "./components/TagsCell/TagsCell";
7
7
  export * from "./components/Tbody";
8
8
  export * from "./components/Td";
9
+ export * from "./components/TextCell/TextCell";
9
10
  export * from "./components/Tfoot";
10
11
  export * from "./components/Th";
11
12
  export * from "./components/Thead";