@trackunit/react-table-base-components 0.0.158 → 0.0.159

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
@@ -162,6 +162,74 @@ const cvaResizeHandel = cssClassVarianceUtilities.cvaMerge(["absolute", "cursor-
162
162
  },
163
163
  });
164
164
 
165
+ const cvaSiteCellWrapper = cssClassVarianceUtilities.cvaMerge(["flex", "flex-row", "items-center", "gap-2", "overflow-hidden"]);
166
+ const cvaSiteCellTooltip = cssClassVarianceUtilities.cvaMerge(["whitespace-no-wrap", "overflow-hidden", "text-ellipsis"]);
167
+
168
+ const cvaSiteIconContainer = cssClassVarianceUtilities.cvaMerge(["flex", "rounded-full", "p-[2px]"], {
169
+ variants: {
170
+ type: {
171
+ AREA: "bg-site-AREA",
172
+ CONSTRUCTION_SITE: "bg-site-CONSTRUCTION_SITE",
173
+ DEPOT: "bg-site-DEPOT",
174
+ WORK_PLACE: "bg-site-WORK_PLACE",
175
+ CLASSIC_POI: "bg-site-CLASSIC_POI",
176
+ CLASSIC_ZONE: "bg-site-CLASSIC_ZONE",
177
+ UNKNOWN: "bg-site-UNKNOWN",
178
+ },
179
+ shape: {
180
+ round: "rounded-full",
181
+ square: "rounded-md",
182
+ },
183
+ },
184
+ defaultVariants: {
185
+ type: "UNKNOWN",
186
+ shape: "square",
187
+ },
188
+ });
189
+
190
+ /**
191
+ * The `<SiteIcon>` component is used for displaying the site icon with a tooltip for the type.
192
+ *
193
+ * @param {SiteIconProps} props - The props for the SiteCell component
194
+ * @returns {JSX.Element} SiteCell component
195
+ */
196
+ const SiteIcon = ({ size = "medium", type, shape, className, dataTestId }) => {
197
+ return (jsxRuntime.jsx("div", { className: cvaSiteIconContainer({ type, shape, className }), "data-testid": dataTestId, children: jsxRuntime.jsx(reactComponents.Icon, { name: getIconName(type), size: size, color: "white" }) }));
198
+ };
199
+ const getIconName = (type) => {
200
+ switch (type) {
201
+ case "CONSTRUCTION_SITE":
202
+ return "ConstructionCone";
203
+ case "WORK_PLACE":
204
+ return "Home";
205
+ case "DEPOT":
206
+ return "BuildingOffice";
207
+ case "AREA":
208
+ return "Map";
209
+ case "CLASSIC_ZONE":
210
+ case "CLASSIC_POI":
211
+ return "Zone";
212
+ default:
213
+ return "QuestionMarkCircle";
214
+ }
215
+ };
216
+
217
+ /**
218
+ * The `<SiteCell>` component is used for displaying the sites in a table cell.
219
+ * The site name is not editable and will be truncated if the cell is too narrow.
220
+ *
221
+ * @param {SiteCellProps} props - The props for the SiteCell component
222
+ * @returns {JSX.Element} SiteCell component
223
+ */
224
+ const SiteCell = ({ count, sites, dataTestId, className }) => {
225
+ var _a, _b, _c, _d, _e;
226
+ const [isTooltipVisible, setIsTooltipVisible] = react.useState(false);
227
+ const updateTooltipVisibility = (element) => {
228
+ setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
229
+ };
230
+ return count > 0 ? (jsxRuntime.jsxs("div", { className: cvaSiteCellWrapper({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx(SiteIcon, { size: "small", type: (_a = sites[0]) === null || _a === void 0 ? void 0 : _a.type }), jsxRuntime.jsx("span", { ref: elementRef => updateTooltipVisibility(elementRef), className: cvaSiteCellTooltip(), children: jsxRuntime.jsx(reactComponents.Tooltip, { disabled: !isTooltipVisible, label: (_c = (_b = sites[0]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "", placement: "bottom", className: "inline", children: (_e = (_d = sites[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : "" }) }), jsxRuntime.jsx("span", { className: "text-slate-500", children: count > 1 ? `+${count - 1}` : "" })] })) : null;
231
+ };
232
+
165
233
  /**
166
234
  * The SortIndicator is used in the table header to indicate the current sort order of the column.
167
235
  * This is a visual only component and does not handle the sorting logic.
@@ -388,6 +456,8 @@ exports.IndicatorCell = IndicatorCell;
388
456
  exports.LinkCell = LinkCell;
389
457
  exports.NumberCell = NumberCell;
390
458
  exports.ResizeHandle = ResizeHandle;
459
+ exports.SiteCell = SiteCell;
460
+ exports.SiteIcon = SiteIcon;
391
461
  exports.SortIndicator = SortIndicator;
392
462
  exports.TableRoot = TableRoot;
393
463
  exports.TagsCell = TagsCell;
package/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  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
- import { Indicator, ExternalLink, Tag, Tooltip } from '@trackunit/react-components';
5
+ import { Indicator, ExternalLink, Icon, Tooltip, Tag } from '@trackunit/react-components';
6
6
  import { useState } from 'react';
7
7
 
8
8
  const cvaCheckboxCell = cvaMerge([""]);
@@ -158,6 +158,74 @@ const cvaResizeHandel = cvaMerge(["absolute", "cursor-col-resize", "right-0", "t
158
158
  },
159
159
  });
160
160
 
161
+ const cvaSiteCellWrapper = cvaMerge(["flex", "flex-row", "items-center", "gap-2", "overflow-hidden"]);
162
+ const cvaSiteCellTooltip = cvaMerge(["whitespace-no-wrap", "overflow-hidden", "text-ellipsis"]);
163
+
164
+ const cvaSiteIconContainer = cvaMerge(["flex", "rounded-full", "p-[2px]"], {
165
+ variants: {
166
+ type: {
167
+ AREA: "bg-site-AREA",
168
+ CONSTRUCTION_SITE: "bg-site-CONSTRUCTION_SITE",
169
+ DEPOT: "bg-site-DEPOT",
170
+ WORK_PLACE: "bg-site-WORK_PLACE",
171
+ CLASSIC_POI: "bg-site-CLASSIC_POI",
172
+ CLASSIC_ZONE: "bg-site-CLASSIC_ZONE",
173
+ UNKNOWN: "bg-site-UNKNOWN",
174
+ },
175
+ shape: {
176
+ round: "rounded-full",
177
+ square: "rounded-md",
178
+ },
179
+ },
180
+ defaultVariants: {
181
+ type: "UNKNOWN",
182
+ shape: "square",
183
+ },
184
+ });
185
+
186
+ /**
187
+ * The `<SiteIcon>` component is used for displaying the site icon with a tooltip for the type.
188
+ *
189
+ * @param {SiteIconProps} props - The props for the SiteCell component
190
+ * @returns {JSX.Element} SiteCell component
191
+ */
192
+ const SiteIcon = ({ size = "medium", type, shape, className, dataTestId }) => {
193
+ return (jsx("div", { className: cvaSiteIconContainer({ type, shape, className }), "data-testid": dataTestId, children: jsx(Icon, { name: getIconName(type), size: size, color: "white" }) }));
194
+ };
195
+ const getIconName = (type) => {
196
+ switch (type) {
197
+ case "CONSTRUCTION_SITE":
198
+ return "ConstructionCone";
199
+ case "WORK_PLACE":
200
+ return "Home";
201
+ case "DEPOT":
202
+ return "BuildingOffice";
203
+ case "AREA":
204
+ return "Map";
205
+ case "CLASSIC_ZONE":
206
+ case "CLASSIC_POI":
207
+ return "Zone";
208
+ default:
209
+ return "QuestionMarkCircle";
210
+ }
211
+ };
212
+
213
+ /**
214
+ * The `<SiteCell>` component is used for displaying the sites in a table cell.
215
+ * The site name is not editable and will be truncated if the cell is too narrow.
216
+ *
217
+ * @param {SiteCellProps} props - The props for the SiteCell component
218
+ * @returns {JSX.Element} SiteCell component
219
+ */
220
+ const SiteCell = ({ count, sites, dataTestId, className }) => {
221
+ var _a, _b, _c, _d, _e;
222
+ const [isTooltipVisible, setIsTooltipVisible] = useState(false);
223
+ const updateTooltipVisibility = (element) => {
224
+ setIsTooltipVisible(element ? element.scrollWidth > element.clientWidth : false);
225
+ };
226
+ return count > 0 ? (jsxs("div", { className: cvaSiteCellWrapper({ className }), "data-testid": dataTestId, children: [jsx(SiteIcon, { size: "small", type: (_a = sites[0]) === null || _a === void 0 ? void 0 : _a.type }), jsx("span", { ref: elementRef => updateTooltipVisibility(elementRef), className: cvaSiteCellTooltip(), children: jsx(Tooltip, { disabled: !isTooltipVisible, label: (_c = (_b = sites[0]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "", placement: "bottom", className: "inline", children: (_e = (_d = sites[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : "" }) }), jsx("span", { className: "text-slate-500", children: count > 1 ? `+${count - 1}` : "" })] })) : null;
227
+ };
228
+
161
229
  /**
162
230
  * The SortIndicator is used in the table header to indicate the current sort order of the column.
163
231
  * This is a visual only component and does not handle the sorting logic.
@@ -377,4 +445,4 @@ const cvaTr = cvaMerge(["border-b", "border-neutral-300", "w-full", "h-max"], {
377
445
  },
378
446
  });
379
447
 
380
- export { CheckboxCell, DateTimeCell, ImageCell, IndicatorCell, LinkCell, NumberCell, ResizeHandle, SortIndicator, TableRoot, TagsCell, Tbody, Td, TextCell, Tfoot, Th, Thead, Tr };
448
+ export { CheckboxCell, DateTimeCell, ImageCell, IndicatorCell, LinkCell, NumberCell, ResizeHandle, SiteCell, SiteIcon, 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.158",
3
+ "version": "0.0.159",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps } from "@trackunit/react-components";
3
+ export type CellSiteType = "AREA" | "CLASSIC_POI" | "CLASSIC_ZONE" | "CONSTRUCTION_SITE" | "DEPOT" | "WORK_PLACE";
4
+ type CellSite = {
5
+ name?: string | null;
6
+ type?: CellSiteType;
7
+ };
8
+ export interface SiteCellProps extends CommonProps {
9
+ sites: CellSite[];
10
+ count: number;
11
+ }
12
+ /**
13
+ * The `<SiteCell>` component is used for displaying the sites in a table cell.
14
+ * The site name is not editable and will be truncated if the cell is too narrow.
15
+ *
16
+ * @param {SiteCellProps} props - The props for the SiteCell component
17
+ * @returns {JSX.Element} SiteCell component
18
+ */
19
+ export declare const SiteCell: ({ count, sites, dataTestId, className }: SiteCellProps) => JSX.Element | null;
20
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Meta, StoryObj } from "@storybook/react";
2
+ import { SiteCell } from "./SiteCell";
3
+ import "./SiteCell.variants";
4
+ type Story = StoryObj<typeof SiteCell>;
5
+ declare const meta: Meta<typeof SiteCell>;
6
+ export default meta;
7
+ export declare const packageName: () => JSX.Element;
8
+ export declare const Default: Story;
9
+ export declare const Example: Story;
@@ -0,0 +1,2 @@
1
+ export declare const cvaSiteCellWrapper: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
+ export declare const cvaSiteCellTooltip: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps, Size } from "@trackunit/react-components";
3
+ import { CellSiteType } from "../SiteCell";
4
+ type SiteType = CellSiteType;
5
+ type Shape = "round" | "square";
6
+ export interface SiteIconProps extends CommonProps {
7
+ type?: SiteType;
8
+ size?: Size;
9
+ shape?: Shape;
10
+ }
11
+ /**
12
+ * The `<SiteIcon>` component is used for displaying the site icon with a tooltip for the type.
13
+ *
14
+ * @param {SiteIconProps} props - The props for the SiteCell component
15
+ * @returns {JSX.Element} SiteCell component
16
+ */
17
+ export declare const SiteIcon: ({ size, type, shape, className, dataTestId }: SiteIconProps) => JSX.Element;
18
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare const cvaSiteIconContainer: (props?: ({
2
+ type?: "AREA" | "CONSTRUCTION_SITE" | "DEPOT" | "WORK_PLACE" | "CLASSIC_POI" | "CLASSIC_ZONE" | "UNKNOWN" | null | undefined;
3
+ shape?: "round" | "square" | null | undefined;
4
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
package/src/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export * from "./components/IndicatorCell/IndicatorCell";
5
5
  export * from "./components/LinkCell/LinkCell";
6
6
  export * from "./components/NumberCell/NumberCell";
7
7
  export * from "./components/ResizeHandle";
8
+ export * from "./components/SiteCell/SiteCell";
9
+ export * from "./components/SiteCell/SiteIcon/SiteIcon";
8
10
  export * from "./components/SortIndicator";
9
11
  export * from "./components/TableRoot";
10
12
  export * from "./components/TagsCell/TagsCell";