{"version":3,"file":"ToastNotification.mjs","sources":["../../../src/components/ToastNotification/ToastNotification.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { useEffect } from 'react';\n\nimport { assertEdsUsage } from '../../util/logging';\nimport type { Status } from '../../util/variant-types';\nimport Button from '../Button';\nimport { hasSlotContent, IconSlot, useSemanticIcon } from '../Icon';\nimport Text from '../Text';\n\nimport styles from './ToastNotification.module.css';\n\nexport type ToastNotificationProps = {\n  // Component API\n  /**\n   * Additional class names that can be appended to the component, passed in for styling.\n   */\n  className?: string;\n  /**\n   * Callback when notification is dismissed. When passed in, renders banner with a close icon in the top right.\n   */\n  onDismiss?: () => void;\n  /**\n   * CSS properties defined for the HTML element.\n   */\n  style?: ToastNotificationCSSProperties;\n  /**\n   * Length of time to wait until `onDismiss` is called\n   */\n  timeout?: number;\n  // Design API\n  /**\n   * Determines whether the toast notification will dismiss on its own, or due to user action. When set to `\"auto\"`,\n   * it will dismiss after 8 seconds.\n   *\n   * **Default is `\"manual\"`**.\n   */\n  dismissType?: 'manual' | 'auto';\n  /**\n   * Keyword to characterize the state of the notification\n   */\n  status?: Status;\n  /**\n   * The title/heading of the notification\n   */\n  title: string;\n};\n\n/**\n * Color overrides a toast still honors, kept out of the component's documented API on\n * purpose. All three are held back: `--toast__bg`, `--toast__fg`, and `--toast__icon`.\n *\n * `--toast__icon` is the reason. It recolors the status icon, which is the one part of a\n * toast a reader uses to tell severity apart at a glance, and recoloring it away from its\n * status is how a favorable toast ends up looking critical. The background and foreground go\n * with it, since a toast recolored past its status reads the same way whichever property did\n * it.\n *\n * Held back rather than removed: they keep working, and the toasts already relying on them\n * keep rendering. They are simply not advertised, so nothing points a new consumer at them.\n * The declarations stay here so existing usage keeps type-checking, and\n * `ToastNotification.test.tsx` covers all three still taking effect, since no story does.\n *\n * See \"Properties held back from the documented API\" in `.github/copilot-instructions.md`.\n */\nexport interface ToastNotificationCSSProperties extends React.CSSProperties {\n  '--toast__bg'?: string;\n\n  '--toast__fg'?: string;\n\n  '--toast__icon'?: string;\n}\n\n/**\n * ## Usage\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Success | Confirms a successful action. | Form submitted, settings saved, message sent. |\n * | Error | Alerts the user to a failure or problem. | Failed save, API error, input validation failure. |\n * | Warning | Warns about potential issues without blocking progress. | Unsaved changes, feature deprecation, connectivity issues. |\n * | Info | Shares neutral or contextual information. | Tip or hint, background updates, non-critical status. |\n *\n * ## Interaction\n *\n * Toast notifications can be manually dismissed or auto-dismissed using the `dismissType` prop; auto toasts are automatically dismissed after 8 seconds. When building with `ToastNotification`, each should slide in and out from the top right of the screen, placed 16px from the bottom and right side of the viewport, fading in with the `eds-anim-fade-long` token and out with the `eds-anim-fade-quick` token.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Keep the toast to a single, simple message such as a confirmation.\n * * Use simple phrases or sentence fragments, in sentence case.\n * * Aim for 1 line of text or less.\n *\n * ### Don'ts\n *\n * * Don't use more than 2 lines of text; if more is required, find another way to provide the information.\n * * Don't include any information in a toast that may be needed again.\n * * Don't punctuate incomplete sentences, and don't rely on color to convey meaning.\n */\nexport const ToastNotification = ({\n  className,\n  dismissType = 'manual',\n  onDismiss,\n  status = 'favorable',\n  timeout = 8000,\n  title,\n  ...other\n}: ToastNotificationProps) => {\n  const componentClassName = clsx(\n    styles['toast'],\n    status && styles[`toast--status-${status}`],\n    className,\n  );\n\n  assertEdsUsage(\n    [!!timeout && typeof onDismiss === 'undefined' && dismissType === 'auto'],\n    'When using dismissType=auto, an onDismiss method must be defined',\n    'error',\n  );\n\n  // Both icons here are semantic: the status icon carries the toast's severity, and the\n  // dismiss button is the same close affordance used everywhere else. The app sets either\n  // one through `IconProvider`, not per toast.\n  const statusIcon = useSemanticIcon(status);\n  const closeIcon = useSemanticIcon('close');\n\n  useEffect(() => {\n    const expireId =\n      dismissType === 'auto'\n        ? setTimeout(() => {\n            onDismiss && onDismiss();\n          }, timeout)\n        : undefined;\n\n    return () => clearTimeout(expireId);\n  }, [onDismiss, dismissType, timeout]);\n\n  return (\n    <div className={componentClassName} {...other}>\n      {hasSlotContent(statusIcon) && (\n        <IconSlot\n          className={styles['toast__icon']}\n          content={statusIcon}\n          purpose=\"decorative\"\n          size=\"24px\"\n        />\n      )}\n      <div className={styles['toast__body']}>\n        <Text as=\"span\" preset=\"body-md\">\n          {title}\n        </Text>\n      </div>\n      {onDismiss && (\n        <Button\n          aria-label=\"close\"\n          className={styles['toast__dismiss-button']}\n          context=\"default\"\n          icon={closeIcon}\n          iconLayout=\"icon-only\"\n          onClick={onDismiss}\n          rank=\"tertiary\"\n          size=\"md\"\n          variant=\"inverse\"\n        />\n      )}\n    </div>\n  );\n};\n\nToastNotification.displayName = 'ToastNotification';\n"],"names":["React"],"mappings":";;;;;;;;;;AAwEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,WAAW,GAAG,QAAQ,EACtB,SAAS,EACT,MAAM,GAAG,WAAW,EACpB,OAAO,GAAG,IAAI,EACd,KAAK,EACL,GAAG,KAAK,EACe,KAAI;IAC3B,MAAM,kBAAkB,GAAG,IAAI,CAC7B,MAAM,CAAC,OAAO,CAAC,EACf,MAAM,IAAI,MAAM,CAAC,iBAAiB,MAAM,CAAA,CAAE,CAAC,EAC3C,SAAS,CACV;IAED,cAAc,CACZ,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,WAAW,KAAK,MAAM,CAAC,EACzE,kEAAkE,EAClE,OAAO,CACR;;;;AAKD,IAAA,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC;AAC1C,IAAA,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC;IAE1C,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,QAAQ,GACZ,WAAW,KAAK;AACd,cAAE,UAAU,CAAC,MAAK;gBACd,SAAS,IAAI,SAAS,EAAE;YAC1B,CAAC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