@elastic/eui
Version:
Elastic UI Component Library
70 lines (69 loc) • 3.16 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["children", "textToCopy", "beforeMessage", "afterMessage"];
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { Component } from 'react';
import { copyToClipboard } from '../../services';
import { EuiToolTip } from '../tool_tip';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var EuiCopy = /*#__PURE__*/function (_Component) {
function EuiCopy(props) {
var _this;
_classCallCheck(this, EuiCopy);
_this = _callSuper(this, EuiCopy, [props]);
_defineProperty(_this, "copy", function () {
var isCopied = copyToClipboard(_this.props.textToCopy);
if (isCopied) {
_this.setState({
tooltipText: _this.props.afterMessage
});
}
});
_defineProperty(_this, "resetTooltipText", function () {
_this.setState({
tooltipText: _this.props.beforeMessage
});
});
_this.state = {
tooltipText: _this.props.beforeMessage
};
return _this;
}
_inherits(EuiCopy, _Component);
return _createClass(EuiCopy, [{
key: "render",
value: function render() {
var _this$props = this.props,
children = _this$props.children,
textToCopy = _this$props.textToCopy,
beforeMessage = _this$props.beforeMessage,
afterMessage = _this$props.afterMessage,
rest = _objectWithoutProperties(_this$props, _excluded);
return (
// See `src/components/tool_tip/tool_tip.js` for explanation of below eslint-disable
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
___EmotionJSX(EuiToolTip, _extends({
content: this.state.tooltipText,
onMouseOut: this.resetTooltipText
}, rest), children(this.copy))
);
}
}]);
}(Component);
_defineProperty(EuiCopy, "defaultProps", {
afterMessage: 'Copied'
});