<template>
  <view class="ml-tree-node__icon" :style="useStyle" v-if="info && info.icon" @tap="handleEvent">
    <ml-icon :name="info.icon"></ml-icon>
  </view>
</template>

<script>
export default {
  name: 'MlTreeIcon',
  options: {
    virtualHost: true
  },
  props: {
    info: Object,
    marginRight: Number
  },
  computed: {
    useStyle () {
      const { info, marginRight } = this
      return `color: ${info?.color}; font-size: ${Number(info?.fontSize)}rpx; margin-right: ${marginRight}rpx`
    }
  },
  methods: {
    handleEvent (e) {
      this.$emit('tap-icon', this.info)
    }
  }
}
</script>

<style lang="scss">
.ml-tree-node__icon {
  height: 100%;
  display: flex;
  padding: 0 10rpx;
  align-items: center;
  justify-content: center;
}
</style>
