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:
40
packages/widgets/src/definition.ts
Normal file
40
packages/widgets/src/definition.ts
Normal 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"];
|
||||
Reference in New Issue
Block a user