Skip to content

Commit

Permalink
Merge pull request #28 from gravity-ui/add-finish-preset-helper
Browse files Browse the repository at this point in the history
feat: add finish preset helper
  • Loading branch information
vanilla-wave authored Aug 22, 2023
2 parents e6cd6d5 + b26af97 commit e7c6e1e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import type {
InferPresetsFromOptions,
} from './types';

let closeHintRef: () => void | undefined;
let passStepRef: (step: string) => Promise<void>;
let controllerRef: Controller<object, string, string>;

export function closeHint() {
if (closeHintRef !== null) {
closeHintRef();
if (controllerRef !== null) {
controllerRef.closeHint();
}
}

export function passStep(step: string) {
if (passStepRef !== null) {
passStepRef(step);
if (controllerRef !== null) {
controllerRef.passStep(step);
}
}

export async function finishPreset(preset: string) {
if (controllerRef !== null) {
await controllerRef.finishPreset(preset);
}
}

Expand All @@ -44,9 +49,8 @@ export function createOnboarding<T extends InitOptions<any, any, any>>(options:
InferStepsFromOptions<T>
>(options);

closeHintRef = controller.closeHint;
// @ts-ignore
passStepRef = controller.passStep;
controllerRef = controller;

const {useWizard, useOnboardingPresets, useOnboardingStep, useOnboardingHint} =
getHooks(controller);
Expand Down

0 comments on commit e7c6e1e

Please sign in to comment.