Skip to content

Commit eed6731

Browse files
committed
fix: handle really long template names
1 parent eab1b0d commit eed6731

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/imagekit-editor-dev/src/components/header/TemplatesDropdown.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { useTemplateStorage } from "../../context/TemplateStorageContext"
3636
import type { TemplateRecord } from "../../storage"
3737
import { applyTemplateStorageAccessFailure } from "../../storage/templateAccessError"
3838
import { useEditorStore } from "../../store"
39+
import { truncateTemplateName } from "../../utils"
3940

4041
const MAX_VISIBLE = 5
4142

@@ -351,8 +352,9 @@ export function TemplatesDropdown({
351352
fontWeight="medium"
352353
isTruncated
353354
color="blue.800"
355+
title={templateName}
354356
>
355-
{templateName}
357+
{truncateTemplateName(templateName)}
356358
</Text>
357359
<Badge colorScheme="blue" fontSize="xs" flexShrink={0}>
358360
Current
@@ -413,8 +415,9 @@ export function TemplatesDropdown({
413415
fontWeight="medium"
414416
isTruncated
415417
color="editorBattleshipGrey.800"
418+
title={record.name}
416419
>
417-
{record.name}
420+
{truncateTemplateName(record.name)}
418421
</Text>
419422

420423
{/* Creator on hover + pin (always visible for pinned, hover for others) */}

packages/imagekit-editor-dev/src/components/templates/TemplatesLibraryView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useTemplateStorage } from "../../context/TemplateStorageContext"
3737
import { useDebounce } from "../../hooks/useDebounce"
3838
import type { TemplateRecord } from "../../storage"
3939
import { useEditorStore } from "../../store"
40+
import { truncateTemplateName } from "../../utils"
4041
import FilterChipsField from "../common/FilterChipsField"
4142
import MultiSelectListField from "../common/MultiSelectListField"
4243
import { SettingsModal } from "../header/SettingsModal"
@@ -605,8 +606,9 @@ function TemplateRow({
605606
fontWeight="medium"
606607
color={isCurrent ? "blue.800" : "editorBattleshipGrey.700"}
607608
isTruncated
609+
title={record.name}
608610
>
609-
{record.name}
611+
{truncateTemplateName(record.name)}
610612
</Text>
611613
{isCurrent && (
612614
<Badge colorScheme="blue" fontSize="xs" flexShrink={0}>

packages/imagekit-editor-dev/src/utils/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const __DEV__ = process.env.NODE_ENV !== "production"
22

33
export const SIMPLE_OVERLAY_TEXT_REGEX = /^[a-zA-Z0-9-._ ]*$/
4+
export const TEMPLATE_NAME_UI_MAX_LENGTH = 30
45

56
export const safeBtoa = (str: string): string => {
67
if (typeof window !== "undefined") {
@@ -93,3 +94,10 @@ export const extractImagePath = (imageUrl: string): string => {
9394
return segments[0] || ""
9495
}
9596
}
97+
98+
export const truncateTemplateName = (name: string) => {
99+
if (name.length <= TEMPLATE_NAME_UI_MAX_LENGTH) {
100+
return name
101+
}
102+
return `${name.slice(0, TEMPLATE_NAME_UI_MAX_LENGTH)}...`
103+
}

0 commit comments

Comments
 (0)