import type { RcSnackbarContentType } from '@ringcentral/juno'; import { combineProps, RcSnackbarAction, RcSnackbarContent, } from '@ringcentral/juno'; import { Close as closeSvg } from '@ringcentral/juno-icon'; import clsx from 'clsx'; import type { FunctionComponent } from 'react'; import React, { memo, useMemo } from 'react'; import type { NotificationItemProps, NotificationMessage, } from './NotificationPanel.interface'; import styles from './styles.scss'; export function getLevelType(level: NotificationMessage['level']) { let type: RcSnackbarContentType; switch (level) { case 'warning': type = 'warn'; break; case 'danger': type = 'error'; break; default: type = level; } return type; } export const NotificationItem: FunctionComponent = memo( ({ data, currentLocale, brand, dismiss, getRenderer, duration = 0, animation: defaultAnimation, backdropAnimation: defaultBackdropAnimation, classes: { snackbar: snackbarClass = {}, backdrop: backdropClass = undefined, } = {}, size, messageAlign, fullWidth, }) => { const Message = getRenderer(data); const second = duration / 1000; const { id, level, classes = {}, loading, action, animation = defaultAnimation, backdropAnimation = defaultBackdropAnimation, backdrop, onBackdropClick, } = data; const type: RcSnackbarContentType = getLevelType(level); const animationStyle = useMemo( () => ({ animationDuration: `${second}s`, }), [second], ); return (
{backdrop && (
)} } action={ action === undefined ? ( { dismiss(id); }} /> ) : ( action ) } />
); }, ); NotificationItem.defaultProps = { duration: 500, classes: {}, size: 'small', messageAlign: 'left', fullWidth: true, };