{"version":3,"file":"UTooltip.mjs","names":["makeComponentProps","makeTagProps","genericComponent","propsFactory","useRender","computed","ref","watch","onMounted","createPopper","makeUTooltipProps","_objectSpread","theme","type","String","required","position","always","Boolean","UTooltip","name","props","emits","click","e","setup","_ref","emit","slots","tooltipIsVisible","tooltipToggle","tooltipComponent","popperInstance","alwaysVisible","popperCreated","destroyTooltip","createTooltip","newValue","value","removeAttribute","placement","offset","setTimeout","modifiers","options","destroy","tooltipTheme","color","backgroundColor","GeneralClasses","ThemeDarkClasses","concat","ThemeLightClasses","PseudoElementClasses","PseudoElementBottomCenterClasses","PseudoElementBottomLeftClasses","PseudoElementBottomRightClasses","PseudoElementTopCenterClasses","PseudoElementTopLeftClasses","PseudoElementTopRightClasses","PseudoElementLeftClasses","PseudoElementRightClasses","classes","_ref2","_defineProperty","_slots$tooltipToggle","_slots$text","_slots$supportingText","_createVNode","onClick","onMouseenter","onMouseleave","onTouchstart","onTouchend","call","supportingText","text"],"sources":["../../../src/components/UTooltip/UTooltip.tsx"],"sourcesContent":["import { makeComponentProps } from '@/composables/component'\nimport { makeTagProps } from '@/composables/tag'\nimport { genericComponent, propsFactory, useRender } from '@/utils'\nimport { ExtractPropTypes } from 'vue'\nimport { computed, ref, watch, onMounted } from 'vue'\nimport { createPopper, Instance, Placement } from '@popperjs/core'\n\nexport const makeUTooltipProps = propsFactory(\n  {\n    theme: {\n      type: String,\n      default: 'dark',\n      required: false,\n    },\n    position: {\n      type: String,\n      default: 'none bottom',\n      required: false,\n    },\n    always: {\n      type: Boolean,\n      default: false,\n      required: false,\n    },\n\n    ...makeComponentProps(),\n    ...makeTagProps(),\n  },\n  'UTooltip'\n)\n\nexport type UTooltipProps = ExtractPropTypes<typeof makeUTooltipProps>\n\nexport type UTooltipSlots = {\n  tooltipToggle: never\n  text: never\n  supportingText: never\n}\n\nexport const UTooltip = genericComponent<UTooltipSlots>()({\n  name: 'UTooltip',\n\n  props: makeUTooltipProps(),\n\n  emits: {\n    click: (e: MouseEvent) => true,\n  },\n\n  setup(props, { emit, slots }) {\n    const tooltipIsVisible = ref(false)\n    const tooltipToggle = ref<HTMLElement | Element | null>(null)\n    const tooltipComponent = ref<Element | HTMLElement | null>(null)\n    const popperInstance = ref<Instance | null>(null)\n    const alwaysVisible = computed(() => props.always)\n    const popperCreated = ref(false)\n\n    watch(\n      () => props.position,\n      () => {\n        destroyTooltip()\n        props.always === true ? createTooltip() : ''\n      }\n    )\n\n    watch(alwaysVisible, (newValue) => {\n      if (newValue === true) {\n        destroyTooltip()\n        createTooltip()\n      } else {\n        destroyTooltip()\n      }\n    })\n\n    function createTooltip() {\n      if (tooltipToggle.value && tooltipComponent.value) {\n        tooltipIsVisible.value = true\n        tooltipComponent.value.removeAttribute('data-popper-reference-hidden')\n        let placement = props.position as Placement\n        let offset = [0, 12]\n\n        if (props.position === 'none top' || props.position === 'none bottom') {\n          offset = [0, 6]\n        } else if (\n          props.position === 'top-end' ||\n          props.position === 'bottom-end'\n        ) {\n          offset = [13, 12]\n        } else if (\n          props.position === 'top-start' ||\n          props.position === 'bottom-start'\n        ) {\n          offset = [-14, 12]\n        }\n\n        if (props.position === 'none top') {\n          placement = 'top'\n        } else if (props.position === 'none bottom') {\n          placement = 'bottom'\n        }\n\n        setTimeout(() => {\n          popperInstance.value = createPopper(\n            tooltipToggle.value as HTMLElement,\n            tooltipComponent.value as HTMLElement,\n            {\n              placement: placement,\n              modifiers: [\n                {\n                  name: 'offset',\n                  options: {\n                    offset: offset,\n                  },\n                },\n              ],\n            }\n          )\n          popperCreated.value = true\n        }, 5)\n      }\n    }\n\n    function destroyTooltip() {\n      tooltipIsVisible.value = false\n      popperCreated.value = false\n\n      if (popperInstance.value) {\n        popperInstance.value.destroy()\n        popperInstance.value = null\n      }\n    }\n\n    onMounted(() => {\n      if (alwaysVisible.value === true) {\n        createTooltip()\n      }\n    })\n\n    const tooltipTheme = computed(() => {\n      let tooltipTheme = {\n        color: 'white',\n        backgroundColor: 'gray-900',\n      }\n      switch (props.theme) {\n        case 'dark':\n          tooltipTheme = {\n            color: 'white',\n            backgroundColor: 'gray-900',\n          }\n          break\n        case 'light':\n          tooltipTheme = {\n            color: 'gray-700',\n            backgroundColor: 'white',\n          }\n          break\n        default:\n          break\n      }\n      return tooltipTheme\n    })\n\n    const GeneralClasses = `absolute flex flex-col font-medium max-w-sm py-2 px-3 text-text-xs\n      rounded-lg w-fit`\n\n    const ThemeDarkClasses = computed(\n      () =>\n        `bg-${tooltipTheme.value.backgroundColor} text-${tooltipTheme.value.color} shadow\n          shadow-lg shadow-${tooltipTheme.value.backgroundColor}`\n    )\n\n    const ThemeLightClasses = computed(\n      () =>\n        `bg-${tooltipTheme.value.backgroundColor} text-${tooltipTheme.value.color} shadow\n          shadow-lg shadow-gray-100`\n    )\n\n    const PseudoElementClasses = computed(\n      () =>\n        `before:block before:absolute before:bg-${tooltipTheme.value.backgroundColor} before:w-3\n          before:h-xs before:rotate-45`\n    )\n\n    const PseudoElementBottomCenterClasses = computed(\n      () =>\n        `before:-bottom-1.5 before:left-1/2 before:transform before:-translate-x-1/2`\n    )\n\n    const PseudoElementBottomLeftClasses = computed(\n      () => `before:-bottom-1.5 before:inset-x-3.5`\n    )\n\n    const PseudoElementBottomRightClasses = computed(\n      () => `before:-bottom-1.5 before:right-3.5`\n    )\n\n    const PseudoElementTopCenterClasses = computed(\n      () =>\n        `before:-top-1.5 before:left-1/2 before:transform before:-translate-x-1/2`\n    )\n\n    const PseudoElementTopLeftClasses = computed(\n      () => `before:-top-1.5 before:inset-x-3.5`\n    )\n\n    const PseudoElementTopRightClasses = computed(\n      () => `before:-top-1.5 before:right-3.5`\n    )\n\n    const PseudoElementLeftClasses = computed(\n      () =>\n        `before:top-1/2 before:transform before:-translate-y-1/2 before:-inset-1.5`\n    )\n\n    const PseudoElementRightClasses = computed(\n      () =>\n        `before:top-1/2 before:transform before:-translate-y-1/2 before:-right-1.5`\n    )\n\n    const classes = computed(() => ({\n      [GeneralClasses]: true,\n      [ThemeLightClasses.value]: props.theme === 'light',\n      [ThemeDarkClasses.value]: props.theme === 'dark',\n      [PseudoElementClasses.value]:\n        props.position !== 'none top' && props.position !== 'none bottom',\n      [PseudoElementBottomCenterClasses.value]: props.position === 'top',\n      [PseudoElementBottomLeftClasses.value]: props.position === 'top-start',\n      [PseudoElementBottomRightClasses.value]: props.position === 'top-end',\n      [PseudoElementTopCenterClasses.value]: props.position === 'bottom',\n      [PseudoElementTopLeftClasses.value]: props.position === 'bottom-start',\n      [PseudoElementTopRightClasses.value]: props.position === 'bottom-end',\n      [PseudoElementLeftClasses.value]: props.position === 'right',\n      [PseudoElementRightClasses.value]: props.position === 'left',\n    }))\n\n    useRender(() => (\n      <div class=\"inline-block\">\n        <div\n          class=\"toggle w-fit h-fit\"\n          ref={tooltipToggle}\n          onClick={(e) => emit('click', e)}\n          onMouseenter={() => !props.always && createTooltip()}\n          onMouseleave={() => !props.always && destroyTooltip()}\n          onTouchstart={() => !props.always && createTooltip()}\n          onTouchend={() => !props.always && destroyTooltip()}\n        >\n          {slots.tooltipToggle?.()}\n        </div>\n        <div\n          ref={tooltipComponent}\n          class={[\n            slots.supportingText && slots.text ? 'gap-1' : '',\n            classes.value,\n            'tooltip',\n            popperCreated.value ? 'opacity-1' : 'opacity-0',\n          ]}\n        >\n          <div>{slots.text?.()}</div>\n          <div>{slots.supportingText?.()}</div>\n        </div>\n      </div>\n    ))\n\n    return {\n      tooltipIsVisible,\n    }\n  },\n})\n\nexport type UTooltip = InstanceType<typeof UTooltip>\n"],"mappings":";;;;;;;SAASA,kBAAkB;AAAA,SAClBC,YAAY;AAAA,SACZC,gBAAgB,EAAEC,YAAY,EAAEC,SAAS;AAElD,SAASC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAEC,SAAS,QAAQ,KAAK;AACrD,SAASC,YAAY,QAA6B,gBAAgB;AAElE,OAAO,IAAMC,iBAAiB,GAAGP,YAAY,CAAAQ,aAAA,CAAAA,aAAA;EAEzCC,KAAK,EAAE;IAC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