Skip to content

Commit e7b71dd

Browse files
committed
Move the progress bar to its component + CSS module
1 parent e39d855 commit e7b71dd

File tree

5 files changed

+57
-38
lines changed

5 files changed

+57
-38
lines changed

src/components/Layout.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactNode, useEffect, useState } from 'react'
22
import { cn } from '../lib/utils.js'
33
import ErrorBar from './ErrorBar.js'
4+
import ProgressBar from './ProgressBar.js'
45
import SideBar from './SideBar.js'
56
import Welcome from './Welcome.js'
67

@@ -51,11 +52,7 @@ export default function Layout({ children, className, progress, error, title }:
5152
</div>
5253
<ErrorBar error={error}></ErrorBar>
5354
</div>
54-
{progress !== undefined && progress < 1 &&
55-
<div className={'progress-bar'} role='progressbar'>
56-
<div style={{ width: `${100 * progress}%` }} />
57-
</div>
58-
}
55+
{progress !== undefined && progress < 1 && <ProgressBar value={progress} />}
5956
{showWelcome && <Welcome onClose={handleCloseWelcome} />}
6057
</main>
6158
}

src/components/ProgressBar.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useConfig } from '../hooks/useConfig'
2+
import { cn } from '../lib/utils.js'
3+
import styles from '../styles/ProgressBar.module.css'
4+
import VisuallyHidden from './VisuallyHidden.js'
5+
6+
export default function ProgressBar({ value }: {value: number}) {
7+
const { customClass } = useConfig()
8+
if (value < 0 || value > 1) {
9+
throw new Error('ProgressBar value must be between 0 and 1')
10+
}
11+
const roundedValue = Math.round(value * 100) / 100
12+
const percentage = roundedValue.toLocaleString('en-US', { style: 'percent' })
13+
return (
14+
<div
15+
className={cn(styles.progressBar, customClass?.progressBar)}
16+
role='progressbar'
17+
aria-valuenow={roundedValue}
18+
aria-valuemin={0}
19+
aria-valuemax={1}
20+
>
21+
<VisuallyHidden>{percentage}</VisuallyHidden>
22+
<div style={{ width: percentage }} role="presentation" />
23+
</div>
24+
)
25+
}

src/hooks/useConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Config {
1515
highTable?: string
1616
imageView?: string
1717
markdownView?: string
18+
progressBar?: string
1819
sideBar?: string
1920
slideCloseButton?: string
2021
slidePanel?: string

src/styles/ProgressBar.module.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* progress bar */
2+
.progressBar {
3+
position: fixed;
4+
top: 0;
5+
left: 0;
6+
right: 0;
7+
height: 2px;
8+
z-index: 1000;
9+
transition: width 0.3s;
10+
11+
/* Shimmer effect overlay */
12+
background-image: linear-gradient(to right, #ddd 0%, #cbb 50%, #ddd 100%);
13+
background-size: 1000px;
14+
animation: shimmer 4s infinite linear;
15+
16+
@keyframes shimmer {
17+
0% {
18+
background-position: -1000px;
19+
}
20+
100% {
21+
background-position: 1000px;
22+
}
23+
}
24+
25+
& > [role="presentation"] {
26+
height: 100%;
27+
background-color: #3a4;
28+
}
29+
}

src/styles/app.css

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,6 @@ input.search:focus {
172172
}
173173
}
174174

175-
/* progress bar */
176-
.progress-bar {
177-
position: fixed;
178-
top: 0;
179-
left: 0;
180-
right: 0;
181-
height: 2px;
182-
z-index: 1000;
183-
transition: width 0.3s;
184-
185-
/* Shimmer effect overlay */
186-
background-image: linear-gradient(
187-
to right,
188-
#ddd 0%,
189-
#cbb 50%,
190-
#ddd 100%
191-
);
192-
background-size: 1000px;
193-
animation: shimmer 4s infinite linear;
194-
}
195-
@keyframes shimmer {
196-
0% {
197-
background-position: -1000px;
198-
}
199-
100% {
200-
background-position: 1000px;
201-
}
202-
}
203-
.progress-bar > div {
204-
height: 100%;
205-
background-color: #3a4;
206-
}
207-
208175
/* file list */
209176
.file-list {
210177
flex: 1;

0 commit comments

Comments
 (0)