Presence
A keyed state enters after the previous state has made room.
Live — this one is real
Usage
"use client";
import { useState } from "react";
import { Presence, Stack, Button, Alert } from "mizu-ui";
export function Example() {
const [saved, setSaved] = useState(false);
return (
<Stack gap={20}>
<Button size="sm" onClick={() => setSaved(!saved)}>
Change state
</Button>
<Presence presenceKey={String(saved)}>
<Alert
title={saved ? "Changes saved" : "Draft in progress"}
tone={saved ? "success" : "neutral"}
>
{saved
? "The current draft is ready for review."
: "Keep shaping the idea."}
</Alert>
</Presence>
</Stack>
);
}
It starts with "use client" because it keeps state or passes functions to components, so it pastes into a Next.js page as it is. Other React setups ignore the directive.
Source & setup
Add this component to your project with the shadcn CLI. The command copies its source into your configured UI directory, with base.css, Mizu’s tokens: it has no static styles and brings no stylesheet of its own. In a project without a components.json, run npx shadcn@latest init 0xuser64bit/mizu/preset first: plain init installs shadcn’s theme into your global CSS. Then load the fonts.
npx shadcn@latest add 0xuser64bit/mizu/presence 0xuser64bit/mizu/stack 0xuser64bit/mizu/button 0xuser64bit/mizu/alertThe example also uses Stack and Button and Alert, so the command adds them too.
Every component imports from its own path, its name in kebab case. To paste the example, replace its mizu-ui import with:
import { Presence } from "@/components/ui/mizu/presence";
import { Stack } from "@/components/ui/mizu/stack";
import { Button } from "@/components/ui/mizu/button";
import { Alert } from "@/components/ui/mizu/alert";For npm imports, import mizu-ui/styles.css once. Fonts are optional via mizu-ui/fonts.css. Override --mizu-* tokens or use className for local styling. Requires React and Motion. A Client Component: its source starts with “use client”.
Inspect motion/Presence.tsx
Source is included in the npm package under src/motion/Presence.tsx.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| presenceKey | string | number | — | Stable identity of the visible state. |
| children / className | ReactNode / string | — | The changing content and wrapper styling. |
Accessibility
Content stays in document order. Do not move a focused control between keyed states; use persistent controls outside Presence.
Motion
AnimatePresence waits for exit and displays the latest state. Reduced motion replaces content without travel.