Skip to content

Commit

Permalink
fixed check mark icons in CommandPaletteSvg
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Feb 22, 2020
1 parent 821537c commit 83c39a6
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/application/src/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export abstract class JupyterFrontEnd<
* Construct a new JupyterFrontEnd object.
*/
constructor(options: JupyterFrontEnd.IOptions<T>) {
// render context menu with svg icon tweaks
// render context menu with inline svg icon tweaks
options.contextMenuRenderer =
options.contextMenuRenderer || MenuSvg.defaultRenderer;

Expand Down
8 changes: 6 additions & 2 deletions packages/apputils-extension/src/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CommandPalette } from '@lumino/widgets';

import { ILayoutRestorer, JupyterFrontEnd } from '@jupyterlab/application';
import { ICommandPalette, IPaletteItem } from '@jupyterlab/apputils';
import { paletteIcon } from '@jupyterlab/ui-components';
import { CommandPaletteSvg, paletteIcon } from '@jupyterlab/ui-components';

/**
* The command IDs used by the apputils extension.
Expand Down Expand Up @@ -141,7 +141,11 @@ namespace Private {
*/
export function createPalette(app: JupyterFrontEnd): CommandPalette {
if (!palette) {
palette = new CommandPalette({ commands: app.commands });
// use a renderer tweaked to use inline svg icons
palette = new CommandPalette({
commands: app.commands,
renderer: CommandPaletteSvg.defaultRenderer
});
palette.id = 'command-palette';
palette.title.icon = paletteIcon;
palette.title.label = 'Commands';
Expand Down
8 changes: 1 addition & 7 deletions packages/apputils/style/commandpalette.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,8 @@
color: var(--jp-ui-font-color3);
}

.lm-CommandPalette-item.lm-mod-toggled .lm-CommandPalette-itemIcon {
background-image: var(--jp-icon-check);
background-size: 16px;
background-repeat: no-repeat;
}

.lm-CommandPalette-item .lm-CommandPalette-itemIcon {
padding: 0px 0px 0px 4px;
margin: 0 4px 0 0;
position: relative;
width: 16px;
top: 2px;
Expand Down
4 changes: 2 additions & 2 deletions packages/mainmenu/src/labmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class JupyterLabMenu implements IJupyterLabMenu {
* groups that are added to the menu.
*/
constructor(options: Menu.IOptions, includeSeparators: boolean = true) {
// render menu with svg icon tweaks
// render menu with inline svg icon tweaks
this.menu = new MenuSvg(options);
this._includeSeparators = includeSeparators;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ export class JupyterLabMenu implements IJupyterLabMenu {
/**
* The underlying Phosphor menu.
*/
readonly menu: MenuSvg;
readonly menu: Menu;

/**
* Whether the menu has been disposed.
Expand Down
68 changes: 68 additions & 0 deletions packages/ui-components/src/icon/commandpalettesvg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { h, VirtualElement } from '@lumino/virtualdom';
import { CommandPalette } from '@lumino/widgets';

import { checkIcon } from './iconimports';
import { iconStyle } from '../style';
import { classes } from '../utils';

// const submenuIcon = caretRightIcon.bindprops({
// justify: 'center',
// kind: 'menuItem'
// });

export namespace CommandPaletteSvg {
/**
* a modified implementation of the CommandPalette Renderer
*/
export class Renderer extends CommandPalette.Renderer {
/**
* Render the icon for a command palette item.
*
* @param data - The data to use for rendering the icon.
*
* @returns A virtual element representing the icon.
*/
renderItemIcon(data: CommandPalette.IItemRenderData): VirtualElement {
let className = this.createIconClass(data);

if (data.item.isToggled) {
// check mark icon takes precedence
return h.div({ className }, checkIcon, data.item.iconLabel);
}

/* <DEPRECATED> */
if (typeof data.item.icon === 'string') {
return h.div({ className }, data.item.iconLabel);
}
/* </DEPRECATED> */

// if data.item.icon is undefined, it will be ignored
return h.div({ className }, data.item.icon!, data.item.iconLabel);
}

/**
* Create the class name for the command item icon.
*
* @param data - The data to use for the class name.
*
* @returns The full class name for the item icon.
*/
createIconClass(data: CommandPalette.IItemRenderData): string {
let name = 'lm-CommandPalette-itemIcon';
/* <DEPRECATED> */
name += ' p-CommandPalette-itemIcon';
/* </DEPRECATED> */

return classes(
iconStyle({ justify: 'center', kind: 'commandPaletteItem' }),
data.item.iconClass,
name
);
}
}

export const defaultRenderer = new Renderer();
}
2 changes: 2 additions & 0 deletions packages/ui-components/src/icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@

export * from './iconimports';
export * from './labicon';

export * from './commandpalettesvg';
export * from './menusvg';
export * from './tabbarsvg';
2 changes: 1 addition & 1 deletion packages/ui-components/src/icon/menusvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class MenuSvg extends Menu {
*/
insertItem(index: number, options: Menu.IItemOptions): Menu.IItem {
if (options.submenu?.renderer === Menu.defaultRenderer) {
//
// create a "view" of the submenu with a different default renderer
const submenu = Object.create(options.submenu, {
renderer: {
configurable: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/ui-components/src/style/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { NestedCSSProperties } from 'typestyle/lib/types';
*/
export type IconKindType =
| 'breadCrumb'
| 'commandPaletteItem'
| 'launcherCard'
| 'launcherSection'
| 'listing'
Expand Down Expand Up @@ -58,6 +59,11 @@ const iconCSSBreadCrumb: NestedCSSProperties = {
verticalAlign: 'middle'
};

const iconCSSCommandPaletteItem: NestedCSSProperties = {
height: '16px',
width: '16px'
};

const iconCSSLauncherCard: NestedCSSProperties = {
height: '52px',
width: '52px'
Expand Down Expand Up @@ -136,6 +142,7 @@ const iconCSSToolbarButton: NestedCSSProperties = {

const iconCSSKind: { [k in IconKindType]: NestedCSSProperties } = {
breadCrumb: iconCSSBreadCrumb,
commandPaletteItem: iconCSSCommandPaletteItem,
launcherCard: iconCSSLauncherCard,
launcherSection: iconCSSLauncherSection,
listing: iconCSSListing,
Expand Down Expand Up @@ -276,6 +283,7 @@ const containerCSSToolbarButton: NestedCSSProperties = {

const containerCSSKind: { [k in IconKindType]: NestedCSSProperties } = {
breadCrumb: containerCSSBreadCrumb,
commandPaletteItem: {},
launcherCard: containerCSSLauncherCard,
launcherSection: containerCSSLauncherSection,
listing: containerCSSListing,
Expand Down

0 comments on commit 83c39a6

Please sign in to comment.