{"version":3,"file":"Drawer.cjs","names":["getDefaultZIndex","factory","useProps","DrawerStackContext","DrawerRoot","DrawerOverlay","DrawerContent","DrawerHeader","DrawerTitle","DrawerCloseButton","DrawerBody","classes","DrawerStack"],"sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import { use, 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, DrawerStackContext } from './DrawerStack';\nimport { DrawerTitle } from './DrawerTitle';\nimport classes from './Drawer.module.css';\n\nexport type DrawerStylesNames = DrawerRootStylesNames;\nexport type DrawerCssVariables = DrawerRootCssVariables;\n\nexport interface DrawerProps extends DrawerRootProps {\n  /** Drawer title */\n  title?: React.ReactNode;\n\n  /** If set, the overlay is displayed @default true */\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  /** If set, the close button is displayed @default true */\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 = {\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} satisfies Partial<DrawerProps>;\n\nexport const Drawer = factory<DrawerFactory>((_props) => {\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 = use(DrawerStackContext);\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      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.classes = classes;\nDrawer.displayName = '@mantine/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"],"mappings":";;;;;;;;;;;;;;;;;AA6DA,MAAM,eAAe;CACnB,qBAAqB;CACrB,cAAc;CACd,YAAY;CACZ,WAAW;CACX,aAAa;CACb,eAAe;CACf,aAAa;CACb,QAAQA,4BAAAA,iBAAiB,QAAQ;CACjC,aAAa;CACb,iBAAiB;CAClB;AAED,MAAa,SAASC,gBAAAA,SAAwB,WAAW;CACvD,MAAM,EACJ,OACA,aACA,cACA,iBACA,kBACA,UACA,QACA,SACA,QACA,GAAG,WACDC,kBAAAA,SAAS,UAAU,cAAc,OAAO;CAE5C,MAAM,OAAA,GAAA,MAAA,KAAUC,oBAAAA,mBAAmB;CACnC,MAAM,YAAY,CAAC,CAAC,SAAS;CAC7B,MAAM,aACJ,OAAO,UACH;EACE,eAAe,IAAI,cAAc;EACjC,WAAW,IAAI,cAAc;EAC7B,QAAQ,IAAI,UAAU,QAAQ;EAC/B,GACD,EAAE;CAER,MAAM,iBACJ,gBAAgB,QAAQ,QAAQ,WAAW,MAAM,IAAI,cAAc,UAAU;AAE/E,EAAA,GAAA,MAAA,iBAAgB;AACd,MAAI,OAAO,QACT,UACI,IAAI,SAAS,SAAS,UAAUH,4BAAAA,iBAAiB,QAAQ,CAAC,GAC1D,IAAI,YAAY,QAAQ;IAE7B;EAAC;EAAQ;EAAS;EAAO,CAAC;AAE7B,QACE,iBAAA,GAAA,kBAAA,MAACI,mBAAAA,YAAD;EACU;EACR,QAAQ,OAAO,UAAU,IAAI,UAAU,QAAQ,GAAG;EAClD,GAAI;EACJ,GAAI;YAJN,CAMG,eACC,iBAAA,GAAA,kBAAA,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