@ltht-react/menu 2.0.162 → 2.0.164

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/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # Input
2
-
3
- <!-- STORY -->
4
-
5
- ### Import
6
-
7
- ```js
8
- import Menu from '@ltht-react/menu'
9
- ```
10
-
11
- ### Usage
12
-
13
- ```jsx
14
- <Menu />
15
- ```
1
+ # Input
2
+
3
+ <!-- STORY -->
4
+
5
+ ### Import
6
+
7
+ ```js
8
+ import Menu from '@ltht-react/menu'
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ ```jsx
14
+ <Menu />
15
+ ```
@@ -60,6 +60,7 @@ var styles_1 = require("@ltht-react/styles");
60
60
  var focus_trap_react_1 = __importDefault(require("focus-trap-react"));
61
61
  var react_1 = require("react");
62
62
  var react_popper_1 = require("react-popper");
63
+ var utils_1 = require("@ltht-react/utils");
63
64
  var defaultMenuButtonProps = {
64
65
  type: 'icon',
65
66
  iconProps: {
@@ -77,6 +78,7 @@ var StyledLeftIcon = (0, styled_1.default)(icon_1.default)(templateObject_7 || (
77
78
  var StyledMenuButtonWrapper = styled_1.default.div(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n display: inline-block;\n"], ["\n display: inline-block;\n"])));
78
79
  var ActionMenu = function (_a) {
79
80
  var actions = _a.actions, _b = _a.menuButtonOptions, menuButtonOptions = _b === void 0 ? defaultMenuButtonProps : _b, _c = _a.id, id = _c === void 0 ? 'action-menu-button' : _c, _d = _a.popupStyle, popupStyle = _d === void 0 ? {} : _d, _e = _a.popupPlacement, popupPlacement = _e === void 0 ? 'bottom-start' : _e, rest = __rest(_a, ["actions", "menuButtonOptions", "id", "popupStyle", "popupPlacement"]);
81
+ var menuItemIdPrefix = id ? "".concat(id, "-") : '';
80
82
  var popperRef = (0, react_1.useRef)(null);
81
83
  var _f = (0, react_1.useState)(null), popperElement = _f[0], setPopperElement = _f[1];
82
84
  var _g = (0, react_1.useState)(null), containerElement = _g[0], setContainerElement = _g[1];
@@ -113,11 +115,15 @@ var ActionMenu = function (_a) {
113
115
  }, id: id, "data-testid": id }))), menuButtonOptions.type === 'button' && ((0, jsx_runtime_1.jsx)(button_1.default, __assign({}, menuButtonOptions.buttonProps, rest, { onClick: function (e) {
114
116
  e.stopPropagation();
115
117
  menuButtonClickHandler();
116
- }, id: id, "data-testid": id, children: menuButtonOptions.text }))), showMenu && ((0, jsx_runtime_1.jsx)(StyledCard, __assign({ tabIndex: -1, ref: setPopperElement, style: __assign(__assign({}, popper.styles.popper), popupStyle) }, popper.attributes.popper, { children: (0, jsx_runtime_1.jsx)(StyledUnorderedList, { role: "menu", "aria-labelledby": id, children: actions.map(function (action, idx) { return ((0, jsx_runtime_1.jsxs)(StyledListItem, { role: "menuitem", onClick: function (e) {
117
- e.stopPropagation();
118
- menuButtonClickHandler();
119
- action.clickHandler();
120
- }, children: [(0, jsx_runtime_1.jsx)(StyledListItemIcon, { children: action.leftIcon && (0, jsx_runtime_1.jsx)(StyledLeftIcon, __assign({}, action.leftIcon)) }), (0, jsx_runtime_1.jsx)(StyledListItemContent, { children: action.text }), (0, jsx_runtime_1.jsx)(StyledListItemIcon, { children: action.rightIcon && (0, jsx_runtime_1.jsx)(StyledRightIcon, __assign({}, action.rightIcon)) })] }, "menu-action-".concat(idx))); }) }) })))] }) }) }));
118
+ }, id: id, "data-testid": id, children: menuButtonOptions.text }))), showMenu && ((0, jsx_runtime_1.jsx)(StyledCard, __assign({ tabIndex: -1, ref: setPopperElement, style: __assign(__assign({}, popper.styles.popper), popupStyle) }, popper.attributes.popper, { children: (0, jsx_runtime_1.jsx)(StyledUnorderedList, { role: "menu", "aria-labelledby": id, children: actions.map(function (action, idx) {
119
+ var textId = (0, utils_1.stringToHtmlId)(action.text);
120
+ var actionMenuItemId = "".concat(menuItemIdPrefix, "action-menu-item-").concat(textId, "-").concat(idx);
121
+ return ((0, jsx_runtime_1.jsxs)(StyledListItem, { "data-testid": actionMenuItemId, id: actionMenuItemId, role: "menuitem", onClick: function (e) {
122
+ e.stopPropagation();
123
+ menuButtonClickHandler();
124
+ action.clickHandler();
125
+ }, children: [(0, jsx_runtime_1.jsx)(StyledListItemIcon, { children: action.leftIcon && (0, jsx_runtime_1.jsx)(StyledLeftIcon, __assign({}, action.leftIcon)) }), (0, jsx_runtime_1.jsx)(StyledListItemContent, { children: action.text }), (0, jsx_runtime_1.jsx)(StyledListItemIcon, { children: action.rightIcon && (0, jsx_runtime_1.jsx)(StyledRightIcon, __assign({}, action.rightIcon)) })] }, "menu-action-".concat(idx)));
126
+ }) }) })))] }) }) }));
121
127
  };
122
128
  exports.default = ActionMenu;
123
129
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
@@ -1 +1 @@
1
- {"version":3,"file":"action-menu.js","sourceRoot":"","sources":["../../src/molecules/action-menu.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAAoC;AACpC,+EAAyE;AACzE,uDAA8D;AAC9D,6CAAiG;AACjG,sEAAwC;AACxC,+BAAuE;AACvE,6CAAwC;AAExC,IAAM,sBAAsB,GAAwB;IAClD,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE;QACT,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,OAAO;KACd;CACF,CAAA;AAED,IAAM,mBAAmB,GAAG,gBAAM,CAAC,EAAE,sIAAA,MACjC,EAAS,2DAIZ,KAJG,kBAAS,CAIZ,CAAA;AAED,IAAM,cAAc,GAAG,gBAAM,CAAC,EAAE,mRAAA,MAC5B,EAAS,mJAQK,EAAyB,mDAI1C,KAZG,kBAAS,EAQK,oBAAW,CAAC,OAAO,CAAC,KAAK,CAI1C,CAAA;AAED,IAAM,kBAAkB,GAAG,gBAAM,CAAC,GAAG,2FAAA,wBAEpC,IAAA,CAAA;AAED,IAAM,qB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A,sBAAc,EAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gCAC1C,IAAM,gBAAgB,GAAG,UAAG,gBAAgB,8BAAoB,MAAM,cAAI,GAAG,CAAE,CAAA;gCAE/E,OAAO,CACL,wBAAC,cAAc,mBACA,gBAAgB,EAC7B,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAC,UAAU,EAEf,OAAO,EAAE,UAAC,CAAC;wCACT,CAAC,CAAC,eAAe,EAAE,CAAA;wCACnB,sBAAsB,EAAE,CAAA;wCACxB,MAAM,CAAC,YAAY,EAAE,CAAA;oCACvB,CAAC,aAED,uBAAC,kBAAkB,cAChB,MAAM,CAAC,QAAQ,IAAI,uBAAC,cAAc,eAAK,MAAM,CAAC,QAAQ,EAAI,GACxC,EACrB,uBAAC,qBAAqB,cAAE,MAAM,CAAC,IAAI,GAAyB,EAC5D,uBAAC,kBAAkB,cAChB,MAAM,CAAC,SAAS,IAAI,uBAAC,eAAe,eAAK,MAAM,CAAC,SAAS,EAAI,GAC3C,KAbhB,sBAAe,GAAG,CAAE,CAcV,CAClB,CAAA;4BACH,CAAC,CAAC,GACkB,IACX,CACd,IACuB,GAChB,GACR,CACP,CAAA;AACH,CAAC,CAAA;AA4BD,kBAAe,UAAU,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ltht-react/menu",
3
- "version": "2.0.162",
3
+ "version": "2.0.164",
4
4
  "description": "ltht-react styled Menu component.",
5
5
  "author": "LTHT",
6
6
  "homepage": "",
@@ -28,12 +28,13 @@
28
28
  "dependencies": {
29
29
  "@emotion/react": "^11.0.0",
30
30
  "@emotion/styled": "^11.0.0",
31
- "@ltht-react/button": "^2.0.162",
32
- "@ltht-react/icon": "^2.0.162",
33
- "@ltht-react/styles": "^2.0.162",
31
+ "@ltht-react/button": "^2.0.164",
32
+ "@ltht-react/icon": "^2.0.164",
33
+ "@ltht-react/styles": "^2.0.164",
34
+ "@ltht-react/utils": "^2.0.164",
34
35
  "focus-trap-react": "^10.0.0",
35
36
  "react": "^18.2.0",
36
37
  "react-popper": "^2.3.0"
37
38
  },
38
- "gitHead": "f85ba7b8b4710d5d1022ebf58ef613dec5f9cadb"
39
+ "gitHead": "60633c8ef7fc6da5513b54d519588de94d6d52dc"
39
40
  }
package/src/index.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import ActionMenu, { ActionMenuOption } from './molecules/action-menu'
2
-
3
- export default ActionMenu
4
- export { ActionMenuOption }
1
+ import ActionMenu, { ActionMenuOption } from './molecules/action-menu'
2
+
3
+ export default ActionMenu
4
+ export { ActionMenuOption }
@@ -1,211 +1,220 @@
1
- import styled from '@emotion/styled'
2
- import Button, { ButtonProps } from '@ltht-react/button/lib/atoms/button'
3
- import Icon, { IconButton, IconProps } from '@ltht-react/icon'
4
- import { BTN_COLOURS, CSS_RESET, PopUp, TableDataWithPopUp, getZIndex } from '@ltht-react/styles'
5
- import FocusTrap from 'focus-trap-react'
6
- import { FC, HTMLAttributes, useRef, useState, useEffect } from 'react'
7
- import { usePopper } from 'react-popper'
8
-
9
- const defaultMenuButtonProps: IconButtonMenuProps = {
10
- type: 'icon',
11
- iconProps: {
12
- type: 'ellipsis-vertical',
13
- size: 'large',
14
- },
15
- }
16
-
17
- const StyledUnorderedList = styled.ul`
18
- ${CSS_RESET}
19
- list-style-type: none;
20
- padding: 0;
21
- margin: 0;
22
- `
23
-
24
- const StyledListItem = styled.li`
25
- ${CSS_RESET}
26
- background-color: 'white';
27
- padding: 0.5rem;
28
- line-height: 1em;
29
- display: flex;
30
- border-radius: 4px;
31
-
32
- &:hover {
33
- background: ${BTN_COLOURS.PRIMARY.VALUE};
34
- cursor: pointer;
35
- color: white;
36
- }
37
- `
38
-
39
- const StyledListItemIcon = styled.div`
40
- flex-basis: 25%;
41
- `
42
-
43
- const StyledListItemContent = styled.div`
44
- flex: 1;
45
- text-align: left;
46
- `
47
-
48
- const StyledCard = styled.div`
49
- ${CSS_RESET}
50
- display: inline-block;
51
- min-width: 10rem;
52
- z-index: 1;
53
- background: white;
54
- border-radius: 4px;
55
- box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.04), 0px 4px 5px rgba(0, 0, 0, 0.06), 0px 2px 4px -1px rgba(0, 0, 0, 0.09);
56
- `
57
-
58
- const StyledRightIcon = styled(Icon)`
59
- margin-right: 0.5rem;
60
- margin-left: 3rem;
61
- `
62
-
63
- const StyledLeftIcon = styled(Icon)`
64
- margin-right: 0.5rem;
65
- margin-left: 0.5rem;
66
- `
67
-
68
- const StyledMenuButtonWrapper = styled.div`
69
- display: inline-block;
70
- `
71
-
72
- const ActionMenu: FC<IProps> = ({
73
- actions,
74
- menuButtonOptions = defaultMenuButtonProps,
75
- id = 'action-menu-button',
76
- popupStyle = {},
77
- popupPlacement = 'bottom-start',
78
- ...rest
79
- }) => {
80
- const popperRef = useRef<HTMLDivElement>(null)
81
- const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null)
82
- const [containerElement, setContainerElement] = useState<HTMLDivElement | null>(null)
83
-
84
- const popper = usePopper(popperRef.current, popperElement, {
85
- placement: popupPlacement,
86
- strategy: 'fixed',
87
- })
88
-
89
- const closePopper = () => {
90
- setShowMenu(false)
91
- }
92
-
93
- const [showMenu, setShowMenu] = useState(false)
94
-
95
- useEffect(() => {
96
- if (containerElement?.parentElement?.style) {
97
- containerElement.parentElement.style.zIndex = showMenu
98
- ? `${getZIndex(PopUp)}`
99
- : `${getZIndex(TableDataWithPopUp)}`
100
- }
101
- }, [containerElement, showMenu])
102
-
103
- const menuButtonClickHandler = () => {
104
- setShowMenu(!showMenu)
105
- }
106
-
107
- return (
108
- <div ref={setContainerElement}>
109
- <FocusTrap
110
- active={showMenu}
111
- focusTrapOptions={{
112
- tabbableOptions: {
113
- displayCheck: 'none',
114
- },
115
- initialFocus: false,
116
- allowOutsideClick: false,
117
- clickOutsideDeactivates: true,
118
- onDeactivate: closePopper,
119
- }}
120
- >
121
- <StyledMenuButtonWrapper ref={popperRef}>
122
- {menuButtonOptions.type === 'icon' && (
123
- <IconButton
124
- iconProps={menuButtonOptions.iconProps}
125
- text={menuButtonOptions.text}
126
- {...rest}
127
- onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
128
- e.stopPropagation()
129
- menuButtonClickHandler()
130
- }}
131
- id={id}
132
- data-testid={id}
133
- />
134
- )}
135
- {menuButtonOptions.type === 'button' && (
136
- <Button
137
- {...menuButtonOptions.buttonProps}
138
- {...rest}
139
- onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
140
- e.stopPropagation()
141
- menuButtonClickHandler()
142
- }}
143
- id={id}
144
- data-testid={id}
145
- >
146
- {menuButtonOptions.text}
147
- </Button>
148
- )}
149
- {showMenu && (
150
- <StyledCard
151
- tabIndex={-1}
152
- ref={setPopperElement}
153
- style={{ ...popper.styles.popper, ...popupStyle }}
154
- {...popper.attributes.popper}
155
- >
156
- <StyledUnorderedList role="menu" aria-labelledby={id}>
157
- {actions.map((action, idx) => (
158
- <StyledListItem
159
- role="menuitem"
160
- key={`menu-action-${idx}`}
161
- onClick={(e) => {
162
- e.stopPropagation()
163
- menuButtonClickHandler()
164
- action.clickHandler()
165
- }}
166
- >
167
- <StyledListItemIcon>
168
- {action.leftIcon && <StyledLeftIcon {...action.leftIcon} />}
169
- </StyledListItemIcon>
170
- <StyledListItemContent>{action.text}</StyledListItemContent>
171
- <StyledListItemIcon>
172
- {action.rightIcon && <StyledRightIcon {...action.rightIcon} />}
173
- </StyledListItemIcon>
174
- </StyledListItem>
175
- ))}
176
- </StyledUnorderedList>
177
- </StyledCard>
178
- )}
179
- </StyledMenuButtonWrapper>
180
- </FocusTrap>
181
- </div>
182
- )
183
- }
184
-
185
- interface IProps extends HTMLAttributes<HTMLButtonElement> {
186
- actions: ActionMenuOption[]
187
- menuButtonOptions?: IconButtonMenuProps | ButtonMenuProps
188
- popupStyle?: React.CSSProperties
189
- popupPlacement?: 'bottom-start' | 'right-start'
190
- }
191
-
192
- interface IconButtonMenuProps {
193
- type: 'icon'
194
- iconProps: IconProps
195
- text?: string
196
- }
197
-
198
- interface ButtonMenuProps {
199
- type: 'button'
200
- buttonProps: ButtonProps
201
- text: string
202
- }
203
-
204
- export interface ActionMenuOption {
205
- text: string
206
- clickHandler: () => void
207
- leftIcon?: IconProps
208
- rightIcon?: IconProps
209
- }
210
-
211
- export default ActionMenu
1
+ import styled from '@emotion/styled'
2
+ import Button, { ButtonProps } from '@ltht-react/button/lib/atoms/button'
3
+ import Icon, { IconButton, IconProps } from '@ltht-react/icon'
4
+ import { BTN_COLOURS, CSS_RESET, PopUp, TableDataWithPopUp, getZIndex } from '@ltht-react/styles'
5
+ import FocusTrap from 'focus-trap-react'
6
+ import { FC, HTMLAttributes, useRef, useState, useEffect } from 'react'
7
+ import { usePopper } from 'react-popper'
8
+ import { stringToHtmlId } from '@ltht-react/utils'
9
+
10
+ const defaultMenuButtonProps: IconButtonMenuProps = {
11
+ type: 'icon',
12
+ iconProps: {
13
+ type: 'ellipsis-vertical',
14
+ size: 'large',
15
+ },
16
+ }
17
+
18
+ const StyledUnorderedList = styled.ul`
19
+ ${CSS_RESET}
20
+ list-style-type: none;
21
+ padding: 0;
22
+ margin: 0;
23
+ `
24
+
25
+ const StyledListItem = styled.li`
26
+ ${CSS_RESET}
27
+ background-color: 'white';
28
+ padding: 0.5rem;
29
+ line-height: 1em;
30
+ display: flex;
31
+ border-radius: 4px;
32
+
33
+ &:hover {
34
+ background: ${BTN_COLOURS.PRIMARY.VALUE};
35
+ cursor: pointer;
36
+ color: white;
37
+ }
38
+ `
39
+
40
+ const StyledListItemIcon = styled.div`
41
+ flex-basis: 25%;
42
+ `
43
+
44
+ const StyledListItemContent = styled.div`
45
+ flex: 1;
46
+ text-align: left;
47
+ `
48
+
49
+ const StyledCard = styled.div`
50
+ ${CSS_RESET}
51
+ display: inline-block;
52
+ min-width: 10rem;
53
+ z-index: 1;
54
+ background: white;
55
+ border-radius: 4px;
56
+ box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.04), 0px 4px 5px rgba(0, 0, 0, 0.06), 0px 2px 4px -1px rgba(0, 0, 0, 0.09);
57
+ `
58
+
59
+ const StyledRightIcon = styled(Icon)`
60
+ margin-right: 0.5rem;
61
+ margin-left: 3rem;
62
+ `
63
+
64
+ const StyledLeftIcon = styled(Icon)`
65
+ margin-right: 0.5rem;
66
+ margin-left: 0.5rem;
67
+ `
68
+
69
+ const StyledMenuButtonWrapper = styled.div`
70
+ display: inline-block;
71
+ `
72
+
73
+ const ActionMenu: FC<IProps> = ({
74
+ actions,
75
+ menuButtonOptions = defaultMenuButtonProps,
76
+ id = 'action-menu-button',
77
+ popupStyle = {},
78
+ popupPlacement = 'bottom-start',
79
+ ...rest
80
+ }) => {
81
+ const menuItemIdPrefix = id ? `${id}-` : ''
82
+ const popperRef = useRef<HTMLDivElement>(null)
83
+ const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null)
84
+ const [containerElement, setContainerElement] = useState<HTMLDivElement | null>(null)
85
+
86
+ const popper = usePopper(popperRef.current, popperElement, {
87
+ placement: popupPlacement,
88
+ strategy: 'fixed',
89
+ })
90
+
91
+ const closePopper = () => {
92
+ setShowMenu(false)
93
+ }
94
+
95
+ const [showMenu, setShowMenu] = useState(false)
96
+
97
+ useEffect(() => {
98
+ if (containerElement?.parentElement?.style) {
99
+ containerElement.parentElement.style.zIndex = showMenu
100
+ ? `${getZIndex(PopUp)}`
101
+ : `${getZIndex(TableDataWithPopUp)}`
102
+ }
103
+ }, [containerElement, showMenu])
104
+
105
+ const menuButtonClickHandler = () => {
106
+ setShowMenu(!showMenu)
107
+ }
108
+
109
+ return (
110
+ <div ref={setContainerElement}>
111
+ <FocusTrap
112
+ active={showMenu}
113
+ focusTrapOptions={{
114
+ tabbableOptions: {
115
+ displayCheck: 'none',
116
+ },
117
+ initialFocus: false,
118
+ allowOutsideClick: false,
119
+ clickOutsideDeactivates: true,
120
+ onDeactivate: closePopper,
121
+ }}
122
+ >
123
+ <StyledMenuButtonWrapper ref={popperRef}>
124
+ {menuButtonOptions.type === 'icon' && (
125
+ <IconButton
126
+ iconProps={menuButtonOptions.iconProps}
127
+ text={menuButtonOptions.text}
128
+ {...rest}
129
+ onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
130
+ e.stopPropagation()
131
+ menuButtonClickHandler()
132
+ }}
133
+ id={id}
134
+ data-testid={id}
135
+ />
136
+ )}
137
+ {menuButtonOptions.type === 'button' && (
138
+ <Button
139
+ {...menuButtonOptions.buttonProps}
140
+ {...rest}
141
+ onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
142
+ e.stopPropagation()
143
+ menuButtonClickHandler()
144
+ }}
145
+ id={id}
146
+ data-testid={id}
147
+ >
148
+ {menuButtonOptions.text}
149
+ </Button>
150
+ )}
151
+ {showMenu && (
152
+ <StyledCard
153
+ tabIndex={-1}
154
+ ref={setPopperElement}
155
+ style={{ ...popper.styles.popper, ...popupStyle }}
156
+ {...popper.attributes.popper}
157
+ >
158
+ <StyledUnorderedList role="menu" aria-labelledby={id}>
159
+ {actions.map((action, idx) => {
160
+ const textId = stringToHtmlId(action.text)
161
+ const actionMenuItemId = `${menuItemIdPrefix}action-menu-item-${textId}-${idx}`
162
+
163
+ return (
164
+ <StyledListItem
165
+ data-testid={actionMenuItemId}
166
+ id={actionMenuItemId}
167
+ role="menuitem"
168
+ key={`menu-action-${idx}`}
169
+ onClick={(e) => {
170
+ e.stopPropagation()
171
+ menuButtonClickHandler()
172
+ action.clickHandler()
173
+ }}
174
+ >
175
+ <StyledListItemIcon>
176
+ {action.leftIcon && <StyledLeftIcon {...action.leftIcon} />}
177
+ </StyledListItemIcon>
178
+ <StyledListItemContent>{action.text}</StyledListItemContent>
179
+ <StyledListItemIcon>
180
+ {action.rightIcon && <StyledRightIcon {...action.rightIcon} />}
181
+ </StyledListItemIcon>
182
+ </StyledListItem>
183
+ )
184
+ })}
185
+ </StyledUnorderedList>
186
+ </StyledCard>
187
+ )}
188
+ </StyledMenuButtonWrapper>
189
+ </FocusTrap>
190
+ </div>
191
+ )
192
+ }
193
+
194
+ interface IProps extends HTMLAttributes<HTMLButtonElement> {
195
+ actions: ActionMenuOption[]
196
+ menuButtonOptions?: IconButtonMenuProps | ButtonMenuProps
197
+ popupStyle?: React.CSSProperties
198
+ popupPlacement?: 'bottom-start' | 'right-start'
199
+ }
200
+
201
+ interface IconButtonMenuProps {
202
+ type: 'icon'
203
+ iconProps: IconProps
204
+ text?: string
205
+ }
206
+
207
+ interface ButtonMenuProps {
208
+ type: 'button'
209
+ buttonProps: ButtonProps
210
+ text: string
211
+ }
212
+
213
+ export interface ActionMenuOption {
214
+ text: string
215
+ clickHandler: () => void
216
+ leftIcon?: IconProps
217
+ rightIcon?: IconProps
218
+ }
219
+
220
+ export default ActionMenu