@robotical/sensors-dashboard
Version:
A dashboard tool for depicting Marty data by Robotical
64 lines (63 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Dropdown;
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/esnext.iterator.map.js");
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
} = _ref;
const optionsJSX = [];
// reformat options array to a compatible type for the dropdown with categories
const optionsObj = {};
for (const option of options) {
const whoAmI = option[0];
if (optionsObj.hasOwnProperty(whoAmI)) {
optionsObj[whoAmI].push(option);
} else {
optionsObj[whoAmI] = [option];
}
}
for (const whoAmI in optionsObj) {
const menuItemsWithinCategory = optionsObj[whoAmI].map(option => {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
value: option,
children: option[2]
}, option[0] + option[1] + option[2]);
});
optionsJSX.push([whoAmI !== "default" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListSubheader, {
children: whoAmI
}), menuItemsWithinCategory]);
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ThemeProvider, {
theme: CustomFontTheme,
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.FormControl, {
fullWidth: true,
children: [!selectedOption && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputLabel, {
id: "demo-simple-select-label",
children: label
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.TextField, {
id: "standard-select-currency",
select: true,
label: label,
value: selectedOption,
onChange: e => _onChange(e.target.value, rule),
size: "small",
children: optionsJSX
})]
})
});
}