Debian Codegraph @

node/@patternfly/react-table/dist/js/components/Table/Td.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.Td = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_1 = require("react");
7 const react_styles_1 = require("@patternfly/react-styles");
8 const table_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Table/table"));
9 const table_scrollable_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Table/table-scrollable"));
10 const table_tree_view_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Table/table-tree-view"));
11 const utils_1 = require("./utils");
12 const draggable_1 = require("./utils/decorators/draggable");
13 const utils_2 = require("./utils");
14 const merge_props_1 = require("./base/merge-props");
15 const Tooltip_1 = require('@patternfly/react-core/dist/js/components/Tooltip/Tooltip');
16 const Table_1 = require("./Table");
17 const c_table__sticky_cell_MinWidth_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_table__sticky_cell_MinWidth'));
18 const c_table__sticky_cell_InsetInlineStart_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_table__sticky_cell_InsetInlineStart'));
19 const c_table__sticky_cell_InsetInlineEnd_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_table__sticky_cell_InsetInlineEnd'));
20 const TdBase = (_a) => {
21 var { children, className, isActionCell = false, hasAction = false, component = 'td', dataLabel, textCenter = false, modifier, select = null, actions = null, expand = null, treeRow: treeRowProp = null, compoundExpand: compoundExpandProp = null, noPadding, width, visibility, innerRef, favorites = null, draggableRow: draggableRowProp = null, tooltip = '', onMouseEnter: onMouseEnterProp = () => { }, isStickyColumn = false, hasRightBorder = false, hasLeftBorder = false, stickyMinWidth = '120px', stickyLeftOffset, stickyRightOffset } = _a, props = tslib_1.__rest(_a, ["children", "className", "isActionCell", "hasAction", "component", "dataLabel", "textCenter", "modifier", "select", "actions", "expand", "treeRow", "compoundExpand", "noPadding", "width", "visibility", "innerRef", "favorites", "draggableRow", "tooltip", "onMouseEnter", "isStickyColumn", "hasRightBorder", "hasLeftBorder", "stickyMinWidth", "stickyLeftOffset", "stickyRightOffset"]);
22 const [showTooltip, setShowTooltip] = (0, react_1.useState)(false);
23 const [truncated, setTruncated] = (0, react_1.useState)(false);
24 const cellRef = innerRef ? innerRef : (0, react_1.createRef)();
25 const onMouseEnter = (event) => {
26 if (event.target.offsetWidth < event.target.scrollWidth) {
27 !showTooltip && setShowTooltip(true);
28 }
29 else {
30 showTooltip && setShowTooltip(false);
31 }
32 onMouseEnterProp(event);
33 };
34 const selectParams = select
35 ? (0, utils_1.selectable)(children, {
36 rowIndex: select.rowIndex,
37 rowData: {
38 selected: select.isSelected,
39 disableSelection: select === null || select === void 0 ? void 0 : select.isDisabled,
40 props: select === null || select === void 0 ? void 0 : select.props
41 },
42 column: {
43 extraParams: {
44 onSelect: select === null || select === void 0 ? void 0 : select.onSelect,
45 selectVariant: select.variant || 'checkbox'
46 }
47 }
48 })
49 : null;
50 const favoriteParams = favorites
51 ? (0, utils_1.favoritable)(null, {
52 rowIndex: favorites === null || favorites === void 0 ? void 0 : favorites.rowIndex,
53 rowData: {
54 favorited: favorites.isFavorited,
55 favoritesProps: favorites === null || favorites === void 0 ? void 0 : favorites.props
56 },
57 column: {
58 extraParams: {
59 onFavorite: favorites === null || favorites === void 0 ? void 0 : favorites.onFavorite
60 }
61 }
62 })
63 : null;
64 const draggableParams = draggableRowProp !== null
65 ? (0, draggable_1.draggable)(null, {
66 rowData: {
67 id: draggableRowProp.id
68 }
69 })
70 : null;
71 const actionParamsFunc = actions ? (0, utils_1.cellActions)(actions.items, null, null) : null;
72 const actionParams = actionParamsFunc
73 ? actionParamsFunc(null, {
74 rowIndex: actions === null || actions === void 0 ? void 0 : actions.rowIndex,
75 rowData: {
76 disableActions: actions === null || actions === void 0 ? void 0 : actions.isDisabled
77 },
78 column: {
79 extraParams: {
80 dropdownPosition: actions === null || actions === void 0 ? void 0 : actions.dropdownPosition,
81 dropdownDirection: actions === null || actions === void 0 ? void 0 : actions.dropdownDirection,
82 menuAppendTo: actions === null || actions === void 0 ? void 0 : actions.menuAppendTo,
83 actionsToggle: actions === null || actions === void 0 ? void 0 : actions.actionsToggle
84 }
85 }
86 })
87 : null;
88 const { hasAnimations, variant } = (0, react_1.useContext)(Table_1.TableContext);
89 const expandableParams = expand !== null
90 ? (0, utils_1.collapsible)(null, {
91 rowIndex: expand.rowIndex,
92 columnIndex: expand === null || expand === void 0 ? void 0 : expand.columnIndex,
93 rowData: {
94 isOpen: expand.isExpanded
95 },
96 column: {
97 extraParams: {
98 onCollapse: expand === null || expand === void 0 ? void 0 : expand.onToggle,
99 expandId: expand === null || expand === void 0 ? void 0 : expand.expandId,
100 variant
101 }
102 }
103 })
104 : null;
105 const updateAnimationClass = () => {
106 var _a, _b;
107 const ancestorControlRow = (_a = cellRef === null || cellRef === void 0 ? void 0 : cellRef.current) === null || _a === void 0 ? void 0 : _a.closest(`.${table_1.default.tableTr}.${table_1.default.tableControlRow}`);
108 const isControlRowExpanded = ancestorControlRow.classList.contains(table_1.default.modifiers.expanded);
109 if (!isControlRowExpanded) {
110 return;
111 }
112 const isCurrentCellExpanded = (_b = cellRef === null || cellRef === void 0 ? void 0 : cellRef.current) === null || _b === void 0 ? void 0 : _b.classList.contains(table_1.default.modifiers.expanded);
113 if (isCurrentCellExpanded) {
114 ancestorControlRow.classList.remove(table_1.default.modifiers.noAnimateExpand);
115 }
116 else {
117 ancestorControlRow.classList.add(table_1.default.modifiers.noAnimateExpand);
118 }
119 };
120 const internalCompoundOnToggle = (event, rowIndex, colIndex, isOpen, rowData, extraData) => {
121 hasAnimations && updateAnimationClass();
122 compoundExpandProp === null || compoundExpandProp === void 0 ? void 0 : compoundExpandProp.onToggle(event, rowIndex, colIndex, isOpen, rowData, extraData);
123 };
124 const compoundParams = compoundExpandProp !== null
125 ? (0, utils_1.compoundExpand)({
126 title: children,
127 props: {
128 isOpen: compoundExpandProp.isExpanded
129 }
130 }, {
131 rowIndex: compoundExpandProp === null || compoundExpandProp === void 0 ? void 0 : compoundExpandProp.rowIndex,
132 columnIndex: compoundExpandProp === null || compoundExpandProp === void 0 ? void 0 : compoundExpandProp.columnIndex,
133 column: {
134 extraParams: {
135 onExpand: internalCompoundOnToggle,
136 expandId: compoundExpandProp === null || compoundExpandProp === void 0 ? void 0 : compoundExpandProp.expandId
137 }
138 }
139 })
140 : null;
141 const widthParams = width ? (0, utils_1.cellWidth)(width)() : null;
142 const visibilityParams = visibility
143 ? (0, utils_1.classNames)(...visibility.map((vis) => utils_1.Visibility[vis]))()
144 : null;
145 const treeRowParams = treeRowProp !== null
146 ? (0, utils_2.treeRow)(treeRowProp.onCollapse, treeRowProp.onCheckChange, treeRowProp.onToggleRowDetails)({
147 title: children
148 }, {
149 rowIndex: treeRowProp.rowIndex,
150 rowData: {
151 props: treeRowProp.props
152 }
153 })
154 : null;
155 const merged = (0, merge_props_1.mergeProps)(selectParams, actionParams, expandableParams, compoundParams, widthParams, visibilityParams, favoriteParams, treeRowParams, draggableParams);
156 const {
157 // selectable adds this but we don't want it
158 // eslint-disable-next-line @typescript-eslint/no-unused-vars
159 isVisible = null, children: mergedChildren = null, className: mergedClassName = '', component: MergedComponent = component } = merged, mergedProps = tslib_1.__rest(merged, ["isVisible", "children", "className", "component"]);
160 const treeTableTitleCell = (className && className.includes(table_tree_view_1.default.tableTreeViewTitleCell)) ||
161 (mergedClassName && mergedClassName.includes(table_tree_view_1.default.tableTreeViewTitleCell));
162 (0, react_1.useEffect)(() => {
163 setTruncated(cellRef.current.offsetWidth <
164 cellRef.current.scrollWidth);
165 }, [cellRef]);
166 const cell = ((0, jsx_runtime_1.jsx)(MergedComponent, Object.assign({ tabIndex: (select || !truncated) && modifier !== 'truncate' ? -1 : 0 }, (!treeTableTitleCell && { 'data-label': dataLabel }), { onFocus: tooltip !== null ? onMouseEnter : onMouseEnterProp, onBlur: () => setShowTooltip(false), onMouseEnter: tooltip !== null ? onMouseEnter : onMouseEnterProp, className: (0, react_styles_1.css)(table_1.default.tableTd, className, isActionCell && table_1.default.tableAction, hasAction && table_1.default.modifiers.action, textCenter && table_1.default.modifiers.center, noPadding && table_1.default.modifiers.noPadding, isStickyColumn && table_scrollable_1.default.tableStickyCell, hasRightBorder && table_scrollable_1.default.modifiers.borderRight, hasLeftBorder && table_scrollable_1.default.modifiers.borderLeft, table_1.default.modifiers[modifier], draggableParams && table_1.default.tableDraggable, mergedClassName), ref: cellRef }, mergedProps, props, (isStickyColumn && {
167 style: Object.assign({ [c_table__sticky_cell_MinWidth_1.default.name]: stickyMinWidth ? stickyMinWidth : undefined, [c_table__sticky_cell_InsetInlineStart_1.default.name]: stickyLeftOffset ? stickyLeftOffset : 0, [c_table__sticky_cell_InsetInlineEnd_1.default.name]: stickyRightOffset ? stickyRightOffset : 0 }, props.style)
168 }), { children: mergedChildren || children })));
169 const canMakeDefaultTooltip = tooltip === '' ? typeof children === 'string' : true;
170 return tooltip !== null && canMakeDefaultTooltip && showTooltip ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [cell, (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { triggerRef: cellRef, content: tooltip || (tooltip === '' && children), isVisible: true })] })) : (cell);
171 };
172 exports.Td = (0, react_1.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsx)(TdBase, Object.assign({}, props, { innerRef: ref }))));
173 exports.Td.displayName = 'Td';
174 //# sourceMappingURL=Td.js.map