UNPKG

@elastic/eui

Version:

Elastic UI Component Library

94 lines (93 loc) 5.46 kB
var _excluded = ["children", "className", "isOpen", "isAttached", "hasDragDrop", "position"]; 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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } 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 _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, { createContext } from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { useEuiTheme } from '../../../services'; import { EuiPanel } from '../../panel/panel'; import { euiPopoverPanelStyles } from './_popover_panel.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; var DEFAULT_PANEL_PADDING_SIZE = 'l'; export var EuiPopoverPanelContext = /*#__PURE__*/createContext({ paddingSize: DEFAULT_PANEL_PADDING_SIZE }); /** * *INTERNAL ONLY* * Purely for re-use of styling */ export var EuiPopoverPanel = function EuiPopoverPanel(_ref) { var children = _ref.children, className = _ref.className, isOpen = _ref.isOpen, isAttached = _ref.isAttached, hasDragDrop = _ref.hasDragDrop, position = _ref.position, rest = _objectWithoutProperties(_ref, _excluded); var _rest$paddingSize = rest.paddingSize, paddingSize = _rest$paddingSize === void 0 ? DEFAULT_PANEL_PADDING_SIZE : _rest$paddingSize; var euiThemeContext = useEuiTheme(); // Using BEM child class for BWC var classes = classNames('euiPopover__panel', className); var styles = euiPopoverPanelStyles(euiThemeContext); var panelCSS = [styles.euiPopover__panel, isOpen && styles.isOpen, isOpen && position && styles[position]]; if (isAttached) { panelCSS = [].concat(_toConsumableArray(panelCSS), [isOpen && styles.attached.isOpen, position && styles.attached[position]]); } if (hasDragDrop) { panelCSS = [].concat(_toConsumableArray(panelCSS), [styles.hasDragDrop.hasDragDrop, position && styles.hasDragDrop[position]]); } return ___EmotionJSX(EuiPopoverPanelContext.Provider, { value: { paddingSize: paddingSize } }, ___EmotionJSX(EuiPanel, _extends({ className: classes, css: panelCSS, "data-popover-panel": true, "data-popover-open": isOpen || undefined }, rest), children)); }; EuiPopoverPanel.propTypes = { element: PropTypes.oneOf(["div"]), /** * Padding for all four sides */ paddingSize: PropTypes.any, /** * Corner border radius */ borderRadius: PropTypes.any, /** * When true the panel will grow in height to match `EuiFlexItem` */ grow: PropTypes.bool, panelRef: PropTypes.any, /** * Background color of the panel; * Usually a lightened form of the brand colors */ color: PropTypes.any, className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, isOpen: PropTypes.bool, isAttached: PropTypes.bool, position: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.oneOf([null])]), hasDragDrop: PropTypes.bool };