{"version":3,"file":"ExpressiveMoneyInput.mjs","sources":["../../src/expressiveMoneyInput/ExpressiveMoneyInput.tsx"],"sourcesContent":["import Body from '../body';\nimport { Label } from '../label/Label';\nimport { clsx } from 'clsx';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { useId, type ReactNode } from 'react';\n\nimport {\n  type Props as CurrencySelectorProps,\n  CurrencySelector,\n} from './currencySelector/CurrencySelector';\nimport { CommonProps } from '../common';\nimport { AmountInput } from './amountInput/AmountInput';\nimport { Chevron } from './chevron/Chevron';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt/InlinePrompt';\n\ntype AmountType = number | null;\nexport type CurrencyType = string;\n\ntype DefaultCurrencySelectorInstanceType = Pick<\n  CurrencySelectorProps,\n  'addons' | 'options' | 'onChange' | 'onOpen' | 'onSearchChange'\n>;\ntype CustomCurrencySelectorInstanceType = {\n  customRender?: (props: { id: string; labelId: string }) => ReactNode;\n};\ntype CurrencySelectorType = DefaultCurrencySelectorInstanceType &\n  CustomCurrencySelectorInstanceType;\n\nexport type Props = {\n  label?: ReactNode;\n  currencySelector?: CurrencySelectorType;\n  amount?: AmountType;\n  /**\n   * The currency code, e.g. `USD`, `EUR`, `GBP`, etc. Governs the flag rendered in the currency selector.\n   */\n  currency: CurrencyType;\n  inlinePrompt?: {\n    sentiment?: InlinePromptProps['sentiment'];\n    message: InlinePromptProps['children'];\n    media?: InlinePromptProps['media'];\n  };\n  showChevron?: boolean;\n  /**\n   * If set, it auto-focuses the amount input upon component mount.<br />\n   * ⚠️ **Use with caution**, as it may impact user experience and\n   * fail [WCAG 2.4.3 requirements](https://www.w3.org/WAI/WCAG21/Understanding/focus-order.html)\n   */\n  autoFocus?: boolean;\n  /**\n   * Dims the input to indicate a loading state. Does not disable it.\n   */\n  loading?: boolean;\n  onAmountChange: (amount: AmountType) => void;\n  onFocusChange?: (focused: boolean) => void;\n} & CommonProps;\n\n/**\n * This component has been kindly contributed by our friends at the `Send` team 🎉.\n *\n * Some patterns and implementation details used in this component may differ\n * from what's commonly used in the Design System. The overall build and QA was managed\n * by the contributing team directly, and such did not follow a typical DS lifecycle.\n *\n * While we house this component and will help facilitate its future iterations,\n * direct contributions by consuming product teams are highly encouraged.\n *\n * > ⚠️ **Prerequisite:** <br />The component depends on the\n * [framer-motion](https://www.npmjs.com/package/framer-motion) package, which has been\n * deliberately excluded from the Design System bundle and kept as an opt-in only.\n * **Make sure to add it to your project dependencies.**\n */\nexport default function ExpressiveMoneyInput({\n  label,\n  currency,\n  currencySelector = { options: [] } as DefaultCurrencySelectorInstanceType,\n  amount,\n  onAmountChange,\n  className,\n  inlinePrompt,\n  showChevron,\n  autoFocus,\n  loading,\n  onFocusChange,\n}: Props) {\n  const inputId = useId();\n  const labelId = useId();\n  const customAlertId = useId();\n  const currencyId = useId();\n\n  return (\n    <div className={clsx('wds-expressive-money-input', className)}>\n      <Label id={labelId} htmlFor={inputId} className={clsx('m-b-1', 'font-weight-normal')}>\n        {label}\n      </Label>\n      <div\n        className={clsx('d-flex')}\n        role=\"group\"\n        aria-labelledby={labelId}\n        {...(inlinePrompt ? { 'aria-describedby': customAlertId } : {})}\n      >\n        <div className=\"wds-expressive-money-input-currency-selector\">\n          {currencySelector.customRender?.({ id: currencyId, labelId }) ?? (\n            <CurrencySelector\n              id={currencyId}\n              labelId={labelId}\n              currency={currency}\n              {...currencySelector}\n            />\n          )}\n        </div>\n        <AmountInput\n          id={inputId}\n          describedById={currencyId}\n          amount={amount}\n          currency={currency}\n          // eslint-disable-next-line jsx-a11y/no-autofocus\n          autoFocus={autoFocus}\n          loading={loading}\n          onChange={onAmountChange}\n          onFocusChange={onFocusChange}\n        />\n        <div className={clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron')}>\n          <Chevron shouldShow={Boolean(showChevron)} />\n        </div>\n      </div>\n      <AnimatePresence initial={false}>\n        {inlinePrompt && (\n          <div className={clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1')}>\n            <motion.div\n              key={customAlertId}\n              initial={{ opacity: 0, height: 0 }}\n              animate={{\n                opacity: 1,\n                height: 'auto',\n                transition: { delay: 0.75, duration: 0.3 },\n              }}\n              exit={{ opacity: 0, height: 0 }}\n            >\n              {inlinePrompt.sentiment && Object.keys(inlinePrompt.sentiment).length > 0 ? (\n                <InlinePrompt\n                  id={customAlertId}\n                  media={inlinePrompt.media}\n                  sentiment={inlinePrompt.sentiment}\n                >\n                  {inlinePrompt.message}\n                </InlinePrompt>\n              ) : (\n                <Body>{inlinePrompt.message}</Body>\n              )}\n            </motion.div>\n          </div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n"],"names":["ExpressiveMoneyInput","label","currency","currencySelector","options","amount","onAmountChange","className","inlinePrompt","showChevron","autoFocus","loading","onFocusChange","inputId","useId","labelId","customAlertId","currencyId","_jsxs","clsx","children","_jsx","Label","id","htmlFor","role","customRender","CurrencySelector","AmountInput","describedById","onChange","Chevron","shouldShow","Boolean","AnimatePresence","initial","motion","div","opacity","height","animate","transition","delay","duration","exit","sentiment","Object","keys","length","InlinePrompt","media","message","Body"],"mappings":";;;;;;;;;;;AAuEc,SAAUA,oBAAoBA,CAAC;EAC3CC,KAAK;EACLC,QAAQ;AACRC,EAAAA,gBAAgB,GAAG;AAAEC,IAAAA,OAAO,EAAE;GAA2C;EACzEC,MAAM;EACNC,cAAc;EACdC,SAAS;EACTC,YAAY;EACZC,WAAW;EACXC,SAAS;EACTC,OAAO;AACPC,EAAAA;AAAa,CACP,EAAA;AACN,EAAA,MAAMC,OAAO,GAAGC,KAAK,EAAE;AACvB,EAAA,MAAMC,OAAO,GAAGD,KAAK,EAAE;AACvB,EAAA,MAAME,aAAa,GAAGF,KAAK,EAAE;AAC7B,EAAA,MAAMG,UAAU,GAAGH,KAAK,EAAE;AAE1B,EAAA,oBACEI,IAAA,CAAA,KAAA,EAAA;AAAKX,IAAAA,SAAS,EAAEY,IAAI,CAAC,4BAA4B,EAAEZ,SAAS,CAAE;IAAAa,QAAA,EAAA,cAC5DC,GA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