Skip to content

Commit

Permalink
Add hover effect to header menus
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Feb 14, 2024
1 parent 0f9b617 commit cf6c69a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/internal/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
// else we will assume doesn't need it.
needsHoverPosition = rendererNeeds ?? toCheck.kind === GridCellKind.Custom;
needsDamageCell = needsHoverPosition;
} else if (args.kind === groupHeaderKind) {
} else {
needsDamageCell = true;
}

Expand Down Expand Up @@ -1517,6 +1517,8 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
false,
theme,
false,
undefined,
undefined,
false,
0,
spriteManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function drawGridHeaders(
ctx.fillStyle = outerTheme.bgHeader;
ctx.fillRect(0, 0, width, totalHeaderHeight);

const [hCol, hRow] = hovered?.[0] ?? [];
const hCol = hovered?.[0]?.[0];
const hRow = hovered?.[0]?.[1];
const hPosX = hovered?.[1]?.[0];
const hPosY = hovered?.[1]?.[1];

const font = outerTheme.headerFontFull;
// Assinging the context font too much can be expensive, it can be worth it to minimze this
Expand Down Expand Up @@ -115,6 +118,8 @@ export function drawGridHeaders(
selected,
theme,
hoveredBoolean,
hoveredBoolean ? hPosX : undefined,
hoveredBoolean ? hPosY : undefined,
hasSelectedCell,
hover,
spriteManager,
Expand Down Expand Up @@ -415,6 +420,8 @@ function drawHeaderInner(
selected: boolean,
theme: FullTheme,
isHovered: boolean,
posX: number | undefined,
posY: number | undefined,
hoverAmount: number,
spriteManager: SpriteManager,
touchMode: boolean,
Expand Down Expand Up @@ -533,6 +540,12 @@ function drawHeaderInner(
if (shouldDrawMenu && headerLayout.menuBounds !== undefined) {
const menuBounds = headerLayout.menuBounds;

const hovered = posX !== undefined && posY !== undefined && pointInRect(menuBounds, posX + x, posY + y);

if (!hovered) {
ctx.globalAlpha = 0.7;
}

if (c.menuIcon === undefined || c.menuIcon === GridColumnMenuIcon.Triangle) {
// Draw the default triangle menu icon:
ctx.beginPath();
Expand Down Expand Up @@ -572,6 +585,10 @@ function drawHeaderInner(
const iconY = menuBounds.y + (menuBounds.height - theme.headerIconSize) / 2;
spriteManager.drawSprite(c.menuIcon, "normal", ctx, iconX, iconY, theme.headerIconSize, theme);
}

if (!hovered) {
ctx.globalAlpha = 1;
}
}
}

Expand All @@ -585,6 +602,8 @@ export function drawHeader(
selected: boolean,
theme: FullTheme,
isHovered: boolean,
posX: number | undefined,
posY: number | undefined,
hasSelectedCell: boolean,
hoverAmount: number,
spriteManager: SpriteManager,
Expand Down Expand Up @@ -620,6 +639,8 @@ export function drawHeader(
selected,
theme,
isHovered,
posX,
posY,
hoverAmount,
spriteManager,
touchMode,
Expand All @@ -638,6 +659,8 @@ export function drawHeader(
selected,
theme,
isHovered,
posX,
posY,
hoverAmount,
spriteManager,
touchMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { EnqueueCallback } from "../use-animation-queue.js";
import type { ImageWindowLoader } from "../image-window-loader-interface.js";
import type { GroupDetailsCallback, GetRowThemeCallback, Highlight } from "./data-grid-render.cells.js";

export type HoverInfo = readonly [Item, Item];
export type HoverInfo = readonly [Item, readonly [number, number]];

export interface DragAndDropState {
src: number;
Expand Down

0 comments on commit cf6c69a

Please sign in to comment.