@campxdev/shared 1.2.8 → 1.3.0

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.
@@ -1,194 +0,0 @@
1
- import { KeyboardArrowDown, MoreVert } from '@mui/icons-material'
2
- import {
3
- Box,
4
- Button,
5
- ButtonProps,
6
- CircularProgress,
7
- IconButton,
8
- IconButtonProps,
9
- ListItemIcon,
10
- ListItemText,
11
- Menu,
12
- MenuItem,
13
- MenuListProps,
14
- MenuProps,
15
- styled,
16
- } from '@mui/material'
17
- import { ReactNode, useState } from 'react'
18
-
19
- type MenuItem =
20
- | {
21
- label: string | ReactNode
22
- icon?: ReactNode
23
- onClick: (props?: any) => any
24
- }
25
- | { customButton?: ReactNode }
26
-
27
- interface Props {
28
- label?: string
29
- icon?: {
30
- icon: ReactNode
31
- iconProps?: IconButtonProps
32
- outlined?: boolean
33
- }
34
- loading?: boolean
35
- menu: MenuItem[]
36
- buttonProps?: ButtonProps
37
- menuProps?: Omit<MenuProps, 'open'>
38
- menuListProps?: MenuListProps
39
- renderMenuItems?: Array<ReactNode>
40
- }
41
- const defaultIcon = {
42
- icon: <MoreVert color="primary" />,
43
- outlined: true,
44
- }
45
-
46
- export default function DropDownButton({
47
- label,
48
- icon = defaultIcon,
49
- menu = [],
50
- buttonProps,
51
- menuProps,
52
- menuListProps,
53
- loading = false,
54
- renderMenuItems = [],
55
- }: Props) {
56
- const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
57
- const open = Boolean(anchorEl)
58
-
59
- const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
60
- setAnchorEl(event.currentTarget)
61
- }
62
-
63
- const handleClose = () => {
64
- setAnchorEl(null)
65
- }
66
-
67
- return (
68
- <>
69
- {!label ? (
70
- <StyledIconButton
71
- outlined={icon?.outlined ?? false}
72
- onClick={handleClick}
73
- {...icon.iconProps}
74
- >
75
- {icon.icon}
76
- </StyledIconButton>
77
- ) : (
78
- <StyledDropDownButton
79
- onClick={handleClick}
80
- disabled={loading}
81
- endIcon={
82
- loading ? (
83
- <CircularProgress size="20px" thickness={1.7} />
84
- ) : (
85
- <KeyboardArrowDown />
86
- )
87
- }
88
- {...buttonProps}
89
- >
90
- {label}
91
- </StyledDropDownButton>
92
- )}
93
- <Menu
94
- elevation={3}
95
- id="basic-menu"
96
- anchorEl={anchorEl}
97
- open={open}
98
- onClose={handleClose}
99
- MenuListProps={{ sx: { padding: 0 }, ...menuListProps }}
100
- anchorOrigin={{
101
- vertical: 'bottom',
102
- horizontal: 'right',
103
- }}
104
- transformOrigin={{
105
- vertical: 'top',
106
- horizontal: 'right',
107
- }}
108
- {...menuProps}
109
- >
110
- <RenderMenuItems
111
- menu={menu}
112
- renderMenuItems={renderMenuItems}
113
- handleClose={handleClose}
114
- />
115
- </Menu>
116
- </>
117
- )
118
- }
119
-
120
- const RenderMenuItems = ({ renderMenuItems, menu, handleClose }) => {
121
- if (renderMenuItems?.length) {
122
- return (
123
- <>
124
- {renderMenuItems.map((Item, index) => (
125
- <StyledMenuItem
126
- disableRipple
127
- sx={{
128
- minWidth: '120px',
129
- width: '100%',
130
- padding: 0,
131
- '&:hover': { background: 'none' },
132
- }}
133
- key={index}
134
- >
135
- {Item}
136
- </StyledMenuItem>
137
- ))}
138
- </>
139
- )
140
- }
141
- if (menu?.length) {
142
- return (
143
- <>
144
- {menu.map((item, index) => (
145
- <>
146
- {item?.customButton ? (
147
- item.customButton
148
- ) : (
149
- <StyledMenuItem
150
- sx={{ minWidth: '120px', width: '100%' }}
151
- key={index}
152
- onClick={() => {
153
- handleClose()
154
- item.onClick()
155
- }}
156
- >
157
- {item?.icon && <ListItemIcon>{item.icon}</ListItemIcon>}
158
- <ListItemText>{item.label}</ListItemText>
159
- </StyledMenuItem>
160
- )}
161
- </>
162
- ))}
163
- </>
164
- )
165
- }
166
- }
167
-
168
- const StyledIconButton = styled(IconButton, {
169
- shouldForwardProp: (prop) => prop !== 'outlined',
170
- })<{ outlined?: boolean }>(({ theme, outlined }) => ({
171
- ...(outlined && {
172
- border: `1px solid ${theme.palette.primary.main}`,
173
- borderRadius: '5px',
174
- }),
175
- }))
176
-
177
- const StyledMenuItem = styled(MenuItem)(({}) => ({
178
- display: 'flex',
179
- alignItems: 'center',
180
- '& .MuiListItemIcon-root': {
181
- minWidth: '24px',
182
- },
183
- '& .MuiSvgIcon-root': {
184
- height: '18px',
185
- width: '18px',
186
- },
187
- '& .MuiTypography-root': {
188
- fontWeight: 600,
189
- },
190
- }))
191
-
192
- const StyledDropDownButton = styled(Button)(({}) => ({
193
- padding: '0 14px',
194
- }))
@@ -1,103 +0,0 @@
1
- import {
2
- ListItemIcon,
3
- ListItemText,
4
- Menu,
5
- MenuItem,
6
- MenuListProps,
7
- MenuProps,
8
- styled,
9
- } from '@mui/material'
10
- import { cloneElement, ReactNode, useState } from 'react'
11
-
12
- interface Props {
13
- anchor: any
14
- loading?: boolean
15
- menu: {
16
- label: string | ReactNode
17
- icon?: ReactNode
18
- onClick: (props?: any) => any
19
- component?: ReactNode
20
- }[]
21
- menuProps?: Omit<MenuProps, 'open'>
22
- menuListProps?: MenuListProps
23
- }
24
-
25
- export default function MenuButton({
26
- menu,
27
- menuProps,
28
- menuListProps,
29
- loading = false,
30
- anchor,
31
- }: Props) {
32
- const [anchorEl, setAnchorEl] = useState<any>(null)
33
- const open = Boolean(anchorEl)
34
-
35
- const handleClick = (event) => {
36
- setAnchorEl(event.currentTarget)
37
- }
38
-
39
- const handleClose = () => {
40
- setAnchorEl(null)
41
- }
42
-
43
- const AnchorEl = cloneElement(anchor, {
44
- onClick: handleClick,
45
- })
46
-
47
- return (
48
- <>
49
- {AnchorEl}
50
- <Menu
51
- elevation={2}
52
- id="basic-menu"
53
- anchorEl={anchorEl}
54
- open={open}
55
- onClose={handleClose}
56
- MenuListProps={{
57
- sx: { padding: 0 },
58
- ...menuListProps,
59
- }}
60
- anchorOrigin={{
61
- vertical: 'bottom',
62
- horizontal: 'right',
63
- }}
64
- transformOrigin={{
65
- vertical: 'top',
66
- horizontal: 'right',
67
- }}
68
- {...menuProps}
69
- >
70
- {menu.map((item, index) => (
71
- <StyledMenuItem
72
- sx={{ minWidth: '120px', width: '100%' }}
73
- key={index}
74
- onClick={() => {
75
- handleClose()
76
- item.onClick()
77
- }}
78
- >
79
- {item?.icon && <ListItemIcon>{item.icon}</ListItemIcon>}
80
- <ListItemText>{item.label}</ListItemText>
81
- </StyledMenuItem>
82
- ))}
83
- </Menu>
84
- </>
85
- )
86
- }
87
-
88
- const StyledMenuItem = styled(MenuItem)(({ theme }) => ({
89
- padding: '10px 20px',
90
- display: 'flex',
91
- alignItems: 'center',
92
- '& .MuiListItemIcon-root': {
93
- minWidth: '24px',
94
- },
95
- '& .MuiSvgIcon-root': {
96
- height: '18px',
97
- width: '18px',
98
- },
99
- '& .MuiTypography-root': {
100
- fontWeight: 600,
101
- },
102
- borderBottom: theme.borders.grayLight,
103
- }))