Presence
EffectsMotionPresence keeps keyed children mounted for their exits. MotionSurface adds coordinated lifecycle states to an existing primitive.
Try it
Add to your project
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/presence.jsonThe command includes the component’s shared dependencies. Your project keeps editable source files.
Include the complete example
This example also composes button, card, typography. Install its parts together:
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/button.json https://luv-jeri.github.io/cojeev-ui/r/card.json https://luv-jeri.github.io/cojeev-ui/r/typography.json https://luv-jeri.github.io/cojeev-ui/r/presence.jsonUsing presence
Keep the MotionPresence boundary mounted and give changing children stable keys.
Use MotionSurface asChild around exactly one ref-capable primitive.
Use quiet motion to settle immediately; the shared preference is inherited.
Use settle for a small scale-down exit, soften for upward blurred words, or focus for whole-phrase focus changes. These use a gentle 420ms default exit; existing presets keep their earlier timings.
Set exitDelay on sibling words for a departure sequence; it is capped at 600ms. exitDuration is seconds, bounded to 0–2. The caller controls removal, rather than a video timeline disappearing live content.
For staggered words, a keyed conditional heading inside MotionPresence may contain MotionSurface asChild spans. Keep a single accessible heading label and hide the animated fragments. Soft-focus presets own CSS filter; use a separate wrapper if the child already has an authored filter.
Directional blur can be composed with MotionSurface preset="soften": provide signed x or y and a blur in initial/exit, then zero x/y and blur in animate. Keep it inside MotionPresence for real removal; no separate wrapper primitive is needed.
API
Compose the exported parts below. The prop types are read from the React source during the registry build.
Native element or underlying primitive props are inherited where declared, including accessible labels, event handlers and refs.
MotionPresenceProps
Accepts the native or primitive props declared by its exported TypeScript type.
MotionSurfaceProps
| Prop | Type | Required |
|---|---|---|
data-slot | string | No |
asChildMerge onto exactly one ref-capable child, preserving its native element. | boolean | No |
preset | PresencePreset | No |
delaySeconds; use motionTokens.stagger for a coordinated sibling sequence. | number | No |
exitDelaySeconds before exit; cap sibling staggering yourself to a short total window. | number | No |
exitDurationSeconds. Soft-focus and settling presets use a gentler 420ms default. | number | No |
Accessibility
Preserve native semantics with asChild.
Put presence outside the actual conditional removal; an inner boundary cannot retain its own parent.
Exiting surfaces are inert and hidden from assistive technology until removed; quiet preferences remove the delay and motion.
States and appearance
For conditional content, keep a MotionPresence boundary around keyed MotionSurface children. The shared entrance and exit states work with native primitives and respect your motion preference.
Try pointer and keyboard interaction, and switch the appearance control in the navigation to compare light and dark mode. Motion respects reduced motion preferences.