UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.38 kB
{"version":3,"file":"OptionalPortal.mjs","names":[],"sources":["../../../src/components/Portal/OptionalPortal.tsx"],"sourcesContent":["import { factory, Factory, useMantineEnv } from '../../core';\nimport { Portal, PortalProps } from './Portal';\n\nexport interface OptionalPortalProps extends PortalProps {\n /**\n * Determines whether children should be rendered inside Portal.\n * When false, children are rendered as regular React children.\n *\n * Note: In test environment, Portal is always disabled regardless of this value.\n *\n * @default true\n */\n withinPortal?: boolean;\n}\n\nexport type OptionalPortalFactory = Factory<{\n props: OptionalPortalProps;\n ref: HTMLDivElement;\n}>;\n\nexport const OptionalPortal = factory<OptionalPortalFactory>(\n ({ withinPortal = true, children, ...others }) => {\n const env = useMantineEnv();\n\n if (env === 'test' || !withinPortal) {\n return <>{children}</>;\n }\n\n return <Portal {...others}>{children}</Portal>;\n }\n);\n\nOptionalPortal.displayName = '@mantine/core/OptionalPortal';\n\nexport namespace OptionalPortal {\n export type Props = OptionalPortalProps;\n}\n"],"mappings":";;;;;;AAoBA,MAAa,iBAAiB,SAC3B,EAAE,eAAe,MAAM,UAAU,GAAG,aAAa;CAGhD,IAFY,cAEN,MAAM,UAAU,CAAC,cACrB,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAGvB,OAAO,oBAAC,QAAD;EAAQ,GAAI;EAAS;CAAiB,CAAA;AAC/C,CACF;AAEA,eAAe,cAAc"}