Skip to content

Commit 4eb2408

Browse files
committed
reverse the config keys to group all class names under customClass
1 parent dbf56e2 commit 4eb2408

File tree

5 files changed

+22
-39
lines changed

5 files changed

+22
-39
lines changed

src/components/Layout.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { ReactNode, useEffect, useState } from 'react'
22
import { cn } from '../lib/utils.js'
3-
import SideBar, { SideBarConfig } from './SideBar.js'
4-
import Welcome, { WelcomeConfig } from './Welcome.js'
5-
6-
export type LayoutConfig = WelcomeConfig & SideBarConfig
3+
import SideBar from './SideBar.js'
4+
import Welcome from './Welcome.js'
75

86
interface LayoutProps {
97
children: ReactNode
108
className?: string
119
progress?: number
1210
error?: Error
1311
title?: string
14-
config?: LayoutConfig
1512
}
1613

1714
/**
@@ -24,9 +21,8 @@ interface LayoutProps {
2421
* @param props.progress - progress bar value
2522
* @param props.error - error message to display
2623
* @param props.title - page title
27-
* @param props.config - configuration for the layout
2824
*/
29-
export default function Layout({ children, className, progress, error, title, config }: LayoutProps) {
25+
export default function Layout({ children, className, progress, error, title }: LayoutProps) {
3026
const [showWelcome, setShowWelcome] = useState(false)
3127

3228
// Check localStorage on mount to see if the user has seen the welcome popup
@@ -47,7 +43,7 @@ export default function Layout({ children, className, progress, error, title, co
4743
}, [title])
4844

4945
return <main className='main'>
50-
<SideBar config={config} />
46+
<SideBar />
5147
<div className='content-container'>
5248
<div className={cn('content', className)}>
5349
{children}
@@ -59,7 +55,7 @@ export default function Layout({ children, className, progress, error, title, co
5955
<div style={{ width: `${100 * progress}%` }} />
6056
</div>
6157
}
62-
{showWelcome && <Welcome onClose={handleCloseWelcome} config={config}/>}
58+
{showWelcome && <Welcome onClose={handleCloseWelcome} />}
6359
</main>
6460
}
6561

src/components/SideBar.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1+
import { useConfig } from '../hooks/useConfig.js'
12
import { cn } from '../lib/utils.js'
23
import styles from '../styles/SideBar.module.css'
34

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)}>
5+
export default function SideBar() {
6+
const { customClass } = useConfig()
7+
return <nav className={cn(styles.sideBar, customClass?.sideBar)}>
198
<div>
20-
<a className={cn(styles.brand, config?.brand?.className)} href='/'>hyperparam</a>
9+
<a className={cn(styles.brand, customClass?.brand)} href='/'>hyperparam</a>
2110
</div>
2211
</nav>
2312
}

src/components/Welcome.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import { MouseEvent, useEffect } from 'react'
2+
import { useConfig } from '../hooks/useConfig.js'
23
import { cn } from '../lib/utils.js'
34
import styles from '../styles/Welcome.module.css'
45

5-
export interface WelcomeConfig {
6-
welcome?: {
7-
className?: string
8-
}
9-
}
10-
116
interface WelcomePopupProps {
127
onClose: () => void,
13-
config?: WelcomeConfig
148
}
159

1610
/**
1711
* Welcome popup component shown to first-time users.
1812
* Clicking outside the popup or pressing Escape will dismiss it.
1913
*/
20-
export default function Welcome({ onClose, config }: WelcomePopupProps) {
14+
export default function Welcome({ onClose }: WelcomePopupProps) {
15+
const { customClass } = useConfig()
2116
// Close popup when clicking outside
2217
function handleBackdropClick(e: MouseEvent) {
2318
if (e.target === e.currentTarget) {
@@ -38,7 +33,7 @@ export default function Welcome({ onClose, config }: WelcomePopupProps) {
3833
}, [onClose])
3934

4035
return (
41-
<div className={cn(styles.welcome, config?.welcome?.className)} onClick={handleBackdropClick}>
36+
<div className={cn(styles.welcome, customClass?.welcome)} onClick={handleBackdropClick}>
4237
<div>
4338
<h2>npx hyperparam</h2>
4439
<p>

src/components/viewers/ParquetView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function ParquetView({ source, setProgress, setError }: ViewerPro
2929
const [isLoading, setIsLoading] = useState<boolean>(true)
3030
const [content, setContent] = useState<Content>()
3131
const [cell, setCell] = useState<{ row: number, col: number } | undefined>()
32-
const { highTable, routes } = useConfig()
32+
const { customClass, routes } = useConfig()
3333

3434
useEffect(() => {
3535
async function loadParquetDataFrame() {
@@ -102,7 +102,7 @@ export default function ParquetView({ source, setProgress, setError }: ViewerPro
102102
onDoubleClickCell={onDoubleClickCell}
103103
onMouseDownCell={onMouseDownCell}
104104
onError={setError}
105-
className={cn(styles.hightable, highTable?.className)}
105+
className={cn(styles.hightable, customClass?.highTable)}
106106
/>}
107107

108108
{isLoading && <div className='center'><Spinner /></div>}

src/hooks/useConfig.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import { createContext, useContext } from 'react'
88
* It gives a way to pass additional values to the components, for example custom CSS classes.
99
*/
1010
export interface Config {
11-
highTable?: {
12-
className?: string;
11+
customClass?: {
12+
brand?: string
13+
highTable?: string
14+
sideBar?: string
15+
welcome?: string
1316
}
1417
routes?: {
1518
getSourceRouteUrl?: (params: { sourceId: string }) => string
@@ -18,7 +21,7 @@ export interface Config {
1821
slidePanel?: {
1922
minWidth?: number
2023
defaultWidth?: number
21-
}
24+
},
2225
}
2326

2427
const ConfigContext = createContext<Config>({})

0 commit comments

Comments
 (0)