2020-08-13 01:28:25 -07:00
|
|
|
export function messageBubbleColorForString(str) {
|
2020-06-15 13:41:37 -07: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-19 23:22:08 -07:00
|
|
|
|
|
|
|
// Tweak these to adjust the result of the color
|
2020-10-16 17:36:11 -07:00
|
|
|
const saturation = 25;
|
|
|
|
const lightness = 45;
|
|
|
|
const alpha = 0.3;
|
|
|
|
const hue = parseInt(Math.abs(hash), 16) % 360;
|
|
|
|
|
|
|
|
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function textColorForString(str) {
|
|
|
|
let hash = 0;
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tweak these to adjust the result of the color
|
|
|
|
const saturation = 80;
|
|
|
|
const lightness = 80;
|
|
|
|
const alpha = 0.8;
|
2020-09-21 14:14:15 -07:00
|
|
|
const hue = parseInt(Math.abs(hash), 16) % 360;
|
2020-08-19 23:22:08 -07:00
|
|
|
|
|
|
|
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
2020-08-13 01:28:25 -07:00
|
|
|
}
|