Skip to content

Commit dbf56e2

Browse files
committed
extract SideBar to its component + CSS module
1 parent 90ffb0a commit dbf56e2

File tree

4 files changed

+71
-56
lines changed

4 files changed

+71
-56
lines changed

src/components/Layout.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ReactNode, useEffect, useState } from 'react'
22
import { cn } from '../lib/utils.js'
3+
import SideBar, { SideBarConfig } from './SideBar.js'
34
import Welcome, { WelcomeConfig } from './Welcome.js'
45

5-
export type LayoutConfig = WelcomeConfig
6+
export type LayoutConfig = WelcomeConfig & SideBarConfig
67

78
interface LayoutProps {
89
children: ReactNode
@@ -46,7 +47,7 @@ export default function Layout({ children, className, progress, error, title, co
4647
}, [title])
4748

4849
return <main className='main'>
49-
<Sidebar />
50+
<SideBar config={config} />
5051
<div className='content-container'>
5152
<div className={cn('content', className)}>
5253
{children}
@@ -62,14 +63,6 @@ export default function Layout({ children, className, progress, error, title, co
6263
</main>
6364
}
6465

65-
function Sidebar() {
66-
return <nav className='nav'>
67-
<div>
68-
<a className="brand" href='/'>hyperparam</a>
69-
</div>
70-
</nav>
71-
}
72-
7366
export function Spinner({ className }: { className?: string }) {
7467
return <div className={cn('spinner', className)}></div>
7568
}

src/components/SideBar.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { cn } from '../lib/utils.js'
2+
import styles from '../styles/SideBar.module.css'
3+
4+
export interface SideBarConfig {
5+
sideBar?: {
6+
className?: string
7+
},
8+
brand?: {
9+
className?: string
10+
}
11+
}
12+
13+
interface SideBarProps {
14+
config?: SideBarConfig
15+
}
16+
17+
export default function SideBar({ config }: SideBarProps) {
18+
return <nav className={cn(styles.sideBar, config?.sideBar?.className)}>
19+
<div>
20+
<a className={cn(styles.brand, config?.brand?.className)} href='/'>hyperparam</a>
21+
</div>
22+
</nav>
23+
}

src/styles/SideBar.module.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* sidebar */
2+
.sideBar {
3+
display: flex;
4+
flex-direction: column;
5+
height: 100vh;
6+
width: 48px;
7+
height: 100vh;
8+
}
9+
.sideBar > div {
10+
background-image: linear-gradient(to bottom, #f2f2f2, #e4e4e4);
11+
box-shadow: 0 0 6px rgba(10, 10, 10, 0.4);
12+
height: 100vh;
13+
position: absolute;
14+
width: 48px;
15+
z-index: 30;
16+
}
17+
18+
/* brand logo */
19+
.brand {
20+
align-items: center;
21+
color: #222;
22+
display: flex;
23+
filter: drop-shadow(0 0 2px #bbb);
24+
font-family: "Century Gothic", "Helvetica Neue", Helvetica, Arial, sans-serif;
25+
font-size: 1.1em;
26+
font-weight: bold;
27+
text-orientation: mixed;
28+
letter-spacing: 0.3px;
29+
padding: 10px 12px;
30+
user-select: none;
31+
writing-mode: vertical-rl;
32+
}
33+
.brand:hover {
34+
color: #222;
35+
filter: drop-shadow(0 0 2px #afa6b9);
36+
text-decoration: none;
37+
}
38+
.brand::before {
39+
content: "";
40+
background: url("../assets/logo.svg") no-repeat 0 center;
41+
background-size: 26px;
42+
height: 26px;
43+
width: 26px;
44+
margin-bottom: 10px;
45+
}

src/styles/app.css

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,6 @@ li {
5656
height: 100vh;
5757
}
5858

59-
/* brand logo */
60-
.brand {
61-
align-items: center;
62-
color: #222;
63-
display: flex;
64-
filter: drop-shadow(0 0 2px #bbb);
65-
font-family: 'Century Gothic', 'Helvetica Neue', Helvetica, Arial, sans-serif;
66-
font-size: 1.1em;
67-
font-weight: bold;
68-
text-orientation: mixed;
69-
letter-spacing: 0.3px;
70-
padding: 10px 12px;
71-
user-select: none;
72-
writing-mode: vertical-rl;
73-
}
74-
.brand:hover {
75-
color: #222;
76-
filter: drop-shadow(0 0 2px #afa6b9);
77-
text-decoration: none;
78-
}
79-
.brand::before {
80-
content: '';
81-
background: url("../assets/logo.svg") no-repeat 0 center;
82-
background-size: 26px;
83-
height: 26px;
84-
width: 26px;
85-
margin-bottom: 10px;
86-
}
87-
8859
a {
8960
color: #342267;
9061
cursor: pointer;
@@ -125,23 +96,6 @@ main {
12596
justify-content: center;
12697
}
12798

128-
/* sidebar */
129-
.nav {
130-
display: flex;
131-
flex-direction: column;
132-
height: 100vh;
133-
width: 48px;
134-
height: 100vh;
135-
}
136-
.nav > div {
137-
background-image: linear-gradient(to bottom, #f2f2f2, #e4e4e4);
138-
box-shadow: 0 0 6px rgba(10, 10, 10, 0.4);
139-
height: 100vh;
140-
position: absolute;
141-
width: 48px;
142-
z-index: 30;
143-
}
144-
14599
/* content area */
146100
.content-container {
147101
min-width: 0;

0 commit comments

Comments
 (0)