Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ActionMenuItemWrapper for actions menus item
code from MesPapiers app. Careful we create a `componentsProps` to replace original `iconProps` and `typographyProps`
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
react/MuiCozyTheme/ListItem/ListItemBase/ActionsMenu/ActionMenuItemWrapper.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react' | ||
import cx from 'classnames' | ||
import PropTypes from 'prop-types' | ||
|
||
import { makeStyles } from '../../../../styles' | ||
import Typography from '../../../../Typography' | ||
import Icon, { iconPropType } from '../../../../Icon' | ||
import { ActionMenuItem } from '../../../../ActionMenu' | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
disabledItem: { | ||
cursor: 'default', | ||
'&:hover': { | ||
backgroundColor: 'initial' | ||
} | ||
}, | ||
disabledIcon: { | ||
fill: theme.palette.text.disabled | ||
}, | ||
disabledTypography: { | ||
color: theme.palette.text.disabled | ||
} | ||
})) | ||
|
||
const ActionMenuItemWrapper = ({ | ||
icon, | ||
className, | ||
isEnabled, | ||
componentsProps, | ||
children, | ||
onClick | ||
}) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<ActionMenuItem | ||
className={cx(`u-flex-items-center ${className}`, { | ||
[styles.disabledItem]: !isEnabled | ||
})} | ||
left={ | ||
<Icon | ||
icon={icon} | ||
className={cx({ | ||
[styles.disabledIcon]: !isEnabled | ||
})} | ||
{...componentsProps?.iconProps} | ||
/> | ||
} | ||
onClick={onClick} | ||
> | ||
<Typography | ||
className={cx({ | ||
[styles.disabledTypography]: !isEnabled | ||
})} | ||
{...componentsProps?.typographyProps} | ||
> | ||
{children} | ||
</Typography> | ||
</ActionMenuItem> | ||
) | ||
} | ||
|
||
ActionMenuItemWrapper.defaultProps = { | ||
className: '', | ||
isEnabled: true, | ||
componentsProps: {} | ||
} | ||
|
||
ActionMenuItemWrapper.propTypes = { | ||
icon: iconPropType, | ||
className: PropTypes.string, | ||
isEnabled: PropTypes.bool, | ||
componentsProps: PropTypes.shape({ | ||
iconProps: PropTypes.object, | ||
typographyProps: PropTypes.object | ||
}), | ||
children: PropTypes.node, | ||
onClick: PropTypes.func | ||
} | ||
|
||
export default ActionMenuItemWrapper |