TextCard.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <text-card-base v-bind="$attrs">
  3. <template v-slot:header-extra="{ text }">
  4. <b-nav class="ml-auto flex-nowrap" pills>
  5. <template v-if="children">
  6. <b-nav-item
  7. v-for="child in text.children" :key="child.id"
  8. @click="onChildOpen($event, text.id, child.id)"
  9. :active="children.includes(child.id)"
  10. >
  11. {{ child.id }}
  12. </b-nav-item>
  13. </template>
  14. <b-nav-item>
  15. <b-button-close @click="onSelfClose($event, text.id)" />
  16. </b-nav-item>
  17. </b-nav>
  18. </template>
  19. <template v-slot:footer-extra="{ text, toCommaList }">
  20. <b-button
  21. v-if="text.siblings"
  22. :id="'siblings-' + text.id"
  23. size="sm"
  24. >
  25. {{ $t('siblings') }}
  26. </b-button>
  27. <b-popover
  28. v-if="text.siblings"
  29. :target="'siblings-' + text.id" triggers="hover" placement="top"
  30. >
  31. <div v-for="sibling in text.siblings" :key="sibling.id">
  32. <h6 @click="onSiblingOpen($event, sibling.id)" class="clickable">
  33. <span class="text-authors d-block">{{ toCommaList(sibling.authors) }},</span>
  34. <span class="text-title d-block">{{ sibling.title }},</span>
  35. <span class="text-edition d-block">{{ text.edition ? text.edition.name : text.edition }}</span>
  36. </h6>
  37. </div>
  38. </b-popover>
  39. </template>
  40. </text-card-base>
  41. </template>
  42. <script>
  43. import TextCardBase from './TextCardBase'
  44. export default {
  45. name: 'TextCard',
  46. components: {
  47. TextCardBase
  48. },
  49. props: {
  50. children: { type: Array, default: null }
  51. },
  52. methods: {
  53. onChildOpen (_, id, childId) {
  54. this.$emit('open', id, childId)
  55. },
  56. onSiblingOpen (_, id) {
  57. this.$emit('open', id)
  58. },
  59. onSelfClose (e, id) {
  60. // stop the click event propagation to avoid other listeners to interact with a soon to be deleted element.
  61. e.stopPropagation()
  62. this.$emit('close', id)
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. </style>