Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/components/Welcome/Welcome.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fireEvent, render } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { ConfigProvider } from '../../hooks/useConfig.js'
import Welcome from './Welcome.js'

describe('Welcome Component', () => {
Expand Down Expand Up @@ -64,4 +65,18 @@ describe('Welcome Component', () => {
fireEvent.keyDown(window, { key: 'Enter' })
expect(onClose).not.toHaveBeenCalled()
})

it('renders custom content and button text', () => {
const onClose = vi.fn()
const customContent = <p>Custom welcome message</p>
const customButtonText = 'Custom Got it'
const { getByText } = render(
<ConfigProvider value={{ welcome: { content: customContent, buttonText: customButtonText } }}>
<Welcome onClose={onClose} />
</ConfigProvider>
)

expect(getByText('Custom welcome message')).toBeDefined()
expect(getByText('Custom Got it')).toBeDefined()
})
})
20 changes: 11 additions & 9 deletions src/components/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface WelcomePopupProps {
* Clicking outside the popup or pressing Escape will dismiss it.
*/
export default function Welcome({ onClose }: WelcomePopupProps) {
const { customClass } = useConfig()
const { customClass, welcome } = useConfig()
// Close popup when clicking outside
function handleBackdropClick(e: MouseEvent) {
if (e.target === e.currentTarget) {
Expand All @@ -35,18 +35,20 @@ export default function Welcome({ onClose }: WelcomePopupProps) {
return (
<div className={cn(styles.welcome, customClass?.welcome)} onClick={handleBackdropClick}>
<div>
<h2>npx hyperparam</h2>
<p>
{welcome?.content ?? <>
<h2>npx hyperparam</h2>
<p>
This is the <a href="https://hyperparam.app">Hyperparam</a> cli for local data viewing.
</p>
<p>
</p>
<p>
This tool lets you browse and explore large datasets particularly in parquet format.
</p>
<p>
</p>
<p>
Supported file types include Parquet, CSV, JSON, Markdown, and Text.
</p>
</p>
</>}
<button onClick={onClose}>
Got it
{welcome?.buttonText ?? 'Got it'}
</button>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext } from 'react'
import { ReactNode, createContext, useContext } from 'react'

/**
* Config is a flat object of key-value pairs.
Expand Down Expand Up @@ -37,6 +37,10 @@ export interface Config {
minWidth?: number
defaultWidth?: number
}
welcome?: {
content?: ReactNode
buttonText?: string
}
}

const ConfigContext = createContext<Config>({})
Expand Down