Skip to content

Commit 4ab523b

Browse files
authored
[WB-1814.10] Refactor wonder-blocks-dropdown to use semantic colors (#2474)
## Summary: Last PR that migrates the remaining components to use semantic colors. - Added `All Variants` stories to `ActionItem` and `OptionItem`. - Refactored `ActionItem` and `OptionItem` to use semantic colors. - Also refactored `ActionMenu`, `SingleSelect`, `MultiSelect` and `Combobox` to use semantic colors. - Simplified the styles in `ActionMenuOpenerCore` to use a single static StyleSheet instance (instead of generating another one in runtime). ### Implementation plan: 1. #2439 2. #2440 3. #2441 4. #2446 5. #2449 6. #2464 7. #2468 8. #2470 9. #2472 10. Dropdown (current PR) Issue: WB-1814 ## Test plan: Verify that all the dropdown stories are still working as expected. Author: jandrade Reviewers: jandrade, beaesguerra Required Reviewers: Approved By: beaesguerra Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ 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), ⏭️ dependabot, ✅ gerald Pull Request URL: #2474
1 parent 8fc65a9 commit 4ab523b

21 files changed

+558
-191
lines changed

.changeset/seven-mangos-drive.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-dropdown": patch
3+
---
4+
5+
Migrate Dropdown components to semanticColor. Simplify ActionMenuOpenerCore styles

.storybook/preview.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import wonderBlocksTheme from "./wonder-blocks-theme";
33
import {Decorator} from "@storybook/react";
4-
import {color} from "@khanacademy/wonder-blocks-tokens";
4+
import {semanticColor} from "@khanacademy/wonder-blocks-tokens";
55
import Link from "@khanacademy/wonder-blocks-link";
66
import {ThemeSwitcherContext} from "@khanacademy/wonder-blocks-theming";
77
import {RenderStateRoot} from "../packages/wonder-blocks-core/src";
@@ -50,19 +50,19 @@ const parameters = {
5050
values: [
5151
{
5252
name: "light",
53-
value: color.white,
53+
value: semanticColor.surface.primary,
5454
},
5555
{
5656
name: "darkBlue",
57-
value: color.darkBlue,
57+
value: semanticColor.surface.inverse,
5858
},
5959
{
6060
name: "khanmigo",
61-
value: color.eggplant,
61+
value: semanticColor.khanmigo.primary,
6262
},
6363
{
6464
name: "offWhite",
65-
value: color.offWhite,
65+
value: semanticColor.surface.secondary,
6666
},
6767
],
6868
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import * as React from "react";
2+
import type {Meta, StoryObj} from "@storybook/react";
3+
4+
import {AllVariants} from "../components/all-variants";
5+
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
6+
import {IconMappings} from "../wonder-blocks-icon/phosphor-icon.argtypes";
7+
import {ActionItem} from "@khanacademy/wonder-blocks-dropdown";
8+
import {View} from "@khanacademy/wonder-blocks-core";
9+
10+
const rows = [
11+
{name: "Unchecked", props: {checked: false}},
12+
{name: "Checked", props: {checked: true}},
13+
{name: "Indeterminate", props: {checked: null}},
14+
];
15+
16+
const columns = [
17+
{
18+
name: "Default",
19+
props: {},
20+
},
21+
{
22+
name: "Disabled",
23+
props: {disabled: true},
24+
},
25+
{
26+
name: "Custom label",
27+
props: {
28+
label: "Action Item",
29+
onClick: () => {},
30+
leftAccessory: (
31+
<PhosphorIcon icon={IconMappings.calendar} size="medium" />
32+
),
33+
rightAccessory: (
34+
<PhosphorIcon icon={IconMappings.caretRight} size="medium" />
35+
),
36+
},
37+
},
38+
];
39+
40+
type Story = StoryObj<typeof ActionItem>;
41+
42+
/**
43+
* The following stories are used to generate the pseudo states for the
44+
* ActionItem component. This is only used for visual testing in Chromatic.
45+
*/
46+
const meta = {
47+
title: "Packages / Dropdown / ActionItem / ActionItem - All Variants",
48+
component: ActionItem,
49+
render: (args) => (
50+
<AllVariants rows={rows} columns={columns}>
51+
{(props) => <ActionItem {...args} {...props} />}
52+
</AllVariants>
53+
),
54+
args: {
55+
label: "Action Item",
56+
onClick: () => {},
57+
disabled: false,
58+
testId: "",
59+
lang: "",
60+
role: "menuitem",
61+
style: {},
62+
horizontalRule: "none",
63+
leftAccessory: null,
64+
rightAccessory: null,
65+
},
66+
decorators: [
67+
(Story): React.ReactElement<React.ComponentProps<typeof View>> => (
68+
<View style={{width: 800}}>
69+
<Story />
70+
</View>
71+
),
72+
],
73+
parameters: {
74+
backgrounds: {
75+
default: "offWhite",
76+
},
77+
},
78+
tags: ["!autodocs"],
79+
} satisfies Meta<typeof ActionItem>;
80+
81+
export default meta;
82+
83+
export const Default: Story = {};
84+
85+
export const Hover: Story = {
86+
parameters: {pseudo: {hover: true}},
87+
};
88+
89+
export const Focus: Story = {
90+
parameters: {pseudo: {focusVisible: true}},
91+
};
92+
93+
export const HoverFocus: Story = {
94+
name: "Hover + Focus",
95+
parameters: {pseudo: {hover: true, focusVisible: true}},
96+
};
97+
98+
export const Active: Story = {
99+
parameters: {pseudo: {active: true, focusVisible: true}},
100+
};

__docs__/wonder-blocks-dropdown/action-item.stories.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {StyleSheet} from "aphrodite";
44
import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
55
import {ActionItem} from "@khanacademy/wonder-blocks-dropdown";
66
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
7-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
7+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
88

99
import ComponentInfo from "../components/component-info";
1010
import packageConfig from "../../packages/wonder-blocks-dropdown/package.json";
@@ -26,12 +26,12 @@ const defaultArgs = {
2626

2727
const styles = StyleSheet.create({
2828
example: {
29-
background: color.offWhite,
29+
background: semanticColor.surface.secondary,
3030
padding: spacing.medium_16,
3131
width: 300,
3232
},
3333
items: {
34-
background: color.white,
34+
background: semanticColor.surface.primary,
3535
},
3636
});
3737

@@ -69,6 +69,10 @@ export default {
6969
version={packageConfig.version}
7070
/>
7171
),
72+
// These stories are being tested in action-item-variants.stories.tsx
73+
chromatic: {
74+
disableSnapshot: true,
75+
},
7276
},
7377
} as Meta<typeof ActionItem>;
7478

@@ -154,4 +158,10 @@ export const HorizontalRule = {
154158
<ActionItem {...args} />
155159
</View>
156160
),
161+
parameters: {
162+
chromatic: {
163+
// Enabling to test how the horizontal rule looks.
164+
disableSnapshot: false,
165+
},
166+
},
157167
};

__docs__/wonder-blocks-dropdown/action-menu.stories.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {View} from "@khanacademy/wonder-blocks-core";
1010
import {Checkbox} from "@khanacademy/wonder-blocks-form";
1111
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
1212
import Pill from "@khanacademy/wonder-blocks-pill";
13-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
13+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
1414
import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
1515
import {
1616
ActionItem,
@@ -122,7 +122,7 @@ export default {
122122

123123
const styles = StyleSheet.create({
124124
example: {
125-
background: color.offWhite,
125+
background: semanticColor.surface.secondary,
126126
padding: spacing.medium_16,
127127
},
128128
exampleExtended: {
@@ -144,22 +144,22 @@ const styles = StyleSheet.create({
144144
* Custom opener styles
145145
*/
146146
customOpener: {
147-
borderLeft: `${spacing.xxxSmall_4}px solid ${color.purple}`,
147+
borderLeft: `${spacing.xxxSmall_4}px solid ${semanticColor.status.warning.foreground}`,
148148
borderRadius: spacing.xxxSmall_4,
149-
background: color.fadedPurple24,
150-
color: color.offBlack,
149+
background: semanticColor.status.warning.background,
150+
color: semanticColor.text.primary,
151151
padding: spacing.medium_16,
152152
},
153153
focused: {
154-
outlineColor: color.purple,
154+
outlineColor: semanticColor.border.focus,
155155
outlineOffset: spacing.xxxxSmall_2,
156156
},
157157
hovered: {
158158
textDecoration: "underline",
159159
cursor: "pointer",
160160
},
161161
pressed: {
162-
color: color.blue,
162+
color: semanticColor.status.warning.foreground,
163163
},
164164
});
165165

@@ -482,8 +482,8 @@ export const CustomActionItems: StoryComponentType = {
482482
onClick={action("user profile clicked!")}
483483
style={{
484484
[":hover [data-testid=new-pill]" as any]: {
485-
backgroundColor: color.white,
486-
color: color.blue,
485+
backgroundColor: semanticColor.surface.primary,
486+
color: semanticColor.status.notice.foreground,
487487
},
488488
}}
489489
/>,

__docs__/wonder-blocks-dropdown/combobox.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as React from "react";
77
import magnifyingGlassIcon from "@phosphor-icons/core/bold/magnifying-glass-bold.svg";
88

99
import {LabelLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography";
10-
import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
10+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
1111
import {Checkbox} from "@khanacademy/wonder-blocks-form";
1212
import {Combobox, OptionItem} from "@khanacademy/wonder-blocks-dropdown";
1313
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
@@ -49,7 +49,7 @@ const customItems = allProfilesWithPictures.map((user, index) => (
4949

5050
const styles = StyleSheet.create({
5151
example: {
52-
background: color.offWhite,
52+
background: semanticColor.surface.secondary,
5353
padding: spacing.medium_16,
5454
width: 300,
5555
},

__docs__/wonder-blocks-dropdown/listbox.stories.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as React from "react";
66
import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
77
import {Listbox, OptionItem} from "@khanacademy/wonder-blocks-dropdown";
88
import Pill from "@khanacademy/wonder-blocks-pill";
9-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
9+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
1010

1111
import {allProfilesWithPictures} from "./option-item-examples";
1212

@@ -27,12 +27,12 @@ const items = [
2727

2828
const styles = StyleSheet.create({
2929
example: {
30-
background: color.offWhite,
30+
background: semanticColor.surface.secondary,
3131
padding: spacing.medium_16,
3232
width: 360,
3333
},
3434
customListbox: {
35-
border: `5px solid ${color.offBlack16}`,
35+
border: `5px solid ${semanticColor.border.primary}`,
3636
width: 250,
3737
},
3838
});

__docs__/wonder-blocks-dropdown/multi-select.stories.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
88
import Button from "@khanacademy/wonder-blocks-button";
99
import {Checkbox} from "@khanacademy/wonder-blocks-form";
1010
import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal";
11-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
11+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
1212
import {HeadingLarge} from "@khanacademy/wonder-blocks-typography";
1313
import {MultiSelect, OptionItem} from "@khanacademy/wonder-blocks-dropdown";
1414
import Pill from "@khanacademy/wonder-blocks-pill";
@@ -109,22 +109,22 @@ const styles = StyleSheet.create({
109109
* Custom opener styles
110110
*/
111111
customOpener: {
112-
borderLeft: `${spacing.xxxSmall_4}px solid ${color.purple}`,
112+
borderLeft: `${spacing.xxxSmall_4}px solid ${semanticColor.status.warning.foreground}`,
113113
borderRadius: spacing.xxxSmall_4,
114-
background: color.fadedPurple24,
115-
color: color.offBlack,
114+
background: semanticColor.status.warning.background,
115+
color: semanticColor.text.primary,
116116
padding: spacing.medium_16,
117117
},
118118
focused: {
119-
outlineColor: color.purple,
119+
outlineColor: semanticColor.border.focus,
120120
outlineOffset: spacing.xxxxSmall_2,
121121
},
122122
hovered: {
123123
textDecoration: "underline",
124124
cursor: "pointer",
125125
},
126126
pressed: {
127-
color: color.blue,
127+
color: semanticColor.status.warning.foreground,
128128
},
129129
});
130130

0 commit comments

Comments
 (0)