{"version":3,"file":"Drawer.cjs","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { factory, Factory, getDefaultZIndex, useProps } from '../../core';\nimport { ModalBaseCloseButtonProps, ModalBaseOverlayProps } from '../ModalBase';\nimport { DrawerBody } from './DrawerBody';\nimport { DrawerCloseButton } from './DrawerCloseButton';\nimport { DrawerContent } from './DrawerContent';\nimport { DrawerHeader } from './DrawerHeader';\nimport { DrawerOverlay } from './DrawerOverlay';\nimport {\n  DrawerRoot,\n  DrawerRootCssVariables,\n  DrawerRootProps,\n  DrawerRootStylesNames,\n} from './DrawerRoot';\nimport { DrawerStack, useDrawerStackContext } from './DrawerStack';\nimport { DrawerTitle } from './DrawerTitle';\n\nexport type DrawerStylesNames = DrawerRootStylesNames;\nexport type DrawerCssVariables = DrawerRootCssVariables;\n\nexport interface DrawerProps extends DrawerRootProps {\n  /** Drawer title */\n  title?: React.ReactNode;\n\n  /** Determines whether the overlay should be rendered, `true` by default */\n  withOverlay?: boolean;\n\n  /** Props passed down to the `Overlay` component, can be used to configure opacity, `background-color`, styles and other properties */\n  overlayProps?: ModalBaseOverlayProps;\n\n  /** Drawer content */\n  children?: React.ReactNode;\n\n  /** Determines whether the close button should be rendered, `true` by default */\n  withCloseButton?: boolean;\n\n  /** Props passed down to the close button */\n  closeButtonProps?: ModalBaseCloseButtonProps;\n\n  /** Id of the drawer in the `Drawer.Stack` */\n  stackId?: string;\n}\n\nexport type DrawerFactory = Factory<{\n  props: DrawerProps;\n  ref: HTMLDivElement;\n  stylesNames: DrawerStylesNames;\n  vars: DrawerCssVariables;\n  staticComponents: {\n    Root: typeof DrawerRoot;\n    Overlay: typeof DrawerOverlay;\n    Content: typeof DrawerContent;\n    Body: typeof DrawerBody;\n    Header: typeof DrawerHeader;\n    Title: typeof DrawerTitle;\n    CloseButton: typeof DrawerCloseButton;\n    Stack: typeof DrawerStack;\n  };\n}>;\n\nconst defaultProps: Partial<DrawerProps> = {\n  closeOnClickOutside: true,\n  withinPortal: true,\n  lockScroll: true,\n  trapFocus: true,\n  returnFocus: true,\n  closeOnEscape: true,\n  keepMounted: false,\n  zIndex: getDefaultZIndex('modal'),\n  withOverlay: true,\n  withCloseButton: true,\n};\n\nexport const Drawer = factory<DrawerFactory>((_props, ref) => {\n  const {\n    title,\n    withOverlay,\n    overlayProps,\n    withCloseButton,\n    closeButtonProps,\n    children,\n    opened,\n    stackId,\n    zIndex,\n    ...others\n  } = useProps('Drawer', defaultProps, _props);\n\n  const ctx = useDrawerStackContext();\n  const hasHeader = !!title || withCloseButton;\n  const stackProps =\n    ctx && stackId\n      ? {\n          closeOnEscape: ctx.currentId === stackId,\n          trapFocus: ctx.currentId === stackId,\n          zIndex: ctx.getZIndex(stackId),\n        }\n      : {};\n\n  const overlayVisible =\n    withOverlay === false ? false : stackId && ctx ? ctx.currentId === stackId : opened;\n\n  useEffect(() => {\n    if (ctx && stackId) {\n      opened\n        ? ctx.addModal(stackId, zIndex || getDefaultZIndex('modal'))\n        : ctx.removeModal(stackId);\n    }\n  }, [opened, stackId, zIndex]);\n\n  return (\n    <DrawerRoot\n      ref={ref}\n      opened={opened}\n      zIndex={ctx && stackId ? ctx.getZIndex(stackId) : zIndex}\n      {...others}\n      {...stackProps}\n    >\n      {withOverlay && (\n        <DrawerOverlay\n          visible={overlayVisible}\n          transitionProps={ctx && stackId ? { duration: 0 } : undefined}\n          {...overlayProps}\n        />\n      )}\n      <DrawerContent __hidden={ctx && stackId && opened ? stackId !== ctx.currentId : false}>\n        {hasHeader && (\n          <DrawerHeader>\n            {title && <DrawerTitle>{title}</DrawerTitle>}\n            {withCloseButton && <DrawerCloseButton {...closeButtonProps} />}\n          </DrawerHeader>\n        )}\n\n        <DrawerBody>{children}</DrawerBody>\n      </DrawerContent>\n    </DrawerRoot>\n  );\n});\n\nDrawer.displayName = '@raikou/core/Drawer';\nDrawer.Root = DrawerRoot;\nDrawer.Overlay = DrawerOverlay;\nDrawer.Content = DrawerContent;\nDrawer.Body = DrawerBody;\nDrawer.Header = DrawerHeader;\nDrawer.Title = DrawerTitle;\nDrawer.CloseButton = DrawerCloseButton;\nDrawer.Stack = DrawerStack;\n"],"names":["getDefaultZIndex","factory","useProps","useDrawerStackContext","useEffect","jsxs","DrawerRoot","jsx","DrawerOverlay","DrawerContent","DrawerHeader","DrawerTitle","DrawerCloseButton","DrawerBody","DrawerStack"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4DA,MAAM,YAAqC,GAAA;AAAA,EACzC,mBAAqB,EAAA,IAAA;AAAA,EACrB,YAAc,EAAA,IAAA;AAAA,EACd,UAAY,EAAA,IAAA;AAAA,EACZ,SAAW,EAAA,IAAA;AAAA,EACX,WAAa,EAAA,IAAA;AAAA,EACb,aAAe,EAAA,IAAA;AAAA,EACf,WAAa,EAAA,KAAA;AAAA,EACb,MAAA,EAAQA,kCAAiB,OAAO,CAAA;AAAA,EAChC,WAAa,EAAA,IAAA;AAAA,EACb,eAAiB,EAAA;AACnB,CAAA;AAEO,MAAM,MAAS,GAAAC,eAAA,CAAuB,CAAC,MAAA,EAAQ,GAAQ,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,KAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,eAAA;AAAA,IACA,gBAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAG;AAAA,GACD,GAAAC,iBAAA,CAAS,QAAU,EAAA,YAAA,EAAc,MAAM,CAAA;AAE3C,EAAA,MAAM,MAAMC,iCAAsB,EAAA;AAClC,EAAM,MAAA,SAAA,GAAY,CAAC,CAAC,KAAS,IAAA,eAAA;AAC7B,EAAM,MAAA,UAAA,GACJ,OAAO,OACH,GAAA;AAAA,IACE,aAAA,EAAe,IAAI,SAAc,KAAA,OAAA;AAAA,IACjC,SAAA,EAAW,IAAI,SAAc,KAAA,OAAA;AAAA,IAC7B,MAAA,EAAQ,GAAI,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