-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(userProfile): refactor profile component to be stateful
- add profileIconClick - add classname prop - add tests
- Loading branch information
Chris Maina
committed
Feb 28, 2019
1 parent
b250ab1
commit 7c954be
Showing
4 changed files
with
100 additions
and
25 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,37 +1,61 @@ | ||
import React from 'react'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ProfileComponent = ({ name, userImage }) => ( | ||
<div className='profile'> | ||
<p className='profile__name'>{name}</p> | ||
<span | ||
className='profile__image' | ||
style={{ | ||
backgroundImage: `url(${userImage})`, | ||
}} | ||
/> | ||
<i className='fa fa-ellipsis-v fa-lg data-toggle' data-toggle='dropdown' aria-haspopup='true' aria-hidden='true' /> | ||
<div className='dropdown-menu'> | ||
<p>{name}</p> | ||
<div className='dropdown-divider' /> | ||
<div> | ||
<span className='fa fa-cog' /> | ||
<p>Profile</p> | ||
<span className='fa fa-sign-out' /> | ||
<p>Logout</p> | ||
class ProfileComponent extends Component { | ||
state = { | ||
showProfile: false, | ||
}; | ||
|
||
/** | ||
* @name profileIconClick | ||
* toggles state to show profile dropdown | ||
*/ | ||
profileIconClick = () => { | ||
this.setState(prevState => ({ showProfile: !prevState.showProfile })); | ||
}; | ||
|
||
render() { | ||
const { name, userImage, className } = this.props; | ||
const { showProfile } = this.state; | ||
return ( | ||
<div className={`profile ${className}`}> | ||
<div className='profile__content' aria-hidden='true' onClick={this.profileIconClick}> | ||
<p className='profile__name'>{name}</p> | ||
<span | ||
className='profile__image' | ||
style={{ | ||
backgroundImage: `url(${userImage})`, | ||
}} | ||
/> | ||
<i className='fa fa-ellipsis-v fa-lg' /> | ||
</div> | ||
<div className={showProfile ? 'dropdown-menu show' : 'dropdown-menu'}> | ||
<p className='profile-dropdown__option--name'>{name}</p> | ||
<div className='dropdown-divider' /> | ||
<div> | ||
<span className='fa fa-cog profile-dropdown__icon' /> | ||
<p className='profile-dropdown__option'>Profile</p> | ||
</div> | ||
<div> | ||
<span className='fa fa-sign-out profile-dropdown__icon' /> | ||
<p className='profile-dropdown__option'>Logout</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
} | ||
} | ||
|
||
ProfileComponent.defaultProps = { | ||
name: '', | ||
userImage: '', | ||
className: '', | ||
}; | ||
|
||
ProfileComponent.propTypes = { | ||
name: PropTypes.string, | ||
userImage: PropTypes.string, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default ProfileComponent; |
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
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
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