@zag-js/presence
Version:
Core logic for the presence widget implemented as a state machine
55 lines (52 loc) • 1.49 kB
TypeScript
import { Machine, EventObject, Service } from '@zag-js/core';
interface PresenceProps {
/**
* Whether the node is present (controlled by the user)
*/
present?: boolean | undefined;
/**
* Function called when the animation ends in the closed state
*/
onExitComplete?: VoidFunction | undefined;
/**
* Whether to synchronize the present change immediately or defer it to the next frame
*/
immediate?: boolean | undefined;
}
interface PresenceSchema {
refs: {
node: HTMLElement | null;
styles: CSSStyleDeclaration | null;
};
props: PresenceProps;
context: {
initial: boolean;
unmountAnimationName: string | null;
prevAnimationName: string | null;
};
state: "unmounted" | "unmountSuspended" | "mounted";
action: string;
effect: string;
event: EventObject;
}
type PresenceService = Service<PresenceSchema>;
type PresenceMachine = Machine<PresenceSchema>;
interface PresenceApi {
/**
* Whether the animation should be skipped.
*/
skip: boolean;
/**
* Whether the node is present in the DOM.
*/
present: boolean;
/**
* Function to set the node (as early as possible)
*/
setNode: (node: HTMLElement | null) => void;
/**
* Function to programmatically unmount the node
*/
unmount: VoidFunction;
}
export type { PresenceApi, PresenceMachine, PresenceProps, PresenceSchema, PresenceService };