UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.29 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"],"mappings":";;;;;;AAoBA,MAAa,iBAAiB,SAC3B,EAAE,eAAe,MAAM,UAAU,GAAG,aAAa;AAGhD,KAFY,eAAe,KAEf,UAAU,CAAC,aACrB,QAAO,oBAAA,UAAA,EAAG,UAAY,CAAA;AAGxB,QAAO,oBAAC,QAAD;EAAQ,GAAI;EAAS;EAAkB,CAAA;EAEjD;AAED,eAAe,cAAc"}