-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
509 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {Router} from '@diplodoc/components'; | ||
|
||
import {createContext, useContext} from 'react'; | ||
|
||
export interface RouterConfig extends Router { | ||
depth: number; | ||
} | ||
|
||
export const RouterContext = createContext<RouterConfig>({ | ||
pathname: '/', | ||
depth: 0, | ||
}); | ||
|
||
RouterContext.displayName = 'RouterContext'; | ||
|
||
export const RouterProvider = RouterContext.Provider; | ||
|
||
export function useRouter() { | ||
return useContext(RouterContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
export const Search = () => { | ||
return <div>Initial</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.Suggest { | ||
margin-right: 20px; | ||
min-width: 200px; | ||
transition: min-width 0.3s; | ||
|
||
.dc-root_focused-search & { | ||
min-width: 500px; | ||
} | ||
|
||
&__Item { | ||
&__Marker { | ||
background: var(--g-color-base-neutral-medium); | ||
padding: 0 3px 1px; | ||
border-radius: 4px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type {ISearchProvider, SearchSuggestApi} from '@diplodoc/components'; | ||
|
||
import React, {useCallback, useRef} from 'react'; | ||
import {SearchSuggest} from '@diplodoc/components'; | ||
|
||
import {updateRootClassName} from '../../utils'; | ||
|
||
import {useProvider} from './useProvider'; | ||
import './Suggest.scss'; | ||
|
||
export function Suggest() { | ||
const provider: ISearchProvider | null = useProvider(); | ||
const suggest = useRef<SearchSuggestApi>(null); | ||
|
||
const onFocus = useCallback(() => { | ||
updateRootClassName({focusSearch: true}); | ||
}, []); | ||
|
||
const onBlur = useCallback(() => { | ||
updateRootClassName({focusSearch: false}); | ||
setTimeout(() => { | ||
if (suggest.current) { | ||
suggest.current.close(); | ||
} | ||
}, 100); | ||
}, []); | ||
|
||
if (!provider) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SearchSuggest | ||
ref={suggest} | ||
provider={provider} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
classNameContainer={'Suggest'} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type {SearchConfig, WorkerApi, WorkerConfig} from './types'; | ||
|
||
import {createContext} from 'react'; | ||
|
||
export type {SearchConfig, WorkerConfig, WorkerApi}; | ||
|
||
export const SearchContext = createContext<SearchConfig | null | undefined>(null); | ||
|
||
SearchContext.displayName = 'SearchContext'; | ||
|
||
export const SearchProvider = SearchContext.Provider; | ||
|
||
export {Search} from './Search'; |
Oops, something went wrong.