From 5ad4485c6416782efb5a7626e0681563c92a2985 Mon Sep 17 00:00:00 2001 From: Ryan Alexander <38785445+ryanalexander@users.noreply.github.com> Date: Tue, 17 Aug 2021 19:30:41 +1000 Subject: [PATCH] Transparent will now fallback to the contrasting colour of background https://github.com/revoltchat/revite/issues/88 --- src/pages/settings/panes/Appearance.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/panes/Appearance.tsx b/src/pages/settings/panes/Appearance.tsx index 9cf9ef9c..7ad56cb1 100644 --- a/src/pages/settings/panes/Appearance.tsx +++ b/src/pages/settings/panes/Appearance.tsx @@ -372,7 +372,16 @@ export function Component(props: Props) { } /> - {x} + + {x} +
{ }; }); -function getContrastingColour(hex: string){ +function getContrastingColour(hex: string) { hex = hex.replace("#", ""); - const r = parseInt(hex.substr(0,2),16); - const g = parseInt(hex.substr(2,2),16); - const b = parseInt(hex.substr(4,2),16); - const cc = ((r*299)+(g*587)+(b*114))/1000; - return (cc >= 128) ? 'black' : 'white'; + const r = parseInt(hex.substr(0, 2), 16); + const g = parseInt(hex.substr(2, 2), 16); + const b = parseInt(hex.substr(4, 2), 16); + const cc = (r * 299 + g * 587 + b * 114) / 1000; + return cc >= 128 ? "black" : "white"; }