@elastic/eui
Version:
Elastic UI Component Library
199 lines (198 loc) • 16 kB
JavaScript
var _excluded = ["className", "buttonSize", "color", "idSelected", "idToSelectedMap", "isDisabled", "isFullWidth", "isIconOnly", "legend", "name", "onChange", "options", "type"];
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 classNames from 'classnames';
import PropTypes from "prop-types";
import React from 'react';
import { useEuiMemoizedStyles } from '../../../services';
import { EuiScreenReaderOnly } from '../../accessibility';
import { EuiButtonGroupButton } from './button_group_button';
import { euiButtonGroupStyles, euiButtonGroupButtonsStyles } from './button_group.styles';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var EuiButtonGroup = function EuiButtonGroup(_ref) {
var className = _ref.className,
_ref$buttonSize = _ref.buttonSize,
buttonSize = _ref$buttonSize === void 0 ? 's' : _ref$buttonSize,
_ref$color = _ref.color,
color = _ref$color === void 0 ? 'text' : _ref$color,
_ref$idSelected = _ref.idSelected,
idSelected = _ref$idSelected === void 0 ? '' : _ref$idSelected,
_ref$idToSelectedMap = _ref.idToSelectedMap,
idToSelectedMap = _ref$idToSelectedMap === void 0 ? {} : _ref$idToSelectedMap,
_ref$isDisabled = _ref.isDisabled,
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
_ref$isFullWidth = _ref.isFullWidth,
isFullWidth = _ref$isFullWidth === void 0 ? false : _ref$isFullWidth,
_ref$isIconOnly = _ref.isIconOnly,
isIconOnly = _ref$isIconOnly === void 0 ? false : _ref$isIconOnly,
legend = _ref.legend,
name = _ref.name,
onChange = _ref.onChange,
_ref$options = _ref.options,
options = _ref$options === void 0 ? [] : _ref$options,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'single' : _ref$type,
rest = _objectWithoutProperties(_ref, _excluded);
var wrapperCssStyles = [euiButtonGroupStyles.euiButtonGroup, isFullWidth && euiButtonGroupStyles.fullWidth];
var styles = useEuiMemoizedStyles(euiButtonGroupButtonsStyles);
var cssStyles = [styles.euiButtonGroup__buttons, isFullWidth && styles.fullWidth, styles[buttonSize]];
var classes = classNames('euiButtonGroup', {
'euiButtonGroup-isDisabled': isDisabled
}, className);
var typeIsSingle = type === 'single';
return ___EmotionJSX("fieldset", _extends({
css: wrapperCssStyles,
className: classes
}, rest, {
disabled: isDisabled
}), ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("legend", null, legend)), ___EmotionJSX("div", {
css: cssStyles,
className: "euiButtonGroup__buttons"
}, options.map(function (option) {
return ___EmotionJSX(EuiButtonGroupButton, _extends({
key: option.id,
isDisabled: isDisabled
}, option, {
onClick: typeIsSingle ? function () {
return onChange(option.id, option.value);
} : function () {
return onChange(option.id);
},
isSelected: typeIsSingle ? option.id === idSelected : idToSelectedMap[option.id],
color: color,
size: buttonSize,
isIconOnly: isIconOnly
}));
})));
};
EuiButtonGroup.propTypes = {
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
/**
* Typical sizing is `s`. Medium `m` size should be reserved for major features.
* `compressed` is meant to be used alongside and within compressed forms.
*/
buttonSize: PropTypes.oneOf(["s", "m", "compressed"]),
isDisabled: PropTypes.bool,
/**
* Expands the whole group to the full width of the container.
* Each button gets equal widths no matter the content
*/
isFullWidth: PropTypes.bool,
/**
* Hides the label to only show the `iconType` provided by the `option`
*/
isIconOnly: PropTypes.bool,
/**
* A hidden group title (required for accessibility)
*/
legend: PropTypes.string.isRequired,
/**
* Any of the named color palette options.
*/
color: PropTypes.any,
/**
* Default for `type` is single so it can also be excluded
*/
/**
* Actual type is `'single' | 'multi'`.
* Determines how the selection of the group should be handled.
* With `'single'` only one option can be selected at a time (similar to radio group).
* With `'multi'` multiple options selected (similar to checkbox group).
*/
type: PropTypes.oneOfType([PropTypes.oneOfType([PropTypes.oneOf(["single", "multi"]), PropTypes.oneOf(["single"])]), PropTypes.oneOf(["multi"])]),
/**
* An array of #EuiButtonGroupOptionProps
*/
options: PropTypes.arrayOf(PropTypes.shape({
/**
* Each option must have a unique `id` for maintaining selection
*/
id: PropTypes.string.isRequired,
/**
* Each option must have a `label` even for icons which will be applied as the `aria-label`
*/
label: PropTypes.node.isRequired,
isDisabled: PropTypes.bool,
/**
* The value of the radio input.
*/
value: PropTypes.any,
/**
* The type of the underlying HTML button
*/
type: PropTypes.any,
/**
* By default, will use the button text for the native browser title.
*
* This can be either customized or unset via `title: ''` if necessary.
*/
title: PropTypes.any,
/**
* Optional custom tooltip content for the button
*/
toolTipContent: PropTypes.node,
/**
* Optional props to pass to the underlying **[EuiToolTip](/#/display/tooltip)**
*/
toolTipProps: PropTypes.any,
/**
* Any `type` accepted by EuiIcon
*/
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]),
/**
* Can only be one side `left` or `right`
*/
iconSide: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.oneOf([undefined])]),
isLoading: PropTypes.bool,
/**
* 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,
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any
}).isRequired).isRequired,
/**
* @deprecated No longer needed. You can safely remove this prop entirely
*/
name: PropTypes.string,
/**
* Styles the selected option to look selected (usually with `fill`)
* Required by and only used in `type='single'`.
*/
idSelected: PropTypes.string,
/**
* Multi: Returns the `id` of the clicked option
*/
/**
* Single: Returns the `id` of the clicked option and the `value`
*/
onChange: PropTypes.func,
/**
* A map of `id`s as keys with the selected boolean values.
* Required by and only used in `type='multi'`.
*/
idToSelectedMap: PropTypes.shape({})
};