Skip to content

Commit 3cc29e1

Browse files
authored
Merge pull request NotionX#379 from NotionX/show-search
made search be able to be shown from outside
2 parents 018a611 + 43e8a47 commit 3cc29e1

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

packages/react-notion-x/src/components/header.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ export const Search: React.FC<{
8787
search?: SearchNotionFn
8888
title?: React.ReactNode
8989
}> = ({ block, search, title = 'Search' }) => {
90-
const { searchNotion, rootPageId } = useNotionContext()
90+
const { searchNotion, rootPageId, isShowingSearch } = useNotionContext()
9191
const onSearchNotion = search || searchNotion
9292

93-
const [isSearchOpen, setIsSearchOpen] = React.useState(false)
93+
const [isSearchOpen, setIsSearchOpen] = React.useState(isShowingSearch)
94+
React.useEffect(() => {
95+
setIsSearchOpen(isShowingSearch)
96+
}, [isShowingSearch])
97+
9498
const onOpenSearch = React.useCallback(() => {
9599
setIsSearchOpen(true)
96100
}, [])

packages/react-notion-x/src/context.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface NotionContext {
2020
mapPageUrl: MapPageUrlFn
2121
mapImageUrl: MapImageUrlFn
2222
searchNotion?: SearchNotionFn
23+
isShowingSearch?: boolean
2324

2425
rootPageId?: string
2526
rootDomain?: string
@@ -47,6 +48,7 @@ export interface PartialNotionContext {
4748
mapPageUrl?: MapPageUrlFn
4849
mapImageUrl?: MapImageUrlFn
4950
searchNotion?: SearchNotionFn
51+
isShowingSearch?: boolean
5052

5153
rootPageId?: string
5254
rootDomain?: string
@@ -148,6 +150,7 @@ const defaultNotionContext: NotionContext = {
148150
mapPageUrl: defaultMapPageUrl(),
149151
mapImageUrl: defaultMapImageUrl,
150152
searchNotion: null,
153+
isShowingSearch: false,
151154

152155
fullPage: false,
153156
darkMode: false,

packages/react-notion-x/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export * from './context'
66
export * from './components/text'
77
export * from './components/header'
88
export * from './components/page-icon'
9-
export * from './components/search-dialog'

packages/react-notion-x/src/renderer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const NotionRenderer: React.FC<{
1818
mapPageUrl?: MapPageUrlFn
1919
mapImageUrl?: MapImageUrlFn
2020
searchNotion?: SearchNotionFn
21+
isShowingSearch?: boolean
2122

2223
rootPageId?: string
2324
rootDomain?: string
@@ -60,6 +61,7 @@ export const NotionRenderer: React.FC<{
6061
mapPageUrl,
6162
mapImageUrl,
6263
searchNotion,
64+
isShowingSearch,
6365
fullPage,
6466
rootPageId,
6567
rootDomain,
@@ -94,6 +96,7 @@ export const NotionRenderer: React.FC<{
9496
mapPageUrl={mapPageUrl}
9597
mapImageUrl={mapImageUrl}
9698
searchNotion={searchNotion}
99+
isShowingSearch={isShowingSearch}
97100
fullPage={fullPage}
98101
rootPageId={rootPageId}
99102
rootDomain={rootDomain}

0 commit comments

Comments
 (0)