feat: custom components in settings (#165)

This commit is contained in:
megumin 2022-10-26 22:42:26 +01:00 committed by GitHub
parent 49e72bab32
commit 13882b5732
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 3 deletions

View file

@ -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<V = any> = { ok: true; value: V; } | { ok: false, error: any; };