56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
import { Primitives, Types } from "@a2ui/lit/0.8";
|
|
|
|
//#region src/react-renderer/hooks/useA2UIComponent.d.ts
|
|
/**
|
|
* Result returned by the useA2UIComponent hook.
|
|
*/
|
|
interface UseA2UIComponentResult {
|
|
/** The current theme */
|
|
theme: Types.Theme;
|
|
/** Resolve a StringValue to its actual string value */
|
|
resolveString: (value: Primitives.StringValue | null | undefined) => string | null;
|
|
/** Resolve a NumberValue to its actual number value */
|
|
resolveNumber: (value: Primitives.NumberValue | null | undefined) => number | null;
|
|
/** Resolve a BooleanValue to its actual boolean value */
|
|
resolveBoolean: (value: Primitives.BooleanValue | null | undefined) => boolean | null;
|
|
/** Set a value in the data model (for two-way binding) */
|
|
setValue: (path: string, value: Types.DataValue) => void;
|
|
/** Get a value from the data model */
|
|
getValue: (path: string) => Types.DataValue | null;
|
|
/** Dispatch a user action */
|
|
sendAction: (action: Types.Action) => void;
|
|
/** Generate a unique ID for accessibility */
|
|
getUniqueId: (prefix: string) => string;
|
|
}
|
|
/**
|
|
* Base hook for A2UI components. Provides data binding, theme access,
|
|
* and action dispatching.
|
|
*
|
|
* @param node - The component node from the A2UI message processor
|
|
* @param surfaceId - The surface ID this component belongs to
|
|
* @returns Object with theme, data binding helpers, and action dispatcher
|
|
*
|
|
* @example
|
|
* ```tsx
|
|
* function TextField({ node, surfaceId }: A2UIComponentProps<Types.TextFieldNode>) {
|
|
* const { theme, resolveString, setValue } = useA2UIComponent(node, surfaceId);
|
|
*
|
|
* const label = resolveString(node.properties.label);
|
|
* const value = resolveString(node.properties.text) ?? '';
|
|
*
|
|
* return (
|
|
* <div className={classMapToString(theme.components.TextField.container)}>
|
|
* <label>{label}</label>
|
|
* <input
|
|
* value={value}
|
|
* onChange={(e) => setValue(node.properties.text?.path!, e.target.value)}
|
|
* />
|
|
* </div>
|
|
* );
|
|
* }
|
|
* ```
|
|
*/
|
|
declare function useA2UIComponent<T extends Types.AnyComponentNode>(node: T, surfaceId: string): UseA2UIComponentResult;
|
|
//#endregion
|
|
export { UseA2UIComponentResult, useA2UIComponent };
|
|
//# sourceMappingURL=useA2UIComponent.d.mts.map
|