React
Provider, hooks, and headless components from the React entry point.
Every export of @kumbatio/energy-system/react, generated from the declarations of the installed package (v2.1.1).
import { EnergyGate, EnergyIndicator, EnergyProvider } from '@kumbatio/energy-system/react'9 value exports and 5 type exports.
Functions
EnergyGate
export declare function EnergyGate({ presence, min, max, fallback, whenHidden, children, }: EnergyGateProps): ReactNode;Declarative energy gating for a subtree.
// Hide the AI chat at 50 and below:
<EnergyGate min={75}>
<AiChatPanel />
</EnergyGate>
// Full presence map, muted state styled by the child:
<EnergyGate presence={aiChatPresence}>
{(presence) => <AiChatPanel muted={presence === 'muted'} />}
</EnergyGate>Headless: renders no wrapper element of its own.
EnergyIndicator
export declare function EnergyIndicator({ children }: EnergyIndicatorProps): ReactNode;Headless energy indicator - bring your own UI
EnergyProvider
export declare function EnergyProvider({ engine: externalEngine, defaultLevel, persistence, onLevelChange, applyToDOM, domTarget, children, }: EnergyProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<EnergyEngine | null>>;useEnergyGate
export declare function useEnergyGate(minLevel: EnergyLevel): boolean;Returns true if current energy level meets or exceeds the given minimum
useEnergyLevel
export declare function useEnergyLevel(): [
EnergyLevel,
(level: EnergyLevel, source?: EnergySource) => void
];Read the current energy level and setter
useEnergyLevelCycler
export declare function useEnergyLevelCycler(): () => void;Returns a function that cycles to the next energy level
useEnergyPresence
export declare function useEnergyPresence(presence: EnergyPresenceMap): EnergyPresence;Resolve a presence map against the current energy level
useEnergyState
export declare function useEnergyState(): EnergyState;Get the full energy state (level + timestamp + source)
useStrategy
export declare function useStrategy<T>(strategy: AdaptationStrategy<T>): T;Resolve a strategy against current energy level
Interfaces
EnergyIndicatorProps
export interface EnergyIndicatorProps {
children: (props: EnergyIndicatorRenderProps) => ReactNode;
}Prop
Type
EnergyIndicatorRenderProps
export interface EnergyIndicatorRenderProps {
level: EnergyLevel;
label: string;
description: string;
cognitiveProfile: EnergyLevelDefinition['cognitiveProfile'];
state: EnergyState;
definition: EnergyLevelDefinition;
levels: readonly EnergyLevelDefinition[];
cycle: () => void;
setLevel: (level: EnergyLevel, source?: EnergySource) => void;
}Prop
Type
EnergyProviderProps
export interface EnergyProviderProps {
/** Pre-created engine. When provided, this engine is used directly. */
engine?: EnergyEngine;
/** Initial energy level when the provider creates its own engine. */
defaultLevel?: EnergyLevel;
/** Persistence adapter when the provider creates its own engine. */
persistence?: EnergyPersistence;
/** Called on every level change. */
onLevelChange?: EnergyChangeListener;
/** Whether to apply energy level to DOM via data attributes */
applyToDOM?: boolean;
/**
* Element the level is projected onto. Default: `document.body`.
*
* Pass `() => document.documentElement` when the stylesheet keys off
* `[data-energy-level]` at the root - resolved inside the effect, so the
* render phase never touches the DOM. Whatever the target, the provider
* snapshots what was there, layers overlapping providers, and restores the
* baseline on unmount.
*/
domTarget?: HTMLElement | (() => HTMLElement | null);
children: ReactNode;
}Prop
Type
Type aliases
EnergyGateProps
export type EnergyGateProps = EnergyGateBaseProps & ({
/** Full presence declaration for this element */
presence: EnergyPresenceMap;
min?: never;
max?: never;
} | {
presence?: never;
/** Shorthand: visible at or above this level, hidden below */
min: EnergyLevel;
/** Optionally also hidden above this level (band gating) */
max?: EnergyLevel;
} | {
presence?: never;
min?: never;
/** Shorthand: visible at or below this level, hidden above */
max: EnergyLevel;
});EnergyHiddenBehavior
export type EnergyHiddenBehavior = 'preserve' | 'unmount';What happens to the gated subtree when its presence resolves to 'hidden'.
preserve(default): kept mounted inside<Activity mode="hidden">, so component state, DOM and scroll position survive. Effects are torn down while hidden and re-run on reveal, and hidden content is not rendered on the server. Energy is expected to move up and down; a half-written message should still be there when capacity returns.unmount: removed from the tree entirely. Use for subtrees whose cost is worth reclaiming at low energy (media, canvases, live connections).
