added new util fun that genearte new unique color for each item.
This commit is contained in:
parent
c5bfacda3b
commit
e5b8ec03df
@ -18,4 +18,34 @@ export const ProjectStatus =(statusId)=>{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for different color for each user
|
||||
export function hashString(str) {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + char;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
// Map a hash value to a Bootstrap background class
|
||||
export function getBgClassFromHash(str) {
|
||||
const bgClasses = [
|
||||
"primary",
|
||||
"secondary",
|
||||
"success",
|
||||
"danger",
|
||||
"warning",
|
||||
"info",
|
||||
"dark",
|
||||
"light",
|
||||
];
|
||||
|
||||
const hash = hashString(str);
|
||||
const index = Math.abs(hash % bgClasses.length);
|
||||
return bgClasses[index];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user