99 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-03-06 23:53:28 -05:00
import { Fragment } from 'react'
2020-02-20 19:57:29 -05:00
import classNames from 'classnames/bind'
import Icon from './icon'
2020-03-05 10:44:17 -05:00
import Text from './text'
2020-02-20 19:57:29 -05:00
const cx = classNames.bind(_s)
2020-02-19 18:57:07 -05:00
export default class Input extends PureComponent {
2020-02-20 19:57:29 -05:00
static propTypes = {
placeholder: PropTypes.string,
prependIcon: PropTypes.string,
value: PropTypes.string,
hasClear: PropTypes.bool,
onChange: PropTypes.func,
onKeyUp: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
onClear: PropTypes.func,
2020-03-05 10:44:17 -05:00
title: PropTypes.string,
2020-03-06 23:53:28 -05:00
small: PropTypes.bool,
2020-03-12 12:09:15 -04:00
readOnly: PropTypes.string,
2020-03-14 13:31:29 -04:00
inputRef: PropTypes.func,
2020-02-20 19:57:29 -05:00
}
2020-02-19 18:57:07 -05:00
render() {
2020-03-05 10:44:17 -05:00
const {
placeholder,
prependIcon,
value,
hasClear,
onChange,
onKeyUp,
onFocus,
onBlur,
onClear,
2020-03-06 23:53:28 -05:00
title,
2020-03-12 12:09:15 -04:00
small,
2020-03-14 13:31:29 -04:00
readOnly,
inputRef
2020-03-05 10:44:17 -05:00
} = this.props
2020-02-20 19:57:29 -05:00
const inputClasses = cx({
default: 1,
text: 1,
outlineNone: 1,
lineHeight125: 1,
displayBlock: 1,
2020-03-11 19:56:18 -04:00
py10: 1,
2020-03-12 12:09:15 -04:00
backgroundTransparent: !readOnly,
backgroundSubtle2: readOnly,
colorSecondary: readOnly,
2020-02-20 19:57:29 -05:00
fontSize15PX: 1,
flexGrow1: 1,
2020-03-12 12:09:15 -04:00
circle: 1,
2020-03-11 19:56:18 -04:00
px5: !!prependIcon,
pl15: !prependIcon,
pr15: !hasClear,
2020-02-20 19:57:29 -05:00
})
2020-02-19 18:57:07 -05:00
return (
2020-03-06 23:53:28 -05:00
<Fragment>
2020-02-20 19:57:29 -05:00
{
2020-03-05 10:44:17 -05:00
!!title &&
2020-03-11 19:56:18 -04:00
<div className={[_s.default, _s.mb10, _s.pl15].join(' ')}>
2020-03-05 10:44:17 -05:00
<Text size='small' weight='medium' color='secondary'>
{title}
</Text>
</div>
2020-02-20 19:57:29 -05:00
}
2020-03-05 10:44:17 -05:00
<div className={[_s.default, _s.backgroundColorPrimary, _s.border1PX, _s.borderColorSecondary, _s.flexRow, _s.circle, _s.alignItemsCenter].join(' ')}>
{
!!prependIcon &&
2020-03-11 19:56:18 -04:00
<Icon id={prependIcon} width='16px' height='16px' className={[_s.ml15, _s.mr5].join(' ')} />
2020-03-05 10:44:17 -05:00
}
2020-02-20 19:57:29 -05:00
2020-03-05 10:44:17 -05:00
<input
className={inputClasses}
type='text'
placeholder={placeholder}
2020-03-14 13:31:29 -04:00
ref={inputRef}
2020-03-05 10:44:17 -05:00
value={value}
onChange={onChange}
onKeyUp={onKeyUp}
onFocus={onFocus}
onBlur={onBlur}
2020-03-12 12:09:15 -04:00
readOnly={readOnly}
2020-03-05 10:44:17 -05:00
/>
2020-02-20 19:57:29 -05:00
2020-03-05 10:44:17 -05:00
{
hasClear &&
<div role='button' tabIndex='0' className={'btnClasses'} onClick={onClear}>
<Icon id='close' width='10px' height='10px' className={_s.fillColorWhite} aria-label='Clear' />
</div>
}
</div>
2020-03-06 23:53:28 -05:00
</Fragment>
2020-02-19 18:57:07 -05:00
)
}
}