-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFR] Custom User Menu icon #2391
Changes from 4 commits
5fa653d
9ede5b2
040a6f0
92f0276
be0343b
86f6187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,13 @@ class UserMenu extends React.Component { | |
children: PropTypes.node, | ||
label: PropTypes.string.isRequired, | ||
logout: PropTypes.node, | ||
icon: PropTypes.node, | ||
translate: PropTypes.func.isRequired, | ||
}; | ||
|
||
static defaultProps = { | ||
label: 'ra.auth.user_menu', | ||
icon: <AccountCircle />, | ||
}; | ||
|
||
state = { | ||
|
@@ -36,23 +38,24 @@ class UserMenu extends React.Component { | |
}; | ||
|
||
render() { | ||
const { children, label, logout, translate } = this.props; | ||
const { children, label, icon, logout, translate } = this.props; | ||
if (!logout && !children) return null; | ||
const { anchorEl } = this.state; | ||
const open = Boolean(anchorEl); | ||
|
||
const menuIconProps = { | ||
'arial-label': label && translate(label, { _: label }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should provide a default label too imo. Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently there is a default label used as default prop: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry missed it |
||
'aria-owns': open ? 'menu-appbar' : null, | ||
'aria-haspopup': true, | ||
color: 'inherit', | ||
onClick: this.handleMenu, | ||
children: cloneElement(icon), | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Tooltip title={label && translate(label, { _: label })}> | ||
<IconButton | ||
arial-label={label && translate(label, { _: label })} | ||
aria-owns={open ? 'menu-appbar' : null} | ||
aria-haspopup="true" | ||
onClick={this.handleMenu} | ||
color="inherit" | ||
> | ||
<AccountCircle /> | ||
</IconButton> | ||
<IconButton {...menuIconProps} /> | ||
</Tooltip> | ||
<Menu | ||
id="menu-appbar" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't need you need to extract the props now that only the
icon
prop is accepted.