File tree Expand file tree Collapse file tree 5 files changed +64
-19
lines changed
Expand file tree Collapse file tree 5 files changed +64
-19
lines changed Original file line number Diff line number Diff line change 22
33All 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
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change @@ -11,8 +11,13 @@ export default {
1111
1212export 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
Original file line number Diff line number Diff line change @@ -7,7 +7,11 @@ import { PhoenixIconsColored } from '../../types/PhoenixIcons'
77import { MarginProps } from '../common/Spacing/MarginProps'
88import { PaddingProps } from '../common/Spacing/PaddingProps'
99import MenuItemIcon from './MenuItemIcon'
10- import { StyledMenuItem , StyledMenuItemAnchor } from './MenuStyles'
10+ import {
11+ StyledMenuItem ,
12+ StyledMenuItemAnchor ,
13+ StyledMenuItemButton
14+ } from './MenuStyles'
1115
1216export 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}
Original file line number Diff line number Diff 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+
5871export const styledIconCss = css < MenuItemIconProps > `
5972 width: 20px;
6073 height: 20px;
You can’t perform that action at this time.
0 commit comments