{"version":3,"file":"InfoPrompt.mjs","sources":["../../../src/Prompt/InfoPrompt/InfoPrompt.tsx"],"sourcesContent":["import { Children, HTMLAttributes, ReactNode, TouchEvent, isValidElement, useState } from 'react';\nimport { LiveRegion, Sentiment, Typography } from '../../common';\nimport type { AriaLive } from '../../common';\nimport { GiftBox } from '@transferwise/icons';\nimport type { Sentiment as SurfaceSentiment } from '../../SentimentSurface';\nimport StatusIcon from '../../StatusIcon';\nimport { clsx } from 'clsx';\nimport Body from '../../Body';\nimport Link, { LinkProps } from '../../Link';\nimport { PrimitivePrompt, PrimitivePromptProps } from '../PrimitivePrompt';\n\nexport type InfoPromptAction = Pick<LinkProps, 'href' | 'target' | 'onClick'> & {\n  /**\n   * The label text for the action link\n   */\n  label: string;\n};\n\nexport type InfoPromptMedia = {\n  /**\n   * The icon/image asset to display.\n   * The asset should include its own accessibility attributes (e.g. title, aria-label) if it conveys meaning.\n   */\n  asset: ReactNode;\n};\n\nexport type InfoPromptProps = Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'aria-live' | 'role'> &\n  Pick<PrimitivePromptProps, 'data-testid'> & {\n    /**\n     * The sentiment determines the colour scheme\n     * @default 'neutral'\n     */\n    sentiment?: SurfaceSentiment;\n    /**\n     * Handler called when the close button is clicked.\n     * If not provided, the close button is hidden.\n     */\n    onDismiss?: () => void;\n    /**\n     * Custom media to override the default status icon.\n     * Success and proposition sentiments support 2 status variations: standard checkmark & confetti.\n     */\n    media?: InfoPromptMedia;\n    /**\n     * Action link to be displayed below the description\n     */\n    action?: InfoPromptAction;\n    /**\n     * Title content for the prompt\n     */\n    title?: string;\n    /**\n     * Description content for the prompt (required). Accepts plain text or rich content (ReactNode).\n     * If the description contains an interactive element, the `action` prop must not be used simultaneously.\n     */\n    description: ReactNode;\n    className?: string;\n    /**\n     * Sets the ARIA live region politeness level.\n     * - `'polite'` — announced after the current speech (default)\n     * - `'assertive'` — interrupts the current speech immediately\n     * - `'off'` — disables the live region entirely\n     * @default 'polite'\n     */\n    'aria-live'?: AriaLive;\n  };\n\n/**\n * `InfoPrompt` displays important contextual messages to users within a screen.\n * It provides a visually distinct way to communicate information, warnings, errors,\n * or positive feedback with optional actions and dismissal capabilities.\n *\n * Use this component to replace the deprecated `Alert` component (run codemod to migrate: **`npx \\@wise/wds-codemods@latest info-prompt`**).\n *\n * Guidance can be found in the [design system](https://docs.wise.design/components/info-prompt).\n */\nexport const InfoPrompt = ({\n  sentiment = 'neutral',\n  onDismiss,\n  media,\n  action,\n  title,\n  description,\n  className,\n  'aria-live': ariaLive = 'polite',\n  'data-testid': dataTestId,\n  ...restProps\n}: InfoPromptProps) => {\n  const [shouldFire, setShouldFire] = useState<boolean>();\n  const announceOnChange = [\n    title,\n    Children.toArray(description)\n      .map((child) =>\n        isValidElement<{ children?: ReactNode }>(child) ? child.props.children : child,\n      )\n      .join(''),\n    action?.label,\n  ]\n    .filter(Boolean)\n    .join('|');\n  const statusIconSentiment =\n    sentiment === 'success'\n      ? Sentiment.POSITIVE\n      : (sentiment as Exclude<SurfaceSentiment, 'proposition'>);\n\n  const handleTouchStart = (event: TouchEvent<HTMLDivElement>) => {\n    const target = event.target as HTMLElement;\n    if (target.closest('.wds-prompt__dismiss') || target.closest('.wds-info-prompt__action')) {\n      return;\n    }\n    setShouldFire(true);\n  };\n\n  const handleTouchEnd = () => {\n    if (shouldFire && action) {\n      (action.onClick as (() => void) | undefined)?.();\n      if (action.href) {\n        if (action.target === '_blank') {\n          window.top?.open(action.href, '_blank', 'noopener, noreferrer');\n        } else {\n          window.top?.location.assign(action.href);\n        }\n      }\n    }\n    setShouldFire(false);\n  };\n\n  const handleTouchMove = () => {\n    setShouldFire(false);\n  };\n\n  const renderMedia = () => {\n    if (media) {\n      return <span className=\"wds-info-prompt__media\">{media.asset}</span>;\n    }\n\n    if (sentiment === 'proposition') {\n      return (\n        <span className=\"wds-info-prompt__media\">\n          <GiftBox />\n        </span>\n      );\n    }\n\n    return <StatusIcon size={24} sentiment={statusIconSentiment} />;\n  };\n\n  // Render content directly in LiveRegion\n  return (\n    <LiveRegion aria-live={ariaLive} announceOnChange={announceOnChange}>\n      <PrimitivePrompt\n        sentiment={sentiment}\n        media={renderMedia()}\n        data-testid={dataTestId}\n        className={clsx('wds-info-prompt', className)}\n        {...restProps}\n        onTouchStart={handleTouchStart}\n        onTouchEnd={handleTouchEnd}\n        onTouchMove={handleTouchMove}\n        onDismiss={onDismiss}\n      >\n        <div className=\"wds-info-prompt__content\">\n          {title && (\n            <Body className=\"wds-info-prompt__title\" type={Typography.BODY_LARGE_BOLD} as=\"span\">\n              {title}\n            </Body>\n          )}\n          <Body as=\"span\" className=\"wds-info-prompt__description\">\n            {description}\n          </Body>\n          {action && (\n            <Link\n              href={action.href}\n              target={action.target}\n              type={Typography.LINK_DEFAULT}\n              className=\"wds-info-prompt__action\"\n              onClick={action.onClick}\n            >\n              {action.label}\n            </Link>\n          )}\n        </div>\n      </PrimitivePrompt>\n    </LiveRegion>\n  );\n};\n"],"names":["InfoPrompt","sentiment","onDismiss","media","action","title","description","className","ariaLive","dataTestId","restProps","shouldFire","setShouldFire","useState","announceOnChange","Children","toArray","map","child","isValidElement","props","children","join","label","filter","Boolean","statusIconSentiment","Sentiment","POSITIVE","handleTouchStart","event","target","closest","handleTouchEnd","onClick","href","window","top","open","location","assign","handleTouchMove","renderMedia","_jsx","asset","GiftBox","StatusIcon","size","LiveRegion","PrimitivePrompt","clsx","onTouchStart","onTouchEnd","onTouchMove","_jsxs","Body","type","Typography","BODY_LARGE_BOLD","as","Link","LINK_DEFAULT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EO,MAAMA,UAAU,GAAGA,CAAC;AACzBC,EAAAA,SAAS,GAAG,SAAS;EACrBC,SAAS;EACTC,KAAK;EACLC,MAAM;EACNC,KAAK;EACLC,WAAW;EACXC,SAAS;EACT,WAAW,EAAEC,QAAQ,GAAG,QAAQ;AAChC,EAAA,aAAa,EAAEC,UAAU;EACzB,GAAGC;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