Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes context menu hit test to deal with svg nodes. #7242

Merged
merged 2 commits into from Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/application/src/frontend.ts
Expand Up @@ -105,8 +105,8 @@ export abstract class JupyterFrontEnd<

/**
* Walks up the DOM hierarchy of the target of the active `contextmenu`
* event, testing the nodes for a user-supplied funcion. This can
* be used to find a node on which to operate, given a context menu click.
* event, testing each HTMLElement ancestor for a user-supplied funcion. This can
* be used to find an HTMLElement on which to operate, given a context menu click.
*
* @param test - a function that takes an `HTMLElement` and returns a
* boolean for whether it is the element the requester is seeking.
Expand All @@ -118,16 +118,16 @@ export abstract class JupyterFrontEnd<
): HTMLElement | undefined {
if (
!this._contextMenuEvent ||
!(this._contextMenuEvent.target instanceof HTMLElement)
!(this._contextMenuEvent.target instanceof Node)
) {
return undefined;
}
let node = this._contextMenuEvent.target as HTMLElement;
let node = this._contextMenuEvent.target;
do {
if (test(node)) {
if (node instanceof HTMLElement && test(node)) {
return node;
}
node = node.parentNode as HTMLElement;
node = node.parentNode;
} while (node && node.parentNode && node !== node.parentNode);
return undefined;

Expand Down
57 changes: 37 additions & 20 deletions packages/ui-components/src/style/icon.ts
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { cssRule, style } from 'typestyle/lib';
import { style } from 'typestyle/lib';
import { NestedCSSProperties } from 'typestyle/lib/types';

/**
Expand Down Expand Up @@ -66,14 +66,15 @@ const iconCSSBreadCrumb: NestedCSSProperties = {
height: '16px',
width: '16px',
verticalAlign: 'middle',
// `&` will be substituted for the generated classname (interpolation)
$nest: {
'&:hover': {
backgroundColor: 'var(--jp-layout-color2)'
},
'&:first-child': {
marginLeft: '0px'
},
['.jp-mod-dropTarget']: {
['.jp-mod-dropTarget&']: {
backgroundColor: 'var(--jp-brand-color2)',
opacity: 0.7
}
Expand Down Expand Up @@ -175,7 +176,36 @@ const containerCSSSettingsEditor: NestedCSSProperties = {
};

const containerCSSSideBar: NestedCSSProperties = {
transform: 'rotate(90deg)'
// `&` will be substituted for the generated classname (interpolation)
$nest: {
// left sidebar tab divs
'.jp-SideBar.jp-mod-left .p-TabBar-tab &': {
transform: 'rotate(90deg)'
},
// left sidebar currently selected tab div
'.jp-SideBar.jp-mod-left .p-TabBar-tab.p-mod-current &': {
transform:
'rotate(90deg)\n' +
' translate(\n' +
' calc(-0.5 * var(--jp-border-width)),\n' +
' calc(-0.5 * var(--jp-border-width))\n' +
' )'
},

// right sidebar tab divs
'.jp-SideBar.jp-mod-right .p-TabBar-tab &': {
transform: 'rotate(-90deg)'
},
// right sidebar currently selected tab div
'.jp-SideBar.jp-mod-right .p-TabBar-tab.p-mod-current &': {
transform:
'rotate(-90deg)\n' +
' translate(\n' +
' calc(0.5 * var(--jp-border-width)),\n' +
' calc(-0.5 * var(--jp-border-width))\n' +
' )'
}
}
};

const containerCSSSplash: NestedCSSProperties = {
Expand Down Expand Up @@ -236,9 +266,12 @@ function containerCSS(props: IIconStyle): NestedCSSProperties {
* for setting the style on the container of an svg node representing an icon
*/
export const iconStyle = (props: IIconStyle): string => {
const conCSS = containerCSS(props);

return style({
...containerCSS(props),
...conCSS,
$nest: {
...conCSS.$nest,
['svg']: iconCSS(props)
}
});
Expand All @@ -250,19 +283,3 @@ export const iconStyle = (props: IIconStyle): string => {
export const iconStyleFlat = (props: IIconStyle): string => {
return style(iconCSS(props));
};

// TODO: Figure out a better cludge for styling current sidebar tab selection
cssRule(
`.p-TabBar-tab.p-mod-current .${iconStyle({
center: true,
kind: 'sideBar'
})}`,
{
transform:
'rotate(90deg)\n' +
' translate(\n' +
' calc(-0.5 * var(--jp-border-width)),\n' +
' calc(-0.5 * var(--jp-border-width))\n' +
' )'
}
);