UNPKG

bknd

Version:

Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.

64 lines (63 loc) 3.01 kB
import type { DB, Field } from "../.."; import type { ReactNode } from "react"; import type { Entity } from "../../data/entities"; import type { DropdownProps } from "../../ui/components/overlay/Dropdown"; import type { ButtonProps } from "../../ui/components/buttons/Button"; export type BkndAdminEntityContext = "list" | "create" | "update"; export type BkndAdminEntitiesOptions = { [E in keyof DB]?: BkndAdminEntityOptions<E>; }; export type BkndAdminEntityOptions<E extends keyof DB | string> = { /** * Header to be rendered depending on the context */ header?: (context: BkndAdminEntityContext, entity: Entity, data?: DB[E]) => ReactNode | void | undefined; /** * Footer to be rendered depending on the context */ footer?: (context: BkndAdminEntityContext, entity: Entity, data?: DB[E]) => ReactNode | void | undefined; /** * Actions to be rendered depending on the context */ actions?: (context: BkndAdminEntityContext, entity: Entity, data?: DB[E]) => { /** * Primary actions are always visible */ primary?: (ButtonProps | undefined | null | false)[]; /** * Context actions are rendered in a dropdown */ context?: DropdownProps["items"]; }; /** * Field UI overrides */ fields?: { [F in keyof DB[E]]?: BkndAdminEntityFieldOptions<E>; }; }; export type BkndAdminEntityFieldOptions<E extends keyof DB | string> = { /** * Override the rendering of a certain field */ render?: (context: BkndAdminEntityContext, entity: Entity, field: Field, ctx: { data?: DB[E]; value?: DB[E][keyof DB[E]]; handleChange: (value: any) => void; }) => ReactNode | void | undefined; }; export declare function useEntityAdminOptions(entity: Entity, context: BkndAdminEntityContext, data?: any): { footer: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null; header: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null; field: (name: string) => BkndAdminEntityFieldOptions<string> | undefined; actions: { /** * Primary actions are always visible */ primary?: (ButtonProps | undefined | null | false)[]; /** * Context actions are rendered in a dropdown */ context?: DropdownProps["items"]; } | undefined; };