You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
868 B
31 lines
868 B
export function messageBubbleColorForString(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 = 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; |
|
const hue = parseInt(Math.abs(hash), 16) % 360; |
|
|
|
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`; |
|
}
|
|
|