import React, { ReactNode } from 'react'; import { OnboardingEngine, EngineState, OnboardingEngineConfig, OnboardingContext as OnboardingContextType } from '@onboardjs/core'; import { OnboardingStep, StepComponentRegistry } from '../types'; import type { NavigatorConfig } from '../types/navigator'; import { type LocalStoragePersistenceOptions, type UsePersistenceConfig } from '../hooks/internal'; import { type LoadingState } from '../utils/loadingState'; export interface OnboardingActions { next: (stepSpecificData?: Record) => Promise; previous: () => Promise; skip: () => Promise; goToStep: (stepId: string, stepSpecificData?: Record) => Promise; updateContext: (newContextData: Partial) => Promise; reset: (newConfig?: Partial>) => Promise; } export interface OnboardingContextValue extends OnboardingActions { engine: OnboardingEngine | null; engineInstanceId?: number | undefined; state: EngineState | null; /** * Granular loading state breakdown for better UX control. * Provides visibility into why the UI is blocked. * * @example * ```tsx * const { loading } = useOnboarding() * * if (loading.isHydrating) { * return * } else if (loading.isEngineProcessing) { * return * } else if (loading.isComponentProcessing) { * return * } * ``` */ loading: LoadingState; /** * @deprecated Use `loading.isAnyLoading` instead. Will be removed in v2.0. * Convenience boolean that is true when any loading is occurring. */ isLoading: boolean; setComponentLoading: (loading: boolean) => void; currentStep: OnboardingStep | null | undefined; isCompleted: boolean | undefined; /** The current error state of the engine, if any. */ error: Error | null; /** * A convenience method to render the current step's content. * This can be used by consumers to render the step UI. */ renderStep: () => React.ReactNode; } /** * Generic context factory function. * This approach avoids variance issues by creating a new context for each generic instantiation. * @internal This is internal API, use OnboardingContext for the default context. */ declare function createOnboardingContext(): React.Context | undefined>; /** * Default onboarding context for the base OnboardingContextType. * This is used by providers and consumers to manage state. */ export declare const OnboardingContext: React.Context> | undefined>; /** * Create a typed onboarding context for a specific context type. * Useful for cases where you need type-safe context with a custom context shape. */ export { createOnboardingContext }; export type { LocalStoragePersistenceOptions }; /** * Configuration props for OnboardingProvider component. * Extends OnboardingEngineConfig to support all engine configuration options. * * @example * ```tsx * import { AnalyticsBeforeSendHook } from '@onboardjs/core' * * const beforeSend: AnalyticsBeforeSendHook = (event) => { * // Filter out sensitive events * if (event.type.includes('password')) { * return null * } * // Modify event * return { * ...event, * properties: { * ...event.properties, * customField: 'value' * } * } * } * * * * * ``` */ export interface OnboardingProviderProps extends Omit, 'loadData' | 'persistData' | 'clearPersistedData' | 'onFlowComplete' | 'steps'> { children: ReactNode; localStoragePersistence?: LocalStoragePersistenceOptions; customOnDataLoad?: UsePersistenceConfig['customOnDataLoad']; customOnDataPersist?: UsePersistenceConfig['customOnDataPersist']; customOnClearPersistedData?: UsePersistenceConfig['customOnClearPersistedData']; onFlowComplete?: (context: TContext) => Promise | void; /** * A registry mapping step types and ids to their React components. * This allows users to provide their own custom step components. * This prop is now optional and will be overridden by the `OnboardingStep.component` property * if defined. */ componentRegistry?: StepComponentRegistry; /** * The array of steps to initialize the onboarding flow. */ steps: OnboardingStep[]; /** * Configuration for URL-based navigation. * When provided, step changes will be synchronized with the browser URL, * enabling deep linking and browser back/forward navigation. * * @example * ```tsx * import { useRouter, usePathname } from 'next/navigation' * import { createNextNavigator } from '@onboardjs/react' * * function OnboardingLayout({ children }) { * const router = useRouter() * const pathname = usePathname() * const navigator = useMemo( * () => createNextNavigator(router, pathname), * [router, pathname] * ) * * return ( * * {children} * * ) * } * ``` */ navigator?: NavigatorConfig; } export declare function OnboardingProvider({ children, steps, initialStepId, initialContext, onFlowComplete: passedOnFlowComplete, onStepChange, localStoragePersistence, customOnDataLoad, customOnDataPersist, customOnClearPersistedData, plugins, componentRegistry, debug, navigator: navigatorConfig, flowId, flowName, flowVersion, flowMetadata, publicKey, apiHost, cloudOptions, analytics, userId, }: OnboardingProviderProps): import("react/jsx-runtime").JSX.Element;