@elastic/eui
Version:
Elastic UI Component Library
58 lines (57 loc) • 2.52 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "isOpen", "isAttached", "hasDragDrop", "position"];
/*
* 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 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));
};