Files
UT-Registration-Plus/src/shared/util/updateBadgeText.ts
Razboy20 5ed81e4be9 feat: course color generation (#179)
* feat: course color generation

* feat: add proper TS for hex colors

* refactor: fix oklab and improve contrast ratios

* fix: update HexColor type

* refactor: update color switch point

* refactor: color-related functions and types

* fix: imports and TS issues

* fix: imports and TS issues

* chore: add no-restricted-syntax ForInStatement

* chore(docs): add jsdoc

---------

Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
2024-03-19 18:54:11 -05:00

35 lines
1.2 KiB
TypeScript

import { colors } from '../types/ThemeColors';
import { MILLISECOND } from './time';
/** How long should we flash the badge when it changes value */
export const POPUP_FLASH_TIME = 200 * MILLISECOND;
/** The maximum number to show in the badge, after which we show a '+' */
export const BADGE_LIMIT = 10;
/**
* Updates the badge text based on the given value.
* If the value is greater than the badge limit, it sets the badge text to the badge limit followed by a '+'.
* @param value - The value to be displayed in the badge.
*/
export default function updateBadgeText(value: number): void {
let badgeText = '';
if (value > 0) {
if (value > BADGE_LIMIT) {
badgeText = `${BADGE_LIMIT}+`;
} else {
badgeText = `${value}`;
}
}
chrome.action.setBadgeText({ text: badgeText });
flashBadgeColor();
}
/**
* Flashes the badge color by setting the badge background color to a color and then resetting it after a short delay.
*/
function flashBadgeColor() {
chrome.action.setBadgeBackgroundColor({ color: colors.ut.burntorange });
setTimeout(() => chrome.action.setBadgeBackgroundColor({ color: colors.ut.orange }), POPUP_FLASH_TIME);
}