UNPKG

@bigfishtv/cockpit

Version:

61 lines (47 loc) 2.63 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _class; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } import React, { Component } from 'react'; import { withFormValue } from '@bigfishtv/react-forms'; import Cell from '../cell/Cell'; import Icon from '../Icon'; import Button from '../button/Button'; var UrlCellInput = withFormValue(_class = function (_Component) { _inherits(UrlCellInput, _Component); function UrlCellInput(props) { _classCallCheck(this, UrlCellInput); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); _this.state = { editing: false }; return _this; } UrlCellInput.prototype.render = function render() { var _this2 = this; return this.state.editing ? React.createElement('input', _extends({ ref: function ref(i) { return _this2.input = i; }, type: 'text' }, this.props, { onBlur: function onBlur() { return _this2.setState({ editing: false }); } })) : React.createElement(Cell, { Icon: React.createElement(Icon, { name: 'link', size: '18' }), title: React.createElement( 'a', { href: this.props.value, target: '_blank' }, this.props.value ), CellControl: function CellControl() { return React.createElement( Button, { style: 'icon', onClick: function onClick() { return _this2.setState({ editing: true }, function () { return _this2.input.focus(); }); } }, React.createElement(Icon, { name: 'edit', size: '18' }) ); } }); }; return UrlCellInput; }(Component)) || _class; export { UrlCellInput as default };