Merge pull request #496 from matrix-org/dbkr/directory_search_box
Directory search join button
This commit is contained in:
commit
2e1644877d
2 changed files with 120 additions and 0 deletions
|
@ -59,6 +59,7 @@ module.exports.components['views.dialogs.TextInputDialog'] = require('./componen
|
||||||
module.exports.components['views.elements.AddressSelector'] = require('./components/views/elements/AddressSelector');
|
module.exports.components['views.elements.AddressSelector'] = require('./components/views/elements/AddressSelector');
|
||||||
module.exports.components['views.elements.AddressTile'] = require('./components/views/elements/AddressTile');
|
module.exports.components['views.elements.AddressTile'] = require('./components/views/elements/AddressTile');
|
||||||
module.exports.components['views.elements.DeviceVerifyButtons'] = require('./components/views/elements/DeviceVerifyButtons');
|
module.exports.components['views.elements.DeviceVerifyButtons'] = require('./components/views/elements/DeviceVerifyButtons');
|
||||||
|
module.exports.components['views.elements.DirectorySearchBox'] = require('./components/views/elements/DirectorySearchBox');
|
||||||
module.exports.components['views.elements.EditableText'] = require('./components/views/elements/EditableText');
|
module.exports.components['views.elements.EditableText'] = require('./components/views/elements/EditableText');
|
||||||
module.exports.components['views.elements.EditableTextContainer'] = require('./components/views/elements/EditableTextContainer');
|
module.exports.components['views.elements.EditableTextContainer'] = require('./components/views/elements/EditableTextContainer');
|
||||||
module.exports.components['views.elements.EmojiText'] = require('./components/views/elements/EmojiText');
|
module.exports.components['views.elements.EmojiText'] = require('./components/views/elements/EmojiText');
|
||||||
|
|
119
src/components/views/elements/DirectorySearchBox.js
Normal file
119
src/components/views/elements/DirectorySearchBox.js
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
Copyright 2016 OpenMarket Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
|
export default class DirectorySearchBox extends React.Component {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._collectInput = this._collectInput.bind(this);
|
||||||
|
this._onClearClick = this._onClearClick.bind(this);
|
||||||
|
this._onChange = this._onChange.bind(this);
|
||||||
|
this._onKeyUp = this._onKeyUp.bind(this);
|
||||||
|
this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
|
||||||
|
|
||||||
|
this.input = null;
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
value: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_collectInput(e) {
|
||||||
|
this.input = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
_onClearClick() {
|
||||||
|
this.setState({value: ''});
|
||||||
|
|
||||||
|
if (this.input) {
|
||||||
|
this.input.focus();
|
||||||
|
|
||||||
|
if (this.props.onClear) {
|
||||||
|
this.props.onClear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onChange(ev) {
|
||||||
|
if (!this.input) return;
|
||||||
|
this.setState({value: ev.target.value});
|
||||||
|
|
||||||
|
if (this.props.onChange) {
|
||||||
|
this.props.onChange(this.state.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onKeyUp(ev) {
|
||||||
|
if (ev.key == 'Enter') {
|
||||||
|
if (this.props.onJoinClick) {
|
||||||
|
this.props.onJoinClick(this.state.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onJoinButtonClick() {
|
||||||
|
if (this.props.onJoinClick) {
|
||||||
|
this.props.onJoinClick(this.state.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_contentLooksLikeAlias() {
|
||||||
|
if (!this.input) return false;
|
||||||
|
|
||||||
|
// liberal test for things that look like room aliases
|
||||||
|
return /^#.+:/.test(this.state.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const searchbox_classes = {
|
||||||
|
mx_DirectorySearchBox: true,
|
||||||
|
};
|
||||||
|
searchbox_classes[this.props.className] = true;
|
||||||
|
|
||||||
|
let join_button;
|
||||||
|
if (this._contentLooksLikeAlias()) {
|
||||||
|
join_button = <span className="mx_DirectorySearchBox_joinButton"
|
||||||
|
onClick={this._onJoinButtonClick}
|
||||||
|
>
|
||||||
|
Join
|
||||||
|
</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <span className={classnames(searchbox_classes)}>
|
||||||
|
<div className="mx_DirectorySearchBox_container">
|
||||||
|
<input type="text" value={this.state.value}
|
||||||
|
className="mx_DirectorySearchBox_input"
|
||||||
|
ref={this._collectInput}
|
||||||
|
onChange={this._onChange} onKeyUp={this._onKeyUp}
|
||||||
|
placeholder="Find a room by keyword or room ID (#matrix:matrix.org)"
|
||||||
|
/>
|
||||||
|
{join_button}
|
||||||
|
<span className="mx_DirectorySearchBox_clear_wrapper">
|
||||||
|
<span className="mx_DirectorySearchBox_clear" onClick={this._onClearClick} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</span>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectorySearchBox.propTypes = {
|
||||||
|
className: React.PropTypes.string,
|
||||||
|
onChange: React.PropTypes.func,
|
||||||
|
onClear: React.PropTypes.func,
|
||||||
|
onJoinClick: React.PropTypes.func,
|
||||||
|
};
|
Loading…
Reference in a new issue