Skip to content

Commit f233952

Browse files
committed
Add suspense and lazy load to VersionHistory
1 parent 264332a commit f233952

File tree

3 files changed

+102
-31
lines changed

3 files changed

+102
-31
lines changed

src/theme/SettingsInfoBlock/styles.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
position: relative;
1818
width: 170px;
1919
height: 80px;
20-
z-index: 1;
20+
z-index: 0;
2121
overflow: hidden;
2222
border-radius: 5px;
2323
margin-bottom: 15px;
Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
11
import { Accordion, Table} from '@clickhouse/click-ui/bundled'
22
import styles from './styles.module.css';
3+
import React, {Suspense} from 'react'
4+
import BrowserOnly from '@docusaurus/BrowserOnly';
35

4-
const VersionHistoryDropdown = ({rows=[]}) => {
5-
return(
6-
<div
7-
className={styles.versionHistory}
8-
>
9-
<Accordion
10-
color="default"
11-
title="Version history"
12-
size="sm"
13-
gap="md"
14-
>
15-
<Table
16-
headers={[
17-
{
18-
label: 'Version'
19-
},
20-
{
21-
label: 'Default value'
22-
},
23-
{
24-
label: 'Comment'
25-
}
26-
]}
27-
rows={rows}
28-
size="sm"
29-
className={styles.table}
30-
></Table>
31-
</Accordion>
32-
</div>
33-
)
6+
const Table = React.lazy(() => import('@clickhouse/click-ui/bundled').then(module => ({
7+
default: module.Table
8+
})));
9+
10+
const Accordion = React.lazy(() => import('@clickhouse/click-ui/bundled').then(module => ({
11+
default: module.Accordion
12+
})));
13+
14+
function VersionHistoryPlaceholder() {
15+
return (
16+
<div className={styles.wrapper}>
17+
<div className={styles.activity}></div>
18+
</div>
19+
);
3420
}
21+
const VersionHistoryDropdown = ({ rows = [] }) => {
22+
return (
23+
<BrowserOnly fallback={<VersionHistoryPlaceholder />}>
24+
{() => {
25+
return (
26+
<div className={styles.versionHistory}>
27+
<Suspense fallback={<VersionHistoryPlaceholder />}>
28+
<Accordion
29+
color="default"
30+
title="Version history"
31+
size="sm"
32+
gap="md"
33+
>
34+
<Table
35+
headers={[
36+
{
37+
label: 'Version'
38+
},
39+
{
40+
label: 'Default value'
41+
},
42+
{
43+
label: 'Comment'
44+
}
45+
]}
46+
rows={rows}
47+
size="sm"
48+
className={styles.table}
49+
></Table>
50+
</Accordion>
51+
</Suspense>
52+
</div>
53+
);
54+
}}
55+
</BrowserOnly>
56+
);
57+
};
3558

3659
export default VersionHistoryDropdown

src/theme/VersionHistory/styles.module.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,51 @@
1111
display: block;
1212
margin-bottom: 0px;
1313
}
14+
15+
.wrapper {
16+
position: relative;
17+
width: 100px;
18+
height: 18px;
19+
z-index: 0;
20+
overflow: hidden;
21+
border-radius: 5px;
22+
margin-bottom: 15px;
23+
}
24+
25+
[data-theme='dark'] .wrapper {
26+
background-color: rgb(46,46,41);
27+
}
28+
29+
[data-theme='light'] .wrapper {
30+
background-color: rgb(245,245,245);
31+
}
32+
33+
.activity {
34+
position: absolute;
35+
left: -45%;
36+
height: 100%;
37+
width: 45%;
38+
animation: loading 1s infinite;
39+
z-index: 45;
40+
}
41+
42+
[data-theme='dark'] .activity {
43+
background-image: linear-gradient(to left, rgba(31,31,28, .05), rgba(31,31,28, .3), rgba(31,31,28, .6), rgba(31,31,28, .3), rgba(31,31,28, .05));
44+
background-image: -moz-linear-gradient(to left, rgba(31,31,28, .05), rgba(31,31,28, .3), rgba(31,31,28, .6), rgba(31,31,28, .3), rgba(31,31,28, .05));
45+
background-image: -webkit-linear-gradient(to left, rgba(31,31,28, .05), rgba(31,31,28, .3), rgba(31,31,28, .6), rgba(31,31,28, .3), rgba(31,31,28, .05));
46+
}
47+
48+
[data-theme='light'] .activity {
49+
background-image: linear-gradient(to left, rgba(227,227,227, .05), rgba(227,227,227, .3), rgba(227,227,227, .6), rgba(227,227,227, .3), rgba(227,227,227, .05));
50+
background-image: -moz-linear-gradient(to left, rgba(227,227,227, .05), rgba(227,227,227, .3), rgba(227,227,227, .6), rgba(227,227,227, .3), rgba(227,227,227, .05));
51+
background-image: -webkit-linear-gradient(to left, rgba(227,227,227, .05), rgba(227,227,227, .3), rgba(227,227,227, .6), rgba(227,227,227, .3), rgba(227,227,227, .05));
52+
}
53+
54+
@keyframes loading {
55+
0% {
56+
left: -45%; /* Start off-screen to the left */
57+
}
58+
100% {
59+
left: calc(100% + 45%); /* Move off-screen to the right */
60+
}
61+
}

0 commit comments

Comments
 (0)