feat(labels): assign random color when creating labels
Resolves F-591 Related discussion: https://community.vikunja.io/t/assign-a-random-color-to-a-new-label/348/7
This commit is contained in:
parent
9c46d064ac
commit
3f3d4b1682
20
src/helpers/color/randomColor.ts
Normal file
20
src/helpers/color/randomColor.ts
Normal file
@ -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)]
|
||||
}
|
@ -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<ILabel> 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<ILabel> implements ILabel
|
||||
constructor(data: Partial<ILabel> = {}) {
|
||||
super()
|
||||
this.assignData(data)
|
||||
|
||||
if (this.hexColor === '') {
|
||||
this.hexColor = getRandomColorHex()
|
||||
}
|
||||
|
||||
if (this.hexColor.substring(0, 1) !== '#') {
|
||||
this.hexColor = '#' + this.hexColor
|
||||
|
Loading…
x
Reference in New Issue
Block a user