{"version":3,"file":"Alert.mjs","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport {\n  CloseButton,\n  Sentiment,\n  Size,\n  Status,\n  Typography,\n  WDS_LIVE_REGION_DELAY_MS,\n} from '../common';\n\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport Button from '../button';\nimport Link from '../link';\n\n/**\n * @deprecated `Alert` component is being replaced by the `InfoPrompt` component\n */\nexport type AlertAction = {\n  'aria-label'?: string;\n  href?: string;\n  target?: string;\n  text: React.ReactNode;\n  onClick?: () => void;\n  /** Controls the rendered element: `'link'` (default) renders a Link, `'button'` renders a Button. When `'button'` is used with `href`, renders an anchor styled as a button. */\n  as?: 'button' | 'link';\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n  | Sentiment.POSITIVE\n  | Sentiment.NEUTRAL\n  | Sentiment.WARNING\n  | Sentiment.NEGATIVE\n  // remove when all instances of Sentiment.PENDING have been updated to Status.PENDING\n  | Sentiment.PENDING\n  | Status.PENDING}`;\n\n/**\n * @deprecated `Alert` component is being replaced by the `InfoPrompt` component\n */\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\n/**\n * @deprecated `Alert` component is being replaced by the `InfoPrompt` component\n */\nexport enum AlertArrowPosition {\n  TOP_LEFT = 'up-left',\n  TOP = 'up-center',\n  TOP_RIGHT = 'up-right',\n  BOTTOM_LEFT = 'down-left',\n  BOTTOM = 'down-center',\n  BOTTOM_RIGHT = 'down-right',\n}\n\n/**\n * @deprecated `Alert` component is being replaced by the `InfoPrompt` component\n */\nexport interface AlertProps {\n  /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n  action?: AlertAction;\n  className?: string;\n  /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n  icon?: React.ReactNode;\n  /**\n   * Override for [StatusIcon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n   * announced by the screen readers\n   * */\n  statusIconLabel?: string;\n  /** Title for the alert component */\n  title?: string;\n  /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n  message?: string;\n  /** The presence of the onDismiss handler will trigger the visibility of the close button */\n  onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n  /**\n   * The type dictates which icon and colour will be used\n   * @default 'neutral'\n   */\n  type?: AlertType;\n  /** @deprecated Use `InlinePrompt` instead. */\n  arrow?: `${AlertArrowPosition}`;\n  /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n  children?: React.ReactNode;\n  /** @deprecated Use `onDismiss` instead. */\n  dismissible?: boolean;\n  /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n  size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n  switch (type) {\n    case 'success':\n      return 'positive';\n    case 'info':\n      return 'neutral';\n    case 'error':\n      return 'negative';\n    default:\n      return type;\n  }\n}\n\n/**\n * @deprecated Use [`InfoPrompt`](https://storybook.wise.design/?path=/docs/prompts-infoprompt--docs) component instead. Run codemod to migrate: **`npx @wise/wds-codemods@latest info-prompt`**\n */\nexport default function Alert({\n  action,\n  className,\n  icon,\n  statusIconLabel,\n  onDismiss,\n  message,\n  title,\n  type = 'neutral',\n  arrow,\n  children,\n  size,\n  dismissible,\n}: AlertProps) {\n  useEffect(() => {\n    if (arrow !== undefined) {\n      logActionRequired(\n        \"Alert component doesn't support 'arrow' anymore, use 'InlinePrompt' instead.\",\n      );\n    }\n  }, [arrow]);\n\n  useEffect(() => {\n    if (children !== undefined) {\n      logActionRequired(\n        \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n      );\n    }\n  }, [children]);\n\n  useEffect(() => {\n    if (dismissible !== undefined) {\n      logActionRequired(\n        \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n      );\n    }\n  }, [dismissible]);\n\n  useEffect(() => {\n    if (size !== undefined) {\n      logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n    }\n  }, [size]);\n\n  const resolvedType = resolveType(type);\n  useEffect(() => {\n    if (resolvedType !== type) {\n      logActionRequired(\n        `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n      );\n    }\n  }, [resolvedType, type]);\n\n  const [shouldFire, setShouldFire] = useState<boolean>();\n\n  const [shouldAnnounce, setShouldAnnounce] = useState<boolean>(false);\n  useEffect(() => {\n    const timeoutId = setTimeout(() => {\n      setShouldAnnounce(true);\n    }, WDS_LIVE_REGION_DELAY_MS);\n\n    return () => clearTimeout(timeoutId);\n  }, []);\n\n  const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n  /**\n   * All focusable elements must be disabled until we announce the alert.\n   * @see https://dequeuniversity.com/rules/axe/4.10/aria-hidden-focus?application=axeAPI\n   */\n  const accessibleTabIndex = shouldAnnounce ? undefined : -1;\n\n  return (\n    <div\n      role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}\n      className=\"wds-alert__liveRegion\"\n    >\n      <div\n        aria-hidden={shouldAnnounce ? undefined : 'true'}\n        className={clsx(\n          'alert d-flex',\n          `alert-${resolvedType}`,\n          arrow != null && alertArrowClassNames(arrow),\n          className,\n        )}\n        data-testid=\"alert\"\n        onTouchStart={() => setShouldFire(true)}\n        onTouchEnd={(event) => {\n          if (\n            shouldFire &&\n            action?.href &&\n            // Check if current event is triggered from closeButton\n            event.target instanceof Node &&\n            closeButtonReference.current &&\n            !closeButtonReference.current.contains(event.target)\n          ) {\n            if (action.target === '_blank') {\n              window.top?.open(action.href);\n            } else {\n              window.top?.location.assign(action.href);\n            }\n          }\n          setShouldFire(false);\n        }}\n        onTouchMove={() => setShouldFire(false)}\n      >\n        <div className=\"alert__icon\">\n          {icon || <StatusIcon size={32} sentiment={resolvedType} iconLabel={statusIconLabel} />}\n        </div>\n        <div className={clsx('alert__content', 'd-flex', 'flex-grow-1')}>\n          <div className=\"alert__message\">\n            <div>\n              {title && (\n                <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n                  {title}\n                </Title>\n              )}\n              <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n                {children || <InlineMarkdown>{message}</InlineMarkdown>}\n              </Body>\n            </div>\n            {action &&\n              ('href' in action && action.as !== 'button' ? (\n                <Link\n                  href={action.href}\n                  aria-label={action['aria-label']}\n                  target={action.target}\n                  type={Typography.LINK_LARGE}\n                  className=\"alert__action\"\n                  tabIndex={accessibleTabIndex}\n                  onClick={action.onClick}\n                >\n                  {action.text}\n                </Link>\n              ) : (\n                <Button\n                  v2\n                  as={action.href ? 'a' : 'button'}\n                  href={action.href}\n                  target={action.target}\n                  size=\"sm\"\n                  sentiment=\"default\"\n                  aria-label={action['aria-label']}\n                  priority=\"secondary-neutral\"\n                  className=\"alert__action\"\n                  tabIndex={accessibleTabIndex}\n                  onClick={action.onClick}\n                >\n                  {action.text}\n                </Button>\n              ))}\n          </div>\n        </div>\n        {onDismiss && (\n          <div className=\"alert__close\">\n            <CloseButton\n              ref={closeButtonReference}\n              size=\"xs\"\n              tabIndex={accessibleTabIndex}\n              onClick={onDismiss}\n            />\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n  switch (arrow) {\n    case 'down-center':\n      return 'arrow arrow-bottom arrow-center';\n    case 'down-left':\n      return 'arrow arrow-bottom arrow-left';\n    case 'down-right':\n      return 'arrow arrow-bottom arrow-right';\n    case 'up-center':\n      return 'arrow arrow-center';\n    case 'up-right':\n      return 'arrow arrow-right';\n    case 'up-left':\n    default:\n      return 'arrow';\n  }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","action","className","icon","statusIconLabel","onDismiss","message","title","arrow","children","size","dismissible","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","shouldAnnounce","setShouldAnnounce","timeoutId","setTimeout","WDS_LIVE_REGION_DELAY_MS","clearTimeout","closeButtonReference","useRef","accessibleTabIndex","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","sentiment","iconLabel","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Link","LINK_LARGE","tabIndex","onClick","text","Button","v2","priority","CloseButton","ref"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqDYA;AAAZ,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B;AAC7B,CAAC,EAPWA,kBAAkB,KAAlBA,kBAAkB,GAAA,EAAA,CAAA,CAAA;AA4C9B,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS;AAClB,IAAA,KAAK,OAAO;AACV,MAAA,OAAO,UAAU;AACnB,IAAA;AACE,MAAA,OAAOA,IAAI;AACf;AACF;AAEA;;AAEG;AACW,SAAUC,KAAKA,CAAC;EAC5BC,MAAM;EACNC,SAAS;EACTC,IAAI;EACJC,eAAe;EACfC,SAAS;EACTC,OAAO;EACPC,KAAK;A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