@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
34 lines (31 loc) • 1.03 kB
JavaScript
import { getCurrentInstance, computed } from 'vue';
import '../../hooks/index.mjs';
import '../../constants/index.mjs';
import { getVsColor } from '../color.mjs';
import { debugWarn } from '../error.mjs';
import { useAttrs } from '../../hooks/use-attrs/index.mjs';
import { componentColors } from '../../constants/color.mjs';
const getComponentColor = () => {
const instance = getCurrentInstance();
if (!instance) {
debugWarn(
"use-attrs",
"getCurrentInstance() returned null. getComponentColor() must be called at the top of a setup function"
);
return computed(() => null);
}
const attrs = useAttrs({ excludeListeners: true });
return computed(() => {
const propColor = componentColors.find(
(color) => attrs.value[color] === true
);
if (propColor)
return propColor;
const hasColorString = attrs.value["color"];
if (!hasColorString)
return null;
return getVsColor(hasColorString);
});
};
export { getComponentColor };
//# sourceMappingURL=color.mjs.map