Skip to content

Commit 728913e

Browse files
committed
Update level.chroma store when colors recalculated and use it in UI instead of 's chroma. Get rid of referencedC hack
1 parent e987dc2 commit 728913e

5 files changed

Lines changed: 7 additions & 10 deletions

File tree

packages/core/src/components/Grid/GridCellLevelHeader.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,21 @@ const ContrastInput = memo(function ContrastInput({
163163

164164
const LevelChromaInput = withValidation(withNumericIncrementControls(Input));
165165
const ChromaInput = memo(function ChromaInput({ levelId }: LevelComponentProps) {
166+
const level = getLevel(levelId);
167+
const chromaCap = useSubscribe(level.chromaCap.$raw);
168+
const error = useSubscribe(level.chromaCap.$validationError);
166169
const $chromaPlaceholder = useSignal((get) => {
167170
return get(chromaModeStore.$lastValidValue) === "even"
168-
? get(level.$tintColor).referencedC.toFixed(2)
171+
? get(level.chroma.$lastValidValue).toFixed(2)
169172
: "max";
170173
});
171174
const $chromaLabel = useSignal((get) => {
172175
const chromaCap = get(level.chromaCap.$raw);
173176

174177
return chromaCap ? LABEL_CHROMA_CAP_DEFINED : LABEL_CHROMA_CAP_SET;
175178
});
176-
177-
const level = getLevel(levelId);
178-
const chromaCap = useSubscribe(level.chromaCap.$raw);
179179
const chromaLabel = useSubscribe($chromaLabel);
180180
const chromaPlaceholder = useSubscribe($chromaPlaceholder);
181-
const error = useSubscribe(level.chromaCap.$validationError);
182181

183182
return (
184183
<LevelChromaInput

packages/core/src/stores/colors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function handleGeneratedColor(payload: GeneratedColorPayload) {
129129

130130
levelStore.$tintColor.set(payload.tint);
131131
for (const [hueId, color] of objectEntries(payload.cells)) {
132+
levelStore.chroma.$raw.set(color.c);
132133
upsertColor(payload.levelId, hueId, color);
133134
}
134135
});

packages/core/src/stores/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const FALLBACK_HUE_TINT_COLOR = FALLBACK_COLOR_DATA;
1212

1313
export const FALLBACK_LEVEL_TINT_COLOR = {
1414
...FALLBACK_COLOR_DATA,
15-
referencedC: 0,
1615
} as ColorLevelTintData;
1716

1817
export const FALLBACK_CELL_COLOR = {

packages/core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export type ColorData = LchColor & {
6161
css: ColorString;
6262
};
6363
export type ColorHueTintData = ColorData;
64-
export type ColorLevelTintData = ColorData & { referencedC: LevelChroma };
64+
export type ColorLevelTintData = ColorData;
6565
export type ColorCellData = ColorData & {
6666
p3: boolean;
6767
};

packages/core/src/utils/colors/calculateColors.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export function calculateColors(
124124
contrastLevel: MIN_LEVEL_TINT_CR,
125125
chroma: LevelChroma(0),
126126
}),
127-
referencedC: LevelChroma(0),
128127
},
129128
cells: {},
130129
});
@@ -151,7 +150,7 @@ export function calculateColors(
151150

152151
// Calculate level tint based only on the first hue row
153152
if (hueIndex === 0) {
154-
tint = { ...cellColor, referencedC: cellColor.c };
153+
tint = cellColor;
155154

156155
if (tint.cr < MIN_LEVEL_TINT_CR) {
157156
tint = {
@@ -161,7 +160,6 @@ export function calculateColors(
161160
contrastLevel: MIN_LEVEL_TINT_CR,
162161
chroma: chroma,
163162
}),
164-
referencedC: cellColor.c,
165163
};
166164
}
167165
}

0 commit comments

Comments
 (0)