aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/SearchBox.js
blob: dda97989a2c8040b7b56d09e6df39e7886dfb1b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import { useFormState } from 'react-use-form-state';

/**
 * @typedef {Object} SearchBoxPropsFields
 * @property {function} onSearch
 */

 /**
 * @typedef {SearchBoxPropsFields} SearchBoxProps
 */

/**
 * @param {SearchBoxProps} props
 */
function SearchBox({ onSearch }) {
    /**
     * @type {(React.FormEvent<HTMLFormElement>)}
     */
    let onSubmit = (event) => {
        event.preventDefault();
        onSearch(formState.values.search);
    };
    const [formState, { text }] = useFormState();
    return (
        <form onSubmit={onSubmit}>
            <input name="search" className="text"
                placeholder="Search..." value={formState.values.search} {...text('search')} />
        </form>
    );
}

export default SearchBox;