Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Added support for special casing UnknownPersona coin",
"type": "minor"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its backwards compatible, so can be a patch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it has a (non-breaking) API change, which qualifies it as minor according to https://github.com/OfficeDev/office-ui-fabric-react/blob/master/ghdocs/Contributing/ChangeFiles.md

Any API change should qualify as at least as a minor change. When you add a new API in a backward compatible manner. i.e. Use of the new API is optional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand corrected!

}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class PersonaBase extends BaseComponent<IPersonaProps, {}> {
allowPhoneInitials,
className,
coinProps,
showUnknownPersonaCoin,
coinSize,
getStyles,
imageAlt,
Expand All @@ -72,6 +73,7 @@ export class PersonaBase extends BaseComponent<IPersonaProps, {}> {
const personaCoinProps: IPersonaSharedProps = {
allowPhoneInitials,
coinProps,
showUnknownPersonaCoin,
coinSize,
imageAlt,
imageInitials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export interface IPersonaSharedProps extends React.HTMLAttributes<PersonaBase> {
*/
showSecondaryText?: boolean;

/**
* If true, show the special coin for unknown persona.
* It has '?' in place of initials, with static font and background colors
*/
showUnknownPersonaCoin?: boolean;

/**
* Optional custom persona coin size in pixel.
*/
Expand Down Expand Up @@ -240,6 +246,11 @@ export interface IPersonaCoinStyleProps {
* @defaultvalue PersonaSize.size48
*/
size?: PersonaSize;

/**
* Decides whether to display coin for unknown persona
*/
showUnknownPersonaCoin?: boolean;
}

export interface IPersonaCoinStyles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class PersonaCoinBase extends BaseComponent<IPersonaCoinProps, IPersonaSt
const {
className,
coinProps,
showUnknownPersonaCoin,
coinSize,
getStyles,
imageUrl,
Expand All @@ -105,6 +106,7 @@ export class PersonaCoinBase extends BaseComponent<IPersonaCoinProps, IPersonaSt
theme: theme!,
className: (coinProps && coinProps.className) ? coinProps.className : className,
size,
showUnknownPersonaCoin,
});

return (
Expand All @@ -128,9 +130,7 @@ export class PersonaCoinBase extends BaseComponent<IPersonaCoinProps, IPersonaSt
<div
className={ mergeStyles(
classNames.initials,
{
backgroundColor: initialsColorPropToColorCode(this.props)
}
!showUnknownPersonaCoin && { backgroundColor: initialsColorPropToColorCode(this.props) }
) }
style={ coinSizeStyle }
aria-hidden='true'
Expand Down Expand Up @@ -166,13 +166,15 @@ export class PersonaCoinBase extends BaseComponent<IPersonaCoinProps, IPersonaSt
imageShouldFadeIn,
imageShouldStartVisible,
theme,
showUnknownPersonaCoin,
} = this.props;

const size = this.props.size as PersonaSize;

const classNames = getClassNames(getStyles, {
theme: theme!,
size
size,
showUnknownPersonaCoin
});

return (
Expand All @@ -195,11 +197,12 @@ export class PersonaCoinBase extends BaseComponent<IPersonaCoinProps, IPersonaSt
const {
allowPhoneInitials,
primaryText,
showUnknownPersonaCoin
} = props;

const isRTL = getRTL();

imageInitials = imageInitials || getInitials(primaryText, isRTL, allowPhoneInitials);
imageInitials = (showUnknownPersonaCoin && '?') || imageInitials || getInitials(primaryText, isRTL, allowPhoneInitials);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move the ? to a const


return (
imageInitials !== ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const getStyles = (

const classNames = getGlobalClassNames(GlobalClassNames, theme);

// Static colors used when displaying 'unknown persona' coin
const unknownPersonaBackgroundColor = palette.neutralLight;
const unknownPersonaFontColor = palette.redDark;

return ({
coin: [
classNames.coin,
Expand Down Expand Up @@ -181,9 +185,9 @@ export const getStyles = (
classNames.initials,
{
borderRadius: '50%',
color: palette.white,
color: props.showUnknownPersonaCoin ? unknownPersonaFontColor : palette.white,
fontSize: FontSizes.large,
fontWeight: FontWeights.regular,
fontWeight: props.showUnknownPersonaCoin ? FontWeights.semibold : FontWeights.regular,
lineHeight: '46px',
height: personaSize.size48,

Expand All @@ -198,6 +202,10 @@ export const getStyles = (
}
},

props.showUnknownPersonaCoin && {
backgroundColor: unknownPersonaBackgroundColor
},

(size.isSize16 || size.isSize24 || size.isSize28) && {
fontSize: FontSizes.xSmall,
},
Expand Down