@ltht-react/menu 2.0.143 → 2.0.144
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 +15 -15
- package/package.json +5 -5
- package/src/index.tsx +4 -4
- package/src/molecules/action-menu.tsx +211 -211
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -8
- package/lib/index.js.map +0 -1
- package/lib/molecules/action-menu.d.ts +0 -27
- package/lib/molecules/action-menu.js +0 -124
- package/lib/molecules/action-menu.js.map +0 -1
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
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ltht-react/menu",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.144",
|
|
4
4
|
"description": "ltht-react styled Menu component.",
|
|
5
5
|
"author": "LTHT",
|
|
6
6
|
"homepage": "",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@emotion/react": "^11.0.0",
|
|
30
30
|
"@emotion/styled": "^11.0.0",
|
|
31
|
-
"@ltht-react/button": "^2.0.
|
|
32
|
-
"@ltht-react/icon": "^2.0.
|
|
33
|
-
"@ltht-react/styles": "^2.0.
|
|
31
|
+
"@ltht-react/button": "^2.0.144",
|
|
32
|
+
"@ltht-react/icon": "^2.0.144",
|
|
33
|
+
"@ltht-react/styles": "^2.0.144",
|
|
34
34
|
"focus-trap-react": "^10.0.0",
|
|
35
35
|
"react": "^18.2.0",
|
|
36
36
|
"react-popper": "^2.3.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1697d516a201e1aa5d95bb7f112573fc14634486"
|
|
39
39
|
}
|
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,211 @@
|
|
|
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
|
+
|
|
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
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var action_menu_1 = __importDefault(require("./molecules/action-menu"));
|
|
7
|
-
exports.default = action_menu_1.default;
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;AAAA,wEAAsE;AAEtE,kBAAe,qBAAU,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ButtonProps } from '@ltht-react/button/lib/atoms/button';
|
|
2
|
-
import { IconProps } from '@ltht-react/icon';
|
|
3
|
-
import { FC, HTMLAttributes } from 'react';
|
|
4
|
-
declare const ActionMenu: FC<IProps>;
|
|
5
|
-
interface IProps extends HTMLAttributes<HTMLButtonElement> {
|
|
6
|
-
actions: ActionMenuOption[];
|
|
7
|
-
menuButtonOptions?: IconButtonMenuProps | ButtonMenuProps;
|
|
8
|
-
popupStyle?: React.CSSProperties;
|
|
9
|
-
popupPlacement?: 'bottom-start' | 'right-start';
|
|
10
|
-
}
|
|
11
|
-
interface IconButtonMenuProps {
|
|
12
|
-
type: 'icon';
|
|
13
|
-
iconProps: IconProps;
|
|
14
|
-
text?: string;
|
|
15
|
-
}
|
|
16
|
-
interface ButtonMenuProps {
|
|
17
|
-
type: 'button';
|
|
18
|
-
buttonProps: ButtonProps;
|
|
19
|
-
text: string;
|
|
20
|
-
}
|
|
21
|
-
export interface ActionMenuOption {
|
|
22
|
-
text: string;
|
|
23
|
-
clickHandler: () => void;
|
|
24
|
-
leftIcon?: IconProps;
|
|
25
|
-
rightIcon?: IconProps;
|
|
26
|
-
}
|
|
27
|
-
export default ActionMenu;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
41
|
-
var t = {};
|
|
42
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
43
|
-
t[p] = s[p];
|
|
44
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
45
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
46
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
47
|
-
t[p[i]] = s[p[i]];
|
|
48
|
-
}
|
|
49
|
-
return t;
|
|
50
|
-
};
|
|
51
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
-
};
|
|
54
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
56
|
-
var styled_1 = __importDefault(require("@emotion/styled"));
|
|
57
|
-
var button_1 = __importDefault(require("@ltht-react/button/lib/atoms/button"));
|
|
58
|
-
var icon_1 = __importStar(require("@ltht-react/icon"));
|
|
59
|
-
var styles_1 = require("@ltht-react/styles");
|
|
60
|
-
var focus_trap_react_1 = __importDefault(require("focus-trap-react"));
|
|
61
|
-
var react_1 = require("react");
|
|
62
|
-
var react_popper_1 = require("react-popper");
|
|
63
|
-
var defaultMenuButtonProps = {
|
|
64
|
-
type: 'icon',
|
|
65
|
-
iconProps: {
|
|
66
|
-
type: 'ellipsis-vertical',
|
|
67
|
-
size: 'large',
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
var StyledUnorderedList = styled_1.default.ul(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n list-style-type: none;\n padding: 0;\n margin: 0;\n"], ["\n ", "\n list-style-type: none;\n padding: 0;\n margin: 0;\n"])), styles_1.CSS_RESET);
|
|
71
|
-
var StyledListItem = styled_1.default.li(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", "\n background-color: 'white';\n padding: 0.5rem;\n line-height: 1em;\n display: flex;\n border-radius: 4px;\n\n &:hover {\n background: ", ";\n cursor: pointer;\n color: white;\n }\n"], ["\n ", "\n background-color: 'white';\n padding: 0.5rem;\n line-height: 1em;\n display: flex;\n border-radius: 4px;\n\n &:hover {\n background: ", ";\n cursor: pointer;\n color: white;\n }\n"])), styles_1.CSS_RESET, styles_1.BTN_COLOURS.PRIMARY.VALUE);
|
|
72
|
-
var StyledListItemIcon = styled_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n flex-basis: 25%;\n"], ["\n flex-basis: 25%;\n"])));
|
|
73
|
-
var StyledListItemContent = styled_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n flex: 1;\n text-align: left;\n"], ["\n flex: 1;\n text-align: left;\n"])));
|
|
74
|
-
var StyledCard = styled_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", "\n display: inline-block;\n min-width: 10rem;\n z-index: 1;\n background: white;\n border-radius: 4px;\n 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);\n"], ["\n ", "\n display: inline-block;\n min-width: 10rem;\n z-index: 1;\n background: white;\n border-radius: 4px;\n 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);\n"])), styles_1.CSS_RESET);
|
|
75
|
-
var StyledRightIcon = (0, styled_1.default)(icon_1.default)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n margin-right: 0.5rem;\n margin-left: 3rem;\n"], ["\n margin-right: 0.5rem;\n margin-left: 3rem;\n"])));
|
|
76
|
-
var StyledLeftIcon = (0, styled_1.default)(icon_1.default)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n margin-right: 0.5rem;\n margin-left: 0.5rem;\n"], ["\n margin-right: 0.5rem;\n margin-left: 0.5rem;\n"])));
|
|
77
|
-
var StyledMenuButtonWrapper = styled_1.default.div(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n display: inline-block;\n"], ["\n display: inline-block;\n"])));
|
|
78
|
-
var ActionMenu = function (_a) {
|
|
79
|
-
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"]);
|
|
80
|
-
var popperRef = (0, react_1.useRef)(null);
|
|
81
|
-
var _f = (0, react_1.useState)(null), popperElement = _f[0], setPopperElement = _f[1];
|
|
82
|
-
var _g = (0, react_1.useState)(null), containerElement = _g[0], setContainerElement = _g[1];
|
|
83
|
-
var popper = (0, react_popper_1.usePopper)(popperRef.current, popperElement, {
|
|
84
|
-
placement: popupPlacement,
|
|
85
|
-
strategy: 'fixed',
|
|
86
|
-
});
|
|
87
|
-
var closePopper = function () {
|
|
88
|
-
setShowMenu(false);
|
|
89
|
-
};
|
|
90
|
-
var _h = (0, react_1.useState)(false), showMenu = _h[0], setShowMenu = _h[1];
|
|
91
|
-
(0, react_1.useEffect)(function () {
|
|
92
|
-
var _a;
|
|
93
|
-
if ((_a = containerElement === null || containerElement === void 0 ? void 0 : containerElement.parentElement) === null || _a === void 0 ? void 0 : _a.style) {
|
|
94
|
-
containerElement.parentElement.style.zIndex = showMenu
|
|
95
|
-
? "".concat((0, styles_1.getZIndex)(styles_1.PopUp))
|
|
96
|
-
: "".concat((0, styles_1.getZIndex)(styles_1.TableDataWithPopUp));
|
|
97
|
-
}
|
|
98
|
-
}, [containerElement, showMenu]);
|
|
99
|
-
var menuButtonClickHandler = function () {
|
|
100
|
-
setShowMenu(!showMenu);
|
|
101
|
-
};
|
|
102
|
-
return ((0, jsx_runtime_1.jsx)("div", { ref: setContainerElement, children: (0, jsx_runtime_1.jsx)(focus_trap_react_1.default, { active: showMenu, focusTrapOptions: {
|
|
103
|
-
tabbableOptions: {
|
|
104
|
-
displayCheck: 'none',
|
|
105
|
-
},
|
|
106
|
-
initialFocus: false,
|
|
107
|
-
allowOutsideClick: false,
|
|
108
|
-
clickOutsideDeactivates: true,
|
|
109
|
-
onDeactivate: closePopper,
|
|
110
|
-
}, children: (0, jsx_runtime_1.jsxs)(StyledMenuButtonWrapper, { ref: popperRef, children: [menuButtonOptions.type === 'icon' && ((0, jsx_runtime_1.jsx)(icon_1.IconButton, __assign({ iconProps: menuButtonOptions.iconProps, text: menuButtonOptions.text }, rest, { onClick: function (e) {
|
|
111
|
-
e.stopPropagation();
|
|
112
|
-
menuButtonClickHandler();
|
|
113
|
-
}, id: id, "data-testid": id }))), menuButtonOptions.type === 'button' && ((0, jsx_runtime_1.jsx)(button_1.default, __assign({}, menuButtonOptions.buttonProps, rest, { onClick: function (e) {
|
|
114
|
-
e.stopPropagation();
|
|
115
|
-
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))); }) }) })))] }) }) }));
|
|
121
|
-
};
|
|
122
|
-
exports.default = ActionMenu;
|
|
123
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
|
|
124
|
-
//# sourceMappingURL=action-menu.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,G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