2020-08-13 10:28:25 +02:00
|
|
|
export function messageBubbleColorForString(str) {
|
2020-06-15 22:41:37 +02:00
|
|
|
let hash = 0;
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
}
|
2020-08-20 08:22:08 +02:00
|
|
|
|
|
|
|
// Tweak these to adjust the result of the color
|
2020-09-21 22:55:25 +02:00
|
|
|
const saturation = 75;
|
|
|
|
const lightness = 65;
|
2020-08-20 08:22:08 +02:00
|
|
|
const alpha = 1.0;
|
2020-09-21 23:14:15 +02:00
|
|
|
const hue = parseInt(Math.abs(hash), 16) % 360;
|
2020-08-20 08:22:08 +02:00
|
|
|
|
|
|
|
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
2020-08-13 10:28:25 +02:00
|
|
|
}
|