Add very simple search support to pages, togglable with "k"
This commit is contained in:
parent
807cd815ea
commit
0dbf6b51b5
8 changed files with 216 additions and 4 deletions
|
@ -0,0 +1,32 @@
|
|||
import React, { useState } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSearch } from '@fortawesome/free-solid-svg-icons/faSearch';
|
||||
import useEventListener from '@/plugins/useEventListener';
|
||||
import SearchModal from '@/components/dashboard/search/SearchModal';
|
||||
|
||||
export default () => {
|
||||
const [ visible, setVisible ] = useState(false);
|
||||
|
||||
useEventListener('keydown', (e: KeyboardEvent) => {
|
||||
if ([ 'input', 'textarea' ].indexOf(((e.target as HTMLElement).tagName || 'input').toLowerCase()) < 0) {
|
||||
if (!visible && e.key.toLowerCase() === 'k') {
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{visible &&
|
||||
<SearchModal
|
||||
appear={true}
|
||||
visible={visible}
|
||||
onDismissed={() => setVisible(false)}
|
||||
/>
|
||||
}
|
||||
<div className={'navigation-link'} onClick={() => setVisible(true)}>
|
||||
<FontAwesomeIcon icon={faSearch}/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
Reference in a new issue