-
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 5 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,39 @@ export class PersonaCoin extends React.Component<IPersonaProps, IPersonaState> { | |
); | ||
} | ||
|
||
@autobind | ||
private _onRenderCoin(props: IPersonaProps, size: number): JSX.Element | null { | ||
if (props.onRenderCoin) { | ||
return props.onRenderCoin(this.props); | ||
} | ||
|
||
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,55 @@ | ||
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 in place of persona coin's image</div> | ||
<Persona | ||
{ ...examplePersona } | ||
size={ PersonaSize.size72 } | ||
presence={ PersonaPresence.online } | ||
onRenderCoin={ this._onRenderCoin } | ||
imageAlt={ 'Custom Coin Image' } | ||
coinSize={ 72 } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
@autobind | ||
private _onRenderCoin(props: IPersonaProps): JSX.Element { | ||
let { | ||
coinSize, | ||
imageUrl, | ||
imageAlt, | ||
} = props; | ||
|
||
return ( | ||
<div className='custom-example-coin'> | ||
<img src={ imageUrl } alt={ imageAlt } width={ coinSize } height={ coinSize } /> | ||
</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