Skip to content

Commit ed50bef

Browse files
authored
Use only SVG icons (#783)
* Use docRegistry for file listing * Vectorize branch icon * Correct unit tests * Better theming * Correct unit tests
1 parent 36790f9 commit ed50bef

24 files changed

+115
-197
lines changed

src/components/ActionButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface IActionButtonProps {
2626
/**
2727
* On-click event handler
2828
*/
29-
onClick?: (event?: React.MouseEvent) => void;
29+
onClick?: (event?: React.MouseEvent<HTMLButtonElement>) => void;
3030
}
3131

3232
/**

src/components/BranchMenu.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
newBranchButtonClass,
1818
wrapperClass
1919
} from '../style/BranchMenu';
20+
import { branchIcon } from '../style/icons';
2021
import { Git, IGitExtension, Level } from '../tokens';
2122
import { NewBranchDialog } from './NewBranchDialog';
2223

@@ -270,13 +271,7 @@ export class BranchMenu extends React.Component<
270271
onClick={this._onBranchClickFactory(branch.name)}
271272
style={style}
272273
>
273-
<span
274-
className={classes(
275-
'jp-git-icon',
276-
listItemIconClass,
277-
isActive && 'jp-git-selected'
278-
)}
279-
/>
274+
<branchIcon.react className={listItemIconClass} tag="span" />
280275
{branch.name}
281276
</ListItem>
282277
);

src/components/FileItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class FileItem extends React.PureComponent<IFileItemProps> {
185185
)}
186186
<FilePath
187187
filepath={this.props.file.to}
188-
selected={this.props.selected}
188+
filetype={this.props.file.type}
189189
/>
190190
{this.props.actions}
191191
<span className={this._getFileChangedLabelClass(this.props.file.y)}>

src/components/FilePath.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
import { DocumentRegistry } from '@jupyterlab/docregistry';
2+
import { fileIcon } from '@jupyterlab/ui-components';
13
import * as React from 'react';
2-
import { classes } from 'typestyle';
3-
import {
4-
fileIconStyle,
5-
fileLabelStyle,
6-
folderLabelStyle
7-
} from '../style/FilePathStyle';
8-
import { extractFilename, getFileIconClassName } from '../utils';
4+
import { fileLabelStyle, folderLabelStyle } from '../style/FilePathStyle';
5+
import { extractFilename } from '../utils';
96

107
/**
118
* FilePath component properties
@@ -16,13 +13,9 @@ export interface IFilePathProps {
1613
*/
1714
filepath: string;
1815
/**
19-
* Is file selected? - impact style of the icon
16+
* File type
2017
*/
21-
selected?: boolean;
22-
}
23-
24-
function getFileIconClass(path: string): string {
25-
return getFileIconClassName(path);
18+
filetype: DocumentRegistry.IFileType;
2619
}
2720

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

29+
const icon = props.filetype.icon || fileIcon;
30+
3631
return (
3732
<React.Fragment>
38-
<span
39-
className={classes(
40-
fileIconStyle,
41-
'jp-git-icon',
42-
getFileIconClass(props.filepath),
43-
props.selected && 'jp-git-selected'
44-
)}
45-
/>
33+
<icon.react elementPosition="center" tag="span" />
4634
<span className={fileLabelStyle}>
4735
{filename}
4836
<span className={folderLabelStyle}>{folder}</span>

src/components/NewBranchDialog.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as React from 'react';
66
import { ListChildComponentProps, VariableSizeList } from 'react-window';
77
import { classes } from 'typestyle';
88
import { Logger } from '../logger';
9+
import { branchIcon } from '../style/icons';
910
import {
1011
actionsWrapperClass,
1112
activeListItemClass,
@@ -313,14 +314,7 @@ export class NewBranchDialog extends React.Component<
313314
onClick={this._onBranchClickFactory(branch.name)}
314315
style={style}
315316
>
316-
<span
317-
className={classes(
318-
'jp-git-icon',
319-
listItemIconClass,
320-
'jp-Icon-16',
321-
isBase && 'jp-git-selected'
322-
)}
323-
/>
317+
<branchIcon.react className={listItemIconClass} tag="span" />
324318
<div className={listItemContentClass}>
325319
<p
326320
className={classes(

src/components/SinglePastCommitInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class SinglePastCommitInfo extends React.Component<
256256
style={style}
257257
title={path}
258258
>
259-
<FilePath filepath={path} />
259+
<FilePath filepath={path} filetype={file.type} />
260260
{flg ? (
261261
<ActionButton icon={diffIcon} title="View file changes" />
262262
) : null}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ async function activate(
112112
gitExtension = new GitExtension(
113113
serverSettings.serverRoot,
114114
docmanager,
115+
app.docRegistry,
115116
settings
116117
);
117118

src/model.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IChangedArgs, PathExt } from '@jupyterlab/coreutils';
22
import { IDocumentManager } from '@jupyterlab/docmanager';
3+
import { DocumentRegistry } from '@jupyterlab/docregistry';
34
import { ISettingRegistry } from '@jupyterlab/settingregistry';
45
import { JSONObject } from '@lumino/coreutils';
56
import { Poll } from '@lumino/polling';
@@ -26,10 +27,12 @@ export class GitExtension implements IGitExtension {
2627
constructor(
2728
serverRoot: string,
2829
docmanager: IDocumentManager = null,
30+
docRegistry: DocumentRegistry = null,
2931
settings?: ISettingRegistry.ISettings
3032
) {
3133
this._serverRoot = serverRoot;
3234
this._docmanager = docmanager;
35+
this._docRegistry = docRegistry;
3336
this._settings = settings || null;
3437
this._taskHandler = new TaskHandler(this);
3538

@@ -519,6 +522,11 @@ export class GitExtension implements IGitExtension {
519522
return d;
520523
}
521524
);
525+
526+
data.modified_files = data.modified_files.map(f => {
527+
f.type = this._resolveFileType(f.modified_file_path);
528+
return f;
529+
});
522530
return data;
523531
}
524532

@@ -751,7 +759,11 @@ export class GitExtension implements IGitExtension {
751759

752760
this._setStatus(
753761
data.files.map(file => {
754-
return { ...file, status: decodeStage(file.x, file.y) };
762+
return {
763+
...file,
764+
status: decodeStage(file.x, file.y),
765+
type: this._resolveFileType(file.to)
766+
};
755767
})
756768
);
757769
} catch (err) {
@@ -1076,6 +1088,21 @@ export class GitExtension implements IGitExtension {
10761088
return path;
10771089
}
10781090

1091+
/**
1092+
* Resolve path to filetype
1093+
*/
1094+
protected _resolveFileType(path: string): DocumentRegistry.IFileType {
1095+
// test if directory
1096+
if (path.endsWith('/')) {
1097+
return DocumentRegistry.defaultDirectoryFileType;
1098+
}
1099+
1100+
return (
1101+
this._docRegistry.getFileTypesForPath(path)[0] ||
1102+
DocumentRegistry.defaultTextFileType
1103+
);
1104+
}
1105+
10791106
/**
10801107
* Set the repository status.
10811108
*
@@ -1131,6 +1158,7 @@ export class GitExtension implements IGitExtension {
11311158
private _currentBranch: Git.IBranch;
11321159
private _serverRoot: string;
11331160
private _docmanager: IDocumentManager | null;
1161+
private _docRegistry: DocumentRegistry | null;
11341162
private _diffProviders: { [key: string]: Git.IDiffCallback } = {};
11351163
private _isDisposed = false;
11361164
private _markerCache: Markers = new Markers(() => this._markChanged.emit());

src/style/BranchMenu.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const filterInputClass = style({
3030
/* top | right | bottom | left */
3131
padding: '1px 18px 2px 7px',
3232

33-
color: 'var(--jp-ui-font-color0)',
33+
color: 'var(--jp-ui-font-color1)',
3434
fontSize: 'var(--jp-ui-font-size1)',
3535
fontWeight: 300,
3636

@@ -86,7 +86,7 @@ export const newBranchButtonClass = style({
8686
width: '7.7em',
8787
height: '2em',
8888

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

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

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

106-
backgroundColor: 'var(--jp-brand-color1)!important'
106+
backgroundColor: 'var(--jp-brand-color1)!important',
107+
108+
$nest: {
109+
'& .jp-icon-selectable[fill]': {
110+
fill: 'var(--jp-layout-color1)'
111+
}
112+
}
107113
});
108114

109115
export const listItemIconClass = style({
110116
width: '16px',
111117
height: '16px',
112118

113-
marginRight: '4px',
114-
115-
backgroundImage: 'var(--jp-icon-git-branch)',
116-
backgroundSize: '16px',
117-
backgroundRepeat: 'no-repeat',
118-
backgroundPosition: 'center'
119+
marginRight: '4px'
119120
});

src/style/CommitBox.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const commitSummaryClass = style({
2424
outline: 'none',
2525
overflowX: 'auto',
2626

27-
color: 'var(--jp-ui-font-color0)',
27+
color: 'var(--jp-ui-font-color1)',
2828
fontSize: 'var(--jp-ui-font-size1)',
2929
fontWeight: 300,
3030

@@ -52,7 +52,7 @@ export const commitDescriptionClass = style({
5252
overflowX: 'auto',
5353
resize: 'none',
5454

55-
color: 'var(--jp-ui-font-color0)',
55+
color: 'var(--jp-ui-font-color1)',
5656
fontSize: 'var(--jp-ui-font-size1)',
5757
fontWeight: 300,
5858

@@ -90,7 +90,7 @@ export const commitButtonClass = style({
9090

9191
marginBottom: '0.5em',
9292

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

9696
cursor: 'pointer',

0 commit comments

Comments
 (0)