Increase contrast in initialjs avatars
Not all the colors initialjs uses by default provide enough contrast against a white text. The default initialjs colors are: ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf", "#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"] We're replacing them with colors containing less luminosity when necessary in order to get a 4,5:1 contrast (it could be argued that a 3:1 contrast is enough when the icons are big, but that isn't always the case and more contrast doesn't hurt): ["#16836d", "#12826c", "#896f06", "#a06608", "#1e8549", "#1e8549", "#b35e14", "#c75000", "#207ab6", "#2779b0", "#de2f1b", "#c0392b", "#9b59b6", "#8e44ad", "#6c767f", "#34495e", "#2c3e50", "#66797a", "#697677", "#d82286", "#c93b8e", "#db310f", "#727755", "#8a6f3d", "#8a6f3d", "#a94136"] Since initialjs doesn't provide a way to change these colors using JavaScript, we're changing them in Ruby, following the same algorithm used by initialjs.
This commit is contained in:
@@ -10,13 +10,20 @@ class Shared::AvatarComponent < ApplicationComponent
|
|||||||
private
|
private
|
||||||
|
|
||||||
def default_options
|
def default_options
|
||||||
{ seed: seed }
|
{ background_color: colors[seed % colors.size] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def options
|
def options
|
||||||
default_options.merge(given_options)
|
default_options.merge(given_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colors
|
||||||
|
["#16836d", "#12826c", "#896f06", "#a06608", "#1e8549", "#1e8549", "#b35e14",
|
||||||
|
"#c75000", "#207ab6", "#2779b0", "#de2f1b", "#c0392b", "#9b59b6", "#8e44ad",
|
||||||
|
"#6c767f", "#34495e", "#2c3e50", "#66797a", "#697677", "#d82286", "#c93b8e",
|
||||||
|
"#db310f", "#727755", "#8a6f3d", "#8a6f3d", "#a94136"]
|
||||||
|
end
|
||||||
|
|
||||||
def seed
|
def seed
|
||||||
record.id
|
record.id
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user