@grafana/ui
Version:
Grafana Components Library
41 lines (36 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var Menu = require('../Menu/Menu.cjs');
var MenuItem = require('../Menu/MenuItem.cjs');
var ScrollContainer = require('../ScrollContainer/ScrollContainer.cjs');
var ToolbarButton = require('../ToolbarButton/ToolbarButton.cjs');
var Dropdown = require('./Dropdown.cjs');
;
const ButtonSelectComponent = (props) => {
const { className, options, value, onChange, narrow, variant, root, ...restProps } = props;
const [isOpen, setIsOpen] = React.useState(false);
const renderMenu = () => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { tabIndex: -1, onClose: () => setIsOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(ScrollContainer.ScrollContainer, { maxHeight: "100vh", children: options.map((item) => {
var _a;
return /* @__PURE__ */ jsxRuntime.jsx(
MenuItem.MenuItem,
{
label: (_a = item.label) != null ? _a : String(item.value),
onClick: () => onChange(item),
active: item.value === (value == null ? void 0 : value.value),
ariaChecked: item.value === (value == null ? void 0 : value.value),
ariaLabel: item.ariaLabel || item.label,
disabled: item.isDisabled,
component: item.component,
role: "menuitemradio"
},
`${item.value}`
);
}) }) });
return /* @__PURE__ */ jsxRuntime.jsx(Dropdown.Dropdown, { root, overlay: renderMenu, placement: "bottom-end", children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarButton.ToolbarButton, { className, isOpen, narrow, variant, ...restProps, children: (value == null ? void 0 : value.label) || ((value == null ? void 0 : value.value) != null ? String(value == null ? void 0 : value.value) : null) }) });
};
ButtonSelectComponent.displayName = "ButtonSelect";
const ButtonSelect = React.memo(ButtonSelectComponent);
exports.ButtonSelect = ButtonSelect;
//# sourceMappingURL=ButtonSelect.cjs.map