import * as React from "react"; import { cx } from "emotion"; import { SearchProps } from "./typings/Search"; import { searchStyle, searchWrapperStyle, clearContainer } from "./styles/Search.styles"; import Loader from "./Loader"; import { colors } from "pebble-shared"; class Search extends React.PureComponent { searchInputRef: React.RefObject = React.createRef(); static defaultProps = { showSearchIcon: true, clearable: true }; render() { const { type, inputProps, onChange, placeholder, showSearchIcon, className, clearable, value, loading } = this.props; const wrapperClassName = cx(searchWrapperStyle, { __pebble__search__small: type === "small", __pebble__search__large: type === "large", __pebble__search__table: type === "table" }); return (
{type !== "large" && showSearchIcon && } ) => { onChange(e.target.value); }} ref={this.searchInputRef} value={value} {...inputProps} /> {loading && } {clearable && (
{ if (this.searchInputRef.current) { this.searchInputRef.current.value = ""; } onChange(""); }} >
)}
); } } export default Search;