{"version":3,"file":"InfoPrompt.mjs","sources":["../../../src/prompt/InfoPrompt/InfoPrompt.tsx"],"sourcesContent":["import { HTMLAttributes, ReactNode, 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 text for the prompt (required)\n     */\n    description: string;\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://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 = [title, description, action?.label].filter(Boolean).join('|');\n  const statusIconSentiment =\n    sentiment === 'success'\n      ? Sentiment.POSITIVE\n      : (sentiment as Exclude<SurfaceSentiment, 'proposition'>);\n\n  const handleTouchStart = () => {\n    setShouldFire(true);\n  };\n\n  const handleTouchEnd = () => {\n    if (shouldFire && 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    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 <GiftBox size={24} />;\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","label","filter","Boolean","join","statusIconSentiment","Sentiment","POSITIVE","handleTouchStart","handleTouchEnd","href","target","window","top","open","location","assign","handleTouchMove","renderMedia","_jsx","children","asset","GiftBox","size","StatusIcon","LiveRegion","PrimitivePrompt","clsx","onTouchStart","onTouchEnd","onTouchMove","_jsxs","Body","type","Typography","BODY_LARGE_BOLD","as","Link","LINK_DEFAULT","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EO,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;AAAS,CACI,KAAI;EACpB,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,QAAQ,EAAW;EACvD,MAAMC,gBAAgB,GAAG,CAACT,KAAK,EAAEC,WAAW,EAAEF,MAAM,EAAEW,KAAK,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACtF,MAAMC,mBAAmB,GACvBlB,SAAS,KAAK,SAAS,GACnBmB,SAAS,CAACC,QAAQ,GACjBpB,SAAsD;EAE7D,MAAMqB,gBAAgB,GAAGA,MAAK;IAC5BV,aAAa,CAAC,IAAI,CAAC;EACrB,CAAC;EAED,M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