UNPKG

@elastic/eui

Version:

Elastic UI Component Library

111 lines (110 loc) 5.29 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["title", "headingElement", "text", "size", "color", "actionProps", "media", "onDismiss", "dismissButtonProps", "children", "className", "announceOnMount", "data-test-subj"]; /* * 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, { forwardRef } from 'react'; import classNames from 'classnames'; import { useEuiMemoizedStyles } from '../../services'; import { useEuiBackgroundColorCSS } from '../../global_styling'; import { useEuiI18n } from '../i18n'; import { EuiTitle } from '../title'; import { EuiButton, EuiButtonEmpty, EuiButtonIcon } from '../button'; import { EuiText } from '../text'; import { EuiLiveAnnouncer } from '../accessibility'; import { euiBannerStyles } from './banner.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiBanner = /*#__PURE__*/forwardRef(function (_ref, ref) { var title = _ref.title, _ref$headingElement = _ref.headingElement, headingElement = _ref$headingElement === void 0 ? 'h2' : _ref$headingElement, text = _ref.text, _ref$size = _ref.size, size = _ref$size === void 0 ? 'm' : _ref$size, _ref$color = _ref.color, color = _ref$color === void 0 ? 'highlighted' : _ref$color, actionProps = _ref.actionProps, media = _ref.media, onDismiss = _ref.onDismiss, dismissButtonProps = _ref.dismissButtonProps, children = _ref.children, className = _ref.className, _ref$announceOnMount = _ref.announceOnMount, announceOnMount = _ref$announceOnMount === void 0 ? false : _ref$announceOnMount, _ref$dataTestSubj = _ref['data-test-subj'], dataTestSubj = _ref$dataTestSubj === void 0 ? 'euiBanner' : _ref$dataTestSubj, rest = _objectWithoutProperties(_ref, _excluded); var styles = useEuiMemoizedStyles(euiBannerStyles); var dismissAriaLabel = useEuiI18n('euiBanner.dismissAriaLabel', 'Dismiss "{title}" announcement', { title: title }); var Heading = headingElement; var headingSize = size === 's' ? 'xxs' : 'xs'; var primaryActionProps = actionProps === null || actionProps === void 0 ? void 0 : actionProps.primary; var secondaryActionProps = actionProps === null || actionProps === void 0 ? void 0 : actionProps.secondary; var hasActions = Boolean(primaryActionProps) || Boolean(secondaryActionProps); var componentClass = 'euiBanner'; var classes = classNames(componentClass, className); var backgroundColorStyles = useEuiBackgroundColorCSS()[color]; var cssStyles = [styles.euiBanner, backgroundColorStyles]; var containerCssStyles = [styles.container, onDismiss && styles.hasDismiss]; return ___EmotionJSX("div", _extends({ ref: ref, className: classes, css: cssStyles, "data-size": size, "data-color": color, "data-test-subj": dataTestSubj }, rest), ___EmotionJSX("div", { className: "".concat(componentClass, "__container"), css: containerCssStyles }, media ? ___EmotionJSX("div", { className: "".concat(componentClass, "__media"), css: styles.media, "data-test-subj": "".concat(dataTestSubj, "-media") }, media) : null, ___EmotionJSX("div", { className: "".concat(componentClass, "__body"), css: styles.body }, ___EmotionJSX("div", { className: "".concat(componentClass, "__content"), css: styles.content }, ___EmotionJSX(EuiTitle, { size: headingSize }, ___EmotionJSX(Heading, { css: styles.title, "data-test-subj": "".concat(dataTestSubj, "-title") }, title)), onDismiss ? ___EmotionJSX(EuiButtonIcon, _extends({ iconType: "cross", color: "text", "aria-label": dismissAriaLabel, "data-test-subj": "".concat(dataTestSubj, "-dismiss") }, dismissButtonProps, { css: [styles.dismiss, dismissButtonProps === null || dismissButtonProps === void 0 ? void 0 : dismissButtonProps.css, ";label:EuiBanner;"], onClick: onDismiss })) : null, text ? ___EmotionJSX(EuiText, { css: styles.text, size: "s", color: "subdued", "data-test-subj": "".concat(dataTestSubj, "-text") }, text) : null, children && children), hasActions ? ___EmotionJSX("div", { className: "".concat(componentClass, "__actions"), css: styles.actions, "data-test-subj": "".concat(dataTestSubj, "-actions") }, primaryActionProps ? ___EmotionJSX(EuiButton, _extends({ "data-test-subj": "".concat(dataTestSubj, "-primaryAction") }, primaryActionProps, { color: "primary", size: "s" })) : null, secondaryActionProps ? ___EmotionJSX(EuiButtonEmpty, _extends({ "data-test-subj": "".concat(dataTestSubj, "-secondaryAction") }, secondaryActionProps, { color: "primary", size: "s" })) : null) : null)), announceOnMount && ___EmotionJSX(EuiLiveAnnouncer, null, title && title, title && text && ",\xA0", text && text, (title || text) && children && ",\xA0", children && children)); }); EuiBanner.displayName = 'EuiBanner';