Skip to content

Commit 8fc65a9

Browse files
authored
[WB-1814.9] Refactor Clickable and Pill to use semantic colors (#2472)
## Summary: - Migrate Clickable and Pill to use semantic colors - Add `All Variants` story to Pill ### Implementation plan: 1. #2439 2. #2440 3. #2441 4. #2446 5. #2449 6. #2464 7. #2468 8. #2470 9. Clickable, Pill (current PR) 10. Dropdown Issue: WB-1814 ## Test plan: Navigate to the `Clickable` and `Pill` stories in Storybook and verify that the colors are correct. Author: jandrade Reviewers: jandrade, 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), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ gerald, ⏭️ dependabot Pull Request URL: #2472
1 parent fff5da0 commit 8fc65a9

File tree

10 files changed

+231
-272
lines changed

10 files changed

+231
-272
lines changed

.changeset/friendly-weeks-drum.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@khanacademy/wonder-blocks-pill": patch
3+
---
4+
5+
- Migrate to `semanticColor`.
6+
- Update background from 16% to 8%.
7+
- Update focus outline to always be `blue` (using global focus color).

.changeset/shaggy-windows-rescue.md

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

__docs__/wonder-blocks-clickable/accessibility.stories.tsx

+27-31
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,51 @@ import {StyleSheet} from "aphrodite";
44
import Clickable from "@khanacademy/wonder-blocks-clickable";
55
import {View} from "@khanacademy/wonder-blocks-core";
66
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
7-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
7+
import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
88
import {Body} from "@khanacademy/wonder-blocks-typography";
99

1010
import {IconMappings} from "../wonder-blocks-icon/phosphor-icon.argtypes";
1111

12+
const actionCategory = semanticColor.action.outlined.progressive;
13+
1214
const styles = StyleSheet.create({
13-
resting: {
14-
boxShadow: `inset 0px 0px 1px 1px ${color.purple}`,
15+
rest: {
16+
border: `1px solid ${actionCategory.default.border}`,
1517
padding: spacing.xSmall_8,
1618
},
17-
hovered: {
19+
hover: {
1820
textDecoration: "underline",
19-
backgroundColor: color.blue,
20-
color: color.white,
21+
borderColor: actionCategory.hover.border,
22+
backgroundColor: actionCategory.hover.background,
23+
color: actionCategory.hover.foreground,
2124
},
22-
pressed: {
23-
color: color.darkBlue,
25+
press: {
26+
background: actionCategory.press.background,
27+
borderColor: actionCategory.press.border,
28+
color: actionCategory.press.foreground,
2429
},
25-
focused: {
26-
outline: `solid 4px ${color.purple}`,
30+
focus: {
31+
outline: `solid 1px ${semanticColor.border.focus}`,
32+
outlineOffset: spacing.xxxxSmall_2,
2733
},
2834
panel: {
2935
padding: spacing.medium_16,
30-
boxShadow: `inset 0px 0px 0 1px ${color.offBlack8}`,
36+
// TODO(WB-1878): Use elevation token.
37+
boxShadow: `0 ${spacing.xSmall_8}px ${spacing.xSmall_8}px 0 ${color.offBlack8}`,
3138
},
3239
});
3340

3441
export default {
3542
title: "Packages / Clickable / Clickable / Accessibility",
3643
component: Clickable,
37-
38-
// Disables chromatic testing for these stories.
3944
parameters: {
40-
previewTabs: {
41-
canvas: {
42-
hidden: true,
43-
},
44-
},
45-
46-
viewMode: "docs",
47-
45+
// Disables chromatic testing for these stories.
4846
chromatic: {
4947
disableSnapshot: true,
5048
},
5149
},
50+
// Include these stories in the Docs tab, but hide them from the sidebar.
51+
tags: ["autodocs", "!dev"],
5252
};
5353

5454
export const Labeling = {
@@ -58,9 +58,7 @@ export const Labeling = {
5858
onClick={() => {}}
5959
aria-label="More information about this subject"
6060
>
61-
{({hovered, focused, pressed}) => (
62-
<PhosphorIcon icon={IconMappings.info} />
63-
)}
61+
{() => <PhosphorIcon icon={IconMappings.info} />}
6462
</Clickable>
6563
</View>
6664
),
@@ -73,9 +71,7 @@ export const DisabledState = {
7371
onClick={(e) => console.log("Hello, world!")}
7472
disabled={true}
7573
>
76-
{({hovered, focused, pressed}) =>
77-
"This is a disabled clickable element"
78-
}
74+
{() => "This is a disabled clickable element"}
7975
</Clickable>
8076
),
8177

@@ -89,10 +85,10 @@ export const KeyboardNavigation = {
8985
{({hovered, focused, pressed}) => (
9086
<View
9187
style={[
92-
styles.resting,
93-
hovered && styles.hovered,
94-
focused && styles.focused,
95-
pressed && styles.pressed,
88+
styles.rest,
89+
hovered && styles.hover,
90+
focused && styles.focus,
91+
pressed && styles.press,
9692
]}
9793
>
9894
<Body>Open School Info</Body>

__docs__/wonder-blocks-clickable/clickable-behavior.stories.tsx

+21-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {StyleSheet} from "aphrodite";
33
import type {Meta, StoryObj} from "@storybook/react";
44

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

88
import {getClickableBehavior} from "@khanacademy/wonder-blocks-clickable";
99
import packageConfig from "../../packages/wonder-blocks-clickable/package.json";
@@ -52,9 +52,9 @@ export const Default: StoryComponentType = (args: any) => {
5252
<View
5353
style={[
5454
styles.clickable,
55-
hovered && styles.hovered,
56-
focused && styles.focused,
57-
pressed && styles.pressed,
55+
hovered && styles.hover,
56+
focused && styles.focus,
57+
pressed && styles.press,
5858
]}
5959
{...childrenProps}
6060
>
@@ -92,9 +92,9 @@ export const WrappingButton: StoryComponentType = (args: any) => {
9292
style={[
9393
styles.clickable,
9494
styles.newButton,
95-
hovered && styles.hovered,
96-
focused && styles.focused,
97-
pressed && styles.pressed,
95+
hovered && styles.hover,
96+
focused && styles.focus,
97+
pressed && styles.press,
9898
]}
9999
{...childrenProps}
100100
>
@@ -125,9 +125,9 @@ export const WithTabIndex: StoryComponentType = () => {
125125
<View
126126
style={[
127127
styles.clickable,
128-
hovered && styles.hovered,
129-
focused && styles.focused,
130-
pressed && styles.pressed,
128+
hovered && styles.hover,
129+
focused && styles.focus,
130+
pressed && styles.press,
131131
]}
132132
{...childrenProps}
133133
>
@@ -156,6 +156,8 @@ WithTabIndex.parameters = {
156156
},
157157
};
158158

159+
const actionCategory = semanticColor.action.outlined.progressive;
160+
159161
const styles = StyleSheet.create({
160162
clickable: {
161163
cursor: "pointer",
@@ -164,18 +166,19 @@ const styles = StyleSheet.create({
164166
},
165167
newButton: {
166168
border: "none",
167-
backgroundColor: color.white,
169+
backgroundColor: actionCategory.default.background,
168170
width: "100%",
169171
},
170-
hovered: {
172+
hover: {
171173
textDecoration: "underline",
172-
backgroundColor: color.blue,
173-
color: color.white,
174+
backgroundColor: actionCategory.hover.background,
175+
color: actionCategory.hover.foreground,
174176
},
175-
pressed: {
176-
backgroundColor: color.darkBlue,
177+
press: {
178+
backgroundColor: actionCategory.press.background,
177179
},
178-
focused: {
179-
outline: `solid 4px ${color.purple}`,
180+
focus: {
181+
outline: `solid 1px ${semanticColor.border.focus}`,
182+
outlineOffset: spacing.xxxxSmall_2,
180183
},
181184
});

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {MemoryRouter, Route, Switch} from "react-router-dom";
44
import type {Meta, StoryObj} from "@storybook/react";
55

66
import {View} from "@khanacademy/wonder-blocks-core";
7-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
7+
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
88
import {Body, LabelLarge} from "@khanacademy/wonder-blocks-typography";
99

1010
import Clickable from "@khanacademy/wonder-blocks-clickable";
@@ -305,28 +305,30 @@ Ref.parameters = {
305305
},
306306
};
307307

308+
const progressive = semanticColor.action.outlined.progressive;
309+
308310
const styles = StyleSheet.create({
309311
clickable: {
310312
borderWidth: 1,
311313
padding: spacing.medium_16,
312314
},
313315
hovered: {
314316
textDecoration: "underline",
315-
backgroundColor: color.teal,
317+
backgroundColor: progressive.hover.background,
316318
},
317319
pressed: {
318-
color: color.blue,
320+
color: progressive.press.foreground,
319321
},
320322
focused: {
321-
outline: `solid 4px ${color.purple}`,
323+
outline: `solid 4px ${semanticColor.border.focus}`,
322324
},
323325
centerText: {
324326
gap: spacing.medium_16,
325327
textAlign: "center",
326328
},
327329
dark: {
328-
backgroundColor: color.darkBlue,
329-
color: color.white,
330+
backgroundColor: semanticColor.surface.inverse,
331+
color: semanticColor.text.inverse,
330332
padding: spacing.xSmall_8,
331333
},
332334
row: {
@@ -337,13 +339,13 @@ const styles = StyleSheet.create({
337339
marginRight: spacing.large_24,
338340
},
339341
navigation: {
340-
border: `1px dashed ${color.purple}`,
342+
border: `1px dashed ${semanticColor.border.primary}`,
341343
marginTop: spacing.large_24,
342344
padding: spacing.large_24,
343345
},
344346
disabled: {
345-
color: color.white,
346-
backgroundColor: color.offBlack64,
347+
color: semanticColor.text.inverse,
348+
backgroundColor: semanticColor.surface.overlay,
347349
},
348350
button: {
349351
maxWidth: 150,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type {Meta, StoryObj} from "@storybook/react";
2+
import * as React from "react";
3+
4+
import {StyleSheet} from "aphrodite";
5+
6+
import {View} from "@khanacademy/wonder-blocks-core";
7+
import Pill from "@khanacademy/wonder-blocks-pill";
8+
import {spacing} from "@khanacademy/wonder-blocks-tokens";
9+
import {AllVariants} from "../components/all-variants";
10+
import {PillKind} from "../../packages/wonder-blocks-pill/src/components/pill";
11+
12+
const rows = [
13+
{name: "Static", props: {}},
14+
{name: "Clickable", props: {onClick: () => {}}},
15+
];
16+
17+
const columns = [
18+
{
19+
name: "Small",
20+
props: {size: "small"},
21+
},
22+
{
23+
name: "Medium",
24+
props: {size: "medium"},
25+
},
26+
{
27+
name: "Large",
28+
props: {size: "large"},
29+
},
30+
];
31+
32+
type Story = StoryObj<typeof Pill>;
33+
34+
const kinds: Array<PillKind> = [
35+
"transparent",
36+
"neutral",
37+
"accent",
38+
"info",
39+
"success",
40+
"warning",
41+
"critical",
42+
];
43+
44+
/**
45+
* The following stories are used to generate the pseudo states for the Switch
46+
* component. This is only used for visual testing in Chromatic.
47+
*/
48+
const meta = {
49+
title: "Packages / Pill / Pill - All Variants",
50+
component: Pill,
51+
render: (args) => (
52+
<AllVariants rows={rows} columns={columns}>
53+
{(props) => (
54+
<View style={styles.container}>
55+
{kinds.map((kind) => (
56+
<Pill {...args} {...props} kind={kind}>
57+
{kind}, {props.size}
58+
</Pill>
59+
))}
60+
</View>
61+
)}
62+
</AllVariants>
63+
),
64+
args: {
65+
children: "This is some text!",
66+
},
67+
tags: ["!autodocs"],
68+
} satisfies Meta<typeof Pill>;
69+
70+
export default meta;
71+
72+
export const Default: Story = {};
73+
74+
export const Hover: Story = {
75+
parameters: {pseudo: {hover: true}},
76+
};
77+
78+
export const Focus: Story = {
79+
parameters: {pseudo: {focusVisible: true}},
80+
};
81+
82+
export const HoverFocus: Story = {
83+
name: "Hover + Focus",
84+
parameters: {pseudo: {hover: true, focusVisible: true}},
85+
};
86+
87+
export const Active: Story = {
88+
parameters: {pseudo: {hover: true, active: true}},
89+
};
90+
91+
const styles = StyleSheet.create({
92+
container: {
93+
gap: spacing.medium_16,
94+
},
95+
});

0 commit comments

Comments
 (0)