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:
30
packages/widgets/src/index.tsx
Normal file
30
packages/widgets/src/index.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import dynamic from "next/dynamic";
|
||||
import type { Loader } from "next/dynamic";
|
||||
|
||||
import { Loader as UiLoader } from "@homarr/ui";
|
||||
|
||||
import * as clock from "./clock";
|
||||
import type { WidgetComponentProps } from "./definition";
|
||||
import type { WidgetImportRecord } from "./import";
|
||||
import * as weather from "./weather";
|
||||
|
||||
export { WidgetEditModal } from "./WidgetEditModal";
|
||||
|
||||
export const widgetSorts = ["clock", "weather"] as const;
|
||||
|
||||
export const widgetImports = {
|
||||
clock,
|
||||
weather,
|
||||
} satisfies WidgetImportRecord;
|
||||
|
||||
export type WidgetSort = (typeof widgetSorts)[number];
|
||||
export type WidgetImports = typeof widgetImports;
|
||||
export type WidgetImportKey = keyof WidgetImports;
|
||||
|
||||
export const loadWidgetDynamic = <TSort extends WidgetSort>(sort: TSort) =>
|
||||
dynamic<WidgetComponentProps<TSort>>(
|
||||
widgetImports[sort].componentLoader as Loader<WidgetComponentProps<TSort>>,
|
||||
{
|
||||
loading: () => <UiLoader />,
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user