{"version":3,"file":"Notification.mjs","names":[],"sources":["../../../../src/components/Notifications/Notification.tsx"],"sourcesContent":["import React, { type ComponentType, forwardRef } from 'react';\nimport clsx from 'clsx';\nimport type { NotificationSeverity } from 'stream-chat';\nimport { type Notification as NotificationType } from 'stream-chat';\n\nimport { useComponentContextIcons } from '../../context';\nimport { useTranslationContext } from '../../context/TranslationContext';\nimport { Button } from '../Button';\nimport { useNotificationApi } from './hooks/useNotificationApi';\n\ntype NotificationEntryDirection = 'bottom' | 'left' | 'right' | 'top';\ntype NotificationTransitionState = 'enter' | 'exit';\n\nexport type NotificationIconProps = {\n  notification: NotificationType;\n};\n\nconst DefaultNotificationIcon = ({ notification }: NotificationIconProps) => {\n  const { IconCheckmark, IconExclamationMark, IconExclamationTriangleFill, IconRefresh } =\n    useComponentContextIcons();\n\n  const IconsBySeverity: Record<NotificationSeverity, ComponentType | null> = {\n    error: IconExclamationMark,\n    info: null,\n    loading: IconRefresh,\n    success: IconCheckmark,\n    warning: IconExclamationTriangleFill,\n  };\n\n  if (!notification.severity) return null;\n\n  const Icon = IconsBySeverity[notification.severity] ?? null;\n  return (\n    Icon && (\n      <div className='str-chat__notification-icon'>\n        <Icon />\n      </div>\n    )\n  );\n};\n\nexport type NotificationProps = {\n  /** Notification from the `client.notifications` state. */\n  notification: NotificationType;\n  className?: string;\n  /** Direction from which the notification enters. */\n  entryDirection?: NotificationEntryDirection;\n  /** Icon component. Defaults to a severity-based icon. */\n  Icon?: React.ComponentType<NotificationIconProps>;\n  /** Called on dismiss. Defaults to removing the notification. */\n  onDismiss?: () => void;\n  /** Shows the close button; persistent notifications (no `duration`) always show it. */\n  showClose?: boolean;\n  /** Transition state set by `NotificationList`. */\n  transitionState?: NotificationTransitionState;\n};\n\nexport const Notification = forwardRef<HTMLDivElement, NotificationProps>(\n  (\n    {\n      className,\n      entryDirection,\n      Icon = DefaultNotificationIcon,\n      notification,\n      onDismiss,\n      showClose = false,\n      transitionState,\n    }: NotificationProps,\n    ref,\n  ) => {\n    const { removeNotification } = useNotificationApi();\n    const { t } = useTranslationContext();\n    const { IconXmark } = useComponentContextIcons();\n\n    const displayMessage = t('translationBuilderTopic.notification', {\n      notification,\n      value: notification.message,\n    });\n\n    const handleDismiss = () => {\n      if (onDismiss) {\n        onDismiss();\n        return;\n      }\n\n      removeNotification(notification.id);\n    };\n\n    const isPersistent = !notification.duration;\n\n    const severity = notification.severity;\n    // The priority follows severity (errors are assertive, the rest polite) unless\n    // `metadata.ariaLive` overrides it (see the `ariaLive` option of `addNotification`).\n    const ariaLiveOverride = notification.metadata?.ariaLive;\n    const livePriority: 'assertive' | 'polite' =\n      ariaLiveOverride === 'assertive' || ariaLiveOverride === 'polite'\n        ? ariaLiveOverride\n        : severity === 'error'\n          ? 'assertive'\n          : 'polite';\n\n    return (\n      <div\n        className={clsx(\n          'str-chat__notification',\n          entryDirection && `str-chat__notification--enter-from-${entryDirection}`,\n          transitionState === 'enter' && 'str-chat__notification--is-entering',\n          transitionState === 'exit' && 'str-chat__notification--is-exiting',\n          severity && `str-chat__notification--${severity}`,\n          severity === 'loading' && 'str-chat__notification--loading',\n          className,\n        )}\n        data-testid='notification'\n        ref={ref}\n      >\n        <div className='str-chat__notification-content'>\n          {Icon && <Icon notification={notification} />}\n          <div\n            aria-atomic='true'\n            aria-live={livePriority}\n            className='str-chat__notification-message'\n            role={livePriority === 'assertive' ? 'alert' : 'status'}\n          >\n            {displayMessage}\n          </div>\n        </div>\n        {notification.actions && notification.actions.length > 0 && (\n          <div className='str-chat__notification-actions'>\n            {notification.actions.map((action, index) => (\n              <Button\n                appearance='outline'\n                className='str-chat__notification-action'\n                inverseTheme\n                key={index}\n                onClick={() => {\n                  action.handler();\n                }}\n                size='sm'\n                variant='secondary'\n              >\n                {action.label}\n              </Button>\n            ))}\n          </div>\n        )}\n        {(showClose || isPersistent) && (\n          <Button\n            appearance='ghost'\n            aria-label={t(\n              'notification.dismissNotification.ariaLabel',\n              'Dismiss notification',\n            )}\n            circular\n            className='str-chat__notification-close-button'\n            inverseTheme\n            onClick={handleDismiss}\n            size='sm'\n            variant='secondary'\n          >\n            <IconXmark />\n          </Button>\n        )}\n      </div>\n    );\n  },\n);\n\nNotification.displayName = 'Notification';\n"],"mappings":";;;;;;;;;AAiBA,IAAM,2BAA2B,EAAE,mBAA0C;CAC3E,MAAM,EAAE,eAAe,qBAAqB,6BAA6B,gBACvE,yBAAyB;CAE3B,MAAM,kBAAsE;EAC1E,OAAO;EACP,MAAM;EACN,SAAS;EACT,SAAS;EACT,SAAS;CACX;CAEA,IAAI,CAAC,aAAa,UAAU,OAAO;CAEnC,MAAM,OAAO,gBAAgB,aAAa,aAAa;CACvD,OACE,QACE,oBAAC,OAAD;EAAK,WAAU;YACb,oBAAC,MAAD,CAAO,CAAA;CACJ,CAAA;AAGX;AAkBA,IAAa,eAAe,YAExB,EACE,WACA,gBACA,OAAO,yBACP,cACA,WACA,YAAY,OACZ,mBAEF,QACG;CACH,MAAM,EAAE,uBAAuB,mBAAmB;CAClD,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,cAAc,yBAAyB;CAE/C,MAAM,iBAAiB,EAAE,wCAAwC;EAC/D;EACA,OAAO,aAAa;CACtB,CAAC;CAED,MAAM,sBAAsB;EAC1B,IAAI,WAAW;GACb,UAAU;GACV;EACF;EAEA,mBAAmB,aAAa,EAAE;CACpC;CAEA,MAAM,eAAe,CAAC,aAAa;CAEnC,MAAM,WAAW,aAAa;CAG9B,MAAM,mBAAmB,aAAa,UAAU;CAChD,MAAM,eACJ,qBAAqB,eAAe,qBAAqB,WACrD,mBACA,aAAa,UACX,cACA;CAER,OACE,qBAAC,OAAD;EACE,WAAW,KACT,0BACA,kBAAkB,sCAAsC,kBACxD,oBAAoB,WAAW,uCAC/B,oBAAoB,UAAU,sCAC9B,YAAY,2BAA2B,YACvC,aAAa,aAAa,mCAC1B,SACF;EACA,eAAY;EACP;YAXP;GAaE,qBAAC,OAAD;IAAK,WAAU;cAAf,CACG,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