<template>
    <div class="text-truncate" :title="showTooltip ? text : undefined">
      {{ truncatedText }}
    </div>
  </template>
  
  <script>
  export default {
    name: 'TextTruncate',
    props: {
      text: {
        type: String,
        required: true,
        default: ''
      },
      maxLength: {
        type: Number,
        default: 20
      },
      ellipsis: {
        type: String,
        default: '...'
      },
      showTooltip: {
        type: Boolean,
        default: true
      }
    },
    computed: {
      truncatedText() {
        if (!this.text || this.text.length <= this.maxLength) {
          return this.text;
        }
        return this.text.slice(0, this.maxLength) + this.ellipsis;
      }
    }
  }
  </script>
  
  <style scoped>
  .text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  </style>
  