2020-04-04 05:39:53 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2020-07-05 01:46:09 +00:00
|
|
|
import { faSearch } from '@fortawesome/free-solid-svg-icons';
|
2020-04-04 05:39:53 +00:00
|
|
|
import useEventListener from '@/plugins/useEventListener';
|
|
|
|
import SearchModal from '@/components/dashboard/search/SearchModal';
|
2022-06-12 13:35:02 +00:00
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
2020-04-04 05:39:53 +00:00
|
|
|
|
|
|
|
export default () => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
2020-04-04 05:39:53 +00:00
|
|
|
|
|
|
|
useEventListener('keydown', (e: KeyboardEvent) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
if (['input', 'textarea'].indexOf(((e.target as HTMLElement).tagName || 'input').toLowerCase()) < 0) {
|
2020-12-25 23:55:31 +00:00
|
|
|
if (!visible && e.metaKey && e.key.toLowerCase() === '/') {
|
2020-04-04 05:39:53 +00:00
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-06-26 19:13:52 +00:00
|
|
|
{visible && <SearchModal appear visible={visible} onDismissed={() => setVisible(false)} />}
|
2022-06-12 13:35:02 +00:00
|
|
|
<Tooltip placement={'bottom'} content={'Search'}>
|
|
|
|
<div className={'navigation-link'} onClick={() => setVisible(true)}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<FontAwesomeIcon icon={faSearch} />
|
2022-06-12 13:35:02 +00:00
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2020-04-04 05:39:53 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|