ui-group.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 lang="ts" 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. defineOptions({
  35. name: 'UIGroup',
  36. })
  37. const animationRef = ref(null)
  38. const props = defineProps({
  39. title: String,
  40. border: Boolean,
  41. borderTop: Boolean,
  42. borderBottom: Boolean,
  43. control: Boolean,
  44. show: Boolean,
  45. })
  46. const contentStyle = computed(() => ({
  47. 'border-bottom': props.borderBottom || props.border,
  48. 'border-top': props.borderTop || props.border,
  49. }))
  50. const contentInstances = ref([])
  51. provide(Relation, contentInstances)
  52. watchEffect(() => {
  53. if (animationRef.value) {
  54. animationRef.value.changeShow(props.show)
  55. }
  56. })
  57. watch(contentInstances, () => {
  58. animationRef.value && animationRef.value.refer()
  59. })
  60. </script>
  61. <!-- <script>
  62. export default { name: 'UiGroup' }
  63. </script> -->