mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 09:23:51 +00:00
4872cd0a48
* feat: colorise spreadSheet with rundown color * feat: add colorisation in spreadsheet for block * feat: border color * fix: cleanup accessible color * fix: review before merge (https://github.com/cpvalente/ontime/pull/1608) * fix: usgae of map instead foreach (https://github.com/cpvalente/ontime/pull/1608) * Update apps/server/src/services/sheet-service/SheetService.ts Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com> * fix: comment condition * fix: Remove Color plugin (but don't can get color like 'red' or 'black') * fix: isLight for more clean code * fix: remove map on isLight function * fix: remove debug logger * refactor colour * lint --------- Co-authored-by: Gwenitora <gwenitora.gardu74@gmail.com> Co-authored-by: Gwenitora <61121870+Gwenitora@users.noreply.github.com> Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { RGBColour } from 'ontime-types';
|
||
import { colourToHex, cssOrHexToColour, isLightColour, mixColours } from 'ontime-utils';
|
||
|
||
type ColourCombination = {
|
||
backgroundColor: string;
|
||
color: string;
|
||
};
|
||
|
||
const defaultUiBackground: RGBColour = { red: 26, green: 26, blue: 26, alpha: 1 };
|
||
/**
|
||
* @description Selects text colour to maintain accessible contrast
|
||
* @param bgColour
|
||
* @return {{backgroundColor, color: string}}
|
||
*/
|
||
export const getAccessibleColour = (bgColour?: string): ColourCombination => {
|
||
if (!bgColour) return { backgroundColor: '#1a1a1a', color: '#fffffa' };
|
||
|
||
const originalColour = cssOrHexToColour(bgColour);
|
||
if (!originalColour) return { backgroundColor: '#1a1a1a', color: '#fffffa' };
|
||
|
||
const backgroundColorMix = mixColours(defaultUiBackground, originalColour, 1 - originalColour.alpha);
|
||
const textColor = isLightColour(backgroundColorMix) ? 'black' : '#fffffa';
|
||
|
||
return { backgroundColor: colourToHex(backgroundColorMix), color: textColor };
|
||
};
|
||
|
||
/**
|
||
* @description Creates a list of classnames from array of css module conditions
|
||
* @param classNames - css modules objects
|
||
*/
|
||
export const cx = (classNames: any[]) => classNames.filter(Boolean).join(' ');
|
||
|
||
export const enDash = '–';
|
||
|
||
export const timerPlaceholder = '––:––:––';
|
||
export const timerPlaceholderMin = '––:––';
|
||
|
||
/**
|
||
* Adds opacity to a given colour if possible
|
||
*/
|
||
export function alpha(colour: string, amount: number): string {
|
||
const originalColour = cssOrHexToColour(colour);
|
||
if (!originalColour) return colour;
|
||
originalColour.alpha = amount;
|
||
return colourToHex(originalColour);
|
||
}
|