Files
ontime/apps/client/src/common/utils/styleUtils.ts
T
Alex Christoffer Rasmussen 4872cd0a48 Colorised spreadsheet (#1643)
* 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>
2025-06-24 22:38:03 +02:00

47 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}