react-amiga-guru-meditation
Version:
A React Error Boundary styled like the Amiga Guru Meditation — accessible, themeable, zero runtime dependencies, ARIA-compliant, CSS variables theming.
72 lines (69 loc) • 3.59 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as react from 'react';
import { Component, ReactNode, ErrorInfo, CSSProperties } from 'react';
interface AmigaFallbackRenderProps {
error: Error;
errorInfo: ErrorInfo | null;
resetErrorBoundary: () => void;
}
type AmigaPortalTarget = boolean | string | HTMLElement;
interface AmigaErrorBoundaryProps {
children?: ReactNode;
/** Render-prop fallback. Takes priority over `fallback`. */
fallbackRender?: (props: AmigaFallbackRenderProps) => ReactNode;
/** Static fallback ReactNode rendered when an error is caught. */
fallback?: ReactNode;
/** Called when an error is caught. Useful for logging or error reporting. */
onError?: (error: Error, errorInfo: ErrorInfo) => void;
/** Called when the boundary is reset (imperatively or via resetKeys change). */
onReset?: (details: {
reason: "imperative" | "keys";
}) => void;
/** When any value in this array changes (shallow equality), the boundary auto-resets. */
resetKeys?: ReadonlyArray<unknown>;
/** Force the error UI to render even without a real error. Useful for showcase/preview. */
show?: boolean;
/** A pre-built error to display when `show` is true (or to override the caught one). */
error?: Error;
/**
* Render the error UI through a React portal at the document level (Amiga-style takeover).
* - `false` (default): render inline where the boundary is mounted.
* - `true`: render in a portal under a div appended to `document.body`.
* - `string`: id of the portal container element (created if missing).
* - `HTMLElement`: explicit portal target.
*/
portal?: AmigaPortalTarget;
/** Title text. Default: "Software Failure. Press left mouse button to continue." */
title?: ReactNode;
/** Override the message line. Receives the caught error. Default: "Guru Meditation: {error.message}". */
formatGuru?: (error: Error) => ReactNode;
/** Show collapsible details with the component stack. Default: true. */
showDetails?: boolean;
/** Disable the blink animation. Default: false. */
noBlink?: boolean;
/** Extra class name applied to the root element. */
className?: string;
/** Inline styles applied to the root element. Useful to set CSS variables. */
style?: CSSProperties;
}
interface State {
error: Error | null;
errorInfo: ErrorInfo | null;
}
declare class AmigaErrorBoundary extends Component<AmigaErrorBoundaryProps, State> {
static displayName: string;
state: State;
static getDerivedStateFromError(error: Error): Partial<State>;
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
componentDidUpdate(prevProps: AmigaErrorBoundaryProps): void;
resetErrorBoundary: () => void;
private resetWithReason;
render(): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
}
/**
* Imperatively trigger an Amiga Guru Meditation from a function component.
* Returns a callback that re-throws the given error during render so the
* nearest <AmigaErrorBoundary> can catch it.
*/
declare function useAmigaGuru(): (error: unknown) => void;
export { AmigaErrorBoundary, type AmigaErrorBoundaryProps, type AmigaFallbackRenderProps, type AmigaPortalTarget, AmigaErrorBoundary as GuruMeditation, useAmigaGuru };