@mongez/react-atom
Version:
A simple state management tool for React Js.
43 lines (42 loc) • 1.32 kB
text/typescript
import { ReactAtom } from "./types.mjs";
//#region ../@mongez/react-atom/src/portal-atom.d.ts
type PortalActions<T = any> = {
/**
* Opens the portal with optional data.
* @param data - Optional data to be passed when opening the portal.
*/
open: (data?: T) => void;
/**
* Closes the portal.
*/
close: () => void;
/**
* Toggles the portal's open state. If the portal is closed, it opens with optional data.
* If the portal is open, it closes.
* @param data - Optional data to be passed when opening the portal.
*/
toggle: (data?: T) => void;
/**
* Hook to determine if the portal is currently open.
* @returns A boolean indicating if the portal is open.
*/
useOpened: () => boolean;
/**
* Hook to retrieve the current data associated with the portal.
* @returns The data associated with the portal.
*/
useData: () => T;
};
type PortalData<T = any> = {
opened: boolean;
data: T;
};
type AtomPortal<T = any> = ReactAtom<PortalData<T>, PortalActions<T>>;
/**
* Create a portal atom
* This atom is used to create a portal (a modal, a tooltip, a dropdown, etc.)
*/
declare function portalAtom<T = any>(name: string, opened?: boolean): AtomPortal<T>;
//#endregion
export { AtomPortal, PortalActions, portalAtom };
//# sourceMappingURL=portal-atom.d.mts.map