UNPKG

@makeen.io/material-ui-kit

Version:
38 lines 2.62 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";import _extends from "@babel/runtime/helpers/extends";import React, { Fragment } from "react"; import { ListItemText, Menu, MenuItem } from "@material-ui/core"; import { withStyles } from "@material-ui/core/styles"; import { Button } from "../../atoms"; var StyledMenu = withStyles({ paper: { border: "1px solid #d3d4d5" } })(function (props) {return /*#__PURE__*/React.createElement(Menu, _extends({ getContentAnchorEl: null, anchorOrigin: { horizontal: "center", vertical: "bottom" }, transformOrigin: { horizontal: "center", vertical: "top" } }, props));}); var StyledMenuItem = withStyles(function (theme) {return { root: { "& .MuiListItemIcon-root, & .MuiListItemText-primary": { fontSize: 13 }, "&:focus": { "& .MuiListItemIcon-root, & .MuiListItemText-primary": { color: theme.palette.quaternary.contrastText }, backgroundColor: theme.palette.quaternary.main } } };})(MenuItem); export default (function (_ref) {var disabled = _ref.disabled,options = _ref.options,children = _ref.children,onClick = _ref.onClick,customRender = _ref.customRender,menuId = _ref.menuId,rest = _objectWithoutProperties(_ref, ["disabled", "options", "children", "onClick", "customRender", "menuId"]);var _React$useState = React.useState(null),_React$useState2 = _slicedToArray(_React$useState, 2),anchorEl = _React$useState2[0],setAnchorEl = _React$useState2[1]; var handleClick = function handleClick(event) { setAnchorEl(event.currentTarget); }; var handleClose = function handleClose() { setAnchorEl(null); }; var renderOptions = function renderOptions(option, index) {return /*#__PURE__*/React.createElement(StyledMenuItem, { key: index }, /*#__PURE__*/ React.createElement(ListItemText, { onClick: option.onClick, primary: option.label }));}; var customRenderOptions = function customRenderOptions(option, index) {return /*#__PURE__*/React.createElement(Fragment, { key: index }, option);}; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Button, _extends({ "aria-controls": menuId, "aria-haspopup": "true", onClick: handleClick }, rest), children), /*#__PURE__*/ React.createElement(StyledMenu, { autoFocus: false, id: menuId, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose }, (options || []).map(customRender ? customRenderOptions : renderOptions))); }); //# sourceMappingURL=index.js.map