]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/compose/components/search.js
1 import React
from 'react';
2 import PropTypes
from 'prop-types';
3 import { defineMessages
, injectIntl
, FormattedMessage
} from 'react-intl';
5 const messages
= defineMessages({
6 placeholder: { id: 'search.placeholder', defaultMessage: 'Search' }
9 class Search
extends React
.PureComponent
{
12 value: PropTypes
.string
.isRequired
,
13 submitted: PropTypes
.bool
,
14 onChange: PropTypes
.func
.isRequired
,
15 onSubmit: PropTypes
.func
.isRequired
,
16 onClear: PropTypes
.func
.isRequired
,
17 onShow: PropTypes
.func
.isRequired
,
18 intl: PropTypes
.object
.isRequired
21 handleChange
= (e
) => {
22 this.props
.onChange(e
.target
.value
);
25 handleClear
= (e
) => {
28 if (this.props
.value
.length
> 0 || this.props
.submitted
) {
33 handleKeyDown
= (e
) => {
34 if (e
.key
=== 'Enter') {
36 this.props
.onSubmit();
49 const { intl
, value
, submitted
} = this.props
;
50 const hasValue
= value
.length
> 0 || submitted
;
53 <div className
='search'>
55 className
='search__input'
57 placeholder
={intl
.formatMessage(messages
.placeholder
)}
59 onChange
={this.handleChange
}
60 onKeyUp
={this.handleKeyDown
}
61 onFocus
={this.handleFocus
}
64 <div role
='button' tabIndex
='0' className
='search__icon' onClick
={this.handleClear
}>
65 <i className
={`fa fa-search ${hasValue ? '' : 'active'}`} />
66 <i aria
-label
={intl
.formatMessage(messages
.placeholder
)} className
={`fa fa-times-circle ${hasValue ? 'active' : ''}`} />
74 export default injectIntl(Search
);
This page took 0.087396 seconds and 4 git commands to generate.