import { HTMLAttributes, ReactNode, useState } from 'react'; import { LiveRegion, Sentiment, Typography } from '../../common'; import type { AriaLive } from '../../common'; import { GiftBox } from '@transferwise/icons'; import type { Sentiment as SurfaceSentiment } from '../../sentimentSurface'; import StatusIcon from '../../statusIcon'; import { clsx } from 'clsx'; import Body from '../../body'; import Link, { LinkProps } from '../../link'; import { PrimitivePrompt, PrimitivePromptProps } from '../PrimitivePrompt'; export type InfoPromptAction = Pick & { /** * The label text for the action link */ label: string; }; export type InfoPromptMedia = { /** * The icon/image asset to display. * The asset should include its own accessibility attributes (e.g. title, aria-label) if it conveys meaning. */ asset: ReactNode; }; export type InfoPromptProps = Omit, 'title' | 'aria-live' | 'role'> & Pick & { /** * The sentiment determines the colour scheme * @default 'neutral' */ sentiment?: SurfaceSentiment; /** * Handler called when the close button is clicked. * If not provided, the close button is hidden. */ onDismiss?: () => void; /** * Custom media to override the default status icon. * Success and proposition sentiments support 2 status variations: standard checkmark & confetti. */ media?: InfoPromptMedia; /** * Action link to be displayed below the description */ action?: InfoPromptAction; /** * Title content for the prompt */ title?: string; /** * Description text for the prompt (required) */ description: string; className?: string; /** * Sets the ARIA live region politeness level. * - `'polite'` — announced after the current speech (default) * - `'assertive'` — interrupts the current speech immediately * - `'off'` — disables the live region entirely * @default 'polite' */ 'aria-live'?: AriaLive; }; /** * `InfoPrompt` displays important contextual messages to users within a screen. * It provides a visually distinct way to communicate information, warnings, errors, * or positive feedback with optional actions and dismissal capabilities. * * Use this component to replace the deprecated `Alert` component (run codemod to migrate: **`npx \@wise/wds-codemods@latest info-prompt`**). * * Guidance can be found in the [design system](https://wise.design/components/info-prompt). */ export const InfoPrompt = ({ sentiment = 'neutral', onDismiss, media, action, title, description, className, 'aria-live': ariaLive = 'polite', 'data-testid': dataTestId, ...restProps }: InfoPromptProps) => { const [shouldFire, setShouldFire] = useState(); const announceOnChange = [title, description, action?.label].filter(Boolean).join('|'); const statusIconSentiment = sentiment === 'success' ? Sentiment.POSITIVE : (sentiment as Exclude); const handleTouchStart = () => { setShouldFire(true); }; const handleTouchEnd = () => { if (shouldFire && action?.href) { if (action.target === '_blank') { window.top?.open(action.href, '_blank', 'noopener, noreferrer'); } else { window.top?.location.assign(action.href); } } setShouldFire(false); }; const handleTouchMove = () => { setShouldFire(false); }; const renderMedia = () => { if (media) { return {media.asset}; } if (sentiment === 'proposition') { return ; } return ; }; // Render content directly in LiveRegion return (
{title && ( {title} )} {description} {action && ( {action.label} )}
); };