UNPKG

@elastic/eui

Version:

Elastic UI Component Library

295 lines (293 loc) 19.8 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiCollapsibleNavGroup = exports.BACKGROUNDS = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _classnames = _interopRequireDefault(require("classnames")); var _services = require("../../../services"); var _accordion = require("../../accordion"); var _icon = require("../../icon"); var _flex = require("../../flex"); var _title = require("../../title"); var _collapsible_nav_group = require("./collapsible_nav_group.styles"); var _react2 = require("@emotion/react"); var _excluded = ["className", "children", "id", "title", "iconType", "iconSize", "background", "isCollapsible", "titleElement", "titleSize", "iconProps"]; /* * 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. */ var BACKGROUNDS = exports.BACKGROUNDS = ['none', 'light', 'dark']; var EuiCollapsibleNavGroup = exports.EuiCollapsibleNavGroup = function EuiCollapsibleNavGroup(_ref) { var className = _ref.className, children = _ref.children, id = _ref.id, title = _ref.title, iconType = _ref.iconType, _ref$iconSize = _ref.iconSize, iconSize = _ref$iconSize === void 0 ? 'l' : _ref$iconSize, _ref$background = _ref.background, background = _ref$background === void 0 ? 'none' : _ref$background, _ref$isCollapsible = _ref.isCollapsible, isCollapsible = _ref$isCollapsible === void 0 ? false : _ref$isCollapsible, _ref$titleElement = _ref.titleElement, titleElement = _ref$titleElement === void 0 ? 'h3' : _ref$titleElement, _ref$titleSize = _ref.titleSize, titleSize = _ref$titleSize === void 0 ? 'xxs' : _ref$titleSize, iconProps = _ref.iconProps, rest = (0, _objectWithoutProperties2.default)(_ref, _excluded); var groupID = (0, _services.useGeneratedHtmlId)({ conditionalId: id }); var titleID = "".concat(groupID, "__title"); var styles = (0, _services.useEuiMemoizedStyles)(_collapsible_nav_group.euiCollapsibleNavGroupStyles); var cssStyles = [styles.euiCollapsibleNavGroup, isCollapsible ? styles.isCollapsible : styles.notCollapsible, background && styles[background]]; var classes = (0, _classnames.default)('euiCollapsibleNavGroup', className); // Warn if consumer passes an iconType without a title if (iconType && !title) { console.warn('EuiCollapsibleNavGroup will not render an icon without `title`.'); } var childrenStyles = [styles.childrenWrapper.euiCollapsibleNavGroup__children, title && styles.childrenWrapper.withHeading]; var content = children && (0, _react2.jsx)("div", { css: childrenStyles, className: "euiCollapsibleNavGroup__children" }, children); var headingClasses = 'euiCollapsibleNavGroup__heading'; var TitleElement = titleElement; var titleContent = title ? (0, _react2.jsx)(_flex.EuiFlexGroup, { gutterSize: "m", alignItems: "center", responsive: false }, iconType && (0, _react2.jsx)(_flex.EuiFlexItem, { grow: false }, (0, _react2.jsx)(_icon.EuiIcon, (0, _extends2.default)({}, iconProps, { type: iconType, size: iconSize }))), (0, _react2.jsx)(_flex.EuiFlexItem, null, (0, _react2.jsx)(_title.EuiTitle, { size: titleSize }, (0, _react2.jsx)(TitleElement, { id: titleID, className: "euiCollapsibleNavGroup__title" }, title)))) : undefined; var render; if (isCollapsible && title) { render = (0, _react2.jsx)(_accordion.EuiAccordion, (0, _extends2.default)({ id: groupID, css: cssStyles, className: classes, buttonClassName: headingClasses, buttonContent: titleContent, initialIsOpen: true, arrowDisplay: "right" }, rest), content); } else { render = (0, _react2.jsx)("div", (0, _extends2.default)({ id: groupID, css: cssStyles, className: classes }, rest), titleContent && (0, _react2.jsx)("div", { className: headingClasses }, titleContent), content); } return background === 'dark' ? (0, _react2.jsx)(_services.EuiThemeProvider, { colorMode: "dark", wrapperProps: { cloneElement: true } }, render) : render; }; EuiCollapsibleNavGroup.propTypes = { /** * ReactNode to render as this component's content */ /** * ReactNode to render as this component's content */ children: _propTypes.default.node, /** * Sits left of the `title` and only when `title` is present */ 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]), /** * Change the size of the icon in the `title` */ iconSize: _propTypes.default.any, /** * Further extend the props applied to EuiIcon */ iconProps: _propTypes.default.shape({ className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any, /** * One of EUI's color palette or a valid CSS color value https://developer.mozilla.org/en-US/docs/Web/CSS/color_value. * Note that coloring only works if your SVG is removed of fill attributes. */ color: _propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.any.isRequired]), /** * Descriptive title for naming the icon based on its use */ title: _propTypes.default.string, /** * A unique identifier for the title element */ titleId: _propTypes.default.string, /** * Its value should be one or more element IDs */ "aria-labelledby": _propTypes.default.string, /** * Callback when the icon has been loaded & rendered */ onIconLoad: _propTypes.default.func }), /** * Optionally provide an id, otherwise one will be created */ /** * Optionally provide an id, otherwise one will be created */ id: _propTypes.default.string, /** * Adds a background color to the entire group, * applying the correct text color to the `title` only */ /** * Adds a background color to the entire group, * applying the correct text color to the `title` only */ background: _propTypes.default.any, /** * Determines the title's heading element */ /** * Determines the title's heading element */ titleElement: _propTypes.default.oneOf(["h2", "h3", "h4", "h5", "h6", "span"]), /** * Title sizing equivalent to EuiTitle, but only `s` and smaller */ /** * Title sizing equivalent to EuiTitle, but only `s` and smaller */ titleSize: _propTypes.default.any, className: _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.string]), _propTypes.default.string]), "aria-label": _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.string]), _propTypes.default.string]), "data-test-subj": _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.string]), _propTypes.default.string]), css: _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.any, _propTypes.default.any]), _propTypes.default.any]), /** * Applied to the entire .euiAccordion wrapper. * When using `fieldset`, it will enforce `buttonElement = legend` as well. */ element: _propTypes.default.oneOf(["div", "fieldset"]), /** * Defaults to the [group role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/group_role). * * If your accordion contains significant enough content to be a document * [landmark role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/region_role#accessibility_concerns), consider using the `region` role instead. * @default group */ role: _propTypes.default.any, /** * Class that will apply to the trigger for the accordion. */ buttonClassName: _propTypes.default.string, /** * Apply more props to the triggering button. * * Includes optional `paddingSize` prop which allows sizes of `s`, `m`, or `l`. * Note: Padding will not be present on the side closest to the accordion arrow. */ buttonProps: _propTypes.default.shape({ className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any, paddingSize: _propTypes.default.oneOf(["s", "m", "l"]) }), /** * Class that will apply to the trigger content for the accordion. */ buttonContentClassName: _propTypes.default.string, /** * The content of the clickable trigger */ buttonContent: _propTypes.default.node, /** * Applied to the main button receiving the `onToggle` event. * Anything other than the default `button` does not support removing the arrow display (for accessibility of focus). */ buttonElement: _propTypes.default.oneOf(["div", "legend", "button"]), /** * Extra props to pass to the EuiButtonIcon containing the arrow. */ arrowProps: _propTypes.default.any, /** * Will appear right aligned against the button. Useful for separate actions like deletions. */ extraAction: _propTypes.default.node, /** * The accordion will start in the open state. */ initialIsOpen: _propTypes.default.bool, /** * Optional callback method called on open and close with a single `isOpen` parameter */ onToggle: _propTypes.default.func, /** * The padding around the exposed accordion content. */ paddingSize: _propTypes.default.any, /** * Placement of the arrow indicator, or 'none' to hide it. */ arrowDisplay: _propTypes.default.oneOf(["left", "right", "none"]), /** * Optional border styling. Defaults to 'none'. */ borders: _propTypes.default.oneOf(["horizontal", "all", "none"]), /** * Control the opening of accordion via prop */ forceState: _propTypes.default.oneOf(["closed", "open"]), /** * Change `extraAction` and children into a loading spinner */ isLoading: _propTypes.default.bool, /** * Choose whether the loading message replaces the content. Customize the message by passing a node */ isLoadingMessage: _propTypes.default.oneOfType([_propTypes.default.bool.isRequired, _propTypes.default.node.isRequired]), /** * Disable the open/close interaction and visually subdues the trigger */ isDisabled: _propTypes.default.bool, /** * If `true`, wraps children in the body of an accordion, * requiring the prop `title` to be used as the button. * When `false`, simply renders a div without any accordion functionality. */ /** * If `true`, wraps children in the body of an accordion, * requiring the prop `title` to be used as the button. * When `false`, simply renders a div without any accordion functionality. */ isCollapsible: _propTypes.default.oneOfType([_propTypes.default.oneOf([true]).isRequired, _propTypes.default.oneOf([false])]), /** * The title gets wrapped in the appropriate heading level * with the option to add an iconType */ /** * The title gets wrapped in the appropriate heading level * with the option to add an iconType */ title: _propTypes.default.oneOfType([_propTypes.default.node.isRequired, _propTypes.default.node]) };