{"version":3,"file":"ModalBase.cjs","sources":["../../../src/components/ModalBase/ModalBase.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport {\n  Box,\n  BoxProps,\n  ElementProps,\n  getDefaultZIndex,\n  getShadow,\n  getSpacing,\n  RaikouShadow,\n  RaikouSize,\n  RaikouSpacing,\n} from '../../core';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport { TransitionOverride } from '../Transition';\nimport { ModalBaseProvider } from './ModalBase.context';\nimport { useModal } from './use-modal';\n\ntype RemoveScrollProps = Omit<React.ComponentProps<typeof RemoveScroll>, 'children'>;\n\nexport interface ModalBaseProps extends BoxProps, ElementProps<'div', 'title'> {\n  unstyled?: boolean;\n\n  /** If set modal/drawer will not be unmounted from the DOM when it is hidden, `display: none` styles will be added instead, `false` by default */\n  keepMounted?: boolean;\n\n  /** Determines whether modal/drawer is opened */\n  opened: boolean;\n\n  /** Called when modal/drawer is closed */\n  onClose: () => void;\n\n  /** Id used to connect modal/drawer with body and title */\n  id?: string;\n\n  /** Determines whether scroll should be locked when `opened={true}`, `true` by default */\n  lockScroll?: boolean;\n\n  /** Determines whether focus should be trapped, `true` by default */\n  trapFocus?: boolean;\n\n  /** Determines whether the component should be rendered inside `Portal`, `true` by default */\n  withinPortal?: boolean;\n\n  /** Props passed down to the Portal component when `withinPortal` is set */\n  portalProps?: Omit<PortalProps, 'children'>;\n\n  /** Modal/drawer content */\n  children?: React.ReactNode;\n\n  /** Determines whether the modal/drawer should be closed when user clicks on the overlay, `true` by default */\n  closeOnClickOutside?: boolean;\n\n  /** Props added to the `Transition` component that used to animate overlay and body, use to configure duration and animation type, `{ duration: 200, transition: 'pop' }` by default */\n  transitionProps?: TransitionOverride;\n\n  /** Called when exit transition ends */\n  onExitTransitionEnd?: () => void;\n\n  /** Called when enter transition ends */\n  onEnterTransitionEnd?: () => void;\n\n  /** Determines whether `onClose` should be called when user presses the escape key, `true` by default */\n  closeOnEscape?: boolean;\n\n  /** Determines whether focus should be returned to the last active element when `onClose` is called, `true` by default */\n  returnFocus?: boolean;\n\n  /** `z-index` CSS property of the root element, `200` by default */\n  zIndex?: string | number;\n\n  /** Key of `theme.shadows` or any valid CSS box-shadow value, 'xl' by default */\n  shadow?: RaikouShadow;\n\n  /** Key of `theme.spacing` or any valid CSS value to set content, header and footer padding, `'md'` by default */\n  padding?: RaikouSpacing;\n\n  /** Controls width of the content area, `'md'` by default */\n  size?: RaikouSize | (string & {}) | number;\n\n  /** Props passed down to react-remove-scroll, can be used to customize scroll lock behavior */\n  removeScrollProps?: RemoveScrollProps;\n}\n\nexport const ModalBase = forwardRef<HTMLDivElement, ModalBaseProps>(\n  (\n    {\n      keepMounted,\n      opened,\n      onClose,\n      id,\n      transitionProps,\n      onExitTransitionEnd,\n      onEnterTransitionEnd,\n      trapFocus,\n      closeOnEscape,\n      returnFocus,\n      closeOnClickOutside,\n      withinPortal,\n      portalProps,\n      lockScroll,\n      children,\n      zIndex,\n      shadow,\n      padding,\n      __vars,\n      unstyled,\n      removeScrollProps,\n      ...others\n    },\n    ref\n  ) => {\n    const { _id, titleMounted, bodyMounted, shouldLockScroll, setTitleMounted, setBodyMounted } =\n      useModal({ id, transitionProps, opened, trapFocus, closeOnEscape, onClose, returnFocus });\n\n    const { key: removeScrollKey, ...otherRemoveScrollProps } = removeScrollProps || {};\n\n    return (\n      <OptionalPortal {...portalProps} withinPortal={withinPortal}>\n        <ModalBaseProvider\n          value={{\n            opened,\n            onClose,\n            closeOnClickOutside,\n            onExitTransitionEnd,\n            onEnterTransitionEnd,\n            transitionProps: { ...transitionProps, keepMounted },\n            getTitleId: () => `${_id}-title`,\n            getBodyId: () => `${_id}-body`,\n            titleMounted,\n            bodyMounted,\n            setTitleMounted,\n            setBodyMounted,\n            trapFocus,\n            closeOnEscape,\n            zIndex,\n            unstyled,\n          }}\n        >\n          <RemoveScroll\n            enabled={shouldLockScroll && lockScroll}\n            key={removeScrollKey}\n            {...otherRemoveScrollProps}\n          >\n            <Box\n              ref={ref}\n              {...others}\n              __vars={{\n                ...__vars,\n                '--mb-z-index': (zIndex || getDefaultZIndex('modal')).toString(),\n                '--mb-shadow': getShadow(shadow),\n                '--mb-padding': getSpacing(padding),\n              }}\n            >\n              {children}\n            </Box>\n          </RemoveScroll>\n        </ModalBaseProvider>\n      </OptionalPortal>\n    );\n  }\n);\n\nModalBase.displayName = '@raikou/core/ModalBase';\n"],"names":["forwardRef","useModal","jsx","OptionalPortal","ModalBaseProvider","RemoveScroll","Box","getDefaultZIndex","getShadow","getSpacing"],"mappings":";;;;;;;;;;;;;;;;;AAoFO,MAAM,SAAY,GAAAA,gBAAA;AAAA,EACvB,CACE;AAAA,IACE,WAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,EAAA;AAAA,IACA,eAAA;AAAA,IACA,mBAAA;AAAA,IACA,oBAAA;AAAA,IACA,SAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAA;AAAA,IACA,mBAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,UAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,iBAAA;AAAA,IACA,GAAG;AAAA,KAEL,GACG,KAAA;AACH,IAAA,MAAM,EAAE,GAAK,EAAA,YAAA,EAAc,WAAa,EAAA,gBAAA,EAAkB,iBAAiB,cAAe,EAAA,GACxFC,iBAAS,CAAA,EAAE,IAAI,eAAiB,EAAA,MAAA,EAAQ,WAAW,aAAe,EAAA,OAAA,EAAS,aAAa,CAAA;AAE1F,IAAA,MAAM,EAAE,GAAK,EAAA,eAAA,EAAiB,GAAG,sBAAuB,EAAA,GAAI,qBAAqB,EAAC;AAElF,IAAA,uBACGC,cAAA,CAAAC,6BAAA,EAAA,EAAgB,GAAG,WAAA,EAAa,YAC/B,EAAA,QAAA,kBAAAD,cAAA;AAAA,MAACE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