Skip to content

Commit fff5da0

Browse files
authored
[WB-1814.8] Refactor Popover, Tooltip, Toolbar to use semantic colors (#2470)
## Summary: Next step is to refactor the `Popover`, `Tooltip` and `Toolbar` packages to use semantic colors. ### Implementation plan: 1. #2439 2. #2440 3. #2441 4. #2446 5. #2449 6. #2464 7. #2468 8. Popover, Tooltip, Toolbar (current PR) 9. Dropdown 10. Clickable, Pill Issue: WB-1814 ## Test plan: Verify that the Modal Chromatic snapshots are mostly unchanged. Author: jandrade Reviewers: beaesguerra Required Reviewers: Approved By: beaesguerra Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Chromatic - Build and test on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ⏭️ dependabot Pull Request URL: #2470
1 parent 6d37702 commit fff5da0

File tree

10 files changed

+52
-47
lines changed

10 files changed

+52
-47
lines changed

.changeset/curly-countries-protect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-popover": patch
3+
---
4+
5+
Migrate to semanticColor tokens

.changeset/eighty-grapes-mate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-toolbar": patch
3+
---
4+
5+
Migrate to semanticColor tokens

.changeset/mean-badgers-sit.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-tooltip": patch
3+
---
4+
5+
Migrate to semanticColor tokens

__docs__/wonder-blocks-popover/popover-content-core.stories.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {Meta, StoryObj} from "@storybook/react";
55
import Clickable from "@khanacademy/wonder-blocks-clickable";
66
import {View} from "@khanacademy/wonder-blocks-core";
77
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
8-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
99
import {
1010
Body,
1111
HeadingSmall,
@@ -67,7 +67,7 @@ const styles = StyleSheet.create({
6767
action: {
6868
backgroundColor: "transparent",
6969
border: "none",
70-
color: color.white,
70+
color: semanticColor.text.inverse,
7171
cursor: "pointer",
7272
margin: spacing.small_12,
7373
padding: spacing.xxSmall_6,
@@ -132,7 +132,7 @@ const CustomPopoverContent = (
132132
<>
133133
<PhosphorIcon
134134
icon={IconMappings.pencilSimple}
135-
color={color.gold}
135+
color={semanticColor.status.warning.foreground}
136136
size="large"
137137
/>
138138
<LabelLarge>Option 1</LabelLarge>
@@ -144,7 +144,7 @@ const CustomPopoverContent = (
144144
<>
145145
<PhosphorIcon
146146
icon={IconMappings.pencilSimple}
147-
color={color.green}
147+
color={semanticColor.status.success.foreground}
148148
size="large"
149149
/>
150150
<LabelLarge>Option 2</LabelLarge>
@@ -156,7 +156,7 @@ const CustomPopoverContent = (
156156
<>
157157
<PhosphorIcon
158158
icon={IconMappings.pencilSimple}
159-
color={color.blue}
159+
color={semanticColor.status.notice.foreground}
160160
size="large"
161161
/>
162162
<LabelLarge>Option 3</LabelLarge>

__docs__/wonder-blocks-popover/popover.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {Meta, StoryObj} from "@storybook/react";
55
import Button from "@khanacademy/wonder-blocks-button";
66
import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
77
import {Strut} from "@khanacademy/wonder-blocks-layout";
8-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
99
import {HeadingMedium, LabelLarge} from "@khanacademy/wonder-blocks-typography";
1010
import type {Placement} from "@khanacademy/wonder-blocks-tooltip";
1111

@@ -81,7 +81,7 @@ const styles = StyleSheet.create({
8181
justifyContent: "space-between",
8282
},
8383
playground: {
84-
border: `1px dashed ${color.purple}`,
84+
border: `1px dashed ${semanticColor.border.primary}`,
8585
marginTop: spacing.large_24,
8686
padding: spacing.large_24,
8787
flexDirection: "row",

__docs__/wonder-blocks-tooltip/tooltip.stories.tsx

+9-23
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
1212
import {TextField} from "@khanacademy/wonder-blocks-form";
1313
import IconButton from "@khanacademy/wonder-blocks-icon-button";
1414
import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal";
15-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
15+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
1616
import {Body} from "@khanacademy/wonder-blocks-typography";
1717
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
1818

@@ -313,7 +313,7 @@ export const WithStyle: StoryComponentType = () => {
313313
<View style={[styles.centered, styles.row]}>
314314
<Tooltip
315315
contentStyle={{
316-
color: color.white,
316+
color: semanticColor.text.inverse,
317317
padding: spacing.xLarge_32,
318318
}}
319319
content={`This is a styled tooltip.`}
@@ -337,25 +337,6 @@ WithStyle.parameters = {
337337
},
338338
};
339339

340-
WithStyle.play = async ({canvasElement}) => {
341-
const canvas = within(canvasElement.ownerDocument.body);
342-
343-
// Get HTML elements
344-
const tooltipContent = await canvas.findByTestId("test-tooltip-content");
345-
const innerTooltipView =
346-
// eslint-disable-next-line testing-library/no-node-access
347-
(await canvas.findByRole("tooltip")).firstChild;
348-
349-
// Assert
350-
await expect(innerTooltipView).toHaveStyle(
351-
"background-color: rgb(11, 33, 73)",
352-
);
353-
await expect(tooltipContent).toHaveStyle({
354-
padding: "32px",
355-
color: "#fff",
356-
});
357-
};
358-
359340
/**
360341
* Tooltip by default (and for performance reasons) only updates its position
361342
* under the following conditions:
@@ -474,7 +455,7 @@ const styles = StyleSheet.create({
474455
height: "200vh",
475456
},
476457
block: {
477-
border: `solid 1px ${color.purple}`,
458+
border: `solid 1px ${semanticColor.mastery.primary}`,
478459
width: spacing.xLarge_32,
479460
height: spacing.xLarge_32,
480461
alignItems: "center",
@@ -506,7 +487,12 @@ export const InTopCorner = {
506487
icon={info}
507488
size="small"
508489
aria-hidden
509-
style={{":hover": {backgroundColor: color.red}}}
490+
style={{
491+
":hover": {
492+
backgroundColor:
493+
semanticColor.status.critical.foreground,
494+
},
495+
}}
510496
/>
511497
</Tooltip>
512498
</View>

packages/wonder-blocks-popover/src/components/popover-content-core.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {StyleSheet} from "aphrodite";
33

44
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
55
import {View} from "@khanacademy/wonder-blocks-core";
6-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
6+
import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
77

88
import CloseButton from "./close-button";
99

@@ -107,8 +107,9 @@ export default class PopoverContentCore extends React.Component<Props> {
107107
const styles = StyleSheet.create({
108108
content: {
109109
borderRadius: spacing.xxxSmall_4,
110-
border: `solid 1px ${color.offBlack16}`,
111-
backgroundColor: color.white,
110+
border: `solid 1px ${semanticColor.border.primary}`,
111+
backgroundColor: semanticColor.surface.primary,
112+
// TODO(WB-1878): Use `elevation` token.
112113
boxShadow: `0 ${spacing.xSmall_8}px ${spacing.xSmall_8}px 0 ${color.offBlack8}`,
113114
margin: 0,
114115
maxWidth: spacing.medium_16 * 18, // 288px
@@ -120,13 +121,13 @@ const styles = StyleSheet.create({
120121
* Theming
121122
*/
122123
blue: {
123-
backgroundColor: color.blue,
124-
color: color.white,
124+
backgroundColor: semanticColor.surface.emphasis,
125+
color: semanticColor.text.inverse,
125126
},
126127

127128
darkBlue: {
128-
backgroundColor: color.darkBlue,
129-
color: color.white,
129+
backgroundColor: semanticColor.surface.inverse,
130+
color: semanticColor.text.inverse,
130131
},
131132

132133
/**

packages/wonder-blocks-toolbar/src/components/toolbar.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from "react";
55
import {StyleSheet} from "aphrodite";
66

77
import {View} from "@khanacademy/wonder-blocks-core";
8-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
8+
import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
99
import {
1010
HeadingSmall,
1111
LabelLarge,
@@ -120,13 +120,13 @@ export default function Toolbar({
120120

121121
const sharedStyles = StyleSheet.create({
122122
container: {
123-
border: `1px solid ${color.offBlack16}`,
123+
background: semanticColor.surface.primary,
124+
border: `1px solid ${semanticColor.border.primary}`,
124125
flex: 1,
125126
display: "grid",
126127
alignItems: "center",
127128
minHeight: 66,
128-
paddingLeft: spacing.medium_16,
129-
paddingRight: spacing.medium_16,
129+
paddingInline: spacing.medium_16,
130130
width: "100%",
131131
},
132132
containerWithTextTitle: {
@@ -142,10 +142,11 @@ const sharedStyles = StyleSheet.create({
142142
small: {
143143
minHeight: 50,
144144
},
145+
// TODO(WB-1852): Remove light variant.
145146
dark: {
146-
backgroundColor: color.darkBlue,
147+
background: semanticColor.surface.inverse,
147148
boxShadow: `0 1px 0 0 ${color.white64}`,
148-
color: "white",
149+
color: semanticColor.text.inverse,
149150
},
150151
leftColumn: {
151152
alignItems: "center",
@@ -159,7 +160,7 @@ const sharedStyles = StyleSheet.create({
159160
flexGrow: 1,
160161
},
161162
subtitle: {
162-
color: color.offBlack64,
163+
color: semanticColor.text.secondary,
163164
},
164165
titles: {
165166
padding: spacing.small_12,

packages/wonder-blocks-tooltip/src/components/tooltip-bubble.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {StyleSheet} from "aphrodite";
22
import * as React from "react";
33
import {View} from "@khanacademy/wonder-blocks-core";
4-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
4+
import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
55

66
import TooltipContent from "./tooltip-content";
77
import TooltipTail from "./tooltip-tail";
@@ -124,8 +124,9 @@ const styles = StyleSheet.create({
124124
content: {
125125
maxWidth: 472,
126126
borderRadius: spacing.xxxSmall_4,
127-
border: `solid 1px ${color.offBlack16}`,
128-
backgroundColor: color.white,
127+
border: `solid 1px ${semanticColor.border.primary}`,
128+
backgroundColor: semanticColor.surface.primary,
129+
// TODO(WB-1878): Use `elevation` token.
129130
boxShadow: `0 ${spacing.xSmall_8}px ${spacing.xSmall_8}px 0 ${color.offBlack8}`,
130131
justifyContent: "center",
131132
},

packages/wonder-blocks-tooltip/src/components/tooltip-tail.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export default class TooltipTail extends React.Component<Props> {
182182
*/
183183
_maybeRenderDropshadow(points: [string, string, string]): React.ReactNode {
184184
const position = this._getFilterPositioning();
185+
185186
if (!position) {
186187
return null;
187188
}

0 commit comments

Comments
 (0)