<template>
  <div class="icons-container">
    <el-tabs type="border-card">
      <el-tab-pane label="Icons">
        <div class="grid">
          <div v-for="item of svgIcons" :key="item" @click="handleClick(item)">
            <el-tooltip placement="top">
              <div slot="content">
                {{ item }}
              </div>
              <div class="icon-item">
                <svg-icon :icon-class="item" class-name="disabled" />
                <span>{{ item }}</span>
              </div>
            </el-tooltip>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="Element-UI Icons">
        <div class="grid">
          <div v-for="item of elementIcons" :key="item" @click="handleClick(`el-icon-${item}`)">
            <el-tooltip placement="top">
              <div slot="content">
                {{ item }}
              </div>
              <div class="icon-item">
                <i :class="'el-icon-' + item" />
                <span>{{ item }}</span>
              </div>
            </el-tooltip>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="更多 Icons">
        <div class="grid">
          <div v-for="item of myIcons" :key="item" @click="handleClick(`iconfont ${item}`)">
            <el-tooltip placement="top">
              <div slot="content">
                {{ item }}
              </div>
              <div class="icon-item">
                <i :class="'iconfont ' + item" />
                <span>{{ item }}</span>
              </div>
            </el-tooltip>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import svgIcons from './svg-icons'
import elementIcons from './element-icons'
import myIcons from './icons'
export default {
  name: 'Icons',
  data() {
    return {
      svgIcons,
      elementIcons,
      myIcons
    }
  },
  methods: {
    handleClick(text) {
      this.$emit('click', text)
    }
  }
}
</script>

<style lang="scss" scoped>
.icons-container {
  margin: 10px 20px 0;
  overflow: hidden;

  .el-tab-pane{
    max-height: 500px;
    overflow-y: auto;
  }

  .grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  .icon-item {
    padding-top: 8px;
    margin: 16px;
    height: 80px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 28px;
    color: #24292e;
    cursor: pointer;
    &:hover{
      background: rgba($color: #000000, $alpha: 0.1);
    }
  }
  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }
  .disabled {
    pointer-events: none;
  }
}
</style>
