Debian Codegraph @

node/@patternfly/react-core/dist/js/components/NotificationDrawer/NotificationDrawerGroup.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.NotificationDrawerGroup = 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 rh_microns_caret_down_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-caret-down-icon'));
8 const react_styles_1 = require("@patternfly/react-styles");
9 const notification_drawer_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/NotificationDrawer/notification-drawer"));
10 const c_notification_drawer__group_toggle_title_max_lines_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_notification_drawer__group_toggle_title_max_lines'));
11 const Badge_1 = require("../Badge");
12 const Tooltip_1 = require("../Tooltip");
13 const NotificationDrawerGroup = (_a) => {
14 var { children, className = '', count, isExpanded, isRead = false,
15 // eslint-disable-next-line @typescript-eslint/no-unused-vars
16 onExpand = (event, expanded) => undefined, title, truncateTitle = 0, tooltipPosition, headingLevel: HeadingLevel = 'h1' } = _a, props = tslib_1.__rest(_a, ["children", "className", "count", "isExpanded", "isRead", "onExpand", "title", "truncateTitle", "tooltipPosition", "headingLevel"]);
17 const titleRef = (0, react_1.useRef)(null);
18 const [isTooltipVisible, setIsTooltipVisible] = (0, react_1.useState)(false);
19 (0, react_1.useEffect)(() => {
20 // Title will always truncate on overflow regardless of truncateTitle prop
21 const showTooltip = titleRef.current && titleRef.current.offsetHeight < titleRef.current.scrollHeight;
22 if (isTooltipVisible !== showTooltip) {
23 setIsTooltipVisible(showTooltip);
24 }
25 if (!titleRef.current || !truncateTitle) {
26 return;
27 }
28 titleRef.current.style.setProperty(c_notification_drawer__group_toggle_title_max_lines_1.default.name, truncateTitle.toString());
29 }, [titleRef, truncateTitle, isTooltipVisible]);
30 const Title = ((0, jsx_runtime_1.jsx)("div", Object.assign({}, (isTooltipVisible && { tabIndex: 0 }), { ref: titleRef, className: (0, react_styles_1.css)(notification_drawer_1.default.notificationDrawerGroupToggleTitle), children: title })));
31 return ((0, jsx_runtime_1.jsxs)("section", Object.assign({}, props, { className: (0, react_styles_1.css)(notification_drawer_1.default.notificationDrawerGroup, isExpanded && notification_drawer_1.default.modifiers.expanded, className), children: [(0, jsx_runtime_1.jsx)(HeadingLevel, { children: (0, jsx_runtime_1.jsxs)("button", { className: (0, react_styles_1.css)(notification_drawer_1.default.notificationDrawerGroupToggle), "aria-expanded": isExpanded, onClick: (e) => onExpand(e, !isExpanded), onKeyDown: (e) => {
32 if (e.key === 'Enter' || e.key === ' ') {
33 e.preventDefault();
34 onExpand(e, !isExpanded);
35 }
36 }, children: [isTooltipVisible ? ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { content: title, position: tooltipPosition, children: Title })) : (Title), (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(notification_drawer_1.default.notificationDrawerGroupToggleCount), children: (0, jsx_runtime_1.jsx)(Badge_1.Badge, { isRead: isRead, children: count }) }), (0, jsx_runtime_1.jsx)("span", { className: notification_drawer_1.default.notificationDrawerGroupToggleIcon, children: (0, jsx_runtime_1.jsx)(rh_microns_caret_down_icon_1.default, {}) })] }) }), children] })));
37 };
38 exports.NotificationDrawerGroup = NotificationDrawerGroup;
39 exports.NotificationDrawerGroup.displayName = 'NotificationDrawerGroup';
40 //# sourceMappingURL=NotificationDrawerGroup.js.map