{"version":3,"file":"InstructionsList.mjs","sources":["../../src/instructionsList/InstructionsList.tsx"],"sourcesContent":["import { CrossCircleFill as DontIcon, CheckCircleFill as DoIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport { ReactNode } from 'react';\n\nimport Body from '../body/Body';\nimport { Typography, CommonProps } from '../common';\n\ntype InstructionNode = {\n  content: ReactNode;\n  ['aria-label']: string;\n};\n\nexport type InstructionsListProps = CommonProps &\n  (\n    | {\n        dos?: readonly ReactNode[];\n        donts?: readonly ReactNode[];\n        sort?: 'dosFirst' | 'dontsFirst';\n      }\n    | {\n        dos?: readonly InstructionNode[];\n        donts?: readonly InstructionNode[];\n        sort?: 'dosFirst' | 'dontsFirst';\n      }\n  );\n\nconst InstructionsList = ({ className, dos, donts, sort = 'dosFirst' }: InstructionsListProps) => {\n  const dosInstructions =\n    dos?.map((doThis, index) => (\n      // eslint-disable-next-line react/no-array-index-key\n      <Instruction key={index} item={doThis} type=\"do\" />\n    )) ?? null;\n\n  const dontsInstructions =\n    donts?.map((dont, index) => (\n      // eslint-disable-next-line react/no-array-index-key\n      <Instruction key={index} item={dont} type=\"dont\" />\n    )) ?? null;\n\n  const orderedInstructions =\n    sort === 'dosFirst' ? (\n      <>\n        {dosInstructions}\n        {dontsInstructions}\n      </>\n    ) : (\n      <>\n        {dontsInstructions}\n        {dosInstructions}\n      </>\n    );\n\n  return <ul className={clsx('tw-instructions', className)}>{orderedInstructions}</ul>;\n};\n\nfunction Instruction({ item, type }: { item: ReactNode | InstructionNode; type: 'do' | 'dont' }) {\n  const isInstructionNode =\n    typeof item === 'object' && item !== null && 'content' in item && 'aria-label' in item;\n  return (\n    <li className=\"instruction\">\n      {type === 'do' ? (\n        <DoIcon\n          size={24}\n          className={type}\n          title={isInstructionNode ? item['aria-label'] : undefined}\n        />\n      ) : (\n        <DontIcon\n          size={24}\n          className={type}\n          title={isInstructionNode ? item['aria-label'] : undefined}\n        />\n      )}\n      <Body className=\"text-primary\" type={Typography.BODY_LARGE} preserveNewlines>\n        {isInstructionNode ? item.content : item}\n      </Body>\n    </li>\n  );\n}\n\nexport default InstructionsList;\n"],"names":["InstructionsList","className","dos","donts","sort","dosInstructions","map","doThis","index","_jsx","Instruction","item","type","dontsInstructions","dont","orderedInstructions","_jsxs","_Fragment","children","clsx","isInstructionNode","DoIcon","size","title","undefined","DontIcon","Body","Typography","BODY_LARGE","preserveNewlines","content"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAMA,gBAAgB,GAAGA,CAAC;EAAEC,SAAS;EAAEC,GAAG;EAAEC,KAAK;AAAEC,EAAAA,IAAI,GAAG;AAAU,CAAyB,KAAI;EAC/F,MAAMC,eAAe,GACnBH,GAAG,EAAEI,GAAG,CAAC,CAACC,MAAM,EAAEC,KAAK;AAAA;AACrB;AACAC,EAAAA,GAAA,CAACC,WAAW,EAAA;AAAaC,IAAAA,IAAI,EAAEJ,MAAO;AAACK,IAAAA,IAAI,EAAC;AAAI,GAAA,EAA9BJ,MACnB,CAAC,IAAI,IAAI;EAEZ,MAAMK,iBAAiB,GACrBV,KAAK,EAAEG,GAAG,CAAC,CAACQ,IAAI,EAAEN,KAAK;AAAA;AACrB;AACAC,EAAAA,GAAA,CAACC,WAAW,EAAA;AAAaC,IAAAA,IAAI,EAAEG,IAAK;AAACF,IAAAA,IAAI,EAAC;AAAM,GAAA,EAA9BJ,MACnB,CAAC,IAAI,IAAI;EAEZ,MAAMO,mBAAmB,GACvBX,IAAI,KAAK,UAAU,gBACjBY,IAAA,CAAAC,QAAA,EAAA;IAAAC,QAAA,EAAA,CACGb,eAAe,EACfQ,iBAAiB;AAAA,GACpB,CAAG,gBAEHG,IAAA,CAAAC,QAAA,EAAA;IAAAC,QAAA,EAAA,CACGL,iBAAiB,EACjBR,eAAe;AAAA,GAClB,CACD;AAEH,EAAA,oBAAOI,GAAA,CAAA,IAAA,EAAA;AAAIR,IAAAA,SAAS,EAAEkB,IAAI,CAAC,iBAAiB,EAAElB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