Skip to content

Commit c501fa4

Browse files
committed
extract Layout styles to CSS Module
1 parent 2eb13be commit c501fa4

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

src/components/Layout.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ReactNode, useEffect, useState } from 'react'
2+
import { useConfig } from '../hooks/useConfig.js'
23
import { cn } from '../lib/utils.js'
4+
import styles from '../styles/Layout.module.css'
35
import ErrorBar from './ErrorBar.js'
46
import ProgressBar from './ProgressBar.js'
57
import SideBar from './SideBar.js'
68
import Welcome from './Welcome.js'
79

810
interface LayoutProps {
911
children: ReactNode
10-
className?: string
1112
progress?: number
1213
error?: Error
1314
title?: string
@@ -19,13 +20,13 @@ interface LayoutProps {
1920
*
2021
* @param props
2122
* @param props.children - content to display inside the layout
22-
* @param props.className - additional class names to apply to the content container
2323
* @param props.progress - progress bar value
2424
* @param props.error - error message to display
2525
* @param props.title - page title
2626
*/
27-
export default function Layout({ children, className, progress, error, title }: LayoutProps) {
27+
export default function Layout({ children, progress, error, title }: LayoutProps) {
2828
const [showWelcome, setShowWelcome] = useState(false)
29+
const { customClass } = useConfig()
2930

3031
// Check localStorage on mount to see if the user has seen the welcome popup
3132
useEffect(() => {
@@ -44,15 +45,15 @@ export default function Layout({ children, className, progress, error, title }:
4445
document.title = title ? `${title} - hyperparam` : 'hyperparam'
4546
}, [title])
4647

47-
return <main className='main'>
48+
return <div className={cn(styles.layout, customClass?.layout)}>
4849
<SideBar />
49-
<div className='content-container'>
50-
<div className={cn('content', className)}>
50+
<main>
51+
<div>
5152
{children}
5253
</div>
5354
<ErrorBar error={error}></ErrorBar>
54-
</div>
55+
</main>
5556
{progress !== undefined && progress < 1 && <ProgressBar value={progress} />}
5657
{showWelcome && <Welcome onClose={handleCloseWelcome} />}
57-
</main>
58+
</div>
5859
}

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
errorBar?: string
1616
highTable?: string
1717
imageView?: string
18+
layout?: string
1819
markdownView?: string
1920
path?: string
2021
progressBar?: string

src/styles/Layout.module.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.layout {
2+
/* layout */
3+
display: flex;
4+
height: 100vh;
5+
max-width: 100vw;
6+
7+
/* content area */
8+
main {
9+
min-width: 0;
10+
height: 100vh;
11+
display: flex;
12+
flex-direction: column;
13+
flex: 1;
14+
15+
& > div:first-child {
16+
display: flex;
17+
flex-direction: column;
18+
flex: 1;
19+
height: 100vh;
20+
padding: 0;
21+
/* no outer scrollbars */
22+
overflow: hidden;
23+
}
24+
}
25+
}

src/styles/app.css

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,13 @@ a:hover {
6666
text-decoration: underline;
6767
}
6868

69-
/* layout */
70-
main {
71-
display: flex;
72-
height: 100vh;
73-
max-width: 100vw;
74-
}
75-
7669
.center {
7770
flex: 1;
7871
display: flex;
7972
align-items: center;
8073
justify-content: center;
8174
}
8275

83-
/* content area */
84-
.content-container {
85-
min-width: 0;
86-
height: 100vh;
87-
display: flex;
88-
flex-direction: column;
89-
flex: 1;
90-
}
91-
.content {
92-
display: flex;
93-
flex-direction: column;
94-
flex: 1;
95-
height: 100vh;
96-
padding: 0;
97-
/* no outer scrollbars */
98-
overflow: hidden;
99-
}
100-
10176
.top-actions {
10277
left: auto;
10378
}

0 commit comments

Comments
 (0)