Skip to content

Commit 283bace

Browse files
committed
move ErrorBar styles to CSS module + new component
1 parent b73d419 commit 283bace

File tree

6 files changed

+87
-78
lines changed

6 files changed

+87
-78
lines changed

src/components/ErrorBar.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { CSSProperties, useState } from 'react'
2+
import { useConfig } from '../hooks/useConfig.js'
3+
import { cn } from '../lib/utils.js'
4+
import styles from '../styles/ErrorBar.module.css'
5+
6+
interface ErrorBarProps {
7+
error?: Error
8+
}
9+
10+
export default function ErrorBar({ error }: ErrorBarProps) {
11+
const [showError, setShowError] = useState(error !== undefined)
12+
const [prevError, setPrevError] = useState(error)
13+
const { customClass } = useConfig()
14+
15+
if (error) console.error(error)
16+
/// Reset error visibility when error prop changes
17+
if (error !== prevError) {
18+
setPrevError(error)
19+
setShowError(error !== undefined)
20+
}
21+
22+
return <div
23+
className={cn(styles.errorBar, customClass?.errorBar)}
24+
style={{ '--error-bar-visibility': showError ? 'visible' : 'hidden' } as CSSProperties}
25+
>
26+
<div>
27+
<span>{error?.toString()}</span>
28+
<button
29+
aria-label='Close error message'
30+
onClick={() => { setShowError(false) }}>
31+
&times;
32+
</button>
33+
</div>
34+
</div>
35+
}

src/components/Layout.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ReactNode, useEffect, useState } from 'react'
22
import { cn } from '../lib/utils.js'
3+
import ErrorBar from './ErrorBar.js'
34
import SideBar from './SideBar.js'
45
import Welcome from './Welcome.js'
56

@@ -58,27 +59,3 @@ export default function Layout({ children, className, progress, error, title }:
5859
{showWelcome && <Welcome onClose={handleCloseWelcome} />}
5960
</main>
6061
}
61-
62-
export function ErrorBar({ error }: { error?: Error }) {
63-
const [showError, setShowError] = useState(error !== undefined)
64-
const [prevError, setPrevError] = useState(error)
65-
66-
if (error) console.error(error)
67-
/// Reset error visibility when error prop changes
68-
if (error !== prevError) {
69-
setPrevError(error)
70-
setShowError(error !== undefined)
71-
}
72-
73-
return <div className={cn('error-bar', showError && 'show-error')}>
74-
<div className='error-content'>
75-
<span>{error?.toString()}</span>
76-
<button
77-
aria-label='Close error message'
78-
className='close-button'
79-
onClick={() => { setShowError(false) }}>
80-
&times;
81-
</button>
82-
</div>
83-
</div>
84-
}

src/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Breadcrumb from './Breadcrumb.js'
22
import Cell from './Cell.js'
3+
import ErrorBar from './ErrorBar.js'
34
import File from './File.js'
45
import Folder from './Folder.js'
5-
import Layout, { ErrorBar } from './Layout.js'
6+
import Layout from './Layout.js'
67
import Markdown from './Markdown.js'
78
import Page from './Page.js'
89
import Spinner from './Spinner.js'

src/hooks/useConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Config {
1111
customClass?: {
1212
brand?: string
1313
contentWrapper?: string
14+
errorBar?: string
1415
highTable?: string
1516
imageView?: string
1617
markdownView?: string

src/styles/ErrorBar.module.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.errorBar {
2+
visibility: var(--error-bar-visibility, hidden);
3+
max-height: 30%;
4+
padding: 0;
5+
background-color: #dd111199;
6+
overflow: hidden;
7+
transition: max-height 0.3s;
8+
white-space: pre-wrap;
9+
font-family: monospace;
10+
11+
& > div {
12+
display: flex;
13+
align-items: center;
14+
justify-content: space-between;
15+
min-height: 100%;
16+
overflow-y: auto;
17+
padding: 10px 10px 10px 20px;
18+
}
19+
20+
/* close button */
21+
button,
22+
button:active,
23+
button:focus,
24+
button:focus-visible,
25+
button:hover {
26+
background: none;
27+
border: none;
28+
border-radius: 4px;
29+
padding: 0 8px;
30+
cursor: pointer;
31+
color: #333;
32+
font-size: 30px;
33+
display: flex;
34+
align-items: center;
35+
justify-content: center;
36+
transition: background-color 0.2s;
37+
}
38+
button:active {
39+
background-color: rgba(0, 0, 0, 0.2);
40+
}
41+
button:focus {
42+
background-color: rgba(0, 0, 0, 0.1);
43+
outline: 2px solid #a44;
44+
}
45+
button:hover {
46+
background-color: rgba(0, 0, 0, 0.1);
47+
}
48+
}

src/styles/app.css

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -205,59 +205,6 @@ input.search:focus {
205205
background-color: #3a4;
206206
}
207207

208-
/* error bar */
209-
.error-bar {
210-
max-height: 0;
211-
padding: 0;
212-
background-color: #dd111199;
213-
overflow: hidden;
214-
transition: max-height 0.3s;
215-
white-space: pre-wrap;
216-
}
217-
.error-bar * {
218-
font-family: monospace;
219-
}
220-
.show-error {
221-
max-height: 30%;
222-
}
223-
.error-content {
224-
display: flex;
225-
align-items: center;
226-
justify-content: space-between;
227-
min-height: 100%;
228-
overflow-y: auto;
229-
padding: 10px 10px 10px 20px;
230-
}
231-
232-
/* error bar close button */
233-
.close-button,
234-
.close-button:active,
235-
.close-button:focus,
236-
.close-button:focus-visible,
237-
.close-button:hover {
238-
background: none;
239-
border: none;
240-
border-radius: 4px;
241-
padding: 0 8px;
242-
cursor: pointer;
243-
color: #333;
244-
font-size: 30px;
245-
display: flex;
246-
align-items: center;
247-
justify-content: center;
248-
transition: background-color 0.2s;
249-
}
250-
button.close-button:active {
251-
background-color: rgba(0, 0, 0, 0.2);
252-
}
253-
button.close-button:focus {
254-
background-color: rgba(0, 0, 0, 0.1);
255-
outline: 2px solid #a44;
256-
}
257-
button.close-button:hover {
258-
background-color: rgba(0, 0, 0, 0.1);
259-
}
260-
261208
/* file list */
262209
.file-list {
263210
flex: 1;

0 commit comments

Comments
 (0)