Browse Source

add backgroundColor

visuddhinanda 2 years ago
parent
commit
6abe5b1d9a
1 changed files with 11 additions and 1 deletions
  1. 11 1
      dashboard/src/components/auth/Studio.tsx

+ 11 - 1
dashboard/src/components/auth/Studio.tsx

@@ -2,6 +2,7 @@ import { Avatar, Space } from "antd";
 
 
 import StudioCard from "./StudioCard";
 import StudioCard from "./StudioCard";
 
 
+const avatarColor = ["indianred", "blueviolet", "#87d068", "#108ee9"];
 export interface IStudio {
 export interface IStudio {
   id: string;
   id: string;
   nickName?: string;
   nickName?: string;
@@ -23,6 +24,11 @@ const StudioWidget = ({
   popOver,
   popOver,
   onClick,
   onClick,
 }: IWidget) => {
 }: IWidget) => {
+  let colorIndex = 0;
+  if (data?.nickName) {
+    colorIndex = data?.nickName?.charCodeAt(0) % avatarColor.length;
+  }
+
   return (
   return (
     <StudioCard popOver={popOver} studio={data}>
     <StudioCard popOver={popOver} studio={data}>
       <Space
       <Space
@@ -35,7 +41,11 @@ const StudioWidget = ({
         {hideAvatar ? (
         {hideAvatar ? (
           <></>
           <></>
         ) : (
         ) : (
-          <Avatar size="small" src={data?.avatar}>
+          <Avatar
+            size="small"
+            src={data?.avatar}
+            style={{ backgroundColor: avatarColor[colorIndex] }}
+          >
             {data?.nickName?.slice(0, 2)}
             {data?.nickName?.slice(0, 2)}
           </Avatar>
           </Avatar>
         )}
         )}