Skip to content

Commit

Permalink
feat: add bookmark widget
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Aug 10, 2024
1 parent f6e5518 commit f0c1f9a
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/definitions/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const widgetKinds = [
"mediaServer",
"calendar",
"rssFeed",
"bookmarks"
] as const;
export type WidgetKind = (typeof widgetKinds)[number];
9 changes: 9 additions & 0 deletions packages/translation/src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,15 @@ export default {
},
},
},
bookmarks: {
name: "Bookmarks",
description: "Displays a static list of strings or links",
option: {
title: {
label: "Title",
}
}
},
dnsHoleSummary: {
name: "DNS Hole Summary",
description: "Displays the summary of your DNS Hole",
Expand Down
2 changes: 2 additions & 0 deletions packages/widgets/src/_inputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WidgetSelectInput } from "./widget-select-input";
import { WidgetSliderInput } from "./widget-slider-input";
import { WidgetSwitchInput } from "./widget-switch-input";
import { WidgetTextInput } from "./widget-text-input";
import {WidgetOrderedObjectListInput} from "./widget-ordered-object-list-input";

const mapping = {
text: WidgetTextInput,
Expand All @@ -19,6 +20,7 @@ const mapping = {
slider: WidgetSliderInput,
switch: WidgetSwitchInput,
app: WidgetAppInput,
orderedObjectList: WidgetOrderedObjectListInput
} satisfies Record<WidgetOptionType, unknown>;

export const getInputForType = <TType extends WidgetOptionType>(type: TType) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {CommonWidgetInputProps} from "./common";

export const WidgetOrderedObjectListInput = ({ property, kind, options }: CommonWidgetInputProps<"orderedObjectList">) => {

Check failure on line 3 in packages/widgets/src/_inputs/widget-ordered-object-list-input.tsx

View workflow job for this annotation

GitHub Actions / lint

'property' is defined but never used. Allowed unused args must match /^_/u

Check failure on line 3 in packages/widgets/src/_inputs/widget-ordered-object-list-input.tsx

View workflow job for this annotation

GitHub Actions / lint

'kind' is defined but never used. Allowed unused args must match /^_/u
return <div>
{JSON.stringify(options)}
<span>AAAA!</span>
</div>
}
1 change: 1 addition & 0 deletions packages/widgets/src/bookmarks/bookmark-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface BookmarkItem {}
15 changes: 15 additions & 0 deletions packages/widgets/src/bookmarks/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client";

import {Code, Stack, Title} from "@mantine/core";
import type {WidgetComponentProps} from "../definition";

export default function BookmarksWidget({options}: WidgetComponentProps<"bookmarks">) {
return <Stack>
<Title size="h4" px="0.25rem">
{options.title}
</Title>
<Code mx={"md"} block>
{JSON.stringify(options)}
</Code>
</Stack>
}
19 changes: 19 additions & 0 deletions packages/widgets/src/bookmarks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {IconClock} from "@tabler/icons-react";

import {createWidgetDefinition} from "../definition";
import {optionsBuilder} from "../options";
import type {BookmarkItem} from "./bookmark-item";

export const {definition, componentLoader} = createWidgetDefinition("bookmarks", {
icon: IconClock,
options: optionsBuilder.from(
(factory) => ({
title: factory.text(),
items: factory.orderedObjectList<BookmarkItem>({
itemComponent: (bookmarkItem) => {
return <span>Bookmark: {JSON.stringify(bookmarkItem)}</span>
}
})
}),
),
}).withDynamicImport(() => import("./component"));
2 changes: 2 additions & 0 deletions packages/widgets/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as smartHomeEntityState from "./smart-home/entity-state";
import * as smartHomeExecuteAutomation from "./smart-home/execute-automation";
import * as video from "./video";
import * as weather from "./weather";
import * as bookmarks from "./bookmarks";

export { reduceWidgetOptionsWithDefaultValues } from "./options";

Expand All @@ -43,6 +44,7 @@ export const widgetImports = {
mediaServer,
calendar,
rssFeed,
bookmarks
} satisfies WidgetImportRecord;

export type WidgetImports = typeof widgetImports;
Expand Down
6 changes: 6 additions & 0 deletions packages/widgets/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { z } from "@homarr/validation";

import { widgetImports } from ".";
import type { inferSelectOptionValue, SelectOption } from "./_inputs/widget-select-input";
import React from "react";

Check warning on line 8 in packages/widgets/src/options.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

interface CommonInput<TType> {
defaultValue?: TType;
Expand Down Expand Up @@ -109,6 +110,11 @@ const optionsFactory = {
defaultValue: "",
withDescription: input?.withDescription ?? false,
}),
orderedObjectList: <TItem>(input?: (Omit<CommonInput<string>, "defaultValue"> & { itemComponent: (item: TItem) => React.ReactNode })) => ({
type: "orderedObjectList" as const,
defaultValue: [],
itemComponent: input?.itemComponent ?? null,
}),
};

type WidgetOptionFactory = typeof optionsFactory;
Expand Down

0 comments on commit f0c1f9a

Please sign in to comment.