Skip to content

Commit d1ee696

Browse files
committed
Backport PR #893: Use animated icon as status indicator
1 parent ebd1b12 commit d1ee696

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

src/widgets/StatusWidget.ts renamed to src/components/StatusWidget.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
import { ReactWidget } from '@jupyterlab/apputils';
12
import { ISettingRegistry } from '@jupyterlab/settingregistry';
23
import { IStatusBar } from '@jupyterlab/statusbar';
3-
import { Widget } from '@lumino/widgets';
4-
import { statusWidgetClass } from '../style/StatusWidget';
4+
import React from 'react';
5+
import { gitIcon } from '../style/icons';
6+
import {
7+
statusAnimatedIconClass,
8+
statusIconClass
9+
} from '../style/StatusWidget';
510
import { IGitExtension } from '../tokens';
611
import { sleep } from '../utils';
712

8-
/**
9-
* Class for creating a status bar widget.
10-
*/
11-
export class StatusWidget extends Widget {
13+
export class StatusWidget extends ReactWidget {
1214
/**
1315
* Returns a status bar widget.
1416
*
1517
* @returns widget
1618
*/
1719
constructor() {
1820
super();
19-
this.addClass(statusWidgetClass);
2021
}
2122

2223
/**
@@ -25,16 +26,23 @@ export class StatusWidget extends Widget {
2526
set status(text: string) {
2627
this._status = text;
2728
if (!this._locked) {
28-
this._lock();
29-
this.refresh();
29+
this._animate();
3030
}
3131
}
3232

33-
/**
34-
* Refreshes the status widget.
35-
*/
36-
refresh(): void {
37-
this.node.textContent = 'Git: ' + this._status;
33+
render(): JSX.Element {
34+
return (
35+
<div title={`Git: ${this._status}`}>
36+
<gitIcon.react
37+
className={
38+
this._status !== 'idle' ? statusAnimatedIconClass : statusIconClass
39+
}
40+
left={'1px'}
41+
top={'3px'}
42+
stylesheet={'statusBar'}
43+
/>
44+
</div>
45+
);
3846
}
3947

4048
/**
@@ -44,11 +52,12 @@ export class StatusWidget extends Widget {
4452
*
4553
* - This is used to throttle updates in order to prevent "flashing" messages.
4654
*/
47-
async _lock(): Promise<void> {
55+
async _animate(): Promise<void> {
4856
this._locked = true;
57+
this.update();
4958
await sleep(500);
5059
this._locked = false;
51-
this.refresh();
60+
this.update();
5261
}
5362

5463
/**

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
addFileBrowserContextMenu,
1717
createGitMenu
1818
} from './commandsAndMenu';
19+
import { addStatusBarWidget } from './components/StatusWidget';
1920
import { GitExtension } from './model';
2021
import { getServerSettings } from './server';
2122
import { gitIcon } from './style/icons';
2223
import { Git, IGitExtension } from './tokens';
2324
import { addCloneButton } from './widgets/gitClone';
2425
import { GitWidget } from './widgets/GitWidget';
25-
import { addStatusBarWidget } from './widgets/StatusWidget';
2626

2727
export { Git, IGitExtension } from './tokens';
2828

src/style/StatusWidget.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
import { style } from 'typestyle';
1+
import { keyframes, style } from 'typestyle';
22

3-
export const statusWidgetClass = style({
4-
color: 'var(--jp-ui-font-color1)',
5-
fontFamily: 'var(--jp-ui-font-family)',
6-
fontSize: 'var(--jp-ui-font-size1)',
7-
lineHeight: '24px'
3+
const fillAnimation = keyframes({
4+
to: { fillOpacity: 1 }
5+
});
6+
7+
export const statusIconClass = style({
8+
$nest: {
9+
'& .jp-icon3': {
10+
animationName: fillAnimation,
11+
animationDuration: '1s'
12+
}
13+
}
14+
});
15+
16+
const pathAnimation = keyframes({
17+
'0%': { fillOpacity: 1 },
18+
'50%': { fillOpacity: 0.6 },
19+
'100%': { fillOpacity: 1 }
20+
});
21+
22+
export const statusAnimatedIconClass = style({
23+
$nest: {
24+
'& .jp-icon3': {
25+
animationName: pathAnimation,
26+
animationDuration: '2s',
27+
animationIterationCount: 'infinite'
28+
}
29+
}
830
});

style/icons/git.svg

Lines changed: 0 additions & 1 deletion
Loading

0 commit comments

Comments
 (0)