{"version":3,"file":"PromoCard.mjs","sources":["../../src/promoCard/PromoCard.tsx"],"sourcesContent":["import { Check } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport React, { forwardRef, FunctionComponent, useEffect, useId, useState } from 'react';\n\nimport Body from '../body';\nimport { Typography } from '../common';\nimport BaseCard, { type BaseCardProps } from '../common/baseCard';\nimport Display from '../display';\nimport Image from '../image/Image';\nimport Title from '../title';\n\nimport { usePromoCardContext } from './PromoCardContext';\nimport PromoCardIndicator, { type PromoCardIndicatorProps } from './PromoCardIndicator';\n\nexport type ReferenceType = React.Ref<HTMLInputElement> | React.Ref<HTMLDivElement>;\nexport type RelatedTypes =\n  | ''\n  | 'alternate'\n  | 'author'\n  | 'bookmark'\n  | 'external'\n  | 'help'\n  | 'license'\n  | 'next'\n  | 'nofollow'\n  | 'noreferrer'\n  | 'noopener'\n  | 'prev'\n  | 'search'\n  | 'tag';\n\nexport interface PromoCardCommonProps {\n  /** Optional prop to specify classNames onto the PromoCard */\n  className?: string;\n\n  /** Optional prop to specify the ID of the PromoCard */\n  id?: string;\n\n  /** Required prop to specify the descriptive text of the PromoCard  */\n  description: string;\n\n  /**\n   * Optional prop to specify the heading level of the PromoCard\n   *\n   * @default 'h3'\n   */\n  headingLevel?: 'h3' | 'h4' | 'h5' | 'h6';\n\n  /** Optional prop to specify text for the indicator label of the PromoCard */\n  indicatorLabel?: string;\n\n  /** Optional prop to specify the icon for the indicator icon of the PromoCard */\n  indicatorIcon?: PromoCardIndicatorProps['icon'];\n\n  /** Optional prop to specify an image alt text  */\n  imageAlt?: string;\n\n  /** Optional prop to specify an image class  */\n  imageClass?: string;\n\n  /** Optional prop to specify an image source url  */\n  imageSource?: string;\n\n  /** Specify whether the PromoCard is disabled, or not */\n  isDisabled?: boolean;\n\n  /** Specify an onClick event handler */\n  onClick?: () => void;\n\n  /** Specify an onKeyDown event handler */\n  onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n\n  /** Optional prop to specify the ID used for testing */\n  testId?: string;\n\n  /** Required prop to specify the title text of the PromoCard  */\n  title: string;\n\n  /** Set to false to use body font style for the title   */\n  useDisplayFont?: boolean;\n\n  ref?: ReferenceType;\n}\n\nexport interface PromoCardLinkProps extends PromoCardCommonProps, Omit<BaseCardProps, 'children'> {\n  /**\n   * Optional prop to prompts a user to save the linked URL instead of\n   * navigating to it\n   */\n  download?: string;\n\n  /** Optionally specify an href for your PromoCard to contain an <a> element */\n  href?: string;\n\n  /** Optionally specify the language of the linked URL */\n  hrefLang?: string;\n\n  /** Optional property that can be pass a ref for the anchor. */\n  anchorRef?: React.Ref<HTMLAnchorElement>;\n\n  /**\n   * Optional prop to specify the ID of the anchor element which can be useful when using a ref.\n   */\n  anchorId?: string;\n\n  /**\n   * Relationship between the PromoCard href URL and the current page. See\n   * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel).\n   */\n  rel?: RelatedTypes;\n\n  /** Optional prop to to display where the linked URL will show */\n  target?: React.HTMLAttributeAnchorTarget;\n\n  /** Only applies to role=\"radio\" or \"checkbox\" */\n  defaultChecked?: never;\n  isChecked?: never;\n  tabIndex?: never;\n  type?: never;\n  ref?: ReferenceType;\n  value?: never;\n}\n\nexport interface PromoCardCheckedProps\n  extends PromoCardCommonProps, Omit<BaseCardProps, 'children'> {\n  /** Specify the initial checked attribute of the PromoCard */\n  defaultChecked?: boolean;\n\n  /** Specify whether the PromoCard is checked, or not */\n  isChecked?: boolean;\n\n  /** Optional prop to specify the tabIndex of the PromoCard */\n  tabIndex?: number;\n\n  /** Optional property to provide component Ref */\n  ref?: ReferenceType;\n\n  /** Optional prop to specify the input type of the PromoCard  */\n  type?: 'checkbox' | 'radio';\n\n  /** Specify the value attribute of the PromoCard if Checkbox or Radio */\n  value?: string;\n\n  /** Only applies to <a />s */\n  download?: never;\n  href?: never;\n  anchorRef?: never;\n  anchorId?: never;\n  hrefLang?: never;\n  rel?: never;\n  target?: never;\n}\n\nexport type PromoCardProps = PromoCardLinkProps | PromoCardCheckedProps;\n\nexport type PolymorphicPromoCard = (\n  props: PromoCardLinkProps | PromoCardCheckedProps,\n) => React.JSX.Element;\n\n/**\n * PromoCard component.\n *\n * PromoCard is a marketing style component that is used to group marketing\n * product related information (such as choosing Card types). It can be used to\n * display information in a structured way, and can be customized with various\n * props to suit different use cases.\n *\n * @component\n * @param {string} className - Additional class name for the PromoCard.\n * @param {string} description - Description text for the PromoCard.\n * @param {boolean} defaultChecked - Initial checked state for checkboxes and radios.\n * @param {string} download - Download file name for links.\n * @param {string} href - URL for links.\n * @param {string} hrefLang - Language code for linked URL.\n * @param {string} id - ID of the PromoCard.\n * @param {string} imageAlt - Alt text for the image.\n * @param {string} imageSource - Source URL of the image.\n * @param {string} indicatorLabel - Label for the indicator icon.\n * @param {boolean} isChecked - Checked state for checkboxes and radios.\n * @param {boolean} isDisabled - Whether the PromoCard is disabled.\n * @param {Function} onClick - Click event handler for the PromoCard.\n * @param {string} rel - Relationship between the URL and the current page.\n * @param {number} tabIndex - Tab index for keyboard navigation.\n * @param {string} target - Target window for links.\n * @param {string} testId - ID used for testing.\n * @param {string} title - Title text of the PromoCard.\n * @param {('checkbox'|'radio')} type - Type of the PromoCard (checkbox, radio).\n * @param {string} value - Value for checkboxes and radios.\n * @returns {React.JSX.Element} The rendered PromoCard component.\n * @example\n * <PromoCard\n *   title=\"Example PromoCard\"\n *   description=\"This is an example PromoCard with a link variation.\"\n *   href=\"https://example.com\"\n *   target=\"_blank\"\n *   imageSource=\"https://example.com/image.png\"\n *   imageAlt=\"Example Image\"\n *   indicatorLabel=\"Learn More\"\n * />\n */\nconst PromoCard: FunctionComponent<PromoCardProps> = forwardRef(\n  (\n    {\n      className,\n      description,\n      defaultChecked,\n      download,\n      href,\n      hrefLang,\n      id,\n      headingLevel = 'h3',\n      imageAlt,\n      imageClass,\n      imageSource,\n      indicatorLabel,\n      indicatorIcon,\n      isChecked,\n      isDisabled,\n      onClick,\n      onKeyDown,\n      rel,\n      tabIndex,\n      target,\n      testId,\n      title,\n      type,\n      value,\n      isSmall,\n      useDisplayFont = true,\n      anchorRef,\n      anchorId,\n      ...props\n    },\n    ref: ReferenceType,\n  ) => {\n    // Set the `checked` state to the value of `defaultChecked` if it is truthy,\n    // or the value of `isChecked` if it is truthy, or `false` if neither\n    // is truthy.\n    const { state, onChange, isDisabled: contextIsDisabled } = usePromoCardContext();\n    const [checked, setChecked] = useState(\n      type === 'checkbox' ? (defaultChecked ?? isChecked ?? false) : false,\n    );\n\n    const handleClick = () => {\n      if (type === 'radio') {\n        onChange(value || ''); // Update the context state for radio\n      } else if (type === 'checkbox') {\n        setChecked(!checked); // Update local state for checkbox\n      }\n    };\n\n    const fallbackId = useId();\n    const componentId = id || fallbackId;\n\n    // Set the icon to `'arrow'` if `href` is truthy and `type` is falsy, or\n    // `'download'` if `download` is truthy. If neither condition is true, set\n    // `icon` to `undefined`.\n\n    // Create a function to get icon type\n    const getIconType = () => {\n      if (indicatorIcon) {\n        return indicatorIcon;\n      }\n\n      if (download) {\n        return 'download';\n      }\n\n      if (href && !type) {\n        return 'arrow';\n      }\n\n      return undefined;\n    };\n\n    const CardTitle = useDisplayFont ? Display : Title;\n\n    // Define all class names string based on the values of the `href`, `type`,\n    // `checked`, and `className` props.\n    const commonClasses = clsx(\n      {\n        'np-Card--promoCard': true,\n        'np-Card--checked': !href && type,\n        'np-Card--link': href && !type,\n        'is-checked':\n          type === 'radio' ? value === state : type === 'checkbox' ? checked : undefined,\n      },\n      className,\n    );\n\n    // Object with common props that will be passed to the `Card` components\n    const commonProps = {\n      className: commonClasses,\n      id: componentId,\n      isDisabled: isDisabled || contextIsDisabled,\n      onClick,\n      onKeyDown,\n      ref,\n      'data-testid': testId,\n      isSmall,\n    };\n\n    // Object with Anchor props that will be passed to the `a` element. These\n    // won't be refurned if set to `isDisabled`\n    const anchorProps =\n      href && !isDisabled\n        ? {\n            download,\n            href: href || undefined,\n            hrefLang,\n            rel,\n            target,\n            ref: anchorRef,\n            id: anchorId,\n          }\n        : {};\n\n    // Object of all Checked props that will be passed to the root `Card` component\n    const checkedProps =\n      (type === 'checkbox' || type === 'radio') && !href\n        ? {\n            ...commonProps,\n            'aria-checked':\n              type === 'radio' ? value === state : type === 'checkbox' ? checked : undefined,\n            'aria-describedby': `${componentId}-title`,\n            'aria-disabled': isDisabled,\n            'data-value': value ?? undefined,\n            role: type === 'checkbox' || type === 'radio' ? type : undefined,\n            onClick: handleClick,\n            onKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => {\n              if (event.key === 'Enter' || event.key === ' ') {\n                handleClick();\n              }\n            },\n            ref,\n            tabIndex: 0,\n          }\n        : {};\n\n    const getTitle = () => {\n      const titleContent =\n        href && !type ? (\n          <a className=\"np-Card-titleLink\" {...anchorProps}>\n            {title}\n          </a>\n        ) : (\n          title\n        );\n\n      const titleProps = {\n        id: `${componentId}-title`,\n        as: headingLevel,\n        className: 'np-Card-title',\n      };\n\n      return useDisplayFont ? (\n        <Display type={Typography.DISPLAY_SMALL} {...titleProps}>\n          {titleContent}\n        </Display>\n      ) : (\n        <Title type={Typography.TITLE_SUBSECTION} {...titleProps}>\n          {titleContent}\n        </Title>\n      );\n    };\n\n    useEffect(() => {\n      setChecked(defaultChecked ?? isChecked ?? false);\n    }, [defaultChecked, isChecked]);\n\n    return (\n      <BaseCard {...commonProps} {...checkedProps} {...props}>\n        {(value === state || checked) && (\n          <span className=\"np-Card-check\">\n            <Check size={24} aria-hidden=\"true\" />\n          </span>\n        )}\n\n        {getTitle()}\n\n        <Body className=\"np-Card-description\">{description}</Body>\n\n        {imageSource && (\n          <div className={clsx('np-Card-image', { imageClass })}>\n            <Image src={imageSource} alt={imageAlt || ''} loading=\"lazy\" />\n          </div>\n        )}\n\n        <PromoCardIndicator label={indicatorLabel} icon={getIconType()} isSmall={isSmall} />\n      </BaseCard>\n    );\n  },\n) as PolymorphicPromoCard;\n\nexport default React.memo(PromoCard);\n"],"names":["PromoCard","forwardRef","className","description","defaultChecked","download","href","hrefLang","id","headingLevel","imageAlt","imageClass","imageSource","indicatorLabel","indicatorIcon","isChecked","isDisabled","onClick","onKeyDown","rel","tabIndex","target","testId","title","type","value","isSmall","useDisplayFont","anchorRef","anchorId","props","ref","state","onChange","contextIsDisabled","usePromoCardContext","checked","setChecked","useState","handleClick","fallbackId","useId","componentId","getIconType","undefined","commonClasses","clsx","commonProps","anchorProps","checkedProps","role","event","key","getTitle","titleContent","_jsx","children","titleProps","as","Display","Typography","DISPLAY_SMALL","Title","TITLE_SUBSECTION","useEffect","_jsxs","BaseCard","Check","size","Body","Image","src","alt","loading","PromoCardIndicator","label","icon","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwMA,MAAMA,SAAS,gBAAsCC,UAAU,CAC7D,CACE;EACEC,SAAS;EACTC,WAAW;EACXC,cAAc;EACdC,QAAQ;EACRC,IAAI;EACJC,QAAQ;EACRC,EAAE;AACFC,EAAAA,YAAY,GAAG,IAAI;EACnBC,QAAQ;EACRC,UAAU;EACVC,WAAW;EACXC,cAAc;EACdC,aAAa;EACbC,SAAS;EACTC,UAAU;EACVC,OAAO;EACPC,SAAS;EACTC,GAAG;EACHC,QAAQ;EACRC,MAAM;EACNC,MAAM;EACNC,KAAK;EACLC,IAAI;EACJC,KAAK;EACLC,OAAO;AACPC,EAAAA,cAAc,GAAG,IAAI;EACrBC,SAAS;EACTC,QAAQ;EACR,GAAGC;AAAK,CACT,EACDC,GAAkB,KAChB;AACF;AACA;AACA;EACA,MAAM;IAAEC,KAAK;IAAEC,QAAQ;AAAEjB,IAAAA,UAAU,EAAEkB;GAAmB,GAAGC,mBAAmB,EAAE;AAChF,EAAA,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,QAAQ,CACpCd,IAAI,KAAK,UAAU,GAAIpB,cAAc,IAAIW,SAAS,IAAI,KAAK,GAAI,KAAK,CACrE;EAED,MAAMwB,WAAW,GAAGA,MAAK;IACvB,IAAIf,IAAI,KAAK,OAAO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