Skip to content

Commit ee7dde5

Browse files
fix: issue with default brand color (#1678)
* fix: issue with default brand color * Refactor DEFAULT naming * Enable brand panel
1 parent bab8980 commit ee7dde5

File tree

9 files changed

+56
-38
lines changed

9 files changed

+56
-38
lines changed

Diff for: apps/studio/electron/main/assets/helpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Node, ObjectExpression } from '@babel/types';
22
import type { ColorUpdate } from '@onlook/models/assets';
3+
import { DEFAULT_COLOR_NAME } from '@onlook/models/constants';
34
import fg from 'fast-glob';
45
import fs from 'fs';
56
import path from 'path';
@@ -122,7 +123,7 @@ export function addTailwindRootColor(
122123
type: 'ObjectProperty',
123124
key: {
124125
type: 'Identifier',
125-
name: 'DEFAULT',
126+
name: DEFAULT_COLOR_NAME,
126127
},
127128
value: {
128129
type: 'StringLiteral',

Diff for: apps/studio/electron/main/assets/styles.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
} from '@onlook/models/assets';
1111
import { Theme } from '@onlook/models/assets';
1212
import type { CodeDiffRequest } from '@onlook/models/code';
13+
import { DEFAULT_COLOR_NAME } from '@onlook/models/constants';
1314
import { parseHslValue } from '@onlook/utility';
1415
import fs from 'fs';
1516
import { camelCase } from 'lodash';
@@ -54,7 +55,7 @@ export async function updateTailwindColorConfig(
5455
return { success: true };
5556
}
5657

57-
const camelCaseName = camelCase(newName);
58+
const camelCaseName = newName === DEFAULT_COLOR_NAME ? newName : camelCase(newName);
5859
return originalKey
5960
? updateTailwindColorVariable(colorUpdate, originalKey, newColor, camelCaseName, theme)
6061
: createTailwindColorVariable(colorUpdate, newColor, camelCaseName, parentName);
@@ -91,7 +92,7 @@ function addTailwindNestedColor(
9192
type: 'ObjectProperty',
9293
key: {
9394
type: 'Identifier',
94-
name: 'DEFAULT',
95+
name: DEFAULT_COLOR_NAME,
9596
},
9697
value: {
9798
type: 'StringLiteral',
@@ -226,11 +227,11 @@ function updateTailwindConfigFile(
226227
) {
227228
// Special handling for DEFAULT
228229
const oldVarName =
229-
nestedProp.key.name === 'DEFAULT'
230+
nestedProp.key.name === DEFAULT_COLOR_NAME
230231
? parentKey
231232
: `${parentKey}-${nestedProp.key.name}`;
232233
const newVarName =
233-
nestedProp.key.name === 'DEFAULT'
234+
nestedProp.key.name === DEFAULT_COLOR_NAME
234235
? newName
235236
: `${newName}-${nestedProp.key.name}`;
236237

@@ -261,7 +262,9 @@ function updateTailwindConfigFile(
261262
if (nestedProp.value.type === 'StringLiteral') {
262263
// Special handling for DEFAULT values
263264
const varName =
264-
keyName === 'DEFAULT' ? parentKey : newCssVarName;
265+
keyName === DEFAULT_COLOR_NAME
266+
? parentKey
267+
: newCssVarName;
265268
nestedProp.value.value = `var(--${varName})`;
266269
valueUpdated = true;
267270
}
@@ -296,7 +299,7 @@ async function updateTailwindColorVariable(
296299
newCssVarName = newName !== parentKey ? `${newName}` : originalName;
297300
} else {
298301
// Special handling for DEFAULT
299-
if (keyName === 'DEFAULT') {
302+
if (keyName === DEFAULT_COLOR_NAME) {
300303
newCssVarName = parentKey;
301304
originalName = parentKey;
302305
} else {

Diff for: apps/studio/src/lib/editor/engine/theme/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ProjectsManager } from '@/lib/projects';
22
import { invokeMainChannel } from '@/lib/utils';
33
import type { ColorItem } from '@/routes/editor/LayersPanel/BrandTab/ColorPanel/ColorPalletGroup';
4-
import { MainChannels } from '@onlook/models';
4+
import { DEFAULT_COLOR_NAME, MainChannels } from '@onlook/models';
55
import type { ConfigResult, ParsedColors, ThemeColors } from '@onlook/models/assets';
66
import { Theme } from '@onlook/models/assets';
77
import { Color } from '@onlook/utility';
@@ -74,7 +74,7 @@ export class ThemeManager {
7474
) {
7575
processConfigObject(value, prefix ? `${prefix}-${key}` : key, key);
7676

77-
if ('DEFAULT' in value) {
77+
if (DEFAULT_COLOR_NAME in value) {
7878
const varName = extractVarName(value.DEFAULT as string);
7979
if (varName) {
8080
parsed[key] = {
@@ -182,7 +182,7 @@ export class ThemeManager {
182182
ungroupedKeys.forEach((key) => {
183183
colorGroupsObj[key] = [
184184
{
185-
name: 'DEFAULT',
185+
name: DEFAULT_COLOR_NAME,
186186
originalKey: `${key}-DEFAULT`,
187187
lightColor: parsed[key].lightMode,
188188
darkColor: parsed[key].darkMode,
@@ -230,7 +230,7 @@ export class ThemeManager {
230230

231231
// Create color items for each shade in the scale
232232
const colorItems: ColorItem[] = Object.entries(defaultColorScale)
233-
.filter(([shade]) => shade !== 'DEFAULT')
233+
.filter(([shade]) => shade !== DEFAULT_COLOR_NAME)
234234
.map(([shade, defaultValue]) => {
235235
const lightModeValue = lightModeColors[`${colorName}-${shade}`]?.value;
236236
const darkModeValue = darkModeColors[`${colorName}-${shade}`]?.value;
@@ -498,8 +498,8 @@ export class ThemeManager {
498498

499499
const brandGroup = this.brandColors[groupName];
500500
if (brandGroup) {
501-
if (!shadeName || shadeName === 'DEFAULT') {
502-
const defaultColor = brandGroup.find((color) => color.name === 'DEFAULT');
501+
if (!shadeName || shadeName === DEFAULT_COLOR_NAME) {
502+
const defaultColor = brandGroup.find((color) => color.name === DEFAULT_COLOR_NAME);
503503
if (defaultColor?.lightColor) {
504504
return defaultColor.lightColor;
505505
}

Diff for: apps/studio/src/routes/editor/EditPanel/StylesTab/single/ColorInput/index.tsx

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { useEditorEngine } from '@/components/Context';
22
import type { CompoundStyle, SingleStyle } from '@/lib/editor/styles/models';
33
import { invokeMainChannel } from '@/lib/utils';
44
import type { ColorItem } from '@/routes/editor/LayersPanel/BrandTab/ColorPanel/ColorPalletGroup';
5-
import { MainChannels } from '@onlook/models/constants';
5+
import { DEFAULT_COLOR_NAME, MainChannels } from '@onlook/models/constants';
66
import { Icons } from '@onlook/ui/icons';
77
import { Color, isColorEmpty } from '@onlook/utility';
88
import { observer } from 'mobx-react-lite';
99
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
10-
import { PopoverPicker } from './Popover';
10+
import { BrandPopoverPicker } from './ColorBrandPicker';
1111

1212
const stripUrlWrapper = (url: string) => {
1313
return url.replace(/^url\((['"]?)(.*)\1\)/, '$2');
@@ -125,8 +125,8 @@ const ColorInput = observer(
125125
onValueChange?.(elementStyle.key, valueString);
126126
} else {
127127
let colorValue = newValue.originalKey;
128-
if (colorValue.endsWith('DEFAULT')) {
129-
colorValue = colorValue.split('-DEFAULT')[0];
128+
if (colorValue.endsWith(DEFAULT_COLOR_NAME)) {
129+
colorValue = colorValue.split(`-${DEFAULT_COLOR_NAME}`)[0];
130130
}
131131
editorEngine.style.updateCustom(elementStyle.key, colorValue);
132132
onValueChange?.(elementStyle.key, colorValue);
@@ -199,21 +199,22 @@ const ColorInput = observer(
199199
};
200200
return (
201201
<div className="w-32 p-[6px] gap-2 flex flex-row rounded cursor-pointer bg-background-onlook/75">
202-
{/* <BrandPopoverPicker
203-
color={color}
204-
onChange={sendStyleUpdate}
205-
onChangeEnd={sendStyleUpdate}
206-
backgroundImage={backgroundImage}
207-
compoundStyle={compoundStyle}
208-
/> */}
209-
210-
<PopoverPicker
202+
<BrandPopoverPicker
211203
color={color}
212204
onChange={sendStyleUpdate}
213205
onChangeEnd={sendStyleUpdate}
214206
backgroundImage={backgroundImage}
215207
compoundStyle={compoundStyle}
216208
/>
209+
210+
{/* <PopoverPicker
211+
color={color}
212+
onChange={sendStyleUpdate}
213+
onChangeEnd={sendStyleUpdate}
214+
backgroundImage={backgroundImage}
215+
compoundStyle={compoundStyle}
216+
/> */}
217+
217218
<ColorTextInput
218219
value={value}
219220
isFocused={isFocused}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { useEditorEngine } from '@/components/Context';
2+
import { invokeMainChannel } from '@/lib/utils';
3+
import { Theme } from '@onlook/models/assets';
4+
import { MainChannels } from '@onlook/models/constants';
15
import { Button } from '@onlook/ui/button';
26
import {
37
DropdownMenu,
@@ -6,14 +10,10 @@ import {
610
DropdownMenuTrigger,
711
} from '@onlook/ui/dropdown-menu';
812
import { Icons } from '@onlook/ui/icons';
13+
import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@onlook/ui/tooltip';
914
import { Color, toNormalCase } from '@onlook/utility';
1015
import { useState } from 'react';
1116
import { ColorPopover } from './ColorPopover';
12-
import { MainChannels } from '@onlook/models/constants';
13-
import { invokeMainChannel } from '@/lib/utils';
14-
import { useEditorEngine } from '@/components/Context';
15-
import { Tooltip, TooltipContent, TooltipTrigger, TooltipPortal } from '@onlook/ui/tooltip';
16-
import { Theme } from '@onlook/models/assets';
1717

1818
export interface ColorItem {
1919
name: string;
@@ -284,7 +284,7 @@ export const BrandPalletGroup = ({
284284
color.name,
285285
)}
286286
</span>
287-
<span className="text-xs text-muted-foreground">
287+
<span className="text-xs text-background-tertiary">
288288
{getColorValue(color)}
289289
</span>
290290
</div>

Diff for: apps/studio/src/routes/editor/LayersPanel/BrandTab/ColorPanel/ColorPopover.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { DEFAULT_COLOR_NAME } from '@onlook/models/constants';
12
import { Popover, PopoverContent, PopoverTrigger } from '@onlook/ui/popover';
23
import { Tooltip, TooltipContent, TooltipTrigger } from '@onlook/ui/tooltip';
4+
import { cn } from '@onlook/ui/utils';
35
import { toNormalCase, type Color } from '@onlook/utility';
46
import { camelCase } from 'lodash';
57
import { useEffect, useState } from 'react';
@@ -33,7 +35,8 @@ export const ColorPopover = ({
3335
}
3436
};
3537
const handleSave = () => {
36-
const camelCaseName = camelCase(editedName);
38+
const camelCaseName =
39+
editedName === DEFAULT_COLOR_NAME ? editedName : camelCase(editedName);
3740

3841
if (existedName?.includes(camelCaseName) && camelCaseName !== brandColor) {
3942
setError('Color name already exists');
@@ -74,15 +77,17 @@ export const ColorPopover = ({
7477
setEditedName(e.target.value);
7578
setError(null);
7679
}}
77-
className={`w-full rounded-md border ${
78-
error ? 'border-red-500' : 'border-white/10'
79-
} bg-background-secondary px-2 py-1 text-sm`}
80-
disabled={isDefaultPalette || editedName === 'DEFAULT'}
80+
className={cn(
81+
'w-full rounded-md border bg-background-secondary px-2 py-1 text-sm',
82+
error ? 'border-red-500' : 'border-white/10',
83+
)}
84+
disabled={isDefaultPalette || editedName === DEFAULT_COLOR_NAME}
8185
onKeyDown={(e) => {
8286
if (e.key === 'Enter') {
8387
handleSave();
8488
}
8589
}}
90+
autoFocus
8691
/>
8792
</TooltipTrigger>
8893
{error && (

Diff for: apps/studio/src/routes/editor/LayersPanel/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const LayersPanel = observer(() => {
158158

159159
<button
160160
className={cn(
161-
'w-16 h-16 rounded-xl flex flex-col items-center justify-center gap-1.5 p-2 hidden',
161+
'w-16 h-16 rounded-xl flex flex-col items-center justify-center gap-1.5 p-2',
162162
selectedTab === TabValue.BRAND && isLocked
163163
? 'bg-accent text-foreground border-[0.5px] border-foreground/20'
164164
: 'text-muted-foreground hover:text-foreground hover:bg-accent/50',

Diff for: packages/models/src/constants/editor.ts

+2
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ export const DefaultSettings = {
8686
buildFlags: '--no-lint',
8787
},
8888
};
89+
90+
export const DEFAULT_COLOR_NAME = 'DEFAULT';

Diff for: packages/utility/src/string.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ export function toNormalCase(str: string): string {
1616
return str;
1717
}
1818

19+
// Skip if the string is fully uppercase
20+
if (str === str.toUpperCase()) {
21+
return str;
22+
}
23+
1924
// For other cases, convert camelCase/PascalCase to normal case
25+
2026
return str
2127
.replace(/([A-Z])/g, ' $1')
2228
.trim()

0 commit comments

Comments
 (0)