shadcn.io is not affiliated with official shadcn/ui
Shadcn Presence for React and Tailwind
Animate components on mount and unmount.
Installation
bunx --bun shadcn@latest add https://kit.dev/r/presence.jsonpnpm dlx shadcn@latest add https://kit.dev/r/presence.jsonnpx shadcn@latest add https://kit.dev/r/presence.jsonyarn shadcn@latest add https://kit.dev/r/presence.jsonInstall the following dependencies:
bun add @ark-ui/reactpnpm add @ark-ui/reactnpm install @ark-ui/reactyarn add @ark-ui/reactCopy and paste the following code into your project.
"use client";
import { Presence as ArkPresence } from "@ark-ui/react/presence";
import type React from "react";
export const Presence = (props: React.ComponentProps<typeof ArkPresence>) => {
const { lazyMount = true, unmountOnExit = true, ...rest } = props;
return (
<ArkPresence
data-slot="presence"
lazyMount={lazyMount}
unmountOnExit={unmountOnExit}
{...rest}
/>
);
};Update the import paths to match your project setup.
Usage
import React from "react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Presence } from "@/components/ui/presence";const PresenceDemo = () => {
const [present, setPresent] = React.useState(false);
return (
<div className="relative">
<Button
clickEffect={false}
onClick={() => setPresent(!present)}
variant="outline"
>
Toggle
</Button>
<Presence asChild present={present}>
<div
className={cn(
"absolute bottom-full left-1/2 mb-2 -translate-x-1/2",
"px-4 py-2",
"bg-muted",
"text-sm",
"rounded-md border",
"origin-bottom",
"data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-[98%] data-[state=closed]:slide-out-to-bottom-5 data-[state=closed]:animate-out",
"data-[state=open]:fade-in-0 data-[state=open]:zoom-in-[98%] data-[state=open]:slide-in-from-bottom-5 data-[state=open]:animate-in"
)}
>
Content
</div>
</Presence>
</div>
);
};Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
API Reference
Presence
PropType
AttributeType