Skip to content

Commit bc7566f

Browse files
committed
Change fontawesome support to work for fontawesome 4 and 5.
JupyterLab and notebook are upgrading to fontawesome 5 (with the v4 backwards compatibility shim). However, in some places, our CSS is very specific to version 4. This commit modifies these places to use syntax that should for both fontawesome 4 and 5. It involves some DOM structure changes, but that is a private implementation detail, so is backwards compatible with our public API. This is a forward-port of jupyter-widgets#2793 and 5941cba Fixes jupyter-widgets#2794
1 parent 9b28600 commit bc7566f

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

packages/controls/css/widgets-base.css

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -395,23 +395,13 @@
395395
line-height: var(--jp-widgets-inline-height);
396396
margin-right: var(--jp-widgets-inline-margin);
397397
margin-left: var(--jp-widgets-inline-margin);
398-
399-
/* from the fa class in FontAwesome: https://github.com/FortAwesome/Font-Awesome/blob/49100c7c3a7b58d50baa71efef11af41a66b03d3/css/font-awesome.css#L14 */
400-
display: inline-block;
401-
font: normal normal normal 14px/1 FontAwesome;
402-
font-size: inherit;
403-
text-rendering: auto;
404-
-webkit-font-smoothing: antialiased;
405-
-moz-osx-font-smoothing: grayscale;
406398
}
407399

408400
.widget-valid.mod-valid i:before {
409-
content: '\f00c';
410401
color: green;
411402
}
412403

413404
.widget-valid.mod-invalid i:before {
414-
content: '\f00d';
415405
color: red;
416406
}
417407

@@ -953,6 +943,8 @@
953943
margin-left: 4px;
954944
}
955945

946+
/* This font-awesome strategy may not work across FA4 and FA5, but we don't
947+
actually support closable tabs, so it really doesn't matter */
956948
.jupyter-widgets.widget-tab
957949
> .p-TabBar
958950
.p-mod-closable
@@ -998,20 +990,6 @@
998990
border-bottom: none;
999991
}
1000992

1001-
.p-Collapse .p-Collapse-header::before {
1002-
content: '\f0da\00A0'; /* caret-right, non-breaking space */
1003-
display: inline-block;
1004-
font: normal normal normal 14px/1 FontAwesome;
1005-
font-size: inherit;
1006-
text-rendering: auto;
1007-
-webkit-font-smoothing: antialiased;
1008-
-moz-osx-font-smoothing: grayscale;
1009-
}
1010-
1011-
.p-Collapse-open > .p-Collapse-header::before {
1012-
content: '\f0d7\00A0'; /* caret-down, non-breaking space */
1013-
}
1014-
1015993
.p-Collapse-contents {
1016994
padding: var(--jp-widgets-container-padding);
1017995
background-color: var(--jp-layout-color1);

packages/controls/src/lumino/accordion.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export class Collapse extends Widget {
4040
this._header = new Widget();
4141
this._header.addClass(COLLAPSE_HEADER_CLASS);
4242
this._header.node.addEventListener('click', this);
43+
// Fontawesome icon for caret
44+
const icon = document.createElement('i');
45+
icon.classList.add('fa', 'fa-fw', 'fa-caret-right');
46+
this._header.node.appendChild(icon);
47+
// Label content
48+
this._header.node.appendChild(document.createElement('span'));
49+
4350
this._content = new Panel();
4451
this._content.addClass(COLLAPSE_CONTENTS_CLASS);
4552

@@ -111,14 +118,19 @@ export class Collapse extends Widget {
111118
this._content.hide();
112119
}
113120
this.removeClass(COLLAPSE_CLASS_OPEN);
121+
this._header.node.children[0].classList.add('fa-caret-right');
122+
this._header.node.children[0].classList.remove('fa-caret-down');
114123
this._collapseChanged.emit(void 0);
115124
}
125+
116126
private _uncollapse(): void {
117127
this._collapsed = false;
118128
if (this._content) {
119129
this._content.show();
120130
}
121131
this.addClass(COLLAPSE_CLASS_OPEN);
132+
this._header.node.children[0].classList.add('fa-caret-down');
133+
this._header.node.children[0].classList.remove('fa-caret-right');
122134
this._collapseChanged.emit(void 0);
123135
}
124136

@@ -150,7 +162,7 @@ export class Collapse extends Widget {
150162
* Handle the `changed` signal of a title object.
151163
*/
152164
private _onTitleChanged(sender: Title<Widget>): void {
153-
this._header.node.textContent = this._widget.title.label;
165+
this._header.node.children[1].textContent = this._widget.title.label;
154166
}
155167

156168
private _onChildDisposed(sender: Widget): void {

packages/controls/src/widget_bool.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,14 @@ export class ValidView extends DescriptionView {
301301
/**
302302
* Called when view is rendered.
303303
*/
304-
render(): void {
304+
render() {
305305
super.render();
306306
this.el.classList.add('jupyter-widgets');
307307
this.el.classList.add('widget-valid');
308308
this.el.classList.add('widget-inline-hbox');
309-
const icon = document.createElement('i');
310-
this.el.appendChild(icon);
309+
this.icon = document.createElement('i');
310+
this.icon.classList.add('fa', 'fa-fw');
311+
this.el.appendChild(this.icon);
311312
this.readout = document.createElement('span');
312313
this.readout.classList.add('widget-valid-readout');
313314
this.readout.classList.add('widget-readout');
@@ -321,15 +322,20 @@ export class ValidView extends DescriptionView {
321322
* Called when the model is changed. The model may have been
322323
* changed by another view or by a state update from the back-end.
323324
*/
324-
update(): void {
325+
update() {
325326
this.el.classList.remove('mod-valid');
326327
this.el.classList.remove('mod-invalid');
328+
this.icon.classList.remove('fa-check');
329+
this.icon.classList.remove('fa-times');
327330
this.readout.textContent = this.model.get('readout');
328331
if (this.model.get('value')) {
329332
this.el.classList.add('mod-valid');
333+
this.icon.classList.add('fa-check');
330334
} else {
331335
this.el.classList.add('mod-invalid');
336+
this.icon.classList.add('fa-times');
332337
}
333338
}
334339
readout: HTMLSpanElement;
340+
icon: HTMLElement;
335341
}

0 commit comments

Comments
 (0)