Skip to content

Commit f0ef2f8

Browse files
generate unique id for numeric variable
1 parent a235314 commit f0ef2f8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

apps/studio/src/lib/editor/engine/theme/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { makeAutoObservable } from 'mobx';
99
import colors from 'tailwindcss/colors';
1010
import type { EditorEngine } from '..';
1111
import { camelCase } from 'lodash';
12+
import { customAlphabet } from 'nanoid/non-secure';
1213

1314
interface ColorValue {
1415
value: string;
@@ -451,9 +452,10 @@ export class ThemeManager {
451452
throw new Error('Color not found');
452453
}
453454
// If the color name is a number, we need to add a suffix to the new color name
455+
const randomId = customAlphabet('0123456789', 5)();
454456
const newName = isNaN(Number(colorName))
455457
? `${colorName}Copy`
456-
: `${colorName}${group.length + 1}`;
458+
: `${colorName}${randomId}`;
457459

458460
const color = Color.from(
459461
theme === Theme.DARK

apps/studio/src/routes/editor/LayersPanel/BrandTab/ColorPanel/ColorPalletGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export const BrandPalletGroup = ({
125125
};
126126

127127
const generateUniqueColorName = () => {
128-
const randomId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 5)();
128+
const randomIdText = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 5)();
129+
const randomIdNumber = customAlphabet('0123456789', 5)();
130+
const randomId = isNaN(Number(title)) ? randomIdText : randomIdNumber;
129131
return `${title} ${randomId}`;
130132
};
131133

0 commit comments

Comments
 (0)