Skip to content

Commit

Permalink
Use only SVG icons (#783)
Browse files Browse the repository at this point in the history
* Use docRegistry for file listing

* Vectorize branch icon

* Correct unit tests

* Better theming

* Correct unit tests
  • Loading branch information
fcollonval authored Sep 28, 2020
1 parent 36790f9 commit ed50bef
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 197 deletions.
2 changes: 1 addition & 1 deletion src/components/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IActionButtonProps {
/**
* On-click event handler
*/
onClick?: (event?: React.MouseEvent) => void;
onClick?: (event?: React.MouseEvent<HTMLButtonElement>) => void;
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/components/BranchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
newBranchButtonClass,
wrapperClass
} from '../style/BranchMenu';
import { branchIcon } from '../style/icons';
import { Git, IGitExtension, Level } from '../tokens';
import { NewBranchDialog } from './NewBranchDialog';

Expand Down Expand Up @@ -270,13 +271,7 @@ export class BranchMenu extends React.Component<
onClick={this._onBranchClickFactory(branch.name)}
style={style}
>
<span
className={classes(
'jp-git-icon',
listItemIconClass,
isActive && 'jp-git-selected'
)}
/>
<branchIcon.react className={listItemIconClass} tag="span" />
{branch.name}
</ListItem>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class FileItem extends React.PureComponent<IFileItemProps> {
)}
<FilePath
filepath={this.props.file.to}
selected={this.props.selected}
filetype={this.props.file.type}
/>
{this.props.actions}
<span className={this._getFileChangedLabelClass(this.props.file.y)}>
Expand Down
30 changes: 9 additions & 21 deletions src/components/FilePath.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { fileIcon } from '@jupyterlab/ui-components';
import * as React from 'react';
import { classes } from 'typestyle';
import {
fileIconStyle,
fileLabelStyle,
folderLabelStyle
} from '../style/FilePathStyle';
import { extractFilename, getFileIconClassName } from '../utils';
import { fileLabelStyle, folderLabelStyle } from '../style/FilePathStyle';
import { extractFilename } from '../utils';

/**
* FilePath component properties
Expand All @@ -16,13 +13,9 @@ export interface IFilePathProps {
*/
filepath: string;
/**
* Is file selected? - impact style of the icon
* File type
*/
selected?: boolean;
}

function getFileIconClass(path: string): string {
return getFileIconClassName(path);
filetype: DocumentRegistry.IFileType;
}

export const FilePath: React.FunctionComponent<IFilePathProps> = (
Expand All @@ -33,16 +26,11 @@ export const FilePath: React.FunctionComponent<IFilePathProps> = (
.slice(0, props.filepath.length - filename.length)
.replace(/^\/|\/$/g, ''); // Remove leading and trailing '/'

const icon = props.filetype.icon || fileIcon;

return (
<React.Fragment>
<span
className={classes(
fileIconStyle,
'jp-git-icon',
getFileIconClass(props.filepath),
props.selected && 'jp-git-selected'
)}
/>
<icon.react elementPosition="center" tag="span" />
<span className={fileLabelStyle}>
{filename}
<span className={folderLabelStyle}>{folder}</span>
Expand Down
10 changes: 2 additions & 8 deletions src/components/NewBranchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as React from 'react';
import { ListChildComponentProps, VariableSizeList } from 'react-window';
import { classes } from 'typestyle';
import { Logger } from '../logger';
import { branchIcon } from '../style/icons';
import {
actionsWrapperClass,
activeListItemClass,
Expand Down Expand Up @@ -313,14 +314,7 @@ export class NewBranchDialog extends React.Component<
onClick={this._onBranchClickFactory(branch.name)}
style={style}
>
<span
className={classes(
'jp-git-icon',
listItemIconClass,
'jp-Icon-16',
isBase && 'jp-git-selected'
)}
/>
<branchIcon.react className={listItemIconClass} tag="span" />
<div className={listItemContentClass}>
<p
className={classes(
Expand Down
2 changes: 1 addition & 1 deletion src/components/SinglePastCommitInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class SinglePastCommitInfo extends React.Component<
style={style}
title={path}
>
<FilePath filepath={path} />
<FilePath filepath={path} filetype={file.type} />
{flg ? (
<ActionButton icon={diffIcon} title="View file changes" />
) : null}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async function activate(
gitExtension = new GitExtension(
serverSettings.serverRoot,
docmanager,
app.docRegistry,
settings
);

Expand Down
30 changes: 29 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IChangedArgs, PathExt } from '@jupyterlab/coreutils';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { JSONObject } from '@lumino/coreutils';
import { Poll } from '@lumino/polling';
Expand All @@ -26,10 +27,12 @@ export class GitExtension implements IGitExtension {
constructor(
serverRoot: string,
docmanager: IDocumentManager = null,
docRegistry: DocumentRegistry = null,
settings?: ISettingRegistry.ISettings
) {
this._serverRoot = serverRoot;
this._docmanager = docmanager;
this._docRegistry = docRegistry;
this._settings = settings || null;
this._taskHandler = new TaskHandler(this);

Expand Down Expand Up @@ -519,6 +522,11 @@ export class GitExtension implements IGitExtension {
return d;
}
);

data.modified_files = data.modified_files.map(f => {
f.type = this._resolveFileType(f.modified_file_path);
return f;
});
return data;
}

Expand Down Expand Up @@ -751,7 +759,11 @@ export class GitExtension implements IGitExtension {

this._setStatus(
data.files.map(file => {
return { ...file, status: decodeStage(file.x, file.y) };
return {
...file,
status: decodeStage(file.x, file.y),
type: this._resolveFileType(file.to)
};
})
);
} catch (err) {
Expand Down Expand Up @@ -1076,6 +1088,21 @@ export class GitExtension implements IGitExtension {
return path;
}

/**
* Resolve path to filetype
*/
protected _resolveFileType(path: string): DocumentRegistry.IFileType {
// test if directory
if (path.endsWith('/')) {
return DocumentRegistry.defaultDirectoryFileType;
}

return (
this._docRegistry.getFileTypesForPath(path)[0] ||
DocumentRegistry.defaultTextFileType
);
}

/**
* Set the repository status.
*
Expand Down Expand Up @@ -1131,6 +1158,7 @@ export class GitExtension implements IGitExtension {
private _currentBranch: Git.IBranch;
private _serverRoot: string;
private _docmanager: IDocumentManager | null;
private _docRegistry: DocumentRegistry | null;
private _diffProviders: { [key: string]: Git.IDiffCallback } = {};
private _isDisposed = false;
private _markerCache: Markers = new Markers(() => this._markChanged.emit());
Expand Down
21 changes: 11 additions & 10 deletions src/style/BranchMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const filterInputClass = style({
/* top | right | bottom | left */
padding: '1px 18px 2px 7px',

color: 'var(--jp-ui-font-color0)',
color: 'var(--jp-ui-font-color1)',
fontSize: 'var(--jp-ui-font-size1)',
fontWeight: 300,

Expand Down Expand Up @@ -86,7 +86,7 @@ export const newBranchButtonClass = style({
width: '7.7em',
height: '2em',

color: 'white',
color: 'var(--jp-ui-inverse-font-color1)',
fontSize: 'var(--jp-ui-font-size1)',

backgroundColor: 'var(--jp-brand-color1)',
Expand All @@ -101,19 +101,20 @@ export const listItemClass = style({
});

export const activeListItemClass = style({
color: 'white!important',
color: 'var(--jp-ui-inverse-font-color1)!important',

backgroundColor: 'var(--jp-brand-color1)!important'
backgroundColor: 'var(--jp-brand-color1)!important',

$nest: {
'& .jp-icon-selectable[fill]': {
fill: 'var(--jp-layout-color1)'
}
}
});

export const listItemIconClass = style({
width: '16px',
height: '16px',

marginRight: '4px',

backgroundImage: 'var(--jp-icon-git-branch)',
backgroundSize: '16px',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center'
marginRight: '4px'
});
6 changes: 3 additions & 3 deletions src/style/CommitBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const commitSummaryClass = style({
outline: 'none',
overflowX: 'auto',

color: 'var(--jp-ui-font-color0)',
color: 'var(--jp-ui-font-color1)',
fontSize: 'var(--jp-ui-font-size1)',
fontWeight: 300,

Expand Down Expand Up @@ -52,7 +52,7 @@ export const commitDescriptionClass = style({
overflowX: 'auto',
resize: 'none',

color: 'var(--jp-ui-font-color0)',
color: 'var(--jp-ui-font-color1)',
fontSize: 'var(--jp-ui-font-size1)',
fontWeight: 300,

Expand Down Expand Up @@ -90,7 +90,7 @@ export const commitButtonClass = style({

marginBottom: '0.5em',

color: 'white',
color: 'var(--jp-ui-inverse-font-color1)',
fontSize: 'var(--jp-ui-font-size1)',

cursor: 'pointer',
Expand Down
8 changes: 4 additions & 4 deletions src/style/FileItemStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const fileStyle = style(
);

export const selectedFileStyle = style({
color: 'white',
color: 'var(--jp-ui-inverse-font-color1)',
background: 'var(--jp-brand-color1)',

$nest: {
'&:hover': {
color: 'white',
color: 'var(--jp-ui-inverse-font-color1)',
background: 'var(--jp-brand-color1) !important'
},
'&:hover .jp-icon-selectable[fill]': {
Expand All @@ -37,7 +37,7 @@ export const selectedFileStyle = style({
stroke: 'var(--jp-layout-color2)'
},
'& .jp-icon-selectable[fill]': {
fill: '#fff'
fill: 'var(--jp-layout-color1)'
},
'& .jp-icon-selectable-inverse[fill]': {
fill: 'var(--jp-brand-color1)'
Expand All @@ -51,7 +51,7 @@ export const fileChangedLabelStyle = style({
});

export const selectedFileChangedLabelStyle = style({
color: 'white !important'
color: 'var(--jp-ui-inverse-font-color1) !important'
});

export const fileChangedLabelBrandStyle = style({
Expand Down
40 changes: 0 additions & 40 deletions src/style/FileListStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,3 @@ export const fileListWrapperClass = style({
overflow: 'hidden',
overflowY: 'auto'
});

export const notebookFileIconStyle = style({
backgroundImage: 'var(--jp-icon-notebook)'
});

export const folderFileIconStyle = style({
backgroundImage: 'var(--jp-icon-directory)'
});

export const genericFileIconStyle = style({
backgroundImage: 'var(--jp-icon-file)'
});

export const yamlFileIconStyle = style({
backgroundImage: 'var(--jp-icon-yaml)'
});

export const markdownFileIconStyle = style({
backgroundImage: 'var(--jp-icon-markdown)'
});

export const imageFileIconStyle = style({
backgroundImage: 'var(--jp-icon-image)'
});

export const spreadsheetFileIconStyle = style({
backgroundImage: 'var(--jp-icon-spreadsheet)'
});

export const jsonFileIconStyle = style({
backgroundImage: 'var(--jp-icon-json)'
});

export const pythonFileIconStyle = style({
backgroundImage: 'var(--jp-icon-python)'
});

export const rKernelFileIconStyle = style({
backgroundImage: 'var(--jp-icon-r-kernel)'
});
4 changes: 0 additions & 4 deletions src/style/FilePathStyle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { style } from 'typestyle';

export const fileIconStyle = style({
alignSelf: 'center',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
backgroundSize: '16px',
flex: '0 0 auto',
height: '16px',
width: '16px',
Expand Down
Loading

0 comments on commit ed50bef

Please sign in to comment.