UNPKG

@elastic/eui

Version:

Elastic UI Component Library

343 lines (336 loc) 22.9 kB
var _excluded = ["className", "pageTitle", "pageTitleProps", "iconType", "iconProps", "tabs", "tabsProps", "description", "breadcrumbs", "breadcrumbProps", "alignItems", "responsive", "rightSideItems", "rightSideGroupProps", "children", "restrictWidth", "paddingSize", "bottomBorder", "style"], _excluded2 = ["label"]; 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 _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 _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 from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { EuiIcon } from '../../icon'; import { EuiTab, EuiTabs } from '../../tabs'; import { EuiFlexGroup, EuiFlexItem } from '../../flex'; import { EuiSpacer } from '../../spacer'; import { EuiTitle } from '../../title'; import { EuiText } from '../../text'; import { useIsWithinBreakpoints, useEuiTheme } from '../../../services'; import { EuiScreenReaderOnly } from '../../accessibility'; import { EuiBreadcrumbs } from '../../breadcrumbs'; import { useEuiPaddingCSS } from '../../../global_styling'; import { setStyleForRestrictedPageWidth } from '../_restrict_width'; import { euiPageHeaderStyles } from './page_header.styles'; import { euiPageHeaderContentStyles } from './page_header_content.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var ALIGN_ITEMS = ['top', 'bottom', 'center', 'stretch']; // Gets all the tab props including the button or link props /** * The left side can either be a title with optional description and/or icon; * Or a list of tabs, * Or a custom node */ export var EuiPageHeaderContent = function EuiPageHeaderContent(_ref) { var className = _ref.className, pageTitle = _ref.pageTitle, pageTitleProps = _ref.pageTitleProps, iconType = _ref.iconType, iconProps = _ref.iconProps, tabs = _ref.tabs, tabsProps = _ref.tabsProps, description = _ref.description, breadcrumbs = _ref.breadcrumbs, breadcrumbProps = _ref.breadcrumbProps, alignItems = _ref.alignItems, _ref$responsive = _ref.responsive, responsive = _ref$responsive === void 0 ? true : _ref$responsive, rightSideItems = _ref.rightSideItems, rightSideGroupProps = _ref.rightSideGroupProps, children = _ref.children, restrictWidth = _ref.restrictWidth, _ref$paddingSize = _ref.paddingSize, _paddingSize = _ref$paddingSize === void 0 ? 'none' : _ref$paddingSize, _bottom_border = _ref.bottomBorder, style = _ref.style, rest = _objectWithoutProperties(_ref, _excluded); var isResponsiveBreakpoint = useIsWithinBreakpoints(['xs', 's'], !!responsive); var useTheme = useEuiTheme(); var classes = classNames('euiPageHeaderContent', className); var pageHeaderStyles = euiPageHeaderStyles(useTheme); var contentStyles = euiPageHeaderContentStyles(useTheme); var styles = setStyleForRestrictedPageWidth(restrictWidth, style); var paddingSides = 'vertical'; var paddingSize = _paddingSize; var bottomBorder = _bottom_border; var onlyChildren = !tabs && !pageTitle && !rightSideItems && !description && children; var onlyTabs = tabs && !pageTitle && !rightSideItems && !description && !children; var tabsAsTitle = tabs && !pageTitle; var tabsAtTheBottom = pageTitle && tabs; var borderWithoutPadding = (!paddingSize || paddingSize === 'none') && bottomBorder; if (onlyTabs) { paddingSize = 'none'; } else if (tabsAsTitle) { paddingSides = 'bottom'; } else if (tabsAtTheBottom) { paddingSides = 'top'; bottomBorder = bottomBorder === false ? false : true; } else if (borderWithoutPadding) { paddingSides = 'bottom'; paddingSize = 'l'; } var blockPadding = useEuiPaddingCSS(paddingSides); var cssStyles = [contentStyles.euiPageHeaderContent, bottomBorder && pageHeaderStyles.border, blockPadding[paddingSize]]; var childrenOnlyStyles = [contentStyles.flex, contentStyles[alignItems || 'center'], responsive === true && isResponsiveBreakpoint && contentStyles.responsive, responsive === 'reverse' && isResponsiveBreakpoint && contentStyles.responsiveReverse]; // Don't go any further if there's no other content than children if (onlyChildren) { return ___EmotionJSX("div", _extends({ css: cssStyles }, rest), ___EmotionJSX("div", { css: childrenOnlyStyles }, children)); } var descriptionNode; if (description) { descriptionNode = ___EmotionJSX(React.Fragment, null, (pageTitle || tabs) && ___EmotionJSX(EuiSpacer, null), ___EmotionJSX(EuiText, { grow: false }, ___EmotionJSX("p", null, description))); } var optionalBreadcrumbs = breadcrumbs ? ___EmotionJSX(React.Fragment, null, ___EmotionJSX(EuiBreadcrumbs, _extends({ breadcrumbs: breadcrumbs }, breadcrumbProps)), ___EmotionJSX(EuiSpacer, { size: "s" })) : undefined; var pageTitleNode; if (pageTitle) { var iconCssStyles = [contentStyles.euiPageHeaderContent__titleIcon, iconProps === null || iconProps === void 0 ? void 0 : iconProps.css]; var icon = iconType ? ___EmotionJSX(EuiIcon, _extends({ size: "xl" }, iconProps, { css: iconCssStyles, type: iconType })) : undefined; pageTitleNode = ___EmotionJSX(EuiTitle, _extends({}, pageTitleProps, { size: "l" }), ___EmotionJSX("h1", null, icon, pageTitle)); } var tabsNode; if (tabs) { var _tabs$find; var tabsSize = pageTitle ? 'l' : 'xl'; var renderTabs = function renderTabs() { return tabs.map(function (tab, index) { var label = tab.label, tabRest = _objectWithoutProperties(tab, _excluded2); return ___EmotionJSX(EuiTab, _extends({ key: index }, tabRest), label); }); }; // When tabs exist without a pageTitle, we need to recreate an h1 based on the currently selected tab and visually hide it var screenReaderPageTitle = !pageTitle && ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("h1", null, (_tabs$find = tabs.find(function (obj) { return obj.isSelected === true; })) === null || _tabs$find === void 0 ? void 0 : _tabs$find.label)); tabsNode = ___EmotionJSX(React.Fragment, null, pageTitleNode && ___EmotionJSX(EuiSpacer, null), screenReaderPageTitle, ___EmotionJSX(EuiTabs, _extends({}, tabsProps, { bottomBorder: false, size: tabsSize }), renderTabs())); } var childrenNode = children && ___EmotionJSX(React.Fragment, null, ___EmotionJSX(EuiSpacer, null), children); var bottomContentNode; if (childrenNode || tabsNode && pageTitleNode) { bottomContentNode = ___EmotionJSX("div", { className: "euiPageHeaderContent__bottom" }, childrenNode, pageTitleNode && tabsNode); } /** * The left side order depends on if a `pageTitle` was supplied. * If not, but there are `tabs`, then the tabs become the page title */ var leftSideOrder; if (tabsNode && !pageTitleNode) { leftSideOrder = ___EmotionJSX(React.Fragment, null, tabsNode, descriptionNode); } else { leftSideOrder = ___EmotionJSX(React.Fragment, null, pageTitleNode, descriptionNode); } var rightSideFlexItem; if (rightSideItems && rightSideItems.length) { var itemsToRender = isResponsiveBreakpoint ? rightSideItems : _toConsumableArray(rightSideItems).reverse(); var rightSideFlexItems = itemsToRender.map(function (item, index) { return ___EmotionJSX(EuiFlexItem, { grow: false, key: index }, item); }); rightSideFlexItem = ___EmotionJSX(EuiFlexItem, { grow: false }, ___EmotionJSX(EuiFlexGroup, _extends({ wrap: true, responsive: false }, rightSideGroupProps), rightSideFlexItems)); } return alignItems === 'top' || isResponsiveBreakpoint ? ___EmotionJSX("div", _extends({ className: classes, css: cssStyles, style: styles }, rest), optionalBreadcrumbs, ___EmotionJSX(EuiFlexGroup, { responsive: !!responsive, className: "euiPageHeaderContent__top", alignItems: pageTitle ? 'flexStart' : 'baseline', gutterSize: "l" }, isResponsiveBreakpoint && responsive === 'reverse' ? ___EmotionJSX(React.Fragment, null, rightSideFlexItem, ___EmotionJSX(EuiFlexItem, null, leftSideOrder)) : ___EmotionJSX(React.Fragment, null, ___EmotionJSX(EuiFlexItem, null, leftSideOrder), rightSideFlexItem)), bottomContentNode) : ___EmotionJSX("div", _extends({ className: classes, css: cssStyles, style: styles }, rest), optionalBreadcrumbs, ___EmotionJSX(EuiFlexGroup, { responsive: !!responsive, className: "euiPageHeaderContent__top", alignItems: alignItems === 'bottom' ? 'flexEnd' : alignItems, gutterSize: "l" }, ___EmotionJSX(EuiFlexItem, null, leftSideOrder, bottomContentNode), rightSideFlexItem)); }; EuiPageHeaderContent.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * The only option is on/off */ bottomBorder: PropTypes.bool, /** * Adjust the padding. * When using this setting it's best to be consistent throughout all similar usages */ paddingSize: PropTypes.any, /** * Set to false if you don't want the children to stack at small screen sizes. * Set to `reverse` to display the right side content first for the sake of hierarchy (like global time) */ responsive: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.oneOf(["reverse"])]), /** * Vertical alignment of the left and right side content; * Default is `center` for custom content, but `top` for when `pageTitle` or `tabs` are included */ alignItems: PropTypes.any, /** * Pass custom an array of content to this side usually up to 3 buttons. * The first button should be primary, usually with `fill` and will be visually displayed as the last item, * but first in the tab order */ rightSideItems: PropTypes.arrayOf(PropTypes.node.isRequired), /** * Additional EuiFlexGroup props to pass to the container of the `rightSideItems` */ rightSideGroupProps: PropTypes.any, /** * Custom children will be rendered before the `tabs` unless no `pageTitle` is present, then it will be the last item */ children: PropTypes.node, /** * Position is dependent on existing with a `pageTitle` or `tabs` * Automatically get wrapped in a single paragraph tag inside an EuiText block */ description: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.node.isRequired]), /** * Wrapped in an `H1` so choose appropriately. * A simple string is best */ pageTitle: PropTypes.node, /** * Additional props to pass to the EuiTitle */ pageTitleProps: PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, textTransform: PropTypes.any, id: PropTypes.string }), /** * Optional icon to place to the left of the title */ iconType: PropTypes.oneOfType([PropTypes.oneOf(["accessibility", "addDataApp", "advancedSettingsApp", "agentApp", "aggregate", "analyzeEvent", "annotation", "apmApp", "apmTrace", "appSearchApp", "apps", "arrowDown", "arrowLeft", "arrowRight", "arrowUp", "arrowStart", "arrowEnd", "article", "asterisk", "at", "auditbeatApp", "beaker", "bell", "bellSlash", "beta", "bolt", "boxesHorizontal", "boxesVertical", "branch", "branchUser", "broom", "brush", "bug", "bullseye", "calendar", "canvasApp", "casesApp", "check", "checkInCircleFilled", "cheer", "classificationJob", "clock", "cloudDrizzle", "cloudStormy", "cloudSunny", "cluster", "codeApp", "color", "compute", "console", "consoleApp", "container", "continuityAbove", "continuityAboveBelow", "continuityBelow", "continuityWithin", "controlsHorizontal", "controlsVertical", "copy", "copyClipboard", "createAdvancedJob", "createMultiMetricJob", "createPopulationJob", "createSingleMetricJob", "cross", "crossClusterReplicationApp", "crosshairs", "currency", "cut", "dashboardApp", "dataVisualizer", "database", "desktop", "devToolsApp", "discoverApp", "discuss", "document", "documentEdit", "documentation", "documents", "dot", "dotInCircle", "doubleArrowLeft", "doubleArrowRight", "download", "editorAlignCenter", "editorAlignLeft", "editorAlignRight", "editorBold", "editorChecklist", "editorCodeBlock", "editorComment", "editorDistributeHorizontal", "editorDistributeVertical", "editorHeading", "editorItalic", "editorItemAlignBottom", "editorItemAlignCenter", "editorItemAlignLeft", "editorItemAlignMiddle", "editorItemAlignRight", "editorItemAlignTop", "editorLink", "editorOrderedList", "editorPositionBottomLeft", "editorPositionBottomRight", "editorPositionTopLeft", "editorPositionTopRight", "editorRedo", "editorStrike", "editorTable", "editorUnderline", "editorUndo", "editorUnorderedList", "email", "empty", "emsApp", "eql", "eraser", "error", "exit", "expand", "expandMini", "exportAction", "eye", "eyeClosed", "faceHappy", "faceNeutral", "faceSad", "filebeatApp", "filter", "filterExclude", "filterIgnore", "filterInclude", "filterInCircle", "flag", "fleetApp", "fold", "folderCheck", "folderClosed", "folderExclamation", "folderOpen", "frameNext", "framePrevious", "fullScreen", "fullScreenExit", "function", "gear", "gisApp", "glasses", "globe", "grab", "grabHorizontal", "graphApp", "grid", "grokApp", "heart", "heartbeatApp", "heatmap", "help", "home", "iInCircle", "image", "importAction", "indexClose", "indexEdit", "indexFlush", "indexManagementApp", "indexMapping", "indexOpen", "indexPatternApp", "indexRollupApp", "indexRuntime", "indexSettings", "indexTemporary", "infinity", "inputOutput", "inspect", "invert", "ip", "key", "keyboard", "kqlField", "kqlFunction", "kqlOperand", "kqlSelector", "kqlValue", "kubernetesNode", "kubernetesPod", "launch", "layers", "lensApp", "lettering", "lineDashed", "lineDotted", "lineSolid", "link", "list", "listAdd", "lock", "lockOpen", "logoAWS", "logoAWSMono", "logoAerospike", "logoApache", "logoAppSearch", "logoAzure", "logoAzureMono", "logoBeats", "logoBusinessAnalytics", "logoCeph", "logoCloud", "logoCloudEnterprise", "logoCode", "logoCodesandbox", "logoCouchbase", "logoDocker", "logoDropwizard", "logoElastic", "logoElasticStack", "logoElasticsearch", "logoEnterpriseSearch", "logoEtcd", "logoGCP", "logoGCPMono", "logoGithub", "logoGmail", "logoGolang", "logoGoogleG", "logoHAproxy", "logoIBM", "logoIBMMono", "logoKafka", "logoKibana", "logoKubernetes", "logoLogging", "logoLogstash", "logoMaps", "logoMemcached", "logoMetrics", "logoMongodb", "logoMySQL", "logoNginx", "logoObservability", "logoOsquery", "logoPhp", "logoPostgres", "logoPrometheus", "logoRabbitmq", "logoRedis", "logoSecurity", "logoSiteSearch", "logoSketch", "logoSlack", "logoUptime", "logoVulnerabilityManagement", "logoWebhook", "logoWindows", "logoWorkplaceSearch", "logsApp", "logstashFilter", "logstashIf", "logstashInput", "logstashOutput", "logstashQueue", "machineLearningApp", "magnet", "magnifyWithExclamation", "magnifyWithMinus", "magnifyWithPlus", "managementApp", "mapMarker", "memory", "menu", "menuDown", "menuLeft", "menuRight", "menuUp", "merge", "metricbeatApp", "metricsApp", "minimize", "minus", "minusInCircle", "minusInCircleFilled", "mobile", "monitoringApp", "moon", "namespace", "nested", "node", "notebookApp", "number", "offline", "online", "outlierDetectionJob", "package", "packetbeatApp", "pageSelect", "pagesSelect", "paperClip", "partial", "pause", "payment", "pencil", "percent", "pin", "pinFilled", "pipelineApp", "pivot", "play", "playFilled", "plus", "plusInCircle", "plusInCircleFilled", "popout", "push", "questionInCircle", "quote", "recentlyViewedApp", "refresh", "regressionJob", "reporter", "reportingApp", "returnKey", "save", "savedObjectsApp", "scale", "search", "searchProfilerApp", "securityAnalyticsApp", "securityApp", "securitySignal", "securitySignalDetected", "securitySignalResolved", "sessionViewer", "shard", "share", "snowflake", "sortAscending", "sortDescending", "sortDown", "sortLeft", "sortRight", "sortUp", "sortable", "spaces", "spacesApp", "sparkles", "sqlApp", "starEmpty", "starEmptySpace", "starFilled", "starFilledSpace", "starMinusEmpty", "starMinusFilled", "starPlusEmpty", "starPlusFilled", "stats", "stop", "stopFilled", "stopSlash", "storage", "string", "submodule", "sun", "swatchInput", "symlink", "tableDensityCompact", "tableDensityExpanded", "tableDensityNormal", "tableOfContents", "tag", "tear", "temperature", "timeline", "timelineWithArrow", "timelionApp", "timeRefresh", "timeslider", "training", "trash", "unfold", "unlink", "upgradeAssistantApp", "uptimeApp", "user", "userAvatar", "users", "usersRolesApp", "vector", "videoPlayer", "visArea", "visAreaStacked", "visBarHorizontal", "visBarHorizontalStacked", "visBarVertical", "visBarVerticalStacked", "visGauge", "visGoal", "visLine", "visMapCoordinate", "visMapRegion", "visMetric", "visPie", "visTable", "visTagCloud", "visText", "visTimelion", "visVega", "visVisualBuilder", "visualizeApp", "vulnerabilityManagementApp", "warning", "alert", "watchesApp", "wordWrap", "wordWrapDisabled", "workplaceSearchApp", "wrench", "tokenAlias", "tokenAnnotation", "tokenArray", "tokenBinary", "tokenBoolean", "tokenClass", "tokenCompletionSuggester", "tokenConstant", "tokenDate", "tokenDenseVector", "tokenElement", "tokenEnum", "tokenEnumMember", "tokenEvent", "tokenException", "tokenField", "tokenFile", "tokenFlattened", "tokenFunction", "tokenGeo", "tokenHistogram", "tokenInterface", "tokenIP", "tokenJoin", "tokenKey", "tokenKeyword", "tokenMethod", "tokenMetricCounter", "tokenMetricGauge", "tokenModule", "tokenNamespace", "tokenNested", "tokenNull", "tokenNumber", "tokenObject", "tokenOperator", "tokenPackage", "tokenParameter", "tokenPercolator", "tokenProperty", "tokenRange", "tokenRankFeature", "tokenRankFeatures", "tokenRepo", "tokenSearchType", "tokenShape", "tokenString", "tokenStruct", "tokenSymbol", "tokenTag", "tokenText", "tokenTokenCount", "tokenVariable"]).isRequired, PropTypes.string.isRequired, PropTypes.elementType.isRequired]), /** * Additional EuiIcon props to apply to the optional icon */ iconProps: PropTypes.any, /** * Optional array breadcrumbs that render before the `pageTitle` */ breadcrumbs: PropTypes.arrayOf(PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, href: PropTypes.string, rel: PropTypes.string, onClick: PropTypes.func, /** * Visible label of the breadcrumb */ text: PropTypes.node.isRequired, /** * Force a max-width on the breadcrumb text */ truncate: PropTypes.bool, /** * Accepts any EuiLink `color` when rendered as one (has `href` or `onClick`) */ color: PropTypes.any, /** * Override the existing `aria-current` which defaults to `page` for the last breadcrumb */ "aria-current": PropTypes.any }).isRequired), /** * Adjust the props of [EuiBreadcrumbs](#/navigation/breadcrumbs) */ breadcrumbProps: PropTypes.any, /** * In-app navigation presented as large borderless tabs. * Accepts an array of `EuiTab` objects; */ tabs: PropTypes.arrayOf(PropTypes.shape({ /** * Visible text of the tab */ label: PropTypes.node.isRequired }).isRequired), /** * Any extras to apply to the outer tabs container. * Extends `EuiTabs` */ tabsProps: PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * ReactNode to render as this component's content */ children: PropTypes.node, /** * Adds a bottom border to separate it from the content after */ bottomBorder: PropTypes.bool }), /** * Sets the max-width of the page, * set to `true` to use the default size of `1200px`, * set to `false` to not restrict the width, * set to a number for a custom width in px, * set to a string for a custom width in custom measurement. */ restrictWidth: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.number.isRequired, PropTypes.string.isRequired]) };