@elastic/eui
Version:
Elastic UI Component Library
275 lines (274 loc) • 18.2 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EuiHeaderSectionItemButton = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _services = require("../../../services");
var _badge_notification = require("../../badge/notification_badge/badge_notification");
var _icon = require("../../icon");
var _button = require("../../button");
var _responsive = require("../../responsive");
var _header_section_item_button = require("./header_section_item_button.styles");
var _react2 = require("@emotion/react");
var _excluded = ["children", "className", "notification", "notificationColor"];
/*
* 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.
*/
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var EuiHeaderSectionItemButton = exports.EuiHeaderSectionItemButton = /*#__PURE__*/(0, _react.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 = (0, _objectWithoutProperties2.default)(_ref, _excluded);
var buttonRef = (0, _react.useRef)(null);
var animationTargetRef = (0, _react.useRef)(null);
(0, _react.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 euiTheme = (0, _services.useEuiTheme)();
var styles = (0, _header_section_item_button.euiHeaderSectionItemButtonStyles)(euiTheme);
var classes = (0, _classnames.default)('euiHeaderSectionItemButton', className);
var notificationDot = (0, _react2.jsx)(_icon.EuiIcon, {
className: "euiHeaderSectionItemButton__notification euiHeaderSectionItemButton__notification--dot",
css: [styles.notification.euiHeaderSectionItemButton__notification, styles.notification.dot, ";label:notificationDot;"],
color: notificationColor,
type: "dot",
size: "l"
});
var buttonNotification;
if (notification === true) {
buttonNotification = notificationDot;
} else if (notification) {
buttonNotification = (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_responsive.EuiHideFor, {
sizes: ['xs']
}, (0, _react2.jsx)(_badge_notification.EuiNotificationBadge, {
className: "euiHeaderSectionItemButton__notification euiHeaderSectionItemButton__notification--badge",
css: [styles.notification.euiHeaderSectionItemButton__notification, styles.notification.badge, ";label:buttonNotification;"],
color: notificationColor
}, notification)), (0, _react2.jsx)(_responsive.EuiShowFor, {
sizes: ['xs']
}, notificationDot));
}
return (0, _react2.jsx)(_button.EuiButtonEmpty, (0, _extends2.default)({
className: classes,
css: styles.euiHeaderSectionItemButton,
color: "text",
buttonRef: buttonRef
}, rest), (0, _react2.jsx)("span", {
ref: animationTargetRef,
className: "euiHeaderSectionItemButton__content",
css: styles.euiHeaderSectionItemButton__content
}, children), buttonNotification);
});
EuiHeaderSectionItemButton.propTypes = {
href: _propTypes.default.string,
onClick: _propTypes.default.func,
/**
* Any of the named color palette options.
*/
color: _propTypes.default.any,
size: _propTypes.default.any,
/**
* Ensure the text of the button sits flush to the left, right, or both sides of its container
*/
/**
* Ensure the text of the button sits flush to the left, right, or both sides of its container
*/
flush: _propTypes.default.any,
/**
* `disabled` is also allowed
*/
/**
* `disabled` is also allowed
*/
isDisabled: _propTypes.default.bool,
/**
* 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.default.bool,
/**
* 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.*
*/
/**
* 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.default.bool,
target: _propTypes.default.string,
rel: _propTypes.default.string,
type: _propTypes.default.any,
buttonRef: _propTypes.default.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.default.shape({
className: _propTypes.default.string,
"aria-label": _propTypes.default.string,
"data-test-subj": _propTypes.default.string,
css: _propTypes.default.any
}),
/**
* Any `type` accepted by EuiIcon
*/
iconType: _propTypes.default.oneOfType([_propTypes.default.oneOf(["accessibility", "addDataApp", "advancedSettingsApp", "agentApp", "aggregate", "analyzeEvent", "annotation", "anomalyChart", "anomalySwimLane", "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", "changePointDetection", "check", "checkInCircleFilled", "cheer", "classificationJob", "clickLeft", "clickRight", "clock", "clockCounter", "cloudDrizzle", "cloudStormy", "cloudSunny", "cluster", "codeApp", "color", "compute", "console", "consoleApp", "container", "continuityAbove", "continuityAboveBelow", "continuityBelow", "continuityWithin", "controlsHorizontal", "controlsVertical", "copy", "copyClipboard", "createAdvancedJob", "createMultiMetricJob", "createPopulationJob", "createSingleMetricJob", "cross", "crossClusterReplicationApp", "crossInCircle", "crosshairs", "currency", "cut", "dashboardApp", "dataVisualizer", "database", "desktop", "devToolsApp", "diff", "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", "endpoint", "eql", "eraser", "error", "errorFilled", "esqlVis", "exit", "expand", "expandMini", "exportAction", "eye", "eyeClosed", "faceHappy", "faceNeutral", "faceSad", "fieldStatistics", "filebeatApp", "filter", "filterExclude", "filterIgnore", "filterInclude", "filterInCircle", "flag", "fleetApp", "fold", "folderCheck", "folderClosed", "folderExclamation", "folderOpen", "frameNext", "framePrevious", "fullScreen", "fullScreenExit", "function", "gear", "gisApp", "glasses", "globe", "grab", "grabHorizontal", "grabOmnidirectional", "gradient", "graphApp", "grid", "grokApp", "heart", "heartbeatApp", "heatmap", "help", "home", "iInCircle", "image", "importAction", "index", "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", "logPatternAnalysis", "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", "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", "minusInSquare", "mobile", "monitoringApp", "moon", "move", "namespace", "nested", "newChat", "node", "notebookApp", "number", "offline", "online", "outlierDetectionJob", "package", "packetbeatApp", "pageSelect", "pagesSelect", "palette", "paperClip", "partial", "pause", "payment", "pencil", "percent", "pin", "pinFilled", "pipeBreaks", "pipelineApp", "pipeNoBreaks", "pivot", "play", "playFilled", "plus", "plusInCircle", "plusInCircleFilled", "plusInSquare", "popout", "push", "questionInCircle", "quote", "recentlyViewedApp", "refresh", "regressionJob", "reporter", "reportingApp", "returnKey", "save", "savedObjectsApp", "scale", "search", "searchProfilerApp", "securityAnalyticsApp", "securityApp", "securitySignal", "securitySignalDetected", "securitySignalResolved", "sessionViewer", "shard", "share", "singleMetricViewer", "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", "transitionLeftIn", "transitionLeftOut", "transitionTopIn", "transitionTopOut", "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", "warningFilled", "alert", "watchesApp", "wordWrap", "wordWrapDisabled", "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.default.string.isRequired, _propTypes.default.elementType.isRequired]),
/**
* Can only be one side `left` or `right`
*/
iconSide: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.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.default.oneOfType([_propTypes.default.shape({
className: _propTypes.default.string,
"aria-label": _propTypes.default.string,
"data-test-subj": _propTypes.default.string,
css: _propTypes.default.any,
ref: _propTypes.default.any,
"data-text": _propTypes.default.string
}).isRequired, _propTypes.default.oneOf([false])]),
iconSize: _propTypes.default.any,
className: _propTypes.default.string,
"aria-label": _propTypes.default.string,
"data-test-subj": _propTypes.default.string,
css: _propTypes.default.any,
/**
* Inserts the node into a EuiBadgeNotification and places it appropriately against the button.
* Or pass `true` to render a simple dot
*/
notification: _propTypes.default.oneOfType([_propTypes.default.node.isRequired, _propTypes.default.bool.isRequired]),
/**
* Changes the color of the notification background
*/
notificationColor: _propTypes.default.any
};
EuiHeaderSectionItemButton.displayName = 'EuiHeaderSectionItemButton';