// @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
|