@elastic/eui
Version:
Elastic UI Component Library
92 lines (91 loc) • 6.08 kB
JavaScript
var _excluded = ["lineNumber", "children"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
/*
* 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, { useState } from 'react';
import PropTypes from "prop-types";
import { useEuiTheme } from '../../services';
import { useEuiI18n } from '../i18n';
import { EuiPopover } from '../popover';
import { EuiIcon } from '../icon';
import { useEuiButtonFocusCSS } from '../../themes/amsterdam/global_styling/mixins/button';
import { euiCodeBlockAnnotationsStyles } from './code_block_annotations.style';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
var lineNumber = _ref.lineNumber,
children = _ref.children,
rest = _objectWithoutProperties(_ref, _excluded);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isOpen = _useState2[0],
setIsOpen = _useState2[1];
var ariaLabel = useEuiI18n('euiCodeBlockAnnotations.ariaLabel', 'Click to view a code annotation for line {lineNumber}', {
lineNumber: lineNumber
});
var _useEuiTheme = useEuiTheme(),
euiTheme = _useEuiTheme.euiTheme,
colorMode = _useEuiTheme.colorMode;
var styles = euiCodeBlockAnnotationsStyles(euiTheme);
var buttonIconFocusStyle = useEuiButtonFocusCSS();
var cssButtonIconStyles = [styles.euiCodeBlockAnnotation__buttonIcon, buttonIconFocusStyle];
var isDarkMode = colorMode === 'DARK';
return ___EmotionJSX(EuiPopover, _extends({
css: styles.euiCodeBlockAnnotation
}, rest, {
isOpen: isOpen,
closePopover: function closePopover() {
return setIsOpen(false);
},
button: ___EmotionJSX("button", {
onClick: function onClick() {
return setIsOpen(!isOpen);
},
"aria-label": ariaLabel,
css: cssButtonIconStyles,
"data-test-subj": "euiCodeBlockAnnotationIcon"
}, ___EmotionJSX(EuiIcon, {
type: AnnotationInfoIcon,
size: "s",
color: isDarkMode ? euiTheme.colors.ink : 'ghost'
})),
zIndex: Number(euiTheme.levels.mask) + 1 // Ensure fullscreen annotation popovers sit above the mask
,
anchorPosition: "downLeft",
panelProps: {
'data-test-subj': 'euiCodeBlockAnnotationPopover'
}
}), children);
};
EuiCodeBlockAnnotation.propTypes = {
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
lineNumber: PropTypes.number.isRequired
};
var AnnotationInfoIcon = function AnnotationInfoIcon(props) {
return ___EmotionJSX("svg", _extends({
width: 11,
height: 11,
viewBox: "0 0 16 16",
fill: "none",
xmlns: "http://www.w3.org/2000/svg"
}, props), ___EmotionJSX("path", {
fillRule: "evenodd",
clipRule: "evenodd",
d: "M7.139 14l-.052-6.007H5V6.28h4.111l.052 6.007h1.915V14h-3.94zM6.712 3.38c0-.396.118-.725.354-.987S7.639 2 8.077 2c.438 0 .777.131 1.016.393.24.262.359.591.359.987 0 .39-.12.714-.359.972s-.578.388-1.016.388c-.438 0-.775-.13-1.011-.388-.236-.258-.354-.582-.354-.972z"
}));
};