-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Persona - onRenderCoin prop #3799
Changes from 2 commits
9936cf4
ae70398
9c8081d
d1f84be
8191668
dc6e620
9f69787
2b1dc7c
8416d7c
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ import { | |
divProperties, | ||
getInitials, | ||
getNativeProps, | ||
getRTL | ||
getRTL, | ||
IRenderFunction | ||
} from '../../Utilities'; | ||
import { Image, ImageFit, ImageLoadState } from '../../Image'; | ||
import { PersonaPresence } from './PersonaPresence'; | ||
|
@@ -114,17 +115,7 @@ export class PersonaCoin extends React.Component<IPersonaProps, IPersonaState> { | |
</div> | ||
) | ||
} | ||
<Image | ||
className={ css('ms-Persona-image', styles.image) } | ||
imageFit={ ImageFit.cover } | ||
src={ imageUrl } | ||
width={ coinSize || SIZE_TO_PIXELS[size] } | ||
height={ coinSize || SIZE_TO_PIXELS[size] } | ||
alt={ imageAlt } | ||
shouldFadeIn={ imageShouldFadeIn } | ||
shouldStartVisible={ imageShouldStartVisible } | ||
onLoadingStateChange={ this._onPhotoLoadingStateChange } | ||
/> | ||
{ this._onRenderCoin( this.props, size ) } | ||
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.
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. Ah nice! yeah that's much cleaner thank you so much! |
||
<PersonaPresence { ...this.props } /> | ||
</div> | ||
) : | ||
|
@@ -143,6 +134,44 @@ export class PersonaCoin extends React.Component<IPersonaProps, IPersonaState> { | |
); | ||
} | ||
|
||
@autobind | ||
private _onRenderCoin(props: IPersonaProps, size: number): JSX.Element { | ||
if (props.onRenderCoin) { | ||
console.log(size); | ||
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. Probably wasn't meant to be included in the commit. 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. Yes, I'll clean that up. I was attempting to make a slightly better example to show. If you have any ideas on that let me know. |
||
return( | ||
<div> | ||
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. Does the Coin need to be wrapped in these 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. I think the change I just committed is a bit cleaner. The div can be removed if a null return from _onRenderCoin is allowed which would just print nothing. |
||
{ props.onRenderCoin(this.props) } | ||
</div> | ||
); | ||
} | ||
|
||
let { | ||
coinProps, | ||
coinSize, | ||
imageUrl, | ||
imageAlt, | ||
initialsColor, | ||
primaryText, | ||
imageShouldFadeIn, | ||
onRenderInitials = this._onRenderInitials, | ||
imageShouldStartVisible | ||
} = this.props; | ||
|
||
return( | ||
<Image | ||
className={ css('ms-Persona-image', styles.image) } | ||
imageFit={ ImageFit.cover } | ||
src={ imageUrl } | ||
width={ coinSize || SIZE_TO_PIXELS[size] } | ||
height={ coinSize || SIZE_TO_PIXELS[size] } | ||
alt={ imageAlt } | ||
shouldFadeIn={ imageShouldFadeIn } | ||
shouldStartVisible={ imageShouldStartVisible } | ||
onLoadingStateChange={ this._onPhotoLoadingStateChange } | ||
/> | ||
); | ||
} | ||
|
||
@autobind | ||
private _onRenderInitials(props: IPersonaProps): JSX.Element { | ||
let { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from 'react'; | ||
import { autobind } from 'office-ui-fabric-react/lib/Utilities'; | ||
import { | ||
IPersonaProps, | ||
Persona, | ||
PersonaSize, | ||
PersonaPresence | ||
} from 'office-ui-fabric-react/lib/Persona'; | ||
import { Icon } from 'office-ui-fabric-react/lib/Icon'; | ||
import { TestImages } from '../../../common/TestImages'; | ||
import './PersonaExample.scss'; | ||
import * as exampleStylesImport from '../../../common/_exampleStyles.scss'; | ||
const exampleStyles: any = exampleStylesImport; | ||
|
||
const examplePersona = { | ||
imageUrl: TestImages.personaMale, | ||
imageInitials: 'TR', | ||
primaryText: 'Ted Randall', | ||
secondaryText: 'Project Manager', | ||
optionalText: 'Available at 4:00pm' | ||
}; | ||
|
||
export class PersonaCustomCoinRenderExample extends React.Component { | ||
|
||
public render() { | ||
return ( | ||
<div className='ms-PersonaExample'> | ||
<div className={ exampleStyles.exampleLabel }>Custom functional element as image</div> | ||
<Persona | ||
{ ...examplePersona } | ||
size={ PersonaSize.size72 } | ||
presence={ PersonaPresence.online } | ||
onRenderCoin={ this._onRenderCoin } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
@autobind | ||
private _onRenderSecondaryText(props: IPersonaProps): JSX.Element { | ||
return ( | ||
<div> | ||
<Icon iconName={ 'Suitcase' } className={ 'ms-JobIconExample' } /> | ||
{ props.secondaryText } | ||
</div> | ||
); | ||
} | ||
|
||
@autobind | ||
private _onRenderCoin(props: IPersonaProps): JSX.Element { | ||
return ( | ||
<div className='custom-example-coin'> | ||
<img src={ props.imageUrl } alt='' width='72' height='72' /> | ||
</div> | ||
); | ||
} | ||
} |
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.
IRenderFunction
isn't used