From 98bed1b7f6f80fc9fa4389198b0298796e7f8641 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Fri, 23 Apr 2021 12:51:14 +0300 Subject: [PATCH] use generated background color for hotbar icons Signed-off-by: Jari Kolehmainen --- package.json | 2 ++ src/renderer/components/hotbar/hotbar-icon.tsx | 17 ++++++++++++++++- yarn.lock | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 378b2428f4..3112bb60db 100644 --- a/package.json +++ b/package.json @@ -262,6 +262,7 @@ "@types/npm": "^2.0.31", "@types/progress-bar-webpack-plugin": "^2.1.0", "@types/proper-lockfile": "^4.1.1", + "@types/randomcolor": "^0.5.5", "@types/react": "^17.0.0", "@types/react-beautiful-dnd": "^13.0.0", "@types/react-dom": "^17.0.0", @@ -326,6 +327,7 @@ "postinstall-postinstall": "^2.1.0", "prettier": "^2.2.0", "progress-bar-webpack-plugin": "^2.1.0", + "randomcolor": "^0.6.2", "raw-loader": "^4.0.1", "react-beautiful-dnd": "^13.0.0", "react-refresh": "^0.9.0", diff --git a/src/renderer/components/hotbar/hotbar-icon.tsx b/src/renderer/components/hotbar/hotbar-icon.tsx index cbf77fba44..2a7476fb39 100644 --- a/src/renderer/components/hotbar/hotbar-icon.tsx +++ b/src/renderer/components/hotbar/hotbar-icon.tsx @@ -12,6 +12,7 @@ import { observable } from "mobx"; import { navigate } from "../../navigation"; import { HotbarStore } from "../../../common/hotbar-store"; import { ConfirmDialog } from "../confirm-dialog"; +import randomColor from "randomcolor"; interface Props extends DOMAttributes { entity: CatalogEntity; @@ -86,6 +87,12 @@ export class HotbarIcon extends React.Component { } } + generateAvatarStyle(entity: CatalogEntity): React.CSSProperties { + return { + "backgroundColor": randomColor({ seed: entity.metadata.name, luminosity: "dark" }) + }; + } + render() { const { entity, errorClass, isActive, @@ -105,7 +112,15 @@ export class HotbarIcon extends React.Component { return (
{entity.metadata.name} - {this.iconString} + + {this.iconString} +