@itwin/itwinui-react
Version:
A react component library for iTwinUI
34 lines (33 loc) • 1.45 kB
TypeScript
import * as React from 'react';
export declare const PortalContainerContext: React.Context<HTMLElement | null>;
export type PortalProps = {
/**
* Where should the element be portaled to?
*
* If true, it will portal into nearest ThemeProvider's portalContainer.
*
* If false, it will not be portaled.
*
* Otherwise, it will portal to the element passed to `to`.
*
* If `to`/`to()` === `null`/`undefined`, the default behavior will be used (i.e. as if `portal` is not passed).
*
* @default true
*/
portal?: boolean | {
to: HTMLElement | null | undefined | (() => HTMLElement | null | undefined);
};
};
/**
* Helper component that portals children according to the following conditions:
* - renders null on server
* - if `portal` is set to true, renders into the element provided by PortalContainerContext.
* - if `portal` is set to false, renders as-is without portal.
* - otherwise renders into `portal.to` (can be an element or a function)
* - If `to`/`to()` === `null`/`undefined`, the default behavior will be used (i.e. as if `portal` is not passed).
* - E.g. `portal={{ to: () => document.querySelector('.may-not-exist') }}`.
*
* @private
*/
export declare const Portal: (props: React.PropsWithChildren<PortalProps>) => React.ReactNode;
export declare const usePortalTo: (portal: NonNullable<PortalProps["portal"]>) => HTMLElement | null;