* Truncate a tag to fit within maxWidth, accounting for padding and hash prefix
(tag: string, maxWidth: number)
| 41 | * Truncate a tag to fit within maxWidth, accounting for padding and hash prefix |
| 42 | */ |
| 43 | function truncateTag(tag: string, maxWidth: number): string { |
| 44 | // Available space for the tag text itself: maxWidth - " #" - " " |
| 45 | const availableForTag = maxWidth - TAB_PADDING - HASH_PREFIX_LENGTH; |
| 46 | if (stringWidth(tag) <= availableForTag) { |
| 47 | return tag; |
| 48 | } |
| 49 | if (availableForTag <= 1) { |
| 50 | return tag.charAt(0); |
| 51 | } |
| 52 | return truncateToWidth(tag, availableForTag); |
| 53 | } |
| 54 | export function TagTabs({ |
| 55 | tabs, |
| 56 | selectedIndex, |
no test coverage detected