UNPKG

@elastic/eui

Version:

Elastic UI Component Library

249 lines (248 loc) 19.2 kB
var _excluded = ["children", "className", "notification", "notificationColor"]; 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, useImperativeHandle, useMemo, useRef } from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { useEuiMemoizedStyles, useIsWithinMaxBreakpoint } from '../../../services'; import { EuiNotificationBadge } from '../../badge/notification_badge/badge_notification'; import { EuiIcon } from '../../icon'; import { EuiButtonEmpty } from '../../button'; import { euiHeaderSectionItemButtonStyles } from './header_section_item_button.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiHeaderSectionItemButton = /*#__PURE__*/forwardRef(function (_ref, /** * Allows for animating with .euiAnimate() */ ref) { var children = _ref.children, className = _ref.className, notification = _ref.notification, _ref$notificationColo = _ref.notificationColor, notificationColor = _ref$notificationColo === void 0 ? 'accent' : _ref$notificationColo, rest = _objectWithoutProperties(_ref, _excluded); var buttonRef = useRef(null); var animationTargetRef = useRef(null); useImperativeHandle(ref, function () { buttonRef.current.euiAnimate = function () { var _animationTargetRef$c; var keyframes = [{ transform: 'rotate(0)', offset: 0, easing: 'ease-in-out' }, { transform: 'rotate(30deg)', offset: 0.01, easing: 'ease-in-out' }, { transform: 'rotate(-28deg)', offset: 0.03, easing: 'ease-in-out' }, { transform: 'rotate(34deg)', offset: 0.05, easing: 'ease-in-out' }, { transform: 'rotate(-32deg)', offset: 0.07, easing: 'ease-in-out' }, { transform: 'rotate(30deg)', offset: 0.09, easing: 'ease-in-out' }, { transform: 'rotate(-28deg)', offset: 0.11, easing: 'ease-in-out' }, { transform: 'rotate(26deg)', offset: 0.13, easing: 'ease-in-out' }, { transform: 'rotate(-24deg)', offset: 0.15, easing: 'ease-in-out' }, { transform: 'rotate(22deg)', offset: 0.17, easing: 'ease-in-out' }, { transform: 'rotate(-20deg)', offset: 0.19, easing: 'ease-in-out' }, { transform: 'rotate(18deg)', offset: 0.21, easing: 'ease-in-out' }, { transform: 'rotate(-16deg)', offset: 0.23, easing: 'ease-in-out' }, { transform: 'rotate(14deg)', offset: 0.25, easing: 'ease-in-out' }, { transform: 'rotate(-12deg)', offset: 0.27, easing: 'ease-in-out' }, { transform: 'rotate(10deg)', offset: 0.29, easing: 'ease-in-out' }, { transform: 'rotate(-8deg)', offset: 0.31, easing: 'ease-in-out' }, { transform: 'rotate(6deg)', offset: 0.33, easing: 'ease-in-out' }, { transform: 'rotate(-4deg)', offset: 0.35, easing: 'ease-in-out' }, { transform: 'rotate(2deg)', offset: 0.37, easing: 'ease-in-out' }, { transform: 'rotate(-1deg)', offset: 0.39, easing: 'ease-in-out' }, { transform: 'rotate(1deg)', offset: 0.41, easing: 'ease-in-out' }, { transform: 'rotate(0)', offset: 0.43, easing: 'ease-in-out' }, { transform: 'rotate(0)', offset: 1, easing: 'ease-in-out' }]; (_animationTargetRef$c = animationTargetRef.current) === null || _animationTargetRef$c === void 0 || _animationTargetRef$c.animate(keyframes, { duration: 5000 }); }; return buttonRef.current; }, []); var styles = useEuiMemoizedStyles(euiHeaderSectionItemButtonStyles); var classes = classNames('euiHeaderSectionItemButton', className); var isSmallScreen = useIsWithinMaxBreakpoint('s'); var shouldShowDot = notification === true || !!(notification && isSmallScreen); var buttonNotification = useMemo(function () { var cssStyles = [styles.notification.euiHeaderSectionItemButton__notification, shouldShowDot ? styles.notification.dot : styles.notification.badge]; if (shouldShowDot) { return ___EmotionJSX(EuiIcon, { className: "euiHeaderSectionItemButton__notification euiHeaderSectionItemButton__notification--dot", css: cssStyles, color: notificationColor, type: "dot", size: "l" }); } else if (notification) { return ___EmotionJSX(EuiNotificationBadge, { className: "euiHeaderSectionItemButton__notification euiHeaderSectionItemButton__notification--badge", css: cssStyles, color: notificationColor }, notification); } }, [notification, notificationColor, styles.notification, shouldShowDot]); return ___EmotionJSX(EuiButtonEmpty, _extends({ className: classes, css: styles.euiHeaderSectionItemButton, color: "text", buttonRef: buttonRef }, rest), ___EmotionJSX("span", { ref: animationTargetRef, className: "euiHeaderSectionItemButton__content", css: styles.euiHeaderSectionItemButton__content }, children), buttonNotification); }); EuiHeaderSectionItemButton.propTypes = { href: PropTypes.string, onClick: PropTypes.func, /** * Force disables the button and changes the icon to a loading spinner */ /** * Force disables the button and changes the icon to a loading spinner */ isLoading: PropTypes.bool, target: PropTypes.string, rel: PropTypes.string, type: PropTypes.any, buttonRef: PropTypes.any, /** * Object of props passed to the `<span>` wrapping the button's content */ /** * Object of props passed to the `<span>` wrapping the button's content */ contentProps: PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any }), /** * Any `type` accepted by EuiIcon */ iconType: PropTypes.oneOfType([PropTypes.oneOf(["accessibility", "addDataApp", "addToDashboard", "advancedSettingsApp", "agentApp", "aggregate", "alignBottom", "alignBottomLeft", "alignBottomRight", "alignCenterHorizontal", "alignCenterVertical", "alignLeft", "alignRight", "alignTop", "alignTopLeft", "alignTopRight", "alert", "analyzeEvent", "annotation", "anomalyChart", "chartAnomaly", "anomalySwimLane", "apmApp", "apmTrace", "chartWaterfall", "appSearchApp", "apps", "arrowDown", "chevronSingleDown", "arrowLeft", "chevronSingleLeft", "arrowRight", "chevronSingleRight", "arrowUp", "chevronSingleUp", "arrowStart", "chevronLimitLeft", "arrowEnd", "chevronLimitRight", "article", "asterisk", "at", "archive", "axisX", "axisYLeft", "axisYRight", "auditbeatApp", "backgroundTask", "beaker", "bell", "bellSlash", "beta", "bolt", "boxesHorizontal", "boxesVertical", "branch", "briefcase", "branchUser", "broom", "brush", "bug", "bulb", "bullseye", "calendar", "canvasApp", "casesApp", "changePointDetection", "chartChangePoint", "chartArea", "chartAreaStack", "chartBarHorizontal", "chartBarHorizontalStack", "chartBarVertical", "chartBarVerticalStack", "chartGauge", "chartHeatmap", "chartLine", "chartPie", "chartTagCloud", "chartThreshold", "check", "checkCircle", "checkInCircleFilled", "checkCircleFill", "cheer", "popper", "classificationJob", "clickLeft", "clickRight", "clock", "clockCounter", "clockControl", "cloud", "cloudDrizzle", "cloudStormy", "cloudSunny", "cluster", "code", "codeApp", "color", "paintBucket", "commandLine", "comment", "compare", "compute", "processor", "console", "consoleApp", "container", "continuityAbove", "continuityAboveBelow", "continuityBelow", "continuityWithin", "contrast", "contrastHigh", "contrastFill", "controls", "controlsHorizontal", "controlsVertical", "copy", "copyClipboard", "crossProjectSearch", "createAdvancedJob", "createGenericJob", "createGeoJob", "createMultiMetricJob", "createPopulationJob", "createSingleMetricJob", "cross", "crossClusterReplicationApp", "crossInCircle", "crossCircle", "crosshair", "crosshairs", "currency", "money", "cut", "scissors", "dashboardApp", "dashedCircle", "dataVisualizer", "database", "desktop", "display", "devToolsApp", "diff", "discoverApp", "distributeHorizontal", "distributeVertical", "download", "drag", "dragHorizontal", "dragVertical", "discuss", "document", "documentEdit", "documentation", "documents", "dot", "dotInCircle", "doubleArrowLeft", "chevronDoubleLeft", "doubleArrowRight", "chevronDoubleRight", "ellipsis", "editorAlignCenter", "textAlignCenter", "editorAlignLeft", "textAlignLeft", "editorAlignRight", "textAlignRight", "editorBold", "textBold", "editorChecklist", "listCheck", "editorCodeBlock", "editorComment", "editorDistributeHorizontal", "editorDistributeVertical", "editorHeading", "textHeading", "editorItalic", "textItalic", "editorItemAlignBottom", "editorItemAlignCenter", "editorItemAlignLeft", "editorItemAlignMiddle", "editorItemAlignRight", "editorItemAlignTop", "editorLink", "editorOrderedList", "listNumber", "editorPositionBottomLeft", "editorPositionBottomRight", "editorPositionTopLeft", "editorPositionTopRight", "editorRedo", "redo", "editorStrike", "textStrike", "editorTable", "table", "editorUnderline", "textUnderline", "editorUndo", "undo", "editorUnorderedList", "listBullet", "email", "mail", "empty", "emsApp", "endpoint", "eql", "query", "eraser", "error", "errorFilled", "errorFill", "esqlVis", "exit", "logOut", "expand", "maximize", "expandMini", "export", "exportAction", "upload", "external", "eye", "eyeClosed", "eyeSlash", "faceHappy", "faceNeutral", "faceSad", "fieldStatistics", "tableInfo", "filebeatApp", "filter", "filterExclude", "filterIgnore", "filterInclude", "filterInCircle", "flask", "flag", "fleetApp", "fold", "folder", "folderClosed", "folderClose", "folderCheck", "folderExclamation", "folderOpen", "folderOpened", "frameNext", "framePrevious", "fullScreen", "fullScreenExit", "function", "gear", "gisApp", "glasses", "globe", "grab", "grabHorizontal", "grabOmnidirectional", "gradient", "graphApp", "grid", "grokApp", "heart", "heartbeatApp", "heatmap", "help", "home", "hourglass", "if", "info", "image", "importAction", "index", "indexClose", "indexEdit", "indexFlush", "indexManagementApp", "indexMapping", "mapping", "indexOpen", "indexPatternApp", "indexRollupApp", "indexRuntime", "indexSettings", "indexTemporary", "tableTime", "infinity", "inputOutput", "inspect", "invert", "ip", "key", "keyboard", "kqlField", "queryField", "kqlFunction", "kqlOperand", "queryOperand", "kqlSelector", "querySelector", "kqlValue", "queryValue", "kubernetesNode", "kubernetesPod", "launch", "rocket", "layers", "lensApp", "lettering", "text", "lineBreak", "lineBreakSlash", "lineDash", "lineDashed", "lineDot", "lineDotted", "lineSolid", "link", "linkSlash", "list", "listAdd", "lock", "lockOpen", "logPatternAnalysis", "pattern", "logRateAnalysis", "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", "logoVectorDB", "logoVulnerabilityManagement", "logoWebhook", "logoWindows", "logoWorkplaceSearch", "logsApp", "logstashFilter", "logstashIf", "logstashInput", "logstashOutput", "logstashQueue", "queue", "machineLearningApp", "magnet", "magnify", "magnifyExclamation", "magnifyMinus", "magnifyPlus", "magnifyWithExclamation", "magnifyWithMinus", "magnifyWithPlus", "managementApp", "map", "mapMarker", "waypoint", "megaphone", "memory", "menu", "menuDown", "menuLeft", "menuRight", "menuUp", "merge", "metricbeatApp", "metricsApp", "minimize", "minus", "minusCircle", "minusInCircle", "minusInCircleFilled", "minusInSquare", "minusSquare", "mobile", "monitoringApp", "moon", "move", "namespace", "nested", "newChat", "node", "vectorTriangle", "notebookApp", "number", "offline", "wifiSlash", "online", "wifi", "outlierDetectionJob", "package", "packetbeatApp", "pageSelect", "pagesSelect", "palette", "paperClip", "partial", "pause", "payment", "pencil", "percent", "pin", "pinFill", "pinFilled", "pipeBreaks", "pipelineApp", "pipeNoBreaks", "pivot", "play", "playFilled", "plugs", "plus", "plusCircle", "plusInCircle", "plusInCircleFilled", "plusInSquare", "plusSquare", "popout", "presentation", "productRobot", "productAgent", "productCloudInfra", "productDashboard", "productDiscover", "productML", "productStreamsClassic", "productStreamsWired", "push", "send", "question", "quote", "radar", "readOnly", "recentlyViewedApp", "refresh", "regressionJob", "reporter", "reportingApp", "return", "returnKey", "save", "savedObjectsApp", "scale", "search", "searchProfilerApp", "section", "securityAnalyticsApp", "securityApp", "securitySignal", "securitySignalDetected", "securitySignalResolved", "server", "sessionViewer", "shard", "share", "significantEvents", "singleMetricViewer", "snowflake", "sortAscending", "sortDescending", "sortDown", "sortLeft", "sortRight", "sortUp", "sortable", "spaces", "spacesApp", "sparkles", "sqlApp", "star", "starEmpty", "starEmptySpace", "starFill", "starFilled", "starFillSpace", "starFilledSpace", "starMinusEmpty", "starMinusFill", "starMinusFilled", "starPlusEmpty", "starPlusFill", "starPlusFilled", "stats", "stop", "stopFill", "stopFilled", "stopSlash", "storage", "streamsClassic", "streamsWired", "string", "submodule", "sun", "swatchInput", "symlink", "tableDensityCompact", "tableDensityHigh", "tableDensityExpanded", "tableDensityLow", "tableDensityNormal", "tableOfContents", "tag", "tear", "temperature", "thermometer", "thumbDown", "thumbUp", "timeline", "timelineWithArrow", "timelionApp", "timeRefresh", "refreshTime", "timeslider", "training", "transitionBottomIn", "transitionBottomOut", "transitionLeftIn", "transitionLeftOut", "transitionTopIn", "transitionTopOut", "trash", "unfold", "unlink", "upgradeAssistantApp", "uptimeApp", "user", "userAvatar", "users", "usersRolesApp", "unarchive", "vector", "vectorSquare", "videoPlayer", "visArea", "visAreaStacked", "visBarHorizontal", "visBarHorizontalStacked", "visBarVertical", "visBarVerticalStacked", "visGauge", "visGoal", "visLine", "visMapCoordinate", "visMapRegion", "visMetric", "chartMetric", "visPie", "visTable", "visTagCloud", "visText", "visTimelion", "visVega", "visVisualBuilder", "visualizeApp", "vulnerabilityManagementApp", "warning", "warningFilled", "warningFill", "watchesApp", "web", "wordWrap", "wordWrapDisabled", "workflowsApp", "workflow", "workplaceSearchApp", "wrench", "tokenAlias", "tokenAnnotation", "tokenArray", "tokenBinary", "tokenBoolean", "tokenClass", "tokenCompletionSuggester", "tokenConstant", "tokenDate", "tokenDimension", "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", "tokenSemanticText", "tokenShape", "tokenString", "tokenStruct", "tokenSymbol", "tokenTag", "tokenText", "tokenTokenCount", "tokenVariable", "tokenVectorDense", "tokenDenseVector", "tokenVectorSparse"]).isRequired, PropTypes.string.isRequired, PropTypes.elementType.isRequired]), /** * Can only be one side `left` or `right` */ iconSide: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.oneOf([undefined])]), /** * Object of props passed to the `<span>` wrapping the content's text/children only (not icon) * * This span wrapper can be removed by passing `textProps={false}`. */ textProps: PropTypes.oneOfType([PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, ref: PropTypes.any, "data-text": PropTypes.string }).isRequired, PropTypes.oneOf([false])]), iconSize: PropTypes.any, /** * Controls the disabled behavior via the native `disabled` attribute. */ isDisabled: PropTypes.bool, className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * 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, /** * Inserts the node into a EuiBadgeNotification and places it appropriately against the button. * Or pass `true` to render a simple dot */ notification: PropTypes.oneOfType([PropTypes.node.isRequired, PropTypes.bool.isRequired]), /** * Changes the color of the notification background */ notificationColor: PropTypes.any }; EuiHeaderSectionItemButton.displayName = 'EuiHeaderSectionItemButton';