| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { useEffect, useRef, useState } from 'react'; |
| 4 |
import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import styles from '@patternfly/react-styles/css/components/NotificationDrawer/notification-drawer.mjs'; |
| 7 |
import maxLines from '@patternfly/react-tokens/dist/esm/c_notification_drawer__group_toggle_title_max_lines'; |
| 8 |
import { Badge } from '../Badge'; |
| 9 |
import { Tooltip } from '../Tooltip'; |
| 10 |
export const NotificationDrawerGroup = (_a) => { |
| 11 |
var { children, className = '', count, isExpanded, isRead = false, |
| 12 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 13 |
onExpand = (event, expanded) => undefined, title, truncateTitle = 0, tooltipPosition, headingLevel: HeadingLevel = 'h1' } = _a, props = __rest(_a, ["children", "className", "count", "isExpanded", "isRead", "onExpand", "title", "truncateTitle", "tooltipPosition", "headingLevel"]); |
| 14 |
const titleRef = useRef(null); |
| 15 |
const [isTooltipVisible, setIsTooltipVisible] = useState(false); |
| 16 |
useEffect(() => { |
| 17 |
// Title will always truncate on overflow regardless of truncateTitle prop |
| 18 |
const showTooltip = titleRef.current && titleRef.current.offsetHeight < titleRef.current.scrollHeight; |
| 19 |
if (isTooltipVisible !== showTooltip) { |
| 20 |
setIsTooltipVisible(showTooltip); |
| 21 |
} |
| 22 |
if (!titleRef.current || !truncateTitle) { |
| 23 |
return; |
| 24 |
} |
| 25 |
titleRef.current.style.setProperty(maxLines.name, truncateTitle.toString()); |
| 26 |
}, [titleRef, truncateTitle, isTooltipVisible]); |
| 27 |
const Title = (_jsx("div", Object.assign({}, (isTooltipVisible && { tabIndex: 0 }), { ref: titleRef, className: css(styles.notificationDrawerGroupToggleTitle), children: title }))); |
| 28 |
return (_jsxs("section", Object.assign({}, props, { className: css(styles.notificationDrawerGroup, isExpanded && styles.modifiers.expanded, className), children: [_jsx(HeadingLevel, { children: _jsxs("button", { className: css(styles.notificationDrawerGroupToggle), "aria-expanded": isExpanded, onClick: (e) => onExpand(e, !isExpanded), onKeyDown: (e) => { |
| 29 |
if (e.key === 'Enter' || e.key === ' ') { |
| 30 |
e.preventDefault(); |
| 31 |
onExpand(e, !isExpanded); |
| 32 |
} |
| 33 |
}, children: [isTooltipVisible ? (_jsx(Tooltip, { content: title, position: tooltipPosition, children: Title })) : (Title), _jsx("div", { className: css(styles.notificationDrawerGroupToggleCount), children: _jsx(Badge, { isRead: isRead, children: count }) }), _jsx("span", { className: styles.notificationDrawerGroupToggleIcon, children: _jsx(RhMicronsCaretDownIcon, {}) })] }) }), children] }))); |
| 34 |
}; |
| 35 |
NotificationDrawerGroup.displayName = 'NotificationDrawerGroup'; |
| 36 |
//# sourceMappingURL=NotificationDrawerGroup.js.map |