Skip to content

Commit

Permalink
fix: show copy cursor in grid on key down and not just mouse move (#1735
Browse files Browse the repository at this point in the history
)

- Adds copy cell key handler to set cursor on key down. Grid was only
showing copy cursor on mouse move, not just key down. Unfortunately we
still require focus to get the key down, and I don't think it's worth
hacking around that.
- Moved cursor styles to linker and irisgrid css respectively, so that
it is shared to DHE. AppMainContainer.css isn't used in DHE.
- Moved cursors and logos in to asset folder (folders named "assets" are
bundled by Vite
- Tweaked copy icon svg (aliasing is improved)
- default cursor to "copy" in iris grid so that it shows in embed widget
and DHE

BREAKING CHANGE: linker and iris grid custom cursor styling and assets
are now provided by components directly. DHE css and svg files
containing linker cursors should be removed/de-duplicated.
  • Loading branch information
dsmmcken authored Feb 7, 2024
1 parent 33c6a8d commit 0781900
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 57 deletions.
15 changes: 0 additions & 15 deletions packages/code-studio/src/assets/svg/cursor-copy.svg

This file was deleted.

28 changes: 0 additions & 28 deletions packages/code-studio/src/main/AppMainContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ $tab-link-disabled-color: $gray-600;

$nav-space: 4px; // give a gap around some buttons for focus area that are in nav bar

.grid-cursor-copy {
cursor:
url('../assets/svg/cursor-copy.svg') 8 8,
copy;
}

.grid-cursor-linker {
cursor:
url('../assets/svg/cursor-linker.svg') 8 8,
crosshair;
}

.grid-cursor-linker-not-allowed {
cursor:
url('../assets/svg/cursor-linker-not-allowed.svg') 8 8,
not-allowed;
}

.linker-overlay path.link-select {
cursor: pointer;
}

.linker-overlay.danger-delete path.link-select {
cursor:
url('../assets/svg/cursor-unlinker.svg') 8 8,
pointer;
}

.app-main-top-nav-menus {
display: flex;
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dist",
"scss",
"css",
"logos"
"assets"
],
"sideEffects": [
"*.css"
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/theme/Logo.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:root {
--dh-logo-dark-img: url('../../logos/community-wordmark-dark.svg');
--dh-logo-light-img: url('../../logos/community-wordmark-light.svg');
--dh-logo-dark-img: url('../../assets/logos/community-wordmark-dark.svg');
--dh-logo-light-img: url('../../assets/logos/community-wordmark-light.svg');
}

.dh-logo {
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard-core-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"@deephaven/mocks": "file:../mocks"
},
"files": [
"dist"
"dist",
"assets"
],
"sideEffects": [
"*.css"
Expand Down
6 changes: 6 additions & 0 deletions packages/dashboard-core-plugins/src/linker/LinkerLink.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ $dash-size: 10;
}

&.danger-delete {
path.link-select {
cursor:
url('../assets/svg/cursor-unlinker.svg') 8 8,
pointer;
}

path.link-select:hover ~ path.link-background {
stroke: $dash-delete-color-2;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/dashboard-core-plugins/src/panels/IrisGridPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ $panel-message-overlay-top: 30px;
color: $danger;
}
}

.grid-cursor-linker {
cursor: crosshair;
}

.grid-cursor-copy {
cursor: copy;
}
5 changes: 5 additions & 0 deletions packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1736,18 +1736,23 @@ class Grid extends PureComponent<GridProps, GridState> {
event: GridKeyboardEvent
): void {
const keyHandlers = this.getKeyHandlers();
let cursor = null;
for (let i = 0; i < keyHandlers.length; i += 1) {
const keyHandler = keyHandlers[i];
const result =
keyHandler[functionName] != null &&
keyHandler[functionName](event, this);
if (result !== false) {
if (keyHandler.cursor != null) {
({ cursor } = keyHandler);
}
const options = result as EventHandlerResultOptions;
if (options?.stopPropagation ?? true) event.stopPropagation();
if (options?.preventDefault ?? true) event.preventDefault();
break;
}
}
this.setState({ cursor });
}

handleKeyDown(event: GridKeyboardEvent): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/grid/src/KeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class KeyHandler {
this.order = order;
}

// Cursor to use if this returns any truthy value including { stopPropagation: false, preventDefault: false }
cursor: string | null = null;

/**
* Handle a keydown event on the grid.
* @param event The keyboard event
Expand Down
14 changes: 14 additions & 0 deletions packages/iris-grid/assets/svg/cursor-copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/iris-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"@deephaven/mocks": "file:../mocks"
},
"files": [
"dist"
"dist",
"assets"
],
"sideEffects": [
"*.css"
Expand Down
18 changes: 18 additions & 0 deletions packages/iris-grid/src/IrisGrid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ $cell-invalid-box-shadow:
position: relative;
}

.grid-cursor-copy {
cursor:
url('../assets/svg/cursor-copy.svg') 8 8,
copy;
}

.grid-cursor-linker {
cursor:
url('../assets/svg/cursor-linker.svg') 8 8,
crosshair;
}

.grid-cursor-linker-not-allowed {
cursor:
url('../assets/svg/cursor-linker-not-allowed.svg') 8 8,
not-allowed;
}

.table-sidebar {
height: 100%;
flex: 0 0 $table-sidebar-max-width;
Expand Down
4 changes: 3 additions & 1 deletion packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import PendingDataBottomBar from './PendingDataBottomBar';
import IrisGridCopyHandler, { CopyOperation } from './IrisGridCopyHandler';
import FilterInputField from './FilterInputField';
import {
CopyCellKeyHandler,
ClearFilterKeyHandler,
CopyKeyHandler,
ReverseKeyHandler,
Expand Down Expand Up @@ -497,7 +498,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
columnSelectionValidator: null,
columnAllowedCursor: null,
columnNotAllowedCursor: null,
copyCursor: null,
copyCursor: 'copy',
name: 'table',
onlyFetchVisibleColumns: true,
showSearchBar: false,
Expand Down Expand Up @@ -709,6 +710,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {

const { dh } = model;
const keyHandlers: KeyHandler[] = [
new CopyCellKeyHandler(this),
new ReverseKeyHandler(this),
new ClearFilterKeyHandler(this),
];
Expand Down
45 changes: 45 additions & 0 deletions packages/iris-grid/src/key-handlers/CopyCellKeyHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { KeyboardEvent } from 'react';
import { KeyHandler } from '@deephaven/grid';
import { ContextActionUtils } from '@deephaven/components';
import type { Grid } from '@deephaven/grid';
import { IrisGrid } from '../IrisGrid';

class CopyCellKeyHandler extends KeyHandler {
private irisGrid: IrisGrid;

constructor(irisGrid: IrisGrid) {
super();

this.irisGrid = irisGrid;
this.cursor = null;
}

onDown(event: KeyboardEvent, grid: Grid): boolean {
if (
event.altKey &&
!ContextActionUtils.isModifierKeyDown(event) &&
!event.shiftKey
) {
const { mouseX, mouseY } = grid.state;
if (mouseX == null || mouseY == null) {
return false;
}
const gridPoint = grid.getGridPointFromXY(mouseX, mouseY);
if (gridPoint.column != null && gridPoint.row != null) {
this.cursor = this.irisGrid.props.copyCursor;
return true;
}
}
return false;
}

onUp(event: KeyboardEvent, grid: Grid): boolean {
if (this.cursor === this.irisGrid.props.copyCursor) {
this.cursor = null;
return true;
}
return false;
}
}

export default CopyCellKeyHandler;
1 change: 1 addition & 0 deletions packages/iris-grid/src/key-handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as CopyCellKeyHandler } from './CopyCellKeyHandler';
export { default as CopyKeyHandler } from './CopyKeyHandler';
export { default as ReverseKeyHandler } from './ReverseKeyHandler';
export { default as ClearFilterKeyHandler } from './ClearFilterKeyHandler';

0 comments on commit 0781900

Please sign in to comment.