diff --git a/src/helpers/color/randomColor.ts b/src/helpers/color/randomColor.ts new file mode 100644 index 000000000..c729d4e17 --- /dev/null +++ b/src/helpers/color/randomColor.ts @@ -0,0 +1,20 @@ + +const COLORS = [ + '#ffbe0b', + '#fd8a09', + '#fb5607', + '#ff006e', + '#efbdeb', + '#8338ec', + '#5f5ff6', + '#3a86ff', + '#4c91ff', + '#0ead69', + '#25be8b', + '#073b4c', + '#373f47', +] + +export function getRandomColorHex(): string { + return COLORS[Math.floor(Math.random() * COLORS.length)] +} diff --git a/src/models/label.ts b/src/models/label.ts index de524ac46..89b20b251 100644 --- a/src/models/label.ts +++ b/src/models/label.ts @@ -5,15 +5,14 @@ import type {ILabel} from '@/modelTypes/ILabel' import type {IUser} from '@/modelTypes/IUser' import {colorIsDark} from '@/helpers/color/colorIsDark' - -const DEFAULT_LABEL_BACKGROUND_COLOR = 'e8e8e8' +import {getRandomColorHex} from '@/helpers/color/randomColor' export default class LabelModel extends AbstractModel implements ILabel { id = 0 title = '' // FIXME: this should be empty and be definied in the client. // that way it get's never send to the server db and is easier to change in future versions. - hexColor = DEFAULT_LABEL_BACKGROUND_COLOR + hexColor = '' description = '' createdBy: IUser projectId = 0 @@ -25,6 +24,10 @@ export default class LabelModel extends AbstractModel implements ILabel constructor(data: Partial = {}) { super() this.assignData(data) + + if (this.hexColor === '') { + this.hexColor = getRandomColorHex() + } if (this.hexColor.substring(0, 1) !== '#') { this.hexColor = '#' + this.hexColor