react-cimpress-comment
Version:
Visualizes comment(s) for a particular platform resource
124 lines (101 loc) • 5.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
require('../../style/index.css');
require('../../style/visibilityOption.css');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
var CommentVisibilityOption = function (_React$Component) {
_inherits(CommentVisibilityOption, _React$Component);
function CommentVisibilityOption() {
_classCallCheck(this, CommentVisibilityOption);
return _possibleConstructorReturn(this, (CommentVisibilityOption.__proto__ || Object.getPrototypeOf(CommentVisibilityOption)).apply(this, arguments));
}
_createClass(CommentVisibilityOption, [{
key: 'tt',
value: function tt(key) {
var _props = this.props,
t = _props.t,
locale = _props.locale;
if (locale.length > 2) {
locale = locale.substr(0, 2);
}
return t(key, { lng: locale });
}
}, {
key: 'handleMouseDown',
value: function handleMouseDown(event) {
event.preventDefault();
event.stopPropagation();
if (!this.props.option.disabled) {
this.props.onSelect(this.props.option, event);
}
}
}, {
key: 'handleMouseEnter',
value: function handleMouseEnter(event) {
this.props.onFocus(this.props.option, event);
}
}, {
key: 'handleMouseMove',
value: function handleMouseMove(event) {
if (this.props.isFocused) return;
this.props.onFocus(this.props.option, event);
}
}, {
key: 'render',
value: function render() {
var icon = _react2.default.createElement('div', { className: 'visibility-option-icon fa fa-' + this.props.option.icon });
return _react2.default.createElement(
'div',
{ className: this.props.className,
onMouseDown: this.handleMouseDown.bind(this),
onMouseEnter: this.handleMouseEnter.bind(this),
onMouseMove: this.handleMouseMove.bind(this),
title: this.props.option.title },
_react2.default.createElement(
'div',
null,
icon,
_react2.default.createElement(
'span',
null,
this.props.option.label
)
),
_react2.default.createElement(
'div',
null,
_react2.default.createElement(
'small',
null,
this.props.option.description
)
)
);
}
}]);
return CommentVisibilityOption;
}(_react2.default.Component);
CommentVisibilityOption.propTypes = {
// Silence eslint
t: _propTypes2.default.func,
locale: _propTypes2.default.string,
children: _propTypes2.default.node,
className: _propTypes2.default.string,
isDisabled: _propTypes2.default.bool,
isFocused: _propTypes2.default.bool,
isSelected: _propTypes2.default.bool,
onFocus: _propTypes2.default.func,
onSelect: _propTypes2.default.func,
option: _propTypes2.default.object.isRequired
};
exports.default = CommentVisibilityOption;