diff --git a/packages/old-import/src/widgets/options.ts b/packages/old-import/src/widgets/options.ts index d8a84e95e..31658ecd1 100644 --- a/packages/old-import/src/widgets/options.ts +++ b/packages/old-import/src/widgets/options.ts @@ -38,6 +38,7 @@ const optionMapping: OptionMapping = { return mappedLayouts[oldOptions.layout]; }, + hideTitle: () => undefined, hideIcon: (oldOptions) => oldOptions.items.some((item) => item.hideIcon), hideHostname: (oldOptions) => oldOptions.items.some((item) => item.hideHostname), openNewTab: (oldOptions) => oldOptions.items.some((item) => item.openNewTab), diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.json index d7d9f8697..7c664d97d 100644 --- a/packages/translation/src/lang/en.json +++ b/packages/translation/src/lang/en.json @@ -1127,9 +1127,15 @@ }, "grid": { "label": "Grid" + }, + "gridHorizontal": { + "label": "Grid horizontal" } } }, + "hideTitle": { + "label": "Hide title" + }, "hideIcon": { "label": "Hide icons" }, diff --git a/packages/widgets/src/bookmarks/component.tsx b/packages/widgets/src/bookmarks/component.tsx index a20093846..db7eabf07 100644 --- a/packages/widgets/src/bookmarks/component.tsx +++ b/packages/widgets/src/bookmarks/component.tsx @@ -1,6 +1,6 @@ "use client"; -import { Anchor, Box, Card, Divider, Flex, Group, Stack, Text, Title, UnstyledButton } from "@mantine/core"; +import { Anchor, Card, Flex, Group, Stack, Text, Title, UnstyledButton } from "@mantine/core"; import combineClasses from "clsx"; import type { RouterOutputs } from "@homarr/api"; @@ -12,7 +12,7 @@ import { MaskedOrNormalImage } from "@homarr/ui"; import type { WidgetComponentProps } from "../definition"; import classes from "./bookmark.module.css"; -export default function BookmarksWidget({ options, width, height, itemId }: WidgetComponentProps<"bookmarks">) { +export default function BookmarksWidget({ options, itemId }: WidgetComponentProps<"bookmarks">) { const board = useRequiredBoard(); const [data] = clientApi.app.byIds.useSuspenseQuery(options.items, { select(data) { @@ -48,21 +48,22 @@ export default function BookmarksWidget({ options, width, height, itemId }: Widg {options.title} )} - {options.layout === "grid" && ( + {(options.layout === "grid" || options.layout === "gridHorizontal") && ( )} - {options.layout !== "grid" && ( + {options.layout !== "grid" && options.layout !== "gridHorizontal" && ( { +const FlexLayout = ({ + data, + direction, + hideTitle, + hideIcon, + hideHostname, + openNewTab, + hasIconColor, +}: FlexLayoutProps) => { const board = useRequiredBoard(); return ( - {data.map((app, index) => ( + {data.map((app) => (
- - + {direction === "row" ? ( - + ) : ( - + )} @@ -117,29 +134,27 @@ const FlexLayout = ({ data, direction, hideIcon, hideHostname, openNewTab, hasIc interface GridLayoutProps { data: RouterOutputs["app"]["byIds"]; - width: number; - height: number; + hideTitle: boolean; hideIcon: boolean; hideHostname: boolean; openNewTab: boolean; + itemDirection: "horizontal" | "vertical"; hasIconColor: boolean; } -const GridLayout = ({ data, width, height, hideIcon, hideHostname, openNewTab, hasIconColor }: GridLayoutProps) => { - // Calculates the perfect number of columns for the grid layout based on the width and height in pixels and the number of items - const columns = Math.ceil(Math.sqrt(data.length * (width / height))); - +const GridLayout = ({ + data, + hideTitle, + hideIcon, + hideHostname, + openNewTab, + itemDirection, + hasIconColor, +}: GridLayoutProps) => { const board = useRequiredBoard(); return ( - + {data.map((app) => ( - + {itemDirection === "horizontal" ? ( + + ) : ( + + )} ))} - + ); }; const VerticalItem = ({ app, + hideTitle, hideIcon, hideHostname, hasIconColor, - size = 30, }: { app: RouterOutputs["app"]["byIds"][number]; + hideTitle: boolean; hideIcon: boolean; hideHostname: boolean; hasIconColor: boolean; - size?: number; }) => { return ( - - {app.name} - + {!hideTitle && ( + + {app.name} + + )} {!hideIcon && ( )} {!hideHostname && ( - + {app.href ? new URL(app.href).hostname : undefined} )} @@ -215,17 +241,19 @@ const VerticalItem = ({ const HorizontalItem = ({ app, + hideTitle, hideIcon, hideHostname, hasIconColor, }: { app: RouterOutputs["app"]["byIds"][number]; + hideTitle: boolean; hideIcon: boolean; hideHostname: boolean; hasIconColor: boolean; }) => { return ( - + {!hideIcon && ( )} - - - {app.name} - + {!(hideTitle && hideHostname) && ( + <> + + {!hideTitle && ( + + {app.name} + + )} - {!hideHostname && ( - - {app.href ? new URL(app.href).hostname : undefined} - - )} - + {!hideHostname && ( + + {app.href ? new URL(app.href).hostname : undefined} + + )} + + + )} ); }; diff --git a/packages/widgets/src/bookmarks/index.tsx b/packages/widgets/src/bookmarks/index.tsx index 763b0a3ad..37eaa9450 100644 --- a/packages/widgets/src/bookmarks/index.tsx +++ b/packages/widgets/src/bookmarks/index.tsx @@ -14,12 +14,13 @@ export const { definition, componentLoader } = createWidgetDefinition("bookmarks return optionsBuilder.from((factory) => ({ title: factory.text(), layout: factory.select({ - options: (["grid", "row", "column"] as const).map((value) => ({ + options: (["grid", "gridHorizontal", "row", "column"] as const).map((value) => ({ value, label: (t) => t(`widget.bookmarks.option.layout.option.${value}.label`), })), defaultValue: "column", }), + hideTitle: factory.switch({ defaultValue: false }), hideIcon: factory.switch({ defaultValue: false }), hideHostname: factory.switch({ defaultValue: false }), openNewTab: factory.switch({ defaultValue: true }),