Components

Portal

Utility component to render children elsewhere in the DOM tree

Overview

Portal is a utility component that wraps React's createPortal. Used internally by overlay components such as Dialog, Toast, and ContextMenu.

  • SSR Safe — Checks typeof document for safe server-side rendering
  • Customizable — Change the target DOM node with the container prop
  • Null safe — Returns null when there are no children

Basic Usage

import { Portal } from '@illog/ui'
 
// Without container, Portal renders into document.body
export function FloatingPanel() {
  return (
    <Portal>
      <div className="floating-panel">This content is rendered in document.body.</div>
    </Portal>
  )
}

Custom Container

Props

PropTypeDefaultRequiredDescription
containerElement | DocumentFragment'document.body'NoWhere to render the children
childrenReactNode-NoContent to move

Guidelines

  • Typically used indirectly through Dialog, Toast, ContextMenu, etc., rather than directly
  • Use a custom container when you need to resolve z-index conflicts