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