diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-05-28 16:17:13 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-06-04 11:25:34 +0200 |
commit | b614604effda51ca7c76c8901be78ced62b642b2 (patch) | |
tree | 971fc02905cf3e0c75ef4fb00d93ce72b43936cb /plugins/base/frontend/src/main/components/search | |
parent | 4065a65fe3294e0ddf54f5756380f7dc1aa032b2 (diff) | |
download | dokka-b614604effda51ca7c76c8901be78ced62b642b2.tar.gz dokka-b614604effda51ca7c76c8901be78ced62b642b2.tar.bz2 dokka-b614604effda51ca7c76c8901be78ced62b642b2.zip |
Update TS migration to current dev, move to a common package, rename to frontend
Diffstat (limited to 'plugins/base/frontend/src/main/components/search')
-rw-r--r-- | plugins/base/frontend/src/main/components/search/search.tsx | 45 | ||||
-rw-r--r-- | plugins/base/frontend/src/main/components/search/types.ts | 26 |
2 files changed, 71 insertions, 0 deletions
diff --git a/plugins/base/frontend/src/main/components/search/search.tsx b/plugins/base/frontend/src/main/components/search/search.tsx new file mode 100644 index 00000000..f0df0c98 --- /dev/null +++ b/plugins/base/frontend/src/main/components/search/search.tsx @@ -0,0 +1,45 @@ +import React, {useCallback, useState} from 'react'; +import {Select} from '@jetbrains/ring-ui'; +import '@jetbrains/ring-ui/components/input-size/input-size.scss'; +import {IWindow, Option, Props, State} from "./types"; + +const WithFuzzySearchFilterComponent: React.FC<Props> = ({data}: Props) => { + const [selected, onSelected] = useState<Option>(data[0]); + const onChangeSelected = useCallback( + (option: Option) => { + window.location.replace(`${(window as IWindow).pathToRoot}${option.location}?query=${option.name}`) + onSelected(option); + }, + [data] + ); + return ( + <div className="search-container"> + <div className="search"> + <Select + selectedLabel="Search" + label="Please type page name" + filter={{fuzzy: true}} + clear + selected={selected} + data={data} + onSelect={onChangeSelected} + /> + </div> + </div> + ) +} + +export const WithFuzzySearchFilter = () => { + let data: Option[] = []; + const pages = (window as IWindow).pages; + if (pages) { + data = pages.map((page, i) => ({ + ...page, + label: page.name, + key: i + 1, + type: page.kind + })); + } + + return <WithFuzzySearchFilterComponent data={data}/>; +}; diff --git a/plugins/base/frontend/src/main/components/search/types.ts b/plugins/base/frontend/src/main/components/search/types.ts new file mode 100644 index 00000000..2900153a --- /dev/null +++ b/plugins/base/frontend/src/main/components/search/types.ts @@ -0,0 +1,26 @@ +export type Page = { + name: string; + kind: string; + location: string; +} + +export type Option = Page & { + label: string; + key: number; + location: string; + name: string; +} + +export type IWindow = typeof window & { + pathToRoot: string + pages: Page[] +} + +export type Props = { + data: Option[] +}; + + +export type State = { + selected: any +} |