From b458ac478001a7713e0ddad8b3065c3b7940e193 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Fri, 18 Apr 2025 19:44:05 +0530 Subject: [PATCH] added new util fun that genearte new unique color for each item. --- src/utils/projectStatus.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/utils/projectStatus.js b/src/utils/projectStatus.js index 306359e4..771c6294 100644 --- a/src/utils/projectStatus.js +++ b/src/utils/projectStatus.js @@ -18,4 +18,34 @@ export const ProjectStatus =(statusId)=>{ default: break; } -} \ No newline at end of file +} + + +// 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]; + } + \ No newline at end of file