-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3992 from StevenSmith-code/WV-312-replace-placeho…
…lder-avatar-with-candidate-initials [WV-312] replace placeholder avatar with candidate initials [TEAM REVIEW]
- Loading branch information
Showing
11 changed files
with
97 additions
and
43 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import DesignTokenColors from '../components/Style/DesignTokenColors'; | ||
|
||
function speakerDisplayNameToAvatarColor (speakerDisplayName) { | ||
let hashForRandomIndexValue = 0; | ||
/* eslint-disable no-bitwise */ | ||
for (let i = 0; i < speakerDisplayName.length; i += 1) { | ||
hashForRandomIndexValue = | ||
speakerDisplayName.charCodeAt(i) + | ||
((hashForRandomIndexValue << 5) - hashForRandomIndexValue); | ||
} | ||
const avatarColorKeys = Object.keys(DesignTokenColors).filter((key) => key.startsWith('avatar')); | ||
/* eslint-enable no-bitwise */ | ||
if (avatarColorKeys.length === 0) { | ||
console.error('No avatar colors found in DesignTokenColors.'); | ||
return DesignTokenColors.avatarBlue700; | ||
} | ||
const colorIndex = Math.abs(hashForRandomIndexValue) % avatarColorKeys.length; | ||
const colorKey = avatarColorKeys[colorIndex]; | ||
return DesignTokenColors[colorKey]; | ||
} | ||
|
||
export default speakerDisplayNameToAvatarColor; |
Oops, something went wrong.