• Docs
  • Blog
    • 0.25.1

    • light

      dark

      system

      Switch mode
    • Cerberus

      Acheron

      Elysium

    Get Started
    Components
    Styling
    Theming

    Concepts

    OverviewCompositionTesting

    Layout

    Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

    Components

    AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

    Utilities

    Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

    Portal

    Portal displays content in outside of the DOM hierarchy.

    • npm
    • source
    import { Portal } from '@cerberus/react'

    Usage

    Copy
    nav.tsx
    'use client'
    import { Close } from '@carbon/icons-react'
    import { Button, IconButton, Portal, Show } from '@cerberus/react'
    import { hstack } from 'styled-system/patterns'
    import { useState } from 'react'
    function PortalPreview() {
    const [showPortal, setShowPortal] = useState<boolean>(false)
    function handleShowPortal() {
    setShowPortal(true)
    }
    function handleClosePortal() {
    setShowPortal(false)
    }
    return (
    <>
    <Button onClick={handleShowPortal}>Show Portal</Button>
    <Show when={showPortal}>
    <Portal>
    <div
    className={hstack({
    backgroundColor: 'info.surface.initial',
    color: 'info.text.initial',
    justify: 'space-between',
    left: 0,
    mxi: '4',
    p: '4',
    position: 'absolute',
    right: 0,
    rounded: 'md',
    shadow: 'md',
    top: '4',
    zIndex: 'toast',
    })}
    >
    <p>
    This is a portal element that is outside of the DOM hierarchy of
    the parent component.
    </p>
    <IconButton
    ariaLabel="Close Portal"
    onClick={handleClosePortal}
    tooltipPosition="bottom"
    >
    <Close />
    </IconButton>
    </div>
    </Portal>
    </Show>
    </>
    )
    }

    API

    export interface PortalProps {
    container?: RefObject<HTMLElement>;
    disabled?: boolean;
    }
    define function Portal(props: PropsWithChildren<PortalProps>): ReactPortal | null

    Props

    The Portal component accepts the following props:

    NameDefaultDescription
    containerdocument.bodyThe mounted element to place the children contents within.
    disabledfalseDisables the portal from rendering. Perfect for when you need to disabled a child Portal that is rendered within another Portal.

    On this page

    • Edit this page on Github
    Cerberus Design System | Docs