| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Tr = 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 helpers_1 = require('@patternfly/react-core/dist/js/helpers'); |
| 8 |
const table_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Table/table")); |
| 9 |
const inline_edit_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/InlineEdit/inline-edit")); |
| 10 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 11 |
const Table_1 = require("./Table"); |
| 12 |
const TrBase = (_a) => { |
| 13 |
var { children, className, isExpanded, isContentExpanded, isEditable, isHidden = false, isClickable = false, isRowSelected = false, isStriped = false, isBorderRow = false, isControlRow = false, innerRef, ouiaId, ouiaSafe = true, resetOffset = false, onRowClick, isSelectable, 'aria-label': passedAriaLabel } = _a, props = tslib_1.__rest(_a, ["children", "className", "isExpanded", "isContentExpanded", "isEditable", "isHidden", "isClickable", "isRowSelected", "isStriped", "isBorderRow", "isControlRow", "innerRef", "ouiaId", "ouiaSafe", "resetOffset", "onRowClick", "isSelectable", 'aria-label']); |
| 14 |
const ouiaProps = (0, helpers_1.useOUIAProps)('TableRow', ouiaId, ouiaSafe); |
| 15 |
const [computedAriaLabel, setComputedAriaLabel] = (0, react_1.useState)(''); |
| 16 |
let onKeyDown = null; |
| 17 |
if (onRowClick) { |
| 18 |
onKeyDown = (e) => { |
| 19 |
if (e.key === 'Enter' || e.key === ' ') { |
| 20 |
onRowClick(e); |
| 21 |
e.preventDefault(); |
| 22 |
} |
| 23 |
}; |
| 24 |
} |
| 25 |
const rowIsHidden = isHidden || (isExpanded !== undefined && !isExpanded); |
| 26 |
const { registerSelectableRow, hasAnimations } = (0, react_1.useContext)(Table_1.TableContext); |
| 27 |
(0, react_1.useEffect)(() => { |
| 28 |
if (isSelectable && !rowIsHidden) { |
| 29 |
setComputedAriaLabel(`${isRowSelected ? 'Row selected' : ''}`); |
| 30 |
registerSelectableRow(); |
| 31 |
} |
| 32 |
else { |
| 33 |
setComputedAriaLabel(undefined); |
| 34 |
} |
| 35 |
}, [isRowSelected, isSelectable, registerSelectableRow, rowIsHidden]); |
| 36 |
const ariaLabel = passedAriaLabel || computedAriaLabel; |
| 37 |
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("tr", Object.assign({ className: (0, react_styles_1.css)(table_1.default.tableTr, className, isExpanded !== undefined && table_1.default.tableExpandableRow, (isExpanded || isContentExpanded) && table_1.default.modifiers.expanded, isEditable && inline_edit_1.default.modifiers.inlineEditable, isClickable && table_1.default.modifiers.clickable, isRowSelected && table_1.default.modifiers.selected, isStriped && table_1.default.modifiers.striped, isBorderRow && table_1.default.modifiers.borderRow, isControlRow && table_1.default.tableControlRow, resetOffset && table_1.default.modifiers.firstCellOffsetReset), hidden: rowIsHidden }, (isClickable && { tabIndex: 0 }), { "aria-label": ariaLabel, ref: innerRef }, (hasAnimations && rowIsHidden && { inert: '' }), (onRowClick && { onClick: onRowClick, onKeyDown }), ouiaProps, props, { children: children })) })); |
| 38 |
}; |
| 39 |
exports.Tr = (0, react_1.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsx)(TrBase, Object.assign({}, props, { innerRef: ref })))); |
| 40 |
exports.Tr.displayName = 'Tr'; |
| 41 |
//# sourceMappingURL=Tr.js.map |