mirror of
https://github.com/revoltchat/revite.git
synced 2025-01-12 23:41:25 -05:00
Update Appearance.tsx
This commit is contained in:
parent
457097ade4
commit
98d1f06ce6
1 changed files with 15 additions and 14 deletions
|
@ -373,13 +373,10 @@ export function Component(props: Props) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
style={`color: ${
|
style={`color: ${getContrastingColour(
|
||||||
theme[x].toUpperCase() === "TRANSPARENT"
|
theme[x],
|
||||||
? getContrastingColour(
|
|
||||||
theme["primary-background"],
|
theme["primary-background"],
|
||||||
)
|
)}`}>
|
||||||
: getContrastingColour(theme[x])
|
|
||||||
}`}>
|
|
||||||
{x}
|
{x}
|
||||||
</span>
|
</span>
|
||||||
<div className={styles.override}>
|
<div className={styles.override}>
|
||||||
|
@ -455,11 +452,15 @@ export const Appearance = connectState(Component, (state) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
function getContrastingColour(hex: string) {
|
function getContrastingColour(hex: string, fallback: string): string {
|
||||||
|
try {
|
||||||
hex = hex.replace("#", "");
|
hex = hex.replace("#", "");
|
||||||
const r = parseInt(hex.substr(0, 2), 16);
|
const r = parseInt(hex.substr(0, 2), 16);
|
||||||
const g = parseInt(hex.substr(2, 2), 16);
|
const g = parseInt(hex.substr(2, 2), 16);
|
||||||
const b = parseInt(hex.substr(4, 2), 16);
|
const b = parseInt(hex.substr(4, 2), 16);
|
||||||
const cc = (r * 299 + g * 587 + b * 114) / 1000;
|
const cc = (r * 299 + g * 587 + b * 114) / 1000;
|
||||||
return cc >= 75 ? "black" : "white";
|
return cc >= 175 ? "black" : "white";
|
||||||
|
} catch (e) {
|
||||||
|
return getContrastingColour(fallback, "#fffff");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue