@etsoo/materialui 1.6.54 → 1.6.56
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/cjs/ButtonList.d.ts +46 -0
- package/lib/cjs/ButtonList.js +100 -0
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/ButtonList.d.ts +46 -0
- package/lib/mjs/ButtonList.js +61 -0
- package/lib/mjs/index.d.ts +2 -1
- package/lib/mjs/index.js +1 -0
- package/package.json +4 -4
- package/src/ButtonList.tsx +170 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ButtonGroupProps } from "@mui/material/ButtonGroup";
|
|
3
|
+
/**
|
|
4
|
+
* Button list item
|
|
5
|
+
*/
|
|
6
|
+
export type ButtonListItem = {
|
|
7
|
+
/**
|
|
8
|
+
* Label, '-' for divider
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/**
|
|
12
|
+
* Icon
|
|
13
|
+
*/
|
|
14
|
+
icon?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Click action
|
|
17
|
+
*/
|
|
18
|
+
action?: (item: ButtonListItem, index: number) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Button list props
|
|
22
|
+
*/
|
|
23
|
+
export type ButtonListProps = Omit<ButtonGroupProps, "ref"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Check if button is disabled
|
|
26
|
+
* @param index Button index
|
|
27
|
+
* @returns Result
|
|
28
|
+
*/
|
|
29
|
+
checkDisable?: (index: number) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Button items
|
|
32
|
+
*/
|
|
33
|
+
items: ButtonListItem[];
|
|
34
|
+
/**
|
|
35
|
+
* Click button handler
|
|
36
|
+
* @param event Click event
|
|
37
|
+
* @param index Current button index
|
|
38
|
+
*/
|
|
39
|
+
onItemClick?: (event: React.MouseEvent, index: number) => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Dropdown button list
|
|
43
|
+
* @param props Props
|
|
44
|
+
* @returns Component
|
|
45
|
+
*/
|
|
46
|
+
export declare function ButtonList(props: ButtonListProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ButtonList = ButtonList;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
43
|
+
const ButtonGroup_1 = __importDefault(require("@mui/material/ButtonGroup"));
|
|
44
|
+
const ArrowDropDown_1 = __importDefault(require("@mui/icons-material/ArrowDropDown"));
|
|
45
|
+
const ClickAwayListener_1 = __importDefault(require("@mui/material/ClickAwayListener"));
|
|
46
|
+
const Grow_1 = __importDefault(require("@mui/material/Grow"));
|
|
47
|
+
const Paper_1 = __importDefault(require("@mui/material/Paper"));
|
|
48
|
+
const Popper_1 = __importDefault(require("@mui/material/Popper"));
|
|
49
|
+
const MenuItem_1 = __importDefault(require("@mui/material/MenuItem"));
|
|
50
|
+
const MenuList_1 = __importDefault(require("@mui/material/MenuList"));
|
|
51
|
+
const ListItemIcon_1 = __importDefault(require("@mui/material/ListItemIcon"));
|
|
52
|
+
const Divider_1 = __importDefault(require("@mui/material/Divider"));
|
|
53
|
+
/**
|
|
54
|
+
* Dropdown button list
|
|
55
|
+
* @param props Props
|
|
56
|
+
* @returns Component
|
|
57
|
+
*/
|
|
58
|
+
function ButtonList(props) {
|
|
59
|
+
// Destruct
|
|
60
|
+
const { checkDisable, items, onItemClick, ...buttonGroupProps } = props;
|
|
61
|
+
const [open, setOpen] = React.useState(false);
|
|
62
|
+
const anchorRef = React.useRef(null);
|
|
63
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
64
|
+
const handleClick = (event) => {
|
|
65
|
+
handleClickEvent(event, selectedIndex);
|
|
66
|
+
};
|
|
67
|
+
const handleClickEvent = (event, index) => {
|
|
68
|
+
onItemClick?.(event, index);
|
|
69
|
+
if (!event.isDefaultPrevented()) {
|
|
70
|
+
const item = items[index];
|
|
71
|
+
item.action?.(item, index);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const handleMenuItemClick = (event, index) => {
|
|
75
|
+
setSelectedIndex(index);
|
|
76
|
+
setOpen(false);
|
|
77
|
+
handleClickEvent(event, index);
|
|
78
|
+
};
|
|
79
|
+
const handleToggle = () => {
|
|
80
|
+
setOpen((prevOpen) => !prevOpen);
|
|
81
|
+
};
|
|
82
|
+
const handleClose = (event) => {
|
|
83
|
+
if (anchorRef.current &&
|
|
84
|
+
anchorRef.current.contains(event.target)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setOpen(false);
|
|
88
|
+
};
|
|
89
|
+
return ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [(0, jsx_runtime_1.jsxs)(ButtonGroup_1.default, { ref: anchorRef, ...buttonGroupProps, children: [(0, jsx_runtime_1.jsx)(Button_1.default, { onClick: (event) => handleClick(event), startIcon: items[selectedIndex].icon, children: items[selectedIndex].label }), (0, jsx_runtime_1.jsx)(Button_1.default, { size: "small", onClick: handleToggle, children: (0, jsx_runtime_1.jsx)(ArrowDropDown_1.default, {}) })] }), (0, jsx_runtime_1.jsx)(Popper_1.default, { sx: { zIndex: 1 }, open: open, anchorEl: anchorRef.current, transition: true, disablePortal: true, children: ({ TransitionProps, placement }) => ((0, jsx_runtime_1.jsx)(Grow_1.default, { ...TransitionProps, style: {
|
|
90
|
+
transformOrigin: placement === "bottom" ? "center top" : "center bottom"
|
|
91
|
+
}, children: (0, jsx_runtime_1.jsx)(Paper_1.default, { children: (0, jsx_runtime_1.jsx)(ClickAwayListener_1.default, { onClickAway: handleClose, children: (0, jsx_runtime_1.jsx)(MenuList_1.default, { autoFocusItem: true, children: items.map((item, index) => {
|
|
92
|
+
const label = item.label;
|
|
93
|
+
if (label === "-") {
|
|
94
|
+
return (0, jsx_runtime_1.jsx)(Divider_1.default, {}, index);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return ((0, jsx_runtime_1.jsxs)(MenuItem_1.default, { disabled: checkDisable?.(index) ?? false, selected: index === selectedIndex, onClick: (event) => handleMenuItemClick(event, index), children: [item.icon && ((0, jsx_runtime_1.jsx)(ListItemIcon_1.default, { children: item.icon })), item.label] }, label));
|
|
98
|
+
}
|
|
99
|
+
}) }) }) }) })) })] }));
|
|
100
|
+
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./AutocompleteExtendedProps";
|
|
|
41
41
|
export * from "./BackButton";
|
|
42
42
|
export * from "./BridgeCloseButton";
|
|
43
43
|
export * from "./ButtonLink";
|
|
44
|
+
export * from "./ButtonList";
|
|
44
45
|
export * from "./ButtonPopover";
|
|
45
46
|
export * from "./ButtonPopupCheckbox";
|
|
46
47
|
export * from "./ButtonPopupRadio";
|
|
@@ -135,4 +136,4 @@ export * from "./UserAvatar";
|
|
|
135
136
|
export * from "./UserAvatarEditor";
|
|
136
137
|
export * from "./ViewContainer";
|
|
137
138
|
export { default as AccountTreeIcon } from "@mui/icons-material/AccountTree";
|
|
138
|
-
export { DataGrid, Toolbar, ToolbarButton, useGridApiContext, useGridApiRef, useGridSelector, type GridColDef, type GridSlots } from "@mui/x-data-grid";
|
|
139
|
+
export { DataGrid, Toolbar, ToolbarButton, useGridApiContext, useGridApiRef, useGridSelector, type GridColDef, type GridRowId, type GridSlots } from "@mui/x-data-grid";
|
package/lib/cjs/index.js
CHANGED
|
@@ -61,6 +61,7 @@ __exportStar(require("./AutocompleteExtendedProps"), exports);
|
|
|
61
61
|
__exportStar(require("./BackButton"), exports);
|
|
62
62
|
__exportStar(require("./BridgeCloseButton"), exports);
|
|
63
63
|
__exportStar(require("./ButtonLink"), exports);
|
|
64
|
+
__exportStar(require("./ButtonList"), exports);
|
|
64
65
|
__exportStar(require("./ButtonPopover"), exports);
|
|
65
66
|
__exportStar(require("./ButtonPopupCheckbox"), exports);
|
|
66
67
|
__exportStar(require("./ButtonPopupRadio"), exports);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ButtonGroupProps } from "@mui/material/ButtonGroup";
|
|
3
|
+
/**
|
|
4
|
+
* Button list item
|
|
5
|
+
*/
|
|
6
|
+
export type ButtonListItem = {
|
|
7
|
+
/**
|
|
8
|
+
* Label, '-' for divider
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/**
|
|
12
|
+
* Icon
|
|
13
|
+
*/
|
|
14
|
+
icon?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Click action
|
|
17
|
+
*/
|
|
18
|
+
action?: (item: ButtonListItem, index: number) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Button list props
|
|
22
|
+
*/
|
|
23
|
+
export type ButtonListProps = Omit<ButtonGroupProps, "ref"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Check if button is disabled
|
|
26
|
+
* @param index Button index
|
|
27
|
+
* @returns Result
|
|
28
|
+
*/
|
|
29
|
+
checkDisable?: (index: number) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Button items
|
|
32
|
+
*/
|
|
33
|
+
items: ButtonListItem[];
|
|
34
|
+
/**
|
|
35
|
+
* Click button handler
|
|
36
|
+
* @param event Click event
|
|
37
|
+
* @param index Current button index
|
|
38
|
+
*/
|
|
39
|
+
onItemClick?: (event: React.MouseEvent, index: number) => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Dropdown button list
|
|
43
|
+
* @param props Props
|
|
44
|
+
* @returns Component
|
|
45
|
+
*/
|
|
46
|
+
export declare function ButtonList(props: ButtonListProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import Button from "@mui/material/Button";
|
|
4
|
+
import ButtonGroup from "@mui/material/ButtonGroup";
|
|
5
|
+
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
|
|
6
|
+
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
|
7
|
+
import Grow from "@mui/material/Grow";
|
|
8
|
+
import Paper from "@mui/material/Paper";
|
|
9
|
+
import Popper from "@mui/material/Popper";
|
|
10
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
11
|
+
import MenuList from "@mui/material/MenuList";
|
|
12
|
+
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
13
|
+
import Divider from "@mui/material/Divider";
|
|
14
|
+
/**
|
|
15
|
+
* Dropdown button list
|
|
16
|
+
* @param props Props
|
|
17
|
+
* @returns Component
|
|
18
|
+
*/
|
|
19
|
+
export function ButtonList(props) {
|
|
20
|
+
// Destruct
|
|
21
|
+
const { checkDisable, items, onItemClick, ...buttonGroupProps } = props;
|
|
22
|
+
const [open, setOpen] = React.useState(false);
|
|
23
|
+
const anchorRef = React.useRef(null);
|
|
24
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
25
|
+
const handleClick = (event) => {
|
|
26
|
+
handleClickEvent(event, selectedIndex);
|
|
27
|
+
};
|
|
28
|
+
const handleClickEvent = (event, index) => {
|
|
29
|
+
onItemClick?.(event, index);
|
|
30
|
+
if (!event.isDefaultPrevented()) {
|
|
31
|
+
const item = items[index];
|
|
32
|
+
item.action?.(item, index);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const handleMenuItemClick = (event, index) => {
|
|
36
|
+
setSelectedIndex(index);
|
|
37
|
+
setOpen(false);
|
|
38
|
+
handleClickEvent(event, index);
|
|
39
|
+
};
|
|
40
|
+
const handleToggle = () => {
|
|
41
|
+
setOpen((prevOpen) => !prevOpen);
|
|
42
|
+
};
|
|
43
|
+
const handleClose = (event) => {
|
|
44
|
+
if (anchorRef.current &&
|
|
45
|
+
anchorRef.current.contains(event.target)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setOpen(false);
|
|
49
|
+
};
|
|
50
|
+
return (_jsxs(React.Fragment, { children: [_jsxs(ButtonGroup, { ref: anchorRef, ...buttonGroupProps, children: [_jsx(Button, { onClick: (event) => handleClick(event), startIcon: items[selectedIndex].icon, children: items[selectedIndex].label }), _jsx(Button, { size: "small", onClick: handleToggle, children: _jsx(ArrowDropDownIcon, {}) })] }), _jsx(Popper, { sx: { zIndex: 1 }, open: open, anchorEl: anchorRef.current, transition: true, disablePortal: true, children: ({ TransitionProps, placement }) => (_jsx(Grow, { ...TransitionProps, style: {
|
|
51
|
+
transformOrigin: placement === "bottom" ? "center top" : "center bottom"
|
|
52
|
+
}, children: _jsx(Paper, { children: _jsx(ClickAwayListener, { onClickAway: handleClose, children: _jsx(MenuList, { autoFocusItem: true, children: items.map((item, index) => {
|
|
53
|
+
const label = item.label;
|
|
54
|
+
if (label === "-") {
|
|
55
|
+
return _jsx(Divider, {}, index);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return (_jsxs(MenuItem, { disabled: checkDisable?.(index) ?? false, selected: index === selectedIndex, onClick: (event) => handleMenuItemClick(event, index), children: [item.icon && (_jsx(ListItemIcon, { children: item.icon })), item.label] }, label));
|
|
59
|
+
}
|
|
60
|
+
}) }) }) }) })) })] }));
|
|
61
|
+
}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./AutocompleteExtendedProps";
|
|
|
41
41
|
export * from "./BackButton";
|
|
42
42
|
export * from "./BridgeCloseButton";
|
|
43
43
|
export * from "./ButtonLink";
|
|
44
|
+
export * from "./ButtonList";
|
|
44
45
|
export * from "./ButtonPopover";
|
|
45
46
|
export * from "./ButtonPopupCheckbox";
|
|
46
47
|
export * from "./ButtonPopupRadio";
|
|
@@ -135,4 +136,4 @@ export * from "./UserAvatar";
|
|
|
135
136
|
export * from "./UserAvatarEditor";
|
|
136
137
|
export * from "./ViewContainer";
|
|
137
138
|
export { default as AccountTreeIcon } from "@mui/icons-material/AccountTree";
|
|
138
|
-
export { DataGrid, Toolbar, ToolbarButton, useGridApiContext, useGridApiRef, useGridSelector, type GridColDef, type GridSlots } from "@mui/x-data-grid";
|
|
139
|
+
export { DataGrid, Toolbar, ToolbarButton, useGridApiContext, useGridApiRef, useGridSelector, type GridColDef, type GridRowId, type GridSlots } from "@mui/x-data-grid";
|
package/lib/mjs/index.js
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./AutocompleteExtendedProps";
|
|
|
41
41
|
export * from "./BackButton";
|
|
42
42
|
export * from "./BridgeCloseButton";
|
|
43
43
|
export * from "./ButtonLink";
|
|
44
|
+
export * from "./ButtonList";
|
|
44
45
|
export * from "./ButtonPopover";
|
|
45
46
|
export * from "./ButtonPopupCheckbox";
|
|
46
47
|
export * from "./ButtonPopupRadio";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.56",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@mui/x-data-grid": "^9.1.0",
|
|
50
50
|
"chart.js": "^4.5.1",
|
|
51
51
|
"chartjs-plugin-datalabels": "^2.2.0",
|
|
52
|
-
"dompurify": "^3.4.
|
|
52
|
+
"dompurify": "^3.4.3",
|
|
53
53
|
"eventemitter3": "^5.0.4",
|
|
54
54
|
"pica": "^9.0.1",
|
|
55
55
|
"pulltorefreshjs": "^0.1.22",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"@types/react-avatar-editor": "^13.0.4",
|
|
80
80
|
"@types/react-dom": "^19.2.3",
|
|
81
81
|
"@types/react-input-mask": "^3.0.6",
|
|
82
|
-
"@vitejs/plugin-react": "^6.0.
|
|
82
|
+
"@vitejs/plugin-react": "^6.0.2",
|
|
83
83
|
"jsdom": "^29.1.1",
|
|
84
84
|
"typescript": "^6.0.3",
|
|
85
|
-
"vitest": "^4.1.
|
|
85
|
+
"vitest": "^4.1.6"
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Button from "@mui/material/Button";
|
|
3
|
+
import ButtonGroup, { ButtonGroupProps } from "@mui/material/ButtonGroup";
|
|
4
|
+
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
|
|
5
|
+
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
|
6
|
+
import Grow from "@mui/material/Grow";
|
|
7
|
+
import Paper from "@mui/material/Paper";
|
|
8
|
+
import Popper from "@mui/material/Popper";
|
|
9
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
10
|
+
import MenuList from "@mui/material/MenuList";
|
|
11
|
+
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
12
|
+
import Divider from "@mui/material/Divider";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Button list item
|
|
16
|
+
*/
|
|
17
|
+
export type ButtonListItem = {
|
|
18
|
+
/**
|
|
19
|
+
* Label, '-' for divider
|
|
20
|
+
*/
|
|
21
|
+
label: string;
|
|
22
|
+
/**
|
|
23
|
+
* Icon
|
|
24
|
+
*/
|
|
25
|
+
icon?: React.ReactNode;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Click action
|
|
29
|
+
*/
|
|
30
|
+
action?: (item: ButtonListItem, index: number) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Button list props
|
|
35
|
+
*/
|
|
36
|
+
export type ButtonListProps = Omit<ButtonGroupProps, "ref"> & {
|
|
37
|
+
/**
|
|
38
|
+
* Check if button is disabled
|
|
39
|
+
* @param index Button index
|
|
40
|
+
* @returns Result
|
|
41
|
+
*/
|
|
42
|
+
checkDisable?: (index: number) => boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Button items
|
|
46
|
+
*/
|
|
47
|
+
items: ButtonListItem[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Click button handler
|
|
51
|
+
* @param event Click event
|
|
52
|
+
* @param index Current button index
|
|
53
|
+
*/
|
|
54
|
+
onItemClick?: (event: React.MouseEvent, index: number) => void;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Dropdown button list
|
|
59
|
+
* @param props Props
|
|
60
|
+
* @returns Component
|
|
61
|
+
*/
|
|
62
|
+
export function ButtonList(props: ButtonListProps) {
|
|
63
|
+
// Destruct
|
|
64
|
+
const { checkDisable, items, onItemClick, ...buttonGroupProps } = props;
|
|
65
|
+
|
|
66
|
+
const [open, setOpen] = React.useState(false);
|
|
67
|
+
const anchorRef = React.useRef<HTMLDivElement>(null);
|
|
68
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
69
|
+
|
|
70
|
+
const handleClick = (
|
|
71
|
+
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
72
|
+
) => {
|
|
73
|
+
handleClickEvent(event, selectedIndex);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleClickEvent = (event: React.MouseEvent, index: number) => {
|
|
77
|
+
onItemClick?.(event, index);
|
|
78
|
+
|
|
79
|
+
if (!event.isDefaultPrevented()) {
|
|
80
|
+
const item = items[index];
|
|
81
|
+
item.action?.(item, index);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleMenuItemClick = (
|
|
86
|
+
event: React.MouseEvent<HTMLLIElement, MouseEvent>,
|
|
87
|
+
index: number
|
|
88
|
+
) => {
|
|
89
|
+
setSelectedIndex(index);
|
|
90
|
+
setOpen(false);
|
|
91
|
+
|
|
92
|
+
handleClickEvent(event, index);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handleToggle = () => {
|
|
96
|
+
setOpen((prevOpen) => !prevOpen);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const handleClose = (event: Event) => {
|
|
100
|
+
if (
|
|
101
|
+
anchorRef.current &&
|
|
102
|
+
anchorRef.current.contains(event.target as HTMLElement)
|
|
103
|
+
) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setOpen(false);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<React.Fragment>
|
|
112
|
+
<ButtonGroup ref={anchorRef} {...buttonGroupProps}>
|
|
113
|
+
<Button
|
|
114
|
+
onClick={(event) => handleClick(event)}
|
|
115
|
+
startIcon={items[selectedIndex].icon}
|
|
116
|
+
>
|
|
117
|
+
{items[selectedIndex].label}
|
|
118
|
+
</Button>
|
|
119
|
+
<Button size="small" onClick={handleToggle}>
|
|
120
|
+
<ArrowDropDownIcon />
|
|
121
|
+
</Button>
|
|
122
|
+
</ButtonGroup>
|
|
123
|
+
<Popper
|
|
124
|
+
sx={{ zIndex: 1 }}
|
|
125
|
+
open={open}
|
|
126
|
+
anchorEl={anchorRef.current}
|
|
127
|
+
transition
|
|
128
|
+
disablePortal
|
|
129
|
+
>
|
|
130
|
+
{({ TransitionProps, placement }) => (
|
|
131
|
+
<Grow
|
|
132
|
+
{...TransitionProps}
|
|
133
|
+
style={{
|
|
134
|
+
transformOrigin:
|
|
135
|
+
placement === "bottom" ? "center top" : "center bottom"
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<Paper>
|
|
139
|
+
<ClickAwayListener onClickAway={handleClose}>
|
|
140
|
+
<MenuList autoFocusItem>
|
|
141
|
+
{items.map((item, index) => {
|
|
142
|
+
const label = item.label;
|
|
143
|
+
|
|
144
|
+
if (label === "-") {
|
|
145
|
+
return <Divider key={index} />;
|
|
146
|
+
} else {
|
|
147
|
+
return (
|
|
148
|
+
<MenuItem
|
|
149
|
+
key={label}
|
|
150
|
+
disabled={checkDisable?.(index) ?? false}
|
|
151
|
+
selected={index === selectedIndex}
|
|
152
|
+
onClick={(event) => handleMenuItemClick(event, index)}
|
|
153
|
+
>
|
|
154
|
+
{item.icon && (
|
|
155
|
+
<ListItemIcon>{item.icon}</ListItemIcon>
|
|
156
|
+
)}
|
|
157
|
+
{item.label}
|
|
158
|
+
</MenuItem>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
})}
|
|
162
|
+
</MenuList>
|
|
163
|
+
</ClickAwayListener>
|
|
164
|
+
</Paper>
|
|
165
|
+
</Grow>
|
|
166
|
+
)}
|
|
167
|
+
</Popper>
|
|
168
|
+
</React.Fragment>
|
|
169
|
+
);
|
|
170
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -47,6 +47,7 @@ export * from "./AutocompleteExtendedProps";
|
|
|
47
47
|
export * from "./BackButton";
|
|
48
48
|
export * from "./BridgeCloseButton";
|
|
49
49
|
export * from "./ButtonLink";
|
|
50
|
+
export * from "./ButtonList";
|
|
50
51
|
export * from "./ButtonPopover";
|
|
51
52
|
export * from "./ButtonPopupCheckbox";
|
|
52
53
|
export * from "./ButtonPopupRadio";
|
|
@@ -153,5 +154,6 @@ export {
|
|
|
153
154
|
useGridApiRef,
|
|
154
155
|
useGridSelector,
|
|
155
156
|
type GridColDef,
|
|
157
|
+
type GridRowId,
|
|
156
158
|
type GridSlots
|
|
157
159
|
} from "@mui/x-data-grid";
|