Skip to content

Commit 971f0cd

Browse files
jupyter: table style tweaks (#1345)
1 parent 9fa28aa commit 971f0cd

3 files changed

Lines changed: 76 additions & 50 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add: Jupyter notebook table output style tweaks
Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2025 znai maintainers
23
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,43 +15,34 @@
1415
* limitations under the License.
1516
*/
1617

17-
import React from 'react'
18-
import JupyterCell from './JupyterCell'
18+
import React from "react";
19+
import JupyterCell from "./JupyterCell";
1920

20-
import {elementsLibrary} from '../DefaultElementsLibrary'
21+
import { elementsLibrary } from "../DefaultElementsLibrary";
2122

2223
const simpleNotebook = {
23-
cells: [
24-
{
25-
"cellType" : "code",
26-
"lang" : "python",
27-
"snippet" : "from pandas import read_csv\nfrom IPython.display import display",
28-
"type" : "JupyterCell"
29-
},
30-
{
31-
cellType : "output",
32-
text:
33-
" a b c\n" +
34-
"0 1 2 3\n" +
35-
"1 4 5 6\n"
36-
},
37-
{
38-
cellType: "output",
39-
html: `
24+
cells: [
25+
{
26+
cellType: "code",
27+
lang: "python",
28+
snippet: "from pandas import read_csv\nfrom IPython.display import display",
29+
type: "JupyterCell",
30+
},
31+
{
32+
cellType: "output",
33+
text: " a b c\n" + "0 1 2 3\n" + "1 4 5 6\n",
34+
},
35+
{
36+
cellType: "output",
37+
html: `
4038
<div>
41-
<style scoped>
42-
.dataframe tbody tr th:only-of-type {
43-
vertical-align: middle;
44-
}
45-
46-
.dataframe tbody tr th {
47-
vertical-align: top;
48-
}
49-
50-
.dataframe thead th {
51-
text-align: right;
52-
}
53-
</style>
39+
<style>
40+
.dataframe > thead > tr,
41+
.dataframe > tbody > tr {
42+
text-align: right;
43+
white-space: pre-wrap;
44+
}
45+
</style>
5446
<table border="1" class="dataframe">
5547
<thead>
5648
<tr style="text-align: right;">
@@ -63,26 +55,26 @@ const simpleNotebook = {
6355
<tbody>
6456
<tr>
6557
<th>0</th>
66-
<td>1</td>
58+
<td>11</td>
6759
<td>2</td>
6860
<td>3</td>
6961
</tr>
7062
<tr>
7163
<th>1</th>
7264
<td>4</td>
73-
<td>5</td>
65+
<td>50</td>
7466
<td>6</td>
7567
</tr>
7668
</tbody>
7769
</table>
78-
</div> `
79-
}
80-
]
81-
}
70+
</div> `,
71+
},
72+
],
73+
};
8274

8375
export function jupyterDemo(registry) {
84-
registry
85-
.add('code cell', () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[0]}/>)
86-
.add('output text cell', () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[1]}/>)
87-
.add('output htlml cell', () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[2]}/>)
76+
registry
77+
.add("code cell", () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[0]} />)
78+
.add("output text cell", () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[1]} />)
79+
.add("output htlml cell", () => <JupyterCell elementsLibrary={elementsLibrary} {...simpleNotebook.cells[2]} />);
8880
}

znai-reactjs/src/doc-elements/jupyter/JupyterHtmlCell.css

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2025 znai maintainers
23
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,17 +20,49 @@
1920
margin-bottom: var(--znai-snippets-space-below);
2021
}
2122

22-
.jupyter-html thead tr,
2323
.jupyter-html table {
24+
margin: 0;
25+
border-collapse: collapse;
26+
background-color: var(--znai-table-body-background-color);
27+
border: 1px solid var(--znai-table-border-color);
28+
}
29+
30+
.jupyter-html thead tr {
2431
border: none;
2532
}
2633

27-
.jupyter-html td,
34+
.jupyter-html thead {
35+
background-color: var(--znai-table-header-background-color);
36+
}
37+
2838
.jupyter-html th {
29-
padding: 6px
39+
background: var(--znai-table-header-background-color);
40+
padding: 12px 16px;
41+
font-weight: 600;
42+
text-align: left;
43+
color: var(--znai-table-title-color);
44+
font-size: var(--znai-smaller-text-size);
45+
text-transform: uppercase;
46+
border-bottom: 1px solid var(--znai-table-border-color);
47+
border-right: 1px solid var(--znai-table-border-color);
48+
}
49+
50+
.jupyter-html th:last-child {
51+
border-right: none;
3052
}
3153

32-
.jupyter-html table td,
33-
.jupyter-html table th {
34-
border: 1px solid var(--znai-snippets-outer-border-color);
35-
}
54+
.jupyter-html td {
55+
padding: 12px 16px;
56+
color: var(--znai-regular-text-color);
57+
font-size: var(--znai-regular-text-size);
58+
border-bottom: 1px solid var(--znai-table-border-color);
59+
border-right: 1px solid var(--znai-table-border-color);
60+
}
61+
62+
.jupyter-html td:last-child {
63+
border-right: none;
64+
}
65+
66+
.jupyter-html tbody tr:last-child td {
67+
border-bottom: none;
68+
}

0 commit comments

Comments
 (0)