Skip to content

Commit 09b5228

Browse files
committed
Added ability to set colours for entities
1 parent 6e144ad commit 09b5228

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Diff for: src/Widget.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
const Widget = () => {
1515
const [title, setTitle] = useSyncedState("title", "")
1616
const [description, setDescription] = useSyncedState("description", "")
17+
const [colour, setColour] = useSyncedState<string>("colour", EntityColours.None)
1718

1819
const [propertyIds, setPropertyIds] = useSyncedState<string[]>("propertyKeys", [])
1920
const properties = useSyncedMap<Property>("properties")
@@ -41,6 +42,19 @@ const Widget = () => {
4142

4243
usePropertyMenu(
4344
[
45+
{
46+
itemType: "color-selector",
47+
tooltip: "Entity colour",
48+
options: Object.keys(EntityColours).map((colourOption) => ({
49+
option: EntityColours[colourOption],
50+
tooltip: colourOption,
51+
})),
52+
propertyName: "entity-colour",
53+
selectedOption: colour,
54+
},
55+
{
56+
itemType: "separator",
57+
},
4458
{
4559
itemType: "dropdown",
4660
propertyName: "property-type",
@@ -63,12 +77,14 @@ const Widget = () => {
6377
addProperty()
6478
} else if (event.propertyName === "property-type" && event.propertyValue) {
6579
setTypeToAdd(event.propertyValue as PropertyType)
80+
} else if (event.propertyName === "entity-colour" && event.propertyValue) {
81+
setColour(event.propertyValue)
6682
}
6783
},
6884
)
6985

7086
return (
71-
<WidgetContainer>
87+
<WidgetContainer keyColour={colour}>
7288
<EnitityDetails
7389
title={title}
7490
description={description}

Diff for: src/components/WidgetContainer.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
interface WidgetContainerProps {
22
children?: FigmaDeclarativeNode | FigmaDeclarativeNode[]
3+
keyColour?: string
34
}
45

56
const WidgetContainer = (props: WidgetContainerProps) => (
67
<AutoLayout
78
direction="vertical"
89
verticalAlignItems="center"
9-
spacing={16}
10-
padding={16}
1110
cornerRadius={8}
1211
fill="#FFFFFF"
1312
effect={[
@@ -25,6 +24,9 @@ const WidgetContainer = (props: WidgetContainerProps) => (
2524
},
2625
]}
2726
>
28-
{props.children}
27+
<AutoLayout width="fill-parent" height={4} fill={props.keyColour || EntityColours.None} />
28+
<AutoLayout spacing={16} padding={16} direction="vertical">
29+
{props.children}
30+
</AutoLayout>
2931
</AutoLayout>
3032
)

Diff for: src/types/EntityColours.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const EntityColours = {
2+
None: "#FFF",
3+
Red: "#FA2626",
4+
Yellow: "#FFC000",
5+
Green: "#04A740",
6+
Blue: "#0463A7",
7+
Purple: "#620CE2",
8+
Magenta: "#E20CAA",
9+
Concrete: "#91A0AC",
10+
} as const
11+
12+
type EntityColourName = keyof typeof EntityColours

0 commit comments

Comments
 (0)