feat: refine widget interactions
This commit is contained in:
125 files changed
+3281
-1459
No files matched your search
@@ -12,7 +12,7 @@ Homarr has the following keyboard shortcuts:
|
||||
| `MOD` + `J` | Toggles Dark Mode |
|
||||
| `MOD` + `E` | Toggles Edit Mode |
|
||||
| Hold `Shift` while hovering a widget | Opens its temporary advanced view |
|
||||
| `Shift` + `Enter` on a focused widget | Opens and pins its advanced view |
|
||||
| `Shift` + `Enter` on a focused widget | Opens its advanced view until it is closed |
|
||||
| `Esc` | Closes an open advanced view or board menu |
|
||||
| `Shift` + `F10` on a focused board section | Opens the precise add-item menu at the next available cell |
|
||||
|
||||
@@ -20,8 +20,9 @@ Homarr has the following keyboard shortcuts:
|
||||
|
||||
Here `MOD` refers to the modifier key, which is `Ctrl` on Windows and `Cmd` on macOS.
|
||||
|
||||
Advanced view and precise placement are available outside edit mode. Precise placement still requires permission to
|
||||
change the board and the right-click interaction preference to be enabled.
|
||||
Advanced view and precise placement are available outside edit mode. App tiles stay compact and do not have an
|
||||
advanced view. Precise placement still requires permission to change the board and the right-click interaction
|
||||
preference to be enabled.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -191,9 +191,10 @@ When entering the edit mode, you'll get some additional buttons to work with:
|
||||
- **Exit edit mode**: Click this button to save your changes and exit edit mode.
|
||||
|
||||
Outside edit mode, right-click a widget for its live status, refresh, settings, quick options, and supported actions.
|
||||
Hold `Shift` while hovering a widget for a temporary advanced view; use its pin control to keep it open. You can also
|
||||
focus the widget and press `Shift` + `Enter` to open it pinned. If you can change the board, right-click empty grid
|
||||
space to add an item at that position.
|
||||
Hold `Shift` while hovering a widget to expand an advanced preview in place while the rest of the board stays visible
|
||||
but dimmed. Release `Shift` to close it. You can also focus the widget and press `Shift` + `Enter` to keep its advanced
|
||||
view open until you close it. App tiles stay compact. If you can change the board, right-click empty grid space to add
|
||||
an item at that position.
|
||||
On a touch device, touch and hold empty grid space for the same precise-placement menu.
|
||||
|
||||
To continue, click the option "New Item":
|
||||
|
||||
@@ -179,8 +179,9 @@ This will disable the status check for apps.
|
||||
|
||||
Widgets expose their routine controls without requiring edit mode:
|
||||
|
||||
- Hold `Shift` while hovering a widget for a temporary advanced view, then use its pin control to keep it open. Focus
|
||||
the widget and press `Shift` + `Enter` to open it pinned, or use the maximize control on touch devices.
|
||||
- Hold `Shift` while hovering a widget to expand its advanced preview in place while the other widgets remain visible
|
||||
but dimmed. Release `Shift` to close it. Focus the widget and press `Shift` + `Enter` to keep the view open until you
|
||||
close it, or use the maximize control on touch devices. App tiles stay compact.
|
||||
- Right-click a widget to inspect its live query status, refresh its data, change quick options, open settings, or run
|
||||
supported actions. Available controls follow your board and integration permissions.
|
||||
- If you can modify the board, right-click or touch and hold an empty grid cell to add an item there. Focus a board
|
||||
|
||||
@@ -35,7 +35,7 @@ import anchorNoteWidgetScreenshot from "./img/widget.png";
|
||||
|
||||
### Interactions
|
||||
|
||||
- Click **Edit** to start editing the selected note.
|
||||
- Hover the widget, focus within it, or use a touch device to reveal **Edit**, then select it to start editing the note.
|
||||
- Click **Save** to persist changes to Anchor.
|
||||
- Click **Cancel** to discard unsaved changes.
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ description: "Embeds an app into the board."
|
||||
hide_title: true
|
||||
---
|
||||
|
||||
import { WidgetInteractionGuide } from "@site/src/components/widgets/interactions";
|
||||
|
||||
import { AddingWidget } from "@site/src/components/widgets/adding";
|
||||
import { WidgetConfig } from "@site/src/components/widgets/configuration";
|
||||
import { WidgetHeader } from "@site/src/components/widgets/header";
|
||||
@@ -27,7 +25,10 @@ import piHoleApp from "./img/pi-hole-ping-icon.png";
|
||||
<img src={piHoleApp} alt="app pi-hole with-status-check status-check-icon" width={128 * 1.5} height={128 * 1.5} />
|
||||
<img src={jellyseerrApp} alt="app jellyseerr with-description-tooltip" height={128 * 1.5} />
|
||||
</div>
|
||||
<WidgetInteractionGuide />
|
||||
|
||||
### Interactions
|
||||
|
||||
App tiles stay compact and open their configured destination directly. Right-click a tile to inspect its status or change its settings when the board and your preferences allow it.
|
||||
|
||||
### Adding the widget
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { bookmarksWidget } from ".";
|
||||
|
||||
The bookmarks widget allows you to display multiple app links in a single widget.
|
||||
You can add links to your favorite applications, websites, or any other resources you want quick access to.
|
||||
Its normal view adapts each configured layout to the available width and height: lower-priority hostnames are hidden before names or icons, and larger collections scroll instead of crushing cards.
|
||||
|
||||
### Screenshots
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ import withoutIntegrations from "./img/without-integrations.png";
|
||||
### Interactions
|
||||
|
||||
- Hover over a marked date to preview its events in a popover.
|
||||
- Click on a marked date to pin the popover open (it will stay visible even after moving the mouse away).
|
||||
- Click the date again or click outside to close the pinned popover.
|
||||
- The advanced view replaces the month grid with a grouped event list. Use its previous and next controls to change months.
|
||||
- If one selected integration is unavailable, its warning indicator remains visible while events from healthy integrations continue to load.
|
||||
|
||||
<WidgetInteractionGuide />
|
||||
|
||||
@@ -33,6 +33,8 @@ import screen from "./img/screen.png";
|
||||
|
||||
<WidgetInteractionGuide />
|
||||
|
||||
Hover or focus the widget to pause its slideshow; touch devices keep the control available. A paused slideshow keeps its resume control visible. The advanced view groups previous, pause or resume, and next together and adds a thumbnail strip for quick navigation.
|
||||
|
||||
### Adding the widget
|
||||
|
||||
<AddingWidget />
|
||||
|
||||
@@ -38,7 +38,7 @@ import editOn from "./img/edit.png";
|
||||
|
||||
### Editing
|
||||
|
||||
When the permissions of the user allows it, you can enter the editing of the text by clicking the following button in the top right.
|
||||
When your permissions allow it, hover the widget, focus within it, or use a touch device to reveal the edit button in the top right. You can also double-click the document to edit it directly.
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { stockPriceWidget } from ".";
|
||||
<WidgetHeader widget={stockPriceWidget} categories={["Finance", "Market"]} />
|
||||
|
||||
Using the Stocks widget, you can show the current stock prices of your favorite companies on your dashboard.
|
||||
The compact view prioritizes the symbol, current price, and trend. Company name, change, and time range appear only when both the widget width and height can support them; the advanced view always shows the complete summary.
|
||||
|
||||
### Screenshots
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ import { weatherWidget } from ".";
|
||||
<WidgetHeader widget={weatherWidget} categories={["Weather"]} />
|
||||
|
||||
The Weather Widget uses your location to display the current, highest and lowest temperature.
|
||||
The advanced view always combines current conditions with the full seven-day forecast, including humidity, wind,
|
||||
gusts, sunrise and sunset. Both views reuse the same cached Open Meteo response.
|
||||
|
||||
### Screenshots
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { IconArrowsMaximize, IconMouse2, IconPlus } from "@tabler/icons-react";
|
||||
import { IconArrowsMaximize, IconLayoutGrid, IconMouse2, IconPlus } from "@tabler/icons-react";
|
||||
|
||||
const interactions = [
|
||||
{
|
||||
icon: IconArrowsMaximize,
|
||||
title: "Advanced view",
|
||||
description:
|
||||
"Hold Shift while hovering (then pin it), press Shift + Enter, or choose Open advanced view from the widget menu.",
|
||||
"Hold Shift while hovering for an in-place preview, press Shift + Enter, or choose Open advanced view from the widget menu.",
|
||||
},
|
||||
{
|
||||
icon: IconMouse2,
|
||||
@@ -19,6 +19,12 @@ const interactions = [
|
||||
description:
|
||||
"With board changes allowed, right-click or touch and hold empty grid space to add there. Keyboard users can press Shift + F10.",
|
||||
},
|
||||
{
|
||||
icon: IconLayoutGrid,
|
||||
title: "Adaptive detail",
|
||||
description:
|
||||
"Resize a widget to tune its density. Compact views keep primary status visible, then reveal details and controls as space or intent allows.",
|
||||
},
|
||||
] as const;
|
||||
|
||||
export const WidgetInteractionGuide = () => (
|
||||
@@ -30,7 +36,7 @@ export const WidgetInteractionGuide = () => (
|
||||
Hide shortcuts
|
||||
</span>
|
||||
</summary>
|
||||
<div className="grid gap-3 border-0 border-t border-solid border-[#e5e7eb] p-4 md:grid-cols-3 dark:border-[#333]">
|
||||
<div className="grid gap-3 border-0 border-t border-solid border-[#e5e7eb] p-4 md:grid-cols-2 xl:grid-cols-4 dark:border-[#333]">
|
||||
{interactions.map(({ icon: Icon, title, description }) => (
|
||||
<div key={title} className="rounded-lg bg-white p-3 shadow-sm dark:bg-gray-950">
|
||||
<Icon aria-hidden size={20} stroke={1.5} className="mb-2 stroke-red-500" />
|
||||
@@ -40,8 +46,8 @@ export const WidgetInteractionGuide = () => (
|
||||
))}
|
||||
</div>
|
||||
<p className="m-0 px-4 pb-4 text-xs text-[#696969] dark:text-[#999]">
|
||||
Advanced view reuses the widget's live data and cache. Touch devices expose a maximize control; board actions
|
||||
respect your permissions and right-click preference.
|
||||
Advanced view reuses the widget's live data and cache. The rest of the board stays visible but dimmed. Touch
|
||||
devices expose a maximize control; app tiles stay compact.
|
||||
</p>
|
||||
</details>
|
||||
);
|
||||
@@ -1,28 +1,18 @@
|
||||
.focusScope {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 198;
|
||||
background: rgba(0, 0, 0, 0.64);
|
||||
backdrop-filter: blur(6px) saturate(0.75);
|
||||
touch-action: none;
|
||||
pointer-events: none;
|
||||
animation: focus-backdrop-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
.surface {
|
||||
position: fixed;
|
||||
z-index: 199;
|
||||
z-index: 1;
|
||||
pointer-events: auto;
|
||||
overflow: hidden;
|
||||
background: var(--mantine-color-body);
|
||||
box-shadow: var(--mantine-shadow-lg);
|
||||
box-shadow: var(--mantine-shadow-md);
|
||||
overscroll-behavior: contain;
|
||||
animation: focus-surface-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
|
||||
animation: focus-surface-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
|
||||
transform-origin: top left;
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
.backdropClosing {
|
||||
@@ -45,7 +35,7 @@
|
||||
.surfaceHostAdvanced {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 199;
|
||||
z-index: calc(var(--mantine-z-index-modal) - 1);
|
||||
width: auto;
|
||||
height: auto;
|
||||
pointer-events: none;
|
||||
@@ -58,33 +48,8 @@
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.surfaceControlsAdvanced {
|
||||
right: 0;
|
||||
bottom: auto;
|
||||
height: 60px;
|
||||
background: color-mix(in srgb, var(--mantine-color-body) 92%, transparent);
|
||||
border-bottom: 1px solid var(--mantine-color-default-border);
|
||||
}
|
||||
|
||||
.surfaceTitle {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 120px;
|
||||
left: 16px;
|
||||
}
|
||||
|
||||
.closeButton {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 2;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.pinButton {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 60px;
|
||||
position: fixed;
|
||||
z-index: 2;
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -141,8 +106,7 @@
|
||||
|
||||
@media (forced-colors: active) {
|
||||
.backdrop {
|
||||
backdrop-filter: none;
|
||||
background: Canvas;
|
||||
opacity: 0.8;
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Box, Portal, RemoveScroll } from "@mantine/core";
|
||||
import { Overlay, Portal } from "@mantine/core";
|
||||
|
||||
import { useEditMode } from "@homarr/boards/edit-mode";
|
||||
|
||||
@@ -14,17 +14,21 @@ interface ActiveFocus {
|
||||
itemId: string;
|
||||
source: HTMLElement;
|
||||
sourceRect: FocusRect;
|
||||
pinned: boolean;
|
||||
activation: "preview" | "manual";
|
||||
autofocusClose: boolean;
|
||||
phase: "visible" | "closing";
|
||||
}
|
||||
|
||||
interface OpenAdvancedFocusOptions {
|
||||
activation?: ActiveFocus["activation"];
|
||||
autofocusClose?: boolean;
|
||||
}
|
||||
|
||||
interface AdvancedFocusContextValue {
|
||||
active: ActiveFocus | null;
|
||||
open: (itemId: string, source: HTMLElement, pinned?: boolean) => void;
|
||||
open: (itemId: string, source: HTMLElement, options?: OpenAdvancedFocusOptions) => void;
|
||||
close: (restoreFocus?: boolean) => void;
|
||||
dismiss: (itemId: string) => void;
|
||||
pin: (autofocusClose?: boolean) => void;
|
||||
hover: (itemId: string, source: HTMLElement) => void;
|
||||
leave: (itemId: string) => void;
|
||||
}
|
||||
@@ -64,7 +68,7 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
}, []);
|
||||
|
||||
const open = useCallback(
|
||||
(itemId: string, source: HTMLElement, pinned = false) => {
|
||||
(itemId: string, source: HTMLElement, options: OpenAdvancedFocusOptions = {}) => {
|
||||
if (isEditMode) return;
|
||||
cancelHoverTimer();
|
||||
cancelCloseTimer();
|
||||
@@ -73,8 +77,8 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
itemId,
|
||||
source,
|
||||
sourceRect: { left: rect.left, top: rect.top, width: rect.width, height: rect.height },
|
||||
pinned,
|
||||
autofocusClose: pinned,
|
||||
activation: options.activation ?? "manual",
|
||||
autofocusClose: options.autofocusClose ?? false,
|
||||
phase: "visible",
|
||||
});
|
||||
},
|
||||
@@ -101,15 +105,23 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
cancelHoverTimer();
|
||||
const hovered = hoveredRef.current;
|
||||
if (!hovered || !shiftHeldRef.current || activeRef.current) return;
|
||||
hoverTimerRef.current = setTimeout(() => open(hovered.itemId, hovered.source), HOVER_DELAY_MS);
|
||||
hoverTimerRef.current = setTimeout(
|
||||
() => open(hovered.itemId, hovered.source, { activation: "preview" }),
|
||||
HOVER_DELAY_MS,
|
||||
);
|
||||
}, [cancelHoverTimer, open]);
|
||||
|
||||
const hover = useCallback(
|
||||
(itemId: string, source: HTMLElement) => {
|
||||
hoveredRef.current = { itemId, source };
|
||||
const current = activeRef.current;
|
||||
if (current?.activation === "preview" && current.itemId !== itemId) {
|
||||
cancelCloseTimer();
|
||||
updateActive(null);
|
||||
}
|
||||
startHoverTimer();
|
||||
},
|
||||
[startHoverTimer],
|
||||
[cancelCloseTimer, startHoverTimer, updateActive],
|
||||
);
|
||||
|
||||
const leave = useCallback(
|
||||
@@ -130,15 +142,6 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
[cancelCloseTimer, cancelHoverTimer, updateActive],
|
||||
);
|
||||
|
||||
const pin = useCallback(
|
||||
(autofocusClose = false) => {
|
||||
const current = activeRef.current;
|
||||
if (!current || current.pinned || current.phase === "closing") return;
|
||||
updateActive({ ...current, pinned: true, autofocusClose });
|
||||
},
|
||||
[updateActive],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape" && activeRef.current) {
|
||||
@@ -151,7 +154,7 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
}
|
||||
if (isEditMode) return;
|
||||
if (event.key !== "Shift" || event.repeat || isEditableTarget(event.target)) return;
|
||||
if (activeRef.current?.pinned) return;
|
||||
if (activeRef.current?.activation === "manual") return;
|
||||
shiftHeldRef.current = true;
|
||||
startHoverTimer();
|
||||
};
|
||||
@@ -159,12 +162,12 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
if (event.key !== "Shift") return;
|
||||
shiftHeldRef.current = false;
|
||||
cancelHoverTimer();
|
||||
if (activeRef.current && !activeRef.current.pinned) close(false);
|
||||
if (activeRef.current?.activation === "preview") close(false);
|
||||
};
|
||||
const handleBlur = () => {
|
||||
shiftHeldRef.current = false;
|
||||
cancelHoverTimer();
|
||||
if (activeRef.current && !activeRef.current.pinned) close(false);
|
||||
if (activeRef.current?.activation === "preview") close(false);
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
@@ -184,20 +187,22 @@ export const BoardAdvancedFocusProvider = ({ children }: PropsWithChildren) => {
|
||||
}, [close, isEditMode]);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({ active, open, close, dismiss, pin, hover, leave }),
|
||||
[active, close, dismiss, hover, leave, open, pin],
|
||||
() => ({ active, open, close, dismiss, hover, leave }),
|
||||
[active, close, dismiss, hover, leave, open],
|
||||
);
|
||||
|
||||
return (
|
||||
<AdvancedFocusContext.Provider value={value}>
|
||||
<RemoveScroll enabled={active !== null} className={classes.focusScope}>
|
||||
{children}
|
||||
</RemoveScroll>
|
||||
{children}
|
||||
{active && (
|
||||
<Portal>
|
||||
<Box
|
||||
<Overlay
|
||||
fixed
|
||||
data-advanced-focus-overlay
|
||||
backgroundOpacity={0.38}
|
||||
blur={0}
|
||||
zIndex="calc(var(--mantine-z-index-modal) - 2)"
|
||||
className={`${classes.backdrop} ${active.phase === "closing" ? classes.backdropClosing : ""}`}
|
||||
onPointerDown={() => close()}
|
||||
aria-hidden
|
||||
/>
|
||||
</Portal>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { isEscapeOwnedByNestedOverlay } from "./escape";
|
||||
describe("isEscapeOwnedByNestedOverlay", () => {
|
||||
test("allows Escape from the advanced surface itself", () => {
|
||||
const surface = document.createElement("section");
|
||||
surface.setAttribute("role", "dialog");
|
||||
surface.setAttribute("role", "region");
|
||||
const button = document.createElement("button");
|
||||
surface.append(button);
|
||||
|
||||
@@ -14,7 +14,7 @@ describe("isEscapeOwnedByNestedOverlay", () => {
|
||||
|
||||
test("leaves Escape to a nested Mantine modal", () => {
|
||||
const surface = document.createElement("section");
|
||||
surface.setAttribute("role", "dialog");
|
||||
surface.setAttribute("role", "region");
|
||||
const modal = document.createElement("section");
|
||||
modal.setAttribute("role", "dialog");
|
||||
const input = document.createElement("input");
|
||||
@@ -25,7 +25,7 @@ describe("isEscapeOwnedByNestedOverlay", () => {
|
||||
|
||||
test.each(["menu", "listbox"])("leaves Escape to a nested %s overlay", (role) => {
|
||||
const surface = document.createElement("section");
|
||||
surface.setAttribute("role", "dialog");
|
||||
surface.setAttribute("role", "region");
|
||||
const overlay = document.createElement("div");
|
||||
overlay.setAttribute("role", role);
|
||||
const target = document.createElement("button");
|
||||
@@ -36,7 +36,7 @@ describe("isEscapeOwnedByNestedOverlay", () => {
|
||||
|
||||
test("honors Mantine's stop-propagation marker for menus and comboboxes", () => {
|
||||
const surface = document.createElement("section");
|
||||
surface.setAttribute("role", "dialog");
|
||||
surface.setAttribute("role", "region");
|
||||
const target = document.createElement("button");
|
||||
target.setAttribute("data-mantine-stop-propagation", "true");
|
||||
surface.append(target);
|
||||
@@ -46,7 +46,7 @@ describe("isEscapeOwnedByNestedOverlay", () => {
|
||||
|
||||
test("does not mistake the compact widget source for a nested overlay", () => {
|
||||
const surface = document.createElement("section");
|
||||
surface.setAttribute("role", "dialog");
|
||||
surface.setAttribute("role", "region");
|
||||
const source = document.createElement("button");
|
||||
|
||||
expect(isEscapeOwnedByNestedOverlay(source, surface)).toBe(false);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getAdvancedFocusRect } from "./geometry";
|
||||
import { getAdvancedFocusClosePosition, getAdvancedFocusRect } from "./geometry";
|
||||
|
||||
describe("getAdvancedFocusRect", () => {
|
||||
it("expands a widget and keeps it inside the viewport", () => {
|
||||
const rect = getAdvancedFocusRect({ left: 10, top: 10, width: 300, height: 200 }, { width: 1200, height: 800 });
|
||||
it("expands around the widget instead of centering a modal", () => {
|
||||
const rect = getAdvancedFocusRect({ left: 450, top: 300, width: 300, height: 200 }, { width: 1200, height: 800 });
|
||||
|
||||
expect(rect.left).toBe(120);
|
||||
expect(rect.top).toBeCloseTo(118.6);
|
||||
expect(rect.width).toBe(960);
|
||||
expect(rect.height).toBeCloseTo(622.8);
|
||||
expect(rect).toEqual({ left: 200, top: 120, width: 800, height: 560 });
|
||||
expect(rect.left + rect.width / 2).toBe(600);
|
||||
expect(rect.top + rect.height / 2).toBe(400);
|
||||
});
|
||||
|
||||
it("uses the available viewport on small screens", () => {
|
||||
@@ -22,9 +21,34 @@ describe("getAdvancedFocusRect", () => {
|
||||
});
|
||||
|
||||
it("keeps controls below the fixed board header on short screens", () => {
|
||||
const rect = getAdvancedFocusRect({ left: 0, top: 0, width: 500, height: 500 }, { width: 1366, height: 768 });
|
||||
const rect = getAdvancedFocusRect({ left: 1200, top: 700, width: 500, height: 500 }, { width: 1366, height: 768 });
|
||||
|
||||
expect(rect.top).toBeGreaterThanOrEqual(84);
|
||||
expect(rect.top + rect.height).toBeLessThanOrEqual(744);
|
||||
expect(rect.left).toBeGreaterThanOrEqual(16);
|
||||
expect(rect.left + rect.width).toBeLessThanOrEqual(1350);
|
||||
expect(rect.top).toBeGreaterThanOrEqual(76);
|
||||
expect(rect.top + rect.height).toBeLessThanOrEqual(752);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAdvancedFocusClosePosition", () => {
|
||||
it("keeps the close control outside the surface when the right side has room", () => {
|
||||
expect(getAdvancedFocusClosePosition({ left: 16, top: 76, width: 800, height: 560 }, 1280)).toEqual({
|
||||
left: 824,
|
||||
top: 76,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the left side when the surface is anchored to the right edge", () => {
|
||||
expect(getAdvancedFocusClosePosition({ left: 464, top: 76, width: 800, height: 560 }, 1280)).toEqual({
|
||||
left: 412,
|
||||
top: 76,
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the inside corner on narrow screens", () => {
|
||||
expect(getAdvancedFocusClosePosition({ left: 8, top: 68, width: 374, height: 624 }, 390)).toEqual({
|
||||
left: 330,
|
||||
top: 76,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,22 +7,48 @@ export interface FocusRect {
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface FocusClosePosition {
|
||||
left: number;
|
||||
top: number;
|
||||
}
|
||||
|
||||
const closeButtonSize = 44;
|
||||
const closeButtonGap = 8;
|
||||
|
||||
export const getAdvancedFocusRect = (source: FocusRect, viewport: { width: number; height: number }): FocusRect => {
|
||||
const margin = viewport.width < 640 ? 8 : 24;
|
||||
const margin = viewport.width < 640 ? 8 : 16;
|
||||
const availableWidth = Math.max(0, viewport.width - margin * 2);
|
||||
const availableHeight = Math.max(0, viewport.height - appShellHeaderHeight - margin * 2);
|
||||
const preferredWidth = viewport.width < 640 ? availableWidth : Math.min(960, availableWidth * 0.9);
|
||||
const preferredHeight = viewport.width < 640 ? availableHeight : Math.min(720, availableHeight * 0.9);
|
||||
const preferredWidth = viewport.width < 640 ? availableWidth : Math.min(800, availableWidth);
|
||||
const preferredHeight = viewport.width < 640 ? availableHeight : Math.min(560, availableHeight);
|
||||
const width = Math.min(availableWidth, Math.max(source.width, preferredWidth));
|
||||
const height = Math.min(availableHeight, Math.max(source.height, preferredHeight));
|
||||
const minimumTop = appShellHeaderHeight + margin;
|
||||
const maximumLeft = Math.max(margin, viewport.width - margin - width);
|
||||
const maximumTop = Math.max(minimumTop, viewport.height - margin - height);
|
||||
|
||||
return {
|
||||
left: Math.max(margin, (viewport.width - width) / 2),
|
||||
top: Math.max(
|
||||
appShellHeaderHeight + margin,
|
||||
appShellHeaderHeight + (viewport.height - appShellHeaderHeight - height) / 2,
|
||||
),
|
||||
left: Math.min(maximumLeft, Math.max(margin, source.left - (width - source.width) / 2)),
|
||||
top: Math.min(maximumTop, Math.max(minimumTop, source.top - (height - source.height) / 2)),
|
||||
width,
|
||||
height,
|
||||
};
|
||||
};
|
||||
|
||||
export const getAdvancedFocusClosePosition = (surface: FocusRect, viewportWidth: number): FocusClosePosition => {
|
||||
const outsideOffset = closeButtonSize + closeButtonGap;
|
||||
const surfaceRight = surface.left + surface.width;
|
||||
|
||||
if (viewportWidth - surfaceRight >= outsideOffset) {
|
||||
return { left: surfaceRight + closeButtonGap, top: surface.top };
|
||||
}
|
||||
|
||||
if (surface.left >= outsideOffset) {
|
||||
return { left: surface.left - outsideOffset, top: surface.top };
|
||||
}
|
||||
|
||||
return {
|
||||
left: Math.max(0, Math.min(viewportWidth - closeButtonSize, surfaceRight - outsideOffset)),
|
||||
top: surface.top + closeButtonGap,
|
||||
};
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { CSSProperties, KeyboardEvent, MutableRefObject, PointerEvent } from "react";
|
||||
import type { CSSProperties, KeyboardEvent, MutableRefObject } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { ActionIcon, Badge, Box, Card, FocusTrap, Text } from "@mantine/core";
|
||||
import { ActionIcon, Badge, Box, Card } from "@mantine/core";
|
||||
import { useElementSize, useViewportSize } from "@mantine/hooks";
|
||||
import { IconMaximize, IconPin, IconX } from "@tabler/icons-react";
|
||||
import { IconMaximize, IconX } from "@tabler/icons-react";
|
||||
import { QueryErrorResetBoundary, useQueryClient } from "@tanstack/react-query";
|
||||
import combineClasses from "clsx";
|
||||
import { NoIntegrationSelectedError } from "@homarr/widgets/errors/classes";
|
||||
@@ -18,7 +18,7 @@ import { WidgetError } from "@homarr/widgets/errors";
|
||||
import type { SectionItem } from "~/app/[locale]/boards/_types";
|
||||
import advancedFocusClasses from "../advanced-focus/advanced-focus.module.css";
|
||||
import { useAdvancedFocus } from "../advanced-focus/context";
|
||||
import { getAdvancedFocusRect } from "../advanced-focus/geometry";
|
||||
import { getAdvancedFocusClosePosition, getAdvancedFocusRect } from "../advanced-focus/geometry";
|
||||
import classes from "../sections/item.module.css";
|
||||
import { useItemActions } from "./item-actions";
|
||||
import itemContentClasses from "./item-content.module.css";
|
||||
@@ -43,42 +43,43 @@ export const BoardItemContent = ({ item }: BoardItemContentProps) => {
|
||||
const board = useRequiredBoard();
|
||||
const t = useI18n();
|
||||
const widgetName = t(`widget.${item.kind}.name`);
|
||||
const advancedDialogLabel = t("item.advancedFocus.dialog", { widget: widgetName });
|
||||
const advancedViewLabel = t("item.advancedFocus.label", { widget: widgetName });
|
||||
const [isEditMode] = useEditMode();
|
||||
const widgetStateRef = useRef<Record<string, unknown> | null>(null);
|
||||
const { active, open, close, dismiss, pin, hover, leave } = useAdvancedFocus();
|
||||
const activeFocus = active?.itemId === item.id ? active : null;
|
||||
const closeButtonRef = useRef<HTMLButtonElement>(null);
|
||||
const { active, open, close, dismiss, hover, leave } = useAdvancedFocus();
|
||||
const supportsAdvancedFocus = item.kind !== "app";
|
||||
const advancedViewId = `advanced-focus-${item.id}`;
|
||||
const activeFocus = supportsAdvancedFocus && active?.itemId === item.id ? active : null;
|
||||
const isAdvanced = activeFocus !== null;
|
||||
const advancedRect = activeFocus
|
||||
? getAdvancedFocusRect(activeFocus.sourceRect, { width: viewportWidth, height: viewportHeight })
|
||||
: null;
|
||||
const closePosition = advancedRect ? getAdvancedFocusClosePosition(advancedRect, viewportWidth) : null;
|
||||
|
||||
// Responsive layout changes remount grid items. Never leave their focus backdrop orphaned.
|
||||
useEffect(() => () => dismiss(item.id), [dismiss, item.id]);
|
||||
|
||||
const openPinned = () => {
|
||||
if (sourceRef.current) open(item.id, sourceRef.current, true);
|
||||
useEffect(() => {
|
||||
if (!activeFocus?.autofocusClose || activeFocus.phase !== "visible") return;
|
||||
const frame = requestAnimationFrame(() => closeButtonRef.current?.focus());
|
||||
return () => cancelAnimationFrame(frame);
|
||||
}, [activeFocus?.autofocusClose, activeFocus?.phase]);
|
||||
|
||||
const openAdvanced = (autofocusClose = false) => {
|
||||
if (sourceRef.current) open(item.id, sourceRef.current, { activation: "manual", autofocusClose });
|
||||
};
|
||||
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (event.currentTarget !== event.target || event.key !== "Enter" || !event.shiftKey || isEditMode) return;
|
||||
if (
|
||||
event.currentTarget !== event.target ||
|
||||
event.key !== "Enter" ||
|
||||
!event.shiftKey ||
|
||||
isEditMode ||
|
||||
!supportsAdvancedFocus
|
||||
)
|
||||
return;
|
||||
event.preventDefault();
|
||||
openPinned();
|
||||
};
|
||||
const handleSurfacePointerDown = (event: PointerEvent<HTMLDivElement>) => {
|
||||
if (!activeFocus || activeFocus.pinned) return;
|
||||
|
||||
const target =
|
||||
event.target instanceof Element
|
||||
? event.target.closest<HTMLElement>(
|
||||
"a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), iframe, [tabindex]:not([tabindex='-1']), [contenteditable='true']",
|
||||
)
|
||||
: null;
|
||||
const alreadyAutofocused = target?.hasAttribute("data-autofocus") ?? false;
|
||||
if (target && !alreadyAutofocused) target.setAttribute("data-autofocus", "true");
|
||||
pin(false);
|
||||
if (target && !alreadyAutofocused) {
|
||||
window.setTimeout(() => target.removeAttribute("data-autofocus"), 250);
|
||||
}
|
||||
openAdvanced(true);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -86,15 +87,21 @@ export const BoardItemContent = ({ item }: BoardItemContentProps) => {
|
||||
<WidgetContextMenu item={item} widgetStateRef={widgetStateRef} sourceRef={sourceRef}>
|
||||
<Box
|
||||
ref={sourceRef}
|
||||
tabIndex={isEditMode ? undefined : 0}
|
||||
role={isEditMode ? undefined : "group"}
|
||||
aria-label={isEditMode ? undefined : `${widgetName}: ${t("item.advancedFocus.open")}`}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={isAdvanced}
|
||||
aria-keyshortcuts="Shift+Enter"
|
||||
onKeyDown={handleKeyDown}
|
||||
onPointerEnter={() => sourceRef.current && hover(item.id, sourceRef.current)}
|
||||
onPointerLeave={() => leave(item.id)}
|
||||
tabIndex={!isEditMode && supportsAdvancedFocus ? 0 : undefined}
|
||||
role={!isEditMode && supportsAdvancedFocus ? "group" : undefined}
|
||||
aria-label={
|
||||
!isEditMode && supportsAdvancedFocus ? `${widgetName}: ${t("item.advancedFocus.open")}` : undefined
|
||||
}
|
||||
aria-expanded={supportsAdvancedFocus ? isAdvanced : undefined}
|
||||
aria-controls={isAdvanced ? advancedViewId : undefined}
|
||||
aria-keyshortcuts={supportsAdvancedFocus ? "Shift+Enter" : undefined}
|
||||
onKeyDown={supportsAdvancedFocus ? handleKeyDown : undefined}
|
||||
onPointerEnter={() => {
|
||||
if (supportsAdvancedFocus && sourceRef.current) hover(item.id, sourceRef.current);
|
||||
}}
|
||||
onPointerLeave={() => {
|
||||
if (supportsAdvancedFocus) leave(item.id);
|
||||
}}
|
||||
className={combineClasses("grid-stack-item-content", isAdvanced && advancedFocusClasses.sourcePlaceholder)}
|
||||
>
|
||||
<div
|
||||
@@ -103,105 +110,82 @@ export const BoardItemContent = ({ item }: BoardItemContentProps) => {
|
||||
isAdvanced && advancedFocusClasses.surfaceHostAdvanced,
|
||||
)}
|
||||
>
|
||||
<FocusTrap active={Boolean(activeFocus?.pinned)}>
|
||||
<Card
|
||||
role={isAdvanced ? "dialog" : undefined}
|
||||
aria-modal={activeFocus?.pinned || undefined}
|
||||
aria-label={isAdvanced ? advancedDialogLabel : undefined}
|
||||
radius={board.itemRadius}
|
||||
p={isAdvanced ? undefined : 0}
|
||||
h={isAdvanced ? undefined : "100%"}
|
||||
w={isAdvanced ? undefined : "100%"}
|
||||
className={combineClasses(
|
||||
classes.itemCard,
|
||||
`${item.kind}-wrapper`,
|
||||
isAdvanced && advancedFocusClasses.surface,
|
||||
activeFocus?.phase === "closing" && advancedFocusClasses.surfaceClosing,
|
||||
item.advancedOptions.customCssClasses.join(" "),
|
||||
)}
|
||||
onPointerDownCapture={isAdvanced ? handleSurfacePointerDown : undefined}
|
||||
styles={{
|
||||
root: {
|
||||
"--opacity": isAdvanced ? 0.98 : board.opacity / 100,
|
||||
containerType: "size",
|
||||
overflow: getOverflowFromKind(item.kind),
|
||||
"--border-color":
|
||||
item.advancedOptions.borderColor !== "" ? item.advancedOptions.borderColor : undefined,
|
||||
},
|
||||
}}
|
||||
style={
|
||||
activeFocus && advancedRect
|
||||
? ({
|
||||
left: advancedRect.left,
|
||||
top: advancedRect.top,
|
||||
width: advancedRect.width,
|
||||
height: advancedRect.height,
|
||||
"--focus-translate-x": `${activeFocus.sourceRect.left - advancedRect.left}px`,
|
||||
"--focus-translate-y": `${activeFocus.sourceRect.top - advancedRect.top}px`,
|
||||
"--focus-scale-x": activeFocus.sourceRect.width / advancedRect.width,
|
||||
"--focus-scale-y": activeFocus.sourceRect.height / advancedRect.height,
|
||||
} as CSSProperties)
|
||||
: undefined
|
||||
}
|
||||
{activeFocus?.activation === "manual" && closePosition && (
|
||||
<ActionIcon
|
||||
ref={closeButtonRef}
|
||||
className={advancedFocusClasses.closeButton}
|
||||
variant="default"
|
||||
size={44}
|
||||
aria-label={t("item.advancedFocus.close")}
|
||||
aria-controls={advancedViewId}
|
||||
style={closePosition}
|
||||
onClick={() => close()}
|
||||
>
|
||||
<div
|
||||
className={combineClasses(
|
||||
advancedFocusClasses.surfaceControls,
|
||||
isAdvanced && advancedFocusClasses.surfaceControlsAdvanced,
|
||||
)}
|
||||
>
|
||||
{isAdvanced && (
|
||||
<Text className={advancedFocusClasses.surfaceTitle} size="sm" fw={600} truncate>
|
||||
{advancedDialogLabel}
|
||||
</Text>
|
||||
)}
|
||||
{isAdvanced && (
|
||||
<ActionIcon
|
||||
data-autofocus={activeFocus.pinned && activeFocus.autofocusClose ? true : undefined}
|
||||
className={advancedFocusClasses.closeButton}
|
||||
variant="default"
|
||||
size={44}
|
||||
aria-label={t("item.advancedFocus.close")}
|
||||
onClick={() => close()}
|
||||
>
|
||||
<IconX size={18} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
{isAdvanced && (
|
||||
<ActionIcon
|
||||
className={advancedFocusClasses.pinButton}
|
||||
variant={activeFocus.pinned ? "filled" : "default"}
|
||||
size={44}
|
||||
aria-label={activeFocus.pinned ? t("item.advancedFocus.pinned") : t("item.advancedFocus.pin")}
|
||||
aria-pressed={activeFocus.pinned}
|
||||
onClick={(event) => pin(event.detail === 0)}
|
||||
>
|
||||
<IconPin size={18} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
{!isEditMode && !isAdvanced && (
|
||||
<ActionIcon
|
||||
className={advancedFocusClasses.touchButton}
|
||||
variant="default"
|
||||
size={44}
|
||||
aria-label={t("item.advancedFocus.open")}
|
||||
onClick={openPinned}
|
||||
>
|
||||
<IconMaximize size={18} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
</div>
|
||||
<Box ref={contentRef} w="100%" h="100%" mih={0}>
|
||||
<InnerContent
|
||||
item={item}
|
||||
width={width}
|
||||
height={height}
|
||||
widgetStateRef={widgetStateRef}
|
||||
displayMode={isAdvanced ? "advanced" : "compact"}
|
||||
/>
|
||||
</Box>
|
||||
</Card>
|
||||
</FocusTrap>
|
||||
<IconX size={18} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
<Card
|
||||
id={isAdvanced ? advancedViewId : undefined}
|
||||
role={isAdvanced ? "region" : undefined}
|
||||
aria-label={isAdvanced ? advancedViewLabel : undefined}
|
||||
radius={board.itemRadius}
|
||||
p={isAdvanced ? undefined : 0}
|
||||
h={isAdvanced ? undefined : "100%"}
|
||||
w={isAdvanced ? undefined : "100%"}
|
||||
className={combineClasses(
|
||||
classes.itemCard,
|
||||
`${item.kind}-wrapper`,
|
||||
isAdvanced && advancedFocusClasses.surface,
|
||||
activeFocus?.phase === "closing" && advancedFocusClasses.surfaceClosing,
|
||||
item.advancedOptions.customCssClasses.join(" "),
|
||||
)}
|
||||
styles={{
|
||||
root: {
|
||||
"--opacity": isAdvanced ? 0.98 : board.opacity / 100,
|
||||
containerType: "size",
|
||||
overflow: getOverflowFromKind(item.kind),
|
||||
"--border-color":
|
||||
item.advancedOptions.borderColor !== "" ? item.advancedOptions.borderColor : undefined,
|
||||
},
|
||||
}}
|
||||
style={
|
||||
activeFocus && advancedRect
|
||||
? ({
|
||||
left: advancedRect.left,
|
||||
top: advancedRect.top,
|
||||
width: advancedRect.width,
|
||||
height: advancedRect.height,
|
||||
"--focus-translate-x": `${activeFocus.sourceRect.left - advancedRect.left}px`,
|
||||
"--focus-translate-y": `${activeFocus.sourceRect.top - advancedRect.top}px`,
|
||||
"--focus-scale-x": activeFocus.sourceRect.width / advancedRect.width,
|
||||
"--focus-scale-y": activeFocus.sourceRect.height / advancedRect.height,
|
||||
} as CSSProperties)
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<div className={advancedFocusClasses.surfaceControls}>
|
||||
{!isEditMode && supportsAdvancedFocus && !isAdvanced && (
|
||||
<ActionIcon
|
||||
className={advancedFocusClasses.touchButton}
|
||||
variant="default"
|
||||
size={44}
|
||||
aria-label={t("item.advancedFocus.open")}
|
||||
onClick={() => openAdvanced()}
|
||||
>
|
||||
<IconMaximize size={18} />
|
||||
</ActionIcon>
|
||||
)}
|
||||
</div>
|
||||
<Box ref={contentRef} w="100%" h="100%" mih={0}>
|
||||
<InnerContent
|
||||
item={item}
|
||||
width={width}
|
||||
height={height}
|
||||
widgetStateRef={widgetStateRef}
|
||||
displayMode={isAdvanced ? "advanced" : "compact"}
|
||||
/>
|
||||
</Box>
|
||||
</Card>
|
||||
</div>
|
||||
</Box>
|
||||
</WidgetContextMenu>
|
||||
|
||||
@@ -283,11 +283,6 @@ const WidgetItem = ({
|
||||
{item.description}
|
||||
</Text>
|
||||
</Tooltip>
|
||||
{hasMatchingIntegration && (
|
||||
<Text size="10px" c="blue.6" fw={600}>
|
||||
{t("item.create.integrationAvailable")}
|
||||
</Text>
|
||||
)}
|
||||
<SupportedIntegrations integrations={item.supportedIntegrations} />
|
||||
</Stack>
|
||||
<Box
|
||||
|
||||
@@ -250,17 +250,21 @@ export const WidgetContextMenu = ({ item, widgetStateRef, sourceRef, children }:
|
||||
>
|
||||
<Menu.ContextMenu>{children}</Menu.ContextMenu>
|
||||
<Menu.Dropdown>
|
||||
<Menu.Item
|
||||
closeMenuOnClick
|
||||
leftSection={<IconMaximize size={16} />}
|
||||
onClick={() => {
|
||||
if (sourceRef.current) openAdvancedFocus(item.id, sourceRef.current, true);
|
||||
}}
|
||||
disabled={isEditMode}
|
||||
>
|
||||
{t("item.advancedFocus.open")}
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
{item.kind !== "app" && (
|
||||
<>
|
||||
<Menu.Item
|
||||
closeMenuOnClick
|
||||
leftSection={<IconMaximize size={16} />}
|
||||
onClick={() => {
|
||||
if (sourceRef.current) openAdvancedFocus(item.id, sourceRef.current);
|
||||
}}
|
||||
disabled={isEditMode}
|
||||
>
|
||||
{t("item.advancedFocus.open")}
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
</>
|
||||
)}
|
||||
{toggleOptions.length > 0 && (
|
||||
<>
|
||||
<Menu.Label>{tMenu("options")}</Menu.Label>
|
||||
|
||||
Reference in new issue
Block a user