2022-11-15 17:49:02 +01:00
import React from 'react' ;
import PropTypes from 'prop-types' ;
import classnames from 'classnames' ;
import { SIZES } from '../../../helpers/constants/design-system' ;
import { ButtonIcon } from '../button-icon' ;
import { Icon , ICON _NAMES } from '../icon' ;
import { TextFieldBase , TEXT _FIELD _BASE _TYPES } from '../text-field-base' ;
import { TextField } from '../text-field' ;
export const TextFieldSearch = ( {
value ,
onChange ,
clearButtonOnClick ,
clearButtonProps ,
className ,
... props
} ) => (
< TextField
className = { classnames ( 'mm-text-field-search' , className ) }
value = { value }
onChange = { onChange }
type = { TEXT _FIELD _BASE _TYPES . SEARCH }
leftAccessory = { < Icon name = { ICON _NAMES . SEARCH _FILLED } size = { SIZES . SM } / > }
2022-12-01 22:48:53 +01:00
showClearButton
2022-11-15 17:49:02 +01:00
clearButtonOnClick = { clearButtonOnClick }
clearButtonProps = { clearButtonProps }
{ ... props }
/ >
) ;
TextFieldSearch . propTypes = {
/ * *
* The value of the TextFieldSearch
* /
value : TextFieldBase . propTypes . value ,
/ * *
* The onChange handler of the TextFieldSearch
* /
onChange : TextFieldBase . propTypes . onChange ,
/ * *
* The onClick handler for the clear button
2022-12-01 22:48:53 +01:00
* Required unless showClearButton is false
*
* @ param { object } props - The props passed to the component .
* @ param { string } propName - The prop name in this case 'id' .
* @ param { string } componentName - The name of the component .
2022-11-15 17:49:02 +01:00
* /
2022-12-01 22:48:53 +01:00
clearButtonOnClick : ( props , propName , componentName ) => {
if (
props . showClearButton &&
( ! props [ propName ] || ! props . clearButtonProps ? . onClick )
) {
return new Error (
` ${ propName } is required unless showClearButton is false. Warning coming from ${ componentName } ui/components/component-library/text-field-search/text-field-search.js ` ,
) ;
}
return null ;
} ,
2022-11-15 17:49:02 +01:00
/ * *
* The props to pass to the clear button
* /
clearButtonProps : PropTypes . shape ( ButtonIcon . PropTypes ) ,
/ * *
* An additional className to apply to the TextFieldSearch
* /
className : PropTypes . string ,
} ;
TextFieldSearch . displayName = 'TextFieldSearch' ;