{"version":3,"file":"Drawer.mjs","sources":["../../src/drawer/Drawer.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { HTMLAttributes, useContext, useId } from 'react';\n\nimport { Position, Typography } from '../common';\nimport { useLayout } from '../common/hooks';\nimport Dimmer from '../dimmer';\nimport { OverlayIdContext } from '../provider/overlay/OverlayIdProvider';\nimport SlidingPanel from '../slidingPanel';\nimport Title from '../title';\nimport { logActionRequiredIf } from '../utilities';\nimport IconButton from '../iconButton';\nimport closeBtnMessages from '../common/closeButton/CloseButton.messages';\nimport { useIntl } from 'react-intl';\nimport { Cross } from '@transferwise/icons';\n\nexport type DrawerProps = {\n  /** The content to appear in the drawer body. */\n  children?: React.ReactNode;\n  className?: string;\n  /** The content to appear in the drawer footer. */\n  footerContent?: React.ReactNode;\n  /** The content to appear in the drawer header. */\n  headerTitle?: React.ReactNode;\n  /**\n   * The status of Drawer either open or not.\n   * @default false\n   */\n  open?: boolean;\n  /**\n   * The placement of Drawer on the screen either left or right. On mobile it will default to bottom.\n   * @default 'right'\n   */\n  position?: `${Position.LEFT | Position.RIGHT | Position.BOTTOM}`;\n  /** The action to perform on close click. */\n  onClose?: (event: KeyboardEvent | React.MouseEvent) => void;\n  onUnmount?: () => void;\n} & Pick<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'>;\n\nexport default function Drawer({\n  children,\n  className,\n  footerContent,\n  headerTitle,\n  onClose,\n  onUnmount,\n  open = false,\n  position = 'right',\n  role = 'dialog',\n  'aria-labelledby': ariaLabelledBy,\n}: DrawerProps) {\n  const intl = useIntl();\n  logActionRequiredIf(\n    'Drawer now expects `onClose`, and will soon make this prop required. Please update your usage to provide it.',\n    !onClose,\n  );\n\n  const { isMobile } = useLayout();\n  const titleId = useId();\n\n  const overlayId = useContext(OverlayIdContext);\n\n  return (\n    <Dimmer open={open} onClose={onClose} onExited={onUnmount}>\n      <SlidingPanel open={open} position={isMobile ? Position.BOTTOM : position}>\n        <div\n          id={overlayId}\n          role={role}\n          aria-modal\n          aria-labelledby={ariaLabelledBy || (headerTitle ? titleId : undefined)}\n          className={clsx('np-drawer', className)}\n        >\n          <div\n            className={clsx(\n              'np-drawer-header',\n              'd-flex',\n              'align-items-center',\n              headerTitle ? 'justify-content-between' : 'justify-content-end',\n              'flex-wrap',\n            )}\n          >\n            {headerTitle && (\n              <Title id={titleId} type={Typography.TITLE_SUBSECTION} className=\"np-drawer-title\">\n                {headerTitle}\n              </Title>\n            )}\n            <IconButton\n              size={40}\n              priority=\"tertiary\"\n              aria-label={intl.formatMessage(closeBtnMessages.ariaLabel)}\n              onClick={onClose}\n            >\n              <Cross />\n            </IconButton>\n          </div>\n          {children && <div className={clsx('np-drawer-content')}>{children}</div>}\n          {footerContent ? (\n            <div className={clsx('np-drawer-footer')}>{footerContent}</div>\n          ) : (\n            <div className=\"m-t-3\" />\n          )}\n        </div>\n      </SlidingPanel>\n    </Dimmer>\n  );\n}\n"],"names":["Drawer","children","className","footerContent","headerTitle","onClose","onUnmount","open","position","role","ariaLabelledBy","intl","useIntl","logActionRequiredIf","isMobile","useLayout","titleId","useId","overlayId","useContext","OverlayIdContext","_jsx","Dimmer","onExited","SlidingPanel","Position","BOTTOM","_jsxs","id","undefined","clsx","Title","type","Typography","TITLE_SUBSECTION","IconButton","size","priority","formatMessage","closeBtnMessages","ariaLabel","onClick","Cross"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCc,SAAUA,MAAMA,CAAC;EAC7BC,QAAQ;EACRC,SAAS;EACTC,aAAa;EACbC,WAAW;EACXC,OAAO;EACPC,SAAS;AACTC,EAAAA,IAAI,GAAG,KAAK;AACZC,EAAAA,QAAQ,GAAG,OAAO;AAClBC,EAAAA,IAAI,GAAG,QAAQ;AACf,EAAA,iBAAiB,EAAEC;AAAc,CACrB,EAAA;AACZ,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AACtBC,EAAAA,mBAAmB,CACjB,8GAA8G,EAC9G,CAACR,OAAO,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