pcm-shared-components 0.0.136 → 0.0.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,6 +31,7 @@ export const DropdownButton = props => {
31
31
  menuData,
32
32
  variant,
33
33
  size,
34
+ menuAnchorLocation,
34
35
  theme
35
36
  } = props;
36
37
  const compTheme = theme ? theme : useTheme();
@@ -38,7 +39,8 @@ export const DropdownButton = props => {
38
39
  return /*#__PURE__*/React.createElement(ThemeProvider, {
39
40
  theme: defaultTheme
40
41
  }, /*#__PURE__*/React.createElement(ReusablePopupMenu, _extends({}, menuData, {
41
- theme: defaultTheme
42
+ theme: defaultTheme,
43
+ menuAnchorLocation: menuAnchorLocation
42
44
  }), /*#__PURE__*/React.createElement(Button, {
43
45
  variant: variant,
44
46
  className: className,
@@ -55,7 +57,8 @@ DropdownButton.defaultProps = {
55
57
  color: 'primary',
56
58
  className: '',
57
59
  variant: 'text',
58
- theme: {}
60
+ theme: {},
61
+ menuAnchorLocation: 'right'
59
62
  };
60
63
  DropdownButton.propTypes = {
61
64
  /** Name of the till being used. Note: if till name exist then inUse is true */
@@ -77,5 +80,8 @@ DropdownButton.propTypes = {
77
80
  size: PropTypes.oneOf(['small', 'medium', 'large']),
78
81
 
79
82
  /** Theme object to use on this component, if none provided then the MUI5 theme provider theme is used*/
80
- theme: PropTypes.object
83
+ theme: PropTypes.object,
84
+
85
+ /** Controls the location of the dropdown popup menu */
86
+ menuAnchorLocation: PropTypes.oneOf(['left', 'center', 'right'])
81
87
  };
@@ -5,7 +5,6 @@ import { makeStyles } from '@mui/styles';
5
5
  import ListItemIcon from "@mui/material/ListItemIcon";
6
6
  import ListItemText from "@mui/material/ListItemText";
7
7
  import Switch from "@mui/material/Switch";
8
- import withStyles from "@mui/styles/withStyles";
9
8
 
10
9
  const GenericSubMenu = ({
11
10
  menu,
@@ -72,8 +71,8 @@ const GenericSubMenu = ({
72
71
  setSubMenuOpen(Boolean(anchorSubMenu));
73
72
  }, [anchorSubMenu]);
74
73
  return /*#__PURE__*/React.createElement("div", {
75
- key: `main_sub_menu_items_${menu.name}`,
76
- className: !full_menu ? "flex flex-row w-full" : 'flex flex-col w-full'
74
+ key: `main_sub_menu_items_${menu.icon}`,
75
+ className: !full_menu ? "flex flex-row" : 'flex flex-col w-full'
77
76
  }, full_menu ? /*#__PURE__*/React.createElement(MenuItem, {
78
77
  onClick: openSubMenu
79
78
  }, menu.icon && /*#__PURE__*/React.createElement(ListItemIcon, null, menu.icon), /*#__PURE__*/React.createElement("div", {
@@ -19,11 +19,11 @@ const StyledMenu = withStyles({
19
19
  elevation: 0,
20
20
  anchorOrigin: {
21
21
  vertical: "bottom",
22
- horizontal: "center"
22
+ horizontal: props.menuAnchorLocation
23
23
  },
24
24
  transformOrigin: {
25
25
  vertical: "top",
26
- horizontal: "center"
26
+ horizontal: props.menuAnchorLocation
27
27
  }
28
28
  }, props)));
29
29
  const StyledMenuItem = withStyles(() => ({
@@ -41,17 +41,28 @@ const StyledMenuItem = withStyles(() => ({
41
41
  }
42
42
  }))(MenuItem);
43
43
 
44
+ const handleMenuOnClick = (menu, handleClose) => {
45
+ menu.onClick();
46
+
47
+ if (typeof menu.isChecked !== "boolean") {
48
+ //This is NOT a menu with a CheckState SO close the menu after the onclick.
49
+ handleClose();
50
+ }
51
+ };
52
+
44
53
  const ReusableMenu = props => {
45
54
  const {
46
55
  menuAnchor,
47
56
  handleClose,
48
57
  menuData,
49
58
  keepMounted,
50
- classes = undefined
59
+ classes = undefined,
60
+ menuAnchorLocation
51
61
  } = props;
52
62
  return /*#__PURE__*/React.createElement(StyledMenu, {
53
63
  id: "customized-menu",
54
64
  anchorEl: menuAnchor,
65
+ menuAnchorLocation: menuAnchorLocation,
55
66
  keepMounted: keepMounted,
56
67
  open: Boolean(menuAnchor),
57
68
  onClose: handleClose
@@ -69,7 +80,9 @@ const ReusableMenu = props => {
69
80
  onClose: handleClose
70
81
  })) : /*#__PURE__*/React.createElement(StyledMenuItem, {
71
82
  className: "w-full",
72
- onClick: menu.onClick,
83
+ onClick: () => {
84
+ handleMenuOnClick(menu, handleClose);
85
+ },
73
86
  key: `reusable_menu_item_${idx}`
74
87
  }, menu.icon && /*#__PURE__*/React.createElement(ListItemIcon, null, menu.icon), /*#__PURE__*/React.createElement(ListItemText, {
75
88
  primary: menu.name
@@ -90,12 +103,14 @@ ReusableMenu.defaultProps = {
90
103
  menuAnchor: undefined,
91
104
  handleClose: undefined,
92
105
  menuData: [],
93
- keepMounted: false
106
+ keepMounted: false,
107
+ menuAnchorLocation: 'center'
94
108
  }; // Type of
95
109
 
96
110
  ReusableMenu.propTypes = {
97
111
  menuAnchor: PropTypes.object,
98
112
  handleClose: PropTypes.func,
99
113
  menuData: PropTypes.array,
100
- keepMounted: PropTypes.bool
114
+ keepMounted: PropTypes.bool,
115
+ menuAnchorLocation: PropTypes.string
101
116
  };
@@ -23,6 +23,7 @@ export const ReusablePopupMenu = props => {
23
23
  menuData,
24
24
  tooltipTitle,
25
25
  keepMounted,
26
+ menuAnchorLocation,
26
27
  theme
27
28
  } = props;
28
29
  const [menuAnchor, setMenuAnchor] = useState(null);
@@ -40,7 +41,8 @@ export const ReusablePopupMenu = props => {
40
41
  menuAnchor,
41
42
  handleClose,
42
43
  menuData,
43
- keepMounted
44
+ keepMounted,
45
+ menuAnchorLocation
44
46
  };
45
47
  const childrenWithProps = Children.map(children, child => {
46
48
  // Checking isValidElement is the safe way and avoids a typescript
@@ -78,7 +80,8 @@ ReusableMenu.defaultProps = {
78
80
  tooltipTitle: '',
79
81
  menuData: [],
80
82
  keepMounted: false,
81
- theme: undefined
83
+ theme: undefined,
84
+ menuAnchorLocation: 'center'
82
85
  }; // Type of
83
86
 
84
87
  ReusableMenu.propTypes = {
@@ -90,5 +93,8 @@ ReusableMenu.propTypes = {
90
93
  /**
91
94
  * The theme object to apply to this object, if no theme provided then the component will used the default theme passed down by the ThemeProvider
92
95
  */
93
- theme: PropTypes.object
96
+ theme: PropTypes.object,
97
+
98
+ /** Controls the location of the dropdown popup menu */
99
+ menuAnchorLocation: PropTypes.oneOf(['left', 'center', 'right'])
94
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pcm-shared-components",
3
- "version": "0.0.136",
3
+ "version": "0.0.139",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "babel": {