Skip to content

Commit 24556ad

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 cbfd7ff commit 24556ad

5 files changed

Lines changed: 8 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,22 @@ 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 chroma = useSubscribe(level.chroma.$raw);
168+
const chromaCap = useSubscribe(level.chromaCap.$raw);
169+
const error = useSubscribe(level.chromaCap.$validationError);
166170
const $chromaPlaceholder = useSignal((get) => {
167171
return get(chromaModeStore.$lastValidValue) === "even"
168-
? get(level.$tintColor).referencedC.toFixed(2)
172+
? get(level.chroma.$lastValidValue).toFixed(2)
169173
: "max";
170174
});
171175
const $chromaLabel = useSignal((get) => {
172176
const chromaCap = get(level.chromaCap.$raw);
173177

174178
return chromaCap ? LABEL_CHROMA_CAP_DEFINED : LABEL_CHROMA_CAP_SET;
175179
});
176-
177-
const level = getLevel(levelId);
178-
const chroma = useSubscribe(level.chroma.$raw);
179-
const chromaCap = useSubscribe(level.chromaCap.$raw);
180180
const chromaLabel = useSubscribe($chromaLabel);
181181
const chromaPlaceholder = useSubscribe($chromaPlaceholder);
182-
const error = useSubscribe(level.chromaCap.$validationError);
183182

184183
return (
185184
<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)