I need to change the color of the text in a span based upon the external value of an assigned department. I have an application where a company can upload an employee roster with the department the person is assigned and I want to color-code all of the employees that are in the same department. I do not know what the department names are until the spreadsheet is uploaded and the color does not matter as long as it is different between departments and consistent. I have colors added as a class. But currently not using them as a class
.kelly-vivid-yellow { color: #FFB300; }
.kelly-strong-purple { color: #803E75; }
.kelly-vivid-orange { color: #FF6800; }
.kelly-very-light-blue { color: #A6BDD7; }
.kelly-vivid-red { color: #C10020; }
.kelly-grayish-yellow { color: #CEA262; }
.kelly-medium-gray { color: #817066; }
plus others.
the Department names could be;
Admin
Grounds
Management
Staff
etc
or
Department One
Department Two
Department Three
etc
or anything else
I was thinking to add all of the colors to an array such as
kellyColors = ["#FFB300;","#803E75;","#FF6800;","#A6BDD7;" etc]
and assign a color to the the department. I ws going to add all of the departments to an array and based upon the position in the array I was going to assign it a color.
departments = ["Admin","Grounds","Management","Staff"]
let Admin = kellyColor[0]; // Admin position in array is 0
let Grounds = kellyColor[1]; // Grounds position in array is 1
etc
but I don't know how to change the color attribute in the span that I'm using as a regex replace in a JavaScript function
this.pubmedData[index]["publication"] = this.pubmedData[index]
["publication"].replace(new RegExp(Employee_Name), match => {
return '<span style="color:#803E75;"><b>' + match + '</b></span>';
});
All suggestions are appreciated
FYI-- this.pubmedData[index]["publication"] is an array that holds information where the name of the employee needs to be color changed. It could be something like:
John Smith and Bob Jones had Friday off.
And I need to color code the Employee names to show are they in the same department or different
this.pubmedData[index]["publication"]
could you please provide a sample console.log for this? – Commander