| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.NotificationBadge = exports.NotificationBadgeVariant = 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 Button_1 = require("../Button"); |
| 8 |
const rh_ui_attention_bell_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-attention-bell-fill-icon')); |
| 9 |
const rh_ui_notification_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-notification-fill-icon')); |
| 10 |
const button_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Button/button")); |
| 11 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 12 |
var NotificationBadgeVariant; |
| 13 |
(function (NotificationBadgeVariant) { |
| 14 |
NotificationBadgeVariant["read"] = "read"; |
| 15 |
NotificationBadgeVariant["unread"] = "unread"; |
| 16 |
NotificationBadgeVariant["attention"] = "attention"; |
| 17 |
NotificationBadgeVariant["plain"] = "plain"; |
| 18 |
})(NotificationBadgeVariant || (exports.NotificationBadgeVariant = NotificationBadgeVariant = {})); |
| 19 |
const NotificationBadge = (_a) => { |
| 20 |
var { children, variant = NotificationBadgeVariant.read, count = 0, attentionIcon = (0, jsx_runtime_1.jsx)(rh_ui_attention_bell_fill_icon_1.default, {}), icon = (0, jsx_runtime_1.jsx)(rh_ui_notification_fill_icon_1.default, {}), className, isExpanded = false, shouldNotify = false, onAnimationEnd } = _a, props = tslib_1.__rest(_a, ["children", "variant", "count", "attentionIcon", "icon", "className", "isExpanded", "shouldNotify", "onAnimationEnd"]); |
| 21 |
const [isAnimating, setIsAnimating] = (0, react_1.useState)(shouldNotify); |
| 22 |
const hasCount = count > 0; |
| 23 |
const hasChildren = children !== undefined; |
| 24 |
const isAttention = variant === NotificationBadgeVariant.attention; |
| 25 |
const isPlain = variant === NotificationBadgeVariant.plain; |
| 26 |
const _buttonState = isPlain ? undefined : variant; |
| 27 |
const notificationIcon = isAttention ? attentionIcon : icon; |
| 28 |
let notificationContent = null; |
| 29 |
if (hasCount) { |
| 30 |
notificationContent = count; |
| 31 |
} |
| 32 |
else if (hasChildren) { |
| 33 |
notificationContent = children; |
| 34 |
} |
| 35 |
const buttonClassName = isAnimating ? (0, react_styles_1.css)(className, button_1.default.modifiers.notify) : className; |
| 36 |
(0, react_1.useEffect)(() => { |
| 37 |
setIsAnimating(shouldNotify); |
| 38 |
}, [shouldNotify]); |
| 39 |
const handleAnimationEnd = (event) => { |
| 40 |
onAnimationEnd === null || onAnimationEnd === void 0 ? void 0 : onAnimationEnd(event); |
| 41 |
setIsAnimating(false); |
| 42 |
}; |
| 43 |
return ((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: isPlain ? Button_1.ButtonVariant.plain : Button_1.ButtonVariant.stateful, className: buttonClassName, "aria-expanded": isExpanded, state: _buttonState, isClicked: isExpanded, icon: notificationIcon, onAnimationEnd: handleAnimationEnd }, props, { children: notificationContent }))); |
| 44 |
}; |
| 45 |
exports.NotificationBadge = NotificationBadge; |
| 46 |
exports.NotificationBadge.displayName = 'NotificationBadge'; |
| 47 |
//# sourceMappingURL=NotificationBadge.js.map |