HintHelp.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script setup lang="ts">
  2. import { isFunction } from 'lodash-es'
  3. import { NButton, NPopover } from 'naive-ui'
  4. import { isVNode } from 'vue'
  5. import type { ButtonProps, PopoverProps } from 'naive-ui'
  6. import type { AllowedComponentProps, HTMLAttributes, SVGAttributes, VNodeChild } from 'vue'
  7. export interface HintHelpProps {
  8. buttonProps?: AllowedComponentProps & ButtonProps
  9. content?: (() => VNodeChild) | string
  10. iconProps?: SVGAttributes
  11. label?: string
  12. labelProps?: HTMLAttributes
  13. popoverProps?: PopoverProps
  14. }
  15. const { label, popoverProps, buttonProps, iconProps, content } = defineProps<HintHelpProps>()
  16. </script>
  17. <template>
  18. <div class="flex items-center gap-x-0.5">
  19. <span>{{ label }}</span>
  20. <NPopover v-bind="popoverProps">
  21. <template #trigger>
  22. <NButton
  23. quaternary
  24. circle
  25. size="small"
  26. v-bind="buttonProps"
  27. >
  28. <template #icon>
  29. <span
  30. class="iconify ph--question"
  31. v-bind="iconProps"
  32. />
  33. </template>
  34. </NButton>
  35. </template>
  36. <component
  37. v-if="isFunction(content) && isVNode(content())"
  38. :is="content"
  39. />
  40. <span v-else>{{ content }}</span>
  41. </NPopover>
  42. </div>
  43. </template>