SDA-3237 Additional colors use-cases

This commit is contained in:
sbenmoussati 2021-08-04 17:43:51 +02:00
parent bd419ca302
commit 019f530044
4 changed files with 82 additions and 14 deletions

View File

@ -23,11 +23,15 @@ const Colors = {
regularFlashingNotificationBgColor: '#27588e', regularFlashingNotificationBgColor: '#27588e',
notificationBackgroundColor: '#27292c', notificationBackgroundColor: '#27292c',
notificationBorderColor: '#717681', notificationBorderColor: '#717681',
mentionBackgroundColor: '#99342c',
mentionBorderColor: '#ff5d50',
}, },
light: { light: {
regularFlashingNotificationBgColor: '#aad4f8', regularFlashingNotificationBgColor: '#aad4f8',
notificationBackgroundColor: '#f1f1f3', notificationBackgroundColor: '#f1f1f3',
notificationBorderColor: 'transparent', notificationBorderColor: 'transparent',
mentionBackgroundColor: '#fcc1b9',
mentionBorderColor: 'transparent',
}, },
}; };
@ -460,9 +464,23 @@ export default class NotificationComp extends React.Component<
const { theme, flash, isExternal, hasMention, color } = this.state; const { theme, flash, isExternal, hasMention, color } = this.state;
const currentColors = const currentColors =
theme === Themes.DARK ? { ...Colors.dark } : { ...Colors.light }; theme === Themes.DARK ? { ...Colors.dark } : { ...Colors.light };
const externalFlashingBackgroundColor =
theme === Themes.DARK ? '#70511f' : '#f6e5a6';
if (flash && theme) { if (flash && theme) {
if (isExternal) { if (isExternal) {
currentColors.notificationBorderColor = '#F7CA3B'; if (!hasMention) {
currentColors.notificationBorderColor = '#F7CA3B';
currentColors.notificationBackgroundColor = externalFlashingBackgroundColor;
if (this.isCustomColor(color)) {
currentColors.notificationBorderColor = this.getThemedCustomBorderColor(
theme,
color,
);
currentColors.notificationBackgroundColor = color;
}
} else {
currentColors.notificationBorderColor = '#F7CA3B';
}
} else if (hasMention) { } else if (hasMention) {
currentColors.notificationBorderColor = currentColors.notificationBorderColor =
currentColors.notificationBorderColor; currentColors.notificationBorderColor;
@ -474,13 +492,26 @@ export default class NotificationComp extends React.Component<
? color ? color
: currentColors.regularFlashingNotificationBgColor; : currentColors.regularFlashingNotificationBgColor;
currentColors.notificationBorderColor = this.isCustomColor(color) currentColors.notificationBorderColor = this.isCustomColor(color)
? color ? this.getThemedCustomBorderColor(theme, color)
: theme === Themes.DARK : theme === Themes.DARK
? '#2996fd' ? '#2996fd'
: 'transparent'; : 'transparent';
} }
} else if (!flash && color) { } else if (!flash) {
currentColors.notificationBackgroundColor = currentColors.notificationBorderColor = color; if (hasMention) {
currentColors.notificationBackgroundColor =
currentColors.mentionBackgroundColor;
currentColors.notificationBorderColor =
currentColors.mentionBorderColor;
} else if (this.isCustomColor(color)) {
currentColors.notificationBackgroundColor = color;
currentColors.notificationBorderColor = this.getThemedCustomBorderColor(
theme,
color,
);
} else if (isExternal) {
currentColors.notificationBorderColor = '#F7CA3B';
}
} }
return currentColors; return currentColors;
} }
@ -548,4 +579,44 @@ export default class NotificationComp extends React.Component<
} }
return false; return false;
} }
/**
* Function that allows to increase color brightness
* @param hex hes color
* @param percent percent
* @returns new hex color
*/
private increaseBrightness(hex: string, percent: number) {
// strip the leading # if it's there
hex = hex.replace(/^\s*#|\s*$/g, '');
const r = parseInt(hex.substr(0, 2), 16);
const g = parseInt(hex.substr(2, 2), 16);
const b = parseInt(hex.substr(4, 2), 16);
return (
'#' +
// tslint:disable-next-line: no-bitwise
(0 | ((1 << 8) + r + ((256 - r) * percent) / 100))
.toString(16)
.substr(1) +
// tslint:disable-next-line: no-bitwise
(0 | ((1 << 8) + g + ((256 - g) * percent) / 100))
.toString(16)
.substr(1) +
// tslint:disable-next-line: no-bitwise
(0 | ((1 << 8) + b + ((256 - b) * percent) / 100)).toString(16).substr(1)
);
}
/**
* Returns custom border color
* @param theme current theme
* @param customColor color
* @returns custom border color
*/
private getThemedCustomBorderColor(theme: string, customColor: string) {
return theme === Themes.DARK
? this.increaseBrightness(customColor, 50)
: 'transparent';
}
} }

View File

@ -143,13 +143,14 @@ body {
cursor: default; cursor: default;
text-overflow: ellipsis; text-overflow: ellipsis;
color: var(--text-color); color: var(--text-color);
white-space: pre-line;
} }
} }
} }
} }
.external-border { .external-border {
border: 2px solid #f7ca3b !important; border: 2px solid #f7ca3b;
} }
.header:lang(fr-FR) { .header:lang(fr-FR) {

View File

@ -64,19 +64,15 @@
} }
@keyframes light-ext-flashing { @keyframes light-ext-flashing {
0% {
background-color: @light-notification-bg-color;
}
50% { 50% {
background-color: @light-external-flash-mention-bg-color; background-color: @light-notification-bg-color;
border-color: @light-external-flash-border-color;
} }
} }
@keyframes dark-ext-flashing { @keyframes dark-ext-flashing {
0% {
background-color: @dark-notification-bg-color;
}
50% { 50% {
background-color: @dark-external-flash-bg-color; background-color: @dark-notification-bg-color;
border-color: @dark-external-flash-border-color;
} }
} }

View File

@ -14,4 +14,4 @@
@light-mention-flash-mention-bg-color: #fcc1b9; @light-mention-flash-mention-bg-color: #fcc1b9;
@light-mention-flash-border-color: #ff5d50; @light-mention-flash-border-color: #ff5d50;
@light-external-flash-border-color: #f7ca3b; @light-external-flash-border-color: #f7ca3b;
@light-external-flash-mention-bg-color: #f6e5a6; @light-external-flash-bg-color: #f6e5a6;