vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 3.63 kB
Source Map (JSON)
{"version":3,"file":"useButtonBackground.mjs","sources":["../../../../../../src/components/va-button/hooks/useButtonBackground.ts"],"sourcesContent":["import { computed, Ref, ComputedRef, getCurrentInstance } from 'vue'\n\nimport { useColors } from '../../../composables'\n\nimport type { ButtonPropsTypes } from '../types'\n\ntype UseButtonBackground = (\n colorComputed: Ref<string>,\n isPressed: Ref<boolean>,\n isHovered: Ref<boolean>,\n ) => {\n backgroundMaskOpacity: ComputedRef<number>;\n backgroundMaskColor: ComputedRef<string>;\n backgroundColor: ComputedRef<string>;\n backgroundColorOpacity: ComputedRef<number>;\n}\n\nexport const useButtonBackground: UseButtonBackground = (\n colorComputed,\n isPressed,\n isHovered,\n) => {\n const instance = getCurrentInstance()\n if (!instance) { throw new Error('`useButtonBackground` hook must be used only inside of setup function!') }\n const props = instance.props as Required<ButtonPropsTypes>\n\n const { getColor, getGradientBackground } = useColors()\n\n const backgroundColor = computed(() => {\n if (props.plain) { return 'transparent' }\n\n return props.gradient\n ? getGradientBackground(colorComputed.value)\n : colorComputed.value\n })\n\n const hoveredBgState = computed(() => !props.plain && isHovered.value)\n const pressedBgState = computed(() => !props.plain && isPressed.value)\n\n const backgroundColorOpacity = computed(() => {\n if (pressedBgState.value && props.pressedBehavior === 'opacity') { return props.pressedOpacity }\n if (hoveredBgState.value && props.hoverBehavior === 'opacity') { return Number(props.hoverOpacity) }\n\n return Number(props.backgroundOpacity)\n })\n\n const hoveredMaskState = computed(() => hoveredBgState.value && props.hoverBehavior === 'mask')\n const pressedMaskState = computed(() => pressedBgState.value && props.pressedBehavior === 'mask')\n\n const backgroundMaskOpacity = computed(() => {\n if (pressedMaskState.value) { return props.pressedOpacity }\n if (hoveredMaskState.value) { return Number(props.hoverOpacity) }\n\n return 0\n })\n const backgroundMaskColor = computed(() => {\n if (pressedMaskState.value) { return getColor(props.pressedMaskColor) }\n if (hoveredMaskState.value) { return getColor(props.hoverMaskColor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