Debian Codegraph @

node/@patternfly/react-core/dist/esm/components/NotificationBadge/NotificationBadge.js

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx } from "react/jsx-runtime";
3 import { useEffect, useState } from 'react';
4 import { Button, ButtonVariant } from '../Button';
5 import RhUiAttentionBellFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-attention-bell-fill-icon';
6 import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon';
7 import styles from '@patternfly/react-styles/css/components/Button/button.mjs';
8 import { css } from '@patternfly/react-styles';
9 export var NotificationBadgeVariant;
10 (function (NotificationBadgeVariant) {
11 NotificationBadgeVariant["read"] = "read";
12 NotificationBadgeVariant["unread"] = "unread";
13 NotificationBadgeVariant["attention"] = "attention";
14 NotificationBadgeVariant["plain"] = "plain";
15 })(NotificationBadgeVariant || (NotificationBadgeVariant = {}));
16 export const NotificationBadge = (_a) => {
17 var { children, variant = NotificationBadgeVariant.read, count = 0, attentionIcon = _jsx(RhUiAttentionBellFillIcon, {}), icon = _jsx(RhUiNotificationFillIcon, {}), className, isExpanded = false, shouldNotify = false, onAnimationEnd } = _a, props = __rest(_a, ["children", "variant", "count", "attentionIcon", "icon", "className", "isExpanded", "shouldNotify", "onAnimationEnd"]);
18 const [isAnimating, setIsAnimating] = useState(shouldNotify);
19 const hasCount = count > 0;
20 const hasChildren = children !== undefined;
21 const isAttention = variant === NotificationBadgeVariant.attention;
22 const isPlain = variant === NotificationBadgeVariant.plain;
23 const _buttonState = isPlain ? undefined : variant;
24 const notificationIcon = isAttention ? attentionIcon : icon;
25 let notificationContent = null;
26 if (hasCount) {
27 notificationContent = count;
28 }
29 else if (hasChildren) {
30 notificationContent = children;
31 }
32 const buttonClassName = isAnimating ? css(className, styles.modifiers.notify) : className;
33 useEffect(() => {
34 setIsAnimating(shouldNotify);
35 }, [shouldNotify]);
36 const handleAnimationEnd = (event) => {
37 onAnimationEnd === null || onAnimationEnd === void 0 ? void 0 : onAnimationEnd(event);
38 setIsAnimating(false);
39 };
40 return (_jsx(Button, Object.assign({ variant: isPlain ? ButtonVariant.plain : ButtonVariant.stateful, className: buttonClassName, "aria-expanded": isExpanded, state: _buttonState, isClicked: isExpanded, icon: notificationIcon, onAnimationEnd: handleAnimationEnd }, props, { children: notificationContent })));
41 };
42 NotificationBadge.displayName = 'NotificationBadge';
43 //# sourceMappingURL=NotificationBadge.js.map