feat: add widget preview pages (#9)

* feat: add widget definition system

* fix: wrong typecheck command in turbo generator

* chore: fix formatting

* feat: add widget preview page

* chore: fix formatting and type errors

* chore: fix from widget edit modal and remove some never casts

* chore: address pull request feedback
This commit is contained in:
Meier Lukas
2024-01-02 15:36:59 +01:00
committed by GitHub
parent fa19966fcc
commit 782897527f
48 changed files with 1226 additions and 81 deletions

View File

@@ -0,0 +1,40 @@
import type { LoaderComponent } from "next/dynamic";
import type { TablerIconsProps } from "@homarr/ui";
import type { WidgetImports, WidgetSort } from ".";
import type {
inferOptionsFromDefinition,
WidgetOptionsRecord,
} from "./options";
export const createWidgetDefinition = <
TSort extends WidgetSort,
TDefinition extends Definition,
>(
sort: TSort,
definition: TDefinition,
) => ({
withDynamicImport: (
componentLoader: () => LoaderComponent<WidgetComponentProps<TSort>>,
) => ({
definition: {
sort,
...definition,
},
componentLoader,
}),
});
interface Definition {
icon: (props: TablerIconsProps) => JSX.Element;
options: WidgetOptionsRecord;
}
export interface WidgetComponentProps<TSort extends WidgetSort> {
options: inferOptionsFromDefinition<WidgetOptionsRecordOf<TSort>>;
integrations: unknown[];
}
export type WidgetOptionsRecordOf<TSort extends WidgetSort> =
WidgetImports[TSort]["definition"]["options"];