1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

clearing search

This commit is contained in:
Fedor Katurov 2020-04-18 18:46:51 +07:00
parent 9498c7b7a0
commit 47adbdf6f0
13 changed files with 215 additions and 195 deletions

View file

@ -1,4 +1,4 @@
import React, { FC, useCallback, FormEvent } from 'react';
import React, { FC, useCallback, FormEvent, useMemo, KeyboardEvent } from 'react';
import { IFlowState } from '~/redux/flow/reducer';
import { InputText } from '~/components/input/InputText';
import { FlowRecent } from '../FlowRecent';
@ -7,6 +7,7 @@ import classnames from 'classnames';
import * as styles from './styles.scss';
import * as FLOW_ACTIONS from '~/redux/flow/actions';
import { FlowSearchResults } from '../FlowSearchResults';
import { Icon } from '~/components/input/Icon';
interface IProps {
recent: IFlowState['recent'];
@ -25,10 +26,37 @@ const FlowStamp: FC<IProps> = ({ recent, updated, search, flowChangeSearch, onLo
event.preventDefault();
}, []);
const onClearSearch = useCallback(() => flowChangeSearch({ text: '' }), [flowChangeSearch]);
const onKeyUp = useCallback(
event => {
if (event.key !== 'Escape') return;
onClearSearch();
event.target.blur();
},
[onClearSearch]
);
const after = useMemo(
() =>
search.text ? (
<Icon icon="close" size={24} className={styles.close_icon} onClick={onClearSearch} />
) : (
<Icon icon="search" size={24} className={styles.search_icon} />
),
[search.text]
);
return (
<div className={styles.wrap}>
<form className={styles.search} onSubmit={onSearchSubmit}>
<InputText title="Поиск" value={search.text} handler={onSearchChange} />
<InputText
title="Поиск"
value={search.text}
handler={onSearchChange}
after={after}
onKeyUp={onKeyUp}
/>
</form>
<div className={styles.grid}>