Skip to content

Commit 1e98035

Browse files
authored
Use semantic tokens for CellCore (#2448)
## Summary: Use semantic tokens for cell-core. Issue: WB-1797 ## Test plan: - Review use of semantic tokens in code to make sure the intent makes sense. - Review stories + Chromatic diff to make sure visual updates are intended Author: beaesguerra Reviewers: beaesguerra, jandrade Required Reviewers: Approved By: jandrade Checks: ✅ 12 checks were successful, ⏭️ 2 checks have been skipped Pull Request URL: #2448
1 parent 507cf2f commit 1e98035

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

.changeset/new-seas-sin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-cell": patch
3+
---
4+
5+
Use semantic color tokens in CellCore

packages/wonder-blocks-cell/src/components/internal/cell-core.tsx

+56-21
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,52 @@ const CellCore = (props: CellCoreProps): React.ReactElement => {
229229
);
230230
};
231231

232+
const cellTokens = {
233+
root: {
234+
default: {
235+
background: semanticColor.surface.primary,
236+
foreground: semanticColor.text.primary,
237+
},
238+
hover: {
239+
background: color.fadedBlue8,
240+
},
241+
press: {
242+
background: color.fadedBlue8,
243+
border: semanticColor.surface.emphasis,
244+
},
245+
selected: {
246+
background: color.fadedBlue8,
247+
foreground: color.activeBlue,
248+
border: semanticColor.surface.emphasis,
249+
},
250+
focus: {
251+
border: semanticColor.focus.outer,
252+
},
253+
disabled: {
254+
foreground: semanticColor.text.disabled,
255+
border: semanticColor.focus.outer,
256+
},
257+
},
258+
accessory: {
259+
default: {
260+
foreground: semanticColor.icon.primary,
261+
},
262+
selected: {
263+
foreground: semanticColor.icon.action,
264+
},
265+
disabled: {
266+
// Use secondary icon color for disabled state because opacity is
267+
// also applied to the accessory. Opacity is used so it is applied
268+
// to images also
269+
foreground: semanticColor.icon.secondary,
270+
},
271+
},
272+
};
273+
232274
const styles = StyleSheet.create({
233275
wrapper: {
234-
background: color.white,
235-
color: color.offBlack,
276+
background: cellTokens.root.default.background,
277+
color: cellTokens.root.default.foreground,
236278
display: "flex",
237279
minHeight: CellMeasurements.cellMinHeight,
238280
textAlign: "left",
@@ -262,13 +304,14 @@ const styles = StyleSheet.create({
262304
activeInnerWrapper: {
263305
position: "relative",
264306
":before": {
307+
// Styles for the left bar indicator
265308
content: "''",
266309
position: "absolute",
267310
top: 0,
268311
left: 0,
269312
bottom: 0,
270313
width: border.width.thick,
271-
backgroundColor: semanticColor.surface.emphasis,
314+
backgroundColor: cellTokens.root.selected.border,
272315
},
273316
},
274317

@@ -291,7 +334,7 @@ const styles = StyleSheet.create({
291334
accessoryRight: {
292335
// The right accessory will have this color by default. Unless the
293336
// accessory element overrides that color internally.
294-
color: semanticColor.icon.primary,
337+
color: cellTokens.accessory.default.foreground,
295338
},
296339

297340
/**
@@ -333,21 +376,21 @@ const styles = StyleSheet.create({
333376
// that the focus ring is drawn inside the cell.
334377
width: `calc(100% - ${spacing.xxxSmall_4}px)`,
335378
height: `calc(100% - ${spacing.xxxSmall_4}px)`,
336-
border: `${spacing.xxxxSmall_2}px solid ${color.blue}`,
379+
border: `${spacing.xxxxSmall_2}px solid ${cellTokens.root.focus.border}`,
337380
borderRadius: spacing.xxxSmall_4,
338381
},
339382
[":focus-visible[aria-disabled=true]:after" as any]: {
340-
borderColor: semanticColor.focus.outer,
383+
borderColor: cellTokens.root.disabled.border,
341384
},
342385

343386
// hover + enabled
344387
[":hover[aria-disabled=false]" as any]: {
345-
background: color.fadedBlue8,
388+
background: cellTokens.root.hover.background,
346389
},
347390

348391
// pressed + enabled
349392
[":active[aria-disabled=false]" as any]: {
350-
background: color.fadedBlue8,
393+
background: cellTokens.root.press.background,
351394
},
352395
// press + enabled + not currently selected (active prop: false)
353396
// We apply the left bar indicator styles on the inner-wrapper element
@@ -372,21 +415,13 @@ const styles = StyleSheet.create({
372415
},
373416

374417
active: {
375-
background: color.fadedBlue8,
376-
color: color.activeBlue,
418+
background: cellTokens.root.selected.background,
419+
color: cellTokens.root.selected.foreground,
377420
cursor: "default",
378-
379-
[":hover[aria-disabled=false]" as any]: {
380-
background: color.fadedBlue8,
381-
},
382-
383-
[":active[aria-disabled=false]" as any]: {
384-
background: color.fadedBlue8,
385-
},
386421
},
387422

388423
disabled: {
389-
color: color.offBlack32,
424+
color: cellTokens.root.disabled.foreground,
390425
":focus-visible": {
391426
// Prevent the focus ring from being displayed when the cell is
392427
// disabled.
@@ -395,11 +430,11 @@ const styles = StyleSheet.create({
395430
},
396431

397432
accessoryActive: {
398-
color: color.blue,
433+
color: cellTokens.accessory.selected.foreground,
399434
},
400435

401436
accessoryDisabled: {
402-
color: color.offBlack,
437+
color: cellTokens.accessory.disabled.foreground,
403438
opacity: 0.32,
404439
},
405440
});

0 commit comments

Comments
 (0)