Files
lnreader-plugins/libs/filterInputs.ts
T
Marcin Majewski d7a76063bf Filters Redesign (#658)
* Add XCheckboxFilter

* Fix madara typo

* Change the branch name in config

* Add typing for madara popoularnovels filters

* Add preview and refactor PluginWrapper

* Add preview HTML sanitize and other improv.

* Web improvements + sanitizeHTML

* Add dark mode

* Add git run less to compile less

* Add less.js to remove the need for compiling less
2023-12-27 20:19:46 +05:30

79 lines
1.9 KiB
TypeScript

export interface FilterOption {
readonly label: string;
readonly value: string;
}
export enum FilterTypes {
TextInput = "Text",
Picker = "Picker",
CheckboxGroup = "Checkbox",
Switch = "Switch",
ExcludableCheckboxGroup = "XCheckbox",
}
type SwitchFilter = {
type: FilterTypes.Switch;
/** Default value */
value: boolean;
};
type TextFilter = {
type: FilterTypes.TextInput;
/** Default value */
value: string;
};
type CheckboxFilter = {
type: FilterTypes.CheckboxGroup;
options: readonly FilterOption[];
/** Default value */
value: string[];
};
type PickerFilter = {
type: FilterTypes.Picker;
options: readonly FilterOption[];
/** Default value */
value: string;
};
type ExcludableCheckboxFilter = {
type: FilterTypes.ExcludableCheckboxGroup;
options: readonly FilterOption[];
value: { include?: string[]; exclude?: string[] };
};
export type Filters = Record<
string,
| { label: string } & (
| PickerFilter
| CheckboxFilter
| TextFilter
| SwitchFilter
| ExcludableCheckboxFilter
)
>;
export type FilterToValues<
T extends Record<string, { type: FilterTypes }> | undefined
> = T extends undefined
? undefined
: {
[K in keyof T]: Omit<
{ type: NonNullable<T>[K]["type"] } & Filters[string],
"label" | "options"
>;
};
export type ValueOfFilter<T extends FilterTypes> =
T extends FilterTypes.CheckboxGroup
? CheckboxFilter["value"]
: T extends FilterTypes.Picker
? PickerFilter["value"]
: T extends FilterTypes.Switch
? SwitchFilter["value"]
: T extends FilterTypes.TextInput
? TextFilter["value"]
: T extends FilterTypes.ExcludableCheckboxGroup
? ExcludableCheckboxFilter["value"]
: never;