From 13882b5732ef14f6535c32f4c6840081d677e0f7 Mon Sep 17 00:00:00 2001 From: megumin Date: Wed, 26 Oct 2022 22:42:26 +0100 Subject: feat: custom components in settings (#165) --- src/utils/types.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/types.ts b/src/utils/types.ts index 41dd0c1..689baa7 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -96,6 +96,7 @@ export enum OptionType { BOOLEAN, SELECT, SLIDER, + COMPONENT, } export type PluginOptionsItem = @@ -103,7 +104,8 @@ export type PluginOptionsItem = | PluginOptionNumber | PluginOptionBoolean | PluginOptionSelect - | PluginOptionSlider; + | PluginOptionSlider + | PluginOptionComponent; export interface PluginOptionBase { description: string; @@ -176,7 +178,32 @@ export interface PluginOptionSlider extends PluginOptionBase { /** * Prevents the user from saving settings if this is false or a string */ - isValid?(value: number): number; + isValid?(value: number): boolean | string; +} + +interface IPluginOptionComponentProps { + /** + * Run this when the value changes. + * + * NOTE: The user will still need to click save to apply these changes. + */ + setValue(newValue: any): void; + /** + * Set to true to prevent the user from saving. + * + * NOTE: This will not show the error to the user. It will only stop them saving. + * Make sure to show the error in your component. + */ + setError(error: boolean): void; + /** + * The options object + */ + option: PluginOptionComponent; +} + +export interface PluginOptionComponent extends PluginOptionBase { + type: OptionType.COMPONENT; + component: (props: IPluginOptionComponentProps) => JSX.Element; } export type IpcRes = { ok: true; value: V; } | { ok: false, error: any; }; -- cgit