all files / src/gridList/ gridTile.vue

0% Statements 0/11
0% Branches 0/11
100% Functions 0/0
0% Lines 0/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158                                                                                                                                                                                                                                                                                                                           
<template>
<div :style="style">
  <div class="mu-grid-tile" :class="tileClass">
    <slot></slot>
    <div class="mu-grid-tile-titlebar" :class="titleBarClass">
      <div class="mu-grid-tile-title-container">
        <div class="mu-grid-tile-title">
          <slot name="title">
            {{title}}
          </slot>
        </div>
        <div class="mu-grid-tile-subtitle">
          <slot name="subTitle">
            {{subTitle}}
          </slot>
        </div>
      </div>
      <div class="mu-grid-tile-action">
        <slot name="action"></slot>
      </div>
    </div>
  </div>
</div>
</template>
 
<script>
export default {
  name: 'mu-grid-tile',
  props: {
    actionPosition: {
      type: String,
      default: 'right',
      validator (val) {
        return ['left', 'right'].indexOf(val) !== -1
      }
    },
    cols: {
      type: Number,
      default: 1
    },
    rows: {
      type: Number,
      default: 1
    },
    title: {
      type: String
    },
    subTitle: {
      type: String
    },
    titlePosition: {
      type: String,
      default: 'bottom',
      validator (val) {
        return ['top', 'bottom'].indexOf(val) !== -1
      }
    },
    titleBarClass: {
      type: [String, Array, Object]
    }
  },
  computed: {
    tileClass () {
      let classArr = []
      if (this.titlePosition === 'top') classArr.push('top')
      if (this.actionPosition === 'left') classArr.push('action-left')
      if (this.$slots && this.$slots.title && this.$slots.subTitle &&
        this.$slots.title.length > 0 && this.$slots.subTitle.length > 0) {
        classArr.push('multiline')
      }
      return classArr
    },
    style () {
      return {
        width: (this.cols / this.$parent.cols * 100) + '%',
        padding: (this.$parent.padding / 2) + 'px',
        height: (this.$parent.cellHeight * this.rows) + 'px'
      }
    }
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-grid-tile {
  position: relative;
  display: block;
  height: 100%;
  overflow: hidden;
  > img {
    height: 100%;
    transform: translateX(-50%);
    position: relative;
    left: 50%;
  }
}
 
.mu-grid-tile-titlebar{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 48px;
  background-color: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
 
  .mu-grid-tile.multiline &{
    height: 68px;
  }
 
  .mu-grid-tile.top &{
    bottom: auto;
    top: 0;
  }
 
}
 
.mu-grid-tile-title-container{
  margin-left: 16px;
  margin-right: 0;
  color: @alternateTextColor;
  flex: 1;
  overflow: hidden;
  .mu-grid-tile.action-left &{
    margin-right: 16px;
    margin-left: 0;
  }
}
 
.mu-grid-tile-action {
  order: 1;
  .mu-grid-tile.action-left & {
    order: -1;
  }
  .mu-icon {
    color: @alternateTextColor;
  }
}
 
.mu-grid-tile-title {
  font-size: 16px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  word-wrap: break-word;
}
 
.mu-grid-tile-subtitle {
  font-size: 12px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  word-wrap: break-word;
}
</style>