Skip to content

Commit 4523400

Browse files
Merge pull request #425 from purple-technology/fx-1772
feat: extending MenuItem functionality
2 parents 7cdc861 + d358e60 commit 4523400

File tree

5 files changed

+64
-19
lines changed

5 files changed

+64
-19
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [5.29.0](https://github.com/purple-technology/phoenix-components/compare/v5.28.2...v5.29.0) (2025-08-29)
6+
7+
8+
### Features
9+
10+
* add button support for MenuItem alongside anchor depending on href prop ([b75494b](https://github.com/purple-technology/phoenix-components/commit/b75494b4358336c929183cd350b8c7dc6ca58bf0))
11+
512
### [5.28.2](https://github.com/purple-technology/phoenix-components/compare/v5.28.1...v5.28.2) (2025-08-18)
613

714

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@purple/phoenix-components",
3-
"version": "5.28.2",
3+
"version": "5.29.0",
44
"description": "",
55
"main": "dist/bundle.umd.js",
66
"module": "dist/bundle.esm.js",

src/components/Menu/Menu.stories.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ export default {
1111

1212
export const Menu = (args) => (
1313
<MenuComponent {...args}>
14-
<MenuItemComponent onClick={args.hide}>Withdraw</MenuItemComponent>
15-
<MenuItemComponent onClick={args.hide}>Transfer</MenuItemComponent>
14+
<MenuItemComponent onClick={args.hide}>No href item</MenuItemComponent>
15+
<MenuItemComponent href="/" onClick={args.hide}>
16+
With href item
17+
</MenuItemComponent>
18+
<MenuItemComponent disabled href="/" onClick={args.hide}>
19+
Disabled item
20+
</MenuItemComponent>
1621
<HorizontalDivider my="3xs" />
1722
<MenuItemComponent icon="lock" onClick={args.hide}>
1823
Change password

src/components/Menu/MenuItem.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { PhoenixIconsColored } from '../../types/PhoenixIcons'
77
import { MarginProps } from '../common/Spacing/MarginProps'
88
import { PaddingProps } from '../common/Spacing/PaddingProps'
99
import MenuItemIcon from './MenuItemIcon'
10-
import { StyledMenuItem, StyledMenuItemAnchor } from './MenuStyles'
10+
import {
11+
StyledMenuItem,
12+
StyledMenuItemAnchor,
13+
StyledMenuItemButton
14+
} from './MenuStyles'
1115

1216
export interface MenuItemProps
1317
extends MarginProps,
@@ -26,22 +30,38 @@ export const MenuItem: React.FC<PropsWithChildren<MenuItemProps>> = ({
2630
onClick,
2731
children,
2832
icon,
33+
href,
34+
disabled,
2935
className,
30-
...props
36+
colorTheme,
37+
...restProps
3138
}) => {
39+
const getClickHandler = ():
40+
| MouseEventHandler<HTMLAnchorElement>
41+
| undefined => (disabled ? undefined : onClick)
42+
43+
const commonProps = {
44+
onClick: getClickHandler(),
45+
disabled,
46+
...restProps
47+
}
48+
49+
const content = (
50+
<>
51+
<MenuItemIcon icon={icon} disabled={disabled} colorTheme={colorTheme} />
52+
{children}
53+
</>
54+
)
55+
3256
return (
33-
<StyledMenuItem data-testid={testId} className={className} {...props}>
34-
<StyledMenuItemAnchor
35-
onClick={!props.disabled ? onClick : undefined}
36-
{...props}
37-
>
38-
<MenuItemIcon
39-
icon={icon}
40-
disabled={props.disabled}
41-
colorTheme={props.colorTheme}
42-
/>
43-
{children}
44-
</StyledMenuItemAnchor>
57+
<StyledMenuItem data-testid={testId} className={className} {...restProps}>
58+
{href ? (
59+
<StyledMenuItemAnchor href={href} {...commonProps}>
60+
{content}
61+
</StyledMenuItemAnchor>
62+
) : (
63+
<StyledMenuItemButton {...commonProps}>{content}</StyledMenuItemButton>
64+
)}
4565
</StyledMenuItem>
4666
)
4767
}

src/components/Menu/MenuStyles.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export const StyledMenuItem = styled.li`
2424
${marginCss}
2525
`
2626

27-
interface StyledMenuItemAnchorProps {
27+
interface MenuItemBaseCssProps {
2828
colorTheme?: ColorTheme
2929
disabled?: boolean
3030
}
3131

32-
export const StyledMenuItemAnchor = styled.a<StyledMenuItemAnchorProps>`
32+
const menuItemBaseCss = css<MenuItemBaseCssProps>`
3333
display: flex;
3434
align-items: center;
3535
text-decoration: none;
@@ -55,6 +55,19 @@ export const StyledMenuItemAnchor = styled.a<StyledMenuItemAnchorProps>`
5555
: undefined}
5656
`
5757

58+
export const StyledMenuItemButton = styled.button<MenuItemBaseCssProps>`
59+
${menuItemBaseCss};
60+
border: none;
61+
background: inherit;
62+
width: 100%;
63+
font-size: 14px;
64+
font-family: ${({ theme }): string => theme.tokens.ref.fontFamily.base};
65+
`
66+
67+
export const StyledMenuItemAnchor = styled.a<MenuItemBaseCssProps>`
68+
${menuItemBaseCss}
69+
`
70+
5871
export const styledIconCss = css<MenuItemIconProps>`
5972
width: 20px;
6073
height: 20px;

0 commit comments

Comments
 (0)