Skip to content

Commit 941e9b7

Browse files
committed
feat(Actions): Add makeAction to simplify action creation
1 parent 4b89cee commit 941e9b7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { forwardRef } from 'react'
2+
3+
import Icon from '../../Icon'
4+
import ListItemIcon from '../../ListItemIcon'
5+
import ListItemText from '../../ListItemText'
6+
import ActionsMenuItem from '../ActionsMenuItem'
7+
8+
const makeComponent = ({ label, icon, name }) => {
9+
const Component = forwardRef((props, ref) => {
10+
return (
11+
<ActionsMenuItem {...props} ref={ref}>
12+
<ListItemIcon>
13+
<Icon icon={icon} />
14+
</ListItemIcon>
15+
<ListItemText primary={label} />
16+
</ActionsMenuItem>
17+
)
18+
})
19+
20+
Component.displayName = name
21+
22+
return Component
23+
}
24+
25+
export const makeAction = ({
26+
name,
27+
label,
28+
icon,
29+
disabled,
30+
displayCondition,
31+
action
32+
}) => {
33+
return {
34+
name,
35+
icon,
36+
label,
37+
disabled,
38+
displayCondition,
39+
action,
40+
Component: makeComponent({ label, icon, name })
41+
}
42+
}

0 commit comments

Comments
 (0)