forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevDocs: Add UserItem component. (Automattic#24230)
- Loading branch information
1 parent
5a4e97d
commit a323cb2
Showing
5 changed files
with
53 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## UserItem | ||
|
||
`UserItem` displays the Gravatar and username of the current user. It takes only one prop: | ||
a user object with a `name` property for the display name. | ||
|
||
### Usage | ||
|
||
```js | ||
export default class extends React.Component { | ||
render() { | ||
return ( | ||
<UserItem user={ currentUser } /> | ||
); | ||
} | ||
} | ||
``` |
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,33 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import UserItem from '../index'; | ||
import { getCurrentUser } from 'state/current-user/selectors'; | ||
|
||
const UserItemExample = ( { currentUser } ) => { | ||
return <UserItem user={ currentUser } />; | ||
}; | ||
|
||
const ConnectedUserItemExample = connect( state => { | ||
const user = getCurrentUser( state ); | ||
if ( ! user ) { | ||
return {}; | ||
} | ||
const currentUser = Object.assign( {}, user, { name: user.display_name } ); | ||
|
||
return { | ||
currentUser, | ||
}; | ||
} )( UserItemExample ); | ||
|
||
ConnectedUserItemExample.displayName = 'UserItem'; | ||
|
||
export default ConnectedUserItemExample; |
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