Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Validators/LabelServiceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
namespace OCA\Deck\Validators;

class LabelServiceValidator extends BaseValidator {
protected function hex_color(string $value): bool {
return preg_match('/[A-Fa-f0-9]{6}/', $value) === 1;
}

public function rules() {
return [
'id' => ['numeric'],
'title' => ['not_empty', 'not_null', 'not_false', 'max:100'],
'boardId' => ['numeric', 'not_null'],
'color' => ['not_empty', 'not_null', 'not_false', 'max:6']
'color' => ['not_empty', 'not_null', 'not_false', 'max:6', 'hex_color']
];
}
}
4 changes: 4 additions & 0 deletions src/mixins/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { isDarkTheme } from '@nextcloud/vue'
import chroma from 'chroma-js'

export default {
methods: {
textColor(hex) {
if (!this.colorIsValid(hex)) {
return isDarkTheme ? '#ffffff' : '#000000'
}
return chroma(hex ?? 'ffffff').get('lab.l') > 50 ? '#000000' : '#ffffff'
},
colorIsValid(hex) {
Expand Down
Loading