API

The parts of eclosion and the props they take.

Anatomy#

Import Eclosion and put the parts together.

import { Eclosion } from "eclosion/react";

<Eclosion.Root>
	<Eclosion.Trigger />
	<Eclosion.Overlay />
	<Eclosion.Content>
		<Eclosion.Title />
		<Eclosion.Description />
		<Eclosion.Shared id="cover" />
		<Eclosion.Close />
	</Eclosion.Content>
</Eclosion.Root>;

Components#

Root#

Holds the state. It renders nothing of its own.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange(open: boolean) => void-
placement"anchored" | "centered""anchored"
originOrigin"center"
modalbooleantrue when centered
swipebooleantrue
containerHTMLElement | nulldocument.body

Origin is "center", a side ("top", "right", "bottom", "left") or a corner ("top-left", "top-right", "bottom-left", "bottom-right"). See Origin.

modal traps focus, makes the page inert and locks scroll.

Trigger#

The button that opens the content. Takes button props.

PropTypeDefault
asChildbooleanfalse

Content#

The surface that grows. Takes div props. Focus goes to initialFocus, then an autoFocus child, then the dialog itself.

PropTypeDefault
initialFocusRefObject<HTMLElement | null>-

Overlay#

A full-screen layer behind the content. Takes div props. You color it, and it fades on its own.

Close#

A button that closes the content. Takes button props, and shows × if it has no children.

PropTypeDefault
asChildbooleanfalse

Title#

Labels the dialog for assistive technology. Renders an h2.

Description#

Describes the dialog for assistive technology. Renders a p.

Shared#

An element that flies between the trigger and the content. Put one with the same id on each side. A copy does the flying, so keep it for media-like elements.

PropTypeDefault
idstringRequired
asChildbooleanfalse

Swipe#

On touch, dragging down dismisses. Inside a scroller, it only takes over from the top. Pass swipe={false} to turn it off, or mark an element with data-eclosion-no-swipe to exempt it.

Good to know#