@etsoo/materialui 1.1.96 → 1.1.97

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.
package/lib/FabBox.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { BoxProps } from '@mui/material';
2
+ import { BoxProps } from "@mui/material";
3
3
  /**
4
4
  * Fabs container box props
5
5
  */
package/lib/FabBox.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Box, useTheme } from '@mui/material';
2
- import React from 'react';
1
+ import { Box, useTheme } from "@mui/material";
2
+ import React from "react";
3
3
  /**
4
4
  * Fabs container box
5
5
  * @param props Props
@@ -7,7 +7,7 @@ import React from 'react';
7
7
  */
8
8
  export function FabBox(props) {
9
9
  // Destruct
10
- const { columnDirection, itemGap = 1, sx = {}, ...rest } = props;
10
+ const { columnDirection, itemGap = 1, sx, ...rest } = props;
11
11
  // Theme
12
12
  const theme = useTheme();
13
13
  const spaceGap = theme.spacing(itemGap);
@@ -17,15 +17,13 @@ export function FabBox(props) {
17
17
  const margin = columnDirection
18
18
  ? { marginTop: spaceGap }
19
19
  : { marginLeft: spaceGap };
20
- // Default style
21
- if (typeof sx === 'object') {
22
- Object.assign(sx, {
23
- position: 'fixed',
24
- display: 'flex',
25
- alignItems: 'center',
26
- flexDirection: columnDirection ? 'column' : 'row',
27
- '& > :not(style) + :not(style)': margin
28
- });
29
- }
30
- return React.createElement(Box, { sx: sx, ...rest });
20
+ return (React.createElement(Box, { sx: {
21
+ position: "fixed",
22
+ display: "flex",
23
+ alignItems: "center",
24
+ background: "rgba(255, 255, 255, .4)",
25
+ flexDirection: columnDirection ? "column" : "row",
26
+ "& > :not(style) + :not(style)": margin,
27
+ ...sx
28
+ }, ...rest }));
31
29
  }
@@ -0,0 +1,9 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import { ButtonProps, MenuProps } from "@mui/material";
3
+ import React from "react";
4
+ export type MenuButtonProps<T extends DataTypes.IdItem> = Omit<MenuProps, "open"> & {
5
+ items: T[];
6
+ labelField: DataTypes.Keys<T, string>;
7
+ button: ((clickHandler: React.MouseEventHandler<HTMLButtonElement>) => React.ReactNode) | ButtonProps;
8
+ };
9
+ export declare function MenuButton<T extends DataTypes.IdItem>(props: MenuButtonProps<T>): JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { Button, Menu, MenuItem } from "@mui/material";
2
+ import React from "react";
3
+ export function MenuButton(props) {
4
+ // Destruct
5
+ const { button, items, labelField, anchorOrigin = {
6
+ vertical: "top",
7
+ horizontal: "right"
8
+ }, transformOrigin = {
9
+ vertical: anchorOrigin.vertical === "center"
10
+ ? "center"
11
+ : anchorOrigin.vertical === "top"
12
+ ? "bottom"
13
+ : "top",
14
+ horizontal: anchorOrigin.horizontal
15
+ }, sx, ...rest } = props;
16
+ // Top?
17
+ const isTop = transformOrigin.vertical === "top";
18
+ // Menu anchor
19
+ const [anchorEl, setAnchorEl] = React.useState();
20
+ // Menu open or not
21
+ const isMenuOpen = Boolean(anchorEl);
22
+ const handleMenuOpen = (event) => {
23
+ setAnchorEl(event.currentTarget);
24
+ };
25
+ const handleMenuClose = () => {
26
+ setAnchorEl(undefined);
27
+ };
28
+ return (React.createElement(React.Fragment, null,
29
+ typeof button === "function" ? (button(handleMenuOpen)) : (React.createElement(Button, { onClick: handleMenuOpen, ...button })),
30
+ React.createElement(Menu, { PaperProps: {
31
+ elevation: 0,
32
+ sx: {
33
+ overflow: "visible",
34
+ filter: "drop-shadow(0px 2px 8px rgba(0,0,0,0.32))",
35
+ "& .MuiAvatar-root": {
36
+ width: 32,
37
+ height: 32
38
+ },
39
+ "&:before": {
40
+ content: '""',
41
+ display: "block",
42
+ position: "absolute",
43
+ top: isTop ? 0 : undefined,
44
+ bottom: isTop ? undefined : -10,
45
+ right: 14,
46
+ width: 10,
47
+ height: 10,
48
+ bgcolor: "background.paper",
49
+ transform: "translateY(-50%) rotate(45deg)",
50
+ zIndex: 0
51
+ },
52
+ ...{ sx }
53
+ }
54
+ }, disableScrollLock: true, anchorEl: anchorEl, anchorOrigin: anchorOrigin, keepMounted: true, transformOrigin: transformOrigin, open: isMenuOpen, transitionDuration: 0, onClose: handleMenuClose, ...rest }, items.map((item) => {
55
+ const label = item[labelField];
56
+ return (React.createElement(MenuItem, { key: item.id, disabled: true }, label));
57
+ }))));
58
+ }
@@ -13,8 +13,9 @@ export type ResponsibleContainerProps<T extends object, F extends DataTypes.Basi
13
13
  * Height will be deducted
14
14
  * @param height Current calcuated height
15
15
  * @param rect Current rect data
16
+ * @param isGrid Is displaying DataGrid
16
17
  */
17
- adjustHeight?: (height: number, rect: DOMRect) => number;
18
+ adjustHeight?: (height: number, rect: DOMRect, isGrid: boolean) => number;
18
19
  /**
19
20
  * Columns
20
21
  */
@@ -95,7 +95,7 @@ export function ResponsibleContainer(props) {
95
95
  if (!isNaN(boxMargin))
96
96
  heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
97
97
  if (adjustHeight != null)
98
- heightLocal -= adjustHeight(heightLocal, rect);
98
+ heightLocal -= adjustHeight(heightLocal, rect, showDataGrid);
99
99
  }
100
100
  if (showDataGrid) {
101
101
  // Delete
package/lib/index.d.ts CHANGED
@@ -61,6 +61,7 @@ export * from "./ListItemRightIcon";
61
61
  export * from "./ListMoreDisplay";
62
62
  export * from "./LoadingButton";
63
63
  export * from "./MaskInput";
64
+ export * from "./MenuButton";
64
65
  export * from "./MobileListItemRenderer";
65
66
  export * from "./MoneyInputField";
66
67
  export * from "./MoreFab";
package/lib/index.js CHANGED
@@ -61,6 +61,7 @@ export * from "./ListItemRightIcon";
61
61
  export * from "./ListMoreDisplay";
62
62
  export * from "./LoadingButton";
63
63
  export * from "./MaskInput";
64
+ export * from "./MenuButton";
64
65
  export * from "./MobileListItemRenderer";
65
66
  export * from "./MoneyInputField";
66
67
  export * from "./MoreFab";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.96",
3
+ "version": "1.1.97",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/FabBox.tsx CHANGED
@@ -1,19 +1,19 @@
1
- import { Box, BoxProps, useTheme } from '@mui/material';
2
- import React from 'react';
1
+ import { Box, BoxProps, useTheme } from "@mui/material";
2
+ import React from "react";
3
3
 
4
4
  /**
5
5
  * Fabs container box props
6
6
  */
7
7
  export type FabBoxProps = BoxProps & {
8
- /**
9
- * Item gap
10
- */
11
- itemGap?: number;
12
-
13
- /**
14
- * Flex direction, row or column
15
- */
16
- columnDirection?: boolean;
8
+ /**
9
+ * Item gap
10
+ */
11
+ itemGap?: number;
12
+
13
+ /**
14
+ * Flex direction, row or column
15
+ */
16
+ columnDirection?: boolean;
17
17
  };
18
18
 
19
19
  /**
@@ -22,30 +22,32 @@ export type FabBoxProps = BoxProps & {
22
22
  * @returns Component
23
23
  */
24
24
  export function FabBox(props: FabBoxProps) {
25
- // Destruct
26
- const { columnDirection, itemGap = 1, sx = {}, ...rest } = props;
27
-
28
- // Theme
29
- const theme = useTheme();
30
- const spaceGap = theme.spacing(itemGap);
31
-
32
- if (columnDirection == null) return <React.Fragment />;
33
-
34
- // margin
35
- const margin = columnDirection
36
- ? { marginTop: spaceGap }
37
- : { marginLeft: spaceGap };
38
-
39
- // Default style
40
- if (typeof sx === 'object') {
41
- Object.assign(sx as any, {
42
- position: 'fixed',
43
- display: 'flex',
44
- alignItems: 'center',
45
- flexDirection: columnDirection ? 'column' : 'row',
46
- '& > :not(style) + :not(style)': margin
47
- });
48
- }
49
-
50
- return <Box sx={sx} {...rest} />;
25
+ // Destruct
26
+ const { columnDirection, itemGap = 1, sx, ...rest } = props;
27
+
28
+ // Theme
29
+ const theme = useTheme();
30
+ const spaceGap = theme.spacing(itemGap);
31
+
32
+ if (columnDirection == null) return <React.Fragment />;
33
+
34
+ // margin
35
+ const margin = columnDirection
36
+ ? { marginTop: spaceGap }
37
+ : { marginLeft: spaceGap };
38
+
39
+ return (
40
+ <Box
41
+ sx={{
42
+ position: "fixed",
43
+ display: "flex",
44
+ alignItems: "center",
45
+ background: "rgba(255, 255, 255, .4)",
46
+ flexDirection: columnDirection ? "column" : "row",
47
+ "& > :not(style) + :not(style)": margin,
48
+ ...sx
49
+ }}
50
+ {...rest}
51
+ />
52
+ );
51
53
  }
@@ -0,0 +1,115 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import { Button, ButtonProps, Menu, MenuItem, MenuProps } from "@mui/material";
3
+ import React from "react";
4
+
5
+ export type MenuButtonProps<T extends DataTypes.IdItem> = Omit<
6
+ MenuProps,
7
+ "open"
8
+ > & {
9
+ items: T[];
10
+ labelField: DataTypes.Keys<T, string>;
11
+ button:
12
+ | ((
13
+ clickHandler: React.MouseEventHandler<HTMLButtonElement>
14
+ ) => React.ReactNode)
15
+ | ButtonProps;
16
+ };
17
+
18
+ export function MenuButton<T extends DataTypes.IdItem>(
19
+ props: MenuButtonProps<T>
20
+ ) {
21
+ // Destruct
22
+ const {
23
+ button,
24
+ items,
25
+ labelField,
26
+ anchorOrigin = {
27
+ vertical: "top",
28
+ horizontal: "right"
29
+ },
30
+ transformOrigin = {
31
+ vertical:
32
+ anchorOrigin.vertical === "center"
33
+ ? "center"
34
+ : anchorOrigin.vertical === "top"
35
+ ? "bottom"
36
+ : "top",
37
+ horizontal: anchorOrigin.horizontal
38
+ },
39
+ sx,
40
+ ...rest
41
+ } = props;
42
+
43
+ // Top?
44
+ const isTop = transformOrigin.vertical === "top";
45
+
46
+ // Menu anchor
47
+ const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement>();
48
+
49
+ // Menu open or not
50
+ const isMenuOpen = Boolean(anchorEl);
51
+
52
+ const handleMenuOpen = (event: React.MouseEvent<HTMLButtonElement>) => {
53
+ setAnchorEl(event.currentTarget);
54
+ };
55
+
56
+ const handleMenuClose = () => {
57
+ setAnchorEl(undefined);
58
+ };
59
+
60
+ return (
61
+ <React.Fragment>
62
+ {typeof button === "function" ? (
63
+ button(handleMenuOpen)
64
+ ) : (
65
+ <Button onClick={handleMenuOpen} {...button} />
66
+ )}
67
+
68
+ <Menu
69
+ PaperProps={{
70
+ elevation: 0,
71
+ sx: {
72
+ overflow: "visible",
73
+ filter: "drop-shadow(0px 2px 8px rgba(0,0,0,0.32))",
74
+ "& .MuiAvatar-root": {
75
+ width: 32,
76
+ height: 32
77
+ },
78
+ "&:before": {
79
+ content: '""',
80
+ display: "block",
81
+ position: "absolute",
82
+ top: isTop ? 0 : undefined,
83
+ bottom: isTop ? undefined : -10,
84
+ right: 14,
85
+ width: 10,
86
+ height: 10,
87
+ bgcolor: "background.paper",
88
+ transform: "translateY(-50%) rotate(45deg)",
89
+ zIndex: 0
90
+ },
91
+ ...{ sx }
92
+ }
93
+ }}
94
+ disableScrollLock
95
+ anchorEl={anchorEl}
96
+ anchorOrigin={anchorOrigin}
97
+ keepMounted
98
+ transformOrigin={transformOrigin}
99
+ open={isMenuOpen}
100
+ transitionDuration={0}
101
+ onClose={handleMenuClose}
102
+ {...rest}
103
+ >
104
+ {items.map((item) => {
105
+ const label = item[labelField] as string;
106
+ return (
107
+ <MenuItem key={item.id} disabled>
108
+ {label}
109
+ </MenuItem>
110
+ );
111
+ })}
112
+ </Menu>
113
+ </React.Fragment>
114
+ );
115
+ }
@@ -42,8 +42,9 @@ export type ResponsibleContainerProps<
42
42
  * Height will be deducted
43
43
  * @param height Current calcuated height
44
44
  * @param rect Current rect data
45
+ * @param isGrid Is displaying DataGrid
45
46
  */
46
- adjustHeight?: (height: number, rect: DOMRect) => number;
47
+ adjustHeight?: (height: number, rect: DOMRect, isGrid: boolean) => number;
47
48
 
48
49
  /**
49
50
  * Columns
@@ -278,7 +279,8 @@ export function ResponsibleContainer<
278
279
  const boxMargin = parseFloat(style.marginBottom);
279
280
  if (!isNaN(boxMargin)) heightLocal -= 3 * boxMargin; // 1 - Box, 2 - Page bottom
280
281
 
281
- if (adjustHeight != null) heightLocal -= adjustHeight(heightLocal, rect);
282
+ if (adjustHeight != null)
283
+ heightLocal -= adjustHeight(heightLocal, rect, showDataGrid);
282
284
  }
283
285
 
284
286
  if (showDataGrid) {
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ export * from "./ListItemRightIcon";
64
64
  export * from "./ListMoreDisplay";
65
65
  export * from "./LoadingButton";
66
66
  export * from "./MaskInput";
67
+ export * from "./MenuButton";
67
68
  export * from "./MobileListItemRenderer";
68
69
  export * from "./MoneyInputField";
69
70
  export * from "./MoreFab";