UIPerformanceEllipsis
UIPerformanceEllipsis
A performance-optimized component for truncating text with support for line clamping, expansion, and tooltips.
<template> <UIPerformanceEllipsis :lineClamp="2" :expandTrigger="'click'" :tooltip="true" :text="longText" :expandable="true" v-model:expanded="isExpanded" @expand="handleExpand" > {{ longText }} </UIPerformanceEllipsis></template>
<script setup lang="ts">const longText = ref('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.')const isExpanded = ref(false)
const handleExpand = (expanded: boolean) => { console.log('Text expanded:', expanded)}</script>Props
lineClamp(number): Number of lines before truncatingexpandTrigger(‘click’): Trigger for expanding texttooltip(boolean | TooltipProps): Show tooltip on hovertext(string): Text content to truncateexpandable(boolean): Allow text expansionexpanded(boolean): Control expanded statetooltipMaxWidth(number): Maximum tooltip widthtooltipPlacement(string): Tooltip placementellipsis(string): Custom ellipsis stringuseNativeEllipsis(boolean): Use native CSS ellipsis
Events
update:expanded: Emitted when expanded state changesexpand: Emitted when text is expandedcollapse: Emitted when text is collapsed
Usage Examples
- Basic Usage:
<template> <UIPerformanceEllipsis :lineClamp="2"> {{ longText }} </UIPerformanceEllipsis></template>- With Tooltip:
<template> <UIPerformanceEllipsis :lineClamp="1" :tooltip="{ placement: 'top', maxWidth: 300 }" > {{ description }} </UIPerformanceEllipsis></template>- Expandable Text:
<template> <UIPerformanceEllipsis :lineClamp="3" :expandable="true" v-model:expanded="isExpanded" > <template #default> {{ content }} </template> <template #expand-trigger="{ expanded }"> <UIButton text size="small"> {{ expanded ? 'Show Less' : 'Show More' }} </UIButton> </template> </UIPerformanceEllipsis></template>- Custom Ellipsis:
<template> <UIPerformanceEllipsis :lineClamp="2" ellipsis="... (more)" :useNativeEllipsis="false" > {{ text }} </UIPerformanceEllipsis></template>Best Practices
-
Performance:
- Use native ellipsis when possible
- Avoid unnecessary re-renders
- Cache truncation calculations
- Optimize for large text blocks
-
User Experience:
- Show clear expansion triggers
- Provide tooltips for context
- Maintain consistent behavior
- Handle text updates smoothly
-
Accessibility:
- Ensure expandable content is accessible
- Provide keyboard navigation
- Include ARIA attributes
- Support screen readers
-
Responsiveness:
- Adjust line clamp based on screen size
- Handle dynamic container widths
- Maintain readability
- Consider mobile interactions
Common Use Cases
- List Items:
<template> <ul class="space-y-2"> <li v-for="item in items" :key="item.id"> <UIPerformanceEllipsis :lineClamp="2" :tooltip="true" > {{ item.description }} </UIPerformanceEllipsis> </li> </ul></template>- Card Content:
<template> <UICard> <UIPerformanceEllipsis :lineClamp="3" :expandable="true" class="text-sm" > {{ cardContent }} </UIPerformanceEllipsis> </UICard></template>- Table Cells:
<template> <UITable :columns="columns" :data="data"> <template #description="{ text }"> <UIPerformanceEllipsis :lineClamp="1" :tooltip="true" > {{ text }} </UIPerformanceEllipsis> </template> </UITable></template>Performance Tips
-
Text Processing:
- Use efficient truncation algorithms
- Implement virtual scrolling for lists
- Cache computed lengths
- Debounce resize handlers
-
Memory Management:
- Clean up event listeners
- Dispose tooltip instances
- Clear cached calculations
- Handle component unmounting
-
Rendering Optimization:
- Use CSS when possible
- Minimize DOM operations
- Batch updates
- Avoid unnecessary calculations