Skip to content

Instantly share code, notes, and snippets.

@lloydjatkinson
Last active July 12, 2019 22:31
Show Gist options
  • Save lloydjatkinson/518c1e00c75cb9ebb3fe92b29c3b2503 to your computer and use it in GitHub Desktop.
Save lloydjatkinson/518c1e00c75cb9ebb3fe92b29c3b2503 to your computer and use it in GitHub Desktop.
const simpleMaterialDesignPalette = [
'#F44336', // Red 500
'#E91E63', // Pink 500
'#9C27B0', // Purple 500
'#673AB7', // Deep Purple 500
'#3F51B5', // Indigo 500
'#2196F3', // Blue 500
'#03A9F4', // Light Blue 500
'#00BCD4', // Cyan 500
'#009688', // Teal 500
'#4CAF50', // Green 500
'#8BC34A', // Light Green 500
'#CDDC39', // Lime 500
'#FFEB3B', // Yellow 500
'#FFC107', // Amber 500
'#FF9800', // Ornage 500
'#FF5722', // Deep Orange 500,
'#9E9E9E', // Grey 500
'#607D8B', // Blue Grey 500
];
const textValue = initials => initials.charCodeAt(0) + (initials.charCodeAt(1) || 0 );
const paletteIndex = (textValue, paletteCount) => textValue % paletteCount;
const assignColourToInitials = initials => {
if (!initials) return '#000000';
return simpleMaterialDesignPalette[paletteIndex(textValue(initials), simpleMaterialDesignPalette.length)];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment