Skip to content

Commit aed8d31

Browse files
authored
Add configuration options to tweak the welcome popop (#217)
see hyparam/space#21
1 parent e155a20 commit aed8d31

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/components/Welcome/Welcome.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fireEvent, render } from '@testing-library/react'
22
import { describe, expect, it, vi } from 'vitest'
3+
import { ConfigProvider } from '../../hooks/useConfig.js'
34
import Welcome from './Welcome.js'
45

56
describe('Welcome Component', () => {
@@ -64,4 +65,18 @@ describe('Welcome Component', () => {
6465
fireEvent.keyDown(window, { key: 'Enter' })
6566
expect(onClose).not.toHaveBeenCalled()
6667
})
68+
69+
it('renders custom content and button text', () => {
70+
const onClose = vi.fn()
71+
const customContent = <p>Custom welcome message</p>
72+
const customButtonText = 'Custom Got it'
73+
const { getByText } = render(
74+
<ConfigProvider value={{ welcome: { content: customContent, buttonText: customButtonText } }}>
75+
<Welcome onClose={onClose} />
76+
</ConfigProvider>
77+
)
78+
79+
expect(getByText('Custom welcome message')).toBeDefined()
80+
expect(getByText('Custom Got it')).toBeDefined()
81+
})
6782
})

src/components/Welcome/Welcome.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface WelcomePopupProps {
1212
* Clicking outside the popup or pressing Escape will dismiss it.
1313
*/
1414
export default function Welcome({ onClose }: WelcomePopupProps) {
15-
const { customClass } = useConfig()
15+
const { customClass, welcome } = useConfig()
1616
// Close popup when clicking outside
1717
function handleBackdropClick(e: MouseEvent) {
1818
if (e.target === e.currentTarget) {
@@ -35,18 +35,20 @@ export default function Welcome({ onClose }: WelcomePopupProps) {
3535
return (
3636
<div className={cn(styles.welcome, customClass?.welcome)} onClick={handleBackdropClick}>
3737
<div>
38-
<h2>npx hyperparam</h2>
39-
<p>
38+
{welcome?.content ?? <>
39+
<h2>npx hyperparam</h2>
40+
<p>
4041
This is the <a href="https://hyperparam.app">Hyperparam</a> cli for local data viewing.
41-
</p>
42-
<p>
42+
</p>
43+
<p>
4344
This tool lets you browse and explore large datasets particularly in parquet format.
44-
</p>
45-
<p>
45+
</p>
46+
<p>
4647
Supported file types include Parquet, CSV, JSON, Markdown, and Text.
47-
</p>
48+
</p>
49+
</>}
4850
<button onClick={onClose}>
49-
Got it
51+
{welcome?.buttonText ?? 'Got it'}
5052
</button>
5153
</div>
5254
</div>

src/hooks/useConfig.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useContext } from 'react'
1+
import { ReactNode, createContext, useContext } from 'react'
22

33
/**
44
* Config is a flat object of key-value pairs.
@@ -37,6 +37,10 @@ export interface Config {
3737
minWidth?: number
3838
defaultWidth?: number
3939
}
40+
welcome?: {
41+
content?: ReactNode
42+
buttonText?: string
43+
}
4044
}
4145

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

0 commit comments

Comments
 (0)