UNPKG

@elastic/eui

Version:

Elastic UI Component Library

201 lines (200 loc) 9.36 kB
var _excluded = ["title", "headingElement", "text", "size", "color", "actionProps", "media", "onDismiss", "dismissButtonProps", "children", "className", "announceOnMount", "data-test-subj"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } 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, { forwardRef } from 'react'; import PropTypes from "prop-types"; 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.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** Heading shown at the top. */title: PropTypes.string.isRequired, /** * HTML element used to render the title. * @default 'h2' */ headingElement: PropTypes.oneOf(["h2", "h3", "h4", "h5", "h6"]), /** Supporting copy rendered below the title. */text: PropTypes.node, /** Extra content rendered directly below `text`. */children: PropTypes.node, /** Illustration slot. Wrapped in a square (1:1) container. */media: PropTypes.node.isRequired, /** * Visual size variant. * @default 'm' */ size: PropTypes.any, /** * Defines the announcement background color. * @default 'highlighted' */ color: PropTypes.oneOf(["highlighted", "plain"]), /** Optional action buttons. */actionProps: PropTypes.shape({ /** Primary call-to-action, rendered as an `EuiButton`. */primary: PropTypes.any, /** Secondary action, rendered as an `EuiButtonEmpty`. Is only rendered when a primary action is available. */secondary: PropTypes.any }), /** * When provided, a dismiss button is rendered in the top-right corner and * this callback fires when the user activates it. */ onDismiss: PropTypes.func, /** Extra props spread onto the dismiss `EuiButtonIcon`. */dismissButtonProps: PropTypes.shape({ "aria-label": PropTypes.string, "aria-labelledby": PropTypes.string, /** * Overall size of button. * Matches the sizes of other EuiButtons */ size: PropTypes.any, /** * Size of the icon only. * This will not affect the overall size of the button */ iconSize: PropTypes.any, /** * Applies the boolean state as the `aria-pressed` property to create a toggle button. * *Only use when the readable text does not change between states.* */ isSelected: PropTypes.bool, /** * Sets the display style for matching other EuiButton types. * `base` is equivalent to a typical EuiButton * `fill` is equivalent to a filled EuiButton * `empty` (default) is equivalent to an EuiButtonEmpty */ display: PropTypes.any, /** * Disables the button and changes the icon to a loading spinner */ isLoading: PropTypes.bool, className: PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * Controls the disabled behavior via the native `disabled` attribute. */ isDisabled: PropTypes.bool, /** * NOTE: Beta feature, may be changed or removed in the future * * Changes the native `disabled` attribute to `aria-disabled` to preserve focusability. * This results in a semantically disabled button without the default browser handling of the disabled state. * * Use e.g. when a disabled button should have a tooltip. */ hasAriaDisabled: PropTypes.bool }), /** * When set to `true`, the content is announced by screen readers on mount. * Use only when the announcement is immediately relevant, e.g. as feedback to user actions. * Avoid using on initial page load as it may create noise for assistive technology users. * * @default false */ announceOnMount: PropTypes.bool }; EuiBanner.displayName = 'EuiBanner';