Skip to content

Commit 4aad557

Browse files
authored
Add theming to Link, use BodyText in Button (#2743)
## Summary: This PR addresses font theming in WB Link, and updates internal typography usage in Button. Longer version: I investigated why Link wasn't using the themed font by comparing it to WB Button. Button used Label typography styles to wrap its text content, which set a themed font on a child `span`. I updated Button to use BodyText. Rather than wrapping Link's contents in an extra span, I elected to add a `font` declaration and account for font weight differences with component tokens. Issue: WB-2052 ## Test plan: 1. Verify Link has Lato font family and regular weight in OG 2. Verify Link has Jakarta font family and bold weight in TB 3. Verify Button has no visual changes in either theme, including color 4. Check font-size scaling for larger sizes in chrome://settings > Appearance > Font Size Author: marcysutton Reviewers: beaesguerra, marcysutton Required Reviewers: Approved By: beaesguerra Checks: ✅ 12 checks were successful, ⏭️ 2 checks have been skipped Pull Request URL: #2743
1 parent a412895 commit 4aad557

File tree

16 files changed

+89
-33
lines changed

16 files changed

+89
-33
lines changed

.changeset/forty-icons-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@khanacademy/wonder-blocks-breadcrumbs": minor
3+
"@khanacademy/wonder-blocks-link": minor
4+
---
5+
6+
Add font theming to Link and Breadcrumbs with links

.changeset/lazy-dolphins-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-tokens": minor
3+
---
4+
5+
Add new font tokens for Links: textDecoration underlineOffset and thickness, font family, and font weight

.changeset/red-numbers-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-button": patch
3+
---
4+
5+
Update ButtonCore to use BodyText component internally for text

.storybook/preview-head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<style>
2323
body {
2424
font-family: "Lato", sans-serif;
25-
font-size: 16px!important;
25+
font-size: 1.6rem!important;
2626
}
2727

2828
/* Overrides the ArgTypes table tabs to avoid some z-index issues with

__docs__/wonder-blocks-link/link-testing-snapshots.stories.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const generateCells = (rtl: boolean = false) => [
2222
{
2323
name: "Primary",
2424
props: {
25-
children: rtl ? rtlText : "This is a Link",
25+
children: rtl ? rtlText : "This is my Link",
2626
},
2727
},
2828
{
@@ -61,10 +61,6 @@ type Story = StoryObj<typeof Link>;
6161
*/
6262
const meta = {
6363
title: "Packages / Link / Testing / Snapshots / Link",
64-
args: {
65-
children: "This is a Link",
66-
href: "https://www.khanacademy.org",
67-
},
6864
parameters: {
6965
chromatic: {
7066
modes: {

packages/wonder-blocks-breadcrumbs/src/components/breadcrumbs-item.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {StyleSheet} from "aphrodite";
44
import type {AriaProps} from "@khanacademy/wonder-blocks-core";
55
import {addStyle} from "@khanacademy/wonder-blocks-core";
66
import Link from "@khanacademy/wonder-blocks-link";
7-
import {spacing} from "@khanacademy/wonder-blocks-tokens";
7+
import {font, spacing} from "@khanacademy/wonder-blocks-tokens";
88

99
type Props = AriaProps & {
1010
/**
@@ -72,6 +72,8 @@ const styles = StyleSheet.create({
7272
alignItems: "center",
7373
justifyContent: "center",
7474
marginRight: spacing.xxxSmall_4,
75+
lineHeight: "inherit",
76+
fontFamily: font.family.sans,
7577
},
7678

7779
separator: {

packages/wonder-blocks-button/src/components/button-core.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import {CSSProperties, StyleSheet} from "aphrodite";
33

4-
import {LabelLarge, LabelSmall} from "@khanacademy/wonder-blocks-typography";
4+
import {BodyText} from "@khanacademy/wonder-blocks-typography";
55
import {View} from "@khanacademy/wonder-blocks-core";
66
import {CircularSpinner} from "@khanacademy/wonder-blocks-progress-spinner";
77

@@ -68,10 +68,11 @@ const ButtonCore: React.ForwardRefExoticComponent<
6868
size === "large" && sharedStyles.large,
6969
];
7070

71-
const Label = size === "small" ? LabelSmall : LabelLarge;
72-
7371
const label = (
74-
<Label
72+
<BodyText
73+
size={size === "small" ? "small" : undefined}
74+
weight={size === "large" ? "bold" : undefined}
75+
tag="span"
7576
style={[
7677
sharedStyles.text,
7778
size === "small" && sharedStyles.smallText,
@@ -82,7 +83,7 @@ const ButtonCore: React.ForwardRefExoticComponent<
8283
testId={testId ? `${testId}-inner-label` : undefined}
8384
>
8485
{children}
85-
</Label>
86+
</BodyText>
8687
);
8788

8889
const sizeMapping = {

packages/wonder-blocks-link/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
"main": "dist/index.js",
1010
"module": "dist/es/index.js",
1111
"types": "dist/index.d.ts",
12+
"exports": {
13+
".": {
14+
"import": "./dist/es/index.js",
15+
"require": "./dist/index.js",
16+
"types": "./dist/index.d.ts"
17+
},
18+
"./styles.css": "./dist/css/vars.css"
19+
},
1220
"scripts": {
21+
"build:css": "pnpm exec wonder-blocks-tokens .",
1322
"test": "echo \"Error: no test specified\" && exit 1",
1423
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
1524
},
@@ -19,7 +28,9 @@
1928
"@khanacademy/wonder-blocks-clickable": "workspace:*",
2029
"@khanacademy/wonder-blocks-core": "workspace:*",
2130
"@khanacademy/wonder-blocks-icon": "workspace:*",
22-
"@khanacademy/wonder-blocks-tokens": "workspace:*"
31+
"@khanacademy/wonder-blocks-tokens": "workspace:*",
32+
"@khanacademy/wonder-blocks-typography": "workspace:*",
33+
"@khanacademy/wonder-blocks-styles": "workspace:*"
2334
},
2435
"peerDependencies": {
2536
"@phosphor-icons/core": "catalog:",

packages/wonder-blocks-link/src/components/link-core.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
spacing,
99
semanticColor,
1010
border,
11+
font,
1112
} from "@khanacademy/wonder-blocks-tokens";
13+
import {focusStyles} from "@khanacademy/wonder-blocks-styles";
1214
import {isClientSideUrl} from "@khanacademy/wonder-blocks-clickable";
1315
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
1416
import externalLinkIcon from "@phosphor-icons/core/bold/arrow-square-out-bold.svg";
@@ -19,6 +21,7 @@ import type {
1921
} from "@khanacademy/wonder-blocks-clickable";
2022
import type {StyleDeclaration} from "aphrodite";
2123
import type {SharedProps} from "./link";
24+
import theme from "../theme";
2225

2326
type Props = SharedProps &
2427
ChildrenProps &
@@ -156,6 +159,8 @@ const linkContentStyles = StyleSheet.create({
156159

157160
const sharedStyles = StyleSheet.create({
158161
shared: {
162+
fontFamily: theme.root.font.family,
163+
fontWeight: theme.root.font.weight,
159164
cursor: "pointer",
160165
textDecoration: "none",
161166
outline: "none",
@@ -167,7 +172,7 @@ const sharedStyles = StyleSheet.create({
167172
* The object that contains the default and inverse colors for the link
168173
* component.
169174
*/
170-
const theme = {
175+
const states = {
171176
color: {
172177
// Primary link color
173178
default: {
@@ -209,49 +214,37 @@ const _generateStyles = (inline: boolean, light: boolean) => {
209214
return styles[buttonType];
210215
}
211216

212-
const variant = light ? theme.color.inverse : theme.color.default;
217+
const variant = light ? states.color.inverse : states.color.default;
213218

214219
const focusStyling = {
215-
outline: `${border.width.thin} solid ${variant.focus.border}`,
216-
borderRadius: border.radius.radius_040,
220+
...focusStyles.focus[":focus-visible"],
221+
borderRadius: border.radius.radius_010,
217222
outlineOffset: border.width.medium,
218223
};
219224

220225
const pressStyling = {
221226
color: variant.press.foreground,
222227
textDecoration: "underline currentcolor solid",
223-
// TODO(WB-1521): Update the underline offset to be 4px after
224-
// the Link audit.
225-
// textUnderlineOffset: 4,
228+
textUnderlineOffset: font.textDecoration.underlineOffset,
226229
};
227230

228231
const newStyles: StyleDeclaration = {
229232
rest: {
230233
color: variant.rest.foreground,
231234
":hover": {
232-
// TODO(WB-1521): Update text decoration to the 1px dashed
233-
// underline after the Link audit.
234-
// textDecoration: "underline currentcolor dashed 2px",
235235
textDecoration: "underline currentcolor solid",
236236
color: variant.hover.foreground,
237-
// TODO(WB-1521): Update the underline offset to be 4px after
238-
// the Link audit.
239-
// textUnderlineOffset: 4,
237+
textUnderlineOffset: font.textDecoration.underlineOffset,
240238
},
241239
// Focus styles only show up with keyboard navigation.
242240
// Mouse users don't see focus styles.
243241
":focus-visible": focusStyling,
244242
":active": pressStyling,
245243
},
246244
restInline: {
247-
// TODO(WB-1521): Update text decoration to the 1px dashed
248-
// underline after the Link audit.
249-
// textDecoration: "underline currentcolor solid 1px",
250245
textDecoration: "underline currentcolor solid",
251-
// TODO(WB-1521): Update the underline offset to be 4px after
252-
// the Link audit.
253-
// textUnderlineOffset: 4,
254-
textUnderlineOffset: border.width.medium,
246+
textDecorationThickness: font.textDecoration.thickness,
247+
textUnderlineOffset: font.textDecoration.underlineOffset,
255248
},
256249
focus: focusStyling,
257250
press: pressStyling,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
root: {
3+
font: {
4+
family: "inherit",
5+
weight: "inherit",
6+
},
7+
},
8+
};

0 commit comments

Comments
 (0)