CardGrid.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template lang="pug">
  2. .card-grid-wrapper
  3. .card-grid-loading(v-if='loading')
  4. spinner
  5. .card-grid(v-else)
  6. add-card(v-if='canAdd' @onClickAdd='onClickAdd')
  7. card(v-for='item in items' :key='item.id' :title='item.name' :image='item.imageMedium' :isSelected='item.id === selectedId' :description='getDescription(item)' @onClick='onClickCard(item)')
  8. </template>
  9. <script>
  10. import AddCard from '@/components/common/AddCard'
  11. import Card from '@/components/common/Card'
  12. import Spinner from '@/components/common/Spinner'
  13. export default {
  14. props: {
  15. items: {
  16. type: Array,
  17. default: []
  18. },
  19. canAdd: {
  20. type: Boolean,
  21. default: false
  22. },
  23. description: {
  24. type: String,
  25. default: ''
  26. },
  27. loading: {
  28. type: Boolean,
  29. default: false
  30. }
  31. },
  32. components: {
  33. AddCard,
  34. Card,
  35. Spinner
  36. },
  37. methods: {
  38. getDescription(item) {
  39. return (!!this.description && item[this.description]) || ''
  40. },
  41. onClickAdd() {
  42. this.$emit('onAdd')
  43. },
  44. onClickCard(item) {
  45. this.selectedId = item.id
  46. this.$emit('onSelect', item)
  47. }
  48. },
  49. data() {
  50. return {
  51. selectedId: -1
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="sass">
  57. .card-grid-wrapper
  58. width: 100%
  59. height: calc(100% - 100px)
  60. margin-top: 15px
  61. overflow-y: auto
  62. .card-grid-loading
  63. width: 100%
  64. height: 100%
  65. display: flex
  66. align-items: center
  67. justify-content: center
  68. .card-grid
  69. width: 100%
  70. </style>