UNPKG

@elastic/eui

Version:

Elastic UI Component Library

290 lines (288 loc) 18.9 kB
var _excluded = ["className", "children", "id", "title", "iconType", "iconSize", "background", "isCollapsible", "titleElement", "titleSize", "iconProps"]; 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 from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { EuiThemeProvider, useEuiMemoizedStyles, useGeneratedHtmlId } from '../../../services'; import { EuiAccordion } from '../../accordion'; import { EuiIcon } from '../../icon'; import { EuiFlexGroup, EuiFlexItem } from '../../flex'; import { EuiTitle } from '../../title'; import { euiCollapsibleNavGroupStyles } from './collapsible_nav_group.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var BACKGROUNDS = ['none', 'light', 'dark']; export var 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 = _objectWithoutProperties(_ref, _excluded); var groupID = useGeneratedHtmlId({ conditionalId: id }); var titleID = "".concat(groupID, "__title"); var styles = useEuiMemoizedStyles(euiCollapsibleNavGroupStyles); var cssStyles = [styles.euiCollapsibleNavGroup, isCollapsible ? styles.isCollapsible : styles.notCollapsible, background && styles[background]]; var classes = classNames('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 && ___EmotionJSX("div", { css: childrenStyles, className: "euiCollapsibleNavGroup__children" }, children); var headingClasses = 'euiCollapsibleNavGroup__heading'; var TitleElement = titleElement; var titleContent = title ? ___EmotionJSX(EuiFlexGroup, { gutterSize: "m", alignItems: "center", responsive: false }, iconType && ___EmotionJSX(EuiFlexItem, { grow: false }, ___EmotionJSX(EuiIcon, _extends({}, iconProps, { type: iconType, size: iconSize }))), ___EmotionJSX(EuiFlexItem, null, ___EmotionJSX(EuiTitle, { size: titleSize }, ___EmotionJSX(TitleElement, { id: titleID, className: "euiCollapsibleNavGroup__title" }, title)))) : undefined; var render; if (isCollapsible && title) { render = ___EmotionJSX(EuiAccordion, _extends({ id: groupID, css: cssStyles, className: classes, buttonClassName: headingClasses, buttonContent: titleContent, initialIsOpen: true, arrowDisplay: "right" }, rest), content); } else { render = ___EmotionJSX("div", _extends({ id: groupID, css: cssStyles, className: classes }, rest), titleContent && ___EmotionJSX("div", { className: headingClasses }, titleContent), content); } return background === 'dark' ? ___EmotionJSX(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.node, /** * Sits left of the `title` and only when `title` is present */ iconType: PropTypes.oneOfType([PropTypes.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.string.isRequired, PropTypes.elementType.isRequired]), /** * Change the size of the icon in the `title` */ iconSize: PropTypes.any, /** * Further extend the props applied to EuiIcon */ iconProps: PropTypes.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.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.oneOfType([PropTypes.string.isRequired, PropTypes.any.isRequired]), /** * Descriptive title for naming the icon based on its use */ title: PropTypes.string, /** * A unique identifier for the title element */ titleId: PropTypes.string, /** * Its value should be one or more element IDs */ "aria-labelledby": PropTypes.string, /** * Callback when the icon has been loaded & rendered */ onIconLoad: PropTypes.func }), /** * Optionally provide an id, otherwise one will be created */ /** * Optionally provide an id, otherwise one will be created */ id: PropTypes.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.any, /** * Determines the title's heading element */ /** * Determines the title's heading element */ titleElement: PropTypes.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.any, className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * Applied to the entire .euiAccordion wrapper. * When using `fieldset`, it will enforce `buttonElement = legend` as well. */ element: PropTypes.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.any, /** * Class that will apply to the trigger for the accordion. */ buttonClassName: PropTypes.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.shape({ className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, paddingSize: PropTypes.oneOf(["s", "m", "l"]) }), /** * Class that will apply to the trigger content for the accordion. */ buttonContentClassName: PropTypes.string, /** * The content of the clickable trigger */ buttonContent: PropTypes.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.oneOf(["div", "legend", "button"]), /** * Extra props to pass to the EuiButtonIcon containing the arrow. */ arrowProps: PropTypes.any, /** * Will appear right aligned against the button. Useful for separate actions like deletions. */ extraAction: PropTypes.node, /** * The accordion will start in the open state. */ initialIsOpen: PropTypes.bool, /** * Optional callback method called on open and close with a single `isOpen` parameter */ onToggle: PropTypes.func, /** * The padding around the exposed accordion content. */ paddingSize: PropTypes.any, /** * Placement of the arrow indicator, or 'none' to hide it. */ arrowDisplay: PropTypes.oneOf(["left", "right", "none"]), /** * Optional border styling. Defaults to 'none'. */ borders: PropTypes.oneOf(["horizontal", "all", "none"]), /** * Control the opening of accordion via prop */ forceState: PropTypes.oneOf(["closed", "open"]), /** * Change `extraAction` and children into a loading spinner */ isLoading: PropTypes.bool, /** * Choose whether the loading message replaces the content. Customize the message by passing a node */ isLoadingMessage: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.node.isRequired]), /** * Disable the open/close interaction and visually subdues the trigger */ isDisabled: PropTypes.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.oneOfType([PropTypes.oneOf([true]).isRequired, PropTypes.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.oneOfType([PropTypes.node.isRequired, PropTypes.node]) };