Skip to content

Commit 557783a

Browse files
committed
move Welcome CSS to a CSS module + allow overriding
1 parent e4ff6e8 commit 557783a

File tree

4 files changed

+59
-47
lines changed

4 files changed

+59
-47
lines changed

src/components/Layout.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { ReactNode, useEffect, useState } from 'react'
22
import { cn } from '../lib/utils.js'
3-
import Welcome from './Welcome.js'
3+
import Welcome, { WelcomeConfig } from './Welcome.js'
4+
5+
export type LayoutConfig = WelcomeConfig
46

57
interface LayoutProps {
68
children: ReactNode
79
className?: string
810
progress?: number
911
error?: Error
1012
title?: string
13+
config?: LayoutConfig
1114
}
1215

1316
/**
@@ -20,8 +23,9 @@ interface LayoutProps {
2023
* @param props.progress - progress bar value
2124
* @param props.error - error message to display
2225
* @param props.title - page title
26+
* @param props.config - configuration for the layout
2327
*/
24-
export default function Layout({ children, className, progress, error, title }: LayoutProps) {
28+
export default function Layout({ children, className, progress, error, title, config }: LayoutProps) {
2529
const [showWelcome, setShowWelcome] = useState(false)
2630

2731
// Check localStorage on mount to see if the user has seen the welcome popup
@@ -54,7 +58,7 @@ export default function Layout({ children, className, progress, error, title }:
5458
<div style={{ width: `${100 * progress}%` }} />
5559
</div>
5660
}
57-
{showWelcome && <Welcome onClose={handleCloseWelcome} />}
61+
{showWelcome && <Welcome onClose={handleCloseWelcome} config={config}/>}
5862
</main>
5963
}
6064

src/components/Welcome.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { MouseEvent, useEffect } from 'react'
2+
import { cn } from '../lib/utils.js'
3+
import styles from '../styles/Welcome.module.css'
4+
5+
export interface WelcomeConfig {
6+
welcome: {
7+
className?: string
8+
}
9+
}
210

311
interface WelcomePopupProps {
4-
onClose: () => void
12+
onClose: () => void,
13+
config?: WelcomeConfig
514
}
615

716
/**
817
* Welcome popup component shown to first-time users.
918
* Clicking outside the popup or pressing Escape will dismiss it.
1019
*/
11-
export default function Welcome({ onClose }: WelcomePopupProps) {
20+
export default function Welcome({ onClose, config }: WelcomePopupProps) {
1221
// Close popup when clicking outside
1322
function handleBackdropClick(e: MouseEvent) {
1423
if (e.target === e.currentTarget) {
@@ -29,7 +38,7 @@ export default function Welcome({ onClose }: WelcomePopupProps) {
2938
}, [onClose])
3039

3140
return (
32-
<div className="welcome" onClick={handleBackdropClick}>
41+
<div className={cn(styles.welcome, config?.welcome.className)} onClick={handleBackdropClick}>
3342
<div>
3443
<h2>npx hyperparam</h2>
3544
<p>

src/styles/Welcome.module.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Welcome popup */
2+
.welcome {
3+
position: fixed;
4+
top: 0;
5+
left: 0;
6+
right: 0;
7+
bottom: 0;
8+
display: flex;
9+
align-items: center;
10+
justify-content: center;
11+
z-index: 1000;
12+
animation: fadeIn 0.3s ease-in;
13+
}
14+
15+
.welcome > div {
16+
background-color: white;
17+
border-radius: 8px;
18+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
19+
display: flex;
20+
flex-direction: column;
21+
padding: 30px;
22+
width: 450px;
23+
max-width: 90%;
24+
}
25+
26+
.welcome h2 {
27+
color: #342267;
28+
margin-bottom: 16px;
29+
font-size: 24px;
30+
}
31+
32+
.welcome p {
33+
color: #444;
34+
line-height: 1.5;
35+
margin-bottom: 24px;
36+
}
37+
38+
.welcome button {
39+
margin-left: auto;
40+
}

src/styles/app.css

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -531,44 +531,3 @@ button.close-button:hover {
531531
overflow-x: auto;
532532
white-space: pre-wrap;
533533
}
534-
535-
/* Welcome popup */
536-
.welcome {
537-
position: fixed;
538-
top: 0;
539-
left: 0;
540-
right: 0;
541-
bottom: 0;
542-
display: flex;
543-
align-items: center;
544-
justify-content: center;
545-
z-index: 1000;
546-
animation: fadeIn 0.3s ease-in;
547-
}
548-
549-
.welcome > div {
550-
background-color: white;
551-
border-radius: 8px;
552-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
553-
display: flex;
554-
flex-direction: column;
555-
padding: 30px;
556-
width: 450px;
557-
max-width: 90%;
558-
}
559-
560-
.welcome h2 {
561-
color: #342267;
562-
margin-bottom: 16px;
563-
font-size: 24px;
564-
}
565-
566-
.welcome p {
567-
color: #444;
568-
line-height: 1.5;
569-
margin-bottom: 24px;
570-
}
571-
572-
.welcome button {
573-
margin-left: auto;
574-
}

0 commit comments

Comments
 (0)