Modal dialog overlay for focused interactions
import {Modal} from "@peakui/react" ;
import {Button, Modal} from "@peakui/react" ;
export default () => (
< Modal >
< Button >Open modal</ Button >
< Modal.Backdrop >
< Modal.Container >
< Modal.Dialog >
< Modal.CloseTrigger /> { /* Optional: close button */ }
< Modal.Header >
< Modal.Icon /> { /* Optional: icon */ }
< Modal.Heading />
</ Modal.Header >
< Modal.Body />
< Modal.Footer />
</ Modal.Dialog >
</ Modal.Container >
</ Modal.Backdrop >
</ Modal >
);
@layer components {
.modal__backdrop {
@apply bg-linear-to-br from-black/50 to-black/70;
}
.modal__dialog {
@apply rounded-2xl border border-white/10 shadow-2xl;
}
.modal__header {
@apply text-center;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The Modal component uses these CSS classes (view source styles ):
.modal__trigger - Trigger element that opens the modal
.modal__backdrop - Overlay backdrop behind the modal
.modal__container - Positioning wrapper with placement support
.modal__dialog - Modal content container
.modal__header - Header section for titles and icons
.modal__heading - Heading element styles
.modal__icon - Optional icon indicator
.modal__body - Main content area
.modal__footer - Footer section for actions
.modal__close-trigger - Close button position styles
.modal__backdrop--opaque - Opaque dimmed backdrop (default)
.modal__backdrop--blur - Blurred backdrop
.modal__backdrop--transparent - Transparent backdrop
.modal__dialog--scroll-inside - Constrains the dialog for body scrolling
.modal__dialog--scroll-outside - Lets the backdrop scroll the dialog
.modal__container--scroll-outside - Moves scrolling to the backdrop
.modal__body--scroll-inside - Makes only the body scrollable
.modal__body--scroll-outside - Allows full-page scrolling
.modal__dialog--xs
.modal__dialog--sm
.modal__dialog--md
.modal__dialog--lg
.modal__dialog--cover - Full screen with margins
.modal__container--full - Fullscreen container without padding
.modal__dialog--full - Fullscreen dialog without radius or shadow
[data-slot="modal-trigger"] - The Modal.Trigger element
[data-slot="modal-backdrop"] - The Modal.Backdrop overlay
[data-slot="modal-container"] - The Modal.Container positioning wrapper
[data-slot="modal-dialog"] - The Modal.Dialog element
[data-slot="modal-header"] - The Modal.Header element
[data-slot="modal-icon"] - The Modal.Icon element
[data-slot="modal-heading"] - The Modal.Heading element
[data-slot="modal-body"] - The Modal.Body element
[data-slot="modal-footer"] - The Modal.Footer element
[data-slot="modal-close-trigger"] - The Modal.CloseTrigger element; it renames CloseButton's slot through the typed data-slot prop
The overlay parts carry React Aria animation states:
Entering : [data-entering="true"]
Exiting : [data-exiting="true"]
Placement : [data-placement="auto | top | center | bottom"] on container and dialog
The trigger supports both pseudo-classes and data attributes:
Focus : :focus-visible or [data-focus-visible="true"]
Disabled : :disabled or [aria-disabled="true"]
Pressed : :active or [data-pressed="true"]
Prop Type Default Description childrenReact.ReactNode- The trigger element followed by the overlay stateUseOverlayStateReturn- Overlay state from useOverlayState() ...restDialogTriggerProps- React Aria DialogTrigger attributes
Prop Type Default Description childrenReact.ReactNode- Non-interactive element to make pressable classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div>; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description variant"opaque" | "blur" | "transparent""opaque"Backdrop overlay style isDismissablebooleantrueClose on backdrop interaction isKeyboardDismissDisabledbooleanfalseDisable the Escape key isOpenboolean- Controlled open state defaultOpenbooleanfalseInitially open, without controlling onOpenChange(isOpen: boolean) => void- Open state change handler UNSTABLE_portalContainerHTMLElement- Custom portal container classNamestring | ((renderProps) => string)- Additional classes, or a function of the state ...restModalOverlayProps- React Aria ModalOverlay attributes
Prop Type Default Description placement"auto" | "top" | "center" | "bottom""auto"Position on screen scroll"inside" | "outside""inside"Scroll behavior size"xs" | "sm" | "md" | "lg" | "cover" | "full""md"Size variant classNamestring | ((renderProps) => string)- Additional classes, or a function of the state ...restModalProps- React Aria Modal attributes
Prop Type Default Description childrenReact.ReactNode | (({close}) => React.ReactNode)- Content, or a function receiving close role"dialog" | "alertdialog""dialog"ARIA role aria-labelstring- Accessible name when no Modal.Heading is present aria-labelledbystring- ID of the labelling element; set from Modal.Heading aria-describedbystring- ID of the describing element classNamestring- Additional classes ...restDialogProps- React Aria Dialog attributes
Prop Type Default Description childrenReact.ReactNode- Header content classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div>; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description childrenReact.ReactNode- Icon content classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div>; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description childrenReact.ReactNode- Heading text; labels the dialog via aria-labelledby classNamestring- Additional classes ...restHeadingProps- React Aria Heading attributes
Prop Type Default Description childrenReact.ReactNode- Body content classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div>; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description childrenReact.ReactNode- Footer content, usually buttons classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div>; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description childrenReact.ReactNode- Custom close button content; defaults to the cross glyph classNamestring | ((renderProps) => string)- Additional classes, or a function of the state ...restButtonProps- React Aria Button attributes ; slot defaults to "close"
import {useOverlayState} from "@peakui/react" ;
const state = useOverlayState ({
defaultOpen: false ,
onOpenChange : ( isOpen ) => console. log (isOpen),
});
state.isOpen; // current state
state. open (); // open the overlay
state. close (); // close the overlay
state. toggle (); // toggle the state
state. setOpen ( true ); // set the state directly
Prop Type Description Modal.Backdrop className(renderProps: ModalOverlayRenderProps) => stringComputes classes from isEntering, isExiting and state Modal.Container className(renderProps: ModalRenderProps) => stringComputes classes from isEntering, isExiting and state Modal.Dialog children(opts: {close: () => void}) => React.ReactNodeRenders content with a callback that closes the modal