ui-group.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="ui-group" :class="{ control }">
  3. <template v-if="!$slots.header">
  4. <h3 v-if="props.title" class="group-title" :class="!$slots.default && contentStyle">
  5. {{ props.title }}
  6. <span v-if="$slots.icon || control" class="group-icon" :class="animationRef && { show: animationRef.show }" @click="control && animationRef.changeShow()">
  7. <slot v-if="$slots.icon" name="icon" />
  8. <icon v-else type="pull-down" size="12px" />
  9. </span>
  10. </h3>
  11. </template>
  12. <div v-else class="group-title" :class="!$slots.default && contentStyle">
  13. <slot name="header" />
  14. <span v-if="$slots.icon || control" class="group-icon" :class="animationRef && { show: animationRef.show }" @click="control && animationRef.changeShow()">
  15. <slot v-if="$slots.icon" name="icon" />
  16. <icon v-else type="pull-down" size="12px" />
  17. </span>
  18. </div>
  19. <template v-if="$slots.default">
  20. <UISizeAnimation v-if="control" ref="animationRef" class="group-content" :class="contentStyle">
  21. <slot />
  22. </UISizeAnimation>
  23. <div v-else class="group-content" :class="contentStyle">
  24. <slot />
  25. </div>
  26. </template>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { computed, provide, ref, watch, watchEffect } from 'vue'
  31. import icon from '../icon'
  32. import UISizeAnimation from '../size-animation'
  33. import { Relation } from './constant'
  34. const animationRef = ref(null)
  35. const props = defineProps({
  36. title: String,
  37. border: Boolean,
  38. borderTop: Boolean,
  39. borderBottom: Boolean,
  40. control: Boolean,
  41. show: Boolean,
  42. })
  43. const contentStyle = computed(() => ({
  44. 'border-bottom': props.borderBottom || props.border,
  45. 'border-top': props.borderTop || props.border,
  46. }))
  47. const contentInstances = ref([])
  48. provide(Relation, contentInstances)
  49. watchEffect(() => {
  50. if (animationRef.value) {
  51. animationRef.value.changeShow(props.show)
  52. }
  53. })
  54. watch(contentInstances, () => {
  55. animationRef.value && animationRef.value.refer()
  56. })
  57. </script>
  58. <script>
  59. export default { name: 'UiGroup' }
  60. </script>