mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 19:46:28 +00:00
d5d0e1036b
* docs: add docs * ignore dumi theme test * fix: error TS2717: Subsequent property declarations must have the same type. * update docs * deploy gh-pages * plugins docs * hash & cname * exportStatic * ssr * vercel * vercel * fix: deploy vercel * Delete vercel.json * docs * fix APP_DIST * on master branch
42 lines
1.1 KiB
TypeScript
Executable File
42 lines
1.1 KiB
TypeScript
Executable File
import React, { useState, useEffect, useRef } from 'react';
|
|
import { useSearch, AnchorLink } from 'dumi/theme';
|
|
import './SearchBar.less';
|
|
|
|
export default () => {
|
|
const [keywords, setKeywords] = useState<string>('');
|
|
const [items, setItems] = useState([]);
|
|
const input = useRef<HTMLInputElement>();
|
|
const result = useSearch(keywords);
|
|
|
|
useEffect(() => {
|
|
if (Array.isArray(result)) {
|
|
setItems(result);
|
|
} else if (typeof result === 'function') {
|
|
result(`.${input.current.className}`);
|
|
}
|
|
}, [result]);
|
|
|
|
return (
|
|
<div className="__dumi-default-search">
|
|
<input
|
|
className="__dumi-default-search-input"
|
|
type="search"
|
|
ref={input}
|
|
{...(Array.isArray(result)
|
|
? { value: keywords, onChange: ev => setKeywords(ev.target.value) }
|
|
: {})}
|
|
/>
|
|
<ul>
|
|
{items.map(meta => (
|
|
<li key={meta.path} onClick={() => setKeywords('')}>
|
|
<AnchorLink to={meta.path}>
|
|
{meta.parent?.title && <span>{meta.parent.title}</span>}
|
|
{meta.title}
|
|
</AnchorLink>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
};
|