UNPKG

@winglet/react-utils

Version:

React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality

49 lines (48 loc) 1.74 kB
import type { PropsWithChildren } from 'react'; import { Anchor } from './Anchor'; import { Portal as BasePortal } from './Portal'; import { withPortal } from './withPortal'; export type { Anchor, BasePortal, withPortal }; /** * Portal system for rendering React components at different DOM locations while maintaining component hierarchy. * * Provides a complete portal solution including the main Portal component, DOM anchor placement, * and Higher-Order Component wrapper for context provision. This system allows breaking out of * CSS containment and z-index stacking contexts while preserving React's component tree structure. * * ### Usage Patterns * * **Compound Object Pattern (Recommended for convenience):** * ```typescript * import { Portal } from '@winglet/react-utils/portal'; * * const App = Portal.with(() => ( * <div> * <Portal> * <Header /> // Header is rendered at Portal.Anchor location * </Portal> * <Portal.Anchor /> * </div> * )); * ``` * * * ### Component References * * For detailed documentation with comprehensive examples and API details: * - **Portal main component**: See {@link BasePortal} export * - **Portal.with HOC**: See {@link withPortal} export * - **Portal.Anchor component**: See {@link Anchor} export * * ### Design Philosophy * * This dual-export approach provides both convenience and flexibility: * - Use `Portal.*` for quick prototyping and compact code * - Use individual imports when you need detailed documentation or tree-shaking * - All approaches provide identical functionality and type safety */ export declare const Portal: { (props: PropsWithChildren): null; with: typeof withPortal; Anchor: typeof Anchor; };