vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 1.86 kB
Source Map (JSON)
{"version":3,"file":"useTextColor.mjs","sources":["../../../../src/composables/useTextColor.ts"],"sourcesContent":["import { computed, getCurrentInstance, Ref, unref } from 'vue'\n\nimport { isColorTransparent, useColors } from './useColors'\n\ntype PropsType = {\n textColor: string,\n color?: string\n}\n\n/**\n * @param componentColor component color. By default `props.color`. If undefined passed in ref, `currentColor` will be returned.\n * @param isTransparent if transparent will return component color as text color.\n * @returns Computed text color based on component's color if `props.textColor` if provided.\n */\nexport const useTextColor = (componentColor?: Ref<string | undefined> | string | undefined, isTransparent: boolean | Ref<boolean> = false) => {\n const { props } = getCurrentInstance() as unknown as { props: PropsType }\n const { getColor, getTextColor } = useColors()\n\n const textColorComputed = computed(() => {\n if (props.textColor) { return getColor(props.textColor) }\n\n const bg = componentColor ? unref(componentColor) : props.color\n\n if (!bg) { return 'currentColor' }\n\n const componentColorHex = getColor(bg)\n\n if (isColorTransparent(componentColorHex)) { return 'currentColor' }\n\n return unref(isTransparent) ? componentColorHex : getColor(getTextColor(componentColorHex))\n })\n\n return { textColorComputed }\n}\n"],"names":[],"mappings":";;;AAcO,MAAM,eAAe,CAAC,gBAA+D,gBAAwC,UAAU;AACtI,QAAA,EAAE,UAAU;AAClB,QAAM,EAAE,UAAU,aAAa,IAAI,UAAU;AAEvC,QAAA,oBAAoB,SAAS,MAAM;AACvC,QAAI,MAAM,WAAW;AAAS,aAAA,SAAS,MAAM,SAAS;AAAA,IAAE;AAExD,UAAM,KAAK,iBAAiB,MAAM,cAAc,IAAI,MAAM;AAE1D,QAAI,CAAC,IAAI;AAAS,aAAA;AAAA,IAAe;AAE3B,UAAA,oBAAoB,SAAS,EAAE;AAEjC,QAAA,mBAAmB,iBAAiB,GAAG;AAAS,aAAA;AAAA,IAAe;AAEnE,WAAO,MAAM,aAAa,IAAI,oBAAoB,SAAS,aAAa,iBAAiB,CAAC;AAAA,EAAA,CAC3F;AAED,SAAO,EAAE,kBAAkB;AAC7B;"}