forked from onlook-dev/onlook
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.ts
More file actions
42 lines (38 loc) · 1.42 KB
/
index.ts
File metadata and controls
42 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type {
CompoundStyle,
CompoundStyleKey,
SingleStyle,
StyleParams,
StyleType,
} from './models';
export class SingleStyleImpl implements SingleStyle {
public readonly elStyleType = 'single';
constructor(
public readonly key: string,
public readonly defaultValue: string,
public readonly displayName: string,
public readonly type: StyleType,
public readonly params?: StyleParams,
) {}
getValue(styleRecord: Record<string, string>) {
// If this is a color style (key is 'color' or ends with 'Color'), ensure we get the actual value
// This ensures text colors and other color values display correctly in the properties panel
if (this.type === 'color' && styleRecord[this.key]) {
return styleRecord[this.key];
}
return styleRecord[this.key] ?? this.defaultValue;
}
}
export class CompoundStyleImpl implements CompoundStyle {
public readonly elStyleType = 'compound';
constructor(
public readonly key: CompoundStyleKey,
public readonly head: SingleStyleImpl,
public readonly children: SingleStyleImpl[],
) {}
isHeadSameAsChildren(style: Record<string, string>) {
const headValue = this.head.getValue(style);
const childrenValues = this.children.map((child) => child.getValue(style));
return !childrenValues.every((value) => value === headValue);
}
}