From 61b48a5b1a4508f0a030850ed8d0a86ec569bef3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 23 Sep 2016 13:48:24 +0100 Subject: [PATCH] Add component for the directory search box --- .../views/elements/DirectorySearchBox.js | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/components/views/elements/DirectorySearchBox.js diff --git a/src/components/views/elements/DirectorySearchBox.js b/src/components/views/elements/DirectorySearchBox.js new file mode 100644 index 0000000000..277c90f129 --- /dev/null +++ b/src/components/views/elements/DirectorySearchBox.js @@ -0,0 +1,85 @@ +/* +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.input = null; + } + + collectInput(e) { + this.input = e; + } + + onClearClick() { + if (this.input) { + this.input.value = ''; + this.input.focus(); + + if (this.props.onClear) { + this.props.onClear(); + } + } + } + + onChange() { + if (!this.input) return; + + if (this.props.onChange) { + this.props.onChange(this.input.value); + } + } + + onKeyUp(ev) { + if (ev.key == 'Enter') { + if (this.props.onJoinClick) { + this.props.onJoinClick(this.input.value); + } + } + } + + render() { + const searchbox_classes = { + mx_DirectorySearchBox: true, + }; + searchbox_classes[this.props.className] = true; + + return + + + ; + } +} + +DirectorySearchBox.propTypes = { + className: React.PropTypes.string, + onChange: React.PropTypes.func, + onClear: React.PropTypes.func, + onJoinClick: React.PropTypes.func, +};