All files / SearchInput index.js

100% Statements 5/5
100% Branches 3/3
100% Functions 3/3
100% Lines 5/5
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                          3x 27x     2x   2x           3x              
// @ts-check
import React from "react"
import styles from "./styles.css"
import PropTypes from "prop-types"
 
/**
 * @typedef {Object} Props - Component Props
 * @prop {React.ReactText} [value=""] - a string property representing the value of the input
 * @prop {(s:string) => any=} onChange - callback function to handle input change
 * @prop {boolean=} border - an optional prop to enable ui border
 */
 
/** @type React.FC<Props>  */
const SearchInput = ({ value = "", onChange, border }) => (
    <div className={`${styles.search} ${border ? styles.withBorder : ""}`.trim()}>
        <span className={styles.searchIcon}>Q</span>
        <div className={styles.searchInput}>
            <input value={value} onChange={e => onChange(e.target.value)} />
        </div>
        <button hidden={!value} className={styles.cleanIcon} onClick={() => onChange("")}>
            x
        </button>
    </div>
)
 
SearchInput.propTypes = {
    value: PropTypes.string,
    onChange: PropTypes.func,
    border: PropTypes.bool
}
 
export default SearchInput