UNPKG

extended-dynamic-forms

Version:

Extended React JSON Schema Form (RJSF) v6 with custom components, widgets, templates, layouts, and form events

66 lines (64 loc) 2.37 kB
import { default as React } from 'react'; import { ChoiceWidgetProps, ChoiceWidgetState, ChoiceOption } from '../ChoiceWidget.types'; import { PresenterStrategy } from '../presenters/PresenterStrategy'; import { DataSourceMetrics } from '../providers/DataSourceProvider'; /** * Interface for the hook return value */ export interface UseChoiceWidgetReturn { options: ChoiceOption[]; presenter: PresenterStrategy; state: ChoiceWidgetState; setState: (updates: Partial<ChoiceWidgetState>) => void; value: unknown; handleChange: (newValue: unknown) => void; eventHandlers: { onFocus: (event: React.FocusEvent) => void; onBlur: (event: React.FocusEvent) => void; onChange: (value: unknown) => void; onSearch: (searchTerm: string) => void; }; isMultiSelect: boolean; isLoading: boolean; hasError: boolean; metrics: DataSourceMetrics; } /** * Core business logic hook for Choice Widget * * This hook orchestrates all Choice Widget functionality including: * - Data source management via useDataSource * - Presenter strategy selection and coordination * - Value transformation between widget and RJSF formats * - Event system integration via FormEventHub * - Schema-based behavior detection * - Performance optimization with memoization * * @param props - RJSF-compatible widget props * @returns Complete widget state and handlers */ export declare function useChoiceWidget(props: ChoiceWidgetProps): UseChoiceWidgetReturn; /** * Hook for using Choice Widget with custom error handling * Note: This hook catches runtime errors but not hook call errors. * Hook call errors should be handled at the component level with Error Boundaries. */ export declare function useChoiceWidgetWithErrorBoundary(props: ChoiceWidgetProps, onError?: (error: Error) => void): UseChoiceWidgetReturn | { error: Error; }; /** * Hook for using Choice Widget with performance monitoring */ export declare function useChoiceWidgetWithMetrics(props: ChoiceWidgetProps, onMetricsUpdate?: (metrics: DataSourceMetrics) => void): UseChoiceWidgetReturn & { performanceMetrics: PerformanceMetrics; }; /** * Performance metrics interface */ interface PerformanceMetrics { initialLoadTime: number; renderCount: number; averageRenderTime: number; lastRenderTime: number; } export {};