mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	fix: MultiPurposeLabel text color (#3485)
This commit is contained in:
		| @@ -8,8 +8,11 @@ | |||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| import { computed, defineComponent } from "@nuxtjs/composition-api"; | import { computed, defineComponent } from "@nuxtjs/composition-api"; | ||||||
|  | // @ts-ignore missing color types | ||||||
|  | import Color from "@sphinxxxx/color-conversion"; | ||||||
| import { MultiPurposeLabelSummary } from "~/lib/api/types/recipe"; | import { MultiPurposeLabelSummary } from "~/lib/api/types/recipe"; | ||||||
|  |  | ||||||
|  |  | ||||||
| export default defineComponent({ | export default defineComponent({ | ||||||
|   props: { |   props: { | ||||||
|     label: { |     label: { | ||||||
| @@ -34,11 +37,15 @@ export default defineComponent({ | |||||||
|     const ACCESSIBILITY_THRESHOLD = 0.179; |     const ACCESSIBILITY_THRESHOLD = 0.179; | ||||||
|  |  | ||||||
|     function pickTextColorBasedOnBgColorAdvanced(bgColor: string, lightColor: string, darkColor: string) { |     function pickTextColorBasedOnBgColorAdvanced(bgColor: string, lightColor: string, darkColor: string) { | ||||||
|       const color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor; |       try { | ||||||
|       const r = parseInt(color.substring(0, 2), 16); // hexToR |         const color = new Color(bgColor); | ||||||
|       const g = parseInt(color.substring(2, 4), 16); // hexToG |  | ||||||
|       const b = parseInt(color.substring(4, 6), 16); // hexToB |         // if opacity is less than 0.3 always return dark color | ||||||
|       const uicolors = [r / 255, g / 255, b / 255]; |         if (color._rgba[3] < 0.3) { | ||||||
|  |           return darkColor; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const uicolors = [color._rgba[0] / 255, color._rgba[1] / 255, color._rgba[2] / 255]; | ||||||
|         const c = uicolors.map((col) => { |         const c = uicolors.map((col) => { | ||||||
|           if (col <= 0.03928) { |           if (col <= 0.03928) { | ||||||
|             return col / 12.92; |             return col / 12.92; | ||||||
| @@ -47,6 +54,10 @@ export default defineComponent({ | |||||||
|         }); |         }); | ||||||
|         const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]; |         const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]; | ||||||
|         return L > ACCESSIBILITY_THRESHOLD ? darkColor : lightColor; |         return L > ACCESSIBILITY_THRESHOLD ? darkColor : lightColor; | ||||||
|  |       } catch (error) { | ||||||
|  |         console.warn(error); | ||||||
|  |         return "black"; | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user