Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add useOnboardingPreset, add presetsNames to export #9

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const getOptions = (
presets: {
createProject: {
name: 'Creating project',
description: '',
steps: [
{
slug: 'openBoard',
Expand All @@ -31,7 +30,6 @@ const getOptions = (
},
createQueue: {
name: 'Creating queue',
description: '',
steps: [],
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ export function getHooks<HintParams, Presets extends string, Steps extends strin
await controller.finishPreset(preset);
};

const resetPresetProgress = async () => {
await controller.resetPresetProgress([preset]);
};

return {
addPreset,
finishPreset,
resetPresetProgress,
};
};

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
return preset as unknown as Preset<InferHintParamsFromPreset<T>, InferStepsFromPreset<T>>;
}

export function createOnboarding<T extends InitOptions<any, any, any>>(options: T) {

Check warning on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

Check warning on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

Check warning on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
const controller = new Controller<
InferHintParamsFromOptions<T>,
InferPresetsFromOptions<T>,
Expand All @@ -51,11 +51,16 @@
const {useOnboarding, useOnboardingPreset, useOnboardingStep, useOnboardingHint} =
getHooks(controller);

const presetsNames = Object.keys(
controller.options.config.presets,
) as unknown as keyof typeof controller.options.config.presets;

return {
useOnboardingStep,
useOnboardingPreset,
useOnboardingHint,
useOnboarding,
controller,
presetsNames,
};
}
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {ReactNode} from 'react';
import type {LoggerOptions} from './logger';

type HintPlacement =
Expand Down Expand Up @@ -30,7 +31,7 @@

export type Preset<HintParams, Steps extends string> = {
name: string;
description: string;
description?: ReactNode[];
type?: 'default' | 'hidden';
steps: PresetStep<Steps, HintParams | undefined>[];
hidden?: boolean;
Expand Down Expand Up @@ -72,8 +73,8 @@
baseState: Partial<BaseState> | undefined;
getProgressState: () => Promise<Partial<ProgressState>>;
onSave: {
state: (state: BaseState) => Promise<any>;

Check warning on line 76 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
progress: (progress: ProgressState) => Promise<any>;

Check warning on line 77 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
};
showHint?: (params: ShowHintParams<HintParams, Presets, Steps>) => void;
logger?: LoggerOptions;
Expand All @@ -88,10 +89,10 @@

// type inference utils
type CommonKeys<T extends object> = keyof T;
type AllKeys<T> = T extends any ? keyof T : never;

Check warning on line 92 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
type Subtract<A, C> = A extends C ? never : A;
type NonCommonKeys<T extends object> = Subtract<AllKeys<T>, CommonKeys<T>>;
type PickType<T, K extends AllKeys<T>> = T extends {[k in K]?: any} ? T[K] : undefined;

Check warning on line 95 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type

export type Merge<T extends object> = {
[k in keyof T]: PickTypeOf<T, k>;
Expand All @@ -104,18 +105,18 @@
: never;

export type InferStepsFromPreset<T> = T extends {steps: Array<infer U>}
? U extends PresetStep<infer Steps, any>

Check warning on line 108 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
? Steps
: never
: never;

export type InferHintParamsFromPreset<T> = T extends {steps: Array<infer U>}
? U extends PresetStep<any, infer HintParams>

Check warning on line 114 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
? HintParams
: never
: never;

export type InferStepsFromOptions<T extends InitOptions<any, any, any>> =

Check warning on line 119 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
T['config']['presets'] extends Record<any, infer U>
? U extends Preset<any, infer Steps>
? Steps
Expand Down
Loading