diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index a6f69326d..c91a6c727 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -76,3 +76,23 @@ $(document).on('click', 'a[rel*=external]', function(e) { e.preventDefault(); window.open(this.href, '_blank', 'noopener'); }); + +window.isColorBright = function(color) { + if (!color) return true; + + if (color.startsWith('#')) { + color = color.slice(1); + } + + if (color.length === 3) { + color = color.split('').map((c) => c + c).join(''); + } + + const r = parseInt(color.substr(0, 2), 16); + const g = parseInt(color.substr(2, 2), 16); + const b = parseInt(color.substr(4, 2), 16); + + const brightness = (r * 299 + g * 587 + b * 114) / 1000; + + return brightness > 180 ? true : false; +}; diff --git a/app/javascript/vue/my_modules/modals/tags.vue b/app/javascript/vue/my_modules/modals/tags.vue index f24d11a66..b0dbd81f1 100644 --- a/app/javascript/vue/my_modules/modals/tags.vue +++ b/app/javascript/vue/my_modules/modals/tags.vue @@ -37,10 +37,10 @@
{{ tag.attributes.name }}
@@ -325,6 +325,9 @@ export default { this.setRandomColor(); }); }, + tagTextColor(color) { + return window.isColorBright(color) ? 'text-black' : 'text-white'; + }, cancelCreating(e) { if (e && e.target.closest('.sn-dropdown')) return; diff --git a/app/javascript/vue/my_modules/renderers/tags.vue b/app/javascript/vue/my_modules/renderers/tags.vue index 0a3174a0b..b7c3836ab 100644 --- a/app/javascript/vue/my_modules/renderers/tags.vue +++ b/app/javascript/vue/my_modules/renderers/tags.vue @@ -5,7 +5,8 @@