UNPKG

@robotical/sensors-dashboard

Version:

A dashboard tool for depicting Marty data by Robotical

80 lines (79 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Dropdown; require("core-js/modules/es.regexp.exec.js"); require("core-js/modules/es.string.replace.js"); require("core-js/modules/web.dom-collections.iterator.js"); var _react = require("react"); var _material = require("@mui/material"); var _jsxRuntime = require("react/jsx-runtime"); const CustomFontTheme = (0, _material.createTheme)({ typography: { fontFamily: "Lato Regular" } }); function Dropdown(_ref) { let { label, onChange: _onChange, options, selectedOption, rule, disabled = false } = _ref; const reactId = (0, _react.useId)(); const fieldId = "".concat(rule, "-rule-").concat(reactId.replace(/:/g, "")); const optionsByAddon = {}; for (const option of options) { const whoAmI = option[0]; if (optionsByAddon.hasOwnProperty(whoAmI)) { optionsByAddon[whoAmI].push(option); } else { optionsByAddon[whoAmI] = [option]; } } const optionElements = []; for (const [whoAmI, addonOptions] of Object.entries(optionsByAddon)) { if (whoAmI !== "default") { optionElements.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListSubheader, { component: "div", children: whoAmI }, "".concat(whoAmI, "-header"))); } for (const option of addonOptions) { optionElements.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, { value: option, children: option[2] }, "".concat(option[0], "-").concat(option[1], "-").concat(option[2]))); } } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ThemeProvider, { theme: CustomFontTheme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.FormControl, { fullWidth: true, disabled: disabled, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, { id: fieldId, select: true, label: label, value: selectedOption !== null && selectedOption !== void 0 ? selectedOption : "", onChange: event => _onChange(event.target.value, rule), size: "small", disabled: disabled, sx: { "& .MuiInputBase-root": { minHeight: "4.4rem" } }, SelectProps: { inputProps: { "aria-label": label } }, children: optionElements }) }) }); }